pub struct InstructionInfoFactory { /* private fields */ }
Expand description

Creates InstructionInfos.

Implementations§

source§

impl InstructionInfoFactory

source

pub fn new() -> Self

Creates a new instance.

Examples
use iced_x86::*;

// add [rdi+r12*8-5AA5EDCCh],esi
let bytes = b"\x42\x01\xB4\xE7\x34\x12\x5A\xA5";
let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE);

// This allocates two vectors but they get re-used every time you call info() and info_options().
let mut info_factory = InstructionInfoFactory::new();

for instr in &mut decoder {
    // There's also info_options() if you only need reg usage or only mem usage.
    // info() returns both.
    let info = info_factory.info(&instr);
    for mem_info in info.used_memory().iter() {
        println!("{:?}", mem_info);
    }
    for reg_info in info.used_registers().iter() {
        println!("{:?}", reg_info);
    }
}
source

pub fn info(&mut self, instruction: &Instruction) -> &InstructionInfo

Creates a new InstructionInfo, see also info_options() if you only need register usage but not memory usage or vice versa.

Arguments
  • instruction: The instruction that should be analyzed
Examples
use iced_x86::*;

// add [rdi+r12*8-5AA5EDCCh],esi
let bytes = b"\x42\x01\xB4\xE7\x34\x12\x5A\xA5";
let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE);
let mut info_factory = InstructionInfoFactory::new();

let instr = decoder.decode();
let info = info_factory.info(&instr);

assert_eq!(info.used_memory().len(), 1);
let mem = info.used_memory()[0];
assert_eq!(mem.segment(), Register::DS);
assert_eq!(mem.base(), Register::RDI);
assert_eq!(mem.index(), Register::R12);
assert_eq!(mem.scale(), 8);
assert_eq!(mem.displacement(), 0xFFFFFFFFA55A1234);
assert_eq!(mem.memory_size(), MemorySize::UInt32);
assert_eq!(mem.access(), OpAccess::ReadWrite);

let regs = info.used_registers();
assert_eq!(regs.len(), 3);
assert_eq!(regs[0].register(), Register::RDI);
assert_eq!(regs[0].access(), OpAccess::Read);
assert_eq!(regs[1].register(), Register::R12);
assert_eq!(regs[1].access(), OpAccess::Read);
assert_eq!(regs[2].register(), Register::ESI);
assert_eq!(regs[2].access(), OpAccess::Read);
source

pub fn info_options( &mut self, instruction: &Instruction, options: u32 ) -> &InstructionInfo

Creates a new InstructionInfo, see also info().

Arguments

Trait Implementations§

source§

impl Debug for InstructionInfoFactory

source§

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

Formats the value using the given formatter. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.