From f194b46623ab0c0c039c04da5af2edbaf2265203 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Tue, 21 May 2024 17:08:44 -0300 Subject: [PATCH] add `MediumLevelILFunction::ssa_variable_definition` --- rust/src/mlil/function.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rust/src/mlil/function.rs b/rust/src/mlil/function.rs index a2492f5d5..e92ce6b1f 100644 --- a/rust/src/mlil/function.rs +++ b/rust/src/mlil/function.rs @@ -7,7 +7,7 @@ use crate::basicblock::BasicBlock; use crate::function::{Function, Location}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref, RefCountable}; use crate::string::BnStrCompatible; -use crate::types::{Conf, PossibleValueSet, Type, UserVariableValues, Variable}; +use crate::types::{Conf, PossibleValueSet, SSAVariable, Type, UserVariableValues, Variable}; use super::{MediumLevelILBlock, MediumLevelILInstruction, MediumLevelILLiftedInstruction}; @@ -449,6 +449,18 @@ impl MediumLevelILFunction { ) } } + + /// Gets the instruction that contains the given SSA variable's definition. + /// + /// Since SSA variables can only be defined once, this will return the single instruction where that occurs. + /// For SSA variable version 0s, which don't have definitions, this will return None instead. + pub fn ssa_variable_definition(&self, var: SSAVariable) -> Option { + let result = unsafe { + BNGetMediumLevelILSSAVarDefinition(self.handle, &var.variable.raw(), var.version) + }; + (result < self.instruction_count()) + .then(|| MediumLevelILInstruction::new(self.to_owned(), result)) + } } impl ToOwned for MediumLevelILFunction {