|
14 | 14 |
|
15 | 15 | //! Interfaces for creating and displaying pretty CFGs in Binary Ninja. |
16 | 16 |
|
| 17 | +use crate::architecture::CoreArchitecture; |
17 | 18 | use crate::disassembly::DisassemblyTextLine; |
18 | | -use binaryninjacore_sys::*; |
19 | | - |
20 | 19 | use crate::rc::*; |
| 20 | +use binaryninjacore_sys::*; |
21 | 21 |
|
22 | 22 | use crate::basic_block::{BasicBlock, BlockContext}; |
23 | 23 | 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; |
24 | 27 | use crate::render_layer::CoreRenderLayer; |
25 | 28 |
|
26 | 29 | pub type BranchType = BNBranchType; |
@@ -52,6 +55,40 @@ impl FlowGraph { |
52 | 55 | unsafe { Array::new(nodes_ptr, count, ()) } |
53 | 56 | } |
54 | 57 |
|
| 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 | + |
55 | 92 | pub fn get_node(&self, i: usize) -> Option<Ref<FlowGraphNode>> { |
56 | 93 | let node_ptr = unsafe { BNGetFlowGraphNode(self.handle, i) }; |
57 | 94 | if node_ptr.is_null() { |
|
0 commit comments