diff options
| author | Mason Reed <mason@vector35.com> | 2025-07-15 06:12:37 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-07-15 12:34:43 -0400 |
| commit | a3773b6922543075750a5b4ed47e79f34e60d800 (patch) | |
| tree | 542d88518fd3b381e1ddf06c0c4be959678ffa20 /plugins/warp/src/plugin | |
| parent | d6c098813fde016e225c4ee072f38cd69d9783f0 (diff) | |
[WARP] Misc improvements
- Fix project file filter not blacklisting warp files
- Fix project name not being used for default file save name
- Prevent adding the same file to the available sources
Diffstat (limited to 'plugins/warp/src/plugin')
| -rw-r--r-- | plugins/warp/src/plugin/create.rs | 20 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/load.rs | 24 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/project.rs | 4 |
3 files changed, 38 insertions, 10 deletions
diff --git a/plugins/warp/src/plugin/create.rs b/plugins/warp/src/plugin/create.rs index 9ebcba2d..0410e74a 100644 --- a/plugins/warp/src/plugin/create.rs +++ b/plugins/warp/src/plugin/create.rs @@ -19,13 +19,18 @@ pub struct SaveFileField; impl SaveFileField { pub fn field(view: &BinaryView) -> FormInputField { - let default_name = view - .file() - .filename() - .split('/') - .last() - .unwrap_or("file") - .to_string(); + let file = view.file(); + let default_name = match file.project_file() { + None => { + // Not in a project, use the file name directly. + file.filename() + .split('/') + .last() + .unwrap_or("file") + .to_string() + } + Some(project_file) => project_file.name(), + }; let signature_dir = user_signature_dir(); let default_file_path = signature_dir.join(&default_name).with_extension("warp"); FormInputField::SaveFileName { @@ -177,6 +182,7 @@ impl CreateFromCurrentView { if std::fs::write(&file_path, file.to_bytes()).is_err() { log::error!("Failed to write data to signature file!"); } + log::info!("Saved signature file to: '{}'", file_path.display()); // Show a report of the generate signatures, if desired. let report_generator = ReportGenerator::new(); diff --git a/plugins/warp/src/plugin/load.rs b/plugins/warp/src/plugin/load.rs index c0319ea5..cef6ea11 100644 --- a/plugins/warp/src/plugin/load.rs +++ b/plugins/warp/src/plugin/load.rs @@ -1,4 +1,4 @@ -use crate::cache::container::add_cached_container; +use crate::cache::container::{add_cached_container, for_cached_containers}; use crate::container::disk::{DiskContainer, DiskContainerSource}; use crate::container::{ContainerError, SourcePath}; use crate::convert::platform_to_target; @@ -12,6 +12,7 @@ use binaryninja::interaction::{ use binaryninja::rc::Ref; use std::collections::HashMap; use std::path::PathBuf; +use std::sync::atomic::AtomicBool; use std::thread; use warp::WarpFile; @@ -125,6 +126,7 @@ impl LoadSignatureFile { let rerun_matcher = RunMatcherField::from_form(&form).unwrap_or(false); let source_file_path = SourcePath::new(file_path.clone()); + let source_file_id = source_file_path.to_source_id(); let file = match LoadSignatureFile::read_file(&view, source_file_path.clone()) { Ok(file) => file, @@ -134,6 +136,26 @@ impl LoadSignatureFile { } }; + // Verify we have not already loaded the file. + let already_exists = AtomicBool::new(false); + for_cached_containers(|c| { + if let Ok(_) = c.source_path(&source_file_id) { + // TODO: What happens if path differs? Warn? + already_exists.store(true, std::sync::atomic::Ordering::SeqCst); + } + }); + if already_exists.load(std::sync::atomic::Ordering::SeqCst) { + let res = show_message_box( + "Load again?", + "File already loaded, would you like to load it again?", + MessageBoxButtonSet::YesNoButtonSet, + MessageBoxIcon::WarningIcon, + ); + if res != MessageBoxButtonResult::YesButton { + return; + } + } + let container_source = DiskContainerSource::new(source_file_path.clone(), file); log::info!("Loading container source: '{}'", container_source.path); let mut map = HashMap::new(); diff --git a/plugins/warp/src/plugin/project.rs b/plugins/warp/src/plugin/project.rs index fc95342c..5047ad0c 100644 --- a/plugins/warp/src/plugin/project.rs +++ b/plugins/warp/src/plugin/project.rs @@ -10,7 +10,7 @@ use binaryninja::project::folder::ProjectFolder; use binaryninja::project::Project; use binaryninja::rc::Ref; use regex::Regex; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::thread; use std::time::Instant; use warp::WarpFile; @@ -186,7 +186,7 @@ impl CreateSignatures { None => Some(warp_filter), }; } - if let Some(filter) = form.file_filter() { + if let Some(filter) = filter { processor = processor.with_file_filter(filter); } |
