Skip to content

Commit

Permalink
add Function::comments method
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 13, 2024
1 parent a2eb4b2 commit 6f84a87
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ impl Function {
}
}

/// All comments in the function
pub fn comments(&self) -> Array<Comments> {
let mut count = 0;
let lines = unsafe { BNGetCommentedAddresses(self.handle, &mut count) };
unsafe { Array::new(lines, count, self.to_owned()) }
}

pub fn basic_blocks(&self) -> Array<BasicBlock<NativeBlock>> {
unsafe {
let mut count = 0;
Expand Down Expand Up @@ -1470,3 +1477,38 @@ unsafe impl CoreArrayProviderInner for PerformanceInfo {
Guard::new(Self(*raw), context)
}
}

/////////////////
// Comments

// NOTE only exists as Array<Comments>, cant be owned
pub struct Comments {
addr: u64,
comment: BnString,
}

impl Comments {
pub fn address(&self) -> u64 {
self.addr
}
pub fn comment(&self) -> &str {
self.comment.as_str()
}
}

impl CoreArrayProvider for Comments {
type Raw = u64;
type Context = Ref<Function>;
type Wrapped<'a> = Comments;
}
unsafe impl CoreArrayProviderInner for Comments {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeAddressList(raw);
}
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, function: &'a Self::Context) -> Self::Wrapped<'a> {
Comments {
addr: *raw,
comment: function.comment_at(*raw),
}
}
}

0 comments on commit 6f84a87

Please sign in to comment.