binaryninja::medium_level_il

Struct MediumLevelILFunction

source
pub struct MediumLevelILFunction { /* private fields */ }

Implementations§

source§

impl MediumLevelILFunction

source

pub fn instruction_at<L: Into<Location>>( &self, loc: L, ) -> Option<MediumLevelILInstruction>

source

pub fn instruction_index_at<L: Into<Location>>( &self, loc: L, ) -> Option<MediumLevelInstructionIndex>

source

pub fn instruction_from_index( &self, index: MediumLevelInstructionIndex, ) -> Option<MediumLevelILInstruction>

source

pub fn instruction_from_expr_index( &self, expr_index: MediumLevelInstructionIndex, ) -> Option<MediumLevelILInstruction>

source

pub fn instruction_count(&self) -> usize

source

pub fn expression_count(&self) -> usize

source

pub fn ssa_form(&self) -> MediumLevelILFunction

source

pub fn function(&self) -> Ref<Function>

source

pub fn basic_blocks(&self) -> Array<BasicBlock<MediumLevelILBlock>>

source

pub fn var_definitions(&self, var: &Variable) -> Array<MediumLevelILInstruction>

source

pub fn create_user_stack_var<'a, S: BnStrCompatible, C: Into<Conf<&'a Type>>>( self, offset: i64, var_type: C, name: S, )

source

pub fn delete_user_stack_var(self, offset: i64)

source

pub fn create_user_var<'a, S: BnStrCompatible, C: Into<Conf<&'a Type>>>( &self, var: &Variable, var_type: C, name: S, ignore_disjoint_uses: bool, )

source

pub fn delete_user_var(&self, var: &Variable)

source

pub fn is_var_user_defined(&self, var: &Variable) -> bool

source

pub fn set_user_var_value( &self, var: &Variable, addr: u64, value: PossibleValueSet, after: bool, ) -> Result<(), ()>

Allows the user to specify a PossibleValueSet value for an MLIL variable at its definition site.

.. warning:: Setting the variable value, triggers a reanalysis of the function and allows the dataflow to compute and propagate values which depend on the current variable. This implies that branch conditions whose values can be determined statically will be computed, leading to potential branch elimination at the HLIL layer.

  • var - Variable for which the value is to be set
  • addr - Address of the definition site of the variable
  • value - Informed value of the variable
§Example
let user_var_val = mlil_fun.user_var_values().iter().next().unwrap();
let def_address = user_var_val.def_site.addr;
let var_value = PossibleValueSet::ConstantValue { value: 5 };
mlil_fun
    .set_user_var_value(&user_var_val.variable, def_address, var_value, false)
    .unwrap();
source

pub fn clear_user_var_value( &self, var: &Variable, addr: u64, after: bool, ) -> Result<(), ()>

Clears a previously defined user variable value.

  • var - Variable for which the value was informed
  • def_addr - Address of the definition site of the variable
source

pub fn user_var_values(&self) -> Array<UserVariableValue>

Returns a map of current defined user variable values. Returns a Map of user current defined user variable values and their definition sites.

source

pub fn clear_user_var_values(&self) -> Result<(), ()>

Clear all user defined variable values.

source

pub fn create_auto_stack_var<'a, T: Into<Conf<&'a Type>>, S: BnStrCompatible>( &self, offset: i64, var_type: T, name: S, )

source

pub fn delete_auto_stack_var(&self, offset: i64)

source

pub fn create_auto_var<'a, S: BnStrCompatible, C: Into<Conf<&'a Type>>>( &self, var: &Variable, var_type: C, name: S, ignore_disjoint_uses: bool, )

source

pub fn var_refs(&self, var: &Variable) -> Array<ILReferenceSource>

Returns a list of ILReferenceSource objects (IL xrefs or cross-references) that reference the given variable. The variable is a local variable that can be either on the stack, in a register, or in a flag. This function is related to get_hlil_var_refs(), which returns variable references collected from HLIL. The two can be different in several cases, e.g., multiple variables in MLIL can be merged into a single variable in HLIL.

  • var - Variable for which to query the xref
§Example
let instr_idx = mlil_fun.var_refs(&mlil_var).get(0).expr_idx;
source

pub fn var_refs_from( &self, location: impl Into<Location>, length: Option<u64>, ) -> Array<VariableReferenceSource>

Retrieves variable references from a specified location or range within a medium-level IL function.

Passing in a length will query a range for variable references, instead of just the address specified in location.

source

pub fn current_address(&self) -> Location

Current IL Address

source

pub fn set_current_address(&self, location: impl Into<Location>)

Set the current IL Address

source

pub fn basic_block_containing_index( &self, index: MediumLevelInstructionIndex, ) -> Option<Ref<BasicBlock<MediumLevelILBlock>>>

Returns the BasicBlock at the given instruction index.

You can also retrieve this using MediumLevelILInstruction::basic_block.

source

pub fn finalize(&self)

Ends the function and computes the list of basic blocks.

NOTE: This should be called after updating MLIL.

source

pub fn generate_ssa_form( &self, analyze_conditionals: bool, handle_aliases: bool, non_aliased_vars: impl IntoIterator<Item = Variable>, aliased_vars: impl IntoIterator<Item = Variable>, )

Generate SSA form given the current MLIL.

NOTE: This should be called after updating MLIL.

  • analyze_conditionals - whether to analyze conditionals
  • handle_aliases - whether to handle aliases
  • non_aliased_vars - optional list of variables known to be not aliased
  • aliased_vars - optional list of variables known to be aliased
source

pub fn ssa_variable_definition( &self, ssa_variable: &SSAVariable, ) -> Option<MediumLevelILInstruction>

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.

source

pub fn ssa_memory_definition( &self, version: usize, ) -> Option<MediumLevelILInstruction>

source

pub fn ssa_variable_uses( &self, ssa_variable: &SSAVariable, ) -> Array<MediumLevelILInstruction>

Gets all the instructions that use the given SSA variable.

source

pub fn ssa_memory_uses(&self, version: usize) -> Array<MediumLevelILInstruction>

source

pub fn is_ssa_variable_live(&self, ssa_variable: &SSAVariable) -> bool

Determines if variable is live at any point in the function

source

pub fn variable_definitions( &self, variable: &Variable, ) -> Array<MediumLevelILInstruction>

source

pub fn variable_uses( &self, variable: &Variable, ) -> Array<MediumLevelILInstruction>

source

pub fn live_instruction_for_variable( &self, variable: &Variable, include_last_user: bool, ) -> Array<MediumLevelILInstruction>

Computes the list of instructions for which var is live. If include_last_use is false, the last use of the variable will not be included in the list (this allows for easier computation of overlaps in liveness between two variables). If the variable is never used, this function will return an empty list.

var - the variable to query include_last_use - whether to include the last use of the variable in the list of instructions

source

pub fn ssa_variable_value(&self, ssa_variable: &SSAVariable) -> RegisterValue

source

pub fn create_graph( &self, settings: Option<DisassemblySettings>, ) -> Ref<FlowGraph>

source

pub fn variables(&self) -> Array<Variable>

This gets just the MLIL variables - you may be interested in the union of MediumLevelILFunction::aliased_variables and Function::parameter_variables for all the variables used in the function

source

pub fn aliased_variables(&self) -> Array<Variable>

This returns a list of Variables that are taken reference to and used elsewhere. You may also wish to consider MediumLevelILFunction::variables and Function::parameter_variables

source

pub fn ssa_variables(&self, variable: &Variable) -> Array<SSAVariable>

This gets the MLIL SSA variables for a given Variable.

Trait Implementations§

source§

impl Debug for MediumLevelILFunction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for MediumLevelILFunction

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for MediumLevelILFunction

source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToOwned for MediumLevelILFunction

source§

type Owned = Ref<MediumLevelILFunction>

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl Eq for MediumLevelILFunction

source§

impl Send for MediumLevelILFunction

source§

impl Sync for MediumLevelILFunction

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.