From 9dadf92c16da5cd21def79ae39ca98803c9208ec Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 5 May 2025 13:17:30 -0400 Subject: [Rust] Rename `AsCStr` to `IntoCStr` --- rust/src/debuginfo.rs | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'rust/src/debuginfo.rs') diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index 92c0170d..248726f3 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -83,7 +83,7 @@ use crate::{ binary_view::BinaryView, platform::Platform, rc::*, - string::{raw_to_string, AsCStr, BnString}, + string::{raw_to_string, BnString, IntoCStr}, types::{NameAndType, Type}, }; @@ -115,7 +115,7 @@ impl DebugInfoParser { } /// Returns debug info parser of the given name, if it exists - pub fn from_name(name: S) -> Result, ()> { + pub fn from_name(name: S) -> Result, ()> { let name = name.to_cstr(); let parser = unsafe { BNGetDebugInfoParserByName(name.as_ptr()) }; @@ -209,7 +209,7 @@ impl DebugInfoParser { // Registers a DebugInfoParser. See `binaryninja::debuginfo::DebugInfoParser` for more details. pub fn register(name: S, parser_callbacks: C) -> Ref where - S: AsCStr, + S: IntoCStr, C: CustomDebugInfoParser, { extern "C" fn cb_is_valid(ctxt: *mut c_void, view: *mut BNBinaryView) -> bool @@ -418,7 +418,7 @@ impl DebugInfo { } /// Returns all types within the parser - pub fn types_by_name(&self, parser_name: S) -> Vec { + pub fn types_by_name(&self, parser_name: S) -> Vec { let parser_name = parser_name.to_cstr(); let mut count: usize = 0; @@ -451,7 +451,7 @@ impl DebugInfo { } /// Returns all functions within the parser - pub fn functions_by_name(&self, parser_name: S) -> Vec { + pub fn functions_by_name(&self, parser_name: S) -> Vec { let parser_name = parser_name.to_cstr(); let mut count: usize = 0; @@ -486,7 +486,7 @@ impl DebugInfo { } /// Returns all data variables within the parser - pub fn data_variables_by_name( + pub fn data_variables_by_name( &self, parser_name: S, ) -> Vec { @@ -523,7 +523,7 @@ impl DebugInfo { result } - pub fn type_by_name(&self, parser_name: S, name: S) -> Option> { + pub fn type_by_name(&self, parser_name: S, name: S) -> Option> { let parser_name = parser_name.to_cstr(); let name = name.to_cstr(); @@ -536,7 +536,7 @@ impl DebugInfo { } } - pub fn get_data_variable_by_name( + pub fn get_data_variable_by_name( &self, parser_name: S, name: S, @@ -558,7 +558,7 @@ impl DebugInfo { } } - pub fn get_data_variable_by_address( + pub fn get_data_variable_by_address( &self, parser_name: S, address: u64, @@ -576,7 +576,7 @@ impl DebugInfo { } /// Returns a list of [`NameAndType`] where the `name` is the parser the type originates from. - pub fn get_types_by_name(&self, name: S) -> Vec { + pub fn get_types_by_name(&self, name: S) -> Vec { let mut count: usize = 0; let name = name.to_cstr(); let raw_names_and_types_ptr = @@ -595,7 +595,10 @@ impl DebugInfo { } // The tuple is (DebugInfoParserName, address, type) - pub fn get_data_variables_by_name(&self, name: S) -> Vec<(String, u64, Ref)> { + pub fn get_data_variables_by_name( + &self, + name: S, + ) -> Vec<(String, u64, Ref)> { let name = name.to_cstr(); let mut count: usize = 0; @@ -646,51 +649,55 @@ impl DebugInfo { result } - pub fn remove_parser_info(&self, parser_name: S) -> bool { + pub fn remove_parser_info(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserInfo(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_types(&self, parser_name: S) -> bool { + pub fn remove_parser_types(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserTypes(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_functions(&self, parser_name: S) -> bool { + pub fn remove_parser_functions(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserFunctions(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_data_variables(&self, parser_name: S) -> bool { + pub fn remove_parser_data_variables(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserDataVariables(self.handle, parser_name.as_ptr()) } } - pub fn remove_type_by_name(&self, parser_name: S, name: S) -> bool { + pub fn remove_type_by_name(&self, parser_name: S, name: S) -> bool { let parser_name = parser_name.to_cstr(); let name = name.to_cstr(); unsafe { BNRemoveDebugTypeByName(self.handle, parser_name.as_ptr(), name.as_ptr()) } } - pub fn remove_function_by_index(&self, parser_name: S, index: usize) -> bool { + pub fn remove_function_by_index(&self, parser_name: S, index: usize) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugFunctionByIndex(self.handle, parser_name.as_ptr(), index) } } - pub fn remove_data_variable_by_address(&self, parser_name: S, address: u64) -> bool { + pub fn remove_data_variable_by_address( + &self, + parser_name: S, + address: u64, + ) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugDataVariableByAddress(self.handle, parser_name.as_ptr(), address) } } /// Adds a type scoped under the current parser's name to the debug info - pub fn add_type(&self, name: S, new_type: &Type, components: &[&str]) -> bool { + pub fn add_type(&self, name: S, new_type: &Type, components: &[&str]) -> bool { // SAFETY: Lifetime of `components` will live long enough, so passing as_ptr is safe. let raw_components: Vec<_> = components.iter().map(|&c| c.as_ptr()).collect(); @@ -772,7 +779,7 @@ impl DebugInfo { } /// Adds a data variable scoped under the current parser's name to the debug info - pub fn add_data_variable( + pub fn add_data_variable( &self, address: u64, t: &Type, -- cgit v1.3.1