Instruction

Struct Instruction 

Source
pub struct Instruction {
    pub prefixes: Prefixes,
    pub mnemonic: Mnemonic,
    pub operands: InstructionOperands,
}
Expand description

an instruction.

Fields§

§prefixes: Prefixes

the instruction’s prefixes.

§mnemonic: Mnemonic

the instruction’s mnemonic.

§operands: InstructionOperands

the instruction’s explicit operands, which are the operands that are specified in the instruction’s textual representation.

Implementations§

Source§

impl Instruction

Source

pub fn memory_operand(&self) -> Option<&MemOperand>

returns the memory operand of this instruction, if any.

Source

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

Source§

fn clone(&self) -> Instruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Instruction

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Instruction

Source§

fn eq(&self, other: &Instruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Instruction

Source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.