From 9c2667464b4e20cfea11cb8d3447f92f51db7440 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 13 Dec 2024 15:17:54 -0500 Subject: 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 --- plugins/warp/src/plugin/add.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'plugins/warp/src/plugin/add.rs') 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), } }); } -- cgit v1.3.1