Skip to content

Commit bec6531

Browse files
committed
Add HLIL APIs to fetch the root or by instruction index, and expose the operation size in the Rust API
1 parent f193132 commit bec6531

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

rust/src/hlil/function.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use std::hash::{Hash, Hasher};
22

33
use binaryninjacore_sys::BNFreeHighLevelILFunction;
44
use binaryninjacore_sys::BNGetHighLevelILBasicBlockList;
5+
use binaryninjacore_sys::BNGetHighLevelILIndexForInstruction;
56
use binaryninjacore_sys::BNGetHighLevelILInstructionCount;
67
use binaryninjacore_sys::BNGetHighLevelILOwnerFunction;
8+
use binaryninjacore_sys::BNGetHighLevelILRootExpr;
79
use binaryninjacore_sys::BNGetHighLevelILSSAForm;
810
use binaryninjacore_sys::BNHighLevelILFunction;
911
use binaryninjacore_sys::BNNewHighLevelILFunctionReference;
@@ -52,6 +54,29 @@ impl HighLevelILFunction {
5254
self.instruction_from_idx(expr_idx).lift()
5355
}
5456

57+
pub fn instruction_from_instruction_idx(&self, instr_idx: usize) -> HighLevelILInstruction {
58+
HighLevelILInstruction::new(self.as_non_ast(), unsafe {
59+
BNGetHighLevelILIndexForInstruction(self.handle, instr_idx)
60+
})
61+
}
62+
63+
pub fn lifted_instruction_from_instruction_idx(
64+
&self,
65+
instr_idx: usize,
66+
) -> HighLevelILLiftedInstruction {
67+
self.instruction_from_instruction_idx(instr_idx).lift()
68+
}
69+
70+
pub fn root(&self) -> HighLevelILInstruction {
71+
HighLevelILInstruction::new(self.as_ast(), unsafe {
72+
BNGetHighLevelILRootExpr(self.handle)
73+
})
74+
}
75+
76+
pub fn lifted_root(&self) -> HighLevelILLiftedInstruction {
77+
self.root().lift()
78+
}
79+
5580
pub fn instruction_count(&self) -> usize {
5681
unsafe { BNGetHighLevelILInstructionCount(self.handle) }
5782
}
@@ -81,6 +106,22 @@ impl HighLevelILFunction {
81106

82107
unsafe { Array::new(blocks, count, context) }
83108
}
109+
110+
pub fn as_ast(&self) -> Ref<HighLevelILFunction> {
111+
Self {
112+
handle: self.handle,
113+
full_ast: true,
114+
}
115+
.to_owned()
116+
}
117+
118+
pub fn as_non_ast(&self) -> Ref<HighLevelILFunction> {
119+
Self {
120+
handle: self.handle,
121+
full_ast: false,
122+
}
123+
.to_owned()
124+
}
84125
}
85126

86127
impl ToOwned for HighLevelILFunction {

rust/src/hlil/instruction.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct HighLevelILInstruction {
1616
pub function: Ref<HighLevelILFunction>,
1717
pub address: u64,
1818
pub index: usize,
19+
pub size: usize,
1920
pub kind: HighLevelILInstructionKind,
2021
}
2122

@@ -629,6 +630,7 @@ impl HighLevelILInstruction {
629630
function,
630631
address: op.address,
631632
index,
633+
size: op.size,
632634
kind,
633635
}
634636
}
@@ -878,6 +880,7 @@ impl HighLevelILInstruction {
878880
function: self.function.clone(),
879881
address: self.address,
880882
index: self.index,
883+
size: self.size,
881884
kind,
882885
}
883886
}

rust/src/hlil/lift.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct HighLevelILLiftedInstruction {
2424
pub function: Ref<HighLevelILFunction>,
2525
pub address: u64,
2626
pub index: usize,
27+
pub size: usize,
2728
pub kind: HighLevelILLiftedInstructionKind,
2829
}
2930

rust/src/hlil/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::HighLevelILLiftedInstruction;
99
#[derive(Clone, Debug, PartialEq, Eq)]
1010
pub struct GotoLabel {
1111
pub(crate) function: Ref<Function>,
12-
pub(crate) target: u64,
12+
pub target: u64,
1313
}
1414

1515
impl GotoLabel {

0 commit comments

Comments
 (0)