Skip to content

Commit

Permalink
add Function::{reg_value_at, reg_value_after, reg_value_at_exit} methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 11, 2024
1 parent 7c82a00 commit 5a06604
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,60 @@ impl Function {
let display = self.int_display_type(instr_addr, value, operand, Some(arch));
(display, name)
}

/// Get the value the provided string register address corresponding to the given virtual address
///
/// * `addr` - virtual address of the instruction to query
/// * `reg` - string value of native register to query
/// * `arch` - (optional) Architecture for the given function
///
/// # Example
/// ```no_run
/// # use binaryninja::architecture::{ArchitectureExt, Register};
/// # let fun: binaryninja::function::Function = todo!();
/// let reg = fun.arch().register_by_name("rdi").unwrap();
/// let value = fun.reg_value_at(0x400dbe, reg.id(), None);
/// ```
pub fn reg_value_at(
&self,
addr: u64,
reg: u32,
arch: Option<CoreArchitecture>,
) -> RegisterValue {
let arch = arch.unwrap_or_else(|| self.arch());
let register = unsafe { BNGetRegisterValueAtInstruction(self.handle, arch.0, addr, reg) };
register.into()
}

/// Gets the value instruction address corresponding to the given virtual address
///
/// * `addr` - virtual address of the instruction to query
/// * `reg` - string value of native register to query
/// * `arch` - (optional) Architecture for the given function
///
/// # Example
/// ```no_run
/// # use binaryninja::architecture::{ArchitectureExt, Register};
/// # let fun: binaryninja::function::Function = todo!();
/// let reg = fun.arch().register_by_name("rdi").unwrap();
/// let value = fun.reg_value_after(0x400dbe, reg.id(), None);
/// ```
pub fn reg_value_after(
&self,
addr: u64,
reg: u32,
arch: Option<CoreArchitecture>,
) -> RegisterValue {
let arch = arch.unwrap_or_else(|| self.arch());
let register =
unsafe { BNGetRegisterValueAfterInstruction(self.handle, arch.0, addr, reg) };
register.into()
}

pub fn reg_value_at_exit(&self, reg: u32) -> Conf<RegisterValue> {
let register = unsafe { BNGetFunctionRegisterValueAtExit(self.handle, reg) };
Conf::new(register.value.into(), register.confidence)
}
}

impl fmt::Debug for Function {
Expand Down

0 comments on commit 5a06604

Please sign in to comment.