bddisasm x86/x64 instruction decoder
no_std
Rust bindings for the bddisasm x86/x64 decoder library, built
on top of bddisasm-sys.
It supports all existing 16-bit, 32-bit and 64-bit instructions, offering a wide range of information about each one, including:
- implicit operands
- explicit operands
- access mode for each operand
- CPUID feature flags
- CPU modes in which an instruction is valid
Usage
Add bddisasm
to your Cargo.toml
:
[]
= "0.4"
Examples
Decoding one instruction
Use DecodedInstruction::decode
to decode an instruction from a chunk of code.
use ;
let code = vec!;
match decode
Decoding multiple instructions
Use Decoder
to decode multiple instructions
from a chunk of code.
use ;
let code = ;
let decoder = new;
for ins in decoder
This will print:
ENCLS
MOV rax, qword ptr [rbx+rcx*4+0x1234]
the provided input buffer is too small
WRMSR
Use Decoder::decode_next_with_info
to get information about the offset inside the code chunk at which an instruction was decoded from.
use ;
let code = ;
let mut decoder = new;
// Keep decoding until there's nothing left to decode
while let Some = decoder.decode_next_with_info
This will print:
0x0 ENCLS
0x3 MOV rax, qword ptr [rbx+rcx*4+0x1234]
Error `the provided input buffer is too small` at offset 0xb
0xc WRMSR
Working with instruction operands
Instruction operands can be analyzed using the operand module. Rich informaion is offered for each type of operand. Bellow is a minimal example that looks at a memory operand.
use ;
// ` MOV rax, qword ptr [rcx+r15*2]`
let code = b"\x4a\x8b\x04\x79";
let ins = decode.unwrap;
// Get the operands
let operands = ins.operands;
// Get the second operand which is the source (`[rcx+r15*2]`)
let src = operands;
println!;
match src.info
Will print:
Source operand type: memory
Base register: 1
Index register: 15
Scale: 2
No displacement
Accessing the raw bindings
The raw bddisasm_sys
bindings are available via the ffi
re-export.
Feature Flags
std
- adds astd
dependency - the only visible difference when doing this is that [DecodeError
] implements theError
trait