From 2f214f6c9935e8ce8df4732cde44a540a003258c Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 7 May 2025 19:22:21 -0400 Subject: [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. --- rust/src/function.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'rust/src/function.rs') diff --git a/rust/src/function.rs b/rust/src/function.rs index 5ebb84f6..c1c29873 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -372,7 +372,7 @@ impl Function { unsafe { BnString::into_string(BNGetFunctionComment(self.handle)) } } - pub fn set_comment(&self, comment: S) { + pub fn set_comment(&self, comment: &str) { let raw = comment.to_cstr(); unsafe { @@ -394,7 +394,7 @@ impl Function { unsafe { BnString::into_string(BNGetCommentForAddress(self.handle, addr)) } } - pub fn set_comment_at(&self, addr: u64, comment: S) { + pub fn set_comment_at(&self, addr: u64, comment: &str) { let raw = comment.to_cstr(); unsafe { @@ -1103,10 +1103,10 @@ impl Function { /// let crash = bv.create_tag_type("Crashes", "🎯"); /// fun.add_tag(&crash, "Nullpointer dereference", Some(0x1337), false, None); /// ``` - pub fn add_tag( + pub fn add_tag( &self, tag_type: &TagType, - data: S, + data: &str, addr: Option, user: bool, arch: Option, @@ -1707,7 +1707,7 @@ impl Function { operand: usize, display_type: IntegerDisplayType, arch: Option, - enum_display_typeid: Option, + enum_display_typeid: Option<&str>, ) { let arch = arch.unwrap_or_else(|| self.arch()); let enum_display_typeid = enum_display_typeid.map(IntoCStr::to_cstr); -- cgit v1.3.1