diff options
Diffstat (limited to 'plugins/warp/src/plugin/function.rs')
| -rw-r--r-- | plugins/warp/src/plugin/function.rs | 65 |
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 { |
