Skip to content

Commit

Permalink
add skip-multiple argument
Browse files Browse the repository at this point in the history
  • Loading branch information
8051Enthusiast committed Feb 28, 2024
1 parent 0bb19f7 commit 890ffcd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/libfind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pubsymref>], rslist: &mut RefHashMap) -> Vec<Segref> {
/// * `skip_multiple`: whether to skip addresses with multiple recognized symbols
pub fn process_segrefs(
cslist: &mut [Vec<Pubsymref>],
rslist: &mut RefHashMap,
skip_amount: Option<usize>,
) -> Vec<Segref> {
// first get all symbols which lay in the file
let mut segrefs: Vec<Segref> = 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,
Expand All @@ -108,6 +118,11 @@ pub fn process_segrefs(cslist: &mut [Vec<Pubsymref>], 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,
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 890ffcd

Please sign in to comment.