diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-06-28 22:13:43 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-06-29 00:26:33 -0400 |
| commit | 2c344cf7a77031021e346fd8649de2b7715b5c45 (patch) | |
| tree | fc9b48db5748231aed4e05128d38ab649717a102 /rust/examples/template/src | |
| parent | 58e515b3bfa3a96e4934b8a625bb6e51399057ec (diff) | |
Resolves #2521; Rust API Linking Errors
Diffstat (limited to 'rust/examples/template/src')
| -rw-r--r-- | rust/examples/template/src/main.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/rust/examples/template/src/main.rs b/rust/examples/template/src/main.rs new file mode 100644 index 00000000..7947c0f7 --- /dev/null +++ b/rust/examples/template/src/main.rs @@ -0,0 +1,46 @@ +use binaryninja::architecture::Architecture; +use binaryninja::binaryview::{BinaryViewBase, BinaryViewExt}; + +// Standalone executables need to provide a main function for rustc +// Plugins should refer to `binaryninja::command::*` for the various registration callbacks. +fn main() { + // This loads all the core architecture, platform, etc plugins + // Standalone executables probably need to call this, but plugins do not + println!("Loading plugins..."); + binaryninja::headless::init(); + + // Your code here... + 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! Standalone executables need to call shutdown or they will hang forever + binaryninja::headless::shutdown(); +} |
