MachoFile
Description
Parsed Mach-O file. Holds the raw bytes plus decoded indices.
Fields
| Name | Description |
|---|---|
allocator |
Allocator backing the owned buffer and the segments/sections/symbols vectors. |
data |
Raw Mach-O bytes. |
data_size |
Length of data in bytes. |
owns_data |
True if data was allocated via allocator. |
cputype |
Mach-O cputype value (e.g. 0x01000007 = x86_64, 0x0100000C = arm64). |
filetype |
MachoFileType value. |
uuid |
16-byte UUID from LC_UUID if present. |
has_uuid |
True iff LC_UUID was found. |
segments |
All LC_SEGMENT_64 entries. |
sections |
Flat list of all sections across segments. |
symbols |
Entries from LC_SYMTAB; may be empty if stripped. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
MachO.c:125:
build_macho_blob();
MachoFile m;
bool ok = MachoFileOpenFromMemory(&m, blob, sizeof(blob), base);
if (!ok) {- In
MachO.c:154:
build_macho_blob();
MachoFile m;
if (!MachoFileOpenFromMemory(&m, blob, sizeof(blob), base)) {
DefaultAllocatorDeinit(&alloc);- In
MachO.c:185:
wr_u32(&fat[0], 0xCAFEBABEu);
MachoFile m;
bool ok = !MachoFileOpenFromMemory(&m, fat, sizeof(fat), base);- In
MachO.c:214:
Allocator *base = ALLOCATOR_OF(&alloc);
MachoFile m;
if (!MachoFileOpen(&m, path, base)) {
DefaultAllocatorDeinit(&alloc);- In
MachO.c:247:
Allocator *base = ALLOCATOR_OF(&alloc);
MachoFile m;
if (!MachoFileOpen(&m, path, base)) {
DefaultAllocatorDeinit(&alloc);- In
MachO.c:69:
typedef struct MachoContext {
MachoFile *out;
u32 ncmds;
u32 sizeofcmds;- In
MachO.c:80:
static bool decode_header(MachoContext *ctx) {
MachoFile *m = ctx->out;
if (m->data_size < MH_HEADER_64_SIZE) {
LOG_ERROR("MachO: file too small for header");- In
MachO.c:252:
// ---------------------------------------------------------------------------
bool MachoFileOpenFromMemory(MachoFile *out, u8 *data, size data_size, Allocator *alloc) {
if (!out || !data || !alloc) {
LOG_ERROR("MachoFileOpenFromMemory: NULL argument");- In
MachO.c:280:
}
bool MachoFileOpen(MachoFile *out, const char *path, Allocator *alloc) {
if (!out || !path || !alloc) {
LOG_ERROR("MachoFileOpen: NULL argument");- In
MachO.c:303:
}
void MachoFileDeinit(MachoFile *self) {
if (!self)
return;- In
MachO.c:315:
}
const MachoSection *MachoFileFindSection(const MachoFile *self, const char *segment, const char *section) {
if (!self || !segment || !section)
return NULL;- In
MachO.c:335:
// matched stabs with all three bits set -- N_SO / N_FUN / N_OSO /
// etc. were getting through and polluting lookups).
const MachoSymbol *MachoFileResolveAddress(const MachoFile *self, u64 vaddr) {
if (!self || self->symbols.length == 0)
return NULL;- In
MachoCache.h:33:
char *module_path;
u64 slide;
MachoFile main;
bool main_open;
MachoFile dsym;- In
MachoCache.h:35:
MachoFile main;
bool main_open;
MachoFile dsym;
bool dsym_open;
DwarfFunctions fns;- In
MachO.h:110:
MachoSections sections;
MachoSymbols symbols;
} MachoFile;
///
- In
MachO.h:122:
/// TAGS: Parser, MachO, File
///
bool MachoFileOpen(MachoFile *out, const char *path, Allocator *alloc);
///
- In
MachO.h:134:
/// TAGS: Parser, MachO, Memory
///
bool MachoFileOpenFromMemory(MachoFile *out, u8 *data, size data_size, Allocator *alloc);
///
- In
MachO.h:139:
/// Release storage owned by a `MachoFile`. Safe on a zeroed struct.
///
void MachoFileDeinit(MachoFile *self);
///
- In
MachO.h:145:
/// absent.
///
const MachoSection *MachoFileFindSection(const MachoFile *self, const char *segment, const char *section);
///
- In
MachO.h:158:
/// FAILURE : Returns NULL.
///
const MachoSymbol *MachoFileResolveAddress(const MachoFile *self, u64 vaddr);
#endif // MISRA_PARSERS_MACHO_H
Last updated on