MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / action

Method action

plugins/warp/src/plugin/add.rs:12–67  ·  view source on GitHub ↗
(&self, view: &BinaryView, func: &Function)

Source from the content-addressed store, hash-verified

10
11impl FunctionCommand for AddFunctionSignature {
12 fn action(&self, view: &BinaryView, func: &Function) {
13 let func_plat_name = func.platform().name().to_string();
14 let signature_dir = user_signature_dir().join(func_plat_name);
15 let view = view.to_owned();
16 let func = func.to_owned();
17 thread::spawn(move || {
18 let Ok(llil) = func.low_level_il() else {
19 log::error!("Could not get low level IL for function.");
20 return;
21 };
22
23 // NOTE: Because we only can consume signatures from a specific directory, we don't need to use the interaction API.
24 // If we did need to save signature files to a project than this would need to change.
25 let Some(save_file) = rfd::FileDialog::new()
26 .add_filter("Signature Files", &["sbin"])
27 .set_file_name("user.sbin")
28 .set_directory(signature_dir)
29 .save_file()
30 else {
31 return;
32 };
33
34 let mut data = warp::signature::Data::default();
35 if let Ok(file_bytes) = std::fs::read(&save_file) {
36 // If the file we are adding the function to already has data we should preserve it!
37 log::info!("Signature file already exists, preserving data...");
38 let Some(file_data) = warp::signature::Data::from_bytes(&file_bytes) else {
39 log::error!("Could not get data from signature file: {:?}", save_file);
40 return;
41 };
42 data = file_data;
43 };
44
45 // Now add our function to the data.
46 data.functions.push(cached_function(&func, &llil));
47
48 if let Some(ref_ty_cache) = cached_type_references(&view) {
49 let referenced_types = ref_ty_cache
50 .cache
51 .iter()
52 .filter_map(|t| t.to_owned())
53 .collect::<Vec<_>>();
54
55 data.types.extend(referenced_types);
56 }
57
58 match std::fs::write(&save_file, data.to_bytes()) {
59 Ok(_) => {
60 log::info!("Signature file saved successfully.");
61 // Force rebuild platform matcher.
62 invalidate_function_matcher_cache();
63 }
64 Err(e) => log::error!("Failed to write data to signature file: {:?}", e),
65 }
66 });
67 }
68
69 fn valid(&self, _view: &BinaryView, _func: &Function) -> bool {

Callers

nothing calls this directly

Calls 11

user_signature_dirFunction · 0.85
cached_functionFunction · 0.85
cached_type_referencesFunction · 0.85
joinMethod · 0.80
nameMethod · 0.45
platformMethod · 0.45
to_ownedMethod · 0.45
low_level_ilMethod · 0.45
pushMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected