pub struct Instruction {
pub prefixes: Prefixes,
pub mnemonic: Mnemonic,
pub operands: InstructionOperands,
}Expand description
an instruction.
Fields§
§prefixes: Prefixesthe instruction’s prefixes.
mnemonic: Mnemonicthe instruction’s mnemonic.
operands: InstructionOperandsthe instruction’s explicit operands, which are the operands that are specified in the instruction’s textual representation.
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn memory_operand(&self) -> Option<&MemOperand>
pub fn memory_operand(&self) -> Option<&MemOperand>
returns the memory operand of this instruction, if any.
Sourcepub fn format(
&self,
state: &RydisState,
style: FormatStyle,
runtime_address: Option<u64>,
) -> Result<FormattedInstruction>
pub fn format( &self, state: &RydisState, style: FormatStyle, runtime_address: Option<u64>, ) -> Result<FormattedInstruction>
formats this instruction into a string.
Examples found in repository?
examples/basic.rs (line 35)
6fn main() -> rydis::Result<()> {
7 let state = rydis::RydisState::new(MachineMode::Long64, StackWidth::Width64)?;
8
9 // encode an instruction
10 let encoded = state.encode(Instruction {
11 prefixes: Prefixes::empty(),
12 mnemonic: Mnemonic::XCHG,
13 operands: [Operand::Reg(Register::RAX), Operand::Reg(Register::RBX)]
14 .into_iter()
15 .collect(),
16 })?;
17 println!("encoded = {:x?}", encoded);
18
19 // decode it
20 let decoded_instruction = state.decode_one(encoded.as_slice())?;
21
22 // modify it
23 let mut modified_instruction = decoded_instruction.to_instruction();
24 modified_instruction.operands[1] = Operand::Mem(MemOperand {
25 base: Some(Register::RBP),
26 index: None,
27 displacement: 0x1234,
28 size: decoded_instruction.operand_width,
29 segment_register_override: None,
30 });
31
32 // format it
33 println!(
34 "modified insn: {}",
35 modified_instruction.format(&state, FormatStyle::Intel, Some(0x123400))?
36 );
37
38 // re-encode the modified instruction
39 let re_encoded = state.encode(modified_instruction)?;
40 println!("re-encoded = {:x?}", re_encoded);
41
42 Ok(())
43}Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl Hash for Instruction
impl Hash for Instruction
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more