Skip to content

Commit

Permalink
Add MLIL APIs for getting by instruction index, and expose the operat…
Browse files Browse the repository at this point in the history
…ion size in the Rust API
  • Loading branch information
D0ntPanic committed Apr 30, 2024
1 parent 2cd83c7 commit f193132
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions rust/src/mlil/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::hash::{Hash, Hasher};

use binaryninjacore_sys::BNFreeMediumLevelILFunction;
use binaryninjacore_sys::BNGetMediumLevelILBasicBlockList;
use binaryninjacore_sys::BNGetMediumLevelILIndexForInstruction;
use binaryninjacore_sys::BNGetMediumLevelILInstructionCount;
use binaryninjacore_sys::BNGetMediumLevelILOwnerFunction;
use binaryninjacore_sys::BNGetMediumLevelILSSAForm;
Expand Down Expand Up @@ -65,6 +66,19 @@ impl MediumLevelILFunction {
self.instruction_from_idx(expr_idx).lift()
}

pub fn instruction_from_instruction_idx(&self, instr_idx: usize) -> MediumLevelILInstruction {
MediumLevelILInstruction::new(self.to_owned(), unsafe {
BNGetMediumLevelILIndexForInstruction(self.handle, instr_idx)
})
}

pub fn lifted_instruction_from_instruction_idx(
&self,
instr_idx: usize,
) -> MediumLevelILLiftedInstruction {
self.instruction_from_instruction_idx(instr_idx).lift()
}

pub fn instruction_count(&self) -> usize {
unsafe { BNGetMediumLevelILInstructionCount(self.handle) }
}
Expand Down
10 changes: 9 additions & 1 deletion rust/src/mlil/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct MediumLevelILInstruction {
pub function: Ref<MediumLevelILFunction>,
pub address: u64,
pub index: usize,
pub size: usize,
pub kind: MediumLevelILInstructionKind,
}

Expand Down Expand Up @@ -704,7 +705,12 @@ impl MediumLevelILInstruction {
}),
// translated directly into a list for Expression or Variables
// TODO MLIL_MEMORY_INTRINSIC_SSA needs to be handled properly
MLIL_CALL_OUTPUT | MLIL_CALL_PARAM | MLIL_CALL_PARAM_SSA | MLIL_CALL_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_SSA => {
MLIL_CALL_OUTPUT
| MLIL_CALL_PARAM
| MLIL_CALL_PARAM_SSA
| MLIL_CALL_OUTPUT_SSA
| MLIL_MEMORY_INTRINSIC_OUTPUT_SSA
| MLIL_MEMORY_INTRINSIC_SSA => {
unreachable!()
}
};
Expand All @@ -713,6 +719,7 @@ impl MediumLevelILInstruction {
function,
address: op.address,
index,
size: op.size,
kind,
}
}
Expand Down Expand Up @@ -1022,6 +1029,7 @@ impl MediumLevelILInstruction {
function: self.function.clone(),
address: self.address,
index: self.index,
size: self.size,
kind,
}
}
Expand Down
1 change: 1 addition & 0 deletions rust/src/mlil/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct MediumLevelILLiftedInstruction {
pub function: Ref<MediumLevelILFunction>,
pub address: u64,
pub index: usize,
pub size: usize,
pub kind: MediumLevelILLiftedInstructionKind,
}

Expand Down

0 comments on commit f193132

Please sign in to comment.