|
1 | | -use crate::cache::{cached_function_guid, try_cached_function_guid}; |
2 | | -use crate::{get_warp_include_tag_type, INCLUDE_TAG_NAME}; |
| 1 | +use crate::cache::{ |
| 2 | + cached_function_guid, insert_cached_function_match, try_cached_function_guid, |
| 3 | + try_cached_function_match, |
| 4 | +}; |
| 5 | +use crate::{ |
| 6 | + get_warp_ignore_tag_type, get_warp_include_tag_type, IGNORE_TAG_NAME, INCLUDE_TAG_NAME, |
| 7 | +}; |
3 | 8 | use binaryninja::background_task::BackgroundTask; |
4 | 9 | use binaryninja::binary_view::{BinaryView, BinaryViewExt}; |
5 | 10 | use binaryninja::command::{Command, FunctionCommand}; |
6 | | -use binaryninja::function::Function; |
| 11 | +use binaryninja::function::{Function, FunctionUpdateType}; |
7 | 12 | use binaryninja::rc::Guard; |
8 | 13 | use rayon::iter::ParallelIterator; |
9 | 14 | use std::thread; |
@@ -43,6 +48,60 @@ impl FunctionCommand for IncludeFunction { |
43 | 48 | } |
44 | 49 | } |
45 | 50 |
|
| 51 | +pub struct IgnoreFunction; |
| 52 | + |
| 53 | +impl FunctionCommand for IgnoreFunction { |
| 54 | + fn action(&self, view: &BinaryView, func: &Function) { |
| 55 | + let sym_name = func.symbol().short_name(); |
| 56 | + let sym_name_str = sym_name.to_string_lossy(); |
| 57 | + let should_add_tag = func.function_tags(None, Some(IGNORE_TAG_NAME)).is_empty(); |
| 58 | + let ignore_tag_type = get_warp_ignore_tag_type(view); |
| 59 | + match should_add_tag { |
| 60 | + true => { |
| 61 | + log::info!( |
| 62 | + "Ignoring function for matching '{}' at 0x{:x}", |
| 63 | + sym_name_str, |
| 64 | + func.start() |
| 65 | + ); |
| 66 | + func.add_tag(&ignore_tag_type, "", None, false, None); |
| 67 | + } |
| 68 | + false => { |
| 69 | + log::info!( |
| 70 | + "Including function for matching '{}' at 0x{:x}", |
| 71 | + sym_name_str, |
| 72 | + func.start() |
| 73 | + ); |
| 74 | + func.remove_tags_of_type(&ignore_tag_type, None, false, None); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + fn valid(&self, _view: &BinaryView, _func: &Function) -> bool { |
| 80 | + true |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +pub struct RemoveFunction; |
| 85 | + |
| 86 | +impl FunctionCommand for RemoveFunction { |
| 87 | + fn action(&self, _view: &BinaryView, func: &Function) { |
| 88 | + let sym_name = func.symbol().short_name(); |
| 89 | + let sym_name_str = sym_name.to_string_lossy(); |
| 90 | + log::info!( |
| 91 | + "Removing matched function '{}' at 0x{:x}", |
| 92 | + sym_name_str, |
| 93 | + func.start() |
| 94 | + ); |
| 95 | + insert_cached_function_match(func, None); |
| 96 | + func.reanalyze(FunctionUpdateType::UserFunctionUpdate); |
| 97 | + } |
| 98 | + |
| 99 | + fn valid(&self, _view: &BinaryView, func: &Function) -> bool { |
| 100 | + // Only allow if the function actually has a match. |
| 101 | + try_cached_function_match(func).is_some() |
| 102 | + } |
| 103 | +} |
| 104 | + |
46 | 105 | pub struct CopyFunctionGUID; |
47 | 106 |
|
48 | 107 | impl FunctionCommand for CopyFunctionGUID { |
|
0 commit comments