Skip to content

Commit a3773b6

Browse files
committed
[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
1 parent d6c0988 commit a3773b6

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

plugins/warp/src/plugin/create.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ pub struct SaveFileField;
1919

2020
impl SaveFileField {
2121
pub fn field(view: &BinaryView) -> FormInputField {
22-
let default_name = view
23-
.file()
24-
.filename()
25-
.split('/')
26-
.last()
27-
.unwrap_or("file")
28-
.to_string();
22+
let file = view.file();
23+
let default_name = match file.project_file() {
24+
None => {
25+
// Not in a project, use the file name directly.
26+
file.filename()
27+
.split('/')
28+
.last()
29+
.unwrap_or("file")
30+
.to_string()
31+
}
32+
Some(project_file) => project_file.name(),
33+
};
2934
let signature_dir = user_signature_dir();
3035
let default_file_path = signature_dir.join(&default_name).with_extension("warp");
3136
FormInputField::SaveFileName {
@@ -177,6 +182,7 @@ impl CreateFromCurrentView {
177182
if std::fs::write(&file_path, file.to_bytes()).is_err() {
178183
log::error!("Failed to write data to signature file!");
179184
}
185+
log::info!("Saved signature file to: '{}'", file_path.display());
180186

181187
// Show a report of the generate signatures, if desired.
182188
let report_generator = ReportGenerator::new();

plugins/warp/src/plugin/load.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cache::container::add_cached_container;
1+
use crate::cache::container::{add_cached_container, for_cached_containers};
22
use crate::container::disk::{DiskContainer, DiskContainerSource};
33
use crate::container::{ContainerError, SourcePath};
44
use crate::convert::platform_to_target;
@@ -12,6 +12,7 @@ use binaryninja::interaction::{
1212
use binaryninja::rc::Ref;
1313
use std::collections::HashMap;
1414
use std::path::PathBuf;
15+
use std::sync::atomic::AtomicBool;
1516
use std::thread;
1617
use warp::WarpFile;
1718

@@ -125,6 +126,7 @@ impl LoadSignatureFile {
125126
let rerun_matcher = RunMatcherField::from_form(&form).unwrap_or(false);
126127

127128
let source_file_path = SourcePath::new(file_path.clone());
129+
let source_file_id = source_file_path.to_source_id();
128130

129131
let file = match LoadSignatureFile::read_file(&view, source_file_path.clone()) {
130132
Ok(file) => file,
@@ -134,6 +136,26 @@ impl LoadSignatureFile {
134136
}
135137
};
136138

139+
// Verify we have not already loaded the file.
140+
let already_exists = AtomicBool::new(false);
141+
for_cached_containers(|c| {
142+
if let Ok(_) = c.source_path(&source_file_id) {
143+
// TODO: What happens if path differs? Warn?
144+
already_exists.store(true, std::sync::atomic::Ordering::SeqCst);
145+
}
146+
});
147+
if already_exists.load(std::sync::atomic::Ordering::SeqCst) {
148+
let res = show_message_box(
149+
"Load again?",
150+
"File already loaded, would you like to load it again?",
151+
MessageBoxButtonSet::YesNoButtonSet,
152+
MessageBoxIcon::WarningIcon,
153+
);
154+
if res != MessageBoxButtonResult::YesButton {
155+
return;
156+
}
157+
}
158+
137159
let container_source = DiskContainerSource::new(source_file_path.clone(), file);
138160
log::info!("Loading container source: '{}'", container_source.path);
139161
let mut map = HashMap::new();

plugins/warp/src/plugin/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use binaryninja::project::folder::ProjectFolder;
1010
use binaryninja::project::Project;
1111
use binaryninja::rc::Ref;
1212
use regex::Regex;
13-
use std::path::{Path, PathBuf};
13+
use std::path::Path;
1414
use std::thread;
1515
use std::time::Instant;
1616
use warp::WarpFile;
@@ -186,7 +186,7 @@ impl CreateSignatures {
186186
None => Some(warp_filter),
187187
};
188188
}
189-
if let Some(filter) = form.file_filter() {
189+
if let Some(filter) = filter {
190190
processor = processor.with_file_filter(filter);
191191
}
192192

0 commit comments

Comments
 (0)