From ea111b55f97f4aef04a1778596bf07e1480c080e Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sat, 24 Aug 2024 18:51:30 -0400 Subject: [PATCH] Run rustfmt --- rust/binaryninjacore-sys/build.rs | 6 +-- .../dwarf/dwarf_import/src/dwarfdebuginfo.rs | 2 +- .../dwarf/dwarf_import/src/helpers.rs | 38 ++++++++++--------- rust/examples/dwarf/dwarf_import/src/lib.rs | 3 +- rust/examples/dwarf/dwarf_import/src/types.rs | 16 ++++---- rust/src/lib.rs | 21 +++++----- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs index 803c629c2..2c8850904 100644 --- a/rust/binaryninjacore-sys/build.rs +++ b/rust/binaryninjacore-sys/build.rs @@ -65,11 +65,7 @@ fn main() { // Make a symlink "libbinaryninjacore.so" pointing to "libbinaryninjacore.so.1" if symlink_target.exists() && symlink_source.symlink_metadata().is_err() { use std::os::unix::fs; - fs::symlink( - symlink_target, - symlink_source, - ) - .expect("failed to create required symlink"); + fs::symlink(symlink_target, symlink_source).expect("failed to create required symlink"); } println!("cargo:rustc-link-search={}", out_dir); } diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index a977deded..1935e0219 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -554,7 +554,7 @@ impl DebugInfoBuilder { if let Some(address) = func.address.as_mut() { let diff = bv.start().overflowing_sub(bv.original_image_base()).0; - *address = (*address).overflowing_add(diff).0; // rebase the address + *address = (*address).overflowing_add(diff).0; // rebase the address let existing_functions = bv.functions_at(*address); match existing_functions.len().cmp(&1) { Ordering::Greater => { diff --git a/rust/examples/dwarf/dwarf_import/src/helpers.rs b/rust/examples/dwarf/dwarf_import/src/helpers.rs index 0bc5e5b16..20dd1ed28 100644 --- a/rust/examples/dwarf/dwarf_import/src/helpers.rs +++ b/rust/examples/dwarf/dwarf_import/src/helpers.rs @@ -481,15 +481,23 @@ pub(crate) fn download_debug_info( } return Err("Could not find a server with debug info for this file".to_string()); } -pub(crate) fn find_local_debug_file_for_build_id(build_id: &String, view: &BinaryView) -> Option { +pub(crate) fn find_local_debug_file_for_build_id( + build_id: &String, + view: &BinaryView, +) -> Option { let settings = Settings::new(""); - let debug_dirs_enabled = settings.get_bool("analysis.debugInfo.enableDebugDirectories", Some(view), None); + let debug_dirs_enabled = settings.get_bool( + "analysis.debugInfo.enableDebugDirectories", + Some(view), + None, + ); if !debug_dirs_enabled { return None; } - let debug_info_paths = settings.get_string_list("analysis.debugInfo.debugDirectories", Some(view), None); + let debug_info_paths = + settings.get_string_list("analysis.debugInfo.debugDirectories", Some(view), None); if debug_info_paths.is_empty() { return None; @@ -536,10 +544,10 @@ pub(crate) fn load_debug_info_for_build_id( (None, false) } - pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option { let settings = Settings::new(""); - let load_sibling_debug = settings.get_bool("analysis.debugInfo.loadSiblingDebugFiles", Some(view), None); + let load_sibling_debug = + settings.get_bool("analysis.debugInfo.loadSiblingDebugFiles", Some(view), None); if !load_sibling_debug { return None; @@ -554,9 +562,7 @@ pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option { } if dsym_folder.exists() && dsym_folder.is_dir() { - let dsym_file = dsym_folder - .join("Contents/Resources/DWARF/") - .join(filename); // TODO: should this just pull any file out? Can there be multiple files? + let dsym_file = dsym_folder.join("Contents/Resources/DWARF/").join(filename); // TODO: should this just pull any file out? Can there be multiple files? if dsym_file.exists() { return Some(dsym_file.to_string_lossy().to_string()); } @@ -565,23 +571,21 @@ pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option { None } - pub(crate) fn load_sibling_debug_file(view: &BinaryView) -> (Option>, bool) { let Some(debug_file) = find_sibling_debug_file(view) else { return (None, false); }; let load_settings = match view.default_platform() { - Some(plat) => format!("{{\"analysis.debugInfo.internal\": false, \"loader.platform\": \"{}\"}}", plat.name()), - None => "{\"analysis.debugInfo.internal\": false}".to_string() + Some(plat) => format!( + "{{\"analysis.debugInfo.internal\": false, \"loader.platform\": \"{}\"}}", + plat.name() + ), + None => "{\"analysis.debugInfo.internal\": false}".to_string(), }; ( - binaryninja::load_with_options( - debug_file, - false, - Some(load_settings) - ), - false + binaryninja::load_with_options(debug_file, false, Some(load_settings)), + false, ) } diff --git a/rust/examples/dwarf/dwarf_import/src/lib.rs b/rust/examples/dwarf/dwarf_import/src/lib.rs index fd046210d..fafe9eaba 100644 --- a/rust/examples/dwarf/dwarf_import/src/lib.rs +++ b/rust/examples/dwarf/dwarf_import/src/lib.rs @@ -507,8 +507,7 @@ impl CustomDebugInfoParser for DWARFParser { let (external_file, close_external) = if !dwarfreader::is_valid(bv) { if let (Some(debug_view), x) = helpers::load_sibling_debug_file(bv) { (Some(debug_view), x) - } - else if let Ok(build_id) = get_build_id(bv) { + } else if let Ok(build_id) = get_build_id(bv) { helpers::load_debug_info_for_build_id(&build_id, bv) } else { (None, false) diff --git a/rust/examples/dwarf/dwarf_import/src/types.rs b/rust/examples/dwarf/dwarf_import/src/types.rs index 50f768cdc..4364f7ab7 100644 --- a/rust/examples/dwarf/dwarf_import/src/types.rs +++ b/rust/examples/dwarf/dwarf_import/src/types.rs @@ -285,15 +285,13 @@ pub(crate) fn get_type( ) { // This needs to recurse first (before the early return below) to ensure all sub-types have been parsed match die_reference { - DieReference::UnitAndOffset((dwarf, entry_unit, entry_offset)) => { - get_type( - dwarf, - entry_unit, - &entry_unit.entry(entry_offset).unwrap(), - debug_info_builder_context, - debug_info_builder, - ) - } + DieReference::UnitAndOffset((dwarf, entry_unit, entry_offset)) => get_type( + dwarf, + entry_unit, + &entry_unit.entry(entry_offset).unwrap(), + debug_info_builder_context, + debug_info_builder, + ), DieReference::Err => { warn!("Failed to fetch DIE when getting type through DW_AT_abstract_origin. Debug information may be incomplete."); None diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 3d6b0b989..e968ee225 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -232,27 +232,22 @@ unsafe extern "C" fn cb_progress_func bool>( closure(progress, total) } - unsafe extern "C" fn cb_progress_nop( _ctxt: *mut std::ffi::c_void, _arg1: usize, - _arg2: usize + _arg2: usize, ) -> bool { true } - /// The main way to open and load files into Binary Ninja. Make sure you've properly initialized the core before calling this function. See [`crate::headless::init()`] -pub fn load( - filename: S, -) -> Option> +pub fn load(filename: S) -> Option> where S: BnStrCompatible, { let filename = filename.into_bytes_with_nul(); let options = "\x00"; - let handle = unsafe { binaryninjacore_sys::BNLoadFilename( filename.as_ref().as_ptr() as *mut _, @@ -388,7 +383,7 @@ where let progress_ctx = match progress { Some(mut x) => &mut x as *mut F as *mut std::ffi::c_void, - None => core::ptr::null_mut() + None => core::ptr::null_mut(), }; let handle = unsafe { @@ -473,7 +468,7 @@ where let progress_ctx = match progress { Some(mut x) => &mut x as *mut F as *mut std::ffi::c_void, - None => core::ptr::null_mut() + None => core::ptr::null_mut(), }; let handle = unsafe { @@ -657,7 +652,9 @@ pub fn license_count() -> i32 { pub fn set_license(license: S) { let license = license.into_bytes_with_nul(); let license_slice = license.as_ref(); - unsafe { binaryninjacore_sys::BNSetLicense(license_slice.as_ptr() as *const std::os::raw::c_char) } + unsafe { + binaryninjacore_sys::BNSetLicense(license_slice.as_ptr() as *const std::os::raw::c_char) + } } pub fn product() -> string::BnString { @@ -682,7 +679,9 @@ pub fn is_ui_enabled() -> bool { pub fn is_database(filename: S) -> bool { let filename = filename.into_bytes_with_nul(); let filename_slice = filename.as_ref(); - unsafe { binaryninjacore_sys::BNIsDatabase(filename_slice.as_ptr() as *const std::os::raw::c_char) } + unsafe { + binaryninjacore_sys::BNIsDatabase(filename_slice.as_ptr() as *const std::os::raw::c_char) + } } pub fn plugin_abi_version() -> u32 {