summaryrefslogtreecommitdiff
path: root/plugins
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 /plugins
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 'plugins')
-rw-r--r--plugins/dwarf/dwarf_export/src/lib.rs7
-rw-r--r--plugins/dwarf/shared/src/lib.rs2
-rw-r--r--plugins/warp/src/bin/sigem.rs2
-rw-r--r--plugins/warp/src/cache.rs2
-rw-r--r--plugins/warp/src/matcher.rs2
-rw-r--r--plugins/warp/src/plugin/create.rs2
6 files changed, 8 insertions, 9 deletions
diff --git a/plugins/dwarf/dwarf_export/src/lib.rs b/plugins/dwarf/dwarf_export/src/lib.rs
index bc159825..d1754d29 100644
--- a/plugins/dwarf/dwarf_export/src/lib.rs
+++ b/plugins/dwarf/dwarf_export/src/lib.rs
@@ -18,7 +18,6 @@ use binaryninja::{
interaction,
interaction::{FormResponses, FormResponses::Index},
rc::Ref,
- string::BnString,
symbol::SymbolType,
types::{MemberAccess, StructureType, Type, TypeClass},
};
@@ -422,7 +421,7 @@ fn export_functions(
// Set subprogram DIE attributes
dwarf.unit.get_mut(function_die_uid).set(
gimli::DW_AT_name,
- AttributeValue::String(function.symbol().short_name().as_bytes().to_vec()),
+ AttributeValue::String(function.symbol().short_name().to_bytes().to_vec()),
);
// TODO : (DW_AT_main_subprogram VS DW_TAG_entry_point)
@@ -557,7 +556,7 @@ fn export_data_vars(
if let Some(symbol) = data_var_sym {
dwarf.unit.get_mut(var_die_uid).set(
gimli::DW_AT_name,
- AttributeValue::String(symbol.full_name().as_bytes().to_vec()),
+ AttributeValue::String(symbol.full_name().to_bytes().to_vec()),
);
if symbol.external() {
@@ -756,7 +755,7 @@ fn export_dwarf(bv: &BinaryView) {
let arch_name = if let Some(arch) = bv.default_arch() {
arch.name()
} else {
- BnString::new("Unknown")
+ String::from("Unknown")
};
let responses = present_form(arch_name.as_str());
diff --git a/plugins/dwarf/shared/src/lib.rs b/plugins/dwarf/shared/src/lib.rs
index b12aeab1..c4ed7937 100644
--- a/plugins/dwarf/shared/src/lib.rs
+++ b/plugins/dwarf/shared/src/lib.rs
@@ -106,7 +106,7 @@ pub fn create_section_reader<'a, Endian: 'a + Endianity>(
if let Some(symbol) = view
.symbols()
.iter()
- .find(|symbol| symbol.full_name().as_str() == "__elf_section_headers")
+ .find(|symbol| symbol.full_name().to_string_lossy() == "__elf_section_headers")
{
if let Some(data_var) = view
.data_variables()
diff --git a/plugins/warp/src/bin/sigem.rs b/plugins/warp/src/bin/sigem.rs
index a455f1e8..a50b4ae2 100644
--- a/plugins/warp/src/bin/sigem.rs
+++ b/plugins/warp/src/bin/sigem.rs
@@ -131,7 +131,7 @@ fn main() {
fn data_from_view(view: &BinaryView) -> Data {
let mut data = Data::default();
let is_function_named = |f: &BNGuard<BNFunction>| {
- !f.symbol().short_name().as_str().contains("sub_") || f.has_user_annotations()
+ !f.symbol().short_name().to_string_lossy().contains("sub_") || f.has_user_annotations()
};
data.functions = view
diff --git a/plugins/warp/src/cache.rs b/plugins/warp/src/cache.rs
index 7219b547..8c82c687 100644
--- a/plugins/warp/src/cache.rs
+++ b/plugins/warp/src/cache.rs
@@ -439,7 +439,7 @@ pub struct TypeRefID(u64);
impl From<&BNNamedTypeReference> for TypeRefID {
fn from(value: &BNNamedTypeReference) -> Self {
let mut hasher = DefaultHasher::new();
- hasher.write(value.id().as_bytes());
+ hasher.write(value.id().to_bytes());
Self(hasher.finish())
}
}
diff --git a/plugins/warp/src/matcher.rs b/plugins/warp/src/matcher.rs
index 81458f8d..6352cd7a 100644
--- a/plugins/warp/src/matcher.rs
+++ b/plugins/warp/src/matcher.rs
@@ -506,7 +506,7 @@ pub struct PlatformID(u64);
impl From<&Platform> for PlatformID {
fn from(value: &Platform) -> Self {
let mut hasher = DefaultHasher::new();
- hasher.write(value.name().to_bytes());
+ hasher.write(value.name().as_bytes());
Self(hasher.finish())
}
}
diff --git a/plugins/warp/src/plugin/create.rs b/plugins/warp/src/plugin/create.rs
index 4beba195..e84e42ad 100644
--- a/plugins/warp/src/plugin/create.rs
+++ b/plugins/warp/src/plugin/create.rs
@@ -18,7 +18,7 @@ pub struct CreateSignatureFile;
impl Command for CreateSignatureFile {
fn action(&self, view: &BinaryView) {
let is_function_named = |f: &Guard<Function>| {
- !f.symbol().short_name().as_str().contains("sub_") || f.has_user_annotations()
+ !f.symbol().short_name().to_string_lossy().contains("sub_") || f.has_user_annotations()
};
let mut signature_dir = user_signature_dir();
if let Some(default_plat) = view.default_platform() {