diff options
| author | Mason Reed <mason@vector35.com> | 2025-12-17 21:23:46 -0500 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-01-11 10:36:01 -0800 |
| commit | 168a3fd34824adc9c6a606cd144219701f15cccf (patch) | |
| tree | 9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /plugins/warp/src/plugin | |
| parent | ca91bc1933976c62d24248f0f7c35af38451ff11 (diff) | |
[Rust] Replace `log` with `tracing`
- Added more documentation
- Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo)
- Simplified some misc code
This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
Diffstat (limited to 'plugins/warp/src/plugin')
| -rw-r--r-- | plugins/warp/src/plugin/commit.rs | 17 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/create.rs | 15 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/debug.rs | 8 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/ffi/container.rs | 5 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/file.rs | 5 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/function.rs | 25 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/load.rs | 5 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/project.rs | 21 | ||||
| -rw-r--r-- | plugins/warp/src/plugin/workflow.rs | 27 |
9 files changed, 70 insertions, 58 deletions
diff --git a/plugins/warp/src/plugin/commit.rs b/plugins/warp/src/plugin/commit.rs index 2af5fc3e..56a78f9a 100644 --- a/plugins/warp/src/plugin/commit.rs +++ b/plugins/warp/src/plugin/commit.rs @@ -6,6 +6,7 @@ use crate::plugin::create::OpenFileField; use binaryninja::binary_view::BinaryView; use binaryninja::command::Command; use binaryninja::interaction::{Form, FormInputField}; +use binaryninja::tracing; use warp::chunk::ChunkKind; use warp::WarpFile; @@ -84,11 +85,11 @@ impl CommitFile { let open_file_path = OpenFileField::from_form(&form)?; let source_id = source_field.from_form(&form)?; - log::info!("Committing file to source: {}", source_id); + tracing::info!("Committing file to source: {}", source_id); let bytes = std::fs::read(open_file_path).ok()?; let Some(warp_file) = WarpFile::from_bytes(&bytes) else { - log::error!("Failed to parse warp file!"); + tracing::error!("Failed to parse warp file!"); return None; }; @@ -103,7 +104,7 @@ impl CommitFile { match &chunk.kind { ChunkKind::Signature(sc) => { let functions: Vec<_> = sc.functions().collect(); - log::info!( + tracing::info!( "Adding {} functions to source: {}", functions.len(), source_id @@ -113,22 +114,22 @@ impl CommitFile { &source_id, &functions, ) { - log::error!("Failed to add functions to source: {}", e); + tracing::error!("Failed to add functions to source: {}", e); } } ChunkKind::Type(sc) => { let types: Vec<_> = sc.types().collect(); - log::info!("Adding {} types to source: {}", types.len(), source_id); + tracing::info!("Adding {} types to source: {}", types.len(), source_id); if let Err(e) = container.add_computed_types(&source_id, &types) { - log::error!("Failed to add types to source: {}", e); + tracing::error!("Failed to add types to source: {}", e); } } } } if let Err(e) = container.commit_source(&source_id) { - log::error!("Failed to commit source: {}", e); + tracing::error!("Failed to commit source: {}", e); } - log::info!("Committed file to source: {}", source_id); + tracing::info!("Committed file to source: {}", source_id); return Some(()); } } diff --git a/plugins/warp/src/plugin/create.rs b/plugins/warp/src/plugin/create.rs index d6839ce6..04a3e9b6 100644 --- a/plugins/warp/src/plugin/create.rs +++ b/plugins/warp/src/plugin/create.rs @@ -10,6 +10,7 @@ use binaryninja::command::Command; use binaryninja::interaction::form::{Form, FormInputField}; use binaryninja::interaction::{MessageBoxButtonResult, MessageBoxButtonSet, MessageBoxIcon}; use binaryninja::rc::Ref; +use binaryninja::tracing; use std::path::PathBuf; use std::thread; use warp::chunk::Chunk; @@ -131,7 +132,7 @@ impl CreateFromCurrentView { existing_chunks.extend(existing_file.chunks); } MessageBoxButtonResult::CancelButton => { - log::info!( + tracing::info!( "User cancelled signature file creation, no operations were performed." ); return None; @@ -168,7 +169,7 @@ impl CreateFromCurrentView { MessageBoxButtonSet::OKButtonSet, MessageBoxIcon::ErrorIcon, ); - log::error!("Failed to create signature file: {}", err); + tracing::error!("Failed to create signature file: {}", err); return None; } @@ -184,7 +185,9 @@ impl CreateFromCurrentView { // After merging, we should have at least one chunk. If not, merging actually removed data. if file.chunks.len() < 1 { - log::error!("Failed to merge chunks! Please report this, it should not happen."); + tracing::error!( + "Failed to merge chunks! Please report this, it should not happen." + ); return None; } } @@ -192,9 +195,9 @@ impl CreateFromCurrentView { let file_bytes = file.to_bytes(); let file_size = file_bytes.len(); if std::fs::write(&file_path, file_bytes).is_err() { - log::error!("Failed to write data to signature file!"); + tracing::error!("Failed to write data to signature file!"); } - log::info!("Saved signature file to: '{}'", file_path.display()); + tracing::info!("Saved signature file to: '{}'", file_path.display()); background_task.finish(); // Show a report of the generate signatures, if desired. @@ -210,7 +213,7 @@ impl CreateFromCurrentView { // The ReportWidget uses a QTextBrowser, which cannot render large files very well. if file_size > 10000000 { - log::warn!("WARP report file is too large to show in the UI. Please see the report file on disk."); + tracing::warn!("WARP report file is too large to show in the UI. Please see the report file on disk."); } else { match report_kind { ReportKindField::None => {} diff --git a/plugins/warp/src/plugin/debug.rs b/plugins/warp/src/plugin/debug.rs index 399dba50..6db491e2 100644 --- a/plugins/warp/src/plugin/debug.rs +++ b/plugins/warp/src/plugin/debug.rs @@ -3,13 +3,13 @@ use crate::{build_function, cache}; use binaryninja::binary_view::BinaryView; use binaryninja::command::{Command, FunctionCommand}; use binaryninja::function::Function; -use binaryninja::ObjectDestructor; +use binaryninja::{tracing, ObjectDestructor}; pub struct DebugFunction; impl FunctionCommand for DebugFunction { fn action(&self, _view: &BinaryView, func: &Function) { - log::info!( + tracing::info!( "{:#?}", build_function(func, || func.lifted_il().ok(), false) ); @@ -25,7 +25,7 @@ pub struct DebugCache; impl Command for DebugCache { fn action(&self, _view: &BinaryView) { for_cached_containers(|c| { - log::info!("Container: {:#?}", c); + tracing::info!("Container: {:#?}", c); }); } @@ -40,7 +40,7 @@ impl Command for DebugInvalidateCache { fn action(&self, view: &BinaryView) { let destructor = cache::CacheDestructor {}; destructor.destruct_view(view); - log::info!("Invalidated all WARP caches..."); + tracing::info!("Invalidated all WARP caches..."); } fn valid(&self, _view: &BinaryView) -> bool { diff --git a/plugins/warp/src/plugin/ffi/container.rs b/plugins/warp/src/plugin/ffi/container.rs index 72c85366..6c2551c1 100644 --- a/plugins/warp/src/plugin/ffi/container.rs +++ b/plugins/warp/src/plugin/ffi/container.rs @@ -10,6 +10,7 @@ use binaryninja::architecture::CoreArchitecture; use binaryninja::binary_view::BinaryView; use binaryninja::rc::Ref; use binaryninja::string::BnString; +use binaryninja::tracing; use binaryninja::types::Type; use binaryninjacore_sys::{BNArchitecture, BNBinaryView, BNType}; use std::ffi::{c_char, CStr}; @@ -219,7 +220,7 @@ pub unsafe extern "C" fn BNWARPContainerFetchFunctions( let guids = unsafe { std::slice::from_raw_parts(guids, count) }; if let Err(e) = container.fetch_functions(&target, &source_tags, guids) { - log::error!("Failed to fetch functions: {}", e); + tracing::error!("Failed to fetch functions: {}", e); } } @@ -586,7 +587,7 @@ pub unsafe extern "C" fn BNWARPContainerSearch( let result = match container.search(&query) { Ok(result) => result, Err(err) => { - log::error!("Failed to search container {:?}: {}", query.deref(), err); + tracing::error!("Failed to search container {:?}: {}", query.deref(), err); return std::ptr::null_mut(); } }; diff --git a/plugins/warp/src/plugin/file.rs b/plugins/warp/src/plugin/file.rs index ec61bd78..899e3f46 100644 --- a/plugins/warp/src/plugin/file.rs +++ b/plugins/warp/src/plugin/file.rs @@ -1,6 +1,7 @@ use crate::report::ReportGenerator; use binaryninja::binary_view::{BinaryView, BinaryViewExt}; use binaryninja::command::Command; +use binaryninja::tracing; pub struct ShowFileReport; @@ -15,12 +16,12 @@ impl Command for ShowFileReport { }; let Ok(bytes) = std::fs::read(&path) else { - log::error!("Failed to read file: {:?}", path); + tracing::error!("Failed to read file: {:?}", path); return; }; let Some(file) = warp::WarpFile::from_bytes(&bytes) else { - log::error!("Failed to parse file: {:?}", path); + tracing::error!("Failed to parse file: {:?}", path); return; }; diff --git a/plugins/warp/src/plugin/function.rs b/plugins/warp/src/plugin/function.rs index 6202f9d7..3c0dc06c 100644 --- a/plugins/warp/src/plugin/function.rs +++ b/plugins/warp/src/plugin/function.rs @@ -10,6 +10,7 @@ use binaryninja::binary_view::{BinaryView, BinaryViewExt}; use binaryninja::command::{Command, FunctionCommand}; use binaryninja::function::{Function, FunctionUpdateType}; use binaryninja::rc::Guard; +use binaryninja::tracing; use rayon::iter::ParallelIterator; use std::thread; use warp::signature::function::FunctionGUID; @@ -24,7 +25,7 @@ impl FunctionCommand for IncludeFunction { let insert_tag_type = get_warp_include_tag_type(view); match should_add_tag { true => { - log::info!( + tracing::info!( "Including selected function '{}' at 0x{:x}", sym_name_str, func.start() @@ -32,7 +33,7 @@ impl FunctionCommand for IncludeFunction { func.add_tag(&insert_tag_type, "", None, false, None); } false => { - log::info!( + tracing::info!( "Removing included function '{}' at 0x{:x}", sym_name_str, func.start() @@ -58,7 +59,7 @@ impl FunctionCommand for IgnoreFunction { let ignore_tag_type = get_warp_ignore_tag_type(view); match should_add_tag { true => { - log::info!( + tracing::info!( "Ignoring function for matching '{}' at 0x{:x}", sym_name_str, func.start() @@ -66,7 +67,7 @@ impl FunctionCommand for IgnoreFunction { func.add_tag(&ignore_tag_type, "", None, false, None); } false => { - log::info!( + tracing::info!( "Including function for matching '{}' at 0x{:x}", sym_name_str, func.start() @@ -87,7 +88,7 @@ impl FunctionCommand for RemoveFunction { fn action(&self, _view: &BinaryView, func: &Function) { let sym_name = func.symbol().short_name(); let sym_name_str = sym_name.to_string_lossy(); - log::info!( + tracing::info!( "Removing matched function '{}' at 0x{:x}", sym_name_str, func.start() @@ -107,10 +108,10 @@ pub struct CopyFunctionGUID; impl FunctionCommand for CopyFunctionGUID { fn action(&self, _view: &BinaryView, func: &Function) { let Some(guid) = cached_function_guid(func, || func.lifted_il().ok()) else { - log::error!("Could not get guid for copied function"); + tracing::error!("Could not get guid for copied function"); return; }; - log::info!( + tracing::info!( "Function GUID for {:?}... {}", func.symbol().short_name(), guid @@ -137,11 +138,11 @@ impl Command for FindFunctionFromGUID { }; let Ok(searched_guid) = guid_str.parse::<FunctionGUID>() else { - log::error!("Failed to parse function guid... {}", guid_str); + tracing::error!("Failed to parse function guid... {}", guid_str); return; }; - log::info!("Searching functions for GUID... {}", searched_guid); + tracing::info!("Searching functions for GUID... {}", searched_guid); let funcs = view.functions(); let view = view.to_owned(); thread::spawn(move || { @@ -159,7 +160,7 @@ impl Command for FindFunctionFromGUID { .collect(); if matched.is_empty() { - log::info!("No matches found for GUID... {}", searched_guid); + tracing::info!("No matches found for GUID... {}", searched_guid); } else { for func in &matched { // Also navigate the user, as that is probably what they want. @@ -170,14 +171,14 @@ impl Command for FindFunctionFromGUID { .navigate_to(¤t_view, func.start()) .is_err() { - log::error!( + tracing::error!( "Failed to navigate to found function 0x{:0x} in view {}", func.start(), current_view ); } } - log::info!("Match found at function... 0x{:0x}", func.start()); + tracing::info!("Match found at function... 0x{:0x}", func.start()); } } diff --git a/plugins/warp/src/plugin/load.rs b/plugins/warp/src/plugin/load.rs index 0b8d1672..bd0e4838 100644 --- a/plugins/warp/src/plugin/load.rs +++ b/plugins/warp/src/plugin/load.rs @@ -10,6 +10,7 @@ use binaryninja::interaction::{ MessageBoxIcon, }; use binaryninja::rc::Ref; +use binaryninja::tracing; use std::collections::HashMap; use std::path::PathBuf; use std::sync::atomic::AtomicBool; @@ -130,7 +131,7 @@ impl LoadSignatureFile { let file = match LoadSignatureFile::read_file(&view, source_file_path.clone()) { Ok(file) => file, Err(e) => { - log::error!("Failed to read signature file: {}", e); + tracing::error!("Failed to read signature file: {}", e); return; } }; @@ -156,7 +157,7 @@ impl LoadSignatureFile { } let container_source = DiskContainerSource::new(source_file_path.clone(), file); - log::info!("Loading container source: '{}'", container_source.path); + tracing::info!("Loading container source: '{}'", container_source.path); let mut map = HashMap::new(); map.insert(source_file_path.to_source_id(), container_source); let container = DiskContainer::new("Loaded signatures".to_string(), map); diff --git a/plugins/warp/src/plugin/project.rs b/plugins/warp/src/plugin/project.rs index 725d164c..8862c00a 100644 --- a/plugins/warp/src/plugin/project.rs +++ b/plugins/warp/src/plugin/project.rs @@ -9,6 +9,7 @@ use binaryninja::interaction::{Form, FormInputField}; use binaryninja::project::folder::ProjectFolder; use binaryninja::project::Project; use binaryninja::rc::Ref; +use binaryninja::tracing; use binaryninja::worker_thread::{set_worker_thread_count, worker_thread_count}; use rayon::ThreadPoolBuilder; use regex::Regex; @@ -157,7 +158,7 @@ impl CreateSignatures { .create_file(&warp_file.to_bytes(), folder, name, "") .is_err() { - log::error!("Failed to create project file!"); + tracing::error!("Failed to create project file!"); } let report = ReportGenerator::new(); @@ -168,7 +169,7 @@ impl CreateSignatures { .create_file(&generated.into_bytes(), folder, &file_name, "Warp file") .is_err() { - log::error!("Failed to create project file!"); + tracing::error!("Failed to create project file!"); } } }; @@ -177,12 +178,12 @@ impl CreateSignatures { let callback_project = project.clone(); let save_individual_files_cb = move |path: &Path, file: &WarpFile| { if file.chunks.is_empty() { - log::debug!("Skipping empty file: {}", path.display()); + tracing::debug!("Skipping empty file: {}", path.display()); return; } // The path returned will be the one on disk, so we will go and grab the project for it. let Some(project_file) = callback_project.file_by_path(path) else { - log::error!("Failed to find project file for path: {}", path.display()); + tracing::error!("Failed to find project file for path: {}", path.display()); return; }; let project_file = project_file.to_owned(); @@ -214,8 +215,8 @@ impl CreateSignatures { processor = processor.with_file_filter(f); } Err(err) => { - log::error!("Failed to parse file filter: {}", err); - log::error!( + tracing::error!("Failed to parse file filter: {}", err); + tracing::error!( "Consider using a substring instead of a glob pattern, e.g. *.exe => exe" ); return; @@ -231,7 +232,7 @@ impl CreateSignatures { .num_threads(processing_thread_count) .build() else { - log::error!("Failed to create processing thread pool!"); + tracing::error!("Failed to create processing thread pool!"); return; }; @@ -240,7 +241,7 @@ impl CreateSignatures { let previous_worker_thread_count = worker_thread_count(); let upgraded_thread_count = previous_worker_thread_count * 3; if upgraded_thread_count > previous_worker_thread_count { - log::info!( + tracing::info!( "Setting worker thread count to {} for the duration of processing...", upgraded_thread_count ); @@ -253,14 +254,14 @@ impl CreateSignatures { save_warp_file(&project, None, "generated.warp", &warp_file); } Err(e) => { - log::error!("Failed to process project: {}", e); + tracing::error!("Failed to process project: {}", e); } }); let processed_file_count = processor .state() .files_with_state(ProcessingFileState::Processed); - log::info!( + tracing::info!( "Processing {} project files took: {:?}", processed_file_count, start.elapsed() diff --git a/plugins/warp/src/plugin/workflow.rs b/plugins/warp/src/plugin/workflow.rs index e5ce9b76..a51c7399 100644 --- a/plugins/warp/src/plugin/workflow.rs +++ b/plugins/warp/src/plugin/workflow.rs @@ -15,6 +15,7 @@ use binaryninja::command::Command; use binaryninja::function::Function as BNFunction; use binaryninja::rc::Ref as BNRef; use binaryninja::settings::{QueryOptions, Settings}; +use binaryninja::tracing; use binaryninja::workflow::{activity, Activity, AnalysisContext, Workflow, WorkflowBuilder}; use dashmap::DashSet; use itertools::Itertools; @@ -39,7 +40,7 @@ impl Command for RunMatcher { // Alert the user if we have no actual regions (+1 comes from the synthetic section). let regions = relocatable_regions(&view); if regions.len() <= 1 && view.memory_map().is_activated() { - log::warn!( + tracing::warn!( "No relocatable regions found, for best results please define sections for the binary!" ); } @@ -90,13 +91,15 @@ impl FunctionSet { .workflow() .expect("Function has no workflow"); if function_workflow.contains(GUID_ACTIVITY_NAME) { - log::error!("No function guids in database, please reanalyze the database."); + tracing::error!( + "No function guids in database, please reanalyze the database." + ); } else { - log::error!( - "Activity '{}' is not in workflow '{}', create function guids manually to run matcher...", - GUID_ACTIVITY_NAME, - function_workflow.name() - ) + tracing::error!( + "Activity '{}' is not in workflow '{}', create function guids manually to run matcher...", + GUID_ACTIVITY_NAME, + function_workflow.name() + ) } } return None; @@ -169,7 +172,7 @@ pub fn run_matcher(view: &BinaryView) { .maximum_possible_functions .is_some_and(|max| max < matched_functions.len() as u64) { - log::warn!( + tracing::warn!( "Skipping {}, too many possible functions: {}", guid, matched_functions.len() @@ -244,10 +247,10 @@ pub fn run_matcher(view: &BinaryView) { } if background_task.is_cancelled() { - log::info!("Matcher was cancelled by user, you may run it again by running the 'Run Matcher' command."); + tracing::info!("Matcher was cancelled by user, you may run it again by running the 'Run Matcher' command."); } - log::info!( + tracing::info!( "Function matching took {:.3} seconds and matched {} functions after {} rounds", start.elapsed().as_secs_f64(), matcher_results.len(), @@ -290,12 +293,12 @@ pub fn run_fetcher(view: &BinaryView) { }); if background_task.is_cancelled() { - log::info!( + tracing::info!( "Fetcher was cancelled by user, you may run it again by running the 'Fetch' command." ); } - log::info!("Fetching took {:?}", start.elapsed()); + tracing::info!("Fetching took {:?}", start.elapsed()); background_task.finish(); } |
