Struct iced_x86::InstructionInfoFactory
source · [−]pub struct InstructionInfoFactory { /* private fields */ }
Expand description
Creates InstructionInfo
s.
If you don’t need to know register and memory usage, it’s faster to call Instruction
and
Code
methods such as Instruction::flow_control()
instead of getting that info from this struct.
Implementations
sourceimpl InstructionInfoFactory
impl InstructionInfoFactory
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance.
If you don’t need to know register and memory usage, it’s faster to call Instruction
and
Code
methods such as Instruction::flow_control()
instead of getting that info from this struct.
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);
}
}
sourcepub fn info(&mut self, instruction: &Instruction) -> &InstructionInfo
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.
If you don’t need to know register and memory usage, it’s faster to call Instruction
and
Code
methods such as Instruction::flow_control()
instead of getting that info from this struct.
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);
sourcepub fn info_options(
&mut self,
instruction: &Instruction,
options: u32
) -> &InstructionInfo
pub fn info_options(
&mut self,
instruction: &Instruction,
options: u32
) -> &InstructionInfo
Creates a new InstructionInfo
, see also info()
.
If you don’t need to know register and memory usage, it’s faster to call Instruction
and
Code
methods such as Instruction::flow_control()
instead of getting that info from this struct.
Arguments
instruction
: The instruction that should be analyzedoptions
: Options, seeInstructionInfoOptions