1 //! Tool to fingerprint the files on the device's filesystem.
2 // Run with:
3 // adb root
4 // m adevice_fingerprint
5 // adb push $ANDROID_PRODUCT_OUT/system/bin/adevice_fingerprint /system/bin/adevice_fingerprint
6 // adb shell /system/bin/adevice_fingerprint --partitions system
7
8 use clap::Parser;
9 use std::io;
10 use std::path::PathBuf;
11 use std::process;
12
13 mod fingerprint;
14
main()15 fn main() {
16 let cli = HelperCli::parse();
17 let partitions: Vec<PathBuf> = cli.partitions.iter().map(PathBuf::from).collect();
18 let root = PathBuf::from("/");
19
20 let infos = fingerprint::fingerprint_partitions(&root, &partitions).unwrap_or_else(|err| {
21 eprintln!("Error scanning directories: {}", err);
22 process::exit(1);
23 });
24
25 serde_json::to_writer(io::stdout(), &infos).unwrap_or_else(|err| {
26 eprintln!("Error writing json: {}", err);
27 process::exit(1);
28 });
29 }
30
31 #[derive(Parser, Debug)]
32 #[command(version = "0.4")]
33 struct HelperCli {
34 /// Partitions in the product tree to report. Repeat or comma-separate.
35 #[arg(long, short, global = true,
36 default_values_t = [String::from("system")], value_delimiter = ',')]
37 partitions: Vec<String>,
38 }
39
40 #[cfg(test)]
41 #[allow(unused)]
42 mod tests {
43 use crate::fingerprint;
44 use std::path::PathBuf;
45
46 // TODO(rbraunstein): Write better device tests.
47 #[test]
fingerprint_apex()48 fn fingerprint_apex() {
49 // Walking system fails on permssion denied because the test isn't run as root.
50 // TODO(rbraunstein): figure out how to run as root and deal better with filesystem errors.
51 /*
52 let partitions: Vec<PathBuf> = Vec::from([PathBuf::from("system")]);
53 let root = PathBuf::from("/");
54
55 let infos = fingerprint::fingerprint_partitions(&root, &partitions).unwrap();
56 assert!(infos.len() > 2000);
57 */
58 }
59 }
60