diff options
| author | Mason Reed <mason@vector35.com> | 2024-12-13 15:17:54 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2024-12-13 15:18:13 -0500 |
| commit | 9c2667464b4e20cfea11cb8d3447f92f51db7440 (patch) | |
| tree | 361ed45cc3b074e1188739bc61ef3634a1bbf109 /plugins/warp/src/plugin/add.rs | |
| parent | 323315207580f3996702b04ec87a43ce8fde6c55 (diff) | |
WARP: User friendly file picker
Instead of using the interaction api or text input just use a rust crate to manage the file picker dialog
Diffstat (limited to 'plugins/warp/src/plugin/add.rs')
| -rw-r--r-- | plugins/warp/src/plugin/add.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/plugins/warp/src/plugin/add.rs b/plugins/warp/src/plugin/add.rs index ef4f9f26..8b50425b 100644 --- a/plugins/warp/src/plugin/add.rs +++ b/plugins/warp/src/plugin/add.rs @@ -5,11 +5,14 @@ use binaryninja::command::FunctionCommand; use binaryninja::function::Function; use std::io::Write; use std::thread; +use crate::user_signature_dir; pub struct AddFunctionSignature; impl FunctionCommand for AddFunctionSignature { fn action(&self, view: &BinaryView, func: &Function) { + let func_plat_name = func.platform().name().to_string(); + let signature_dir = user_signature_dir().join(func_plat_name); let view = view.to_owned(); let func = func.to_owned(); thread::spawn(move || { @@ -17,12 +20,14 @@ impl FunctionCommand for AddFunctionSignature { log::error!("Could not get low level IL for function."); return; }; - - let Some(save_file) = binaryninja::interaction::get_save_filename_input( - "Use Signature File", - "*.sbin", - "user.sbin", - ) else { + + // 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("user.sbin") + .set_directory(signature_dir) + .save_file() else { return; }; @@ -50,17 +55,13 @@ impl FunctionCommand for AddFunctionSignature { data.types.extend(referenced_types); } - 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), + match std::fs::write(&save_file, data.to_bytes()) { + Ok(_) => { + log::info!("Signature file saved successfully."); + // Force rebuild platform matcher. + invalidate_function_matcher_cache(); } - } else { - log::error!("Could not create signature file: {:?}", save_file); + Err(e) => log::error!("Failed to write data to signature file: {:?}", e), } }); } |
