diff options
Diffstat (limited to 'plugins/bntl_utils/src/command/dump.rs')
| -rw-r--r-- | plugins/bntl_utils/src/command/dump.rs | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/plugins/bntl_utils/src/command/dump.rs b/plugins/bntl_utils/src/command/dump.rs index 4b68cd79..96c3b264 100644 --- a/plugins/bntl_utils/src/command/dump.rs +++ b/plugins/bntl_utils/src/command/dump.rs @@ -1,49 +1,59 @@ -use crate::command::{InputFileField, OutputDirectoryField}; +use crate::command::{InputDirectoryField, OutputDirectoryField}; use crate::dump::TILDump; use crate::helper::path_to_type_libraries; +use binaryninja::background_task::BackgroundTask; use binaryninja::binary_view::BinaryView; use binaryninja::command::Command; use binaryninja::interaction::Form; -use binaryninja::types::TypeLibrary; pub struct Dump; -impl Command for Dump { - // TODO: We need a command type that does not require a binary view. - fn action(&self, _view: &BinaryView) { +impl Dump { + pub fn execute() { let mut form = Form::new("Dump to C Header"); // TODO: The choice to select what to include? - form.add_field(InputFileField::field()); + form.add_field(InputDirectoryField::field()); form.add_field(OutputDirectoryField::field()); if !form.prompt() { return; } let output_dir = OutputDirectoryField::from_form(&form).unwrap(); - let input_path = InputFileField::from_form(&form).unwrap(); + let input_path = InputDirectoryField::from_form(&form).unwrap(); - let type_lib = match TypeLibrary::load_from_file(&input_path) { - Some(type_lib) => type_lib, - None => { - tracing::error!("Failed to load type library from {}", input_path.display()); - return; - } - }; + let bg_task = BackgroundTask::new("Dumping type libraries...", true).enter(); - // TODO: Currently we collect input path dependencies from the platform and the parent directory. - let dependencies = path_to_type_libraries(input_path.parent().unwrap()); - let dump = match TILDump::new().with_type_libs(dependencies).dump(&type_lib) { - Ok(dump) => dump, - Err(err) => { - tracing::error!("Failed to dump type library: {}", err); + let type_libraries = path_to_type_libraries(&input_path); + for type_lib in &type_libraries { + if bg_task.is_cancelled() { return; } - }; + bg_task.set_progress_text(&format!("Dumping '{}'...", type_lib.name())); + let dump = match TILDump::new() + .with_type_libs(type_libraries.clone()) + .dump(&type_lib) + { + Ok(dump) => dump, + Err(err) => { + tracing::error!("Failed to dump type library: {}", err); + return; + } + }; - let output_path = output_dir.join(format!("{}.h", type_lib.name())); - if let Err(e) = std::fs::write(&output_path, dump) { - tracing::error!("Failed to write dump to {}: {}", output_path.display(), e); + let output_path = output_dir.join(format!("{}.h", type_lib.name())); + if let Err(e) = std::fs::write(&output_path, dump) { + tracing::error!("Failed to write dump to {}: {}", output_path.display(), e); + } + tracing::info!("Dump written to {}", output_path.display()); } - tracing::info!("Dump written to {}", output_path.display()); + } +} + +impl Command for Dump { + // TODO: We need a command type that does not require a binary view. + fn action(&self, _view: &BinaryView) { + std::thread::spawn(move || { + Dump::execute(); + }); } fn valid(&self, _view: &BinaryView) -> bool { |
