diff options
Diffstat (limited to 'plugins/warp/src/plugin/create.rs')
| -rw-r--r-- | plugins/warp/src/plugin/create.rs | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/plugins/warp/src/plugin/create.rs b/plugins/warp/src/plugin/create.rs index 70abcba9..beb866d8 100644 --- a/plugins/warp/src/plugin/create.rs +++ b/plugins/warp/src/plugin/create.rs @@ -5,11 +5,11 @@ use binaryninja::command::Command; use binaryninja::function::Function; use binaryninja::rc::Guard; use rayon::prelude::*; -use std::io::Write; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; use std::thread; use std::time::Instant; +use crate::user_signature_dir; pub struct CreateSignatureFile; @@ -20,10 +20,10 @@ impl Command for CreateSignatureFile { let is_function_named = |f: &Guard<Function>| { !f.symbol().short_name().as_str().contains("sub_") || f.has_user_annotations() }; - - let mut signature_dir = binaryninja::user_directory().unwrap().join("signatures/"); + let mut signature_dir = user_signature_dir(); if let Some(default_plat) = view.default_platform() { // If there is a default platform, put the signature in there. + // TODO: We should instead use the platform of the function. signature_dir.push(default_plat.name().to_string()); } let view = view.to_owned(); @@ -69,29 +69,26 @@ impl Command for CreateSignatureFile { } log::info!("Signature generation took {:?}", start.elapsed()); + background_task.finish(); - if let Some(sig_file_name) = binaryninja::interaction::get_text_line_input( - "Signature File", - "Create Signature File", - ) { - let save_file = signature_dir.join(sig_file_name + ".sbin"); - log::info!("Saving to signatures to {:?}...", &save_file); - // TODO: Should we overwrite? Prompt user. - if let Ok(mut file) = std::fs::File::create(&save_file) { - match file.write_all(&data.to_bytes()) { - Ok(_) => { - log::info!("Signature file saved successfully."); - // Force rebuild platform matcher. - invalidate_function_matcher_cache(); - } - Err(e) => log::error!("Failed to write data to signature file: {:?}", e), - } - } else { - log::error!("Could not create signature file: {:?}", save_file); + // NOTE: Because we only can consume signatures from a specific directory, we don't need to use the interaction API. + // If we did need to save signature files to a project than this would need to change. + let Some(save_file) = rfd::FileDialog::new() + .add_filter("Signature Files", &["sbin"]) + .set_file_name(format!("{}.sbin", view.file().filename().to_string())) + .set_directory(signature_dir) + .save_file() else { + return; + }; + + match std::fs::write(&save_file, data.to_bytes()) { + Ok(_) => { + log::info!("Signature file saved successfully."); + // Force rebuild platform matcher. + invalidate_function_matcher_cache(); } + Err(e) => log::error!("Failed to write data to signature file: {:?}", e), } - - background_task.finish(); }); } |
