Skip to content

Commit 81a5c89

Browse files
committed
Add BinaryViewExt::comment_at and BinaryViewExt::set_comment_at
How did we not have this before?
1 parent 48f9c54 commit 81a5c89

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

rust/src/binary_view.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,31 @@ pub trait BinaryViewExt: BinaryViewBase {
12221222
unsafe { BNRemoveUserDataTag(self.as_ref().handle, addr, tag.handle) }
12231223
}
12241224

1225+
fn comment_at(&self, addr: u64) -> Option<BnString> {
1226+
unsafe {
1227+
let comment_raw = BNGetGlobalCommentForAddress(self.as_ref().handle, addr);
1228+
match comment_raw.is_null() {
1229+
false => Some(BnString::from_raw(comment_raw)),
1230+
true => None,
1231+
}
1232+
}
1233+
}
1234+
1235+
/// Sets a comment for the [`BinaryView`] at the address specified.
1236+
///
1237+
/// NOTE: This is different from setting a comment at the function-level. To set a comment in a
1238+
/// function use [`Function::set_comment_at`]
1239+
fn set_comment_at(&self, addr: u64, comment: impl BnStrCompatible) {
1240+
let comment_raw = comment.into_bytes_with_nul();
1241+
unsafe {
1242+
BNSetGlobalCommentForAddress(
1243+
self.as_ref().handle,
1244+
addr,
1245+
comment_raw.as_ref().as_ptr() as *const c_char,
1246+
)
1247+
}
1248+
}
1249+
12251250
/// Retrieves a list of the next disassembly lines.
12261251
///
12271252
/// Retrieves an [`Array`] over [`LinearDisassemblyLine`] objects for the

rust/src/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,6 +2768,7 @@ impl Default for HighlightColor {
27682768
}
27692769
}
27702770

2771+
// TODO: Move this out of function, so we can use it in the binary view
27712772
// NOTE only exists as Array<Comments>, cant be owned
27722773
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
27732774
pub struct Comment {

0 commit comments

Comments
 (0)