Skip to main content

Module macho

Module macho 

Expand description

Module for the Mach-O file format support in LIEF.

To get started, one can use crate::macho::parse, crate::macho::FatBinary::parse or crate::Binary::parse to instantiate a crate::macho::FatBinary.

Even though the targeted Mach-O binary is not FAT, LIEF always return a crate::macho::FatBinary which can wrap a single Binary.

let fat = lief::macho::parse("non-fat.macho").unwrap();
assert!(fat.iter().len() == 1);

let fat = lief::macho::parse("real-fat.macho").unwrap();
assert!(fat.iter().len() > 1);

The Binary structure exposes the main interface to inspect or modify Mach-O binaries:

fn inspect_macho(macho: &lief::macho::Binary) {
    for cmd in macho.commands() {
        println!("{:?}", cmd);
    }
}

Modules§

binary
binding_info
builder
commands
export_info
fat_binary
header
parser_config
relocation
section
stub
symbol
thread_local_variables

Structs§

Binary
This is the main interface to read and write Mach-O binary attributes.
ExportInfo
This structure represents an export (info) in a Mach-O binary
FatBinary
This structure represents a FAT Mach-O
Generic
Header
Structure that represents the main Mach-O header (at the beginning of the file)
ParserConfig
This structure is used to tweak the MachO parser: crate::macho::FatBinary::parse_with_config
Stub
This class represents a stub entry in sections like __stubs,__auth_stubs.
Symbol
Structure that represents a Symbol in a Mach-O file.
ThreadLocalVariables
This class represents a MachO section whose type is crate::macho::section::Type::THREAD_LOCAL_VARIABLES.

Enums§

BindingInfo
This enum exposes all the different types of binding operations that we can find in a Mach-O binary. BindingInfo::Dyld exposes the bindings info wrapped in the LC_DYLD_INFO command while BindingInfo::Chained exposes the new chained bindings implemented in the DYLD_CHAINED_FIXUPS command.
Commands
Enum that wraps all the different Mach-O load commands (LC_xxx). Note that all these commands implements the trait: Command
MachOType
Mach-O magic values
Relocation
Enum that represents the different to encode/represent a relocation in a Mach-O file
Section
Enum that wraps all the Mach-O section types, dispatching to the appropriate concrete type when extra semantics are available.

Traits§

MachOSection
Trait shared by all Mach-O section types in the Section enum.

Functions§

check_fat_layout
Check that the layout of the given FAT binary is correct from the loader perspective
check_layout
Check that the layout of the given binary is correct from the loader perspective
is_64
Check if the given file is a 64-bit Mach-O
is_fat
Check if the given file is a FAT Mach-O
parse
Parse a Mach-O file from the given file path
parse_from_dump
Parse a Mach-O binary from a memory dump located at path that was mapped at the virtual address addr
parse_from_dump_with_config
Same as parse_from_dump but with a provided configuration
parse_with_config
Parse a Mach-O file from the given file path with the provided parser configuration