diff options
Diffstat (limited to 'rust/src/binaryview.rs')
| -rw-r--r-- | rust/src/binaryview.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index bf14580c..7da5a744 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -33,6 +33,7 @@ use std::{ops, slice}; use crate::architecture::Architecture; use crate::architecture::CoreArchitecture; use crate::basicblock::BasicBlock; +use crate::component::{Component, ComponentBuilder, IntoComponentGuid}; use crate::databuffer::DataBuffer; use crate::debuginfo::DebugInfo; use crate::fileaccessor::FileAccessor; @@ -1373,6 +1374,61 @@ pub trait BinaryViewExt: BinaryViewBase { Array::new(handle, count, ()) } } + + fn component_by_guid<S: BnStrCompatible>(&self, guid: S) -> Option<Component> { + let name = guid.into_bytes_with_nul(); + let result = unsafe { + BNGetComponentByGuid( + self.as_ref().handle, + name.as_ref().as_ptr() as *const core::ffi::c_char, + ) + }; + core::ptr::NonNull::new(result).map(|h| unsafe { Component::from_raw(h) }) + } + + fn root_component(&self) -> Option<Component> { + let result = unsafe { BNGetRootComponent(self.as_ref().handle) }; + core::ptr::NonNull::new(result).map(|h| unsafe { Component::from_raw(h) }) + } + + fn component_builder(&self) -> ComponentBuilder { + ComponentBuilder::new_from_raw(self.as_ref().handle) + } + + fn component_by_path<P: BnStrCompatible>(&self, path: P) -> Option<Component> { + let path = path.into_bytes_with_nul(); + let result = unsafe { + BNGetComponentByPath( + self.as_ref().handle, + path.as_ref().as_ptr() as *const core::ffi::c_char, + ) + }; + core::ptr::NonNull::new(result).map(|h| unsafe { Component::from_raw(h) }) + } + + fn remove_component(&self, component: &Component) -> bool { + unsafe { BNRemoveComponent(self.as_ref().handle, component.as_raw()) } + } + + fn remove_component_by_guid<P: IntoComponentGuid>(&self, guid: P) -> bool { + let path = guid.component_guid(); + unsafe { BNRemoveComponentByGuid(self.as_ref().handle, path.as_ptr()) } + } + + fn data_variable_parent_components( + &self, + data_variable: &DataVariable, + ) -> Array<Component> { + let mut count = 0; + let result = unsafe { + BNGetDataVariableParentComponents( + self.as_ref().handle, + data_variable.address(), + &mut count, + ) + }; + unsafe { Array::new(result, count, ()) } + } } impl<T: BinaryViewBase> BinaryViewExt for T {} |
