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/warp/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/warp/src')
| -rw-r--r-- | plugins/warp/src/convert.rs | 6 | ||||
| -rw-r--r-- | plugins/warp/src/matcher.rs | 14 | ||||
| -rw-r--r-- | plugins/warp/src/plugin.rs | 2 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/create.rs | 4 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/find.rs | 2 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/types.rs | 4 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/workflow.rs | 4 |
7 files changed, 18 insertions, 18 deletions
diff --git a/plugins/warp/src/convert.rs b/plugins/warp/src/convert.rs index 2e0fb3f1..b6c2f7b4 100644 --- a/plugins/warp/src/convert.rs +++ b/plugins/warp/src/convert.rs @@ -431,7 +431,7 @@ pub fn to_bn_type<A: BNArchitecture>(arch: &A, ty: &Type) -> BNRef<BNType> { let base_struct_ntr = match c.guid { Some(guid) => BNNamedTypeReference::new_with_id( NamedTypeReferenceClass::UnknownNamedTypeClass, - guid.to_string(), + &guid.to_string(), base_struct_ntr_name, ), None => BNNamedTypeReference::new( @@ -475,7 +475,7 @@ pub fn to_bn_type<A: BNArchitecture>(arch: &A, ty: &Type) -> BNRef<BNType> { // TODO: Add default name? let member_name = member.name.to_owned().unwrap_or("enum_VAL".into()); let member_value = member.constant; - builder.insert(member_name, member_value); + builder.insert(&member_name, member_value); } // TODO: Warn if enumeration has no size. let width = bits_to_bytes(c.member_type.size().unwrap()) as usize; @@ -545,7 +545,7 @@ pub fn to_bn_type<A: BNArchitecture>(arch: &A, ty: &Type) -> BNRef<BNType> { let ntr_name = c.name.to_owned().unwrap_or(guid_str.clone()); NamedTypeReference::new_with_id( NamedTypeReferenceClass::UnknownNamedTypeClass, - guid_str, + &guid_str, ntr_name, ) } diff --git a/plugins/warp/src/matcher.rs b/plugins/warp/src/matcher.rs index 6352cd7a..0ce258ad 100644 --- a/plugins/warp/src/matcher.rs +++ b/plugins/warp/src/matcher.rs @@ -159,7 +159,7 @@ impl Matcher { if let Some(ref_guid) = c.guid { // NOTE: We do not need to check for cyclic reference here because // NOTE: GUID references are unable to be referenced by themselves. - if view.type_by_id(ref_guid.to_string()).is_none() { + if view.type_by_id(&ref_guid.to_string()).is_none() { // Add the referrer to the view if it is in the Matcher types if let Some(ref_ty) = matcher.types.get(&ref_guid) { inner_add_type_to_view(matcher, view, arch, visited_refs, &ref_ty); @@ -186,7 +186,7 @@ impl Matcher { // All nested types _should_ be added now, we can add this type. // TODO: Do we want to make unnamed types visible? I think we should, but some people might be opposed. let ty_name = ty.name.to_owned().unwrap_or_else(|| ty_id_str.clone()); - view.define_auto_type_with_id(ty_name, ty_id_str, &to_bn_type(arch, ty)); + view.define_auto_type_with_id(ty_name, &ty_id_str, &to_bn_type(arch, ty)); } _ => {} } @@ -409,7 +409,7 @@ impl MatcherSettings { }); bn_settings.register_setting_json( Self::TRIVIAL_FUNCTION_LEN_SETTING, - trivial_function_len_props.to_string(), + &trivial_function_len_props.to_string(), ); let minimum_function_len_props = json!({ @@ -421,7 +421,7 @@ impl MatcherSettings { }); bn_settings.register_setting_json( Self::MINIMUM_FUNCTION_LEN_SETTING, - minimum_function_len_props.to_string(), + &minimum_function_len_props.to_string(), ); let maximum_function_len_props = json!({ @@ -433,7 +433,7 @@ impl MatcherSettings { }); bn_settings.register_setting_json( Self::MAXIMUM_FUNCTION_LEN_SETTING, - maximum_function_len_props.to_string(), + &maximum_function_len_props.to_string(), ); let minimum_matched_constraints_props = json!({ @@ -445,7 +445,7 @@ impl MatcherSettings { }); bn_settings.register_setting_json( Self::MINIMUM_MATCHED_CONSTRAINTS_SETTING, - minimum_matched_constraints_props.to_string(), + &minimum_matched_constraints_props.to_string(), ); let trivial_function_adjacent_allowed_props = json!({ @@ -457,7 +457,7 @@ impl MatcherSettings { }); bn_settings.register_setting_json( Self::TRIVIAL_FUNCTION_ADJACENT_ALLOWED_SETTING, - trivial_function_adjacent_allowed_props.to_string(), + &trivial_function_adjacent_allowed_props.to_string(), ); } diff --git a/plugins/warp/src/plugin.rs b/plugins/warp/src/plugin.rs index b84173f7..ec903f9c 100644 --- a/plugins/warp/src/plugin.rs +++ b/plugins/warp/src/plugin.rs @@ -52,7 +52,7 @@ pub fn on_matched_function(function: &Function, matched: &WarpFunction) { // TODO: Add metadata. (both binja metadata and warp metadata) function.add_tag( &get_warp_tag_type(&view), - matched.guid.to_string(), + &matched.guid.to_string(), None, true, None, diff --git a/plugins/warp/src/plugin/create.rs b/plugins/warp/src/plugin/create.rs index e84e42ad..1dd83e6e 100644 --- a/plugins/warp/src/plugin/create.rs +++ b/plugins/warp/src/plugin/create.rs @@ -31,7 +31,7 @@ impl Command for CreateSignatureFile { let total_functions = view.functions().len(); let done_functions = AtomicUsize::default(); let background_task = binaryninja::background_task::BackgroundTask::new( - format!("Generating signatures... ({}/{})", 0, total_functions), + &format!("Generating signatures... ({}/{})", 0, total_functions), true, ); @@ -43,7 +43,7 @@ impl Command for CreateSignatureFile { .par_iter() .inspect(|_| { done_functions.fetch_add(1, Relaxed); - background_task.set_progress_text(format!( + background_task.set_progress_text(&format!( "Generating signatures... ({}/{})", done_functions.load(Relaxed), total_functions diff --git a/plugins/warp/src/plugin/find.rs b/plugins/warp/src/plugin/find.rs index b2102e5e..accc015d 100644 --- a/plugins/warp/src/plugin/find.rs +++ b/plugins/warp/src/plugin/find.rs @@ -27,7 +27,7 @@ impl Command for FindFunctionFromGUID { let funcs = view.functions(); thread::spawn(move || { let background_task = binaryninja::background_task::BackgroundTask::new( - format!("Searching functions for GUID... {}", searched_guid), + &format!("Searching functions for GUID... {}", searched_guid), false, ); diff --git a/plugins/warp/src/plugin/types.rs b/plugins/warp/src/plugin/types.rs index 057d5f98..41e03cd3 100644 --- a/plugins/warp/src/plugin/types.rs +++ b/plugins/warp/src/plugin/types.rs @@ -35,7 +35,7 @@ impl Command for LoadTypes { let view = view.to_owned(); std::thread::spawn(move || { let background_task = binaryninja::background_task::BackgroundTask::new( - format!("Applying {} types...", data.types.len()), + &format!("Applying {} types...", data.types.len()), true, ); @@ -43,7 +43,7 @@ impl Command for LoadTypes { for comp_ty in data.types { let ty_id = comp_ty.guid.to_string(); let ty_name = comp_ty.ty.name.to_owned().unwrap_or_else(|| ty_id.clone()); - view.define_auto_type_with_id(ty_name, ty_id, &to_bn_type(&arch, &comp_ty.ty)); + view.define_auto_type_with_id(ty_name, &ty_id, &to_bn_type(&arch, &comp_ty.ty)); } log::info!("Type application took {:?}", start.elapsed()); diff --git a/plugins/warp/src/plugin/workflow.rs b/plugins/warp/src/plugin/workflow.rs index 5a857fbb..9f7c4d0d 100644 --- a/plugins/warp/src/plugin/workflow.rs +++ b/plugins/warp/src/plugin/workflow.rs @@ -44,7 +44,7 @@ impl Command for RunMatcher { .for_each(|function| cached_function_matcher(&function)); log::info!("Function matching took {:?}", start.elapsed()); background_task.finish(); - view.file().commit_undo_actions(undo_id); + view.file().commit_undo_actions(&undo_id); // Now we want to trigger re-analysis. view.update_analysis(); }); @@ -66,7 +66,7 @@ pub fn insert_workflow() { .for_each(|function| cached_function_matcher(&function)); log::info!("Function matching took {:?}", start.elapsed()); background_task.finish(); - view.file().commit_undo_actions(undo_id); + view.file().commit_undo_actions(&undo_id); // Now we want to trigger re-analysis. view.update_analysis(); }; |
