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/custom_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/custom_binary_view.rs')
| -rw-r--r-- | rust/src/custom_binary_view.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index a43bbd4b..de841a26 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -15,6 +15,7 @@ //! An interface for providing your own [BinaryView]s to Binary Ninja. use binaryninjacore_sys::*; +use std::ffi::c_char; pub use binaryninjacore_sys::BNModificationStatus as ModificationStatus; @@ -211,12 +212,12 @@ pub trait BinaryViewTypeBase: AsRef<BinaryViewType> { } pub trait BinaryViewTypeExt: BinaryViewTypeBase { - fn name(&self) -> BnString { - unsafe { BnString::from_raw(BNGetBinaryViewTypeName(self.as_ref().handle)) } + fn name(&self) -> String { + unsafe { BnString::into_string(BNGetBinaryViewTypeName(self.as_ref().handle)) } } - fn long_name(&self) -> BnString { - unsafe { BnString::from_raw(BNGetBinaryViewTypeLongName(self.as_ref().handle)) } + fn long_name(&self) -> String { + unsafe { BnString::into_string(BNGetBinaryViewTypeLongName(self.as_ref().handle)) } } fn register_arch<A: Architecture>(&self, id: u32, endianness: Endianness, arch: &A) { @@ -502,7 +503,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { let view_name = view_type.name(); - if let Some(bv) = file.view_of_type(view_name.as_str()) { + if let Some(bv) = file.view_of_type(&view_name) { // while it seems to work most of the time, you can get really unlucky // if the a free of the existing view of the same type kicks off while // BNCreateBinaryViewOfType is still running. the freeObject callback @@ -514,7 +515,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { // going to try and stop this from happening in the first place. log::error!( "attempt to create duplicate view of type '{}' (existing: {:?})", - view_name.as_str(), + view_name, bv.handle ); @@ -879,7 +880,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { unsafe { let res = BNCreateCustomBinaryView( - view_name.as_ptr(), + view_name.as_ptr() as *const c_char, file.handle, parent.handle, &mut bn_obj, |
