MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / main

Function main

rust/examples/simple.rs:4–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
3
4fn main() {
5 println!("Starting session...");
6 // This loads all the core architecture, platform, etc plugins
7 let headless_session =
8 binaryninja::headless::Session::new().expect("Failed to initialize session");
9
10 println!("Loading binary...");
11 let bv = headless_session
12 .load("/bin/cat")
13 .expect("Couldn't open `/bin/cat`");
14
15 println!("Filename: `{}`", bv.file().filename());
16 println!("File size: `{:#x}`", bv.len());
17 println!("Function count: {}", bv.functions().len());
18
19 for func in &bv.functions() {
20 println!("{}:", func.symbol().full_name());
21 for basic_block in &func.basic_blocks() {
22 // TODO : This is intended to be refactored to be more nice to work with soon(TM)
23 for addr in basic_block.as_ref() {
24 if let Some((_, tokens)) = func.arch().instruction_text(
25 bv.read_buffer(addr, func.arch().max_instr_len())
26 .unwrap()
27 .get_data(),
28 addr,
29 ) {
30 let line = tokens
31 .iter()
32 .map(|token| token.to_string())
33 .collect::<String>();
34 println!("{addr} {line}");
35 }
36 }
37 }
38 }
39}

Callers

nothing calls this directly

Calls 11

read_bufferMethod · 0.80
mapMethod · 0.80
loadMethod · 0.45
functionsMethod · 0.45
basic_blocksMethod · 0.45
as_refMethod · 0.45
instruction_textMethod · 0.45
archMethod · 0.45
get_dataMethod · 0.45
max_instr_lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected