Skip to main content

Emulator

Struct Emulator 

Source
pub struct Emulator<'ctx, M = EmulatedMemory> { /* private fields */ }

Implementations§

Source§

impl<'ctx> Emulator<'ctx, EmulatedMemory>

Source

pub fn new(ctx: &'ctx Context<'ctx>, entry: BlockId) -> Self

Builds an emulator over the default flat memory.

Source

pub fn from_function(ctx: &'ctx Context<'ctx>, func: FunctionId) -> Self

Source

pub fn from_block(ctx: &'ctx Context<'ctx>, block: BlockId) -> Self

Source

pub fn from_address(ctx: &'ctx Context<'ctx>, addr: u64) -> Self

Source§

impl<'ctx, M: EmulatorMemory + Default> Emulator<'ctx, M>

Source

pub fn new_in(ctx: &'ctx Context<'ctx>, entry: BlockId) -> Self

Builds an emulator over an explicit memory backend.

Source

pub fn set_instruction_hook( &mut self, hook: impl Fn(&InstructionRef<'_, '_>, &StandaloneEmulator<M>) + Send + Sync + 'static, )

Source

pub fn set_call_interceptor( &mut self, interceptor: impl FnMut(&Context<'_>, &mut StandaloneEmulator<M>, &CallSite) -> Result<CallInterception, Box<str>> + Send + Sync + 'static, )

Source

pub fn clear_call_interceptor(&mut self)

Source

pub fn from_function_in(ctx: &'ctx Context<'ctx>, func: FunctionId) -> Self

Builds an emulator at a function’s root block, over an explicit backend.

Source

pub fn from_address_in(ctx: &'ctx Context<'ctx>, addr: u64) -> Self

Builds an emulator positioned at addr, over an explicit backend.

Source

pub fn inspect_memory( &mut self, space: SpaceId, addr: u64, size: usize, ) -> Option<Vec<u8>>

Debugging method to view a value at a given address

Source

pub fn set_varnode( &mut self, id: VarnodeId, value: u64, ) -> Result<(), EmulatorErrorKind>

Sets the value of a varnode

Source

pub fn set_varnode_u128( &mut self, id: VarnodeId, value: u128, ) -> Result<(), EmulatorErrorKind>

Sets the value of a varnode using full 128-bit precision.

Source

pub fn set_register( &mut self, id: RegisterId, value: u64, ) -> Result<(), EmulatorErrorKind>

Sets the value of a register

Source

pub fn write_memory( &mut self, space: SpaceId, addr: u64, value: &[u8], ) -> Result<(), EmulatorErrorKind>

Writes a value to memory

Source

pub fn read_memory( &mut self, space: SpaceId, addr: u64, size: usize, ) -> Result<Vec<u8>, EmulatorErrorKind>

Source

pub fn set_register_u128( &mut self, id: RegisterId, value: u128, ) -> Result<(), EmulatorErrorKind>

Sets the value of a register using full 128-bit precision.

Source

pub fn read_varnode(&mut self, id: VarnodeId) -> Option<u64>

Source

pub fn read_varnode_u128(&mut self, id: VarnodeId) -> Option<u128>

Source

pub fn read_register(&mut self, id: RegisterId) -> Option<u64>

Source

pub fn read_register_u128(&mut self, id: RegisterId) -> Option<u128>

Source

pub fn set_register_lane(&mut self, id: RegisterId, lane: usize, value: u64)

Writes a single 64-bit lane of a wide register. Lane n covers bytes [n*8 .. n*8+8] relative to the register’s base address.

Source

pub fn read_register_lane(&mut self, id: RegisterId, lane: usize) -> u64

Reads a single 64-bit lane of a wide register (little-endian). Lane n covers bytes [n*8 .. n*8+8] relative to the register’s base address.

Source

pub fn block(&self) -> BlockRef<'ctx, 'ctx>

Gets the current block

Source

pub fn insn(&self) -> Option<InstructionRef<'ctx, 'ctx>>

Gets the current instruction

Source

pub fn step(&mut self) -> Result<()>

Executes a single pcode instruction

Source

pub fn run_block(&mut self) -> Result<()>

Executes instructions until the end of the current block

Source

pub fn run_until(&mut self, addr: u64) -> Result<()>

Runs blocks until the current block starts at addr.

Source

pub fn run_function(&mut self, func: FunctionId) -> Result<()>

Runs the given function from its root block, stopping before the outermost Return.

Source

pub fn call_stack(&self) -> &[FunctionId]

Returns the current emulator call stack (outermost function first). Only populated during run_function execution.

Trait Implementations§

Source§

impl<'ctx, M: EmulatorMemory> Interpreter for Emulator<'ctx, M>

Source§

type V = SizedValue

Source§

type M = M

Source§

fn memory(&mut self) -> &mut Self::M

Source§

fn ctx(&self) -> &Context<'ctx>

Source§

fn get_value(&mut self, id: ValueId) -> Result<Self::V, EmulatorErrorKind>

Gets the value of the given value ID, if it exists in the context.
Source§

fn get_varnode_value( &mut self, id: VarnodeId, ) -> Result<Self::V, EmulatorErrorKind>

Reads the value of a varnode from the emulated memory space.
Source§

fn set_varnode_value( &mut self, id: VarnodeId, value: Self::V, ) -> Result<(), EmulatorErrorKind>

Writes a value to a varnode in the emulated memory space.
Source§

fn get_register_value( &mut self, reg_id: RegisterId, ) -> Result<Self::V, EmulatorErrorKind>

Returns the value of the given register, if it exists in the context.
Source§

fn set_register_value( &mut self, reg_id: RegisterId, value: Self::V, ) -> Result<(), EmulatorErrorKind>

Sets the value of the given register, if it exists in the context.
Source§

fn interpret_( &mut self, insn: &InstructionRef<'_, '_>, mnemonic: &Mnemonic, ) -> Result<Option<Self::V>, EmulatorErrorKind>

Gets the value of the given instruction, if it has one. This is used for instructions that produce a value, such as copy, load, and binary operations.
Source§

fn interpret( &mut self, insn: InstructionRef<'_, '_>, mnemonic: &Mnemonic, ) -> Result<Option<Self::V>>

Auto Trait Implementations§

§

impl<'ctx, M = EmulatedMemory> !RefUnwindSafe for Emulator<'ctx, M>

§

impl<'ctx, M = EmulatedMemory> !UnwindSafe for Emulator<'ctx, M>

§

impl<'ctx, M> Freeze for Emulator<'ctx, M>

§

impl<'ctx, M> Send for Emulator<'ctx, M>

§

impl<'ctx, M> Sync for Emulator<'ctx, M>

§

impl<'ctx, M> Unpin for Emulator<'ctx, M>

§

impl<'ctx, M> UnsafeUnpin for Emulator<'ctx, M>

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.