From e36dcc8d4ea833d0731cde78bd65f2ca7e030a0d Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 14 Feb 2025 23:36:24 -0500 Subject: Add `BinaryViewExt::comment_at` and `BinaryViewExt::set_comment_at` How did we not have this before? --- rust/src/binary_view.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'rust/src/binary_view.rs') 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 { + 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 -- cgit v1.3.1