Skip to content

Commit aab7d16

Browse files
committed
option to check multiple files
1 parent c4f56c4 commit aab7d16

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/main.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use std::collections::HashMap;
3333
#[cfg(all(target_os = "linux", feature = "elf"))]
3434
use std::collections::HashSet;
3535
use std::ffi::OsStr;
36+
use std::io::BufRead;
37+
use std::io::BufReader;
3638
use std::io::ErrorKind;
3739
#[cfg(all(feature = "color", not(target_os = "windows")))]
3840
use std::os::unix::fs::PermissionsExt;
@@ -774,6 +776,13 @@ fn main() {
774776
.value_name("FILE")
775777
.help("Target file"),
776778
)
779+
.arg(
780+
Arg::new("listfile")
781+
.short('L')
782+
.long("listfile")
783+
.value_name("LISTFILE")
784+
.help("Textfile with one filepath in each line"),
785+
)
777786
.arg(
778787
Arg::new("json")
779788
.short('j')
@@ -842,14 +851,15 @@ fn main() {
842851
)
843852
.group(
844853
ArgGroup::new("operation")
845-
.args(["directory", "file", "pid", "process", "process-all"])
854+
.args(["directory", "file", "listfile", "pid", "process", "process-all"])
846855
.required(true),
847856
)
848857
.get_matches();
849858

850859
// required operation
851860
let file = args.get_one::<String>("file");
852861
let directory = args.get_one::<String>("directory");
862+
let listfile = args.get_one::<String>("listfile");
853863
let procids = args.get_one::<String>("pid");
854864
let procname = args.get_one::<String>("process");
855865
let procall = args.get_flag("process-all");
@@ -976,5 +986,33 @@ fn main() {
976986
process::exit(1);
977987
}
978988
}
989+
} else if let Some(listfile) = listfile {
990+
let file_path = Path::new(listfile);
991+
992+
if !file_path.is_file() {
993+
eprintln!("Listfile {} not found", underline!(listfile));
994+
process::exit(1);
995+
}
996+
997+
let f = fs::File::open(file_path).unwrap();
998+
let mut reader = BufReader::new(f);
999+
let mut line = String::new();
1000+
let mut bins: Vec<Binary> = Vec::new();
1001+
1002+
while let Ok(size) = reader.read_line(&mut line) {
1003+
if size == 0 {
1004+
break;
1005+
}
1006+
let binary_file_path = Path::new(line.trim());
1007+
if !binary_file_path.is_file() {
1008+
eprintln!("File {} not found", underline!(line.trim()));
1009+
process::exit(1);
1010+
}
1011+
if let Ok(mut result) = parse_single_file(binary_file_path, libraries) {
1012+
bins.append(&mut result);
1013+
}
1014+
line.clear();
1015+
}
1016+
print_binary_results(&bins, &settings);
9791017
}
9801018
}

0 commit comments

Comments
 (0)