|
| 1 | +use std::fmt::Debug; |
1 | 2 | use std::ptr::NonNull; |
2 | 3 |
|
3 | 4 | use binaryninjacore_sys::*; |
@@ -68,9 +69,12 @@ impl ReportCollection { |
68 | 69 | unsafe { BnString::into_string(raw) } |
69 | 70 | } |
70 | 71 |
|
71 | | - fn flow_graph(&self, i: usize) -> Ref<FlowGraph> { |
| 72 | + fn flow_graph(&self, i: usize) -> Option<Ref<FlowGraph>> { |
72 | 73 | let raw = unsafe { BNGetReportFlowGraph(self.handle.as_ptr(), i) }; |
73 | | - unsafe { FlowGraph::ref_from_raw(raw) } |
| 74 | + match raw.is_null() { |
| 75 | + false => Some(unsafe { FlowGraph::ref_from_raw(raw) }), |
| 76 | + true => None, |
| 77 | + } |
74 | 78 | } |
75 | 79 |
|
76 | 80 | pub fn add_text(&self, view: &BinaryView, title: &str, contents: &str) { |
@@ -137,6 +141,14 @@ impl ReportCollection { |
137 | 141 | } |
138 | 142 | } |
139 | 143 |
|
| 144 | +impl Debug for ReportCollection { |
| 145 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 146 | + f.debug_struct("ReportCollection") |
| 147 | + .field("count", &self.count()) |
| 148 | + .finish() |
| 149 | + } |
| 150 | +} |
| 151 | + |
140 | 152 | unsafe impl RefCountable for ReportCollection { |
141 | 153 | unsafe fn inc_ref(handle: &Self) -> Ref<Self> { |
142 | 154 | let raw = unsafe { BNNewReportCollectionReference(handle.handle.as_ptr()) }; |
@@ -237,7 +249,9 @@ pub struct ReportFlowGraph<'a>(ReportInner<'a>); |
237 | 249 |
|
238 | 250 | impl ReportFlowGraph<'_> { |
239 | 251 | pub fn flow_graph(&self) -> Ref<FlowGraph> { |
240 | | - self.0.flow_graph() |
| 252 | + self.0 |
| 253 | + .flow_graph() |
| 254 | + .expect("Flow graph not available for flow graph report!") |
241 | 255 | } |
242 | 256 |
|
243 | 257 | pub fn update_report_flow_graph(&self, graph: &FlowGraph) { |
@@ -271,7 +285,7 @@ impl ReportInner<'_> { |
271 | 285 | self.collection.plain_text(self.index) |
272 | 286 | } |
273 | 287 |
|
274 | | - fn flow_graph(&self) -> Ref<FlowGraph> { |
| 288 | + fn flow_graph(&self) -> Option<Ref<FlowGraph>> { |
275 | 289 | self.collection.flow_graph(self.index) |
276 | 290 | } |
277 | 291 |
|
|
0 commit comments