summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-12-19 19:15:38 -0500
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-01-11 10:36:01 -0800
commit587a5c0c537a4b3bc5c737e3b3fc1fd5fbca3a59 (patch)
treea01357f3a1ad00bdf6ebde29dfae673da2f78a57
parent6f75ca031aa7e8f7e1c706d1880b202137b1996f (diff)
[Rust] Update examples to use tracing
-rw-r--r--plugins/warp/examples/headless/Cargo.toml8
-rw-r--r--plugins/warp/examples/headless/src/main.rs106
-rw-r--r--rust/examples/bndb_to_type_library.rs43
-rw-r--r--rust/examples/create_type_library.rs14
-rw-r--r--rust/examples/decompile.rs15
-rw-r--r--rust/examples/demangler.rs17
-rw-r--r--rust/examples/disassemble.rs15
-rw-r--r--rust/examples/dump_settings.rs15
-rw-r--r--rust/examples/dump_type_library.rs11
-rw-r--r--rust/examples/flowgraph.rs33
-rw-r--r--rust/examples/high_level_il.rs13
-rw-r--r--rust/examples/medium_level_il.rs13
-rw-r--r--rust/examples/simple.rs13
-rw-r--r--rust/examples/type_printer.rs7
-rw-r--r--rust/examples/workflow.rs17
-rw-r--r--rust/plugin_examples/data_renderer/Cargo.toml2
16 files changed, 201 insertions, 141 deletions
diff --git a/plugins/warp/examples/headless/Cargo.toml b/plugins/warp/examples/headless/Cargo.toml
index b28b089d..a32796be 100644
--- a/plugins/warp/examples/headless/Cargo.toml
+++ b/plugins/warp/examples/headless/Cargo.toml
@@ -5,10 +5,10 @@ edition = "2021"
[dependencies]
clap = { version = "4.5", features = ["derive"] }
-indicatif = "0.18.2"
warp_ninja.workspace = true
binaryninjacore-sys.workspace = true
binaryninja.workspace = true
-log = "0.4"
-env_logger = "0.11"
-ctrlc = "3.5" \ No newline at end of file
+ctrlc = "3.5"
+tracing = "0.1"
+tracing-subscriber = "0.3"
+tracing-indicatif = "0.3" \ No newline at end of file
diff --git a/plugins/warp/examples/headless/src/main.rs b/plugins/warp/examples/headless/src/main.rs
index c08103a5..29d48f65 100644
--- a/plugins/warp/examples/headless/src/main.rs
+++ b/plugins/warp/examples/headless/src/main.rs
@@ -1,10 +1,16 @@
use binaryninja::headless::Session;
+use binaryninja::tracing::TracingLogListener;
use clap::Parser;
-use indicatif::{ProgressBar, ProgressStyle};
use std::collections::HashMap;
use std::path::PathBuf;
+use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
+use tracing_indicatif::span_ext::IndicatifSpanExt;
+use tracing_indicatif::style::ProgressStyle;
+use tracing_indicatif::IndicatifLayer;
+use tracing_subscriber::layer::SubscriberExt;
+use tracing_subscriber::util::SubscriberInitExt;
use warp_ninja::processor::{
CompressionTypeField, ProcessingFileState, ProcessingState, WarpFileProcessor,
};
@@ -50,9 +56,15 @@ struct Args {
}
fn main() {
+ let indicatif_layer = IndicatifLayer::new();
+ tracing_subscriber::registry()
+ .with(tracing_subscriber::fmt::layer().with_writer(indicatif_layer.get_stderr_writer()))
+ .with(indicatif_layer)
+ .init();
+ let _listener = TracingLogListener::new().register();
+
let _session = Session::new().expect("Failed to create session");
let args = Args::parse();
- env_logger::init();
let compression_ty = match args.compressed {
true => CompressionTypeField::Zstd,
@@ -72,7 +84,12 @@ fn main() {
})
.expect("Error setting Ctrl-C handler");
- let progress_guard = run_progress_bar(processor.state());
+ let finished_signal = Arc::new(AtomicBool::new(false));
+ // Report progress to the terminal.
+ let progress_state = processor.state();
+ let progress_finished_signal = finished_signal.clone();
+ let progress_thread =
+ std::thread::spawn(|| run_progress_bar(progress_state, progress_finished_signal));
let outputs: HashMap<PathBuf, WarpFile<'static>> = args
.input
@@ -80,14 +97,14 @@ fn main() {
.filter_map(|i| match processor.process(i.clone()) {
Ok(o) => Some((i, o)),
Err(err) => {
- log::error!("{}", err);
+ tracing::error!("{}", err);
None
}
})
.collect();
- // Stop progress UI
- progress_guard.finish();
+ finished_signal.store(true, Ordering::Relaxed);
+ progress_thread.join().expect("Progress thread exited");
match args.output.is_dir() {
true => {
@@ -98,7 +115,7 @@ fn main() {
None => input.components().last().unwrap().as_os_str(),
};
let output_path = args.output.join(output_name).with_extension("warp");
- log::info!("Writing to {:?}", output_path);
+ tracing::info!("Writing to {:?}", output_path);
std::fs::write(output_path, output.to_bytes()).unwrap();
}
}
@@ -106,11 +123,11 @@ fn main() {
// Given a non-existing directory, merge all outputs and place at the output path.
match processor.merge_files(outputs.values().cloned().collect()) {
Ok(output) => {
- log::info!("Writing to {:?}", args.output);
+ tracing::info!("Writing to {:?}", args.output);
std::fs::write(args.output, output.to_bytes()).unwrap();
}
Err(err) => {
- log::error!("{}", err);
+ tracing::error!("{}", err);
}
}
}
@@ -118,65 +135,36 @@ fn main() {
}
// TODO: Also poll for background tasks and display them as independent progress bars.
-fn run_progress_bar(state: Arc<ProcessingState>) -> ProgressGuard {
- let pb = ProgressBar::new(0);
- pb.set_style(
- ProgressStyle::with_template(
- "{spinner} {bar:40.cyan/blue} {pos}/{len} ({percent}%) [{elapsed_precise}] {msg}",
- )
- .unwrap()
- .progress_chars("=>-"),
- );
+fn run_progress_bar(state: Arc<ProcessingState>, finished: Arc<AtomicBool>) {
+ let progress_span = tracing::info_span!("loading");
+ let progress_style = ProgressStyle::with_template("{msg} {elapsed} {wide_bar}").unwrap();
+ progress_span.pb_set_style(&progress_style);
+ progress_span.pb_set_message("Processing files");
+ progress_span.pb_set_finish_message("Files processed");
- let pb_clone = pb.clone();
- let state_clone = state.clone();
- let handle = std::thread::spawn(move || loop {
- let total = state_clone.total_files() as u64;
- let done = state_clone.files_with_state(ProcessingFileState::Processed) as u64;
- let unprocessed = state_clone.files_with_state(ProcessingFileState::Unprocessed);
- let analyzing = state_clone.files_with_state(ProcessingFileState::Analyzing);
- let processing = state_clone.files_with_state(ProcessingFileState::Processing);
+ let elapsed = std::time::Instant::now();
+ progress_span.in_scope(|| loop {
+ let total = state.total_files() as u64;
+ let done = state.files_with_state(ProcessingFileState::Processed) as u64;
+ let unprocessed = state.files_with_state(ProcessingFileState::Unprocessed);
+ let analyzing = state.files_with_state(ProcessingFileState::Analyzing);
+ let processing = state.files_with_state(ProcessingFileState::Processing);
- if pb_clone.length().unwrap_or(0) != total {
- pb_clone.set_length(total);
- }
- pb_clone.set_position(done.min(total));
- pb_clone.set_message(format!(
+ progress_span.pb_set_length(total);
+ progress_span.pb_set_position(done.min(total));
+ progress_span.pb_set_message(&format!(
"{{u:{}|a:{}|p:{}|d:{}}}",
unprocessed, analyzing, processing, done
));
- if pb_clone.is_finished() {
+ if state.is_cancelled() || finished.load(Ordering::Relaxed) {
break;
}
std::thread::sleep(Duration::from_millis(100));
});
- ProgressGuard {
- pb,
- handle: Some(handle),
- }
-}
-
-struct ProgressGuard {
- pb: ProgressBar,
- handle: Option<std::thread::JoinHandle<()>>,
-}
-
-impl ProgressGuard {
- fn finish(mut self) {
- self.pb.finish_and_clear();
- if let Some(h) = self.handle.take() {
- let _ = h.join();
- }
- }
-}
-
-impl Drop for ProgressGuard {
- fn drop(&mut self) {
- self.pb.finish_and_clear();
- if let Some(h) = self.handle.take() {
- let _ = h.join();
- }
- }
+ tracing::info!(
+ "Finished processing in {:.2} seconds",
+ elapsed.elapsed().as_secs_f32()
+ );
}
diff --git a/rust/examples/bndb_to_type_library.rs b/rust/examples/bndb_to_type_library.rs
index 84515cf7..2cfaf83e 100644
--- a/rust/examples/bndb_to_type_library.rs
+++ b/rust/examples/bndb_to_type_library.rs
@@ -1,9 +1,21 @@
// Usage: cargo run --example bndb_to_type_library <bndb_path> <type_library_path>
use binaryninja::binary_view::BinaryViewExt;
+use binaryninja::tracing::TracingLogListener;
use binaryninja::types::{QualifiedName, TypeLibrary};
+use tracing_indicatif::span_ext::IndicatifSpanExt;
+use tracing_indicatif::style::ProgressStyle;
+use tracing_subscriber::layer::SubscriberExt;
+use tracing_subscriber::util::SubscriberInitExt;
fn main() {
+ let indicatif_layer = tracing_indicatif::IndicatifLayer::new();
+ tracing_subscriber::registry()
+ .with(tracing_subscriber::fmt::layer().with_writer(indicatif_layer.get_stderr_writer()))
+ .with(indicatif_layer)
+ .init();
+ let _listener = TracingLogListener::new().register();
+
let bndb_path_str = std::env::args().nth(1).expect("No header provided");
let bndb_path = std::path::Path::new(&bndb_path_str);
@@ -11,28 +23,43 @@ fn main() {
let type_lib_path = std::path::Path::new(&type_lib_path_str);
let type_lib_name = type_lib_path.file_stem().unwrap().to_str().unwrap();
- println!("Starting session...");
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- let file = headless_session
- .load(bndb_path)
- .expect("Failed to load BNDB");
+ let file = {
+ let loading_span = tracing::info_span!("loading");
+ let progress_style = ProgressStyle::with_template("{msg} {elapsed} {wide_bar}").unwrap();
+ loading_span.pb_set_style(&progress_style);
+ loading_span.pb_set_message("Loading database");
+ loading_span.pb_set_finish_message("Database loaded");
+ loading_span.in_scope(|| {
+ headless_session
+ .load_with_progress(bndb_path, |pos, total| {
+ loading_span.pb_set_length(total as u64);
+ loading_span.pb_set_position(pos as u64);
+ true
+ })
+ .expect("Failed to load BNDB")
+ })
+ };
let type_lib = TypeLibrary::new(file.default_arch().unwrap(), type_lib_name);
- for ty in &file.types() {
- println!("Adding type: {}", ty.name);
+ let types = file.types();
+ tracing::info!("Adding {} types", types.len());
+ for ty in &types {
type_lib.add_named_type(ty.name, &ty.ty);
}
- for func in &file.functions() {
- println!("Adding function: {}", func.symbol());
+ let functions = file.functions();
+ tracing::info!("Adding {} functions", functions.len());
+ for func in &functions {
let qualified_name =
QualifiedName::from(func.symbol().short_name().to_string_lossy().to_string());
type_lib.add_named_object(qualified_name, &func.function_type());
}
+ tracing::info!("Writing out file... {:?}", type_lib_path);
type_lib.write_to_file(&type_lib_path);
}
diff --git a/rust/examples/create_type_library.rs b/rust/examples/create_type_library.rs
index 74d93765..14c387a4 100644
--- a/rust/examples/create_type_library.rs
+++ b/rust/examples/create_type_library.rs
@@ -1,9 +1,13 @@
// Usage: cargo run --example create_type_library <header_file_path> <platform> <type_library_path>
use binaryninja::platform::Platform;
+use binaryninja::tracing::TracingLogListener;
use binaryninja::types::{CoreTypeParser, TypeLibrary, TypeParser};
fn main() {
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
let header_path_str = std::env::args().nth(1).expect("No header provided");
let header_path = std::path::Path::new(&header_path_str);
let header_name = header_path.file_stem().unwrap().to_str().unwrap();
@@ -14,7 +18,6 @@ fn main() {
let header_contents = std::fs::read_to_string(header_path).expect("Failed to read header file");
- println!("Starting session...");
// This loads all the core architecture, platform, etc plugins
let _headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
@@ -38,14 +41,19 @@ fn main() {
.expect("Parsed types");
for ty in parsed_types.types {
- println!("Adding type: {}", ty.name);
+ tracing::debug!("Adding type: {}", ty.name);
type_lib.add_named_type(ty.name, &ty.ty);
}
for func in parsed_types.functions {
- println!("Adding function: {}", func.name);
+ tracing::debug!("Adding function: {}", func.name);
type_lib.add_named_object(func.name, &func.ty);
}
+ tracing::info!(
+ "Created type library with {} types and {} functions",
+ type_lib.named_types().len(),
+ type_lib.named_objects().len()
+ );
type_lib.write_to_file(&type_lib_path);
}
diff --git a/rust/examples/decompile.rs b/rust/examples/decompile.rs
index 8bf3ecc3..6ba9cbf4 100644
--- a/rust/examples/decompile.rs
+++ b/rust/examples/decompile.rs
@@ -2,6 +2,7 @@ use binaryninja::binary_view::{BinaryView, BinaryViewBase, BinaryViewExt};
use binaryninja::disassembly::{DisassemblyOption, DisassemblySettings};
use binaryninja::function::Function;
use binaryninja::linear_view::LinearViewObject;
+use binaryninja::tracing::TracingLogListener;
fn decompile_to_c(view: &BinaryView, func: &Function) {
let settings = DisassemblySettings::new();
@@ -22,26 +23,28 @@ fn decompile_to_c(view: &BinaryView, func: &Function) {
let lines = first.into_iter().chain(&last);
for line in lines {
- println!("{}", line);
+ tracing::info!("{}", line);
}
}
pub fn main() {
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
let filename = std::env::args().nth(1).expect("No filename provided");
- println!("Starting session...");
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load(&filename)
.expect("Couldn't open file!");
- println!("Filename: `{}`", bv.file().filename());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
+ tracing::info!("Filename: `{}`", bv.file().filename());
+ tracing::info!("File size: `{:#x}`", bv.len());
+ tracing::info!("Function count: {}", bv.functions().len());
for func in &bv.functions() {
decompile_to_c(bv.as_ref(), func.as_ref());
diff --git a/rust/examples/demangler.rs b/rust/examples/demangler.rs
index b2e5eb66..edefaec1 100644
--- a/rust/examples/demangler.rs
+++ b/rust/examples/demangler.rs
@@ -2,6 +2,7 @@ use binaryninja::architecture::CoreArchitecture;
use binaryninja::binary_view::BinaryView;
use binaryninja::demangle::{CustomDemangler, Demangler};
use binaryninja::rc::Ref;
+use binaryninja::tracing::TracingLogListener;
use binaryninja::types::{QualifiedName, Type};
struct TestDemangler;
@@ -26,32 +27,34 @@ impl CustomDemangler for TestDemangler {
}
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let _headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Registering demangler...");
+ tracing::info!("Registering demangler...");
Demangler::register("Test", TestDemangler);
let placeholder_arch = CoreArchitecture::by_name("x86_64").expect("x86 exists");
for d in Demangler::list().iter() {
- println!("{}", d.name());
+ tracing::info!("{}", d.name());
- println!(
+ tracing::info!(
" \"__ZN1AC2Ei\" is mangled? {}",
d.is_mangled_string("__ZN1AC2Ei")
);
- println!(
+ tracing::info!(
" \"__ZN1AC2Ei\" : {:?}",
d.demangle(&placeholder_arch, "__ZN1AC2Ei", None)
);
- println!(
+ tracing::info!(
" \"test_name\" : {:?}",
d.demangle(&placeholder_arch, "test_name", None)
);
- println!(
+ tracing::info!(
" \"test_name2\" : {:?}",
d.demangle(&placeholder_arch, "test_name2", None)
);
diff --git a/rust/examples/disassemble.rs b/rust/examples/disassemble.rs
index 2065c787..ce3ff765 100644
--- a/rust/examples/disassemble.rs
+++ b/rust/examples/disassemble.rs
@@ -1,6 +1,7 @@
use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
use binaryninja::disassembly::{DisassemblyOption, DisassemblySettings, DisassemblyTextRenderer};
use binaryninja::function::Function;
+use binaryninja::tracing::TracingLogListener;
fn disassemble(func: &Function) {
let settings = DisassemblySettings::new();
@@ -17,28 +18,30 @@ fn disassemble(func: &Function) {
if let Some((text, _len)) = text_renderer.instruction_text(instr_addr) {
// TODO: This only ever appears to return a single string?
let text_string: Vec<_> = text.iter().map(|t| t.to_string()).collect();
- println!("{}", text_string.join(""));
+ tracing::info!("{}", text_string.join(""));
}
}
}
}
pub fn main() {
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
let filename = std::env::args().nth(1).expect("No filename provided");
- println!("Starting session...");
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load(&filename)
.expect("Couldn't open file!");
- println!("Filename: `{}`", bv.file().filename());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
+ tracing::info!("Filename: `{}`", bv.file().filename());
+ tracing::info!("File size: `{:#x}`", bv.len());
+ tracing::info!("Function count: {}", bv.functions().len());
for func in &bv.functions() {
disassemble(func.as_ref());
diff --git a/rust/examples/dump_settings.rs b/rust/examples/dump_settings.rs
index 51452ca7..8c4af057 100644
--- a/rust/examples/dump_settings.rs
+++ b/rust/examples/dump_settings.rs
@@ -1,7 +1,10 @@
use binaryninja::settings::Settings;
+use binaryninja::tracing::TracingLogListener;
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let _headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
@@ -12,10 +15,10 @@ fn main() {
let default_value = settings.get_property_string(key, "default");
let title = settings.get_property_string(key, "title");
let description = settings.get_property_string(key, "description");
- println!("{}:", key);
- println!(" value: {}", value);
- println!(" default_value: {}", default_value);
- println!(" title: {}", title);
- println!(" description: {}", description);
+ tracing::info!("{}:", key);
+ tracing::info!(" value: {}", value);
+ tracing::info!(" default_value: {}", default_value);
+ tracing::info!(" title: {}", title);
+ tracing::info!(" description: {}", description);
}
}
diff --git a/rust/examples/dump_type_library.rs b/rust/examples/dump_type_library.rs
index f7398d28..9e6b19c2 100644
--- a/rust/examples/dump_type_library.rs
+++ b/rust/examples/dump_type_library.rs
@@ -2,21 +2,24 @@
use binaryninja::binary_view::BinaryView;
use binaryninja::file_metadata::FileMetadata;
+use binaryninja::tracing::TracingLogListener;
use binaryninja::types::library::TypeLibrary;
use binaryninja::types::printer::{CoreTypePrinter, TokenEscapingType};
fn main() {
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
let type_lib_str = std::env::args().nth(1).expect("No type library provided");
let type_lib_path = std::path::Path::new(&type_lib_str);
- println!("Starting session...");
// This loads all the core architecture, platform, etc plugins
let _headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
let type_lib = TypeLibrary::load_from_file(type_lib_path).expect("Failed to load type library");
- println!("Name: `{}`", type_lib.name());
- println!("GUID: `{}`", type_lib.guid());
+ tracing::info!("Name: `{}`", type_lib.name());
+ tracing::info!("GUID: `{}`", type_lib.guid());
// Print out all the types as a c header.
let type_lib_header_path = type_lib_path.with_extension("h");
@@ -27,7 +30,7 @@ fn main() {
.chain(type_lib.named_objects().iter())
.collect();
- println!(
+ tracing::info!(
"Dumping {} types to: `{:?}`",
all_types.len(),
type_lib_header_path
diff --git a/rust/examples/flowgraph.rs b/rust/examples/flowgraph.rs
index 75c854a7..cb03234e 100644
--- a/rust/examples/flowgraph.rs
+++ b/rust/examples/flowgraph.rs
@@ -6,6 +6,7 @@ use binaryninja::interaction::handler::{
register_interaction_handler, InteractionHandler, InteractionHandlerTask,
};
use binaryninja::interaction::{MessageBoxButtonResult, MessageBoxButtonSet, MessageBoxIcon};
+use binaryninja::tracing::TracingLogListener;
use binaryninja::{
architecture::BranchType,
binary_view::{BinaryView, BinaryViewExt},
@@ -17,22 +18,22 @@ pub struct GraphPrinter;
impl GraphPrinter {
pub fn print_graph(&self, graph: &FlowGraph) {
- println!("Printing flow graph:");
+ tracing::info!("Printing flow graph:");
for node in &graph.nodes() {
// Print all disassembly lines in the node
- println!("Node @ {:?}:", node.position());
- println!("------------------");
- println!("Disassembly lines:");
+ tracing::info!("Node @ {:?}:", node.position());
+ tracing::info!("------------------");
+ tracing::info!("Disassembly lines:");
for line in &node.lines() {
- println!(" {}", line);
+ tracing::info!(" {}", line);
}
// Print outgoing edges
- println!("Outgoing edges:");
+ tracing::info!("Outgoing edges:");
for edge in &node.outgoing_edges() {
- println!(" {:?} => {:?}", edge.branch_type, edge.target.position());
+ tracing::info!(" {:?} => {:?}", edge.branch_type, edge.target.position());
}
- println!("------------------");
+ tracing::info!("------------------");
}
}
}
@@ -62,14 +63,14 @@ impl InteractionHandler for GraphPrinter {
}
fn show_plain_text_report(&mut self, _view: Option<&BinaryView>, title: &str, contents: &str) {
- println!("Plain text report");
- println!("Title: {}", title);
- println!("Contents: {}", contents);
+ tracing::info!("Plain text report");
+ tracing::info!("Title: {}", title);
+ tracing::info!("Contents: {}", contents);
}
fn show_graph_report(&mut self, _view: Option<&BinaryView>, title: &str, graph: &FlowGraph) {
- println!("Graph report");
- println!("Title: {}", title);
+ tracing::info!("Graph report");
+ tracing::info!("Title: {}", title);
self.print_graph(graph);
}
@@ -115,12 +116,14 @@ fn test_graph() {
}
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
diff --git a/rust/examples/high_level_il.rs b/rust/examples/high_level_il.rs
index ddc8f08d..a099437a 100644
--- a/rust/examples/high_level_il.rs
+++ b/rust/examples/high_level_il.rs
@@ -1,19 +1,22 @@
use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
+use binaryninja::tracing::TracingLogListener;
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
- println!("Filename: `{}`", bv.file().filename());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
+ tracing::info!("Filename: `{}`", bv.file().filename());
+ tracing::info!("File size: `{:#x}`", bv.len());
+ tracing::info!("Function count: {}", bv.functions().len());
for func in &bv.functions() {
println!("{:?}:", func.symbol().full_name());
diff --git a/rust/examples/medium_level_il.rs b/rust/examples/medium_level_il.rs
index 543a0856..c9412d08 100644
--- a/rust/examples/medium_level_il.rs
+++ b/rust/examples/medium_level_il.rs
@@ -1,19 +1,22 @@
use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
+use binaryninja::tracing::TracingLogListener;
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
- println!("Filename: `{}`", bv.file().filename());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
+ tracing::info!("Filename: `{}`", bv.file().filename());
+ tracing::info!("File size: `{:#x}`", bv.len());
+ tracing::info!("Function count: {}", bv.functions().len());
for func in &bv.functions() {
println!("{:?}:", func.symbol().full_name());
diff --git a/rust/examples/simple.rs b/rust/examples/simple.rs
index 66dbdfc0..c01ef74e 100644
--- a/rust/examples/simple.rs
+++ b/rust/examples/simple.rs
@@ -1,20 +1,23 @@
use binaryninja::architecture::Architecture;
use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
+use binaryninja::tracing::TracingLogListener;
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
- println!("File: `{}`", bv.file());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
+ tracing::info!("File: `{}`", bv.file());
+ tracing::info!("File size: `{:#x}`", bv.len());
+ tracing::info!("Function count: {}", bv.functions().len());
for func in &bv.functions() {
println!("{}:", func.symbol());
diff --git a/rust/examples/type_printer.rs b/rust/examples/type_printer.rs
index b88a0233..7407197e 100644
--- a/rust/examples/type_printer.rs
+++ b/rust/examples/type_printer.rs
@@ -1,13 +1,16 @@
+use binaryninja::tracing::TracingLogListener;
use binaryninja::types::printer::{CoreTypePrinter, TokenEscapingType};
use binaryninja::types::{MemberAccess, MemberScope, Structure, StructureMember, Type};
fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
diff --git a/rust/examples/workflow.rs b/rust/examples/workflow.rs
index d030209a..bfbbbdb2 100644
--- a/rust/examples/workflow.rs
+++ b/rust/examples/workflow.rs
@@ -2,6 +2,7 @@ use binaryninja::binary_view::BinaryViewExt;
use binaryninja::low_level_il::expression::{ExpressionHandler, LowLevelILExpressionKind};
use binaryninja::low_level_il::instruction::InstructionHandler;
use binaryninja::low_level_il::VisitorAction;
+use binaryninja::tracing::TracingLogListener;
use binaryninja::workflow::{Activity, AnalysisContext, Workflow};
const RUST_ACTIVITY_NAME: &str = "analysis.plugins.rustexample";
@@ -31,7 +32,11 @@ fn example_activity(analysis_context: &AnalysisContext) {
llil_instr.visit_tree(&mut |expr| {
if let LowLevelILExpressionKind::Const(_op) = expr.kind() {
// Replace all consts with 0x1337.
- println!("Replacing llil expression @ 0x{:x} : {}", instr, expr.index);
+ tracing::debug!(
+ "Replacing llil expression @ 0x{:x} : {}",
+ instr,
+ expr.index
+ );
unsafe {
llil.replace_expression(expr.index, llil.const_int(4, 0x1337))
};
@@ -46,12 +51,14 @@ fn example_activity(analysis_context: &AnalysisContext) {
}
pub fn main() {
- println!("Starting session...");
+ tracing_subscriber::fmt::init();
+ let _listener = TracingLogListener::new().register();
+
// This loads all the core architecture, platform, etc plugins
let headless_session =
binaryninja::headless::Session::new().expect("Failed to initialize session");
- println!("Registering workflow...");
+ tracing::info!("Registering workflow...");
let activity = Activity::new_with_action(RUST_ACTIVITY_CONFIG, example_activity);
// Update the meta-workflow with our new activity.
Workflow::cloned("core.function.metaAnalysis")
@@ -61,7 +68,7 @@ pub fn main() {
.register()
.expect("Couldn't register activity");
- println!("Loading binary...");
+ tracing::info!("Loading binary...");
let bv = headless_session
.load("/bin/cat")
.expect("Couldn't open `/bin/cat`");
@@ -74,7 +81,7 @@ pub fn main() {
instr.visit_tree(&mut |expr| {
if let LowLevelILExpressionKind::Const(value) = expr.kind() {
if value.value() == 0x1337 {
- println!(
+ tracing::info!(
"Found constant 0x1337 at instruction 0x{:x} in function {}",
instr.address(),
func.start()
diff --git a/rust/plugin_examples/data_renderer/Cargo.toml b/rust/plugin_examples/data_renderer/Cargo.toml
index 6c9aa63b..5911392f 100644
--- a/rust/plugin_examples/data_renderer/Cargo.toml
+++ b/rust/plugin_examples/data_renderer/Cargo.toml
@@ -10,4 +10,4 @@ crate-type = ["cdylib"]
binaryninjacore-sys = { path = "../../binaryninjacore-sys" }
binaryninja = { path = "../.." }
uuid = "1.18.1"
-tracing = "0.1" \ No newline at end of file
+tracing = "0.1"