From a826c589dfc10c542deba7ca3343a462e02d6bde Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:10:56 -0400 Subject: [Rust] Simplify `BnStrCompatible` trait Followup to https://github.com/Vector35/binaryninja-api/pull/5897/ This simplifies usage of the trait in user code, should just be able to `to_cstr` to get the cstr repr and then call `as_ptr`. Co-authored-by: Michael Krasnitski --- rust/src/architecture.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'rust/src/architecture.rs') diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index ee8033a2..74a8dfa4 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -27,7 +27,7 @@ use crate::{ platform::Platform, rc::*, relocation::CoreRelocationHandler, - string::BnStrCompatible, + string::AsCStr, string::*, types::{NameAndType, Type}, Endianness, @@ -1404,8 +1404,7 @@ impl CoreArchitecture { } pub fn by_name(name: &str) -> Option { - let handle = - unsafe { BNGetArchitectureByName(name.into_bytes_with_nul().as_ptr() as *mut _) }; + let handle = unsafe { BNGetArchitectureByName(name.to_cstr().as_ptr() as *mut _) }; match handle.is_null() { false => Some(CoreArchitecture { handle }), true => None, @@ -1953,8 +1952,8 @@ macro_rules! cc_func { /// Contains helper methods for all types implementing 'Architecture' pub trait ArchitectureExt: Architecture { - fn register_by_name(&self, name: S) -> Option { - let name = name.into_bytes_with_nul(); + fn register_by_name(&self, name: S) -> Option { + let name = name.to_cstr(); match unsafe { BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ref().as_ptr() as *mut _) @@ -2033,7 +2032,7 @@ pub trait ArchitectureExt: Architecture { fn register_relocation_handler(&self, name: S, func: F) where - S: BnStrCompatible, + S: AsCStr, R: 'static + RelocationHandler> + Send @@ -2056,7 +2055,7 @@ impl ArchitectureExt for T {} pub fn register_architecture(name: S, func: F) -> &'static A where - S: BnStrCompatible, + S: AsCStr, A: 'static + Architecture> + Send + Sync + Sized, F: FnOnce(CustomArchitectureHandle, CoreArchitecture) -> A, { @@ -3130,7 +3129,7 @@ where custom_arch.skip_and_return_value(data, addr, val) } - let name = name.into_bytes_with_nul(); + let name = name.to_cstr(); let uninit_arch = ArchitectureBuilder { arch: MaybeUninit::zeroed(), -- cgit v1.3.1