diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-02-02 23:30:56 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-02-06 21:41:07 -0500 |
| commit | 4f18ac5a6b187e0e45b9daf21b3a648ad4a170a8 (patch) | |
| tree | 6464f79c5ecf8869ef4fb3a2a42bbc2f72d250b0 /rust/src/function.rs | |
| parent | b53902e970519b57f09963b22e1c0259640b5e65 (diff) | |
Rust API: Add `function::address_ranges`
Diffstat (limited to 'rust/src/function.rs')
| -rw-r--r-- | rust/src/function.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/rust/src/function.rs b/rust/src/function.rs index aaefe5cd..2eed562e 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::fmt; +use std::{fmt, mem}; use binaryninjacore_sys::*; @@ -156,6 +156,15 @@ impl Function { unsafe { BNGetFunctionHighestAddress(self.handle) } } + pub fn address_ranges(&self) -> Array<AddressRange> { + unsafe { + let mut count = 0; + let addresses = BNGetFunctionAddressRanges(self.handle, &mut count); + + Array::new(addresses, count, ()) + } + } + pub fn comment(&self) -> BnString { unsafe { BnString::from_raw(BNGetFunctionComment(self.handle)) } } @@ -288,3 +297,37 @@ unsafe impl<'a> CoreArrayWrapper<'a> for Function { Guard::new(Function { handle: *raw }, context) } } + +///////////////// +// AddressRange + +#[repr(transparent)] +pub struct AddressRange(pub(crate) BNAddressRange); + +impl AddressRange { + pub fn start(&self) -> u64 { + self.0.start + } + + pub fn end(&self) -> u64 { + self.0.end + } +} + +impl CoreArrayProvider for AddressRange { + type Raw = BNAddressRange; + type Context = (); +} +unsafe impl CoreOwnedArrayProvider for AddressRange { + unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { + BNFreeAddressRanges(raw); + } +} + +unsafe impl<'a> CoreArrayWrapper<'a> for AddressRange { + type Wrapped = &'a AddressRange; + + unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { + mem::transmute(raw) + } +}
\ No newline at end of file |
