diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-04-18 12:38:34 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-04-18 12:39:39 -0400 |
| commit | b14cdec968445e1502ead497b00f49d5bb68c92a (patch) | |
| tree | 3885d4e1515e9c757d594ca5914292f953db0a4a /rust/src/binaryview.rs | |
| parent | b59b1a6076a3772128186db8fe97b5766f92a3fd (diff) | |
Rust API : Misc Changes and Improvements
Diffstat (limited to 'rust/src/binaryview.rs')
| -rw-r--r-- | rust/src/binaryview.rs | 30 |
1 files changed, 30 insertions, 0 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() + ) + } +} |
