Skip to content

Commit a370cf0

Browse files
committed
Add ability to query IL functions in FlowGraph for Rust API
1 parent c8fbd0f commit a370cf0

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

rust/src/flowgraph.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
//! Interfaces for creating and displaying pretty CFGs in Binary Ninja.
1616
17+
use crate::architecture::CoreArchitecture;
1718
use crate::disassembly::DisassemblyTextLine;
18-
use binaryninjacore_sys::*;
19-
2019
use crate::rc::*;
20+
use binaryninjacore_sys::*;
2121

2222
use crate::basic_block::{BasicBlock, BlockContext};
2323
use crate::function::HighlightColor;
24+
use crate::high_level_il::HighLevelILFunction;
25+
use crate::low_level_il::RegularLowLevelILFunction;
26+
use crate::medium_level_il::MediumLevelILFunction;
2427
use crate::render_layer::CoreRenderLayer;
2528

2629
pub type BranchType = BNBranchType;
@@ -52,6 +55,40 @@ impl FlowGraph {
5255
unsafe { Array::new(nodes_ptr, count, ()) }
5356
}
5457

58+
pub fn low_level_il(&self) -> Result<Ref<RegularLowLevelILFunction<CoreArchitecture>>, ()> {
59+
unsafe {
60+
let llil_ptr = BNGetFlowGraphLowLevelILFunction(self.handle);
61+
let func_ptr = BNGetLowLevelILOwnerFunction(llil_ptr);
62+
let arch_ptr = BNGetFunctionArchitecture(func_ptr);
63+
let arch = CoreArchitecture::from_raw(arch_ptr);
64+
BNFreeFunction(func_ptr);
65+
match llil_ptr.is_null() {
66+
false => Ok(RegularLowLevelILFunction::ref_from_raw(arch, llil_ptr)),
67+
true => Err(()),
68+
}
69+
}
70+
}
71+
72+
pub fn medium_level_il(&self) -> Result<Ref<MediumLevelILFunction>, ()> {
73+
unsafe {
74+
let mlil_ptr = BNGetFlowGraphMediumLevelILFunction(self.handle);
75+
match mlil_ptr.is_null() {
76+
false => Ok(MediumLevelILFunction::ref_from_raw(mlil_ptr)),
77+
true => Err(()),
78+
}
79+
}
80+
}
81+
82+
pub fn high_level_il(&self, full_ast: bool) -> Result<Ref<HighLevelILFunction>, ()> {
83+
unsafe {
84+
let hlil_ptr = BNGetFlowGraphHighLevelILFunction(self.handle);
85+
match hlil_ptr.is_null() {
86+
false => Ok(HighLevelILFunction::ref_from_raw(hlil_ptr, full_ast)),
87+
true => Err(()),
88+
}
89+
}
90+
}
91+
5592
pub fn get_node(&self, i: usize) -> Option<Ref<FlowGraphNode>> {
5693
let node_ptr = unsafe { BNGetFlowGraphNode(self.handle, i) };
5794
if node_ptr.is_null() {

0 commit comments

Comments
 (0)