|
14 | 14 |
|
15 | 15 | //! Interfaces for creating and displaying pretty CFGs in Binary Ninja.
|
16 | 16 |
|
17 |
| -use crate::disassembly::DisassemblyTextLine; |
18 |
| -use crate::rc::*; |
19 | 17 | use binaryninjacore_sys::*;
|
20 | 18 |
|
21 |
| -use crate::basic_block::{BasicBlock, BlockContext}; |
22 |
| -use crate::function::HighlightColor; |
23 | 19 | use crate::high_level_il::HighLevelILFunction;
|
24 | 20 | use crate::low_level_il::RegularLowLevelILFunction;
|
25 | 21 | use crate::medium_level_il::MediumLevelILFunction;
|
| 22 | +use crate::rc::*; |
26 | 23 | use crate::render_layer::CoreRenderLayer;
|
27 | 24 |
|
| 25 | +pub mod edge; |
| 26 | +pub mod node; |
| 27 | + |
| 28 | +pub use edge::FlowGraphEdge; |
| 29 | +pub use node::FlowGraphNode; |
| 30 | + |
28 | 31 | pub type BranchType = BNBranchType;
|
29 | 32 | pub type EdgePenStyle = BNEdgePenStyle;
|
30 | 33 | pub type ThemeColor = BNThemeColor;
|
@@ -162,168 +165,3 @@ impl ToOwned for FlowGraph {
|
162 | 165 | unsafe { RefCountable::inc_ref(self) }
|
163 | 166 | }
|
164 | 167 | }
|
165 |
| - |
166 |
| -#[derive(PartialEq, Eq, Hash)] |
167 |
| -pub struct FlowGraphNode { |
168 |
| - pub(crate) handle: *mut BNFlowGraphNode, |
169 |
| -} |
170 |
| - |
171 |
| -impl FlowGraphNode { |
172 |
| - pub(crate) unsafe fn from_raw(raw: *mut BNFlowGraphNode) -> Self { |
173 |
| - Self { handle: raw } |
174 |
| - } |
175 |
| - |
176 |
| - pub(crate) unsafe fn ref_from_raw(raw: *mut BNFlowGraphNode) -> Ref<Self> { |
177 |
| - Ref::new(Self { handle: raw }) |
178 |
| - } |
179 |
| - |
180 |
| - pub fn new(graph: &FlowGraph) -> Ref<Self> { |
181 |
| - unsafe { FlowGraphNode::ref_from_raw(BNCreateFlowGraphNode(graph.handle)) } |
182 |
| - } |
183 |
| - |
184 |
| - pub fn basic_block<C: BlockContext>(&self, context: C) -> Option<Ref<BasicBlock<C>>> { |
185 |
| - let block_ptr = unsafe { BNGetFlowGraphBasicBlock(self.handle) }; |
186 |
| - if block_ptr.is_null() { |
187 |
| - return None; |
188 |
| - } |
189 |
| - Some(unsafe { BasicBlock::ref_from_raw(block_ptr, context) }) |
190 |
| - } |
191 |
| - |
192 |
| - pub fn set_basic_block<C: BlockContext>(&self, block: Option<&BasicBlock<C>>) { |
193 |
| - match block { |
194 |
| - Some(block) => unsafe { BNSetFlowGraphBasicBlock(self.handle, block.handle) }, |
195 |
| - None => unsafe { BNSetFlowGraphBasicBlock(self.handle, std::ptr::null_mut()) }, |
196 |
| - } |
197 |
| - } |
198 |
| - |
199 |
| - pub fn lines(&self) -> Array<DisassemblyTextLine> { |
200 |
| - let mut count = 0; |
201 |
| - let result = unsafe { BNGetFlowGraphNodeLines(self.handle, &mut count) }; |
202 |
| - assert!(!result.is_null()); |
203 |
| - unsafe { Array::new(result, count, ()) } |
204 |
| - } |
205 |
| - |
206 |
| - pub fn set_lines(&self, lines: impl IntoIterator<Item = DisassemblyTextLine>) { |
207 |
| - // NOTE: This will create allocations and increment tag refs, we must call DisassemblyTextLine::free_raw |
208 |
| - let mut raw_lines: Vec<BNDisassemblyTextLine> = lines |
209 |
| - .into_iter() |
210 |
| - .map(DisassemblyTextLine::into_raw) |
211 |
| - .collect(); |
212 |
| - unsafe { |
213 |
| - BNSetFlowGraphNodeLines(self.handle, raw_lines.as_mut_ptr(), raw_lines.len()); |
214 |
| - for raw_line in raw_lines { |
215 |
| - DisassemblyTextLine::free_raw(raw_line); |
216 |
| - } |
217 |
| - } |
218 |
| - } |
219 |
| - |
220 |
| - /// Returns the graph position of the node in X, Y form. |
221 |
| - pub fn position(&self) -> (i32, i32) { |
222 |
| - let pos_x = unsafe { BNGetFlowGraphNodeX(self.handle) }; |
223 |
| - let pos_y = unsafe { BNGetFlowGraphNodeY(self.handle) }; |
224 |
| - (pos_x, pos_y) |
225 |
| - } |
226 |
| - |
227 |
| - /// Sets the graph position of the node. |
228 |
| - pub fn set_position(&self, x: i32, y: i32) { |
229 |
| - unsafe { BNFlowGraphNodeSetX(self.handle, x) }; |
230 |
| - unsafe { BNFlowGraphNodeSetX(self.handle, y) }; |
231 |
| - } |
232 |
| - |
233 |
| - pub fn highlight_color(&self) -> HighlightColor { |
234 |
| - let raw = unsafe { BNGetFlowGraphNodeHighlight(self.handle) }; |
235 |
| - HighlightColor::from(raw) |
236 |
| - } |
237 |
| - |
238 |
| - pub fn set_highlight_color(&self, highlight: HighlightColor) { |
239 |
| - unsafe { BNSetFlowGraphNodeHighlight(self.handle, highlight.into()) }; |
240 |
| - } |
241 |
| - |
242 |
| - // TODO: Add getters and setters for edges |
243 |
| - |
244 |
| - pub fn add_outgoing_edge( |
245 |
| - &self, |
246 |
| - type_: BranchType, |
247 |
| - target: &FlowGraphNode, |
248 |
| - edge_style: EdgeStyle, |
249 |
| - ) { |
250 |
| - unsafe { |
251 |
| - BNAddFlowGraphNodeOutgoingEdge(self.handle, type_, target.handle, edge_style.into()) |
252 |
| - } |
253 |
| - } |
254 |
| -} |
255 |
| - |
256 |
| -unsafe impl RefCountable for FlowGraphNode { |
257 |
| - unsafe fn inc_ref(handle: &Self) -> Ref<Self> { |
258 |
| - Ref::new(Self { |
259 |
| - handle: BNNewFlowGraphNodeReference(handle.handle), |
260 |
| - }) |
261 |
| - } |
262 |
| - |
263 |
| - unsafe fn dec_ref(handle: &Self) { |
264 |
| - BNFreeFlowGraphNode(handle.handle); |
265 |
| - } |
266 |
| -} |
267 |
| - |
268 |
| -impl ToOwned for FlowGraphNode { |
269 |
| - type Owned = Ref<Self>; |
270 |
| - |
271 |
| - fn to_owned(&self) -> Self::Owned { |
272 |
| - unsafe { RefCountable::inc_ref(self) } |
273 |
| - } |
274 |
| -} |
275 |
| - |
276 |
| -impl CoreArrayProvider for FlowGraphNode { |
277 |
| - type Raw = *mut BNFlowGraphNode; |
278 |
| - type Context = (); |
279 |
| - type Wrapped<'a> = Guard<'a, FlowGraphNode>; |
280 |
| -} |
281 |
| - |
282 |
| -unsafe impl CoreArrayProviderInner for FlowGraphNode { |
283 |
| - unsafe fn free(raw: *mut Self::Raw, count: usize, _: &Self::Context) { |
284 |
| - BNFreeFlowGraphNodeList(raw, count); |
285 |
| - } |
286 |
| - |
287 |
| - unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { |
288 |
| - Guard::new(Self::from_raw(*raw), context) |
289 |
| - } |
290 |
| -} |
291 |
| - |
292 |
| -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
293 |
| -pub struct EdgeStyle { |
294 |
| - style: EdgePenStyle, |
295 |
| - width: usize, |
296 |
| - color: ThemeColor, |
297 |
| -} |
298 |
| - |
299 |
| -impl EdgeStyle { |
300 |
| - pub fn new(style: EdgePenStyle, width: usize, color: ThemeColor) -> Self { |
301 |
| - Self { |
302 |
| - style, |
303 |
| - width, |
304 |
| - color, |
305 |
| - } |
306 |
| - } |
307 |
| -} |
308 |
| - |
309 |
| -impl Default for EdgeStyle { |
310 |
| - fn default() -> Self { |
311 |
| - Self::new(EdgePenStyle::SolidLine, 0, ThemeColor::AddressColor) |
312 |
| - } |
313 |
| -} |
314 |
| - |
315 |
| -impl From<BNEdgeStyle> for EdgeStyle { |
316 |
| - fn from(style: BNEdgeStyle) -> Self { |
317 |
| - Self::new(style.style, style.width, style.color) |
318 |
| - } |
319 |
| -} |
320 |
| - |
321 |
| -impl From<EdgeStyle> for BNEdgeStyle { |
322 |
| - fn from(style: EdgeStyle) -> Self { |
323 |
| - Self { |
324 |
| - style: style.style, |
325 |
| - width: style.width, |
326 |
| - color: style.color, |
327 |
| - } |
328 |
| - } |
329 |
| -} |
0 commit comments