From 5fcf6bc59ebc2110d053360d223e6570cdd2272c Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Wed, 7 Feb 2024 11:44:06 -0500 Subject: Refactor MLIL instructions * Turn `MediumLevelILInstruction` into a struct with a `kind` field to indicate the instruction variant, and pull out the `function` and `address` fields from each variant to live in the top-level struct. * Make variant fields public, remove field getter methods and centralize lifting logic to happen all at once. Split tuple fields into individual named fields. * Move the `operands` method to `MediumLevelILLiftedInstruction`, and make it return an owned `Vec` of operands rather than a borrowed iterator. --- rust/src/mlil/function.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'rust/src/mlil/function.rs') diff --git a/rust/src/mlil/function.rs b/rust/src/mlil/function.rs index 8f5ed73d..16cc5102 100644 --- a/rust/src/mlil/function.rs +++ b/rust/src/mlil/function.rs @@ -14,7 +14,7 @@ use crate::function::Function; use crate::function::Location; use crate::rc::{Array, Ref, RefCountable}; -use super::{MediumLevelILBlock, MediumLevelILInstruction}; +use super::{MediumLevelILBlock, MediumLevelILInstruction, MediumLevelILLiftedInstruction}; pub struct MediumLevelILFunction { pub(crate) handle: *mut BNMediumLevelILFunction, @@ -61,6 +61,10 @@ impl MediumLevelILFunction { MediumLevelILInstruction::new(self.to_owned(), expr_idx) } + pub fn lifted_instruction_from_idx(&self, expr_idx: usize) -> MediumLevelILLiftedInstruction { + self.instruction_from_idx(expr_idx).lift() + } + pub fn instruction_count(&self) -> usize { unsafe { BNGetMediumLevelILInstructionCount(self.handle) } } -- cgit v1.3.1