1 | //! Support for reading ELF files. |
2 | //! |
3 | //! Traits are used to abstract over the difference between 32-bit and 64-bit ELF. |
4 | //! The primary trait for this is [`FileHeader`]. |
5 | //! |
6 | //! ## High level API |
7 | //! |
8 | //! [`ElfFile`] implements the [`Object`](crate::read::Object) trait for ELF files. |
9 | //! [`ElfFile`] is parameterised by [`FileHeader`] to allow reading both 32-bit and |
10 | //! 64-bit ELF. There are type aliases for these parameters ([`ElfFile32`] and |
11 | //! [`ElfFile64`]). |
12 | //! |
13 | //! ## Low level API |
14 | //! |
15 | //! The [`FileHeader`] trait can be directly used to parse both [`elf::FileHeader32`] |
16 | //! and [`elf::FileHeader64`]. |
17 | //! |
18 | //! ### Example for low level API |
19 | //! ```no_run |
20 | //! use object::elf; |
21 | //! use object::read::elf::{FileHeader, Sym}; |
22 | //! use std::error::Error; |
23 | //! use std::fs; |
24 | //! |
25 | //! /// Reads a file and displays the name of each symbol. |
26 | //! fn main() -> Result<(), Box<dyn Error>> { |
27 | //! # #[cfg (feature = "std" )] { |
28 | //! let data = fs::read("path/to/binary" )?; |
29 | //! let elf = elf::FileHeader64::<object::Endianness>::parse(&*data)?; |
30 | //! let endian = elf.endian()?; |
31 | //! let sections = elf.sections(endian, &*data)?; |
32 | //! let symbols = sections.symbols(endian, &*data, elf::SHT_SYMTAB)?; |
33 | //! for symbol in symbols.iter() { |
34 | //! let name = symbol.name(endian, symbols.strings())?; |
35 | //! println!("{}" , String::from_utf8_lossy(name)); |
36 | //! } |
37 | //! # } |
38 | //! Ok(()) |
39 | //! } |
40 | //! ``` |
41 | #[cfg (doc)] |
42 | use crate::elf; |
43 | |
44 | mod file; |
45 | pub use file::*; |
46 | |
47 | mod segment; |
48 | pub use segment::*; |
49 | |
50 | mod section; |
51 | pub use section::*; |
52 | |
53 | mod symbol; |
54 | pub use symbol::*; |
55 | |
56 | mod relocation; |
57 | pub use relocation::*; |
58 | |
59 | mod comdat; |
60 | pub use comdat::*; |
61 | |
62 | mod dynamic; |
63 | pub use dynamic::*; |
64 | |
65 | mod compression; |
66 | pub use compression::*; |
67 | |
68 | mod note; |
69 | pub use note::*; |
70 | |
71 | mod hash; |
72 | pub use hash::*; |
73 | |
74 | mod version; |
75 | pub use version::*; |
76 | |
77 | mod attributes; |
78 | pub use attributes::*; |
79 | |