summaryrefslogtreecommitdiff
path: root/plugins/warp/src/plugin/file.rs
blob: cd5fb626b9a0b518df1d12d350cdf345fcfd8734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::report::ReportGenerator;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::command::Command;

pub struct ShowFileReport;

impl Command for ShowFileReport {
    fn action(&self, view: &BinaryView) {
        let view = view.to_owned();
        std::thread::spawn(move || {
            let Some(path) =
                binaryninja::interaction::get_open_filename_input("Select file to show", "*.warp")
            else {
                return;
            };

            let Ok(bytes) = std::fs::read(&path) else {
                tracing::error!("Failed to read file: {:?}", path);
                return;
            };

            let Some(file) = warp::WarpFile::from_bytes(&bytes) else {
                tracing::error!("Failed to parse file: {:?}", path);
                return;
            };

            let report_generator = ReportGenerator::new();
            if let Some(html_string) = report_generator.html_report(&file) {
                view.show_html_report(
                    &format!("WARP File: {}", path.to_string_lossy()),
                    html_string.as_str(),
                    "",
                );
            }
        });
    }

    fn valid(&self, _view: &BinaryView) -> bool {
        true
    }
}