summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2024-11-04 01:48:03 -0500
committerMason Reed <mason@vector35.com>2024-11-04 01:48:03 -0500
commit7743af0603a2568ad28a1b152153eabce8c52dd7 (patch)
tree082d2e33e321fa453c4b6230e679e89d87c19ef6 /plugins
parent393c7fb508b465b0cb096d46eaaefc08030e9fed (diff)
WARP: Misc formatting and remove useless apply command
Diffstat (limited to 'plugins')
-rw-r--r--plugins/warp/src/cache.rs6
-rw-r--r--plugins/warp/src/matcher.rs1
-rw-r--r--plugins/warp/src/plugin.rs17
-rw-r--r--plugins/warp/src/plugin/apply.rs82
-rw-r--r--plugins/warp/src/plugin/find.rs2
5 files changed, 12 insertions, 96 deletions
diff --git a/plugins/warp/src/cache.rs b/plugins/warp/src/cache.rs
index 9364de0d..025c37df 100644
--- a/plugins/warp/src/cache.rs
+++ b/plugins/warp/src/cache.rs
@@ -199,14 +199,16 @@ impl GUIDCache {
// Call site is a function, constrain on it.
let cs_ref_func_id = FunctionID::from(cs_ref_func.as_ref());
if cs_ref_func_id != func_id {
- let call_site_offset: i64 = call_site.address.wrapping_sub(func_start) as i64;
+ let call_site_offset: i64 =
+ call_site.address.wrapping_sub(func_start) as i64;
constraints
.insert(self.function_constraint(&cs_ref_func, call_site_offset));
}
}
Err(_) => {
// We could be dealing with an extern symbol, get the symbol as a constraint.
- let call_site_offset: i64 = call_site.address.wrapping_sub(func_start) as i64;
+ let call_site_offset: i64 =
+ call_site.address.wrapping_sub(func_start) as i64;
if let Ok(call_site_sym) = view.symbol_by_address(cs_ref_addr) {
constraints.insert(
self.function_constraint_from_symbol(
diff --git a/plugins/warp/src/matcher.rs b/plugins/warp/src/matcher.rs
index 823ac2aa..91405381 100644
--- a/plugins/warp/src/matcher.rs
+++ b/plugins/warp/src/matcher.rs
@@ -76,6 +76,7 @@ impl Matcher {
let user_dir = binaryninja::user_directory().unwrap();
let root_user_sig_dir = user_dir.join("signatures");
let plat_user_sig_dir = root_user_sig_dir.join(&platform_name);
+ // If the dir has not been created, create it.
let user_data = get_data_from_dir(&plat_user_sig_dir);
data.extend(user_data);
diff --git a/plugins/warp/src/plugin.rs b/plugins/warp/src/plugin.rs
index ee9c633b..a2d1bf5f 100644
--- a/plugins/warp/src/plugin.rs
+++ b/plugins/warp/src/plugin.rs
@@ -1,20 +1,19 @@
use log::LevelFilter;
-use crate::{build_function, cache};
use crate::cache::{
register_cache_destructor, ViewID, FUNCTION_CACHE, GUID_CACHE, MATCHED_FUNCTION_CACHE,
};
use crate::convert::{to_bn_symbol_at_address, to_bn_type};
use crate::matcher::{invalidate_function_matcher_cache, Matcher, PlatformID, PLAT_MATCHER_CACHE};
+use crate::{build_function, cache};
use binaryninja::binaryview::{BinaryView, BinaryViewExt};
use binaryninja::command::{Command, FunctionCommand};
use binaryninja::function::{Function, FunctionUpdateType};
use binaryninja::rc::Ref;
use binaryninja::tags::TagType;
-use warp::signature::function::Function as WarpFunction;
use binaryninja::ObjectDestructor;
+use warp::signature::function::Function as WarpFunction;
-mod apply;
mod copy;
mod create;
mod find;
@@ -82,7 +81,10 @@ impl FunctionCommand for DebugMatcher {
if let Some(possible_matches) = matcher.functions.get(&func.guid) {
log::info!("{:#?}", possible_matches.value());
} else {
- log::error!("No possible matches found for the function 0x{:x}", function.start());
+ log::error!(
+ "No possible matches found for the function 0x{:x}",
+ function.start()
+ );
};
}
@@ -169,7 +171,6 @@ pub extern "C" fn CorePluginInit() -> bool {
DebugInvalidateCache {},
);
-
binaryninja::command::register_for_function(
"WARP\\Debug\\Function Signature",
"Print the entire signature for the function",
@@ -206,11 +207,5 @@ pub extern "C" fn CorePluginInit() -> bool {
create::CreateSignatureFile {},
);
- // binaryninja::command::register(
- // "WARP\\Apply Signature File",
- // "Applies a signature file to the current view",
- // apply::ApplySignatureFile {},
- // );
-
true
}
diff --git a/plugins/warp/src/plugin/apply.rs b/plugins/warp/src/plugin/apply.rs
deleted file mode 100644
index 78cb3be8..00000000
--- a/plugins/warp/src/plugin/apply.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-use std::collections::HashMap;
-use std::time::Instant;
-
-use crate::cache::cached_function_guid;
-use crate::plugin::on_matched_function;
-use binaryninja::binaryview::{BinaryView, BinaryViewExt};
-use binaryninja::command::Command;
-use rayon::prelude::*;
-use warp::signature::function::{Function, FunctionGUID};
-
-pub struct ApplySignatureFile;
-
-// TODO: All this should do is insert data into the Matcher. this is leftover code.
-impl Command for ApplySignatureFile {
- fn action(&self, view: &BinaryView) {
- // TODO: Start bulk modification
- // TODO: view.begin_bulk_modify_symbols();
- let Some(file) =
- binaryninja::interaction::get_open_filename_input("Apply Signature File", "*.sbin")
- else {
- return;
- };
-
- // TODO: signature files also need to store type information.
-
- let Ok(data) = std::fs::read(&file) else {
- log::error!("Could not read signature file: {:?}", file);
- return;
- };
-
- let Some(data) = warp::signature::Data::from_bytes(&data) else {
- log::error!("Could not get data from signature file: {:?}", file);
- return;
- };
-
- // TODO: Turn Vec<Function> to HashSet so that functions with the same symbol and type get eliminated.
- let data_functions: HashMap<FunctionGUID, Vec<Function>> =
- data.functions
- .into_iter()
- .fold(HashMap::new(), |mut acc, func| {
- #[allow(clippy::unwrap_or_default)]
- acc.entry(func.guid).or_insert_with(Vec::new).push(func);
- acc
- });
-
- let background_task = binaryninja::backgroundtask::BackgroundTask::new(
- format!("Applying signatures from {:?}", file),
- true,
- )
- .unwrap();
-
- let funcs = view.functions();
- let start = Instant::now();
-
- background_task
- .set_progress_text(format!("Building {} patterns to lookup...", funcs.len()));
-
- // TODO: Redo this.
- let single_matched = funcs
- .par_iter()
- .filter_map(|func| {
- let llil = func.low_level_il_if_available()?;
- let pattern = cached_function_guid(&func, &llil);
- Some((func, data_functions.get(&pattern)?))
- })
- .filter(|(_, sig)| sig.len() == 1)
- .collect::<Vec<_>>();
-
- background_task.set_progress_text(format!("Applying {} matches...", single_matched.len()));
- for (func, matched) in single_matched {
- on_matched_function(&func, &matched[0]);
- }
-
- log::info!("Signature application took {:?}", start.elapsed());
-
- background_task.finish();
- }
-
- fn valid(&self, _view: &BinaryView) -> bool {
- true
- }
-}
diff --git a/plugins/warp/src/plugin/find.rs b/plugins/warp/src/plugin/find.rs
index 3a14f7fb..7eb0ab38 100644
--- a/plugins/warp/src/plugin/find.rs
+++ b/plugins/warp/src/plugin/find.rs
@@ -47,7 +47,7 @@ impl Command for FindFunctionFromGUID {
} else {
for (func, _) in matched {
log::info!("Match found at function... 0x{:0x}", func.start());
- }
+ }
}
background_task.finish();