summaryrefslogtreecommitdiff
path: root/rust/src/debuginfo.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 19:22:21 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit2f214f6c9935e8ce8df4732cde44a540a003258c (patch)
tree6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/debuginfo.rs
parentb4cf0be8816182c9efca037e27e9439482f8bf36 (diff)
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids. Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type. This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type. Special consideration must be made for symbols or other possible non utf-8 objects. This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'rust/src/debuginfo.rs')
-rw-r--r--rust/src/debuginfo.rs57
1 files changed, 23 insertions, 34 deletions
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index 248726f3..a4d0b139 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -115,7 +115,7 @@ impl DebugInfoParser {
}
/// Returns debug info parser of the given name, if it exists
- pub fn from_name<S: IntoCStr>(name: S) -> Result<Ref<Self>, ()> {
+ pub fn from_name(name: &str) -> Result<Ref<Self>, ()> {
let name = name.to_cstr();
let parser = unsafe { BNGetDebugInfoParserByName(name.as_ptr()) };
@@ -207,9 +207,8 @@ impl DebugInfoParser {
}
// Registers a DebugInfoParser. See `binaryninja::debuginfo::DebugInfoParser` for more details.
- pub fn register<S, C>(name: S, parser_callbacks: C) -> Ref<Self>
+ pub fn register<C>(name: &str, parser_callbacks: C) -> Ref<Self>
where
- S: IntoCStr,
C: CustomDebugInfoParser,
{
extern "C" fn cb_is_valid<C>(ctxt: *mut c_void, view: *mut BNBinaryView) -> bool
@@ -418,7 +417,7 @@ impl DebugInfo {
}
/// Returns all types within the parser
- pub fn types_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<NameAndType> {
+ pub fn types_by_name(&self, parser_name: &str) -> Vec<NameAndType> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -451,7 +450,7 @@ impl DebugInfo {
}
/// Returns all functions within the parser
- pub fn functions_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<DebugFunctionInfo> {
+ pub fn functions_by_name(&self, parser_name: &str) -> Vec<DebugFunctionInfo> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -486,10 +485,7 @@ impl DebugInfo {
}
/// Returns all data variables within the parser
- pub fn data_variables_by_name<S: IntoCStr>(
- &self,
- parser_name: S,
- ) -> Vec<NamedDataVariableWithType> {
+ pub fn data_variables_by_name(&self, parser_name: &str) -> Vec<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
let mut count: usize = 0;
@@ -523,7 +519,7 @@ impl DebugInfo {
result
}
- pub fn type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> Option<Ref<Type>> {
+ pub fn type_by_name(&self, parser_name: &str, name: &str) -> Option<Ref<Type>> {
let parser_name = parser_name.to_cstr();
let name = name.to_cstr();
@@ -536,10 +532,10 @@ impl DebugInfo {
}
}
- pub fn get_data_variable_by_name<S: IntoCStr>(
+ pub fn get_data_variable_by_name(
&self,
- parser_name: S,
- name: S,
+ parser_name: &str,
+ name: &str,
) -> Option<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
let name = name.to_cstr();
@@ -558,9 +554,9 @@ impl DebugInfo {
}
}
- pub fn get_data_variable_by_address<S: IntoCStr>(
+ pub fn get_data_variable_by_address(
&self,
- parser_name: S,
+ parser_name: &str,
address: u64,
) -> Option<NamedDataVariableWithType> {
let parser_name = parser_name.to_cstr();
@@ -576,7 +572,7 @@ impl DebugInfo {
}
/// Returns a list of [`NameAndType`] where the `name` is the parser the type originates from.
- pub fn get_types_by_name<S: IntoCStr>(&self, name: S) -> Vec<NameAndType> {
+ pub fn get_types_by_name(&self, name: &str) -> Vec<NameAndType> {
let mut count: usize = 0;
let name = name.to_cstr();
let raw_names_and_types_ptr =
@@ -595,10 +591,7 @@ impl DebugInfo {
}
// The tuple is (DebugInfoParserName, address, type)
- pub fn get_data_variables_by_name<S: IntoCStr>(
- &self,
- name: S,
- ) -> Vec<(String, u64, Ref<Type>)> {
+ pub fn get_data_variables_by_name(&self, name: &str) -> Vec<(String, u64, Ref<Type>)> {
let name = name.to_cstr();
let mut count: usize = 0;
@@ -649,55 +642,51 @@ impl DebugInfo {
result
}
- pub fn remove_parser_info<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_info(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserInfo(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_types<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_types(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserTypes(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_functions<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_functions(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserFunctions(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_parser_data_variables<S: IntoCStr>(&self, parser_name: S) -> bool {
+ pub fn remove_parser_data_variables(&self, parser_name: &str) -> bool {
let parser_name = parser_name.to_cstr();
unsafe { BNRemoveDebugParserDataVariables(self.handle, parser_name.as_ptr()) }
}
- pub fn remove_type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> bool {
+ pub fn remove_type_by_name(&self, parser_name: &str, name: &str) -> 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<S: IntoCStr>(&self, parser_name: S, index: usize) -> bool {
+ pub fn remove_function_by_index(&self, parser_name: &str, 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<S: IntoCStr>(
- &self,
- parser_name: S,
- address: u64,
- ) -> bool {
+ pub fn remove_data_variable_by_address(&self, parser_name: &str, 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<S: IntoCStr>(&self, name: S, new_type: &Type, components: &[&str]) -> bool {
+ pub fn add_type(&self, name: &str, 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();
@@ -779,11 +768,11 @@ impl DebugInfo {
}
/// Adds a data variable scoped under the current parser's name to the debug info
- pub fn add_data_variable<S: IntoCStr>(
+ pub fn add_data_variable(
&self,
address: u64,
t: &Type,
- name: Option<S>,
+ name: Option<&str>,
components: &[&str],
) -> bool {
let mut components_array: Vec<*const ::std::os::raw::c_char> =