Skip to content

Commit

Permalink
object: Change Mach-O to new system
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Jun 19, 2024
1 parent 295fa37 commit f05e9c6
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 219 deletions.
137 changes: 70 additions & 67 deletions dumper/format/macho.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,83 @@ import dumper;

int dump_macho(adbg_object_t *o) {
if (SELECTED(Select.headers))
dump_macho_hdr(o);
adbg_object_macho_is_fat(o) ?
dump_macho_header_fat(o) : dump_macho_header_regular(o);

return 0;
}

private:

void dump_macho_hdr(adbg_object_t *o) {
if (o.i.macho.fat) {
print_header("FAT Header");

with (o.i.macho.fat_header) {
print_x32("magic", magic, adbg_object_macho_magic_string(magic));
print_u32("nfat_arch", nfat_arch);
}

print_header("FAT Arch Header");

size_t i;
macho_fat_arch *fa = void;
while ((fa = adbg_object_macho_fat_arch(o, i++)) != null) with (fa) {
print_x32("cputype", cputype, adbg_object_macho_cputype_string(cputype));
print_x32("subtype", subtype, adbg_object_macho_subtype_string(cputype, subtype));
print_x32("offset", offset);
print_x32("size", size);
print_x32("alignment", alignment);
}
} else {
print_header("Header");

with (o.i.macho.header) {
print_x32("magic", magic, adbg_object_macho_magic_string(magic));
void dump_macho_header_fat(adbg_object_t *o) {
print_header("FAT Header");

macho_fat_header_t *header = adbg_object_macho_fat_header(o);

print_x32("magic", header.magic, adbg_object_macho_magic_string(header.magic));
print_u32("nfat_arch", header.nfat_arch);

print_header("FAT Arch Headers");

size_t i;
macho_fat_arch_entry_t *arch = void;
while ((arch = adbg_object_macho_fat_arch(o, i++)) != null) with (arch) {
print_section(cast(uint)i);
print_x32("cputype", cputype, adbg_object_macho_cputype_string(cputype));
print_x32("subtype", subtype, adbg_object_macho_subtype_string(cputype, subtype));
print_x32("filetype", filetype, adbg_object_macho_filetype_string(filetype));
print_u32("ncmds", ncmds);
print_u32("sizeofcmds", sizeofcmds);
print_flags32("flags", flags,
"NOUNDEFS".ptr, MACHO_FLAG_NOUNDEFS,
"INCRLINK".ptr, MACHO_FLAG_INCRLINK,
"DYLDLINK".ptr, MACHO_FLAG_DYLDLINK,
"BINDATLOAD".ptr, MACHO_FLAG_BINDATLOAD,
"PREBOUND".ptr, MACHO_FLAG_PREBOUND,
"SPLIT_SEGS".ptr, MACHO_FLAG_SPLIT_SEGS,
"LAZY_INIT".ptr, MACHO_FLAG_LAZY_INIT,
"TWOLEVEL".ptr, MACHO_FLAG_TWOLEVEL,
"FORCE_FLAT".ptr, MACHO_FLAG_FORCE_FLAT,
"NOMULTIDEFS".ptr, MACHO_FLAG_NOMULTIDEFS,
"NOFIXPREBINDING".ptr, MACHO_FLAG_NOFIXPREBINDING,
"PREBINDABLE".ptr, MACHO_FLAG_PREBINDABLE,
"ALLMODSBOUND".ptr, MACHO_FLAG_ALLMODSBOUND,
"SUBSECTIONS_VIA_SYMBOLS".ptr, MACHO_FLAG_SUBSECTIONS_VIA_SYMBOLS,
"CANONICAL".ptr, MACHO_FLAG_CANONICAL,
"WEAK_DEFINES".ptr, MACHO_FLAG_WEAK_DEFINES,
"BINDS_TO_WEAK".ptr, MACHO_FLAG_BINDS_TO_WEAK,
"ALLOW_STACK_EXECUTION".ptr, MACHO_FLAG_ALLOW_STACK_EXECUTION,
"ROOT_SAFE".ptr, MACHO_FLAG_ROOT_SAFE,
"SETUID_SAFE".ptr, MACHO_FLAG_SETUID_SAFE,
"NO_REEXPORTED_DYLIBS".ptr, MACHO_FLAG_NO_REEXPORTED_DYLIBS,
"PIE".ptr, MACHO_FLAG_PIE,
"DEAD_STRIPPABLE_DYLIB".ptr, MACHO_FLAG_DEAD_STRIPPABLE_DYLIB,
"HAS_TLV_DESCRIPTORS".ptr, MACHO_FLAG_HAS_TLV_DESCRIPTORS,
"NO_HEAP_EXECUTION".ptr, MACHO_FLAG_NO_HEAP_EXECUTION,
"APP_EXTENSION_SAFE".ptr, MACHO_FLAG_APP_EXTENSION_SAFE,
null);
}

print_header("Load commands");

size_t i;
macho_load_command *command = void;
while ((command = adbg_object_macho_load_command(o, i++)) != null) with (command) {
print_x32("cmd", cmd, adbg_object_macho_command_string(cmd));
print_x32("cmdsize", cmdsize);
}
print_x32("offset", offset);
print_x32("size", size);
print_x32("alignment", alignment);
}
}
void dump_macho_header_regular(adbg_object_t *o) {
print_header("Header");

macho_header_t *header = adbg_object_macho_header(o);

with (header) {
print_x32("magic", magic, adbg_object_macho_magic_string(magic));
print_x32("cputype", cputype, adbg_object_macho_cputype_string(cputype));
print_x32("subtype", subtype, adbg_object_macho_subtype_string(cputype, subtype));
print_x32("filetype", filetype, adbg_object_macho_filetype_string(filetype));
print_u32("ncmds", ncmds);
print_u32("sizeofcmds", sizeofcmds);
print_flags32("flags", flags,
"NOUNDEFS".ptr, MACHO_FLAG_NOUNDEFS,
"INCRLINK".ptr, MACHO_FLAG_INCRLINK,
"DYLDLINK".ptr, MACHO_FLAG_DYLDLINK,
"BINDATLOAD".ptr, MACHO_FLAG_BINDATLOAD,
"PREBOUND".ptr, MACHO_FLAG_PREBOUND,
"SPLIT_SEGS".ptr, MACHO_FLAG_SPLIT_SEGS,
"LAZY_INIT".ptr, MACHO_FLAG_LAZY_INIT,
"TWOLEVEL".ptr, MACHO_FLAG_TWOLEVEL,
"FORCE_FLAT".ptr, MACHO_FLAG_FORCE_FLAT,
"NOMULTIDEFS".ptr, MACHO_FLAG_NOMULTIDEFS,
"NOFIXPREBINDING".ptr, MACHO_FLAG_NOFIXPREBINDING,
"PREBINDABLE".ptr, MACHO_FLAG_PREBINDABLE,
"ALLMODSBOUND".ptr, MACHO_FLAG_ALLMODSBOUND,
"SUBSECTIONS_VIA_SYMBOLS".ptr, MACHO_FLAG_SUBSECTIONS_VIA_SYMBOLS,
"CANONICAL".ptr, MACHO_FLAG_CANONICAL,
"WEAK_DEFINES".ptr, MACHO_FLAG_WEAK_DEFINES,
"BINDS_TO_WEAK".ptr, MACHO_FLAG_BINDS_TO_WEAK,
"ALLOW_STACK_EXECUTION".ptr, MACHO_FLAG_ALLOW_STACK_EXECUTION,
"ROOT_SAFE".ptr, MACHO_FLAG_ROOT_SAFE,
"SETUID_SAFE".ptr, MACHO_FLAG_SETUID_SAFE,
"NO_REEXPORTED_DYLIBS".ptr, MACHO_FLAG_NO_REEXPORTED_DYLIBS,
"PIE".ptr, MACHO_FLAG_PIE,
"DEAD_STRIPPABLE_DYLIB".ptr, MACHO_FLAG_DEAD_STRIPPABLE_DYLIB,
"HAS_TLV_DESCRIPTORS".ptr, MACHO_FLAG_HAS_TLV_DESCRIPTORS,
"NO_HEAP_EXECUTION".ptr, MACHO_FLAG_NO_HEAP_EXECUTION,
"APP_EXTENSION_SAFE".ptr, MACHO_FLAG_APP_EXTENSION_SAFE,
null);
}

print_header("Load commands");

size_t i;
macho_load_command_t *command = void;
while ((command = adbg_object_macho_load_command(o, i++)) != null) with (command) {
print_x32("cmd", cmd, SAFEVAL(adbg_object_macho_command_string(cmd)));
print_x32("cmdsize", cmdsize);
}
}
Loading

0 comments on commit f05e9c6

Please sign in to comment.