]>
Commit | Line | Data |
---|---|---|
fc512014 | 1 | use object::{Object, ObjectComdat, ObjectSection, ObjectSymbol}; |
f035d41b XL |
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 | ||
fc512014 XL |
67 | for comdat in file.comdats() { |
68 | print!("{:?} Sections:", comdat); | |
69 | for section in comdat.sections() { | |
70 | print!(" {}", section.0); | |
71 | } | |
72 | println!(); | |
73 | } | |
74 | ||
75 | for symbol in file.symbols() { | |
76 | println!("{}: {:?}", symbol.index().0, symbol); | |
f035d41b XL |
77 | } |
78 | ||
79 | for section in file.sections() { | |
80 | if section.relocations().next().is_some() { | |
81 | println!( | |
82 | "\n{} relocations", | |
83 | section.name().unwrap_or("<invalid name>") | |
84 | ); | |
85 | for relocation in section.relocations() { | |
86 | println!("{:?}", relocation); | |
87 | } | |
88 | } | |
89 | } | |
90 | } | |
91 | } |