diff options
| author | Mason Reed <mason@vector35.com> | 2025-02-14 23:36:24 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-02-24 20:08:01 -0500 |
| commit | e36dcc8d4ea833d0731cde78bd65f2ca7e030a0d (patch) | |
| tree | f250b14af0d7e13795234e444ddceb1be2ab8fda /rust/src | |
| parent | a87f4888eddf804baed4df3de3ac81d737d78ed3 (diff) | |
Add `BinaryViewExt::comment_at` and `BinaryViewExt::set_comment_at`
How did we not have this before?
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/binary_view.rs | 25 | ||||
| -rw-r--r-- | rust/src/function.rs | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index aa5f47f5..aa7c65e6 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -1222,6 +1222,31 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNRemoveUserDataTag(self.as_ref().handle, addr, tag.handle) } } + fn comment_at(&self, addr: u64) -> Option<BnString> { + unsafe { + let comment_raw = BNGetGlobalCommentForAddress(self.as_ref().handle, addr); + match comment_raw.is_null() { + false => Some(BnString::from_raw(comment_raw)), + true => None, + } + } + } + + /// Sets a comment for the [`BinaryView`] at the address specified. + /// + /// NOTE: This is different from setting a comment at the function-level. To set a comment in a + /// function use [`Function::set_comment_at`] + fn set_comment_at(&self, addr: u64, comment: impl BnStrCompatible) { + let comment_raw = comment.into_bytes_with_nul(); + unsafe { + BNSetGlobalCommentForAddress( + self.as_ref().handle, + addr, + comment_raw.as_ref().as_ptr() as *const c_char, + ) + } + } + /// Retrieves a list of the next disassembly lines. /// /// Retrieves an [`Array`] over [`LinearDisassemblyLine`] objects for the diff --git a/rust/src/function.rs b/rust/src/function.rs index b438520a..66f71e5f 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -2768,6 +2768,7 @@ impl Default for HighlightColor { } } +// TODO: Move this out of function, so we can use it in the binary view // NOTE only exists as Array<Comments>, cant be owned #[derive(Clone, Debug, Hash, Eq, PartialEq)] pub struct Comment { |
