]>
Commit | Line | Data |
---|---|---|
1 | use object::{Object, ObjectSection}; | |
2 | use std::{env, fs, process}; | |
3 | ||
4 | fn main() { | |
5 | let arg_len = env::args().len(); | |
6 | if arg_len <= 1 { | |
7 | eprintln!("Usage: {} <file> ...", env::args().next().unwrap()); | |
8 | process::exit(1); | |
9 | } | |
10 | ||
11 | for file_path in env::args().skip(1) { | |
12 | if arg_len > 2 { | |
13 | println!(); | |
14 | println!("{}:", file_path); | |
15 | } | |
16 | ||
17 | let file = match fs::File::open(&file_path) { | |
18 | Ok(file) => file, | |
19 | Err(err) => { | |
20 | println!("Failed to open file '{}': {}", file_path, err,); | |
21 | return; | |
22 | } | |
23 | }; | |
24 | let file = match unsafe { memmap::Mmap::map(&file) } { | |
25 | Ok(mmap) => mmap, | |
26 | Err(err) => { | |
27 | println!("Failed to map file '{}': {}", file_path, err,); | |
28 | return; | |
29 | } | |
30 | }; | |
31 | let file = match object::File::parse(&*file) { | |
32 | Ok(file) => file, | |
33 | Err(err) => { | |
34 | println!("Failed to parse file '{}': {}", file_path, err); | |
35 | return; | |
36 | } | |
37 | }; | |
38 | ||
39 | match file.mach_uuid() { | |
40 | Ok(Some(uuid)) => println!("Mach UUID: {:x?}", uuid), | |
41 | Ok(None) => {} | |
42 | Err(e) => println!("Failed to parse Mach UUID: {}", e), | |
43 | } | |
44 | match file.build_id() { | |
45 | Ok(Some(build_id)) => println!("Build ID: {:x?}", build_id), | |
46 | Ok(None) => {} | |
47 | Err(e) => println!("Failed to parse build ID: {}", e), | |
48 | } | |
49 | match file.gnu_debuglink() { | |
50 | Ok(Some((filename, crc))) => println!( | |
51 | "GNU debug link: {} CRC: {:08x}", | |
52 | String::from_utf8_lossy(filename), | |
53 | crc, | |
54 | ), | |
55 | Ok(None) => {} | |
56 | Err(e) => println!("Failed to parse GNU debug link: {}", e), | |
57 | } | |
58 | ||
59 | for segment in file.segments() { | |
60 | println!("{:?}", segment); | |
61 | } | |
62 | ||
63 | for section in file.sections() { | |
64 | println!("{}: {:?}", section.index().0, section); | |
65 | } | |
66 | ||
67 | for (index, symbol) in file.symbols() { | |
68 | println!("{}: {:?}", index.0, symbol); | |
69 | } | |
70 | ||
71 | for section in file.sections() { | |
72 | if section.relocations().next().is_some() { | |
73 | println!( | |
74 | "\n{} relocations", | |
75 | section.name().unwrap_or("<invalid name>") | |
76 | ); | |
77 | for relocation in section.relocations() { | |
78 | println!("{:?}", relocation); | |
79 | } | |
80 | } | |
81 | } | |
82 | } | |
83 | } |