From 4701de32f6435d25b0e9c3dbd4b21ee9047a6bc9 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 3 Jun 2024 18:06:10 -0600 Subject: [PATCH] Check for existing function with `bl` Ensures that the analyzer won't create a function when the target is already contained within a function. Useful with manual asm that would otherwise trip up the analyzer. Partial work for #56 --- src/analysis/slices.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/analysis/slices.rs b/src/analysis/slices.rs index a8581cc..ce121fa 100644 --- a/src/analysis/slices.rs +++ b/src/analysis/slices.rs @@ -15,7 +15,7 @@ use crate::{ vm::{section_address_for, BranchTarget, GprValue, StepResult, VM}, RelocationTarget, }, - obj::{ObjInfo, ObjKind, ObjSection}, + obj::{ObjInfo, ObjKind, ObjSection, ObjSymbolKind}, }; #[derive(Debug, Default, Clone)] @@ -375,7 +375,24 @@ impl FunctionSlices { } } if branch.link { - self.function_references.insert(addr); + // See if any existing functions contain this address, + // since this could be a label inside a larger function. + let last_function = obj + .symbols + .for_section_range(addr.section, ..addr.address) + .rfind(|(_, symbol)| symbol.kind == ObjSymbolKind::Function); + match last_function { + Some((_, symbol)) + if symbol.address + symbol.size > addr.address as u64 => + { + // Set the function reference to the start of the function + self.function_references.insert(SectionAddress::new( + addr.section, + symbol.address as u32, + )) + } + _ => self.function_references.insert(addr), + }; } else { out_branches.push(addr); if self.add_block_start(addr) {