diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-03 23:15:17 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 6264254065bbae9d89f51cf3330379b7ace09592 (patch) | |
| tree | 9ece1d1739215c2faef2d808ef4fdc019ad527fa /rust/src/binary_view.rs | |
| parent | c3fdda9727f5507818e3f55576ad32215a22b0f9 (diff) | |
[Rust] Return `String` instead of `BnString` for cases where lossy conversion can be tolerated
Still need to go and audit all usage, but realistically the most important places to give the user control are with symbols, where the data can come from non utf8 sources
This is still incomplete, I just looked for usage of -> BnString so any other variant was omitted.
Diffstat (limited to 'rust/src/binary_view.rs')
| -rw-r--r-- | rust/src/binary_view.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index db4c92d7..d8f35caf 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -27,7 +27,7 @@ use crate::architecture::{Architecture, CoreArchitecture}; use crate::base_detection::BaseAddressDetection; use crate::basic_block::BasicBlock; use crate::binary_view::memory_map::MemoryMap; -use crate::component::{Component, IntoComponentGuid}; +use crate::component::Component; use crate::confidence::Conf; use crate::data_buffer::DataBuffer; use crate::debuginfo::DebugInfo; @@ -187,9 +187,9 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn type_name(&self) -> BnString { + fn type_name(&self) -> String { let ptr: *mut c_char = unsafe { BNGetViewType(self.as_ref().handle) }; - unsafe { BnString::from_raw(ptr) } + unsafe { BnString::into_string(ptr) } } fn parent_view(&self) -> Option<Ref<BinaryView>> { @@ -204,9 +204,9 @@ pub trait BinaryViewExt: BinaryViewBase { self.file().view_of_type("Raw") } - fn view_type(&self) -> BnString { + fn view_type(&self) -> String { let ptr: *mut c_char = unsafe { BNGetViewType(self.as_ref().handle) }; - unsafe { BnString::from_raw(ptr) } + unsafe { BnString::into_string(ptr) } } /// Reads up to `len` bytes from address `offset` @@ -1493,9 +1493,14 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNRemoveComponent(self.as_ref().handle, component.handle.as_ptr()) } } - 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 remove_component_by_guid<P: BnStrCompatible>(&self, guid: P) -> bool { + let path = guid.into_bytes_with_nul(); + unsafe { + BNRemoveComponentByGuid( + self.as_ref().handle, + path.as_ref().as_ptr() as *const c_char, + ) + } } fn data_variable_parent_components(&self, data_variable: &DataVariable) -> Array<Component> { |
