Skip to content

Commit 8cd9b51

Browse files
committed
[Rust] Misc interaction::report improvements
- Add `Debug` impl to `ReportCollection` - Fix flow graph related api's not being optional
1 parent c3be6eb commit 8cd9b51

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

rust/src/interaction/report.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Debug;
12
use std::ptr::NonNull;
23

34
use binaryninjacore_sys::*;
@@ -68,9 +69,12 @@ impl ReportCollection {
6869
unsafe { BnString::into_string(raw) }
6970
}
7071

71-
fn flow_graph(&self, i: usize) -> Ref<FlowGraph> {
72+
fn flow_graph(&self, i: usize) -> Option<Ref<FlowGraph>> {
7273
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+
}
7478
}
7579

7680
pub fn add_text(&self, view: &BinaryView, title: &str, contents: &str) {
@@ -137,6 +141,14 @@ impl ReportCollection {
137141
}
138142
}
139143

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+
140152
unsafe impl RefCountable for ReportCollection {
141153
unsafe fn inc_ref(handle: &Self) -> Ref<Self> {
142154
let raw = unsafe { BNNewReportCollectionReference(handle.handle.as_ptr()) };
@@ -237,7 +249,9 @@ pub struct ReportFlowGraph<'a>(ReportInner<'a>);
237249

238250
impl ReportFlowGraph<'_> {
239251
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!")
241255
}
242256

243257
pub fn update_report_flow_graph(&self, graph: &FlowGraph) {
@@ -271,7 +285,7 @@ impl ReportInner<'_> {
271285
self.collection.plain_text(self.index)
272286
}
273287

274-
fn flow_graph(&self) -> Ref<FlowGraph> {
288+
fn flow_graph(&self) -> Option<Ref<FlowGraph>> {
275289
self.collection.flow_graph(self.index)
276290
}
277291

0 commit comments

Comments
 (0)