From 7a521850cfce3f0b879210a34907380642c3b220 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Thu, 6 Jun 2024 21:48:58 -0400 Subject: Fix DWARF parser reporting as valid for any binary with a build id --- rust/examples/dwarf/dwarf_import/src/helpers.rs | 44 +++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'rust/examples/dwarf/dwarf_import/src/helpers.rs') diff --git a/rust/examples/dwarf/dwarf_import/src/helpers.rs b/rust/examples/dwarf/dwarf_import/src/helpers.rs index 8c19f4ad..babe9713 100644 --- a/rust/examples/dwarf/dwarf_import/src/helpers.rs +++ b/rust/examples/dwarf/dwarf_import/src/helpers.rs @@ -432,17 +432,22 @@ pub(crate) fn download_debug_info(view: &BinaryView) -> Result, } -pub(crate) fn load_debug_info_for_build_id(view: &BinaryView) -> Result>, String> { +pub(crate) fn find_local_debug_file(view: &BinaryView) -> Option { let settings = Settings::new(""); let debug_info_paths = settings.get_string_list("analysis.debugInfo.debugDirectories", Some(view), None); + if debug_info_paths.is_empty() { - return Ok(None) + return None } + let build_id = match get_build_id(view) { + Ok(x) => x, + Err(_) => return None, + }; + for debug_info_path in debug_info_paths.into_iter() { if let Ok(path) = PathBuf::from_str(&debug_info_path.to_string()) { - let build_id = get_build_id(view)?; let elf_path = path .join(&build_id[..2]) .join(&build_id[2..]) @@ -452,7 +457,6 @@ pub(crate) fn load_debug_info_for_build_id(view: &BinaryView) -> Result Result Result>, String> { + if let Some(debug_file_path) = find_local_debug_file(view) { + Ok( + binaryninja::load_with_options( + debug_file_path, + false, + Some("{\"analysis.debugInfo.internal\": false}") + ) + ) + } + else { + Ok(None) + } } -- cgit v1.3.1