Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 79 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions plugins/idb_import/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ crate-type = ["cdylib"]
anyhow = { version = "1.0.86", features = ["backtrace"] }
binaryninja.workspace = true
binaryninjacore-sys.workspace = true
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.12" }
tracing = "0.1"
idb-rs = { git = "https://github.com/Vector35/idb-rs", tag = "0.1.13" }
tracing = "0.1"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
53 changes: 0 additions & 53 deletions plugins/idb_import/src/addr_info.rs

This file was deleted.

43 changes: 43 additions & 0 deletions plugins/idb_import/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use binaryninja::interaction::{Form, FormInputField};
use std::path::PathBuf;

pub mod create_til;
pub mod load_file;

pub struct LoadFileField {
filter: String,
default: Option<String>,
}

impl LoadFileField {
#[allow(unused)]
pub fn new(filter: &str) -> Self {
Self {
filter: filter.to_string(),
default: None,
}
}

pub fn with_default(filter: &str, default: &str) -> Self {
Self {
filter: filter.to_string(),
default: Some(default.to_string()),
}
}

pub fn field(&self) -> FormInputField {
FormInputField::OpenFileName {
prompt: "File Path".to_string(),
// TODO: This is called extension but is really a filter.
extension: Some(self.filter.clone()),
default: self.default.clone(),
value: None,
}
}

pub fn from_form(form: &Form) -> Option<PathBuf> {
let field = form.get_field_with_name("File Path")?;
let field_value = field.try_value_string()?;
Some(PathBuf::from(field_value))
}
}
1 change: 1 addition & 0 deletions plugins/idb_import/src/commands/create_til.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

50 changes: 50 additions & 0 deletions plugins/idb_import/src/commands/load_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 SVD File");
// let mut load_settings = LoadSettings::from_view_settings(view);
let mut default_path = PathBuf::from(&view.file().filename());
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) => {
let idb_str = serde_json::to_string_pretty(&idb_info).unwrap();
std::fs::write(&file_path.with_extension("json"), idb_str)
.expect("Failed to write IDB info to JSON file");
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
}
}
Loading
Loading