diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-05-03 18:45:19 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-05-11 16:49:24 -0400 |
| commit | eb7a52bf4bd3b19c22f2eadda444ab045c674fe3 (patch) | |
| tree | 2395d577d410908b5d0291682660dac2017c7e97 /rust/examples/basic_script | |
| parent | 5731e612900bed0d542421e00e64324dbac9367e (diff) | |
Rust API : Better headless support; Introducing `binaryninja::open_view` and `binaryninja::open_view_with_options`, updated init/shutdown, script example, more setting support, and misc fixes
Diffstat (limited to 'rust/examples/basic_script')
| -rw-r--r-- | rust/examples/basic_script/Cargo.toml | 8 | ||||
| -rw-r--r-- | rust/examples/basic_script/src/main.rs | 41 |
2 files changed, 49 insertions, 0 deletions
diff --git a/rust/examples/basic_script/Cargo.toml b/rust/examples/basic_script/Cargo.toml new file mode 100644 index 00000000..035528d4 --- /dev/null +++ b/rust/examples/basic_script/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "basic_script" +version = "0.1.0" +authors = ["KyleMiles <kyle@vector35.com>"] +edition = "2018" + +[dependencies] +binaryninja = {path="../../"} diff --git a/rust/examples/basic_script/src/main.rs b/rust/examples/basic_script/src/main.rs new file mode 100644 index 00000000..94e89df4 --- /dev/null +++ b/rust/examples/basic_script/src/main.rs @@ -0,0 +1,41 @@ +use binaryninja::architecture::Architecture; +use binaryninja::binaryview::{BinaryViewBase, BinaryViewExt}; + +fn main() { + println!("Loading plugins..."); // This loads all the core architecture, platform, etc plugins + binaryninja::headless::init(); + + println!("Loading binary..."); + let bv = binaryninja::open_view("/bin/cat").expect("Couldn't open `/bin/cat`"); + + println!("Filename: `{}`", bv.metadata().filename()); + println!("File size: `{:#x}`", bv.len()); + println!("Function count: {}", bv.functions().len()); + + for func in &bv.functions() { + println!(" `{}`:", func.symbol().full_name()); + for basic_block in &func.basic_blocks() { + // TODO : This is intended to be refactored to be more nice to work with soon(TM) + for addr in basic_block.as_ref() { + print!(" {} ", addr); + match func.arch().instruction_text( + bv.read_buffer(addr, func.arch().max_instr_len()) + .unwrap() + .get_data(), + addr, + ) { + Some((_, tokens)) => { + tokens + .iter() + .for_each(|token| print!("{}", token.text().to_str().unwrap())); + println!("") + } + _ => (), + } + } + } + } + + // Important! You need to call shutdown or your script will hang forever + binaryninja::headless::shutdown(); +} |
