diff options
| author | Mason Reed <mason@vector35.com> | 2024-10-19 20:53:10 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2024-11-04 19:43:26 -0500 |
| commit | 62f2dd7c6c89ca44f2096f535962b63f26f57730 (patch) | |
| tree | 01e2eb165809fc2a653680281a6879f8e6f02d65 | |
| parent | 8609cc98bad6926d7ca94f10112b315d5d820ee0 (diff) | |
Remove ability to panic on pre-initialized logger in rust
Typically this would never occur, however due to the mystical nature of linkers this somehow has happened outside of demo builds
| -rw-r--r-- | arch/msp430/src/lib.rs | 2 | ||||
| -rw-r--r-- | arch/riscv/src/lib.rs | 2 | ||||
| -rw-r--r-- | plugins/warp/src/plugin.rs | 2 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_export/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/idb_import/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/minidump/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/pdb-ng/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/test_demangler/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust/examples/workflow/src/lib.rs | 3 | ||||
| -rw-r--r-- | rust/src/logger.rs | 10 | ||||
| -rw-r--r-- | view/bintxt/src/lib.rs | 2 |
12 files changed, 17 insertions, 16 deletions
diff --git a/arch/msp430/src/lib.rs b/arch/msp430/src/lib.rs index 2e16d5d2..fd8af7a7 100644 --- a/arch/msp430/src/lib.rs +++ b/arch/msp430/src/lib.rs @@ -14,7 +14,7 @@ use architecture::Msp430; #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(log::LevelFilter::Info).unwrap(); + binaryninja::logger::init(log::LevelFilter::Info); let arch = binaryninja::architecture::register_architecture( "msp430", |custom_handle, handle| Msp430::new(handle, custom_handle), diff --git a/arch/riscv/src/lib.rs b/arch/riscv/src/lib.rs index aaeed66d..e59f68e9 100644 --- a/arch/riscv/src/lib.rs +++ b/arch/riscv/src/lib.rs @@ -2891,7 +2891,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer { #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(log::LevelFilter::Trace).expect("Failed to set up logging"); + binaryninja::logger::init(log::LevelFilter::Trace); use riscv_dis::{RiscVIMACDisassembler, Rv32GRegs, Rv64GRegs}; let arch32 = diff --git a/plugins/warp/src/plugin.rs b/plugins/warp/src/plugin.rs index a2d1bf5f..93f4f3b8 100644 --- a/plugins/warp/src/plugin.rs +++ b/plugins/warp/src/plugin.rs @@ -146,7 +146,7 @@ impl Command for DebugInvalidateCache { #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(LevelFilter::Debug).unwrap(); + binaryninja::logger::init(LevelFilter::Debug); // Make sure caches are flushed when the views get destructed. register_cache_destructor(); diff --git a/rust/examples/dwarf/dwarf_export/src/lib.rs b/rust/examples/dwarf/dwarf_export/src/lib.rs index 057abe27..05592f5f 100644 --- a/rust/examples/dwarf/dwarf_export/src/lib.rs +++ b/rust/examples/dwarf/dwarf_export/src/lib.rs @@ -781,7 +781,7 @@ impl Command for MyCommand { #[no_mangle] pub extern "C" fn CorePluginInit() -> bool { - init(LevelFilter::Debug).expect("Unable to initialize logger"); + init(LevelFilter::Debug); register( "Export as DWARF", diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs index b04c04db..20076d0c 100644 --- a/rust/examples/dwarf/dwarf_import/src/lib.rs +++ b/rust/examples/dwarf/dwarf_import/src/lib.rs @@ -658,7 +658,7 @@ impl CustomDebugInfoParser for DWARFParser { #[no_mangle] pub extern "C" fn CorePluginInit() -> bool { - logger::init(LevelFilter::Debug).unwrap(); + logger::init(LevelFilter::Debug); let settings = Settings::new(""); diff --git a/rust/examples/idb_import/src/lib.rs b/rust/examples/idb_import/src/lib.rs index 4bd75c79..0de688be 100644 --- a/rust/examples/idb_import/src/lib.rs +++ b/rust/examples/idb_import/src/lib.rs @@ -337,7 +337,7 @@ fn parse_id0_section_info( #[allow(non_snake_case)] #[no_mangle] pub extern "C" fn CorePluginInit() -> bool { - let _logger = logger::init(LevelFilter::Error); + logger::init(LevelFilter::Error); DebugInfoParser::register("IDB Parser", IDBDebugInfoParser); DebugInfoParser::register("TIL Parser", TILDebugInfoParser); true diff --git a/rust/examples/minidump/src/lib.rs b/rust/examples/minidump/src/lib.rs index 9d8b4054..c899591b 100644 --- a/rust/examples/minidump/src/lib.rs +++ b/rust/examples/minidump/src/lib.rs @@ -21,7 +21,7 @@ impl Command for PrintMemoryInformationCommand { #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(LevelFilter::Trace).expect("failed to initialize logging"); + binaryninja::logger::init(LevelFilter::Trace); debug!("Registering minidump binary view type"); register_view_type("Minidump", "Minidump", view::MinidumpBinaryViewType::new); diff --git a/rust/examples/pdb-ng/src/lib.rs b/rust/examples/pdb-ng/src/lib.rs index e6a97be5..bc12caae 100644 --- a/rust/examples/pdb-ng/src/lib.rs +++ b/rust/examples/pdb-ng/src/lib.rs @@ -697,7 +697,7 @@ pub extern "C" fn PDBPluginInit() -> bool { } fn init_plugin() -> bool { - let _ = logger::init(LevelFilter::Debug); + logger::init(LevelFilter::Debug); DebugInfoParser::register("PDB", PDBParser {}); let settings = Settings::new(""); diff --git a/rust/examples/test_demangler/src/lib.rs b/rust/examples/test_demangler/src/lib.rs index eaa38dad..6735d5fb 100644 --- a/rust/examples/test_demangler/src/lib.rs +++ b/rust/examples/test_demangler/src/lib.rs @@ -57,7 +57,7 @@ impl Command for DemangleCommand { #[no_mangle] pub extern "C" fn CorePluginInit() -> bool { - let _ = logger::init(LevelFilter::Info); + logger::init(LevelFilter::Info); Demangler::register("Test", TestDemangler {}); command::register("Demangle Test", "Test", DemangleCommand {}); true diff --git a/rust/examples/workflow/src/lib.rs b/rust/examples/workflow/src/lib.rs index 3e295c51..47a8d2c8 100644 --- a/rust/examples/workflow/src/lib.rs +++ b/rust/examples/workflow/src/lib.rs @@ -5,7 +5,6 @@ use binaryninja::workflow::{Activity, AnalysisContext, Workflow}; use log::LevelFilter; const RUST_ACTIVITY_NAME: &'static str = "analysis.plugins.rustexample"; -// TODO: runOnce needs to be on... const RUST_ACTIVITY_CONFIG: &'static str = r#"{ "name": "analysis.plugins.rustexample", "title" : "Rust Example", @@ -56,7 +55,7 @@ fn example_activity(analysis_context: &AnalysisContext) { #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(LevelFilter::Debug).unwrap(); + binaryninja::logger::init(LevelFilter::Info); log::info!("Initialized the plugin"); diff --git a/rust/src/logger.rs b/rust/src/logger.rs index 6e0b1887..4e9dd1f9 100644 --- a/rust/src/logger.rs +++ b/rust/src/logger.rs @@ -75,11 +75,13 @@ impl log::Log for Logger { fn flush(&self) {} } -/// Uses BinaryNinja's logging functionality as the sink for -/// Rust's `log` crate. -pub fn init(filter: log::LevelFilter) -> Result<(), log::SetLoggerError> { +/// Uses BinaryNinja's logging functionality as the sink for Rust's `log` crate. +/// +/// NOTE: There is no guarantee that logs will be sent to BinaryNinja as another log sink +/// may have already been initialized beforehand. +pub fn init(filter: log::LevelFilter) { log::set_max_level(filter); - log::set_logger(&LOGGER) + let _ = log::set_logger(&LOGGER); } pub trait LogListener: 'static + Sync { diff --git a/view/bintxt/src/lib.rs b/view/bintxt/src/lib.rs index 96cd1835..fbf3682d 100644 --- a/view/bintxt/src/lib.rs +++ b/view/bintxt/src/lib.rs @@ -12,7 +12,7 @@ use std::ops::Range; #[no_mangle] #[allow(non_snake_case)] pub extern "C" fn CorePluginInit() -> bool { - binaryninja::logger::init(log::LevelFilter::Error).expect("Unable to initialize logger"); + binaryninja::logger::init(log::LevelFilter::Error); binaryninja::custombinaryview::register_view_type(c"ti-txt", c"TI-TXT", |core| { TiTxtViewConstructor { core } |
