-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathload_file.rs
More file actions
46 lines (43 loc) · 1.46 KB
/
load_file.rs
File metadata and controls
46 lines (43 loc) · 1.46 KB
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
42
43
44
45
46
use crate::commands::LoadFileField;
use crate::mapper::IDBMapper;
use crate::parse::IDBFileParser;
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
use binaryninja::command::Command;
use binaryninja::interaction::Form;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
pub struct LoadIDBFile;
impl Command for LoadIDBFile {
fn action(&self, view: &BinaryView) {
let mut form = Form::new("Load IDB File");
let mut default_path = PathBuf::from(&view.file().file_path());
default_path.set_extension("idb");
let file_field =
LoadFileField::with_default("*.idb;;*.i64;;*.til", &default_path.to_string_lossy());
form.add_field(file_field.field());
if !form.prompt() {
return;
}
let Some(file_path) = LoadFileField::from_form(&form) else {
return;
};
let Ok(file) = File::open(&file_path) else {
tracing::error!("Failed to open file: {}", file_path.display());
return;
};
let mut file_reader = BufReader::new(file);
let file_parser = IDBFileParser::new();
match file_parser.parse(&mut file_reader) {
Ok(idb_info) => {
IDBMapper::new(idb_info).map_to_view(view);
}
Err(e) => {
tracing::error!("Failed to parse IDB file: {}", e);
}
}
}
fn valid(&self, _view: &BinaryView) -> bool {
true
}
}