summaryrefslogtreecommitdiff
path: root/plugins/pdb-ng
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/pdb-ng
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/pdb-ng')
-rw-r--r--plugins/pdb-ng/src/lib.rs12
-rw-r--r--plugins/pdb-ng/src/parser.rs10
-rw-r--r--plugins/pdb-ng/src/struct_grouper.rs10
-rw-r--r--plugins/pdb-ng/src/symbol_parser.rs4
-rw-r--r--plugins/pdb-ng/src/type_parser.rs10
5 files changed, 23 insertions, 23 deletions
diff --git a/plugins/pdb-ng/src/lib.rs b/plugins/pdb-ng/src/lib.rs
index 188b2ed5..a87a8076 100644
--- a/plugins/pdb-ng/src/lib.rs
+++ b/plugins/pdb-ng/src/lib.rs
@@ -13,7 +13,6 @@
// limitations under the License.
#![allow(dead_code)]
-use std::collections::HashMap;
use std::env::{current_dir, current_exe, temp_dir};
use std::io::Cursor;
use std::path::PathBuf;
@@ -31,7 +30,6 @@ use binaryninja::download_provider::{DownloadInstanceInputOutputCallbacks, Downl
use binaryninja::interaction::{MessageBoxButtonResult, MessageBoxButtonSet};
use binaryninja::logger::Logger;
use binaryninja::settings::{QueryOptions, Settings};
-use binaryninja::string::BnString;
use binaryninja::{interaction, user_directory};
use parser::PDBParserInstance;
@@ -196,7 +194,7 @@ fn read_from_sym_store(bv: &BinaryView, path: &str) -> Result<(bool, Vec<u8>)> {
.perform_custom_request(
"GET",
path,
- HashMap::<BnString, BnString>::new(),
+ vec![],
DownloadInstanceInputOutputCallbacks {
read: None,
write: Some(Box::new(write)),
@@ -278,21 +276,21 @@ fn search_sym_store(
}
fn parse_pdb_info(view: &BinaryView) -> Option<PDBInfo> {
- match view.get_metadata::<u64, _>("DEBUG_INFO_TYPE") {
+ match view.get_metadata::<u64>("DEBUG_INFO_TYPE") {
Some(Ok(0x53445352 /* 'SDSR' */)) => {}
_ => return None,
}
// This is stored in the BV by the PE loader
- let file_path = match view.get_metadata::<String, _>("PDB_FILENAME") {
+ let file_path = match view.get_metadata::<String>("PDB_FILENAME") {
Some(Ok(md)) => md,
_ => return None,
};
- let mut guid = match view.get_metadata::<Vec<u8>, _>("PDB_GUID") {
+ let mut guid = match view.get_metadata::<Vec<u8>>("PDB_GUID") {
Some(Ok(md)) => md,
_ => return None,
};
- let age = match view.get_metadata::<u64, _>("PDB_AGE") {
+ let age = match view.get_metadata::<u64>("PDB_AGE") {
Some(Ok(md)) => md as u32,
_ => return None,
};
diff --git a/plugins/pdb-ng/src/parser.rs b/plugins/pdb-ng/src/parser.rs
index 783a8a2d..2ca8e209 100644
--- a/plugins/pdb-ng/src/parser.rs
+++ b/plugins/pdb-ng/src/parser.rs
@@ -168,7 +168,8 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
) -> Result<()> {
self.parse_types(Self::split_progress(&progress, 0, &[1.0, 3.0, 0.5, 0.5]))?;
for (name, ty) in self.named_types.iter() {
- self.debug_info.add_type(name, ty.as_ref(), &[]); // TODO : Components
+ self.debug_info
+ .add_type(&name.to_string(), ty.as_ref(), &[]); // TODO : Components
}
info!(
@@ -406,7 +407,8 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
match class {
NamedTypeReferenceClass::UnknownNamedTypeClass
| NamedTypeReferenceClass::TypedefNamedTypeClass => {
- self.debug_info.add_type(&name, Type::void().as_ref(), &[]);
+ self.debug_info
+ .add_type(&name.to_string(), Type::void().as_ref(), &[]);
// TODO : Components
}
NamedTypeReferenceClass::ClassNamedTypeClass
@@ -429,7 +431,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
structure.alignment(1);
self.debug_info.add_type(
- &name,
+ &name.to_string(),
Type::structure(structure.finalize().as_ref()).as_ref(),
&[], // TODO : Components
);
@@ -437,7 +439,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
NamedTypeReferenceClass::EnumNamedTypeClass => {
let enumeration = EnumerationBuilder::new();
self.debug_info.add_type(
- &name,
+ &name.to_string(),
Type::enumeration(
enumeration.finalize().as_ref(),
self.arch.default_integer_size().try_into()?,
diff --git a/plugins/pdb-ng/src/struct_grouper.rs b/plugins/pdb-ng/src/struct_grouper.rs
index 09a81fa7..ff911afd 100644
--- a/plugins/pdb-ng/src/struct_grouper.rs
+++ b/plugins/pdb-ng/src/struct_grouper.rs
@@ -361,7 +361,7 @@ pub fn group_structure(
for member in members {
structure.insert(
&member.ty,
- member.name.clone(),
+ &member.name,
member.offset,
false,
member.access,
@@ -390,7 +390,7 @@ fn apply_groups(
if offset > member.offset {
structure.insert(
&member.ty,
- member.name.clone(),
+ &member.name,
0,
false,
member.access,
@@ -399,7 +399,7 @@ fn apply_groups(
} else {
structure.insert(
&member.ty,
- member.name.clone(),
+ &member.name,
member.offset - offset,
false,
member.access,
@@ -412,7 +412,7 @@ fn apply_groups(
apply_groups(members, &mut inner, children, inner_offset);
structure.insert(
&Conf::new(Type::structure(inner.finalize().as_ref()), MAX_CONFIDENCE),
- format!("__inner{}", i),
+ &format!("__inner{}", i),
inner_offset - offset,
false,
MemberAccess::PublicAccess,
@@ -425,7 +425,7 @@ fn apply_groups(
apply_groups(members, &mut inner, children, inner_offset);
structure.insert(
&Conf::new(Type::structure(inner.finalize().as_ref()), MAX_CONFIDENCE),
- format!("__inner{}", i),
+ &format!("__inner{}", i),
inner_offset - offset,
false,
MemberAccess::PublicAccess,
diff --git a/plugins/pdb-ng/src/symbol_parser.rs b/plugins/pdb-ng/src/symbol_parser.rs
index 6d6e978e..79049d03 100644
--- a/plugins/pdb-ng/src/symbol_parser.rs
+++ b/plugins/pdb-ng/src/symbol_parser.rs
@@ -2027,13 +2027,13 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
Some(X86(xreg)) => {
self.log(|| format!("Register {:?} ==> {:?}", reg, xreg));
self.arch
- .register_by_name(xreg.to_string().to_lowercase())
+ .register_by_name(&xreg.to_string().to_lowercase())
.map(|reg| reg.id())
}
Some(AMD64(areg)) => {
self.log(|| format!("Register {:?} ==> {:?}", reg, areg));
self.arch
- .register_by_name(areg.to_string().to_lowercase())
+ .register_by_name(&areg.to_string().to_lowercase())
.map(|reg| reg.id())
}
// TODO: Other arches
diff --git a/plugins/pdb-ng/src/type_parser.rs b/plugins/pdb-ng/src/type_parser.rs
index 61c64218..d4d5feb4 100644
--- a/plugins/pdb-ng/src/type_parser.rs
+++ b/plugins/pdb-ng/src/type_parser.rs
@@ -898,7 +898,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
bitfield_builder
.as_mut()
.expect("Invariant")
- .insert(&m.ty, m.name, 0, false, m.access, m.scope);
+ .insert(&m.ty, &m.name, 0, false, m.access, m.scope);
}
(None, None) => {
if let Some(mut builder) = bitfield_builder.take() {
@@ -1633,7 +1633,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
for field in fields {
match field {
ParsedType::Enumerate(member) => {
- enumeration.insert(member.name.clone(), member.value);
+ enumeration.insert(&member.name, member.value);
}
e => return Err(anyhow!("Unexpected enumerate member: {:?}", e)),
}
@@ -1803,7 +1803,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
if group.len() == 1 {
structure.insert(
&group[0].ty,
- group[0].name.clone(),
+ &group[0].name,
group[0].offset,
false,
group[0].access,
@@ -1814,7 +1814,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
for member in group {
inner_struct.insert(
&member.ty,
- member.name.clone(),
+ &member.name,
member.offset,
false,
member.access,
@@ -1826,7 +1826,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
Type::structure(inner_struct.finalize().as_ref()),
MAX_CONFIDENCE,
),
- format!("__inner{:x}", i),
+ &format!("__inner{:x}", i),
0,
false,
MemberAccess::PublicAccess,