diff options
| author | Mason Reed <mason@vector35.com> | 2025-06-22 18:56:18 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-07-02 01:56:54 -0400 |
| commit | 53d7da0b30a0dca456659d8cd8a5cdab52ca2a79 (patch) | |
| tree | db55fac6458702e653ff4a6f339c13e94e45929a /rust | |
| parent | d9a66c30bb5df5275fbcad37fb4e4df218819f44 (diff) | |
[Rust] Misc `interaction::report` improvements
- Add `Debug` impl to `ReportCollection`
- Fix flow graph related api's not being optional
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/interaction/report.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/rust/src/interaction/report.rs b/rust/src/interaction/report.rs index 415845db..c362e041 100644 --- a/rust/src/interaction/report.rs +++ b/rust/src/interaction/report.rs @@ -1,3 +1,4 @@ +use std::fmt::Debug; use std::ptr::NonNull; use binaryninjacore_sys::*; @@ -68,9 +69,12 @@ impl ReportCollection { unsafe { BnString::into_string(raw) } } - fn flow_graph(&self, i: usize) -> Ref<FlowGraph> { + fn flow_graph(&self, i: usize) -> Option<Ref<FlowGraph>> { let raw = unsafe { BNGetReportFlowGraph(self.handle.as_ptr(), i) }; - unsafe { FlowGraph::ref_from_raw(raw) } + match raw.is_null() { + false => Some(unsafe { FlowGraph::ref_from_raw(raw) }), + true => None, + } } pub fn add_text(&self, view: &BinaryView, title: &str, contents: &str) { @@ -137,6 +141,14 @@ impl ReportCollection { } } +impl Debug for ReportCollection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ReportCollection") + .field("count", &self.count()) + .finish() + } +} + unsafe impl RefCountable for ReportCollection { unsafe fn inc_ref(handle: &Self) -> Ref<Self> { let raw = unsafe { BNNewReportCollectionReference(handle.handle.as_ptr()) }; @@ -237,7 +249,9 @@ pub struct ReportFlowGraph<'a>(ReportInner<'a>); impl ReportFlowGraph<'_> { pub fn flow_graph(&self) -> Ref<FlowGraph> { - self.0.flow_graph() + self.0 + .flow_graph() + .expect("Flow graph not available for flow graph report!") } pub fn update_report_flow_graph(&self, graph: &FlowGraph) { @@ -271,7 +285,7 @@ impl ReportInner<'_> { self.collection.plain_text(self.index) } - fn flow_graph(&self) -> Ref<FlowGraph> { + fn flow_graph(&self) -> Option<Ref<FlowGraph>> { self.collection.flow_graph(self.index) } |
