1//! Support for reading Mach-O files.
2//!
3//! Traits are used to abstract over the difference between 32-bit and 64-bit Mach-O
4//! files. The primary trait for this is [`MachHeader`].
5//!
6//! ## High level API
7//!
8//! [`MachOFile`] implements the [`Object`](crate::read::Object) trait for Mach-O files.
9//! [`MachOFile`] is parameterised by [`MachHeader`] to allow reading both 32-bit and
10//! 64-bit Mach-O files. There are type aliases for these parameters ([`MachOFile32`] and
11//! [`MachOFile64`]).
12//!
13//! ## Low level API
14//!
15//! The [`MachHeader`] trait can be directly used to parse both [`macho::MachHeader32`]
16//! and [`macho::MachHeader64`]. Additionally, [`FatHeader`] and the [`FatArch`] trait
17//! can be used to iterate images in multi-architecture binaries, and [`DyldCache`] can
18//! be used to locate images in a dyld shared cache.
19//!
20//! ### Example for low level API
21//! ```no_run
22//! use object::macho;
23//! use object::read::macho::{MachHeader, Nlist};
24//! use std::error::Error;
25//! use std::fs;
26//!
27//! /// Reads a file and displays the name of each symbol.
28//! fn main() -> Result<(), Box<dyn Error>> {
29//! # #[cfg(feature = "std")] {
30//! let data = fs::read("path/to/binary")?;
31//! let header = macho::MachHeader64::<object::Endianness>::parse(&*data, 0)?;
32//! let endian = header.endian()?;
33//! let mut commands = header.load_commands(endian, &*data, 0)?;
34//! while let Some(command) = commands.next()? {
35//! if let Some(symtab_command) = command.symtab()? {
36//! let symbols = symtab_command.symbols::<macho::MachHeader64<_>, _>(endian, &*data)?;
37//! for symbol in symbols.iter() {
38//! let name = symbol.name(endian, symbols.strings())?;
39//! println!("{}", String::from_utf8_lossy(name));
40//! }
41//! }
42//! }
43//! # }
44//! Ok(())
45//! }
46//! ```
47#[cfg(doc)]
48use crate::macho;
49
50mod dyld_cache;
51pub use dyld_cache::*;
52
53mod fat;
54pub use fat::*;
55
56mod file;
57pub use file::*;
58
59mod load_command;
60pub use load_command::*;
61
62mod segment;
63pub use segment::*;
64
65mod section;
66pub use section::*;
67
68mod symbol;
69pub use symbol::*;
70
71mod relocation;
72pub use relocation::*;
73