x86asm - A Rust crate for assembling & disassembling x86/64 instructions
The x86asm crate is a Rust library designed for programatically assembling & disassembling x86 instructions. This project supports real, protected, and long mode assembly.
Status
This crate is feature complete but immature. If you encounter bugs or wish for a helpful new feature, feel free to contribute or create an issue. See the contributing section below.
Usage Examples
See the examples directory for full examples.
Encode a series of instructions to an in-memory buffer:
use io:Cursor;
use ;
...
let buffer = new;
let mut writer = new;
// mov eax, 10
// mov ebx, 20
// add eax, ebx
writer.write2; // mov eax, 10
writer.write2; // mov ebx, 20
writer.write2; // add eax, ebx
A more in-depth example demonstrating different addressing modes:
let buffer = new;
let mut writer = new;
// mov ebx, dword ptr [eax]
// mov ebx, dword ptr [eax+5]
// mov ebx, dword ptr [eax+ecx*2]
// mov ebx, dword ptr [eax+ecx*2+5]
// mov ebx, dword ptr ds:5
let instructions = &;
for instr in instructions
Real mode assembly:
let buffer = new;
let mut writer = new;
// mov ax, [bx+si]
// add ax, bx
// mov [bp+si], ax
let instructions = &;
for instr in instructions
Long mode assembly:
let buffer = new;
let mut writer = new;
// mov rax, qword ptr [rip+100]
// mov rbx, 500
// sub rax, rbx
// mov [rcx+rdx*4], rax
let instructions = &;
for instr in instructions
Build
The x86asm crate uses Cargo. To build, clone the repository using Git and run cargo build
from the command line using either stable or nightly Rust.
Contribute
Contributions are welcome! If you're not inclined to dig into the code yourself but encounter an issue, feel free to submit an issue using the GitHub issue tracker. Before contributing, please see gen_defs/README and src/test/README for a detailed description of the instruction format, as well as in-depth guidelines for contributing.
Contributors
- Gregory Comer - Author
License
This project is open source and is licensed under the MIT License. The full text is included in the repository.