summaryrefslogtreecommitdiff
path: root/rust/src/function.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-03 23:15:17 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit6264254065bbae9d89f51cf3330379b7ace09592 (patch)
tree9ece1d1739215c2faef2d808ef4fdc019ad527fa /rust/src/function.rs
parentc3fdda9727f5507818e3f55576ad32215a22b0f9 (diff)
[Rust] Return `String` instead of `BnString` for cases where lossy conversion can be tolerated
Still need to go and audit all usage, but realistically the most important places to give the user control are with symbols, where the data can come from non utf8 sources This is still incomplete, I just looked for usage of -> BnString so any other variant was omitted.
Diffstat (limited to 'rust/src/function.rs')
-rw-r--r--rust/src/function.rs44
1 files changed, 16 insertions, 28 deletions
diff --git a/rust/src/function.rs b/rust/src/function.rs
index c882ab08..53fec505 100644
--- a/rust/src/function.rs
+++ b/rust/src/function.rs
@@ -368,8 +368,8 @@ impl Function {
}
}
- pub fn comment(&self) -> BnString {
- unsafe { BnString::from_raw(BNGetFunctionComment(self.handle)) }
+ pub fn comment(&self) -> String {
+ unsafe { BnString::into_string(BNGetFunctionComment(self.handle)) }
}
pub fn set_comment<S: BnStrCompatible>(&self, comment: S) {
@@ -390,8 +390,8 @@ impl Function {
unsafe { BNSetUserFunctionCanReturn(self.handle, &mut bool_with_confidence) }
}
- pub fn comment_at(&self, addr: u64) -> BnString {
- unsafe { BnString::from_raw(BNGetCommentForAddress(self.handle, addr)) }
+ pub fn comment_at(&self, addr: u64) -> String {
+ unsafe { BnString::into_string(BNGetCommentForAddress(self.handle, addr)) }
}
pub fn set_comment_at<S: BnStrCompatible>(&self, addr: u64, comment: S) {
@@ -459,11 +459,11 @@ impl Function {
unsafe { Array::new(lines, count, ()) }
}
- pub fn variable_name(&self, var: &Variable) -> BnString {
+ pub fn variable_name(&self, var: &Variable) -> String {
unsafe {
let raw_var = BNVariable::from(var);
let raw_name = BNGetVariableName(self.handle, &raw_var);
- BnString::from_raw(raw_name)
+ BnString::into_string(raw_name)
}
}
@@ -1741,10 +1741,10 @@ impl Function {
value: u64,
operand: usize,
arch: Option<CoreArchitecture>,
- ) -> BnString {
+ ) -> String {
let arch = arch.unwrap_or_else(|| self.arch());
unsafe {
- BnString::from_raw(BNGetIntegerConstantDisplayTypeEnumerationType(
+ BnString::into_string(BNGetIntegerConstantDisplayTypeEnumerationType(
self.handle,
arch.handle,
instr_addr,
@@ -1766,7 +1766,7 @@ impl Function {
value: u64,
operand: usize,
arch: Option<CoreArchitecture>,
- ) -> (IntegerDisplayType, BnString) {
+ ) -> (IntegerDisplayType, String) {
let arch = arch.unwrap_or_else(|| self.arch());
let name = self.int_enum_display_typeid(instr_addr, value, operand, Some(arch));
let display = self.int_display_type(instr_addr, value, operand, Some(arch));
@@ -1922,7 +1922,7 @@ impl Function {
addr: u64,
offset: i64,
arch: Option<CoreArchitecture>,
- ) -> Option<(Variable, BnString, Conf<Ref<Type>>)> {
+ ) -> Option<NamedVariableWithType> {
let arch = arch.unwrap_or_else(|| self.arch());
let mut found_value = BNVariableNameAndType::default();
let found = unsafe {
@@ -1937,13 +1937,7 @@ impl Function {
if !found {
return None;
}
- let var = Variable::from(found_value.var);
- let name = unsafe { BnString::from_raw(found_value.name) };
- let var_type = Conf::new(
- unsafe { Type::ref_from_raw(found_value.type_) },
- found_value.typeConfidence,
- );
- Some((var, name, var_type))
+ Some(NamedVariableWithType::from_owned_raw(found_value))
}
pub fn stack_var_at_frame_offset_after_instruction(
@@ -1951,7 +1945,7 @@ impl Function {
addr: u64,
offset: i64,
arch: Option<CoreArchitecture>,
- ) -> Option<(Variable, BnString, Conf<Ref<Type>>)> {
+ ) -> Option<NamedVariableWithType> {
let arch = arch.unwrap_or_else(|| self.arch());
let mut found_value = BNVariableNameAndType::default();
let found = unsafe {
@@ -1966,13 +1960,7 @@ impl Function {
if !found {
return None;
}
- let var = Variable::from(found_value.var);
- let name = unsafe { BnString::from_raw(found_value.name) };
- let var_type = Conf::new(
- unsafe { Type::ref_from_raw(found_value.type_) },
- found_value.typeConfidence,
- );
- Some((var, name, var_type))
+ Some(NamedVariableWithType::from_owned_raw(found_value))
}
pub fn stack_variables_referenced_by(
@@ -2348,8 +2336,8 @@ impl Function {
/// Returns a string representing the provenance. This portion of the API
/// is under development. Currently the provenance information is
/// undocumented, not persistent, and not saved to a database.
- pub fn provenance(&self) -> BnString {
- unsafe { BnString::from_raw(BNGetProvenanceString(self.handle)) }
+ pub fn provenance(&self) -> String {
+ unsafe { BnString::into_string(BNGetProvenanceString(self.handle)) }
}
/// Get registers that are used for the return value
@@ -2780,7 +2768,7 @@ impl Default for HighlightColor {
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct Comment {
pub addr: u64,
- pub comment: BnString,
+ pub comment: String,
}
impl CoreArrayProvider for Comment {