From 7e8de24c479672261b8a5c9911cac8800bad180b Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 3 Jan 2024 15:56:01 -0700 Subject: Add GetRelocationsAt API --- rust/src/binaryview.rs | 9 +++++++++ rust/src/relocation.rs | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'rust/src') 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 { + unsafe { + let mut count = 0; + let handle = BNGetRelocationsAt(self.as_ref().handle, addr, &mut count); + Array::new(handle, count, ()) + } + } } impl 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 { type Handle: Borrow; -- cgit v1.3.1