Skip to content

Commit 1e85844

Browse files
committed
IDB Import refactor
1 parent 1f98e7c commit 1e85844

File tree

11 files changed

+1689
-455
lines changed

11 files changed

+1689
-455
lines changed

Cargo.lock

Lines changed: 55 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/idb_import/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ crate-type = ["cdylib"]
1313
anyhow = { version = "1.0.86", features = ["backtrace"] }
1414
binaryninja.workspace = true
1515
binaryninjacore-sys.workspace = true
16-
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.12" }
17-
tracing = "0.1"
16+
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.13" }
17+
tracing = "0.1"
18+
serde = { version = "1.0", features = ["derive"] }
19+
serde_json = "1.0"

plugins/idb_import/src/addr_info.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

plugins/idb_import/src/commands.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use binaryninja::interaction::{Form, FormInputField};
2+
use std::path::PathBuf;
3+
4+
pub mod load_file;
5+
6+
pub struct LoadFileField {
7+
filter: String,
8+
default: Option<String>,
9+
}
10+
11+
impl LoadFileField {
12+
#[allow(unused)]
13+
pub fn new(filter: &str) -> Self {
14+
Self {
15+
filter: filter.to_string(),
16+
default: None,
17+
}
18+
}
19+
20+
pub fn with_default(filter: &str, default: &str) -> Self {
21+
Self {
22+
filter: filter.to_string(),
23+
default: Some(default.to_string()),
24+
}
25+
}
26+
27+
pub fn field(&self) -> FormInputField {
28+
FormInputField::OpenFileName {
29+
prompt: "File Path".to_string(),
30+
// TODO: This is called extension but is really a filter.
31+
extension: Some(self.filter.clone()),
32+
default: self.default.clone(),
33+
value: None,
34+
}
35+
}
36+
37+
pub fn from_form(form: &Form) -> Option<PathBuf> {
38+
let field = form.get_field_with_name("File Path")?;
39+
let field_value = field.try_value_string()?;
40+
Some(PathBuf::from(field_value))
41+
}
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::commands::LoadFileField;
2+
use crate::mapper::IDBMapper;
3+
use crate::parse::IDBFileParser;
4+
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
5+
use binaryninja::command::Command;
6+
use binaryninja::interaction::Form;
7+
use std::fs::File;
8+
use std::io::BufReader;
9+
use std::path::PathBuf;
10+
11+
pub struct LoadIDBFile;
12+
13+
impl Command for LoadIDBFile {
14+
fn action(&self, view: &BinaryView) {
15+
let mut form = Form::new("Load IDB File");
16+
let mut default_path = PathBuf::from(&view.file().file_path());
17+
default_path.set_extension("idb");
18+
let file_field =
19+
LoadFileField::with_default("*.idb;;*.i64;;*.til", &default_path.to_string_lossy());
20+
form.add_field(file_field.field());
21+
if !form.prompt() {
22+
return;
23+
}
24+
let Some(file_path) = LoadFileField::from_form(&form) else {
25+
return;
26+
};
27+
let Ok(file) = File::open(&file_path) else {
28+
tracing::error!("Failed to open file: {}", file_path.display());
29+
return;
30+
};
31+
let mut file_reader = BufReader::new(file);
32+
let file_parser = IDBFileParser::new();
33+
match file_parser.parse(&mut file_reader) {
34+
Ok(idb_info) => {
35+
IDBMapper::new(idb_info).map_to_view(view);
36+
}
37+
Err(e) => {
38+
tracing::error!("Failed to parse IDB file: {}", e);
39+
}
40+
}
41+
}
42+
43+
fn valid(&self, _view: &BinaryView) -> bool {
44+
true
45+
}
46+
}

0 commit comments

Comments
 (0)