Expand description
this is a crate which allows encoding, decoding and working with x86 instructions in a very convenient and user-friendly way.
it uses the Zydis library under the hood, but provides user-friendly wrappers around Zydis’ interfaces to make it
easier to work with.
§Example
let state = rydis::RydisState::new(MachineMode::Long64, StackWidth::Width64)?;
// encode an instruction
let encoded = state.encode(Instruction {
prefixes: Prefixes::empty(),
mnemonic: Mnemonic::XCHG,
operands: [Operand::Reg(Register::RAX), Operand::Reg(Register::RBX)]
.into_iter()
.collect(),
})?;
// decode it
let decoded_instruction = state.decode_one(encoded.as_slice())?;
// modify it
let mut modified_instruction = decoded_instruction.to_instruction();
modified_instruction.operands[1] = Operand::Mem(MemOperand {
base: Some(Register::RBP),
index: None,
displacement: 0x1234,
size: decoded_instruction.operand_width,
segment_register_override: None,
});
// format it
println!(
"modified insn: {}",
modified_instruction.format(&state, FormatStyle::Intel, Some(0x123400))?
);
// re-encode the modified instruction
let re_encoded = state.encode(modified_instruction)?;Structs§
- Decode
Iter - an iterator which decodes instructions from a buffer.
- Decoded
Instruction - information about a decoded instruction.
- Decoded
Iter Instruction - information about a decoded instruction using the iterator decoder.
- Decoded
Operand - information about a decoded operand.
- Instruction
- an instruction.
- MemOperand
- a memory operand, for example
[rbp+2*rsi+0x35]. - MemOperand
Index - the index of a memory operand, for example the
2*rsipart in[rbp+2*rsi+0x35]. - Operand
Actions - the actions that an operand is used for by an instruction.
- Prefixes
- the prefixes of an instruction.
- PtrOperand
- A pointer operand, for example
0x10:0x1234. - Rydis
State - a structure which encapsulates information required for encoding/decoding instructions.
Enums§
- Error
- the error type of this crate.
- Format
Style - the style to use when formatting an instruction
- Machine
Mode - the machine mode to decode instructions according to.
- Mnemonic
- an instruction mnemonic.
- Operand
- an operand.
- Register
- a register.
- Segment
Register - a segment register.
- Stack
Width - the stack width to decode instructions according to.
- Zydis
Error - an error returned from the zydis library.
Constants§
- MAX_
FORMATTED_ INSTRUCTION_ LEN - the maximum length of a formatted instruction string, in bytes.
- MAX_
INSTRUCTION_ LEN - the maximum length of an instruction, in bytes.
- MAX_
OPERANDS_ AMOUNT - the maximum amount of operands of a single instruction.
Type Aliases§
- Accessed
Flags - information about the flags accessed by an instruction.
- Accessed
Flags Mask - a mask of the flags accessed in some way by some instruction.
- Decoded
Instruction Operands - an array of operands of a decoded instruction.
- Encoded
Instruction Buf - a buffer for an encoded instruction.
- Formatted
Instruction - a formatted instruction string.
- Instruction
Operands - an array of operands of an instruction.
- Result
- the result type of this crate.