summaryrefslogtreecommitdiff
path: root/plugins/dwarf
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 /plugins/dwarf
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 'plugins/dwarf')
-rw-r--r--plugins/dwarf/dwarf_import/src/die_handlers.rs16
-rw-r--r--plugins/dwarf/dwarf_import/src/dwarfdebuginfo.rs2
-rw-r--r--plugins/dwarf/dwarf_import/src/helpers.rs6
-rw-r--r--plugins/dwarf/dwarf_import/src/types.rs8
-rw-r--r--plugins/dwarf/shared/src/lib.rs7
5 files changed, 20 insertions, 19 deletions
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<R: ReaderType>(
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<R: ReaderType>(
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::<String, String>::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<R: ReaderType>(
});
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<R: ReaderType>(
);
} else {
structure_builder.append(
- child_type.as_ref(),
- child_name,
+ &child_type,
+ &child_name,
MemberAccess::NoAccess,
MemberScope::NoScope,
);
diff --git a/plugins/dwarf/shared/src/lib.rs b/plugins/dwarf/shared/src/lib.rs
index c4ed7937..7aa3b486 100644
--- a/plugins/dwarf/shared/src/lib.rs
+++ b/plugins/dwarf/shared/src/lib.rs
@@ -179,9 +179,10 @@ pub fn create_section_reader<'a, Endian: 'a + Endianity>(
}
}
// Truncate Mach-O section names to 16 bytes
- else if let Some(section) =
- view.section_by_name("__".to_string() + &section_name[1..section_name.len().min(15)])
- {
+ else if let Some(section) = view.section_by_name(&format!(
+ "__{}",
+ &section_name[1..section_name.len().min(15)]
+ )) {
Ok(EndianRcSlice::new(
Rc::from(view.read_vec(section.start(), section.len()).as_slice()),
endian,