27 const bool use_pagezero =
true;
28 const bool use_main =
true;
29 const bool use_dylinker =
true;
30 const bool use_libsystem =
true;
31 const bool use_linkedit =
true;
32 ut64 filesize, codeva, datava;
33 ut32 ncmds, magiclen, headerlen;
34 ut64 p_codefsz = 0, p_codeva = 0, p_codesz = 0, p_codepa = 0;
35 ut64 p_datafsz = 0, p_datava = 0, p_datasz = 0, p_datapa = 0;
36 ut64 p_cmdsize = 0, p_entry = 0, p_tmp = 0;
41 #define B(x, y) rz_buf_append_bytes(buf, (const ut8 *)(x), y)
42 #define D(x) rz_buf_append_ut32(buf, x)
43 #define Q(x) rz_buf_append_ut64(buf, x)
44 #define Z(x) rz_buf_append_nbytes(buf, x)
45 #define W(x, y, z) rz_buf_write_at(buf, x, (const ut8 *)(y), z)
47 p_tmp = rz_buf_size(buf); \
49 W(p_tmp, y, strlen(y))
53 B(
"\xcf\xfa\xed\xfe", 4);
59 ncmds = (data && datalen > 0) ? 3 : 2;
129 if (data && datalen > 0) {
135 W(p_tmp,
"__TEXT", 6);
171 WZ(16,
"__LINKEDIT");
192 Z(18 *
sizeof(
ut32));
195 const char *dyld =
"/usr/lib/dyld";
196 const int dyld_len = strlen(dyld) + 1;
198 D((4 * 3) + dyld_len);
204 const char *lib =
"/usr/lib/libSystem.B.dylib";
205 const int lib_len = strlen(lib) + 1;
224 #define STATESIZE (21 * sizeof(ut64))
241 W(p_entry, &codeva, 8);
245 W(p_cmdsize, &headerlen, 4);
246 filesize = magiclen + headerlen + codelen + datalen;
248 W(p_codefsz, &filesize, 8);
249 W(p_codefsz - 16, &filesize, 8);
250 W(p_codeva, &codeva, 8);
253 W(p_codesz, &clen, 8);
255 p_tmp = codeva -
baddr;
256 W(p_codepa, &p_tmp, 8);
260 if (data && datalen > 0) {
262 W(p_datafsz, &filesize, 8);
263 W(p_datava, &datava, 8);
264 W(p_datasz, &datalen, 8);
265 p_tmp = datava -
baddr;
266 W(p_datapa, &p_tmp, 8);
static ut64 baddr(RzBinFile *bf)
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.