Support matching multiple symbols with signatures

Half of #20
This commit is contained in:
Luke Street 2024-01-06 18:31:33 -07:00
parent 458d0599f5
commit 85e044463e

View File

@ -1,4 +1,5 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use itertools::Itertools;
use crate::{ use crate::{
analysis::{ analysis::{
@ -203,17 +204,17 @@ const POST_SIGNATURES: &[(&str, &str)] = &[
]; ];
fn apply_signature_for_symbol(obj: &mut ObjInfo, name: &str, sig_str: &str) -> Result<()> { fn apply_signature_for_symbol(obj: &mut ObjInfo, name: &str, sig_str: &str) -> Result<()> {
let Some((_, symbol)) = obj.symbols.by_name(name)? else { for symbol_idx in obj.symbols.for_name(name).map(|(i, _)| i).collect_vec() {
return Ok(()); let symbol = &obj.symbols[symbol_idx];
};
let Some(section_index) = symbol.section else { let Some(section_index) = symbol.section else {
return Ok(()); continue;
}; };
let addr = symbol.address as u32; let addr = symbol.address as u32;
let section = &obj.sections[section_index]; let section = &obj.sections[section_index];
if let Some(signature) = check_signatures_str(section, addr, sig_str)? { if let Some(signature) = check_signatures_str(section, addr, sig_str)? {
apply_signature(obj, SectionAddress::new(section_index, addr), &signature)?; apply_signature(obj, SectionAddress::new(section_index, addr), &signature)?;
} }
}
Ok(()) Ok(())
} }