object/read/elf/
mod.rs

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)]
42use crate::elf;
43
44mod file;
45pub use file::*;
46
47mod segment;
48pub use segment::*;
49
50mod section;
51pub use section::*;
52
53mod symbol;
54pub use symbol::*;
55
56mod relocation;
57pub use relocation::*;
58
59mod comdat;
60pub use comdat::*;
61
62mod dynamic;
63pub use dynamic::*;
64
65mod compression;
66pub use compression::*;
67
68mod note;
69pub use note::*;
70
71mod hash;
72pub use hash::*;
73
74mod version;
75pub use version::*;
76
77mod attributes;
78pub use attributes::*;