]>
Commit | Line | Data |
---|---|---|
17df50a5 XL |
1 | use object::read::macho::DyldCache; |
2 | use object::Endianness; | |
3 | use std::{env, fs, process}; | |
4 | ||
5 | fn main() { | |
6 | let arg_len = env::args().len(); | |
7 | if arg_len <= 1 { | |
8 | eprintln!("Usage: {} <file> ...", env::args().next().unwrap()); | |
9 | process::exit(1); | |
10 | } | |
11 | ||
12 | for file_path in env::args().skip(1) { | |
13 | if arg_len > 2 { | |
14 | println!(); | |
15 | println!("{}:", file_path); | |
16 | } | |
17 | ||
18 | let file = match fs::File::open(&file_path) { | |
19 | Ok(file) => file, | |
20 | Err(err) => { | |
21 | println!("Failed to open file '{}': {}", file_path, err,); | |
22 | continue; | |
23 | } | |
24 | }; | |
25 | let file = match unsafe { memmap2::Mmap::map(&file) } { | |
26 | Ok(mmap) => mmap, | |
27 | Err(err) => { | |
28 | println!("Failed to map file '{}': {}", file_path, err,); | |
29 | continue; | |
30 | } | |
31 | }; | |
32 | let cache = match DyldCache::<Endianness>::parse(&*file) { | |
33 | Ok(cache) => cache, | |
34 | Err(err) => { | |
35 | println!( | |
36 | "Failed to parse Dyld shared cache file '{}': {}", | |
37 | file_path, err, | |
38 | ); | |
39 | continue; | |
40 | } | |
41 | }; | |
42 | ||
43 | // Print the list of image paths in this file. | |
44 | for image in cache.images() { | |
45 | if let Ok(path) = image.path() { | |
46 | println!("{}", path); | |
47 | } | |
48 | } | |
49 | } | |
50 | } |