1 #include <mach-o/loader.h>
2 #include <mach/machine.h>
8 int size_of_load_cmds
=
9 sizeof(struct segment_command_64
) + sizeof(struct uuid_command
);
11 (uint8_t *)malloc(sizeof(struct mach_header_64
) + size_of_load_cmds
);
12 uint8_t *p
= macho_buf
;
13 struct mach_header_64 mh
;
14 mh
.magic
= MH_MAGIC_64
;
15 mh
.cputype
= CPU_TYPE_ARM64
;
17 mh
.filetype
= MH_EXECUTE
;
19 mh
.sizeofcmds
= size_of_load_cmds
;
20 mh
.flags
= MH_NOUNDEFS
| MH_DYLDLINK
| MH_TWOLEVEL
| MH_PIE
;
22 memcpy(p
, &mh
, sizeof(mh
));
25 struct segment_command_64 seg
;
26 seg
.cmd
= LC_SEGMENT_64
;
27 seg
.cmdsize
= sizeof(seg
);
28 strcpy(seg
.segname
, "__TEXT");
38 memcpy(p
, &seg
, sizeof(seg
));
41 struct uuid_command uuid
;
43 uuid
.cmdsize
= sizeof(uuid
);
44 uuid_clear(uuid
.uuid
);
45 uuid_parse("1b4e28ba-2fa1-11d2-883f-b9a761bde3fb", uuid
.uuid
);
47 memcpy(p
, &uuid
, sizeof(uuid
));
50 // If this needs to be debugged, the memory buffer can be written
52 // (lldb) mem rea -b -o /tmp/t -c `p - macho_buf` macho_buf
53 // (lldb) platform shell otool -hlv /tmp/t
54 // to verify that it is well formed.
56 // And inside lldb, it should be inspectable via
57 // (lldb) script print(lldb.frame.locals["macho_buf"][0].GetValueAsUnsigned())
59 // (lldb) process plugin packet send
60 // 'jGetLoadedDynamicLibrariesInfos:{"solib_addresses":[105553162403968]}]'
62 return 0; // break here