From 6264254065bbae9d89f51cf3330379b7ace09592 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sat, 3 May 2025 23:15:17 -0400 Subject: [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. --- rust/src/binary_view.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'rust/src/binary_view.rs') 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> { @@ -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(&self, guid: P) -> bool { - let path = guid.component_guid(); - unsafe { BNRemoveComponentByGuid(self.as_ref().handle, path.as_ptr()) } + fn remove_component_by_guid(&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 { -- cgit v1.3.1