diff options
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/binaryview.rs | 30 | ||||
| -rw-r--r-- | rust/src/debuginfo.rs | 2 | ||||
| -rw-r--r-- | rust/src/lib.rs | 5 | ||||
| -rw-r--r-- | rust/src/types.rs | 10 |
4 files changed, 44 insertions, 3 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index b6ff3931..9e56f855 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -164,6 +164,24 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { Ok(BinaryView::from_raw(handle)) } } + fn raw_view(&self) -> Result<Ref<BinaryView>> { + let raw = "Raw".into_bytes_with_nul(); + + let handle = + unsafe { BNGetFileViewOfType(self.file().as_ref().handle, raw.as_ptr() as *mut _) }; + + if handle.is_null() { + return Err(()); + } + + unsafe { Ok(BinaryView::from_raw(handle)) } + } + + fn view_type(&self) -> BnString { + let ptr: *mut c_char = unsafe { BNGetViewType(self.as_ref().handle) }; + unsafe { BnString::from_raw(ptr) } + } + /// Reads up to `len` bytes from address `offset` fn read_vec(&self, offset: u64, len: usize) -> Vec<u8> { let mut ret = Vec::with_capacity(len); @@ -1144,3 +1162,15 @@ impl ToOwned for BinaryView { unsafe impl Send for BinaryView {} unsafe impl Sync for BinaryView {} + +impl std::fmt::Debug for BinaryView { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "BinaryView (type: `{}`): '{}', len {:#x}", + self.view_type(), + self.file().filename(), + self.len() + ) + } +} diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index fb108a21..0fd1930e 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -797,7 +797,7 @@ impl DebugInfo { unsafe { BNAddDebugDataVariableInfo( self.handle, - &mut BNDataVariableAndName { + &BNDataVariableAndName { address: var.address, type_: var.t.contents.handle, name: name.as_ref().as_ptr() as *mut _, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 57b71cba..61016c0f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -238,7 +238,10 @@ pub fn open_view<F: AsRef<Path>>(filename: F) -> Result<rc::Ref<binaryview::Bina } else { // TODO : add log prints println!("Opening view of type: `{}`", available_view.name()); - Some(available_view.open(&view).unwrap()) + match available_view.open(&view) { + Ok(view) => Some(view), + _ => None, + } } }); diff --git a/rust/src/types.rs b/rust/src/types.rs index 11934ceb..00c274b7 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -1853,7 +1853,15 @@ impl NamedTypeReference { Self { handle } } - pub fn new<S: BnStrCompatible>( + /// Most people should use this: The core "should" figure out the type ID for you + /// TODO : Check with Peter about what a better description would be + pub fn new(type_class: NamedTypeReferenceClass, mut name: QualifiedName) -> Self { + Self { + handle: unsafe { BNCreateNamedType(type_class, "".as_ptr() as _, &mut name.0) }, + } + } + + pub fn new_with_id<S: BnStrCompatible>( type_class: NamedTypeReferenceClass, type_id: S, mut name: QualifiedName, |
