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/workflow_objc/src | |
| 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/workflow_objc/src')
7 files changed, 29 insertions, 25 deletions
diff --git a/plugins/workflow_objc/src/activities/objc_msg_send_calls.rs b/plugins/workflow_objc/src/activities/objc_msg_send_calls.rs index b39c843c..86024047 100644 --- a/plugins/workflow_objc/src/activities/objc_msg_send_calls.rs +++ b/plugins/workflow_objc/src/activities/objc_msg_send_calls.rs @@ -7,6 +7,7 @@ use binaryninja::{ instruction::{InstructionHandler as _, LowLevelILInstruction, LowLevelILInstructionKind}, operation::{CallSsa, Operation}, }, + tracing, variable::PossibleValueSet, workflow::AnalysisContext, }; @@ -53,7 +54,7 @@ pub fn process(ac: &AnalysisContext) -> Result<(), Error> { Ok(true) => function_changed = true, Ok(_) => {} Err(err) => { - log::error!( + tracing::error!( "Error processing instruction at {:#x}: {}", insn.address(), err diff --git a/plugins/workflow_objc/src/activities/objc_msg_send_calls/rewrite_to_direct_call.rs b/plugins/workflow_objc/src/activities/objc_msg_send_calls/rewrite_to_direct_call.rs index 0ddf2945..56c2aa52 100644 --- a/plugins/workflow_objc/src/activities/objc_msg_send_calls/rewrite_to_direct_call.rs +++ b/plugins/workflow_objc/src/activities/objc_msg_send_calls/rewrite_to_direct_call.rs @@ -4,6 +4,7 @@ use binaryninja::{ function::{LowLevelILFunction, Mutable, NonSSA, SSA}, instruction::{InstructionHandler as _, LowLevelILInstruction, LowLevelILInstructionKind}, }, + tracing, }; use super::MessageSendType; @@ -48,7 +49,7 @@ pub fn process_call( Ok(()) } _ => { - log::error!( + tracing::error!( "Unexpected LLIL operation for objc_msgSend call at {:#x}", insn.address() ); diff --git a/plugins/workflow_objc/src/activities/remove_memory_management.rs b/plugins/workflow_objc/src/activities/remove_memory_management.rs index 3990f010..fdd76650 100644 --- a/plugins/workflow_objc/src/activities/remove_memory_management.rs +++ b/plugins/workflow_objc/src/activities/remove_memory_management.rs @@ -11,6 +11,7 @@ use binaryninja::{ lifting::LowLevelILLabel, LowLevelILRegisterKind, }, + tracing, variable::PossibleValueSet, workflow::AnalysisContext, }; @@ -176,7 +177,7 @@ pub fn process(ac: &AnalysisContext) -> Result<(), Error> { Ok(true) => function_changed = true, Ok(_) => {} Err(err) => { - log::error!( + tracing::error!( "Error processing instruction at {:#x}: {}", insn.address(), err diff --git a/plugins/workflow_objc/src/activities/super_init.rs b/plugins/workflow_objc/src/activities/super_init.rs index cfd3ecdc..1cdf8825 100644 --- a/plugins/workflow_objc/src/activities/super_init.rs +++ b/plugins/workflow_objc/src/activities/super_init.rs @@ -10,6 +10,7 @@ use binaryninja::{ MediumLevelILFunction, MediumLevelILLiftedInstruction, MediumLevelILLiftedInstructionKind, }, rc::Ref, + tracing, types::Type, variable::{RegisterValueType, SSAVariable}, workflow::AnalysisContext, @@ -148,7 +149,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type src: super_param_var, }) = super_param.kind else { - log::debug!( + tracing::debug!( "Unhandled super paramater format at {:#0x} {:?}", super_param.address, super_param @@ -163,7 +164,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type .function .ssa_variable_definition(&super_param_var) else { - log::debug!(" could not find definition of variable?"); + tracing::debug!(" could not find definition of variable?"); return None; }; @@ -171,7 +172,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type MediumLevelILLiftedInstructionKind::SetVarSsa(LiftedSetVarSsa { src, .. }) => src, _ => { // The Swift compiler generates code that conditionally assigns to the receiver field of `objc_super`. - log::debug!( + tracing::debug!( "Unexpected variable definition kind at {:#0x} {:#x?}", super_param_def.address, super_param_def @@ -184,7 +185,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type MediumLevelILLiftedInstructionKind::AddressOf(Var { src: src_var }) => src_var, _ => { // The Swift compiler generates code that initializes the `objc_super` variable in more varied ways. - log::debug!( + tracing::debug!( " found non-address-of variable definition of `objc_super` variable at {:#0x} {:?}", super_param_def.address, super_param_def @@ -223,7 +224,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type // If there are zero, that likely means the assigned value was not a constant. Handling // that is above my pay grade. let &[super_class_ptr] = &super_class_constants[..] else { - log::debug!( + tracing::debug!( "Unexpected number of assignments to super class found for {:#0x}: {:#0x?}", src.address, super_class_constants @@ -232,7 +233,7 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type }; let Some(super_class_symbol) = view.symbol_by_address(super_class_ptr) else { - log::debug!("No symbol found for super class at {super_class_ptr:#0x}"); + tracing::debug!("No symbol found for super class at {super_class_ptr:#0x}"); return None; }; @@ -240,12 +241,14 @@ fn return_type_for_super_init(call: &Call, view: &BinaryView) -> Option<Ref<Type let Some(class_name) = class_name_from_symbol_name(super_class_symbol_name.to_bytes().as_bstr()) else { - log::debug!("Unable to extract class name from symbol name: {super_class_symbol_name:?}"); + tracing::debug!( + "Unable to extract class name from symbol name: {super_class_symbol_name:?}" + ); return None; }; let Some(class_type) = view.type_by_name(class_name.to_str_lossy()) else { - log::debug!("No type found for class named {class_name:?}"); + tracing::debug!("No type found for class named {class_name:?}"); return None; }; diff --git a/plugins/workflow_objc/src/lib.rs b/plugins/workflow_objc/src/lib.rs index 8c859c6b..5b41b6d0 100644 --- a/plugins/workflow_objc/src/lib.rs +++ b/plugins/workflow_objc/src/lib.rs @@ -1,4 +1,4 @@ -use binaryninja::{add_optional_plugin_dependency, logger::Logger, settings::Settings}; +use binaryninja::{add_optional_plugin_dependency, settings::Settings, tracing}; mod activities; mod error; @@ -8,15 +8,11 @@ mod workflow; pub use error::Error; use metadata::GlobalState; -use log::LevelFilter; - fn plugin_init() -> bool { - Logger::new("Plugin.Objective-C") - .with_level(LevelFilter::Debug) - .init(); + binaryninja::tracing_init!("Plugin.Objective-C"); if workflow::register_activities().is_err() { - log::warn!("Failed to register Objective-C workflow"); + tracing::warn!("Failed to register Objective-C workflow"); return false; }; diff --git a/plugins/workflow_objc/src/metadata/global_state.rs b/plugins/workflow_objc/src/metadata/global_state.rs index 61104451..c6682a5f 100644 --- a/plugins/workflow_objc/src/metadata/global_state.rs +++ b/plugins/workflow_objc/src/metadata/global_state.rs @@ -1,10 +1,11 @@ +use binaryninja::file_metadata::SessionId; use binaryninja::{ binary_view::{BinaryView, BinaryViewBase, BinaryViewExt}, file_metadata::FileMetadata, metadata::Metadata, rc::Ref, settings::{QueryOptions, Settings}, - ObjectDestructor, + tracing, ObjectDestructor, }; use dashmap::DashMap; use once_cell::sync::Lazy; @@ -31,8 +32,8 @@ struct SelectorImplementations { sel_to_impl: HashMap<u64, Vec<u64>>, } -static VIEW_INFOS: Lazy<DashMap<usize, Arc<AnalysisInfo>>> = Lazy::new(DashMap::new); -static IGNORED_VIEWS: Lazy<DashMap<usize, bool>> = Lazy::new(DashMap::new); +static VIEW_INFOS: Lazy<DashMap<SessionId, Arc<AnalysisInfo>>> = Lazy::new(DashMap::new); +static IGNORED_VIEWS: Lazy<DashMap<SessionId, bool>> = Lazy::new(DashMap::new); struct ObjectLifetimeObserver; @@ -69,7 +70,7 @@ impl GlobalState { observer.register(); } - fn id(bv: &BinaryView) -> usize { + fn id(bv: &BinaryView) -> SessionId { bv.file().session_id() } @@ -159,7 +160,7 @@ impl AnalysisInfo { }; let version_meta = meta.get("version")?; if version_meta.get_unsigned_integer()? != 1 { - log::error!( + tracing::error!( "workflow_objc: Unexpected Objective-C metadata version. Expected 1, got {}.", version_meta.get_unsigned_integer()? ); @@ -192,7 +193,7 @@ impl AnalysisInfo { for item in &array { let item = item.get_array()?; if item.len() != 2 { - log::warn!( + tracing::warn!( "Expected selector implementation metadata to have 2 items, found {}", item.len() ); diff --git a/plugins/workflow_objc/src/workflow.rs b/plugins/workflow_objc/src/workflow.rs index 08a39042..13e3a71e 100644 --- a/plugins/workflow_objc/src/workflow.rs +++ b/plugins/workflow_objc/src/workflow.rs @@ -1,3 +1,4 @@ +use binaryninja::tracing; use binaryninja::workflow::{activity, Activity, AnalysisContext, Workflow}; use crate::{activities, error::WorkflowRegistrationError}; @@ -15,7 +16,7 @@ fn run<E: std::fmt::Debug>( ) -> impl Fn(&AnalysisContext) { move |ac| { if let Err(err) = func(ac) { - log::debug!("Error occurred while running activity: {err:#x?}"); + tracing::debug!("Error occurred while running activity: {err:#x?}"); } } } |
