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. --- plugins/dwarf/dwarf_import/src/die_handlers.rs | 16 ++++++++-------- plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 2 +- plugins/dwarf/dwarf_import/src/helpers.rs | 6 +++--- plugins/dwarf/dwarf_import/src/types.rs | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'plugins/dwarf/dwarf_import/src') diff --git a/plugins/dwarf/dwarf_import/src/die_handlers.rs b/plugins/dwarf/dwarf_import/src/die_handlers.rs index 52280320..f71fdabc 100644 --- a/plugins/dwarf/dwarf_import/src/die_handlers.rs +++ b/plugins/dwarf/dwarf_import/src/die_handlers.rs @@ -47,19 +47,19 @@ pub(crate) fn handle_base_type( constants::DW_ATE_address => None, constants::DW_ATE_boolean => Some(Type::bool()), constants::DW_ATE_complex_float => None, - constants::DW_ATE_float => Some(Type::named_float(size, name)), - constants::DW_ATE_signed => Some(Type::named_int(size, true, name)), - constants::DW_ATE_signed_char => Some(Type::named_int(size, true, name)), - constants::DW_ATE_unsigned => Some(Type::named_int(size, false, name)), - constants::DW_ATE_unsigned_char => Some(Type::named_int(size, false, name)), + constants::DW_ATE_float => Some(Type::named_float(size, &name)), + constants::DW_ATE_signed => Some(Type::named_int(size, true, &name)), + constants::DW_ATE_signed_char => Some(Type::named_int(size, true, &name)), + constants::DW_ATE_unsigned => Some(Type::named_int(size, false, &name)), + constants::DW_ATE_unsigned_char => Some(Type::named_int(size, false, &name)), constants::DW_ATE_imaginary_float => None, constants::DW_ATE_packed_decimal => None, constants::DW_ATE_numeric_string => None, constants::DW_ATE_edited => None, constants::DW_ATE_signed_fixed => None, constants::DW_ATE_unsigned_fixed => None, - constants::DW_ATE_decimal_float => Some(Type::named_float(size, name)), - constants::DW_ATE_UTF => Some(Type::named_int(size, false, name)), // TODO : Verify + constants::DW_ATE_decimal_float => Some(Type::named_float(size, &name)), + constants::DW_ATE_UTF => Some(Type::named_int(size, false, &name)), // TODO : Verify constants::DW_ATE_UCS => None, constants::DW_ATE_ASCII => None, // Some sort of array? constants::DW_ATE_lo_user => None, @@ -114,7 +114,7 @@ pub(crate) fn handle_enum( match &child.entry().attr(constants::DW_AT_const_value) { Ok(Some(attr)) => { if let Some(value) = get_attr_as_u64(attr) { - enumeration_builder.insert(name, value); + enumeration_builder.insert(&name, value); } else { // Somehow the child entry is not a const value. log::error!("Unhandled enum member value type for `{}`", name); diff --git a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs index 017ed4be..1cedbdf2 100644 --- a/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -546,7 +546,7 @@ impl DebugInfoBuilder { assert!(debug_info.add_data_variable( address, &self.get_type(*type_uid).unwrap().ty, - name.clone(), + name.as_deref(), &[] // TODO : Components )); } diff --git a/plugins/dwarf/dwarf_import/src/helpers.rs b/plugins/dwarf/dwarf_import/src/helpers.rs index e23eb498..f2f67170 100644 --- a/plugins/dwarf/dwarf_import/src/helpers.rs +++ b/plugins/dwarf/dwarf_import/src/helpers.rs @@ -14,7 +14,7 @@ use std::ffi::OsStr; use std::path::{Path, PathBuf}; -use std::{collections::HashMap, ops::Deref, str::FromStr, sync::mpsc}; +use std::{ops::Deref, str::FromStr, sync::mpsc}; use crate::{DebugInfoBuilderContext, ReaderType}; use binaryninja::binary_view::BinaryViewBase; @@ -450,8 +450,8 @@ pub(crate) fn download_debug_info( let result = inst .perform_custom_request( "GET", - artifact_url, - HashMap::::new(), + &artifact_url, + vec![], DownloadInstanceInputOutputCallbacks { read: None, write: Some(Box::new(write)), diff --git a/plugins/dwarf/dwarf_import/src/types.rs b/plugins/dwarf/dwarf_import/src/types.rs index 1e9dd146..78992510 100644 --- a/plugins/dwarf/dwarf_import/src/types.rs +++ b/plugins/dwarf/dwarf_import/src/types.rs @@ -215,8 +215,8 @@ fn do_structure_parse( }); structure_builder.insert( - child_type.as_ref(), - child_name, + &child_type, + &child_name, struct_offset, false, MemberAccess::NoAccess, // TODO : Resolve actual scopes, if possible @@ -224,8 +224,8 @@ fn do_structure_parse( ); } else { structure_builder.append( - child_type.as_ref(), - child_name, + &child_type, + &child_name, MemberAccess::NoAccess, MemberScope::NoScope, ); -- cgit v1.3.1