Note
import lief
# Using filepath
macho: lief.MachO.FatBinary = lief.MachO.parse("/bin/ls")
# Using a Path from pathlib
macho: lief.MachO.FatBinary = lief.MachO.parse(pathlib.Path(r"C:\Users\test.macho"))
# Using a io object
with open("/bin/ssh", 'rb') as f:
macho: lief.MachO.FatBinary = lief.MachO.parse(f)
#include <LIEF/MachO.hpp>
// Using a file path as a std::string
std::unique_ptr<LIEF::MachO::FatBinary> macho = LIEF::MachO::Parser::parse("/bin/ls");
// Using a vector
std::vector<uint8_t> my_raw_macho;
std::unique_ptr<LIEF::MachO::FatBinary> macho = LIEF::MachO::Parser::parse(my_raw_macho);
let macho: lief::macho::FatBinary = lief::macho::FatBinary::parse("/bin/ls");
fat: lief.MachO.FatBinary
# Iterate
for macho in fat:
print(macho.entrypoint)
print(len(macho.commands))
# Pick one at the specified index
macho: lief.MachO.Binary = fat.at(0)
# Pick one based on the architecture
macho: lief.MachO.Binary = fat.take(lief.MachO.Header.CPU_TYPE.ARM64)
std::unique_ptr<LIEF::MachO::FatBinary> fat;
// Iterate
for (const LIEF::MachO::Binary& macho : *fat) {
std::cout << macho.entrypoint() << '\n';
std::cout << macho.commands().size() << '\n';
}
// Pick one at the specified index (without take the ownership)
const LIEF::MachO::Binary* macho = fat->at(0);
// Pick one at the specified index and take the ownership
const LIEF::MachO::Binary* macho = fat->take(0);
// Pick one with the given arch and take the ownership
const LIEF::MachO::Binary* macho = fat->take(LIEF::MachO::Header::CPU_TYPE::ARM64);
let fat: lief::macho::FatBinary;
// Iterate
for macho in fat {
println!("{}", macho.entrypoint());
}
macho: lief.MachO.FatBinary = ...
macho.at(0).write("fit.macho")
macho.write("fat.macho") # write-back the whole FAT binary
std::unique_ptr<LIEF::MachO::FatBinary> macho;
macho->at(LIEF::MachO::Header::CPU_TYPE::ARM64)->write("fit.macho");
macho->write("fat.macho");
Warning
parser_config = lief.MachO.ParserConfig()
parser_config.parse_dyld_bindings = False
macho: lief.MachO.FatBinary = lief.MachO.parse("my.macho", parser_config)
builder_config = lief.MachO.Builder.config_t()
builder_config.linkedit = False
macho.write("new.macho", builder_config)
LIEF::MachO::ParserConfig parser_config;
parser_config.parse_dyld_bindings = false;
auto macho = LIEF::MachO::Parser::parse("my.macho", parser_config);
LIEF::MachO::Builder::config_t builder_config;
builder_config.linkedit = false;
macho->write("new.macho", builder_config);
See also
For more details, you can check the Obj-C section.