diff options
| author | Josh Ferrell <josh@vector35.com> | 2025-12-24 16:45:43 -0500 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2025-12-24 16:46:44 -0500 |
| commit | c9b43e1825977c3e6f32fc32938a963c3b3a5b17 (patch) | |
| tree | ec8f9bbf23a0b1b87deb8e3a64b1e665d8cebb7a /rust/src | |
| parent | 9d8d3842128fbddecfd2620ddd76e6b79bb74632 (diff) | |
[Rust API] Add BinaryViewExt.address_comments
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/binary_view.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index 459253b9..1952c780 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -62,7 +62,7 @@ use crate::types::{ use crate::variable::DataVariable; use crate::workflow::Workflow; use crate::{Endianness, BN_FULL_CONFIDENCE}; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use std::ffi::{c_char, c_void, CString}; use std::fmt::{Display, Formatter}; use std::ops::Range; @@ -1686,6 +1686,24 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNRemoveUserDataTag(self.as_ref().handle, addr, tag.handle) } } + fn address_comments(&self) -> BTreeMap<u64, String> { + let mut comment_count = 0; + let mut result = BTreeMap::new(); + let addresses; + unsafe { + let addresses_raw = + BNGetGlobalCommentedAddresses(self.as_ref().handle, &mut comment_count); + addresses = std::slice::from_raw_parts(addresses_raw, comment_count); + } + + for address in addresses { + if let Some(comment) = self.comment_at(*address) { + result.insert(*address, comment); + } + } + result + } + fn comment_at(&self, addr: u64) -> Option<String> { unsafe { let comment_raw = BNGetGlobalCommentForAddress(self.as_ref().handle, addr); |
