emproof-com/nyxstone
GitHub: emproof-com/nyxstone
Stars: 405 | Forks: 20
# Nyxstone
[](https://github.com/emproof-com/nyxstone/actions/workflows/cpp.yml)
[](https://crates.io/crates/nyxstone)
[](https://pypi.org/project/nyxstone)
[](https://emproof-com.github.io/nyxstone/)
Nyxstone is a fast assembly and disassembly library built on top of LLVM. It does not require patches to the LLVM source tree and links against the standard LLVM libraries shipped by most Linux distributions, Homebrew, and `apt.llvm.org`. The core is a C++ library with Rust and Python bindings. Nyxstone supports every architecture the linked LLVM ships with and lets you configure architecture-specific CPU and feature settings.

## Index
1. [Core Features](#core-features)
2. [Using Nyxstone](#using-nyxstone)
1. [Prerequisites](#prerequisites)
2. [CLI Tool](#cli-tool)
3. [C++ Library](#c-library)
4. [Rust Bindings](#rust-bindings)
5. [Python Bindings](#python-bindings)
3. [How it works](#how-it-works)
4. [Benchmarks](#benchmarks)
5. [Roadmap](#roadmap)
6. [License](#license)
7. [Contributing](#contributing)
8. [Maintainers](#maintainers)
## Core Features
* Assembles and disassembles code for every architecture supported by the linked LLVM, including x86, ARM, AArch64, MIPS, RISC-V, and others.
* C++ library built on LLVM, with Rust and Python bindings.
* Native platform support for Linux and macOS.
* Supports labels in the assembler, including user-provided label-to-address mappings.
* Produces raw bytes, text disassembly, or detailed instruction objects that carry the address, raw bytes, and assembly text together.
* Disassembly can be limited to a user-specified number of instructions.
* Configurable per-architecture target settings (CPU, ISA extensions, hardware features).
* Assembles common data directives (`.byte`, `.word`, `.org`, `.nops`, `.align`, `.fill`, `.uleb128`, …) and the ARM/AArch64 `ldr rX, =const` literal pool.
* Reports an explicit error for input it cannot represent (for example, switching to a section other than `.text`) instead of silently dropping the affected bytes.
For the list of supported architectures, run `clang -print-targets`. For per-architecture features, run `llc -march=ARCH -mattr=help`.
## Using Nyxstone
This section provides instructions on how to get started with Nyxstone, covering the necessary prerequisites, how to use the CLI tool, and step-by-step guidelines for using the library with C++, Rust, and Python.
### Prerequisites
Before building Nyxstone, ensure clang and LLVM are present on your system. **Nyxstone supports LLVM major versions 15-20.** Any minor/patch within those majors works; the build picks the newest LLVM it can find unless you pin one.
The build resolves LLVM in this order:
1. `$NYXSTONE_LLVM_PREFIX`, if set. The build searches that prefix exclusively (system paths are ignored), so this is the way to pin a specific version when multiple are installed.
2. Known per-major install layouts probed newest-first: `/usr/lib/llvm-` (Debian/Ubuntu), `/opt/homebrew/opt/llvm@` (Homebrew on Apple Silicon), `/usr/local/opt/llvm@` (Homebrew on x86 macOS), `/opt/brew/opt/llvm@` (custom-prefix Homebrew on Linux).
3. CMake's default `find_package(LLVM)` search.
If the resolved version is outside 15-20 the configure step fails with a clear error.
#### Installation
* **Debian / Ubuntu**
sudo apt install llvm-${version} llvm-${version}-dev
Debian trixie ships 17-19, Ubuntu ships 15-17 in the default repos. For versions not in your distro's repos, follow the instructions at [apt.llvm.org](https://apt.llvm.org/). The script `apt.llvm.org/llvm.sh ` is the easiest path.
* **Arch**
sudo pacman -S llvm llvm-libs
* **Homebrew (macOS / Linux)**
brew install llvm@20
export NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@20)"
* **From source**
On Windows, run these from a Visual Studio 2022 x64 command prompt and replace `~/lib/my-llvm-20` with a path of your choice.
git clone -b release/20.x --single-branch https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_PARALLEL_LINK_JOBS=1
cmake --build build
cmake --install build --prefix ~/lib/my-llvm-20
export NYXSTONE_LLVM_PREFIX=~/lib/my-llvm-20
You may also need any system libraries LLVM was built against. Check with `llvm-config --system-libs`; on Debian/Ubuntu this is typically `zlib1g-dev` and `libzstd-dev`.
### CLI Tool
Nyxstone ships a [CLI tool](examples/nyxstone-cli.cpp) for one-off assembly and disassembly. Clone the repository and build it with CMake:
git clone https://github.com/emproof-com/nyxstone
cd nyxstone
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
The resulting `nyxstone` binary lands in `build/`. Its help menu:
$ ./nyxstone -h
Usage: nyxstone [-t=] [-p=] [-d]
Examples:
# Assemble an instruction with the default architecture ('x86_64').
nyxstone 'push eax'
# Disassemble the bytes 'ffc300d1' as AArch64 code.
nyxstone -t aarch64 -d ffc300d1
Options:
-t, --triple= LLVM target triple or alias, e.g. 'aarch64'
-c, --cpu= LLVM CPU specifier, e.g. 'cortex-a53'
-f, --features=
- LLVM architecture/CPU feature list, e.g. '+mte,-neon'
-p, --address=
- Label-to-address mappings (used when assembling only)
-d, --disassemble Treat as bytes to disassemble instead of assembly
-h, --help Show this help and usage message
Notes:
The '--triple' parameter also supports aliases for common target triples:
'x86_32' -> 'i686-linux-gnu'
'x86_64' -> 'x86_64-linux-gnu'
'armv6m' -> 'armv6m-none-eabi'
'armv7m' -> 'armv7m-none-eabi'
'armv8m' -> 'armv8m.main-none-eabi'
'aarch64' -> 'aarch64-linux-gnueabihf'
The CPUs for a target can be found with 'llc -mtriple=
标签:通知系统