diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-12-02 04:20:45 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-12-02 04:25:39 -0500 |
| commit | 4aeb55836f26dc9614264bb3b3ce48a8ba5122e8 (patch) | |
| tree | 296cc04b8fd86d4c78db8c38719812fbe6e43659 /rust | |
| parent | bbf4d616ebdec77538832c1353b8e200a1ad9bbf (diff) | |
Rust API - Add BinaryView::data_variables
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/basicblock.rs | 4 | ||||
| -rw-r--r-- | rust/src/binaryview.rs | 11 | ||||
| -rw-r--r-- | rust/src/databuffer.rs | 8 | ||||
| -rw-r--r-- | rust/src/datavariable.rs | 1 | ||||
| -rw-r--r-- | rust/src/lib.rs | 1 | ||||
| -rw-r--r-- | rust/src/types.rs | 26 |
6 files changed, 33 insertions, 18 deletions
diff --git a/rust/src/basicblock.rs b/rust/src/basicblock.rs index 3b9b7e5c..0bd32af3 100644 --- a/rust/src/basicblock.rs +++ b/rust/src/basicblock.rs @@ -69,7 +69,7 @@ unsafe impl<'a, C: 'a + BlockContext> CoreOwnedArrayProvider for Edge<'a, C> { type Raw = BNBasicBlockEdge; type Context = EdgeContext<'a, C>; - unsafe fn free(raw: *mut BNBasicBlockEdge, count: usize, _context: &Self::Context) { + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeBasicBlockEdgeList(raw, count); } } @@ -77,7 +77,7 @@ unsafe impl<'a, C: 'a + BlockContext> CoreOwnedArrayProvider for Edge<'a, C> { unsafe impl<'a, C: 'a + BlockContext> CoreOwnedArrayWrapper<'a> for Edge<'a, C> { type Wrapped = Edge<'a, C>; - unsafe fn wrap_raw(raw: &'a BNBasicBlockEdge, context: &'a Self::Context) -> Edge<'a, C> { + unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Edge<'a, C> { let edge_target = Guard::new( BasicBlock::from_raw(raw.target, context.orig_block.context.clone()), raw, diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 98e7a7a2..17a2570c 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -34,7 +34,7 @@ use crate::section::{Section, SectionBuilder}; use crate::segment::{Segment, SegmentBuilder}; use crate::settings::Settings; use crate::symbol::{Symbol, SymbolType}; -use crate::types::{QualifiedName, Type}; +use crate::types::{DataVariable, QualifiedName, Type}; use crate::Endianness; use crate::rc::*; @@ -420,6 +420,15 @@ pub trait BinaryViewExt: BinaryViewBase { } } + fn data_variables(&self) -> Array<DataVariable> { + unsafe { + let mut count = 0; + let vars = BNGetDataVariables(self.as_ref().handle, &mut count); + + Array::new(vars, count, ()) + } + } + fn define_user_type<S: BnStrCompatible>(&self, name: S, type_obj: &Type) { unsafe { let mut qualified_name = QualifiedName::from(name); diff --git a/rust/src/databuffer.rs b/rust/src/databuffer.rs index d660f570..2d8af7eb 100644 --- a/rust/src/databuffer.rs +++ b/rust/src/databuffer.rs @@ -17,8 +17,6 @@ use binaryninjacore_sys::*; use std::ptr; use std::slice; -// TODO : DataBuffers are RefCounted objects, this needs to be changed to only return Refs to DataBuffers - pub struct DataBuffer(*mut BNDataBuffer); impl DataBuffer { @@ -69,3 +67,9 @@ impl Drop for DataBuffer { } } } + +impl Clone for DataBuffer { + fn clone(&self) -> Self { + Self::from_raw(unsafe { BNDuplicateDataBuffer(self.0) }) + } +} diff --git a/rust/src/datavariable.rs b/rust/src/datavariable.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/rust/src/datavariable.rs @@ -0,0 +1 @@ + diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a477282f..84e21ffd 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -44,6 +44,7 @@ pub mod callingconvention; pub mod command; pub mod custombinaryview; pub mod databuffer; +pub mod datavariable; pub mod debuginfo; pub mod disassembly; pub mod fileaccessor; diff --git a/rust/src/types.rs b/rust/src/types.rs index ec12712b..2567f72d 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1620,22 +1620,22 @@ impl DataVariable { } } -// unsafe impl CoreOwnedArrayProvider for DataVariable { -// type Raw = BNDataVariable; -// type Context = (); +unsafe impl CoreOwnedArrayProvider for DataVariable { + type Raw = BNDataVariable; + type Context = (); -// unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { -// BNFreeDataVariables(raw, count); -// } -// } + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { + BNFreeDataVariables(raw, count); + } +} -// unsafe impl<'a> CoreOwnedArrayWrapper<'a> for DataVariable { -// type Wrapped = &'a DataVariable; +unsafe impl<'a> CoreOwnedArrayWrapper<'a> for DataVariable { + type Wrapped = &'a DataVariable; -// unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { -// mem::transmute(raw) -// } -// } + unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { + mem::transmute(raw) + } +} ///////////////////////// // DataVariableAndName |
