diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2024-01-03 15:56:01 -0700 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2024-01-04 12:42:14 -0700 |
| commit | 7e8de24c479672261b8a5c9911cac8800bad180b (patch) | |
| tree | 6992a8a6f59a46c4be93f7a4693b52fc871fbfce /rust/src | |
| parent | a9cfac7ff14d93ff22092366f99eb2dd3213ea7e (diff) | |
Add GetRelocationsAt API
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/binaryview.rs | 9 | ||||
| -rw-r--r-- | rust/src/relocation.rs | 20 |
2 files changed, 28 insertions, 1 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index d6916e2c..9bcbbec2 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -42,6 +42,7 @@ use crate::linearview::LinearDisassemblyLine; use crate::linearview::LinearViewCursor; use crate::metadata::Metadata; use crate::platform::Platform; +use crate::relocation::Relocation; use crate::section::{Section, SectionBuilder}; use crate::segment::{Segment, SegmentBuilder}; use crate::settings::Settings; @@ -1272,6 +1273,14 @@ pub trait BinaryViewExt: BinaryViewBase { Array::new(handle, count, ()) } } + + fn get_relocations_at(&self, addr: u64) -> Array<Relocation> { + unsafe { + let mut count = 0; + let handle = BNGetRelocationsAt(self.as_ref().handle, addr, &mut count); + Array::new(handle, count, ()) + } + } } impl<T: BinaryViewBase> BinaryViewExt for T {} diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs index cb7e4e3d..7be7861d 100644 --- a/rust/src/relocation.rs +++ b/rust/src/relocation.rs @@ -3,7 +3,7 @@ use crate::{ architecture::{Architecture, CoreArchitecture}, binaryview::BinaryView, llil, - rc::{Ref, RefCountable}, + rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable}, symbol::Symbol, }; use binaryninjacore_sys::*; @@ -210,6 +210,24 @@ impl Relocation { } } +impl CoreArrayProvider for Relocation { + type Raw = *mut BNRelocation; + type Context = (); +} + +unsafe impl CoreOwnedArrayProvider for Relocation { + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { + BNFreeRelocationList(raw, count); + } +} + +unsafe impl<'a> CoreArrayWrapper<'a> for Relocation { + type Wrapped = Relocation; + unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { + Relocation(*raw) + } +} + pub trait RelocationHandler: 'static + Sized + AsRef<CoreRelocationHandler> { type Handle: Borrow<Self>; |
