Rizin
unix-like reverse engineering framework and cli tools
bin_dyldcache.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2018 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2021 keegan
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_types.h>
6 #include <rz_util.h>
7 #include <rz_lib.h>
8 #include <rz_bin.h>
9 #include <rz_core.h>
10 #include <rz_io.h>
11 #include "../format/mach0/dyldcache.h"
12 #include "objc/mach0_classes.h"
13 
14 #define RZ_DYLDCACHE_VFILE_NAME_REBASED "rebased"
15 
16 static ut64 bin_obj_va2pa(ut64 p, ut32 *offset, ut32 *left, RzBinFile *bf) {
17  if (!bf || !bf->o || !bf->o->bin_obj) {
18  return 0;
19  }
20  RzDyldCache *cache = (RzDyldCache *)((struct MACH0_(obj_t) *)bf->o->bin_obj)->user;
21  if (!cache) {
22  return 0;
23  }
24  return rz_dyldcache_va2pa(cache, p, offset, left);
25 }
26 
27 static struct MACH0_(obj_t) * bin_to_mach0(RzBinFile *bf, RzDyldBinImage *bin) {
28  if (!bin || !bf) {
29  return NULL;
30  }
31 
32  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
33  if (!cache) {
34  return NULL;
35  }
36 
37  RzBuffer *buf = rz_buf_new_slice(cache->buf, bin->hdr_offset, rz_buf_size(cache->buf) - bin->hdr_offset);
38  if (!buf) {
39  return NULL;
40  }
41 
42  struct MACH0_(opts_t) opts;
44  (&opts, bf);
45  opts.header_at = bin->header_at - bin->hdr_offset;
46  opts.symbols_off = bin->symbols_off;
47 
48  struct MACH0_(obj_t) *mach0 = MACH0_(new_buf)(buf, &opts);
49 
50  mach0->user = cache;
51  mach0->va2pa = &bin_obj_va2pa;
52 
54 
55  return mach0;
56 }
57 
58 static bool check_buffer(RzBuffer *buf) {
59  if (rz_buf_size(buf) < 32) {
60  return false;
61  }
62 
63  char hdr[17] = { 0 };
64  int rzhdr = rz_buf_read_at(buf, 0, (ut8 *)&hdr, sizeof(hdr) - 1);
65  if (rzhdr != sizeof(hdr) - 1) {
66  return false;
67  }
68 
69  return rz_dyldcache_check_magic(hdr);
70 }
71 
72 static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb) {
74  if (!cache) {
75  return false;
76  }
77  obj->bin_obj = cache;
78  return true;
79 }
80 
81 static RzList *entries(RzBinFile *bf) {
82  RzBinAddr *ptr = NULL;
83  RzList *ret = rz_list_newf(free);
84  if (!ret) {
85  return NULL;
86  }
87  if ((ptr = RZ_NEW0(RzBinAddr))) {
88  rz_list_append(ret, ptr);
89  }
90  return ret;
91 }
92 
93 static RzBinInfo *info(RzBinFile *bf) {
94  RzBinInfo *ret = NULL;
95 
96  if (!bf || !bf->o) {
97  return NULL;
98  }
99 
100  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
101  if (!cache) {
102  return NULL;
103  }
104 
105  bool big_endian = 0;
106  if (!(ret = RZ_NEW0(RzBinInfo))) {
107  return NULL;
108  }
109  ret->file = strdup(bf->file);
110  ret->bclass = strdup("dyldcache");
111  ret->os = strdup("Darwin"); // TODO: actual OS info is available. See the platform member of struct dyld_cache_header in dyld source.
112  if (strstr(cache->hdr->magic, "x86_64")) {
113  ret->arch = strdup("x86");
114  ret->bits = 64;
115  } else {
116  ret->arch = strdup("arm");
117  ret->bits = strstr(cache->hdr->magic, "arm64") ? 64 : 32;
118  }
119  ret->machine = strdup(ret->arch);
120  ret->subsystem = strdup("xnu");
121  ret->type = strdup("library-cache");
122  ret->has_va = true;
123  ret->big_endian = big_endian;
124  ret->dbg_info = 0;
125  return ret;
126 }
127 
128 static ut64 baddr(RzBinFile *bf) {
129  // XXX hardcoded
130  return 0x180000000;
131 }
132 
134  struct MACH0_(obj_t) *mach0 = bin_to_mach0(bf, bin);
135  if (!mach0) {
136  return;
137  }
138 
139  // const RzList*symbols = MACH0_(get_symbols_list) (mach0);
140  const struct symbol_t *symbols = MACH0_(get_symbols)(mach0);
141  if (!symbols) {
142  return;
143  }
144  int i;
145  for (i = 0; !symbols[i].last; i++) {
146  if (!symbols[i].name || !symbols[i].name[0] || symbols[i].addr < 100) {
147  continue;
148  }
149  if (strstr(symbols[i].name, "<redacted>")) {
150  continue;
151  }
153  if (!sym) {
154  break;
155  }
156  sym->name = strdup(symbols[i].name);
157  sym->vaddr = symbols[i].addr;
158  sym->forwarder = "NONE";
160  sym->type = RZ_BIN_TYPE_FUNC_STR;
161  sym->paddr = symbols[i].offset + bf->o->boffset;
162  sym->size = symbols[i].size;
163  sym->ordinal = i;
164 
165  set_u_add(hash, sym->vaddr);
166  rz_list_append(ret, sym);
167  }
169  (mach0);
170 }
171 
172 static bool __is_data_section(const char *name) {
173  if (strstr(name, "_cstring")) {
174  return true;
175  }
176  if (strstr(name, "_os_log")) {
177  return true;
178  }
179  if (strstr(name, "_objc_methname")) {
180  return true;
181  }
182  if (strstr(name, "_objc_classname")) {
183  return true;
184  }
185  if (strstr(name, "_objc_methtype")) {
186  return true;
187  }
188  return false;
189 }
190 
192  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
193  if (!cache) {
194  return;
195  }
196 
197  struct MACH0_(obj_t) *mach0 = bin_to_mach0(bf, bin);
198  if (!mach0) {
199  return;
200  }
201 
202  struct section_t *sections = NULL;
203  if (!(sections = MACH0_(get_sections)(mach0))) {
204  return;
205  }
206 
207  int i;
208  for (i = 0; !sections[i].last; i++) {
210  if (!ptr) {
211  break;
212  }
213  if (bin->file) {
214  ptr->name = rz_str_newf("%s.%s", bin->file, (char *)sections[i].name);
215  } else {
216  ptr->name = rz_str_newf("%s", (char *)sections[i].name);
217  }
218  if (strstr(ptr->name, "la_symbol_ptr")) {
219  int len = sections[i].size / 8;
220  ptr->format = rz_str_newf("Cd %d %d", 8, len);
221  }
222  ptr->is_data = __is_data_section(ptr->name);
223  ptr->size = sections[i].size;
224  ptr->vsize = sections[i].vsize;
225  ptr->vaddr = sections[i].addr;
226  ptr->paddr = rz_dyldcache_va2pa(cache, sections[i].addr, NULL, NULL);
227  if (!ptr->vaddr) {
228  ptr->vaddr = ptr->paddr;
229  }
230  ptr->perm = sections[i].perm;
231  rz_list_append(ret, ptr);
232  }
233  free(sections);
235  (mach0);
236 }
237 
240  if (!ret) {
241  return NULL;
242  }
243  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
246  if (!vf) {
247  return ret;
248  }
249  vf->buf = rz_dyldcache_new_rebasing_buf(cache);
250  vf->buf_owned = true;
252  rz_list_push(ret, vf);
253  }
254  return ret;
255 }
256 
257 static int prot2perm(int x) {
258  int r = 0;
259  if (x & 1) {
260  r |= 4;
261  }
262  if (x & 2) {
263  r |= 2;
264  }
265  if (x & 4) {
266  r |= 1;
267  }
268  return r;
269 }
270 
271 static RzList *maps(RzBinFile *bf) {
272  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
273  if (!cache) {
274  return NULL;
275  }
277  if (!ret) {
278  return NULL;
279  }
280  ut64 slide = rz_dyldcache_get_slide(cache);
281  for (ut32 i = 0; i < cache->n_maps; i++) {
283  if (!map) {
284  rz_list_free(ret);
285  return NULL;
286  }
287  map->name = rz_str_newf("cache_map.%d", i);
288  map->paddr = cache->maps[i].fileOffset;
289  map->psize = cache->maps[i].size;
290  map->vsize = map->psize;
291  map->vaddr = cache->maps[i].address + slide;
292  map->perm = prot2perm(cache->maps[i].initProt);
293  if (rz_dyldcache_range_needs_rebasing(cache, map->paddr, map->psize)) {
295  }
296  rz_list_append(ret, map);
297  }
298  return ret;
299 }
300 
301 static RzList *sections(RzBinFile *bf) {
302  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
303  if (!cache) {
304  return NULL;
305  }
307  if (!ret) {
308  return NULL;
309  }
310  RzListIter *iter;
312  rz_list_foreach (cache->bins, iter, bin) {
313  sections_from_bin(ret, bf, bin);
314  }
315  ut64 slide = rz_dyldcache_get_slide(cache);
316  if (slide) {
318  rz_list_foreach (ret, iter, section) {
319  section->vaddr += slide;
320  }
321  }
322  return ret;
323 }
324 
325 static RzList *symbols(RzBinFile *bf) {
326  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
327  if (!cache) {
328  return NULL;
329  }
330 
332  if (!ret) {
333  return NULL;
334  }
335 
336  RzListIter *iter;
338  rz_list_foreach (cache->bins, iter, bin) {
339  SetU *hash = set_u_new();
340  if (!hash) {
341  rz_list_free(ret);
342  return NULL;
343  }
344  symbols_from_bin(cache, ret, bf, bin, hash);
345  rz_dyldcache_symbols_from_locsym(cache, bin, ret, hash);
346  set_u_free(hash);
347  }
348 
349  ut64 slide = rz_dyldcache_get_slide(cache);
350  if (slide) {
351  RzBinSymbol *sym;
352  rz_list_foreach (ret, iter, sym) {
353  sym->vaddr += slide;
354  }
355  }
356 
357  return ret;
358 }
359 
360 static void destroy(RzBinFile *bf) {
361  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
362  rz_dyldcache_free(cache);
363 }
364 
365 static RzList *classes(RzBinFile *bf) {
366  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
367  if (!cache) {
368  return NULL;
369  }
370 
371  RzList *ret = rz_list_newf(free);
372  if (!ret) {
373  return NULL;
374  }
375 
376  if (!cache->objc_opt_info_loaded) {
377  cache->oi = rz_dyldcache_get_objc_opt_info(bf, cache);
378  cache->objc_opt_info_loaded = true;
379  }
380 
381  RzListIter *iter;
383 
384  RzBuffer *buf = bf->buf;
385  RzBuffer *owned_buf = NULL;
386  if (rz_dyldcache_needs_rebasing(cache)) {
387  owned_buf = rz_dyldcache_new_rebasing_buf(cache);
388  if (!owned_buf) {
389  goto beach;
390  }
391  buf = owned_buf;
392  }
393 
394  ut32 num_of_unnamed_class = 0;
395  rz_list_foreach (cache->bins, iter, bin) {
396  struct MACH0_(obj_t) *mach0 = bin_to_mach0(bf, bin);
397  if (!mach0) {
398  goto beach;
399  }
400 
401  struct section_t *sections = NULL;
402  if (!(sections = MACH0_(get_sections)(mach0))) {
404  (mach0);
405  goto beach;
406  }
407 
408  int i;
409  for (i = 0; !sections[i].last; i++) {
410  if (sections[i].size == 0) {
411  continue;
412  }
413 
414  bool is_classlist = strstr(sections[i].name, "__objc_classlist");
415  bool is_catlist = strstr(sections[i].name, "__objc_catlist");
416 
417  if (!is_classlist && !is_catlist) {
418  continue;
419  }
420 
421  ut8 *pointers = malloc(sections[i].size);
422  if (!pointers) {
423  continue;
424  }
425 
427  if (rz_buf_read_at(buf, offset, pointers, sections[i].size) < sections[i].size) {
428  RZ_FREE(pointers);
429  continue;
430  }
431  ut8 *cursor = pointers;
432  ut8 *pointers_end = pointers + sections[i].size;
433 
434  for (; cursor < pointers_end; cursor += 8) {
435  ut64 pointer_to_class = rz_read_le64(cursor);
436 
437  RzBinClass *klass;
438  if (!(klass = RZ_NEW0(RzBinClass)) ||
439  !(klass->methods = rz_list_new()) ||
440  !(klass->fields = rz_list_new())) {
441  RZ_FREE(klass);
442  RZ_FREE(pointers);
443  RZ_FREE(sections);
445  (mach0);
446  goto beach;
447  }
448 
449  bf->o->bin_obj = mach0;
450  if (is_classlist) {
452  (pointer_to_class, bf, buf, klass, false, NULL, cache->oi);
453  } else {
455  (pointer_to_class, bf, buf, klass, NULL, cache->oi);
456  }
457  bf->o->bin_obj = cache;
458 
459  if (!klass->name) {
460  RZ_LOG_ERROR("CLASS ERROR AT 0x%llx, is_classlist %d\n", pointer_to_class, is_classlist);
461  klass->name = rz_str_newf("UnnamedClass%u", num_of_unnamed_class);
462  if (!klass->name) {
463  RZ_FREE(klass);
464  RZ_FREE(pointers);
465  RZ_FREE(sections);
467  (mach0);
468  goto beach;
469  }
470  num_of_unnamed_class++;
471  }
472  rz_list_append(ret, klass);
473  }
474 
475  RZ_FREE(pointers);
476  }
477 
478  RZ_FREE(sections);
480  (mach0);
481  }
482 
483  return ret;
484 
485 beach:
486  rz_list_free(ret);
487  rz_buf_free(owned_buf);
488  return NULL;
489 }
490 
491 static void header(RzBinFile *bf) {
492  if (!bf || !bf->o) {
493  return;
494  }
495 
496  RzDyldCache *cache = (RzDyldCache *)bf->o->bin_obj;
497  if (!cache) {
498  return;
499  }
500 
501  RzBin *bin = bf->rbin;
502  ut64 slide = rz_dyldcache_get_slide(cache);
503  PrintfCallback p = bin->cb_printf;
504 
505  PJ *pj = pj_new();
506  if (!pj) {
507  return;
508  }
509 
510  pj_o(pj);
511  pj_k(pj, "header");
512  pj_o(pj);
513  pj_ks(pj, "magic", cache->hdr->magic);
514  pj_kn(pj, "mappingOffset", cache->hdr->mappingOffset);
515  pj_kn(pj, "mappingCount", cache->hdr->mappingCount);
516  pj_kn(pj, "imagesOffset", cache->hdr->imagesOffset);
517  pj_kn(pj, "imagesCount", cache->hdr->imagesCount);
518  pj_kn(pj, "dyldBaseAddress", cache->hdr->dyldBaseAddress);
519  pj_kn(pj, "codeSignatureOffset", cache->hdr->codeSignatureOffset);
520  pj_kn(pj, "codeSignatureSize", cache->hdr->codeSignatureSize);
521  pj_kn(pj, "slideInfoOffset", cache->hdr->slideInfoOffset);
522  pj_kn(pj, "slideInfoSize", cache->hdr->slideInfoSize);
523  pj_kn(pj, "localSymbolsOffset", cache->hdr->localSymbolsOffset);
524  pj_kn(pj, "localSymbolsSize", cache->hdr->localSymbolsSize);
525  char uuidstr[128];
526  rz_hex_bin2str((ut8 *)cache->hdr->uuid, 16, uuidstr);
527  pj_ks(pj, "uuid", uuidstr);
528  pj_ks(pj, "cacheType", (cache->hdr->cacheType == 0) ? "development" : "production");
529  pj_kn(pj, "branchPoolsOffset", cache->hdr->branchPoolsOffset);
530  pj_kn(pj, "branchPoolsCount", cache->hdr->branchPoolsCount);
531  pj_kn(pj, "accelerateInfoAddr", cache->hdr->accelerateInfoAddr + slide);
532  pj_kn(pj, "accelerateInfoSize", cache->hdr->accelerateInfoSize);
533  pj_kn(pj, "imagesTextOffset", cache->hdr->imagesTextOffset);
534  pj_kn(pj, "imagesTextCount", cache->hdr->imagesTextCount);
535  pj_end(pj);
536 
537  if (cache->accel) {
538  pj_k(pj, "accelerator");
539  pj_o(pj);
540  pj_kn(pj, "version", cache->accel->version);
541  pj_kn(pj, "imageExtrasCount", cache->accel->imageExtrasCount);
542  pj_kn(pj, "imagesExtrasOffset", cache->accel->imagesExtrasOffset);
543  pj_kn(pj, "bottomUpListOffset", cache->accel->bottomUpListOffset);
544  pj_kn(pj, "dylibTrieOffset", cache->accel->dylibTrieOffset);
545  pj_kn(pj, "dylibTrieSize", cache->accel->dylibTrieSize);
546  pj_kn(pj, "initializersOffset", cache->accel->initializersOffset);
547  pj_kn(pj, "initializersCount", cache->accel->initializersCount);
548  pj_kn(pj, "dofSectionsOffset", cache->accel->dofSectionsOffset);
549  pj_kn(pj, "dofSectionsCount", cache->accel->dofSectionsCount);
550  pj_kn(pj, "reExportListOffset", cache->accel->reExportListOffset);
551  pj_kn(pj, "reExportCount", cache->accel->reExportCount);
552  pj_kn(pj, "depListOffset", cache->accel->depListOffset);
553  pj_kn(pj, "depListCount", cache->accel->depListCount);
554  pj_kn(pj, "rangeTableOffset", cache->accel->rangeTableOffset);
555  pj_kn(pj, "rangeTableCount", cache->accel->rangeTableCount);
556  pj_kn(pj, "dyldSectionAddr", cache->accel->dyldSectionAddr + slide);
557  pj_end(pj);
558  }
559 
560  if (cache->rebase_infos) {
561  size_t i;
562  pj_k(pj, "slideInfo");
563  pj_a(pj);
564  for (i = 0; i < cache->rebase_infos->length; i++) {
565  RzDyldRebaseInfo *rebase_info = cache->rebase_infos->entries[i].info;
566  pj_o(pj);
567  pj_kn(pj, "start", cache->rebase_infos->entries[i].start);
568  pj_kn(pj, "end", cache->rebase_infos->entries[i].end);
569  if (rebase_info) {
570  ut8 version = rebase_info->version;
571  pj_kn(pj, "version", version);
572  pj_kn(pj, "slide", slide);
573  if (version == 3) {
574  RzDyldRebaseInfo3 *info3 = (RzDyldRebaseInfo3 *)rebase_info;
575  pj_kn(pj, "page_starts_count", info3->page_starts_count);
576  pj_kn(pj, "page_size", info3->page_size);
577  pj_kn(pj, "auth_value_add", info3->auth_value_add);
578  } else if (version == 2 || version == 4) {
579  RzDyldRebaseInfo2 *info2 = (RzDyldRebaseInfo2 *)rebase_info;
580  pj_kn(pj, "page_starts_count", info2->page_starts_count);
581  pj_kn(pj, "page_extras_count", info2->page_extras_count);
582  pj_kn(pj, "delta_mask", info2->delta_mask);
583  pj_kn(pj, "value_mask", info2->value_mask);
584  pj_kn(pj, "value_add", info2->value_add);
585  pj_kn(pj, "delta_shift", info2->delta_shift);
586  pj_kn(pj, "page_size", info2->page_size);
587  } else if (version == 1) {
588  RzDyldRebaseInfo1 *info1 = (RzDyldRebaseInfo1 *)rebase_info;
589  pj_kn(pj, "toc_count", info1->toc_count);
590  pj_kn(pj, "entries_size", info1->entries_size);
591  pj_kn(pj, "page_size", 4096);
592  }
593  }
594  pj_end(pj);
595  }
596  pj_end(pj);
597  }
598 
599  if (cache->hdr->imagesTextCount) {
600  pj_k(pj, "images");
601  pj_a(pj);
602  ut64 total_size = cache->hdr->imagesTextCount * sizeof(cache_text_info_t);
603  cache_text_info_t *text_infos = malloc(total_size);
604  if (!text_infos) {
605  goto beach;
606  }
607  if (rz_buf_fread_at(cache->buf, cache->hdr->imagesTextOffset, (ut8 *)text_infos, "16clii", cache->hdr->imagesTextCount) != total_size) {
608  free(text_infos);
609  goto beach;
610  }
611  size_t i;
612  for (i = 0; i != cache->hdr->imagesTextCount; i++) {
613  cache_text_info_t *text_info = &text_infos[i];
614  rz_hex_bin2str((ut8 *)text_info->uuid, 16, uuidstr);
615  pj_o(pj);
616  pj_ks(pj, "uuid", uuidstr);
617  pj_kn(pj, "address", text_info->loadAddress + slide);
618  pj_kn(pj, "textSegmentSize", text_info->textSegmentSize);
619  char file[256];
620  if (rz_buf_read_at(cache->buf, text_info->pathOffset, (ut8 *)&file, sizeof(file)) == sizeof(file)) {
621  file[255] = 0;
622  pj_ks(pj, "path", file);
623  char *last_slash = strrchr(file, '/');
624  if (last_slash && *last_slash) {
625  pj_ks(pj, "name", last_slash + 1);
626  } else {
627  pj_ks(pj, "name", file);
628  }
629  }
630  pj_end(pj);
631  }
632  pj_end(pj);
633  free(text_infos);
634  }
635 
636  pj_end(pj);
637  p("%s\n", pj_string(pj));
638 
639 beach:
640  pj_free(pj);
641 }
642 
644  .name = "dyldcache",
645  .desc = "dyldcache bin plugin",
646  .license = "LGPL3",
647  .load_buffer = &load_buffer,
648  .entries = &entries,
649  .baddr = &baddr,
650  .symbols = &symbols,
651  .virtual_files = &virtual_files,
652  .maps = &maps,
653  .sections = &sections,
654  .check_buffer = &check_buffer,
655  .destroy = &destroy,
656  .classes = &classes,
657  .header = &header,
658  .info = &info,
659 };
660 
661 #ifndef RZ_PLUGIN_INCORE
664  .data = &rz_bin_plugin_dyldcache,
666 };
667 #endif
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
RZ_API void rz_bin_map_free(RzBinMap *map)
Definition: bin.c:1023
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
RZ_API void rz_bin_virtual_file_free(RzBinVirtualFile *vfile)
Definition: bin.c:1012
static ut64 bin_obj_va2pa(ut64 p, ut32 *offset, ut32 *left, RzBinFile *bf)
Definition: bin_dyldcache.c:16
static void sections_from_bin(RzList *ret, RzBinFile *bf, RzDyldBinImage *bin)
static RzList * classes(RzBinFile *bf)
static bool check_buffer(RzBuffer *buf)
Definition: bin_dyldcache.c:58
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_dyldcache.c:72
static RzList * symbols(RzBinFile *bf)
static void header(RzBinFile *bf)
void symbols_from_bin(RzDyldCache *cache, RzList *ret, RzBinFile *bf, RzDyldBinImage *bin, SetU *hash)
static void destroy(RzBinFile *bf)
RZ_API RzLibStruct rizin_plugin
static bool __is_data_section(const char *name)
static RzList * virtual_files(RzBinFile *bf)
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_dyldcache.c:93
static ut64 baddr(RzBinFile *bf)
static int prot2perm(int x)
static RzList * entries(RzBinFile *bf)
Definition: bin_dyldcache.c:81
static RzList * maps(RzBinFile *bf)
RzBinPlugin rz_bin_plugin_dyldcache
static RzList * sections(RzBinFile *bf)
#define RZ_DYLDCACHE_VFILE_NAME_REBASED
Definition: bin_dyldcache.c:14
static struct MACH0_(obj_t)
Definition: bin_dyldcache.c:27
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
uint32_t ut32
RZ_API ut64 rz_dyldcache_get_slide(RzDyldCache *cache)
Definition: dyldcache.c:1097
RZ_API bool rz_dyldcache_check_magic(const char *magic)
Definition: dyldcache.c:18
RZ_API void rz_dyldcache_symbols_from_locsym(RzDyldCache *cache, RzDyldBinImage *bin, RzList *symbols, SetU *hash)
Definition: dyldcache.c:1113
RZ_API void rz_dyldcache_free(RzDyldCache *cache)
Definition: dyldcache.c:1325
RZ_API RzDyldCache * rz_dyldcache_new_buf(RzBuffer *buf)
Definition: dyldcache.c:1170
RZ_API ut64 rz_dyldcache_va2pa(RzDyldCache *cache, uint64_t vaddr, ut32 *offset, ut32 *left)
Definition: dyldcache.c:1353
RZ_API objc_cache_opt_info * rz_dyldcache_get_objc_opt_info(RzBinFile *bf, RzDyldCache *cache)
Definition: dyldcache.c:247
RZ_API RzBuffer * rz_dyldcache_new_rebasing_buf(RzDyldCache *cache)
RZ_API bool rz_dyldcache_needs_rebasing(RzDyldCache *cache)
RZ_API bool rz_dyldcache_range_needs_rebasing(RzDyldCache *cache, ut64 paddr, ut64 size)
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void * malloc(size_t size)
Definition: malloc.c:123
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
struct section_t *MACH0_() get_sections(struct MACH0_(obj_t) *bin)
Definition: mach0.c:2411
const struct symbol_t *MACH0_() get_symbols(struct MACH0_(obj_t) *bin)
Definition: mach0.c:2959
void *MACH0_() mach0_free(struct MACH0_(obj_t) *mo)
Definition: mach0.c:2057
void MACH0_() opts_set_default(struct MACH0_(opts_t) *options, RzBinFile *bf)
Definition: mach0.c:2103
RZ_API void MACH0_() get_class_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass *klass, bool dupe, RzSkipList *relocs, objc_cache_opt_info *oi)
RZ_API void MACH0_() get_category_t(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinClass *klass, RzSkipList *relocs, objc_cache_opt_info *oi)
#define RZ_BIN_MACH0_SYMBOL_TYPE_LOCAL
Definition: mach0_specs.h:26
int x
Definition: mipsasm.c:20
#define RZ_BIN_BIND_LOCAL_STR
Definition: rz_bin.h:106
#define RZ_BIN_BIND_GLOBAL_STR
Definition: rz_bin.h:107
#define RZ_BIN_TYPE_FUNC_STR
Definition: rz_bin.h:119
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
RZ_API st64 rz_buf_fread_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL ut8 *buf, RZ_NONNULL const char *fmt, int n)
...
Definition: buf.c:1001
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API RZ_OWN RzBuffer * rz_buf_new_slice(RzBuffer *b, ut64 offset, ut64 size)
Creates a new buffer from a slice of another buffer.
Definition: buf.c:364
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
static ut64 rz_read_le64(const void *src)
Definition: rz_endian.h:266
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_NEW0(x)
Definition: rz_types.h:284
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_FREE(x)
Definition: rz_types.h:369
#define RZ_VERSION
Definition: rz_version.h:8
RZ_API SetU * set_u_new(void)
Definition: set.c:30
RZ_API void set_u_free(SetU *s)
Definition: set.c:46
RZ_API void set_u_add(SetU *s, ut64 u)
Definition: set.c:34
HtUP SetU
Definition: set.h:22
Definition: malloc.c:26
uint32_t dofSectionsCount
Definition: mach0_specs.h:294
uint32_t bottomUpListOffset
Definition: mach0_specs.h:288
uint32_t reExportCount
Definition: mach0_specs.h:296
uint32_t dofSectionsOffset
Definition: mach0_specs.h:293
uint64_t dyldSectionAddr
Definition: mach0_specs.h:301
uint32_t rangeTableCount
Definition: mach0_specs.h:300
uint32_t depListCount
Definition: mach0_specs.h:298
uint32_t imageExtrasCount
Definition: mach0_specs.h:286
uint32_t dylibTrieOffset
Definition: mach0_specs.h:289
uint32_t reExportListOffset
Definition: mach0_specs.h:295
uint32_t depListOffset
Definition: mach0_specs.h:297
uint32_t initializersCount
Definition: mach0_specs.h:292
uint32_t version
Definition: mach0_specs.h:285
uint32_t initializersOffset
Definition: mach0_specs.h:291
uint32_t rangeTableOffset
Definition: mach0_specs.h:299
uint32_t dylibTrieSize
Definition: mach0_specs.h:290
uint32_t imagesExtrasOffset
Definition: mach0_specs.h:287
uint64_t slideInfoOffset
Definition: mach0_specs.h:219
char magic[16]
Definition: mach0_specs.h:211
uint64_t accelerateInfoAddr
Definition: mach0_specs.h:227
uint64_t localSymbolsOffset
Definition: mach0_specs.h:221
uint64_t codeSignatureSize
Definition: mach0_specs.h:218
uint64_t imagesTextCount
Definition: mach0_specs.h:230
uint64_t cacheType
Definition: mach0_specs.h:224
uint64_t codeSignatureOffset
Definition: mach0_specs.h:217
uint32_t branchPoolsOffset
Definition: mach0_specs.h:225
uint64_t slideInfoSize
Definition: mach0_specs.h:220
uint64_t localSymbolsSize
Definition: mach0_specs.h:222
uint64_t dyldBaseAddress
Definition: mach0_specs.h:216
uint64_t accelerateInfoSize
Definition: mach0_specs.h:228
uint32_t imagesCount
Definition: mach0_specs.h:215
uint64_t imagesTextOffset
Definition: mach0_specs.h:229
uint32_t mappingOffset
Definition: mach0_specs.h:212
uint32_t mappingCount
Definition: mach0_specs.h:213
uint32_t imagesOffset
Definition: mach0_specs.h:214
uint32_t branchPoolsCount
Definition: mach0_specs.h:226
uint8_t uuid[16]
Definition: mach0_specs.h:223
uint64_t size
Definition: mach0_specs.h:242
uint32_t initProt
Definition: mach0_specs.h:245
uint64_t fileOffset
Definition: mach0_specs.h:243
uint64_t address
Definition: mach0_specs.h:241
uint8_t uuid[16]
Definition: mach0_specs.h:234
uint32_t pathOffset
Definition: mach0_specs.h:237
uint32_t textSegmentSize
Definition: mach0_specs.h:236
uint64_t loadAddress
Definition: mach0_specs.h:235
Definition: gzappend.c:170
Definition: z80asm.h:102
Definition: rz_pj.h:12
RzList * fields
Definition: rz_bin.h:654
char * name
Definition: rz_bin.h:647
RzList * methods
Definition: rz_bin.h:653
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
struct rz_bin_t * rbin
Definition: rz_bin.h:316
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
char * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
char * arch
Definition: rz_bin.h:214
int big_endian
Definition: rz_bin.h:235
Description of a single memory mapping into virtual memory from a binary.
Definition: rz_bin.h:602
ut64 boffset
Definition: rz_bin.h:262
void * bin_obj
Definition: rz_bin.h:293
char * name
Definition: rz_bin.h:509
char * version
Definition: rz_bin.h:512
char * format
Definition: rz_bin.h:630
char * name
Definition: rz_bin.h:619
const char * bind
Definition: rz_bin.h:681
const char * type
Definition: rz_bin.h:682
char * name
Definition: rz_bin.h:675
ut32 ordinal
Definition: rz_bin.h:692
const char * forwarder
Definition: rz_bin.h:680
RZ_NONNULL RzBuffer * buf
Definition: rz_bin.h:597
bool buf_owned
whether buf is owned and freed by this RzBinVirtualFile
Definition: rz_bin.h:598
RZ_OWN RZ_NONNULL char * name
Definition: rz_bin.h:596
ut64 start
Definition: dyldcache.h:24
RzDyldRebaseInfo * info
Definition: dyldcache.h:26
ut64 end
Definition: dyldcache.h:25
RzDyldRebaseInfosEntry * entries
Definition: dyldcache.h:30
objc_cache_opt_info * oi
Definition: dyldcache.h:109
cache_map_t * maps
Definition: dyldcache.h:101
RzList * bins
Definition: dyldcache.h:104
cache_accel_t * accel
Definition: dyldcache.h:107
bool objc_opt_info_loaded
Definition: dyldcache.h:110
cache_hdr_t * hdr
Definition: dyldcache.h:96
RzBuffer * buf
Definition: dyldcache.h:105
RzDyldRebaseInfos * rebase_infos
Definition: dyldcache.h:106
Definition: sdb.h:63
Definition: mach0.h:54
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58