1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
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, FunctionUpdateType};
use binaryninja::rc::Guard;
use binaryninja::tracing;
use rayon::iter::ParallelIterator;
use std::thread;
use warp::signature::function::FunctionGUID;
pub struct IncludeFunction;
impl FunctionCommand for IncludeFunction {
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(INCLUDE_TAG_NAME)).is_empty();
let insert_tag_type = get_warp_include_tag_type(view);
match should_add_tag {
true => {
tracing::info!(
"Including selected function '{}' at 0x{:x}",
sym_name_str,
func.start()
);
func.add_tag(&insert_tag_type, "", None, false, None);
}
false => {
tracing::info!(
"Removing included function '{}' at 0x{:x}",
sym_name_str,
func.start()
);
func.remove_tags_of_type(&insert_tag_type, None, false, None);
}
}
}
fn valid(&self, _view: &BinaryView, _func: &Function) -> bool {
// TODO: Only allow if the function is named?
true
}
}
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 => {
tracing::info!(
"Ignoring function for matching '{}' at 0x{:x}",
sym_name_str,
func.start()
);
func.add_tag(&ignore_tag_type, "", None, false, None);
}
false => {
tracing::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();
tracing::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 {
fn action(&self, _view: &BinaryView, func: &Function) {
let Some(guid) = cached_function_guid(func, || func.lifted_il().ok()) else {
tracing::error!("Could not get guid for copied function");
return;
};
tracing::info!(
"Function GUID for {:?}... {}",
func.symbol().short_name(),
guid
);
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(guid.to_string());
}
}
fn valid(&self, _view: &BinaryView, _func: &Function) -> bool {
true
}
}
pub struct FindFunctionFromGUID;
impl Command for FindFunctionFromGUID {
fn action(&self, view: &BinaryView) {
let Some(guid_str) = binaryninja::interaction::get_text_line_input(
"Function GUID",
"Find Function from GUID",
) else {
return;
};
let Ok(searched_guid) = guid_str.parse::<FunctionGUID>() else {
tracing::error!("Failed to parse function guid... {}", guid_str);
return;
};
tracing::info!("Searching functions for GUID... {}", searched_guid);
let funcs = view.functions();
let view = view.to_owned();
thread::spawn(move || {
let background_task = BackgroundTask::new(
&format!("Searching functions for GUID... {}", searched_guid),
false,
);
// Only run this for functions which have already generated a GUID.
let matched: Vec<Guard<Function>> = funcs
.par_iter()
.filter(|func| {
try_cached_function_guid(func).is_some_and(|guid| guid == searched_guid)
})
.collect();
if matched.is_empty() {
tracing::info!("No matches found for GUID... {}", searched_guid);
} else {
for func in &matched {
// Also navigate the user, as that is probably what they want.
if matched.len() == 1 {
let current_view = view.file().current_view();
if view
.file()
.navigate_to(¤t_view, func.start())
.is_err()
{
tracing::error!(
"Failed to navigate to found function 0x{:0x} in view {}",
func.start(),
current_view
);
}
}
tracing::info!("Match found at function... 0x{:0x}", func.start());
}
}
background_task.finish();
});
}
fn valid(&self, _view: &BinaryView) -> bool {
true
}
}
|