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/interaction.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'rust/src/interaction.rs') diff --git a/rust/src/interaction.rs b/rust/src/interaction.rs index 23dcaf85..7e007eb9 100644 --- a/rust/src/interaction.rs +++ b/rust/src/interaction.rs @@ -21,7 +21,7 @@ use std::path::PathBuf; use crate::binary_view::BinaryView; use crate::rc::Ref; -use crate::string::{BnStrCompatible, BnString}; +use crate::string::{AsCStr, BnString}; pub fn get_text_line_input(prompt: &str, title: &str) -> Option { let mut value: *mut c_char = std::ptr::null_mut(); @@ -29,8 +29,8 @@ pub fn get_text_line_input(prompt: &str, title: &str) -> Option { let result = unsafe { BNGetTextLineInput( &mut value, - prompt.into_bytes_with_nul().as_ptr() as *mut _, - title.into_bytes_with_nul().as_ptr() as *mut _, + prompt.to_cstr().as_ptr() as *mut _, + title.to_cstr().as_ptr() as *mut _, ) }; if !result { @@ -46,8 +46,8 @@ pub fn get_integer_input(prompt: &str, title: &str) -> Option { let result = unsafe { BNGetIntegerInput( &mut value, - prompt.into_bytes_with_nul().as_ptr() as *mut _, - title.into_bytes_with_nul().as_ptr() as *mut _, + prompt.to_cstr().as_ptr() as *mut _, + title.to_cstr().as_ptr() as *mut _, ) }; @@ -64,8 +64,8 @@ pub fn get_address_input(prompt: &str, title: &str) -> Option { let result = unsafe { BNGetAddressInput( &mut value, - prompt.into_bytes_with_nul().as_ptr() as *mut _, - title.into_bytes_with_nul().as_ptr() as *mut _, + prompt.to_cstr().as_ptr() as *mut _, + title.to_cstr().as_ptr() as *mut _, std::ptr::null_mut(), 0, ) @@ -84,8 +84,8 @@ pub fn get_open_filename_input(prompt: &str, extension: &str) -> Option let result = unsafe { BNGetOpenFileNameInput( &mut value, - prompt.into_bytes_with_nul().as_ptr() as *mut _, - extension.into_bytes_with_nul().as_ptr() as *mut _, + prompt.to_cstr().as_ptr() as *mut _, + extension.to_cstr().as_ptr() as *mut _, ) }; if !result { @@ -106,9 +106,9 @@ pub fn get_save_filename_input( let result = unsafe { BNGetSaveFileNameInput( &mut value, - prompt.into_bytes_with_nul().as_ptr() as *mut _, - extension.into_bytes_with_nul().as_ptr() as *mut _, - default_name.into_bytes_with_nul().as_ptr() as *mut _, + prompt.to_cstr().as_ptr() as *mut _, + extension.to_cstr().as_ptr() as *mut _, + default_name.to_cstr().as_ptr() as *mut _, ) }; if !result { @@ -125,8 +125,8 @@ pub fn get_directory_name_input(prompt: &str, default_name: &str) -> Option MessageBoxButtonResult { unsafe { BNShowMessageBox( - title.into_bytes_with_nul().as_ptr() as *mut _, - text.into_bytes_with_nul().as_ptr() as *mut _, + title.to_cstr().as_ptr() as *mut _, + text.to_cstr().as_ptr() as *mut _, buttons, icon, ) @@ -495,7 +495,7 @@ impl FormInputBuilder { BNGetFormInput( self.fields.as_mut_ptr(), self.fields.len(), - title.into_bytes_with_nul().as_ptr() as *const _, + title.to_cstr().as_ptr() as *const _, ) } { let result = self @@ -577,7 +577,7 @@ pub fn run_progress_dialog Result<(), ()>>)>( if unsafe { BNRunProgressDialog( - title.into_bytes_with_nul().as_ptr() as *mut _, + title.to_cstr().as_ptr() as *mut _, can_cancel, Some(cb_task::), &mut ctxt as *mut _ as *mut c_void, -- cgit v1.3.1