This module allows to inspect Objective-C metadata from a Mach-O binary.
If a Mach-O binary embeds Objective-C metadata, they can be accessed through lief.MachO.Binary.objc_metadata
/ LIEF::MachO::Binary::objc_metadata()
:
macho: lief.MachO.Binary = ...
metadata: lief.objc.Metadata = macho.objc_metadata
if metadata is not None:
print("Objective-C metadata found")
std::unique_ptr<LIEF::MachO::Binary> macho;
std::unique_ptr<LIEF::objc::Metadata> metadata = macho->objc_metadata();
if (metadata != nullptr) {
std::cout << "Objective metadata found\n";
}
let macho: lief::macho::Binary;
if let Some(metadata) = macho.objc_metadata() {
println!("Objective-C metadata found");
}
Then at this point, one can use the API exposed by the class lief.objc.Metadata
/ LIEF::objc::Metadata
to inspect the Objective-C Metadata.
In particular, the function: lief.objc.Metadata.to_decl()
/ LIEF::objc::Metadata::to_decl()
can be used to generate a header-like output of all the Objective-C metadata found in the binary.
macho: lief.MachO.Binary = lief.parse("some_macho")
metadata: lief.objc.Metadata = macho.objc_metadata
for clazz in metadata.classes:
print(f"name={clazz.name}")
for meth in clazz.methods:
print(f" method.name={meth.name}")
print(metadata.to_decl())
std::unique_ptr<LIEF::MachO::FatBinary> fat = LIEF::MachO::Parser::parse(argv[1]);
LIEF::MachO::Binary* bin = fat->at(0);
std::unique_ptr<LIEF::objc::Metadata> metadata = bin->objc_metadata();
for (const std::unique_ptr<LIEF::objc::Class>& clazz : metadata->classes()) {
log(LOG_LVL, "name={}", clazz->name());
for (const std::unique_ptr<LIEF::objc::Method>& meth : clazz->methods()) {
log(LOG_LVL, " method.name={}", meth->name());
}
}
log(LOG_LVL, metadata->to_decl());
let Some(lief::Binary::MachO(fat)) = lief::Binary::parse(&path) else { process::exit(1); };
let Some(bin) = fat.iter().next() else { process::exit(1); };
let Some(metadata) = bin.objc_metadata() else { process::exit(1); };
for class in metadata.classes() {
println!("name={}", class.name());
for method in class.methods() {
println!(" method.name={}", method.name());
}
}
println!("{}", metadata.to_decl());
This Objective-C support is based on iCDump which is detailed here:
You can find the documentation of the API for the different languages here:
Rust API: https://lief-rs.s3.fr-par.scw.cloud/doc/latest/lief/index.html