Skip to content

Commit

Permalink
add MediumLevelILFunction::ssa_variable_definition
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 21, 2024
1 parent 47ed0c2 commit f194b46
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rust/src/mlil/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<MediumLevelILInstruction> {
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 {
Expand Down

0 comments on commit f194b46

Please sign in to comment.