diff options
| author | Mason Reed <mason@vector35.com> | 2024-10-28 21:18:10 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2024-10-28 21:21:55 -0400 |
| commit | 08f1c49f0cb7f74d0f50dcf60289e974ae9d5c3a (patch) | |
| tree | 1702b3b5828dfb581bb6259040c35bf163ba764f /rust/src/binaryview.rs | |
| parent | 2f17bf7439e2339b4ead7470cafd033875f9837c (diff) | |
Rust: Add `BinaryViewExt::get_code_refs_from` api
Diffstat (limited to 'rust/src/binaryview.rs')
| -rw-r--r-- | rust/src/binaryview.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 9825f2de..226e70de 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -1307,6 +1307,25 @@ pub trait BinaryViewExt: BinaryViewBase { } } + /// Retrieves a list of addresses pointed to by a given address. + fn get_code_refs_from(&self, addr: u64, func: Option<&Function>) -> Vec<u64> { + unsafe { + let mut count = 0; + // TODO: We could have done a [CodeReference] however it seems to be poorly written. + // TODO: It uses manually drop on a ref that only gets dropped in the array, insane behavior. + // TODO: For now just construct it manually. + let mut src = BNReferenceSource { + func: func.map(|f| f.handle).unwrap_or(std::ptr::null_mut()), + arch: func.map(|f| f.arch().0).unwrap_or(std::ptr::null_mut()), + addr, + }; + let addresses = BNGetCodeReferencesFrom(self.as_ref().handle, &mut src, &mut count); + let res = std::slice::from_raw_parts(addresses, count).to_vec(); + BNFreeAddressList(addresses); + res + } + } + /// Retrieves a list of [CodeReference]s pointing into a given [Range]. fn get_code_refs_in_range(&self, range: Range<u64>) -> Array<CodeReference> { unsafe { |
