Skip to content

Commit

Permalink
fix Function documentation by adding MediumLevelILInstruction::get_sp…
Browse files Browse the repository at this point in the history
…lit_var_for_definition
  • Loading branch information
rbran committed May 16, 2024
1 parent b2ecd79 commit dfab709
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,15 +1882,15 @@ impl Function {

/// Splits a varible at the definition site. The given `var` must be the
/// variable unique to the definition and should be obtained by using
/// [MediumLevelILInstruction::get_split_var_for_definition] at the definition site.
/// [mlil::MediumLevelILInstruction::get_split_var_for_definition] at the definition site.
///
/// This function is not meant to split variables that have been previously merged. Use
/// `unmerge_vars` to split previously merged variables.
///
/// <div class="warning">
///
/// Binary Ninja automatically splits all variables that the analysis determines
/// to be safely splittable. Splitting a variable manually with `split_var` can cause
/// to be safely splittable. Splitting a variable manually with [Function::split_variable] can cause
/// IL and decompilation to be incorrect. There are some patterns where variables can be safely
/// split semantically but analysis cannot determine that it is safe. This function is provided
/// to allow variable splitting to be performed in these cases by plugins or by the user.
Expand All @@ -1904,7 +1904,7 @@ impl Function {

/// Undoes varible splitting performed with `split_var`. The given `var`
/// must be the variable unique to the definition and should be obtained by using
/// [MediumLevelILInstruction::get_split_var_for_definition] at the definition site.
/// [mlil::MediumLevelILInstruction::get_split_var_for_definition] at the definition site.
///
/// * `var` - variable to unsplit
pub fn unsplit_variable(&self, var: &Variable) {
Expand Down
17 changes: 17 additions & 0 deletions rust/src/mlil/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use binaryninjacore_sys::BNGetDefaultIndexForMediumLevelILVariableDefinition;
use binaryninjacore_sys::BNGetMediumLevelILByIndex;
use binaryninjacore_sys::BNMediumLevelILInstruction;
use binaryninjacore_sys::BNMediumLevelILOperation;
Expand Down Expand Up @@ -1033,6 +1034,22 @@ impl MediumLevelILInstruction {
}
}

/// Gets the unique variable for a definition instruction. This unique variable can be passed
/// to [crate::function::Function::split_variable] to split a variable at a definition. The given `var` is the
/// assigned variable to query.
///
/// * `var` - variable to query
pub fn get_split_var_for_definition(&self, var: &Variable) -> Variable {
let new_index = unsafe {
BNGetDefaultIndexForMediumLevelILVariableDefinition(
self.function.handle,
&var.raw(),
self.index,
)
};
Variable::new(var.t, new_index, var.storage)
}

fn lift_operand(&self, expr_idx: usize) -> Box<MediumLevelILLiftedInstruction> {
Box::new(self.function.lifted_instruction_from_idx(expr_idx))
}
Expand Down

0 comments on commit dfab709

Please sign in to comment.