summaryrefslogtreecommitdiff
path: root/rust/examples
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-12-06 09:33:32 -0500
committerKyleMiles <krm504@nyu.edu>2023-12-06 09:33:32 -0500
commit6e1a863a4b20d73610e88cb7d9adf676c1053fce (patch)
tree8fd1f76c595f51e1b68fd0da93ac7148410ac1ea /rust/examples
parent9139a14d6b269c4d3dd366959f2e5259bf8fe20f (diff)
DWARF Import : Check if functions already exist at parsed addresses and copy their platform info if they do. Resolves #4798
Diffstat (limited to 'rust/examples')
-rw-r--r--rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
index 429e64e2..ce72a299 100644
--- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
+++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs
@@ -17,6 +17,7 @@ use crate::helpers::{get_uid, resolve_specification, DieReference};
use binaryninja::{
binaryview::{BinaryView, BinaryViewBase, BinaryViewExt},
debuginfo::{DebugFunctionInfo, DebugInfo},
+ platform::Platform,
rc::*,
symbol::SymbolType,
templatesimplifier::simplify_str_to_fqn,
@@ -25,7 +26,7 @@ use binaryninja::{
use gimli::{DebuggingInformationEntry, Dwarf, Reader, Unit};
-use log::error;
+use log::{error, warn};
use std::{
collections::{hash_map::Values, HashMap},
ffi::CString,
@@ -45,6 +46,7 @@ pub(crate) struct FunctionInfoBuilder {
pub(crate) return_type: Option<TypeUID>,
pub(crate) address: Option<u64>,
pub(crate) parameters: Vec<Option<(CString, TypeUID)>>,
+ pub(crate) platform: Option<Ref<Platform>>,
}
impl FunctionInfoBuilder {
@@ -208,6 +210,7 @@ impl DebugInfoBuilder {
return_type,
address,
parameters,
+ platform: None,
});
}
}
@@ -334,8 +337,6 @@ impl DebugInfoBuilder {
fn commit_functions(&self, debug_info: &mut DebugInfo) {
for function in self.functions() {
- // TODO : Handle
- let platform = None;
// let calling_convention: Option<Ref<CallingConvention<CoreArchitecture>>> = None;
debug_info.add_function(DebugFunctionInfo::new(
@@ -344,16 +345,17 @@ impl DebugInfoBuilder {
function.raw_name.clone(),
Some(self.get_function_type(function)),
function.address,
- platform,
+ function.platform.clone(),
));
}
}
pub(crate) fn post_process(&mut self, bv: &BinaryView, _debug_info: &mut DebugInfo) -> &Self {
- // TODO : We don't need post-processing is we process correctly the first time....
+ // TODO : We don't need post-processing if we process correctly the first time....
// When originally resolving names, we need to check:
// If there's already a name from binja that's "more correct" than what we found (has more namespaces)
// If there's no name for the DIE, but there's a linkage name that's resolved in binja to a usable name
+ // This is no longer true, because DWARF doesn't provide platform information for functions, so we at least need to post-process thumb functions
for func in &mut self.functions {
// If the function's raw name already exists in the binary...
@@ -381,6 +383,15 @@ impl DebugInfoBuilder {
}
}
}
+
+ if let Some(address) = func.address {
+ let existing_functions = bv.functions_at(address);
+ if existing_functions.len() > 1 {
+ warn!("Multiple existing functions at address {address:08x}. One or more functions at this address may have the wrong platform information. Please report this binary.");
+ } else if existing_functions.len() == 1 {
+ func.platform = Some(existing_functions.get(0).platform());
+ }
+ }
}
self