diff --git a/src/libfind/mod.rs b/src/libfind/mod.rs index 6e5870e..939e383 100644 --- a/src/libfind/mod.rs +++ b/src/libfind/mod.rs @@ -90,11 +90,21 @@ pub struct Segref { /// * `cslist`: List of public symbols of segments found in the file at each address and the /// symbols it references /// * `rslist`: HashMap of public symbols referenced by segments by address -pub fn process_segrefs(cslist: &mut [Vec], rslist: &mut RefHashMap) -> Vec { +/// * `skip_multiple`: whether to skip addresses with multiple recognized symbols +pub fn process_segrefs( + cslist: &mut [Vec], + rslist: &mut RefHashMap, + skip_amount: Option, +) -> Vec { // first get all symbols which lay in the file let mut segrefs: Vec = Vec::new(); for i in 0..cslist.len() { let matches = unify_refs(cslist, rslist, i); + if let Some(amount) = skip_amount { + if matches.len() > amount { + continue; + } + } for (s, r) in matches { segrefs.push(Segref { location: i, @@ -108,6 +118,11 @@ pub fn process_segrefs(cslist: &mut [Vec], rslist: &mut RefHashMap) - let mut leftover_refs: Vec<_> = rslist.iter().filter(|(i, _)| **i >= cslist.len()).collect(); leftover_refs.sort_by_key(|(i, _)| **i); for (i, arr) in leftover_refs.into_iter() { + if let Some(amount) = skip_amount { + if arr.len() > amount { + continue; + } + } for s in arr.iter().filter(|s| s.1 == RefKind::Valid) { segrefs.push(Segref { location: *i, diff --git a/src/main.rs b/src/main.rs index a50c499..2f42d49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,9 @@ struct Libfind { /// Minimum length of function to match, excluding fixed up addresses (in bytes) #[arg(short, long, default_value_t = 4)] min_fn_length: usize, + /// Skip addresses where more than n functions are found + #[arg(short, long)] + skip_multiple: Option, } #[derive(Parser, Debug)] @@ -204,6 +207,7 @@ fn main() { file, mut libraries, min_fn_length, + skip_multiple, }) => { let contents = read_whole_file_by_name(&file); let check = !no_check; @@ -220,7 +224,7 @@ fn main() { eprintln!("Could not process library files: {}", err); process::exit(2); }); - let segrefs = libfind::process_segrefs(&mut pubnames, &mut refnames); + let segrefs = libfind::process_segrefs(&mut pubnames, &mut refnames, skip_multiple); if json { let json_str = serde_json::to_string(&segrefs).unwrap_or_else(|err| { eprintln!("Could not print json: {}", err);