diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-07 19:22:21 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 2f214f6c9935e8ce8df4732cde44a540a003258c (patch) | |
| tree | 6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /plugins/idb_import/src | |
| parent | b4cf0be8816182c9efca037e27e9439482f8bf36 (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/idb_import/src')
| -rw-r--r-- | plugins/idb_import/src/lib.rs | 9 | ||||
| -rw-r--r-- | plugins/idb_import/src/types.rs | 8 |
2 files changed, 7 insertions, 10 deletions
diff --git a/plugins/idb_import/src/lib.rs b/plugins/idb_import/src/lib.rs index c554831d..46acfd42 100644 --- a/plugins/idb_import/src/lib.rs +++ b/plugins/idb_import/src/lib.rs @@ -198,7 +198,7 @@ pub fn import_til_section( if let TranslateTypeResult::Translated(bn_ty) | TranslateTypeResult::PartiallyTranslated(bn_ty, _) = &ty.ty { - if !debug_info.add_type(ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) { + if !debug_info.add_type(&ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) { error!("Unable to add type `{}`", ty.name.as_utf8_lossy()) } } @@ -209,7 +209,7 @@ pub fn import_til_section( if let TranslateTypeResult::Translated(bn_ty) | TranslateTypeResult::PartiallyTranslated(bn_ty, _) = &ty.ty { - if !debug_info.add_type(ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) { + if !debug_info.add_type(&ty.name.as_utf8_lossy(), bn_ty, &[/* TODO */]) { error!("Unable to fix type `{}`", ty.name.as_utf8_lossy()) } } @@ -239,10 +239,7 @@ fn parse_id0_section_info( } = info; // TODO set comments to address here for function in &bv.functions_containing(addr) { - function.set_comment_at( - addr, - String::from_utf8_lossy(&comments.join(&b"\n"[..])).to_string(), - ); + function.set_comment_at(addr, &String::from_utf8_lossy(&comments.join(&b"\n"[..]))); } let bnty = ty diff --git a/plugins/idb_import/src/types.rs b/plugins/idb_import/src/types.rs index 7b4ca675..b3c9bea0 100644 --- a/plugins/idb_import/src/types.rs +++ b/plugins/idb_import/src/types.rs @@ -335,7 +335,7 @@ impl<F: Fn(usize, usize) -> Result<(), ()>> TranslateIDBTypes<'_, F> { format!("bitfield_{}_{}", offset + start_idx, offset + (i - 1)) }; let field = field_from_bytes(bytes); - struct_builder.append(&field, name, MemberAccess::NoAccess, MemberScope::NoScope); + struct_builder.append(&field, &name, MemberAccess::NoAccess, MemberScope::NoScope); }; for (i, member) in members { @@ -423,7 +423,7 @@ impl<F: Fn(usize, usize) -> Result<(), ()>> TranslateIDBTypes<'_, F> { .as_ref() .map(|name| name.as_utf8_lossy().to_string()) .unwrap_or_else(|| format!("member_{i}")); - structure.append(&mem, name, MemberAccess::NoAccess, MemberScope::NoScope); + structure.append(&mem, &name, MemberAccess::NoAccess, MemberScope::NoScope); } if let Some(start_idx) = first_bitfield_seq { let members_bitrange = &ty_struct.members[start_idx..]; @@ -470,7 +470,7 @@ impl<F: Fn(usize, usize) -> Result<(), ()>> TranslateIDBTypes<'_, F> { .as_ref() .map(|name| name.as_utf8_lossy().to_string()) .unwrap_or_else(|| format!("member_{i}")); - structure.append(&mem, name, MemberAccess::NoAccess, MemberScope::NoScope); + structure.append(&mem, &name, MemberAccess::NoAccess, MemberScope::NoScope); } let str_ref = structure.finalize(); @@ -492,7 +492,7 @@ impl<F: Fn(usize, usize) -> Result<(), ()>> TranslateIDBTypes<'_, F> { .as_ref() .map(|name| name.as_utf8_lossy().to_string()) .unwrap_or_else(|| format!("member_{i}")); - eb.insert(name, member.value); + eb.insert(&name, member.value); } Type::enumeration( &eb.finalize(), |
