diff options
| author | toolCHAINZ <toolCHAINZ@users.noreply.github.com> | 2023-05-04 21:19:32 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-05-10 17:45:15 -0400 |
| commit | 3cbd7682c8696a2005b98e3c1b09f3357ced012d (patch) | |
| tree | a80ee5ba13b068e048605215ea4abf07bab1616b /rust/src/binaryview.rs | |
| parent | dfd2b29120baa6d86ab6e76ab5f940dec63ffe37 (diff) | |
Added some stack layout and reference APIs
Diffstat (limited to 'rust/src/binaryview.rs')
| -rw-r--r-- | rust/src/binaryview.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 9e56f855..05f0d06a 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -22,6 +22,7 @@ use binaryninjacore_sys::*; pub use binaryninjacore_sys::BNModificationStatus as ModificationStatus; use std::ops; +use std::ops::Range; use std::os::raw::c_char; use std::ptr; use std::result; @@ -48,6 +49,7 @@ use crate::types::{DataVariable, NamedTypeReference, QualifiedName, QualifiedNam use crate::Endianness; use crate::rc::*; +use crate::references::{CodeReference, DataReference}; use crate::string::*; // TODO : general reorg of modules related to bv @@ -1003,6 +1005,98 @@ pub trait BinaryViewExt: BinaryViewBase { ) }; } + + /// Retrieves a list of [CodeReference]s pointing to a given address. + fn get_code_refs(&self, addr: u64) -> Array<CodeReference> { + unsafe { + let mut count = 0; + let handle = BNGetCodeReferences(self.as_ref().handle, addr, &mut count); + Array::new(handle, count, ()) + } + } + + /// Retrieves a list of [CodeReference]s pointing into a given [Range]. + fn get_code_refs_in_range(&self, range: Range<u64>) -> Array<CodeReference> { + unsafe { + let mut count = 0; + let handle = BNGetCodeReferencesInRange( + self.as_ref().handle, + range.start, + range.end - range.start, + &mut count, + ); + Array::new(handle, count, ()) + } + } + + /// Retrieves a list of [DataReference]s pointing to a given address. + fn get_data_refs(&self, addr: u64) -> Array<DataReference> { + unsafe { + let mut count = 0; + let handle = BNGetDataReferences(self.as_ref().handle, addr, &mut count); + Array::new(handle, count, ()) + } + } + + /// Retrieves a list of [DataReference]s originating from a given address. + fn get_data_refs_from(&self, addr: u64) -> Array<DataReference> { + unsafe { + let mut count = 0; + let handle = BNGetDataReferencesFrom(self.as_ref().handle, addr, &mut count); + Array::new(handle, count, ()) + } + } + + /// Retrieves a list of [DataReference]s pointing into a given [Range]. + fn get_data_refs_in_range(&self, range: Range<u64>) -> Array<DataReference> { + unsafe { + let mut count = 0; + let handle = BNGetDataReferencesInRange( + self.as_ref().handle, + range.start, + range.end - range.start, + &mut count, + ); + Array::new(handle, count, ()) + } + } + + /// Retrieves a list of [CodeReference]s for locations in code that use a given named type. + /// + /// TODO: It might be cleaner if this used an already allocated type from the core and + /// used its name instead of this slightly-gross [QualifiedName] hack. Since the returned + /// object doesn't have any [QualifiedName], I'm assuming the core does not alias + /// the [QualifiedName] we pass to it and it is safe to destroy it on [Drop], as in this function. + fn get_code_refs_for_type<B: BnStrCompatible>(&self, name: B) -> Array<CodeReference> { + unsafe { + let mut count = 0; + let q_name = &mut QualifiedName::from(name).0; + let handle = BNGetCodeReferencesForType( + self.as_ref().handle, + q_name as *mut BNQualifiedName, + &mut count, + ); + Array::new(handle, count, ()) + } + } + /// Retrieves a list of [DataReference]s instances of a given named type in data. + /// + /// TODO: It might be cleaner if this used an already allocated type from the core and + /// used its name instead of this slightly-gross [QualifiedName] hack. Since the returned + /// object doesn't have any [QualifiedName], I'm assuming the core does not alias + /// the [QualifiedName] we pass to it and it is safe to destroy it on [Drop], as in this function. + fn get_data_refs_for_type<B: BnStrCompatible>(&self, name: B) -> Array<DataReference> { + unsafe { + let mut count = 0; + let q_name = &mut QualifiedName::from(name).0; + let handle = BNGetDataReferencesForType( + self.as_ref().handle, + q_name as *mut BNQualifiedName, + &mut count, + ); + Array::new(handle, count, ()) + } + } } impl<T: BinaryViewBase> BinaryViewExt for T {} |
