Skip to content

Commit f193132

Browse files
committed
Add MLIL APIs for getting by instruction index, and expose the operation size in the Rust API
1 parent 2cd83c7 commit f193132

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

rust/src/mlil/function.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::hash::{Hash, Hasher};
22

33
use binaryninjacore_sys::BNFreeMediumLevelILFunction;
44
use binaryninjacore_sys::BNGetMediumLevelILBasicBlockList;
5+
use binaryninjacore_sys::BNGetMediumLevelILIndexForInstruction;
56
use binaryninjacore_sys::BNGetMediumLevelILInstructionCount;
67
use binaryninjacore_sys::BNGetMediumLevelILOwnerFunction;
78
use binaryninjacore_sys::BNGetMediumLevelILSSAForm;
@@ -65,6 +66,19 @@ impl MediumLevelILFunction {
6566
self.instruction_from_idx(expr_idx).lift()
6667
}
6768

69+
pub fn instruction_from_instruction_idx(&self, instr_idx: usize) -> MediumLevelILInstruction {
70+
MediumLevelILInstruction::new(self.to_owned(), unsafe {
71+
BNGetMediumLevelILIndexForInstruction(self.handle, instr_idx)
72+
})
73+
}
74+
75+
pub fn lifted_instruction_from_instruction_idx(
76+
&self,
77+
instr_idx: usize,
78+
) -> MediumLevelILLiftedInstruction {
79+
self.instruction_from_instruction_idx(instr_idx).lift()
80+
}
81+
6882
pub fn instruction_count(&self) -> usize {
6983
unsafe { BNGetMediumLevelILInstructionCount(self.handle) }
7084
}

rust/src/mlil/instruction.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct MediumLevelILInstruction {
1818
pub function: Ref<MediumLevelILFunction>,
1919
pub address: u64,
2020
pub index: usize,
21+
pub size: usize,
2122
pub kind: MediumLevelILInstructionKind,
2223
}
2324

@@ -704,7 +705,12 @@ impl MediumLevelILInstruction {
704705
}),
705706
// translated directly into a list for Expression or Variables
706707
// TODO MLIL_MEMORY_INTRINSIC_SSA needs to be handled properly
707-
MLIL_CALL_OUTPUT | MLIL_CALL_PARAM | MLIL_CALL_PARAM_SSA | MLIL_CALL_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_SSA => {
708+
MLIL_CALL_OUTPUT
709+
| MLIL_CALL_PARAM
710+
| MLIL_CALL_PARAM_SSA
711+
| MLIL_CALL_OUTPUT_SSA
712+
| MLIL_MEMORY_INTRINSIC_OUTPUT_SSA
713+
| MLIL_MEMORY_INTRINSIC_SSA => {
708714
unreachable!()
709715
}
710716
};
@@ -713,6 +719,7 @@ impl MediumLevelILInstruction {
713719
function,
714720
address: op.address,
715721
index,
722+
size: op.size,
716723
kind,
717724
}
718725
}
@@ -1022,6 +1029,7 @@ impl MediumLevelILInstruction {
10221029
function: self.function.clone(),
10231030
address: self.address,
10241031
index: self.index,
1032+
size: self.size,
10251033
kind,
10261034
}
10271035
}

rust/src/mlil/lift.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct MediumLevelILLiftedInstruction {
2727
pub function: Ref<MediumLevelILFunction>,
2828
pub address: u64,
2929
pub index: usize,
30+
pub size: usize,
3031
pub kind: MediumLevelILLiftedInstructionKind,
3132
}
3233

0 commit comments

Comments
 (0)