Skip to content

Commit

Permalink
Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emesare committed Aug 24, 2024
1 parent 1a22d2f commit ea111b5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 45 deletions.
6 changes: 1 addition & 5 deletions rust/binaryninjacore-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
38 changes: 21 additions & 17 deletions rust/examples/dwarf/dwarf_import/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
pub(crate) fn find_local_debug_file_for_build_id(
build_id: &String,
view: &BinaryView,
) -> Option<String> {
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;
Expand Down Expand Up @@ -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<String> {
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;
Expand All @@ -554,9 +562,7 @@ pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option<String> {
}

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());
}
Expand All @@ -565,23 +571,21 @@ pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option<String> {
None
}


pub(crate) fn load_sibling_debug_file(view: &BinaryView) -> (Option<Ref<BinaryView>>, 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,
)
}
3 changes: 1 addition & 2 deletions rust/examples/dwarf/dwarf_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions rust/examples/dwarf/dwarf_import/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,13 @@ pub(crate) fn get_type<R: ReaderType>(
) {
// 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
Expand Down
21 changes: 10 additions & 11 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,22 @@ unsafe extern "C" fn cb_progress_func<F: FnMut(usize, usize) -> 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<S>(
filename: S,
) -> Option<rc::Ref<binaryview::BinaryView>>
pub fn load<S>(filename: S) -> Option<rc::Ref<binaryview::BinaryView>>
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 _,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -657,7 +652,9 @@ pub fn license_count() -> i32 {
pub fn set_license<S: string::BnStrCompatible>(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 {
Expand All @@ -682,7 +679,9 @@ pub fn is_ui_enabled() -> bool {
pub fn is_database<S: string::BnStrCompatible>(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 {
Expand Down

0 comments on commit ea111b5

Please sign in to comment.