summaryrefslogtreecommitdiff
path: root/plugins/warp/src/plugin/function.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-10-12 22:46:54 -0400
committerMason Reed <mason@vector35.com>2025-10-12 22:50:20 -0400
commit40f7d40e394657575001a8146d8233f1fc4356fd (patch)
treea1dfac7f90bbd284119d0a3e10e205fe2e0303c1 /plugins/warp/src/plugin/function.rs
parent49558b88ed5dacaac0bdf1946291bc37a4a88cb9 (diff)
[WARP] Improve UX surrounding removal of matched functions
- Adds Python API to remove matched function - Adds command + UI actions to remove matched function - Adds command + UI actions to ignore function in subsequent matches
Diffstat (limited to 'plugins/warp/src/plugin/function.rs')
-rw-r--r--plugins/warp/src/plugin/function.rs65
1 files changed, 62 insertions, 3 deletions
diff --git a/plugins/warp/src/plugin/function.rs b/plugins/warp/src/plugin/function.rs
index a4fd2c10..6202f9d7 100644
--- a/plugins/warp/src/plugin/function.rs
+++ b/plugins/warp/src/plugin/function.rs
@@ -1,9 +1,14 @@
-use crate::cache::{cached_function_guid, try_cached_function_guid};
-use crate::{get_warp_include_tag_type, INCLUDE_TAG_NAME};
+use crate::cache::{
+ cached_function_guid, insert_cached_function_match, try_cached_function_guid,
+ try_cached_function_match,
+};
+use crate::{
+ get_warp_ignore_tag_type, get_warp_include_tag_type, IGNORE_TAG_NAME, INCLUDE_TAG_NAME,
+};
use binaryninja::background_task::BackgroundTask;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::command::{Command, FunctionCommand};
-use binaryninja::function::Function;
+use binaryninja::function::{Function, FunctionUpdateType};
use binaryninja::rc::Guard;
use rayon::iter::ParallelIterator;
use std::thread;
@@ -43,6 +48,60 @@ impl FunctionCommand for IncludeFunction {
}
}
+pub struct IgnoreFunction;
+
+impl FunctionCommand for IgnoreFunction {
+ fn action(&self, view: &BinaryView, func: &Function) {
+ let sym_name = func.symbol().short_name();
+ let sym_name_str = sym_name.to_string_lossy();
+ let should_add_tag = func.function_tags(None, Some(IGNORE_TAG_NAME)).is_empty();
+ let ignore_tag_type = get_warp_ignore_tag_type(view);
+ match should_add_tag {
+ true => {
+ log::info!(
+ "Ignoring function for matching '{}' at 0x{:x}",
+ sym_name_str,
+ func.start()
+ );
+ func.add_tag(&ignore_tag_type, "", None, false, None);
+ }
+ false => {
+ log::info!(
+ "Including function for matching '{}' at 0x{:x}",
+ sym_name_str,
+ func.start()
+ );
+ func.remove_tags_of_type(&ignore_tag_type, None, false, None);
+ }
+ }
+ }
+
+ fn valid(&self, _view: &BinaryView, _func: &Function) -> bool {
+ true
+ }
+}
+
+pub struct RemoveFunction;
+
+impl FunctionCommand for RemoveFunction {
+ fn action(&self, _view: &BinaryView, func: &Function) {
+ let sym_name = func.symbol().short_name();
+ let sym_name_str = sym_name.to_string_lossy();
+ log::info!(
+ "Removing matched function '{}' at 0x{:x}",
+ sym_name_str,
+ func.start()
+ );
+ insert_cached_function_match(func, None);
+ func.reanalyze(FunctionUpdateType::UserFunctionUpdate);
+ }
+
+ fn valid(&self, _view: &BinaryView, func: &Function) -> bool {
+ // Only allow if the function actually has a match.
+ try_cached_function_match(func).is_some()
+ }
+}
+
pub struct CopyFunctionGUID;
impl FunctionCommand for CopyFunctionGUID {