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

Method action

plugins/warp/src/plugin/load.rs:7–51  ·  view source on GitHub ↗
(&self, view: &BinaryView)

Source from the content-addressed store, hash-verified

5
6impl Command for LoadSignatureFile {
7 fn action(&self, view: &BinaryView) {
8 let Some(platform) = view.default_platform() else {
9 log::error!("Default platform must be set to load signature!");
10 return;
11 };
12
13 // NOTE: Because we only can consume signatures from a specific directory, we don't need to use the interaction API.
14 // If we did need to load signature files from a project than this would need to change.
15 let Some(file) = rfd::FileDialog::new()
16 .add_filter("Signature Files", &["sbin"])
17 .set_file_name(format!("{}.sbin", view.file().filename()))
18 .pick_file()
19 else {
20 return;
21 };
22
23 let Ok(data) = std::fs::read(&file) else {
24 log::error!("Could not read signature file: {:?}", file);
25 return;
26 };
27
28 let Some(data) = warp::signature::Data::from_bytes(&data) else {
29 log::error!("Could not get data from signature file: {:?}", file);
30 return;
31 };
32
33 let new_matcher = Matcher::from_data(data);
34 log::info!(
35 "Loading signature file with {} functions and {} types...",
36 new_matcher.functions.len(),
37 new_matcher.types.len()
38 );
39 let platform_id = PlatformID::from(platform.as_ref());
40 let matcher_cache = PLAT_MATCHER_CACHE.get_or_init(Default::default);
41 match matcher_cache.get_mut(&platform_id) {
42 Some(mut matcher) => matcher.extend_with_matcher(new_matcher),
43 None => {
44 // We still must uphold `from_platform` in case we are running this before the matcher workflow
45 // is kicked off. Other-wise we only will have the `new_matcher` data.
46 let mut matcher = Matcher::from_platform(platform);
47 matcher.extend_with_matcher(new_matcher);
48 matcher_cache.insert(platform_id, matcher);
49 }
50 }
51 }
52
53 fn valid(&self, _view: &BinaryView) -> bool {
54 true

Callers

nothing calls this directly

Calls 4

default_platformMethod · 0.80
extend_with_matcherMethod · 0.80
as_refMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected