Expand description
Support for reading Mach-O files.
Traits are used to abstract over the difference between 32-bit and 64-bit Mach-O
files. The primary trait for this is MachHeader.
§High level API
MachOFile implements the Object trait for Mach-O files.
MachOFile is parameterised by MachHeader to allow reading both 32-bit and
64-bit Mach-O files. There are type aliases for these parameters (MachOFile32 and
MachOFile64).
§Low level API
The MachHeader trait can be directly used to parse both macho::MachHeader32
and macho::MachHeader64. Additionally, FatHeader and the FatArch trait
can be used to iterate images in multi-architecture binaries, and DyldCache can
be used to locate images in a dyld shared cache.
§Example for low level API
use object::macho;
use object::read::macho::{MachHeader, Nlist};
use std::error::Error;
use std::fs;
/// Reads a file and displays the name of each symbol.
fn main() -> Result<(), Box<dyn Error>> {
let data = fs::read("path/to/binary")?;
let header = macho::MachHeader64::<object::Endianness>::parse(&*data, 0)?;
let endian = header.endian()?;
let mut commands = header.load_commands(endian, &*data, 0)?;
while let Some(command) = commands.next()? {
if let Some(symtab_command) = command.symtab()? {
let symbols = symtab_command.symbols::<macho::MachHeader64<_>, _>(endian, &*data)?;
for symbol in symbols.iter() {
let name = symbol.name(endian, symbols.strings())?;
println!("{}", String::from_utf8_lossy(name));
}
}
}
Ok(())
}Re-exports§
Structs§
- Dyld
Cache - A parsed representation of the dyld shared cache.
- Dyld
Cache Image - One image (dylib) from inside the dyld shared cache.
- Dyld
Cache Image Iterator - An iterator over all the images (dylibs) in the dyld shared cache.
- Dyld
SubCache - Information about a subcache.
- Load
Command Data - The data for a
macho::LoadCommand. - Load
Command Iterator - An iterator for the load commands from a
MachHeader. - MachO
Comdat - A COMDAT section group in a
MachOFile. - MachO
Comdat Iterator - An iterator for the COMDAT section groups in a
MachOFile. - MachO
Comdat Section Iterator - An iterator for the sections in a COMDAT section group in a
MachOFile. - MachO
FatFile - A Mach-O universal binary.
- MachO
File - A partially parsed Mach-O file.
- MachO
Relocation Iterator - An iterator for the relocations in a
MachOSection. - MachO
Section - A section in a
MachOFile. - MachO
Section Iterator - An iterator for the sections in a
MachOFile. - MachO
Segment - A segment in a
MachOFile. - MachO
Segment Iterator - An iterator for the segments in a
MachOFile. - MachO
Symbol - A symbol in a
MachOFile. - MachO
Symbol Iterator - An iterator for the symbols in a
MachOFile. - MachO
Symbol Table - A symbol table in a
MachOFile. - Symbol
Table - A table of symbol entries in a Mach-O file.
Enums§
- Dyld
SubCache Slice - A slice of structs describing each subcache. The struct gained an additional field (the file suffix) in dyld-1042.1 (macOS 13 / iOS 16), so this is an enum of the two possible slice types.
- Load
Command Variant - A
macho::LoadCommandthat has been interpreted according to itscmdfield.
Traits§
- FatArch
- A trait for generic access to
macho::FatArch32andmacho::FatArch64. - Mach
Header - A trait for generic access to
macho::MachHeader32andmacho::MachHeader64. - Nlist
- A trait for generic access to
macho::Nlist32andmacho::Nlist64. - Section
- A trait for generic access to
macho::Section32andmacho::Section64. - Segment
- A trait for generic access to
macho::SegmentCommand32andmacho::SegmentCommand64.
Functions§
- address_
to_ file_ offset - Find the file offset of the image by looking up its address in the mappings.
Type Aliases§
- MachO
Comdat32 - A COMDAT section group in a
MachOFile32. - MachO
Comdat64 - A COMDAT section group in a
MachOFile64. - MachO
Comdat Iterator32 - An iterator for the COMDAT section groups in a
MachOFile64. - MachO
Comdat Iterator64 - An iterator for the COMDAT section groups in a
MachOFile64. - MachO
Comdat Section Iterator32 - An iterator for the sections in a COMDAT section group in a
MachOFile32. - MachO
Comdat Section Iterator64 - An iterator for the sections in a COMDAT section group in a
MachOFile64. - MachO
FatFile32 - A 32-bit Mach-O universal binary.
- MachO
FatFile64 - A 64-bit Mach-O universal binary.
- MachO
File32 - A 32-bit Mach-O object file.
- MachO
File64 - A 64-bit Mach-O object file.
- MachO
Relocation Iterator32 - An iterator for the relocations in a
MachOSection32. - MachO
Relocation Iterator64 - An iterator for the relocations in a
MachOSection64. - MachO
Section32 - A section in a
MachOFile32. - MachO
Section64 - A section in a
MachOFile64. - MachO
Section Iterator32 - An iterator for the sections in a
MachOFile32. - MachO
Section Iterator64 - An iterator for the sections in a
MachOFile64. - MachO
Segment32 - A segment in a
MachOFile32. - MachO
Segment64 - A segment in a
MachOFile64. - MachO
Segment Iterator32 - An iterator for the segments in a
MachOFile32. - MachO
Segment Iterator64 - An iterator for the segments in a
MachOFile64. - MachO
Symbol32 - A symbol in a
MachOFile32. - MachO
Symbol64 - A symbol in a
MachOFile64. - MachO
Symbol Iterator32 - An iterator for the symbols in a
MachOFile32. - MachO
Symbol Iterator64 - An iterator for the symbols in a
MachOFile64. - MachO
Symbol Table32 - A symbol table in a
MachOFile32. - MachO
Symbol Table64 - A symbol table in a
MachOFile64.