Rizin
unix-like reverse engineering framework and cli tools
cbin.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2020 earada <pkedurat@gmail.com>
2 // SPDX-FileCopyrightText: 2011-2020 pancake <pancake@nopcode.org>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_core.h>
6 #include <rz_config.h>
7 #include <rz_demangler.h>
8 #include <rz_util.h>
9 #include <rz_list.h>
10 #include <rz_util/rz_time.h>
11 #include <rz_basefind.h>
12 
13 #include "core_private.h"
14 
15 #define is_invalid_address_va(va, vaddr, paddr) (((va) && (vaddr) == UT64_MAX) || (!(va) && (paddr) == UT64_MAX))
16 #define is_invalid_address_va2(va, vaddr, paddr) (((va) != VA_FALSE && (vaddr) == UT64_MAX) || ((va) == VA_FALSE && (paddr) == UT64_MAX))
17 #define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz)))
18 
19 #define VA_FALSE 0
20 #define VA_TRUE 1
21 #define VA_NOREBASE 2
22 
23 #define LOAD_BSS_MALLOC 0
24 
25 #define IS_MODE_SET(mode) ((mode)&RZ_MODE_SET)
26 #define IS_MODE_SIMPLE(mode) ((mode)&RZ_MODE_SIMPLE)
27 #define IS_MODE_SIMPLEST(mode) ((mode)&RZ_MODE_SIMPLEST)
28 #define IS_MODE_JSON(mode) ((mode)&RZ_MODE_JSON)
29 #define IS_MODE_RZCMD(mode) ((mode)&RZ_MODE_RIZINCMD)
30 #define IS_MODE_EQUAL(mode) ((mode)&RZ_MODE_EQUAL)
31 #define IS_MODE_NORMAL(mode) (!(mode))
32 #define IS_MODE_CLASSDUMP(mode) ((mode)&RZ_MODE_CLASSDUMP)
33 
34 // dup from cmd_info
35 #define PAIR_WIDTH "9"
36 
37 #define bprintf \
38  if (binfile && binfile->rbin && binfile->rbin->verbose) \
39  eprintf
40 
42 
43 static void table_add_row_bool(RzTable *t, const char *key, bool val) {
45  const char *b = val || typeString ? rz_str_bool(val) : "";
46  rz_table_add_rowf(t, "ss", key, b);
47 }
48 
49 static char *__filterQuotedShell(const char *arg) {
51  char *a = malloc(strlen(arg) + 1);
52  if (!a) {
53  return NULL;
54  }
55  char *b = a;
56  while (*arg) {
57  switch (*arg) {
58  case ' ':
59  case '=':
60  case '"':
61  case '\\':
62  case '\r':
63  case '\n':
64  break;
65  default:
66  *b++ = *arg;
67  break;
68  }
69  arg++;
70  }
71  *b = 0;
72  return a;
73 }
74 
75 #define STR(x) (x) ? (x) : ""
76 
77 static ut64 rva(RzBinObject *o, ut64 paddr, ut64 vaddr, int va) {
78  if (va == VA_TRUE) {
79  return rz_bin_object_get_vaddr(o, paddr, vaddr);
80  }
81  if (va == VA_NOREBASE) {
82  return vaddr;
83  }
84  return paddr;
85 }
86 
87 RZ_API void rz_core_bin_options_init(RzCore *core, RZ_OUT RzBinOptions *opts, int fd, ut64 baseaddr, ut64 loadaddr) {
88  rz_return_if_fail(core && opts);
89 
90  bool patch_relocs = rz_config_get_b(core->config, "bin.relocs");
91 
92  rz_bin_options_init(opts, fd, baseaddr, loadaddr, patch_relocs);
93 
94  opts->obj_opts.elf_load_sections = rz_config_get_b(core->config, "elf.load.sections");
95  opts->obj_opts.elf_checks_sections = rz_config_get_b(core->config, "elf.checks.sections");
96  opts->obj_opts.elf_checks_segments = rz_config_get_b(core->config, "elf.checks.segments");
97  opts->obj_opts.big_endian = rz_config_get_b(core->config, "cfg.bigendian");
98 }
99 
101  if (rz_bin_file_set_cur_by_fd(core->bin, bin_fd)) {
102  rz_core_bin_set_cur(core, rz_bin_cur(core->bin));
103  return true;
104  }
105  return false;
106 }
107 
109  char *flagname = NULL, *offset = NULL;
110  RzBinFile *bf = rz_bin_cur(core->bin);
111  if (!bf) {
112  return;
113  }
114  Sdb *db = sdb_ns(bf->sdb, "info", 0);
115  if (!db) {
116  return;
117  }
118  SdbListIter *iter;
119  SdbKv *kv;
120  if (IS_MODE_RZCMD(mode)) {
121  rz_cons_printf("fs format\n");
122  } else if (IS_MODE_SET(mode)) {
123  rz_flag_space_push(core->flags, "format");
124  }
125  // iterate over all keys
126  SdbList *ls = sdb_foreach_list(db, false);
127  ls_foreach (ls, iter, kv) {
128  char *k = sdbkv_key(kv);
129  char *v = sdbkv_value(kv);
130  char *dup = strdup(k);
131  // printf ("?e (%s) (%s)\n", k, v);
132  if ((flagname = strstr(dup, ".offset"))) {
133  *flagname = 0;
134  flagname = dup;
135  if (IS_MODE_RZCMD(mode)) {
136  rz_cons_printf("f %s @ %s\n", flagname, v);
137  } else if (IS_MODE_SET(mode)) {
138  ut64 nv = rz_num_math(core->num, v);
139  rz_flag_set(core->flags, flagname, nv, 0);
140  }
141  free(offset);
142  offset = strdup(v);
143  }
144  if (strstr(dup, ".cparse")) {
145  if (IS_MODE_RZCMD(mode)) {
146  rz_cons_printf("td \"%s\"\n", v);
147  } else if (IS_MODE_SET(mode)) {
148  char *code = rz_str_newf("%s;", v);
149  char *error_msg = NULL;
150  RzTypeDB *typedb = core->analysis->typedb;
151  int result = rz_type_parse_string_stateless(typedb->parser, code, &error_msg);
152  if (result && error_msg) {
153  eprintf("%s", error_msg);
154  free(error_msg);
155  }
156  }
157  }
158  free(dup);
159  }
160  RZ_FREE(offset);
161  ls_foreach (ls, iter, kv) {
162  char *k = sdbkv_key(kv);
163  char *v = sdbkv_value(kv);
164  char *dup = strdup(k);
165  if ((flagname = strstr(dup, ".format"))) {
166  *flagname = 0;
167  if (!offset) {
168  offset = strdup("0");
169  }
170  flagname = dup;
171  if (IS_MODE_RZCMD(mode)) {
172  rz_cons_printf("pf.%s %s\n", flagname, v);
173  } else if (IS_MODE_SET(mode)) {
174  rz_type_db_format_set(core->analysis->typedb, flagname, v);
175  }
176  }
177  free(dup);
178  }
179  ls_foreach (ls, iter, kv) {
180  char *k = sdbkv_key(kv);
181  char *v = sdbkv_value(kv);
182  char *dup = strdup(k);
183  if ((flagname = strstr(dup, ".format"))) {
184  *flagname = 0;
185  if (!offset) {
186  offset = strdup("0");
187  }
188  flagname = dup;
189  int fmtsize = rz_type_format_struct_size(core->analysis->typedb, v, 0, 0);
190  char *offset_key = rz_str_newf("%s.offset", flagname);
191  const char *off = sdb_const_get(db, offset_key, 0);
192  free(offset_key);
193  if (off) {
194  if (IS_MODE_RZCMD(mode)) {
195  rz_cons_printf("Cf %d %s @ %s\n", fmtsize, v, off);
196  } else if (IS_MODE_SET(mode)) {
198  ut8 *buf = malloc(fmtsize);
199  if (buf) {
200  rz_io_read_at(core->io, addr, buf, fmtsize);
201  char *format = rz_type_format_data(core->analysis->typedb, core->print, addr, buf,
202  fmtsize, v, 0, NULL, NULL);
203  free(buf);
204  if (!format) {
205  eprintf("Warning: Cannot register invalid format (%s)\n", v);
206  } else {
207  rz_cons_print(format);
208  free(format);
209  }
210  }
211  }
212  }
213  }
214  if ((flagname = strstr(dup, ".size"))) {
215  *flagname = 0;
216  flagname = dup;
217  if (IS_MODE_RZCMD(mode)) {
218  rz_cons_printf("fL %s %s\n", flagname, v);
219  } else if (IS_MODE_SET(mode)) {
220  RzFlagItem *fi = rz_flag_get(core->flags, flagname);
221  if (fi) {
222  fi->size = rz_num_math(core->num, v);
223  } else {
224  eprintf("Cannot find flag named '%s'\n", flagname);
225  }
226  }
227  }
228  free(dup);
229  }
230  free(offset);
231  if (IS_MODE_SET(mode)) {
232  rz_flag_space_pop(core->flags);
233  }
234 }
235 
237  rz_return_val_if_fail(core && file && core->io, false);
238  if (strchr(file, '\"')) { // TODO: escape "?
239  eprintf("Invalid char found in filename\n");
240  return false;
241  }
242  RzBinOptions opt = { 0 };
243  RzBinFile *bf = rz_bin_open(core->bin, file, &opt);
244  if (!bf) {
245  eprintf("Cannot open bin '%s'\n", file);
246  return false;
247  }
249  rz_bin_file_delete(core->bin, bf);
250  return true;
251 }
252 
253 RZ_API int rz_core_bin_set_by_name(RzCore *core, const char *name) {
254  if (rz_bin_file_set_cur_by_name(core->bin, name)) {
255  rz_core_bin_set_cur(core, rz_bin_cur(core->bin));
256  return true;
257  }
258  return false;
259 }
260 
262  rz_return_val_if_fail(r && binfile && mask, false);
263  RzBinObject *binobj = binfile->o;
264  RzBinInfo *info = binobj ? binobj->info : NULL;
265  if (!info) {
266  return false;
267  }
268 
269  bool va = info->has_va;
270 
271  if (mask & RZ_CORE_BIN_ACC_STRINGS) {
272  rz_core_bin_apply_strings(r, binfile);
273  }
274  if (mask & RZ_CORE_BIN_ACC_INFO) {
275  rz_core_bin_apply_config(r, binfile);
276  }
277  if (mask & RZ_CORE_BIN_ACC_MAIN) {
278  rz_core_bin_apply_main(r, binfile, va);
279  }
280  if (mask & RZ_CORE_BIN_ACC_DWARF) {
281  rz_core_bin_apply_dwarf(r, binfile);
282  }
283  if (mask & RZ_CORE_BIN_ACC_ENTRIES) {
284  rz_core_bin_apply_entry(r, binfile, va);
285  }
286  if (mask & RZ_CORE_BIN_ACC_MAPS) {
287  rz_core_bin_apply_maps(r, binfile, va);
288  }
289  if (mask & RZ_CORE_BIN_ACC_SECTIONS) {
290  rz_core_bin_apply_sections(r, binfile, va);
291  }
292  if (mask & RZ_CORE_BIN_ACC_RELOCS && rz_config_get_b(r->config, "bin.relocs")) {
293  rz_core_bin_apply_relocs(r, binfile, va);
294  }
295  if (mask & RZ_CORE_BIN_ACC_IMPORTS) {
296  rz_core_bin_apply_imports(r, binfile, va);
297  }
298  if (mask & RZ_CORE_BIN_ACC_SYMBOLS) {
299  rz_core_bin_apply_symbols(r, binfile, va);
300  }
301  if (mask & RZ_CORE_BIN_ACC_CLASSES) {
302  rz_core_bin_apply_classes(r, binfile);
303  }
304  if (mask & RZ_CORE_BIN_ACC_RESOURCES) {
305  rz_core_bin_apply_resources(r, binfile);
306  }
307 
308  return true;
309 }
310 
312  rz_return_val_if_fail(r && binfile, false);
313  RzBinObject *binobj = binfile->o;
314  RzBinInfo *info = binobj ? binobj->info : NULL;
315  if (!info) {
316  return false;
317  }
318  const char *arch = info->arch;
319  ut16 bits = info->bits;
321  rz_config_set_i(r->config, "bin.baddr", baseaddr);
322  sdb_num_add(r->sdb, "orig_baddr", baseaddr, 0);
323  r->dbg->bp->baddr = baseaddr;
324  rz_config_set(r->config, "asm.arch", arch);
325  rz_config_set_i(r->config, "asm.bits", bits);
326  rz_config_set(r->config, "analysis.arch", arch);
327  if (info->cpu && *info->cpu) {
328  rz_config_set(r->config, "analysis.cpu", info->cpu);
329  } else {
330  rz_config_set(r->config, "analysis.cpu", arch);
331  }
332  rz_asm_use(r->rasm, arch);
333 
334  rz_core_bin_apply_info(r, binfile, RZ_CORE_BIN_ACC_ALL);
335 
336  rz_core_bin_set_cur(r, binfile);
337  return true;
338 }
339 
340 static bool add_footer(RzCmdStateOutput *main_state, RzCmdStateOutput *state) {
341  if (state->mode == RZ_OUTPUT_MODE_TABLE) {
342  char *s = rz_table_tostring(state->d.t);
343  if (!s) {
344  return false;
345  }
346  rz_cons_printf("%s\n", s);
347  free(s);
348  } else if (state->mode == RZ_OUTPUT_MODE_JSON || state->mode == RZ_OUTPUT_MODE_LONG_JSON) {
349  const char *state_json = pj_string(state->d.pj);
350  pj_raw(main_state->d.pj, state_json);
351  }
353  return true;
354 }
355 
356 static RzCmdStateOutput *add_header(RzCmdStateOutput *main_state, RzOutputMode default_mode, const char *header) {
358  rz_cmd_state_output_init(state, main_state->mode == RZ_OUTPUT_MODE_STANDARD ? default_mode : main_state->mode);
359  if (state->mode == RZ_OUTPUT_MODE_TABLE || state->mode == RZ_OUTPUT_MODE_STANDARD) {
360  rz_cons_printf("[%c%s]\n", toupper(header[0]), header + 1);
361  } else if (state->mode == RZ_OUTPUT_MODE_JSON || state->mode == RZ_OUTPUT_MODE_LONG_JSON) {
362  pj_k(main_state->d.pj, header);
363  }
364  return state;
365 }
366 
386 RZ_API bool rz_core_bin_print(RzCore *core, RZ_NONNULL RzBinFile *bf, ut32 mask, RzCoreBinFilter *filter, RzCmdStateOutput *state, RzList /*<char *>*/ *hashes) {
387  rz_return_val_if_fail(core && state, false);
388 
389 #define wrap_mode(header, default_mode, method) \
390  do { \
391  RzCmdStateOutput *st = add_header(state, default_mode, header); \
392  res &= method; \
393  add_footer(state, st); \
394  } while (0)
395 
396  bool res = true;
397  if (mask & RZ_CORE_BIN_ACC_INFO) {
399  wrap_mode("info", RZ_OUTPUT_MODE_TABLE, rz_core_bin_info_print(core, bf, st));
400  }
401  }
402  if (mask & RZ_CORE_BIN_ACC_IMPORTS) {
405  }
406  }
407  if (mask & RZ_CORE_BIN_ACC_ENTRIES) {
409  wrap_mode("entries", RZ_OUTPUT_MODE_TABLE, rz_core_bin_entries_print(core, bf, st));
410  }
411  }
412  if (mask & RZ_CORE_BIN_ACC_EXPORTS) {
415  }
416  }
417  if (mask & RZ_CORE_BIN_ACC_CLASSES) {
419  wrap_mode("classes", RZ_OUTPUT_MODE_TABLE, rz_core_bin_classes_print(core, bf, st));
420  }
421  }
422  if (mask & RZ_CORE_BIN_ACC_SYMBOLS) {
425  }
426  }
427  if (mask & RZ_CORE_BIN_ACC_SECTIONS) {
429  wrap_mode("sections", RZ_OUTPUT_MODE_TABLE, rz_core_bin_sections_print(core, bf, st, filter, hashes));
430  }
431  }
432  if (mask & RZ_CORE_BIN_ACC_SEGMENTS) {
434  wrap_mode("segments", RZ_OUTPUT_MODE_TABLE, rz_core_bin_segments_print(core, bf, st, filter, hashes));
435  }
436  }
437  if (mask & RZ_CORE_BIN_ACC_MEM) {
439  wrap_mode("memory", RZ_OUTPUT_MODE_TABLE, rz_core_bin_memory_print(core, bf, st));
440  }
441  }
442  if (mask & RZ_CORE_BIN_ACC_STRINGS) {
444  wrap_mode("strings", RZ_OUTPUT_MODE_TABLE, rz_core_bin_strings_print(core, bf, st));
445  }
446  }
447  if (mask & RZ_CORE_BIN_ACC_MAIN) {
449  wrap_mode("main", RZ_OUTPUT_MODE_TABLE, rz_core_bin_main_print(core, bf, st));
450  }
451  }
452  if (mask & RZ_CORE_BIN_ACC_DWARF) {
455  }
456  }
457  if (mask & RZ_CORE_BIN_ACC_RELOCS) {
459  wrap_mode("relocs", RZ_OUTPUT_MODE_TABLE, rz_core_bin_relocs_print(core, bf, st));
460  }
461  }
462  if (mask & RZ_CORE_BIN_ACC_RESOURCES) {
464  wrap_mode("resources", RZ_OUTPUT_MODE_STANDARD, rz_core_bin_resources_print(core, bf, st, hashes));
465  }
466  }
467  if (mask & RZ_CORE_BIN_ACC_FIELDS) {
469  wrap_mode("fields", RZ_OUTPUT_MODE_TABLE, rz_core_bin_fields_print(core, bf, st));
470  }
471  }
472  if (mask & RZ_CORE_BIN_ACC_LIBS) {
474  wrap_mode("libs", RZ_OUTPUT_MODE_TABLE, rz_core_bin_libs_print(core, bf, st));
475  }
476  }
477  if (mask & RZ_CORE_BIN_ACC_SIZE) {
480  }
481  }
482  if (mask & RZ_CORE_BIN_ACC_PDB) {
485  RzPdb *pdb = rz_core_pdb_load_info(core, core->bin->file);
486  if (!pdb) {
488  return false;
489  }
490  rz_core_pdb_info_print(core, core->analysis->typedb, pdb, st);
491  rz_bin_pdb_free(pdb);
492  add_footer(state, st);
493  }
494  }
495  if (mask & RZ_CORE_BIN_ACC_VERSIONINFO) {
497  wrap_mode("versioninfo", RZ_OUTPUT_MODE_STANDARD, rz_core_bin_versions_print(core, bf, st));
498  }
499  }
500  if (mask & RZ_CORE_BIN_ACC_SIGNATURE) {
502  wrap_mode("signatures", RZ_OUTPUT_MODE_STANDARD, rz_core_bin_signatures_print(core, bf, st));
503  }
504  }
505  if (mask & RZ_CORE_BIN_ACC_INITFINI) {
507  wrap_mode("initfini", RZ_OUTPUT_MODE_TABLE, rz_core_bin_initfini_print(core, bf, st));
508  }
509  }
510  if (mask & RZ_CORE_BIN_ACC_TRYCATCH) {
511  if (state->mode & RZ_OUTPUT_MODE_RIZIN) {
512  wrap_mode("trycatch", RZ_OUTPUT_MODE_RIZIN, rz_core_bin_trycatch_print(core, bf, st));
513  }
514  }
515  if (mask & RZ_CORE_BIN_ACC_SECTIONS_MAPPING) {
517  wrap_mode("sections mapping", RZ_OUTPUT_MODE_TABLE, rz_core_bin_sections_mapping_print(core, bf, st));
518  }
519  }
520  if (mask & RZ_CORE_BIN_ACC_BASEFIND) {
522  wrap_mode("basefind", RZ_OUTPUT_MODE_TABLE, rz_core_bin_basefind_print(core, 32, st));
523  }
524  }
525 
526 #undef wrap_mode
527 
528  return res;
529 }
530 
532  rz_return_val_if_fail(r && binfile, false);
533  RzBinObject *o = binfile->o;
534  if (!o) {
535  return false;
536  }
537  const RzList *l = core_bin_strings(r, binfile);
538  if (!l) {
539  return false;
540  }
541  int va = (binfile->o && binfile->o->info && binfile->o->info->has_va) ? VA_TRUE : VA_FALSE;
542  rz_flag_space_push(r->flags, RZ_FLAGS_FS_STRINGS);
544  RzListIter *iter;
545  RzBinString *string;
546  rz_list_foreach (l, iter, string) {
547  if (is_invalid_address_va(va, string->vaddr, string->paddr)) {
548  continue;
549  }
550  ut64 vaddr = rva(o, string->paddr, string->vaddr, va);
551  if (!rz_bin_string_filter(r->bin, string->string, string->length, vaddr)) {
552  continue;
553  }
554  if (rz_cons_is_breaked()) {
555  break;
556  }
557  rz_meta_set_with_subtype(r->analysis, RZ_META_TYPE_STRING, string->type, vaddr, string->size, string->string);
558  char *f_name = strdup(string->string);
559  rz_name_filter(f_name, -1, true);
560  char *str;
561  if (r->bin->prefix) {
562  str = rz_str_newf("%s.str.%s", r->bin->prefix, f_name);
563  } else {
564  str = rz_str_newf("str.%s", f_name);
565  }
566  (void)rz_flag_set(r->flags, str, vaddr, string->size);
567  free(str);
568  free(f_name);
569  }
570  rz_flag_space_pop(r->flags);
572  return true;
573 }
574 
575 static void sdb_concat_by_path(Sdb *s, const char *path) {
576  Sdb *db = sdb_new(0, path, 0);
577  sdb_merge(s, db);
578  sdb_close(db);
579  sdb_free(db);
580 }
581 
583  rz_return_val_if_fail(r && binfile, false);
584  int v;
585  char str[RZ_FLAG_NAME_SIZE];
586  RzBinObject *obj = binfile->o;
587  if (!obj) {
588  return false;
589  }
590  RzBinInfo *info = obj->info;
591  if (!info) {
592  return false;
593  }
594  rz_config_set(r->config, "file.type", rz_str_get(info->rclass));
595  rz_config_set(r->config, "cfg.bigendian",
596  info->big_endian ? "true" : "false");
597  if (info->lang) {
598  rz_config_set(r->config, "bin.lang", info->lang);
599  }
600  rz_config_set(r->config, "asm.os", info->os);
601  if (info->rclass && !strcmp(info->rclass, "pe")) {
602  rz_config_set(r->config, "analysis.cpp.abi", "msvc");
603  } else {
604  rz_config_set(r->config, "analysis.cpp.abi", "itanium");
605  }
606  rz_config_set(r->config, "asm.arch", info->arch);
607  if (info->cpu && *info->cpu) {
608  rz_config_set(r->config, "asm.cpu", info->cpu);
609  }
610  if (info->features && *info->features) {
611  rz_config_set(r->config, "asm.features", info->features);
612  }
613  rz_config_set(r->config, "analysis.arch", info->arch);
615  rz_config_set(r->config, "asm.bits", str);
616  rz_config_set(r->config, "asm.dwarf",
617  (RZ_BIN_DBG_STRIPPED & info->dbg_info) ? "false" : "true");
619  if (v != -1) {
620  rz_config_set_i(r->config, "asm.pcalign", v);
621  }
624  if (info->default_cc && rz_analysis_cc_exist(r->analysis, info->default_cc)) {
625  rz_config_set(r->config, "analysis.cc", info->default_cc);
626  }
627  char *types_dir = rz_path_system(RZ_SDB_TYPES);
628  char *spath = rz_file_path_join(types_dir, "spec.sdb");
629  free(types_dir);
630  if (spath && rz_file_exists(spath)) {
631  sdb_concat_by_path(r->analysis->sdb_fmts, spath);
632  }
633  free(spath);
634  return true;
635 }
636 
637 RZ_API bool rz_core_bin_apply_main(RzCore *r, RzBinFile *binfile, bool va) {
638  rz_return_val_if_fail(r && binfile, false);
639  RzBinObject *o = binfile->o;
640  if (!o) {
641  return false;
642  }
644  if (!binmain) {
645  return false;
646  }
647  ut64 addr = va ? rz_bin_object_addr_with_base(o, binmain->vaddr) : binmain->paddr;
648  rz_flag_space_push(r->flags, RZ_FLAGS_FS_SYMBOLS);
649  rz_flag_set(r->flags, "main", addr, r->blocksize);
650  rz_flag_space_pop(r->flags);
651  return true;
652 }
653 
655  rz_return_val_if_fail(core && binfile, false);
656  if (!rz_config_get_i(core->config, "bin.dbginfo") || !binfile->o) {
657  return false;
658  }
659  RzBinObject *o = binfile->o;
660  const RzBinSourceLineInfo *li = NULL;
662  RzBinDwarfDebugInfo *info = da ? rz_bin_dwarf_parse_info(binfile, da) : NULL;
663  HtUP /*<offset, List *<LocListEntry>*/ *loc_table = rz_bin_dwarf_parse_loc(binfile, core->analysis->bits / 8);
664  if (info) {
666  .info = info,
667  .loc = loc_table
668  };
670  }
671  if (loc_table) {
672  rz_bin_dwarf_loc_free(loc_table);
673  }
676  if (lines) {
677  // move all produced rows line info out (TODO: bin loading should do that)
678  li = o->lines = lines->lines;
679  lines->lines = NULL;
680  }
682  if (!li) {
683  return false;
684  }
685  return true;
686 }
687 
688 static inline bool is_initfini(RzBinAddr *entry) {
689  switch (entry->type) {
693  return true;
694  default:
695  return false;
696  }
697 }
698 
699 RZ_API bool rz_core_bin_apply_entry(RzCore *core, RzBinFile *binfile, bool va) {
700  rz_return_val_if_fail(core && binfile, false);
701  RzBinObject *o = binfile->o;
702  if (!o) {
703  return false;
704  }
705  RzList *entries = o->entries;
706  RzListIter *iter;
707  RzBinAddr *entry = NULL;
708  int i = 0, init_i = 0, fini_i = 0, preinit_i = 0;
709  rz_flag_space_push(core->flags, RZ_FLAGS_FS_SYMBOLS);
710  rz_list_foreach (entries, iter, entry) {
711  ut64 paddr = entry->paddr;
712  ut64 hpaddr = UT64_MAX;
713  ut64 hvaddr = UT64_MAX;
714  if (entry->hpaddr) {
715  hpaddr = entry->hpaddr;
716  if (entry->hvaddr) {
717  hvaddr = rva(o, hpaddr, entry->hvaddr, va);
718  }
719  }
720  if (is_invalid_address_va(va, entry->vaddr, paddr)) {
721  continue;
722  }
723  ut64 at = rva(o, paddr, entry->vaddr, va);
724  const char *type = rz_bin_entry_type_string(entry->type);
725  if (!type) {
726  type = "unknown";
727  }
728  char str[RZ_FLAG_NAME_SIZE];
729  if (entry->type == RZ_BIN_ENTRY_TYPE_INIT) {
730  snprintf(str, RZ_FLAG_NAME_SIZE, "entry.init%i", init_i++);
731  } else if (entry->type == RZ_BIN_ENTRY_TYPE_FINI) {
732  snprintf(str, RZ_FLAG_NAME_SIZE, "entry.fini%i", fini_i++);
733  } else if (entry->type == RZ_BIN_ENTRY_TYPE_PREINIT) {
734  snprintf(str, RZ_FLAG_NAME_SIZE, "entry.preinit%i", preinit_i++);
735  } else {
736  snprintf(str, RZ_FLAG_NAME_SIZE, "entry%i", i++);
737  }
738  rz_flag_set(core->flags, str, at, 1);
739  if (is_initfini(entry) && hvaddr != UT64_MAX) {
740  rz_meta_set(core->analysis, RZ_META_TYPE_DATA, hvaddr, entry->bits / 8, NULL);
741  }
742  }
743  rz_flag_space_pop(core->flags);
744  if (entry) {
745  ut64 at = rva(o, entry->paddr, entry->vaddr, va);
746  rz_core_seek(core, at, false);
747  }
748  return true;
749 }
750 
751 static RzIODesc *find_reusable_file(RzIO *io, RzCoreFile *cf, const char *uri, int perm) {
752  rz_return_val_if_fail(io && uri, NULL);
753 
754  if (!cf) {
755  // valid case, but then we can't reuse anything
756  return NULL;
757  }
758  void **it;
759  rz_pvector_foreach (&cf->extra_files, it) {
760  RzIODesc *desc = *it;
761  if (desc->perm == perm && !strcmp(desc->uri, uri)) {
762  return desc;
763  }
764  }
765  return NULL;
766 }
767 
770  rz_return_val_if_fail(io && map && map->vsize > map->psize, false);
771  bool reused = false;
772  ut64 gap = map->vsize - map->psize;
773  char *uri = rz_str_newf("null://%" PFMT64u, gap);
774  RzIOMap *iomap = NULL;
775  RzIODesc *desc = find_reusable_file(io, cf, uri, map->perm);
776  if (desc) {
777  iomap = rz_io_map_add_batch(io, desc->fd, desc->perm, 0LL, at, gap);
778  reused = true;
779  } else {
780  desc = rz_io_open_at(io, uri, map->perm, 0664, at, &iomap);
781  }
782  free(uri);
783  if (!desc) {
784  return false;
785  }
786  // check if the mapping failed
787  if (!iomap) {
788  if (!reused) {
790  }
791  return false;
792  }
793  if (cf) {
794  if (!reused) {
795  rz_pvector_push(&cf->extra_files, desc);
796  }
797  rz_pvector_push(&cf->maps, iomap);
798  }
799  // update the io map's name to refer to the bin map
800  if (map->name) {
801  free(iomap->name);
802  iomap->name = rz_str_newf("mmap.%s", map->name);
803  }
804  if (!iomap->user) {
805  iomap->user = rz_core_io_map_info_new(cf, map->perm);
806  }
807  return true;
808 }
809 
810 static void add_map(RzCore *core, RZ_NULLABLE RzCoreFile *cf, RzBinFile *bf, RzBinMap *map, ut64 addr, int fd) {
811  RzIODesc *io_desc = rz_io_desc_get(core->io, fd);
812  if (!io_desc || UT64_ADD_OVFCHK(map->psize, map->paddr) ||
813  UT64_ADD_OVFCHK(map->vsize, addr) || !map->vsize) {
814  return;
815  }
816 
817  ut64 size = map->vsize;
818  // if there is some part of the map that needs to be zeroed by the loader
819  // we add a null map that takes care of it
820  if (map->vsize > map->psize) {
821  if (!io_create_mem_map(core->io, cf, map, addr + map->psize)) {
822  return;
823  }
824  size = map->psize;
825  }
826 
827  // It's a valid case to have vsize > 0 and psize == 0, which just creates a map of zeroes.
828  if (!size) {
829  return;
830  }
831 
832  const char *prefix = "fmap";
833 
834  // open and use a different fd for virtual files
835  if (map->vfile_name) {
836  char *uri = rz_str_newf("vfile://%" PFMT32u "/%s", bf->id, map->vfile_name);
837  if (!uri) {
838  return;
839  }
840  ut32 perm = io_desc->perm;
841  RzIODesc *desc = find_reusable_file(core->io, cf, uri, perm);
842  if (!desc) {
843  desc = rz_io_open_nomap(core->io, uri, perm, 0664);
844  if (!desc) {
845  free(uri);
846  return;
847  } else if (cf && !rz_pvector_push(&cf->extra_files, desc)) {
848  free(uri);
849  return;
850  }
851  }
852  free(uri);
853  fd = desc->fd;
854  prefix = "vmap";
855  }
856 
857  // then we map the part of the section that comes from the physical (or virtual) file
858  char *map_name = map->name ? rz_str_newf("%s.%s", prefix, map->name) : rz_str_newf("%s.%d", prefix, fd);
859  if (!map_name) {
860  return;
861  }
862 
863  int perm = map->perm;
864  // workaround to force exec bit in text section
865  if (map->name && strstr(map->name, "text")) {
866  perm |= RZ_PERM_X;
867  }
868 
869  if (size) {
870  RzIOMap *iomap = rz_io_map_add_batch(core->io, fd, perm, map->paddr, addr, size);
871  if (!iomap) {
872  free(map_name);
873  return;
874  }
875  iomap->user = rz_core_io_map_info_new(cf, perm);
876  free(iomap->name);
877  iomap->name = map_name;
878  if (cf) {
879  rz_pvector_push(&cf->maps, iomap);
880  }
881  } else {
882  free(map_name);
883  }
884  return;
885 }
886 
887 RZ_API bool rz_core_bin_apply_maps(RzCore *core, RzBinFile *binfile, bool va) {
888  rz_return_val_if_fail(core && binfile, false);
889  RzIODesc *desc = rz_io_desc_get(core->io, binfile->fd);
890  if (desc && rz_io_desc_is_dbg(desc)) {
891  // In debug mode, mapping comes from the process, not the file
892  return true;
893  }
894  RzBinObject *o = binfile->o;
895  if (!o || !o->maps) {
896  return false;
897  }
898  RzList *maps = o->maps;
899  RzCoreFile *cf = rz_core_file_find_by_fd(core, binfile->fd);
900 
901  RzListIter *it;
902  RzBinMap *map;
903  rz_list_foreach (maps, it, map) {
904  int va_map = va ? VA_TRUE : VA_FALSE;
905  if (va && !(map->perm & RZ_PERM_R)) {
906  va_map = VA_NOREBASE;
907  }
908  ut64 addr = rva(o, map->paddr, map->vaddr, va_map);
909  add_map(core, cf, binfile, map, addr, binfile->fd);
910  }
911  return true;
912 }
913 
918 static void section_perms_str(char *dst, int perms) {
919  dst[0] = (perms & RZ_PERM_SHAR) ? 's' : '-';
920  dst[1] = (perms & RZ_PERM_R) ? 'r' : '-';
921  dst[2] = (perms & RZ_PERM_W) ? 'w' : '-';
922  dst[3] = (perms & RZ_PERM_X) ? 'x' : '-';
923  dst[4] = '\0';
924 }
925 
926 RZ_API bool rz_core_bin_apply_sections(RzCore *core, RzBinFile *binfile, bool va) {
927  rz_return_val_if_fail(core && binfile, false);
928  RzBinObject *o = binfile->o;
929  if (!o) {
930  return false;
931  }
932  RzList *sections = o->sections;
933 
934  // make sure both flag spaces exist.
935  rz_flag_space_push(core->flags, RZ_FLAGS_FS_SEGMENTS);
936  rz_flag_space_set(core->flags, RZ_FLAGS_FS_SECTIONS);
937 
938  bool segments_only = true;
939  RzListIter *iter;
941  rz_list_foreach (sections, iter, section) {
942  if (!section->is_segment) {
943  segments_only = false;
944  break;
945  }
946  }
947 
948  int section_index = 0;
949  rz_list_foreach (sections, iter, section) {
950  int va_sect = va ? VA_TRUE : VA_FALSE;
951  if (va && !(section->perm & RZ_PERM_R)) {
952  va_sect = VA_NOREBASE;
953  }
954  if (is_invalid_address_va2(va_sect, section->vaddr, section->paddr)) {
955  continue;
956  }
957  ut64 addr = rva(o, section->paddr, section->vaddr, va_sect);
958 
959  rz_name_filter(section->name, strlen(section->name) + 1, false);
960 
961  char perms[5];
962  section_perms_str(perms, section->perm);
963  if (section->format) {
964  // This is really slow if section vsize is HUGE
965  if (section->vsize < 1024 * 1024 * 2) {
966  rz_core_cmdf(core, "%s @ 0x%" PFMT64x, section->format, section->vaddr);
967  }
968  }
969  const char *type;
970  if (section->is_segment) {
971  type = "segment";
972  rz_flag_space_set(core->flags, RZ_FLAGS_FS_SEGMENTS);
973  } else {
974  type = "section";
975  rz_flag_space_set(core->flags, RZ_FLAGS_FS_SECTIONS);
976  }
977  char *str;
978  if (core->bin->prefix) {
979  str = rz_str_newf("%s.%s.%s", core->bin->prefix, type, section->name);
980  } else {
981  str = rz_str_newf("%s.%s", type, section->name);
982  }
983  ut64 size = core->io->va ? section->vsize : section->size;
984  rz_flag_set(core->flags, str, addr, size);
985  RZ_FREE(str);
986 
987  if (!section->is_segment || segments_only) {
988  char *pfx = core->bin->prefix;
989  str = rz_str_newf("[%02d] %s %s size %" PFMT64d " named %s%s%s",
990  section_index++, perms, type, size,
991  pfx ? pfx : "", pfx ? "." : "", section->name);
993  RZ_FREE(str);
994  }
995  }
996  rz_flag_space_pop(core->flags);
997 
998  return true;
999 }
1000 
1001 /*
1002  * Decide whether a meta item should be created for the given reloc addr
1003  * and figure out what size it should have.
1004  * \return whether to put a meta item for the given reloc addr
1005  */
1006 static bool meta_for_reloc(RzCore *r, RzBinObject *binobj, RzBinReloc *reloc, bool is_target, ut64 addr, RZ_OUT ut64 *size) {
1007  rz_return_val_if_fail(binobj, false);
1008  RzBinInfo *info = binobj ? binobj->info : NULL;
1009 
1010  int cdsz;
1011  if (is_target) {
1012  // target meta uses the bit size, these are the manually created ones
1013  cdsz = info ? (info->bits / 8) : 0;
1014  } else {
1015  // source meta uses the actual size of the reloc
1016  cdsz = rz_bin_reloc_size(reloc) / 8;
1017  }
1018  if (cdsz <= 0) {
1019  return false;
1020  }
1021 
1022  // only set meta if it's not in an executable section
1023  RzIOMap *map = rz_io_map_get(r->io, addr);
1024  if (!map || map->perm & RZ_PERM_X) {
1025  return false;
1026  }
1027 
1028  *size = cdsz;
1029  return true;
1030 }
1031 
1033  /* workaround for some bin plugs (e.g. ELF) */
1034  if (!s || *s->name) {
1035  return false;
1036  }
1037  return (s->type && !strcmp(s->type, RZ_BIN_TYPE_SECTION_STR));
1038 }
1039 
1041  return s->type && !strcmp(s->type, RZ_BIN_TYPE_SPECIAL_SYM_STR);
1042 }
1043 
1045  /* workaround for some bin plugs (e.g. ELF) */
1046  return (s && s->type && !strcmp(s->type, RZ_BIN_TYPE_FILE_STR));
1047 }
1048 
1050  return is_section_symbol(r->symbol);
1051 }
1052 
1053 static bool is_file_reloc(RzBinReloc *r) {
1054  return is_file_symbol(r->symbol);
1055 }
1056 
1058 #define CASE(T) \
1059  case RZ_BIN_RELOC_##T: return (T) / 8
1060  switch (reloc->type) {
1061  CASE(8);
1062  CASE(16);
1063  CASE(24);
1064  CASE(32);
1065  CASE(64);
1066  }
1067  return 0;
1068 #undef CASE
1069 }
1070 
1071 static char *resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal) {
1072  Sdb *db = sdb;
1073  char *foo = sdb_get(db, sdb_fmt("%d", ordinal), 0);
1074  return (foo && *foo) ? foo : NULL;
1075 }
1076 
1077 // name can be optionally used to explicitly set the used base name (for example for demangling), otherwise the import name will be used.
1078 static char *construct_reloc_name(RZ_NONNULL RzBinReloc *reloc, RZ_NULLABLE const char *name) {
1079  RzStrBuf *buf = rz_strbuf_new("");
1080 
1081  // (optional) libname_
1082  if (reloc->import && reloc->import->libname) {
1083  rz_strbuf_appendf(buf, "%s_", reloc->import->libname);
1084  } else if (reloc->symbol && reloc->symbol->libname) {
1085  rz_strbuf_appendf(buf, "%s_", reloc->symbol->libname);
1086  }
1087 
1088  // actual name
1089  if (name) {
1091  } else if (reloc->import && reloc->import->name && *reloc->import->name) {
1092  rz_strbuf_append(buf, reloc->import->name);
1093  } else if (reloc->symbol && reloc->symbol->name && *reloc->symbol->name) {
1094  rz_strbuf_appendf(buf, "%s", reloc->symbol->name);
1095  } else if (reloc->is_ifunc) {
1096  // addend is the function pointer for the resolving ifunc
1097  rz_strbuf_appendf(buf, "ifunc_%" PFMT64x, reloc->addend);
1098  } else {
1099  rz_strbuf_set(buf, "");
1100  }
1101 
1102  return rz_strbuf_drain(buf);
1103 }
1104 
1105 static void reloc_set_flag(RzCore *r, RzBinReloc *reloc, const char *prefix, ut64 flag_addr) {
1106  int bin_demangle = rz_config_get_i(r->config, "bin.demangle");
1107  bool keep_lib = rz_config_get_i(r->config, "bin.demangle.libs");
1108  const char *lang = rz_config_get(r->config, "bin.lang");
1109  char *reloc_name = construct_reloc_name(reloc, NULL);
1110  if (RZ_STR_ISEMPTY(reloc_name)) {
1111  free(reloc_name);
1112  return;
1113  }
1114  char flagname[RZ_FLAG_NAME_SIZE];
1115  if (r->bin->prefix) {
1116  snprintf(flagname, sizeof(flagname), "%s.%s.%s", r->bin->prefix, prefix, reloc_name);
1117  } else {
1118  snprintf(flagname, sizeof(flagname), "%s.%s", prefix, reloc_name);
1119  }
1120  char *demname = NULL;
1121  if (bin_demangle) {
1122  demname = rz_bin_demangle(r->bin->cur, lang, flagname, flag_addr, keep_lib);
1123  if (demname) {
1124  snprintf(flagname, sizeof(flagname), "reloc.%s", demname);
1125  }
1126  }
1127  rz_name_filter(flagname, 0, true);
1128  RzFlagItem *existing = rz_flag_get(r->flags, flagname);
1129  if (existing && existing->offset == flag_addr) {
1130  // Mostly important for target flags.
1131  // We don't want hundreds of reloc.target.<fcnname>.<xyz> flags at the same location
1132  return;
1133  }
1134  RzFlagItem *fi = rz_flag_set_next(r->flags, flagname, flag_addr, bin_reloc_size(reloc));
1135  if (demname) {
1136  rz_flag_item_set_realname(fi, demname);
1137  free(demname);
1138  } else {
1139  rz_flag_item_set_realname(fi, reloc_name);
1140  }
1141  free(reloc_name);
1142 }
1143 
1144 static void set_bin_relocs(RzCore *r, RzBinObject *o, RzBinReloc *reloc, bool va, Sdb **db, char **sdb_module) {
1145  bool is_pe = true;
1146 
1147  if (is_pe && reloc->import && reloc->import->name && reloc->import->libname && rz_str_startswith(reloc->import->name, "Ordinal_")) {
1148  char *module = reloc->import->libname;
1149  rz_str_case(module, false);
1150 
1151  // strip trailing ".dll"
1152  size_t module_len = strlen(module);
1153  if (module_len > 4 && !strcmp(module + module_len - 4, ".dll")) {
1154  module[module_len - 4] = '\0';
1155  }
1156 
1157  const char *import = reloc->import->name + strlen("Ordinal_");
1158  if (import) {
1159  char *filename = NULL;
1160  int ordinal = atoi(import);
1161  if (!*sdb_module || strcmp(module, *sdb_module)) {
1162  sdb_free(*db);
1163  *db = NULL;
1164  free(*sdb_module);
1165  *sdb_module = strdup(module);
1166  /* always lowercase */
1167  filename = rz_str_newf("%s.sdb", module);
1168  rz_str_case(filename, false);
1169  if (rz_file_exists(filename)) {
1170  *db = sdb_new(NULL, filename, 0);
1171  } else {
1172  char *formats_dir = rz_path_system(RZ_SDB_FORMAT);
1173  free(filename);
1174  filename = rz_str_newf(RZ_JOIN_3_PATHS("%s", "dll", "%s.sdb"), formats_dir, module);
1175  free(formats_dir);
1176  if (rz_file_exists(filename)) {
1177  *db = sdb_new(NULL, filename, 0);
1178  }
1179  }
1180  }
1181  if (*db) {
1182  // ordinal-1 because we enumerate starting at 0
1183  char *symname = resolveModuleOrdinal(*db, module, ordinal - 1); // uses sdb_get
1184  if (symname) {
1185  if (r->bin->prefix) {
1186  reloc->import->name = rz_str_newf("%s.%s", r->bin->prefix, symname);
1187  RZ_FREE(symname);
1188  } else {
1189  reloc->import->name = symname;
1190  }
1191  }
1192  }
1193  free(filename);
1194  }
1195  rz_analysis_hint_set_size(r->analysis, reloc->vaddr, 4);
1196  rz_meta_set(r->analysis, RZ_META_TYPE_DATA, reloc->vaddr, 4, NULL);
1197  }
1198 
1199  ut64 addr = rva(o, reloc->paddr, reloc->vaddr, va);
1200  reloc_set_flag(r, reloc, "reloc", addr);
1201  if (rz_bin_reloc_has_target(reloc)) {
1202  reloc_set_flag(r, reloc, "reloc.target", reloc->target_vaddr);
1203  }
1204 }
1205 
1206 RZ_API bool rz_core_bin_apply_relocs(RzCore *core, RzBinFile *binfile, bool va_bool) {
1207  rz_return_val_if_fail(core && binfile, false);
1208  RzBinObject *o = binfile->o;
1209  if (!o) {
1210  return false;
1211  }
1212 
1213  int va = VA_TRUE; // XXX relocs always vaddr?
1215  if (!relocs) {
1216  relocs = o->relocs;
1217  if (!relocs) {
1218  return false;
1219  }
1220  }
1221 
1222  rz_flag_space_push(core->flags, RZ_FLAGS_FS_RELOCS);
1223 
1224  Sdb *db = NULL;
1225  char *sdb_module = NULL;
1226  for (size_t i = 0; i < relocs->relocs_count; i++) {
1227  RzBinReloc *reloc = relocs->relocs[i];
1228  if (is_invalid_address_va(va, reloc->vaddr, reloc->paddr)) {
1229  continue;
1230  }
1231  ut64 addr = rva(o, reloc->paddr, reloc->vaddr, va);
1232  if ((is_section_reloc(reloc) || is_file_reloc(reloc))) {
1233  /*
1234  * Skip section reloc because they will have their own flag.
1235  * Skip also file reloc because not useful for now.
1236  */
1237  continue;
1238  }
1239  set_bin_relocs(core, o, reloc, va, &db, &sdb_module);
1240  ut64 meta_sz;
1241  if (meta_for_reloc(core, o, reloc, false, addr, &meta_sz)) {
1242  rz_meta_set(core->analysis, RZ_META_TYPE_DATA, addr, meta_sz, NULL);
1243  }
1244  if (va && rz_bin_reloc_has_target(reloc) && meta_for_reloc(core, o, reloc, true, reloc->target_vaddr, &meta_sz)) {
1245  rz_meta_set(core->analysis, RZ_META_TYPE_DATA, reloc->target_vaddr, meta_sz, NULL);
1246  }
1247  }
1248  RZ_FREE(sdb_module);
1249  sdb_free(db);
1250  rz_flag_space_pop(core->flags);
1251 
1252  return relocs != NULL;
1253 }
1254 
1255 RZ_API bool rz_core_bin_apply_imports(RzCore *core, RzBinFile *binfile, bool va) {
1256  rz_return_val_if_fail(core && binfile, false);
1257  RzBinObject *o = binfile->o;
1258  RzBinInfo *info = o ? o->info : NULL;
1259  if (!info) {
1260  return false;
1261  }
1262  int cdsz = info->bits / 8;
1263  if (cdsz <= 0) {
1264  return false;
1265  }
1266  RzListIter *iter;
1267  RzBinImport *import;
1268  RzList *imports = o->imports;
1269  rz_list_foreach (imports, iter, import) {
1270  if (!import->libname || !strstr(import->libname, ".dll")) {
1271  continue;
1272  }
1274  if (!sym) {
1275  continue;
1276  }
1277  if (is_invalid_address_va(va, sym->vaddr, sym->paddr)) {
1278  continue;
1279  }
1280  ut64 addr = rva(o, sym->paddr, sym->vaddr, va ? VA_TRUE : VA_FALSE);
1282  }
1283  return true;
1284 }
1285 
1286 static const char *get_prefix_for_sym(RzBinSymbol *sym) {
1287  if (sym) {
1288  // workaround for ELF
1289  if (sym->type) {
1290  if (!strcmp(sym->type, RZ_BIN_TYPE_NOTYPE_STR)) {
1291  return sym->is_imported ? "loc.imp" : "loc";
1292  }
1293  if (!strcmp(sym->type, RZ_BIN_TYPE_OBJECT_STR)) {
1294  return sym->is_imported ? "obj.imp" : "obj";
1295  }
1296  }
1297  return sym->is_imported ? "sym.imp" : "sym";
1298  }
1299  return "sym";
1300 }
1301 
1302 #define MAXFLAG_LEN_DEFAULT 128
1303 
1304 static char *construct_symbol_flagname(const char *pfx, const char *libname, const char *symname, int len) {
1305  char *r = rz_str_newf("%s.%s%s%s", pfx, libname ? libname : "", libname ? "_" : "", symname);
1306  if (!r) {
1307  return NULL;
1308  }
1309  rz_name_filter(r, len, true); // maybe unnecessary..
1310  char *R = __filterQuotedShell(r);
1311  free(r);
1312  return R;
1313 }
1314 
1323  rz_return_if_fail(r && sym && sym->name);
1324 
1325  bool demangle = rz_config_get_b(r->config, "bin.demangle");
1326  bool keep_lib = rz_config_get_b(r->config, "bin.demangle.libs");
1327 
1328  const char *name = sym->dname && demangle ? sym->dname : sym->name;
1329  sn->name = rz_str_newf("%s%s", sym->is_imported ? "imp." : "", name);
1330  sn->libname = sym->libname ? strdup(sym->libname) : NULL;
1331  const char *pfx = get_prefix_for_sym(sym);
1332  sn->nameflag = construct_symbol_flagname(pfx, sym->libname, rz_bin_symbol_name(sym), MAXFLAG_LEN_DEFAULT);
1333  if (sym->classname && sym->classname[0]) {
1334  sn->classname = strdup(sym->classname);
1335  sn->classflag = rz_str_newf("sym.%s.%s", sn->classname, sn->name);
1336  rz_name_filter(sn->classflag, MAXFLAG_LEN_DEFAULT, true);
1337  sn->methname = rz_str_newf("%s::%s", sn->classname, name);
1338  sn->methflag = rz_str_newf("sym.%s.%s", sn->classname, name);
1339  rz_name_filter(sn->methflag, strlen(sn->methflag), true);
1340  } else {
1341  sn->classname = NULL;
1342  sn->classflag = NULL;
1343  sn->methname = NULL;
1344  sn->methflag = NULL;
1345  }
1346  sn->demname = NULL;
1347  sn->demflag = NULL;
1348  if (demangle && sym->paddr && lang) {
1349  sn->demname = rz_bin_demangle(r->bin->cur, lang, sn->name, sym->vaddr, keep_lib);
1350  if (sn->demname) {
1351  sn->demflag = construct_symbol_flagname(pfx, sym->libname, sn->demname, -1);
1352  }
1353  }
1354 
1355  RzStrEscOptions opt = {
1356  .show_asciidot = false,
1357  .esc_bslash = true,
1358  };
1359  sn->symbolname = rz_str_escape_utf8(sn->demname ? sn->demname : sn->name, &opt);
1360  if (r->bin->prefix) {
1361  char *tmp = rz_str_newf("%s.%s", r->bin->prefix, sn->symbolname);
1362  free(sn->symbolname);
1363  sn->symbolname = tmp;
1364  }
1365 }
1366 
1372  if (!sn) {
1373  return;
1374  }
1375  RZ_FREE(sn->name);
1376  RZ_FREE(sn->symbolname);
1377  RZ_FREE(sn->libname);
1378  RZ_FREE(sn->nameflag);
1379  RZ_FREE(sn->demname);
1380  RZ_FREE(sn->demflag);
1381  RZ_FREE(sn->classname);
1382  RZ_FREE(sn->classflag);
1383  RZ_FREE(sn->methname);
1384  RZ_FREE(sn->methflag);
1385 }
1386 
1387 static void handle_arm_special_symbol(RzCore *core, RzBinObject *o, RzBinSymbol *symbol, int va) {
1388  ut64 addr = rva(o, symbol->paddr, symbol->vaddr, va);
1389  if (!strcmp(symbol->name, "$a")) {
1391  } else if (!strcmp(symbol->name, "$x")) {
1393  } else if (!strcmp(symbol->name, "$t")) {
1395  } else if (!strcmp(symbol->name, "$d")) {
1396  // TODO: we could add data meta type at addr, but sometimes $d
1397  // is in the middle of the code and it would make the code less
1398  // readable.
1399  } else {
1400  if (core->bin->verbose) {
1401  RZ_LOG_WARN("Special symbol %s not handled\n", symbol->name);
1402  }
1403  }
1404 }
1405 
1406 static void handle_arm_hint(RzCore *core, RzBinObject *o, ut64 paddr, ut64 vaddr, int bits, int va) {
1407  RzBinInfo *info = o->info;
1408  if (!info) {
1409  return;
1410  }
1411  if (info->bits > 32) { // we look at 16 or 32 bit only
1412  return;
1413  }
1414 
1415  int force_bits = 0;
1416  ut64 addr = rva(o, paddr, vaddr, va);
1417  if (paddr & 1 || bits == 16) {
1418  force_bits = 16;
1419  } else if (info->bits == 16 && bits == 32) {
1420  force_bits = 32;
1421  } else if (!(paddr & 1) && bits == 32) {
1422  force_bits = 32;
1423  }
1424  if (force_bits) {
1425  rz_analysis_hint_set_bits(core->analysis, addr, force_bits);
1426  }
1427 }
1428 
1429 static void handle_arm_symbol(RzCore *core, RzBinObject *o, RzBinSymbol *symbol, int va) {
1430  handle_arm_hint(core, o, symbol->paddr, symbol->vaddr, symbol->bits, va);
1431 }
1432 
1433 static void handle_arm_entry(RzCore *core, RzBinObject *o, RzBinAddr *entry, int va) {
1434  handle_arm_hint(core, o, entry->paddr, entry->vaddr, entry->bits, va);
1435 }
1436 
1437 static void select_flag_space(RzCore *core, RzBinSymbol *symbol) {
1438  if (symbol->is_imported) {
1439  rz_flag_space_push(core->flags, RZ_FLAGS_FS_IMPORTS);
1440  } else if (symbol->type && !strcmp(symbol->type, RZ_BIN_TYPE_SECTION_STR)) {
1441  rz_flag_space_push(core->flags, RZ_FLAGS_FS_SYMBOLS_SECTIONS);
1442  } else {
1443  rz_flag_space_push(core->flags, RZ_FLAGS_FS_SYMBOLS);
1444  }
1445 }
1446 
1447 RZ_API bool rz_core_bin_apply_symbols(RzCore *core, RzBinFile *binfile, bool va) {
1448  rz_return_val_if_fail(core && binfile, false);
1449  RzBinObject *o = binfile->o;
1450  if (!o || !o->info) {
1451  return false;
1452  }
1453  RzBinInfo *info = o->info;
1454 
1455  bool is_arm = info && info->arch && !strncmp(info->arch, "arm", 3);
1456  bool bin_demangle = rz_config_get_b(core->config, "bin.demangle");
1457  const char *lang = bin_demangle ? rz_config_get(core->config, "bin.lang") : NULL;
1458 
1459  rz_spaces_push(&core->analysis->meta_spaces, "bin");
1460  rz_flag_space_push(core->flags, RZ_FLAGS_FS_SYMBOLS);
1461 
1463  size_t count = 0;
1464  RzListIter *iter;
1465  RzBinSymbol *symbol;
1466  rz_list_foreach (symbols, iter, symbol) {
1467  if (!symbol->name) {
1468  continue;
1469  }
1470  if (is_invalid_address_va(va, symbol->vaddr, symbol->paddr)) {
1471  continue;
1472  }
1473  ut64 addr = rva(o, symbol->paddr, symbol->vaddr, va);
1474  RzBinSymNames sn = { 0 };
1475  count++;
1476  rz_core_sym_name_init(core, &sn, symbol, lang);
1477 
1478  if (is_section_symbol(symbol) || is_file_symbol(symbol)) {
1479  /*
1480  * Skip section symbols because they will have their own flag.
1481  * Skip also file symbols because not useful for now.
1482  */
1483  } else if (is_special_symbol(symbol)) {
1484  if (is_arm) {
1485  handle_arm_special_symbol(core, o, symbol, va);
1486  }
1487  } else {
1488  // TODO: provide separate API in RzBinPlugin to let plugins handle analysis hints/metadata
1489  if (is_arm) {
1490  handle_arm_symbol(core, o, symbol, va);
1491  }
1492  select_flag_space(core, symbol);
1493  /* If that's a Classed symbol (method or so) */
1494  if (sn.classname) {
1495  RzFlagItem *fi = rz_flag_get(core->flags, sn.methflag);
1496  if (core->bin->prefix) {
1497  char *prname = rz_str_newf("%s.%s", core->bin->prefix, sn.methflag);
1498  rz_name_filter(sn.methflag, -1, true);
1499  free(sn.methflag);
1500  sn.methflag = prname;
1501  }
1502  if (fi) {
1504  if ((fi->offset - core->flags->base) == addr) {
1505  rz_flag_unset(core->flags, fi);
1506  }
1507  } else {
1508  fi = rz_flag_set(core->flags, sn.methflag, addr, symbol->size);
1509  char *comment = (fi && fi->comment) ? strdup(fi->comment) : NULL;
1510  if (comment) {
1511  rz_flag_item_set_comment(fi, comment);
1512  RZ_FREE(comment);
1513  }
1514  }
1515  } else {
1516  const char *n = sn.demname ? sn.demname : symbol->name;
1517  const char *fn = sn.demflag ? sn.demflag : sn.nameflag;
1518  char *fnp = (core->bin->prefix) ? rz_str_newf("%s.%s", core->bin->prefix, fn) : strdup(fn ? fn : "");
1519  RzFlagItem *fi = rz_flag_set(core->flags, fnp, addr, symbol->size);
1520  if (fi) {
1522  fi->demangled = (bool)(size_t)sn.demname;
1523  } else {
1524  if (fn) {
1525  eprintf("[Warning] Can't find flag (%s)\n", fn);
1526  }
1527  }
1528  free(fnp);
1529  }
1530  if (sn.demname) {
1531  ut64 size = symbol->size ? symbol->size : 1;
1533  }
1534  rz_flag_space_pop(core->flags);
1535  }
1536  rz_core_sym_name_fini(&sn);
1537  }
1538 
1539  // handle thumb and arm for entry point since they are not present in symbols
1540  if (is_arm) {
1541  RzBinAddr *entry;
1542  rz_list_foreach (o->entries, iter, entry) {
1543  handle_arm_entry(core, o, entry, va);
1544  }
1545  }
1546 
1548  rz_flag_space_pop(core->flags);
1549  return true;
1550 }
1551 
1553  rz_return_val_if_fail(core && binfile, false);
1554  RzBinObject *o = binfile->o;
1555  RzList *cs = o ? o->classes : NULL;
1556  if (!cs) {
1557  return false;
1558  }
1559  if (!rz_config_get_b(core->config, "bin.classes")) {
1560  return false;
1561  }
1562 
1563  rz_flag_space_push(core->flags, RZ_FLAGS_FS_CLASSES);
1564 
1565  RzListIter *iter;
1566  RzBinClass *c;
1567  rz_list_foreach (cs, iter, c) {
1568  if (!c || !c->name || !c->name[0]) {
1569  continue;
1570  }
1571 
1572  // set class flag
1573  char *classname = rz_str_newf("class.%s", c->name);
1574  if (!classname) {
1575  break;
1576  }
1577  rz_name_filter(classname, 0, true);
1578  rz_flag_set(core->flags, classname, c->addr, 1);
1579  free(classname);
1580 
1581  // set method flags
1582  RzBinSymbol *sym;
1583  RzListIter *iter2;
1584  rz_list_foreach (c->methods, iter2, sym) {
1585  char *fn = rz_core_bin_method_build_flag_name(c, sym);
1586  if (fn) {
1587  rz_flag_set(core->flags, fn, sym->vaddr, 1);
1588  free(fn);
1589  }
1590  }
1591  }
1592  rz_flag_space_pop(core->flags);
1593  return true;
1594 }
1595 
1597  rz_return_val_if_fail(core && binfile, false);
1598  RzBinObject *o = binfile->o;
1599  RzBinInfo *info = o ? o->info : NULL;
1600  if (!info || !info->rclass) {
1601  return false;
1602  }
1603  if (strncmp("pe", info->rclass, 2)) {
1604  // only pe will be applied for now
1605  return true;
1606  }
1607  Sdb *sdb = NULL;
1608  int index = 0;
1609  const char *pe_path = "bin/cur/info/pe_resource";
1610  if (!(sdb = sdb_ns_path(core->sdb, pe_path, 0))) {
1611  return false;
1612  }
1613  rz_flag_space_push(core->flags, RZ_FLAGS_FS_RESOURCES);
1614  while (true) {
1615  char key[64];
1616  char *timestr = sdb_get(sdb, rz_strf(key, "resource.%d.timestr", index), 0);
1617  if (!timestr) {
1618  break;
1619  }
1620  ut64 vaddr = sdb_num_get(sdb, rz_strf(key, "resource.%d.vaddr", index), 0);
1621  int size = (int)sdb_num_get(sdb, rz_strf(key, "resource.%d.size", index), 0);
1622  rz_flag_set(core->flags, rz_strf(key, "resource.%d", index), vaddr, size);
1623  index++;
1624  }
1625  rz_flag_space_pop(core->flags);
1626  return true;
1627 }
1628 
1629 static void digests_ht_free(HtPPKv *kv) {
1630  free(kv->key);
1631  free(kv->value);
1632 }
1633 
1641 RZ_API RZ_OWN HtPP *rz_core_bin_create_digests(RzCore *core, ut64 paddr, ut64 size, RzList /*<char *>*/ *digests) {
1642  rz_return_val_if_fail(size && digests, NULL);
1643  HtPP *r = ht_pp_new(NULL, digests_ht_free, NULL);
1644  if (!r) {
1645  return NULL;
1646  }
1647  RzListIter *it;
1648  char *digest;
1649  rz_list_foreach (digests, it, digest) {
1650  ut8 *data = malloc(size);
1651  if (!data) {
1652  ht_pp_free(r);
1653  return NULL;
1654  }
1655  rz_io_pread_at(core->io, paddr, data, size);
1656  char *chkstr = rz_hash_cfg_calculate_small_block_string(core->hash, digest, data, size, NULL, false);
1657  if (!chkstr) {
1658  continue;
1659  }
1660  ht_pp_insert(r, digest, chkstr);
1661  free(data);
1662  }
1663 
1664  return r;
1665 }
1666 
1674  rz_return_val_if_fail(core && core->bin, false);
1675  if (!binfile) {
1676  // Find first available binfile
1677  ut32 fd = rz_core_file_cur_fd(core);
1678  binfile = fd != (ut32)-1
1679  ? rz_bin_file_find_by_fd(core->bin, fd)
1680  : NULL;
1681  if (!binfile) {
1682  return false;
1683  }
1684  }
1685  rz_bin_file_set_cur_binfile(core->bin, binfile);
1686  return true;
1687 }
1688 
1693  rz_return_val_if_fail(r && file, false);
1695  if (!plugin || !rz_config_get_i(r->config, "bin.strings")) {
1696  return NULL;
1697  }
1698  if (plugin->name && !strcmp(plugin->name, "any")) {
1699  return NULL;
1700  }
1701  return rz_bin_get_strings(r->bin);
1702 }
1703 
1708  rz_return_val_if_fail(bf && bf->sdb, NULL);
1709  Sdb *binFileSdb = bf->sdb;
1710  Sdb *info_ns = sdb_ns(binFileSdb, "info", false);
1711  const char *timeDateStamp_string = sdb_const_get(info_ns,
1712  "image_file_header.TimeDateStamp_string", 0);
1713  return timeDateStamp_string;
1714 }
1715 
1716 static bool is_executable(RzBinObject *obj) {
1717  RzListIter *it;
1718  RzBinSection *sec;
1719  rz_return_val_if_fail(obj, false);
1720  if (obj->info && obj->info->arch) {
1721  return true;
1722  }
1723  rz_list_foreach (obj->sections, it, sec) {
1724  if (sec->perm & RZ_PERM_X) {
1725  return true;
1726  }
1727  }
1728  return false;
1729 }
1730 
1731 static bool bin_dwarf(RzCore *core, RzBinFile *binfile, RzCmdStateOutput *state) {
1732  rz_return_val_if_fail(core && binfile, false);
1733  if (!rz_config_get_i(core->config, "bin.dbginfo") || !binfile->o) {
1734  return false;
1735  }
1737  RzBinDwarfDebugInfo *info = da ? rz_bin_dwarf_parse_info(binfile, da) : NULL;
1738  if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
1739  if (da) {
1741  }
1742  if (info) {
1744  }
1745  }
1746  HtUP /*<offset, List *<LocListEntry>*/ *loc_table = rz_bin_dwarf_parse_loc(binfile, core->analysis->bits / 8);
1747  if (loc_table) {
1748  if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
1749  rz_core_bin_dwarf_print_loc(loc_table, core->analysis->bits / 8);
1750  }
1751  rz_bin_dwarf_loc_free(loc_table);
1752  }
1753  if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
1754  RzList *aranges = rz_bin_dwarf_parse_aranges(binfile);
1755  if (aranges) {
1757  rz_list_free(aranges);
1758  }
1759  }
1760  bool ret = false;
1764  if (lines) {
1765  if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
1767  }
1768  if (lines->lines) {
1769  ret = true;
1771  }
1773  }
1775  return ret;
1776 }
1777 
1779  rz_return_if_fail(core && s && state);
1780  if (state->mode == RZ_OUTPUT_MODE_JSON) {
1781  bool chopPath = !rz_config_get_i(core->config, "dir.dwarf.abspath");
1782  char *file = s->file ? strdup(s->file) : NULL;
1783  if (chopPath && file) {
1784  const char *slash = rz_str_lchr(file, '/');
1785  if (slash) {
1786  memmove(file, slash + 1, strlen(slash));
1787  }
1788  }
1789  pj_o(state->d.pj);
1790  if (file) {
1791  pj_ks(state->d.pj, "file", file);
1792  }
1793  pj_kn(state->d.pj, "line", (ut64)s->line);
1794  if (s->column) {
1795  pj_kn(state->d.pj, "column", (ut64)s->column);
1796  }
1797  pj_kn(state->d.pj, "addr", s->address);
1798  pj_end(state->d.pj);
1799  free(file);
1800  } else {
1801  rz_cons_printf("0x%08" PFMT64x "\t%s\t",
1802  s->address, s->file ? s->file : "-");
1803  if (s->line) {
1804  rz_cons_printf("%" PFMT32u "\n", s->line);
1805  } else {
1806  rz_cons_print("-\n");
1807  }
1808  }
1809 }
1810 
1812  rz_return_if_fail(core && li && state);
1815  for (size_t i = 0; i < li->samples_count; i++) {
1816  if (rz_cons_is_breaked()) {
1817  break;
1818  }
1820  }
1823 }
1824 
1825 static const char *bin_reloc_type_name(RzBinReloc *reloc) {
1826 #define CASE(T) \
1827  case RZ_BIN_RELOC_##T: return reloc->additive ? "ADD_" #T : "SET_" #T
1828  switch (reloc->type) {
1829  CASE(8);
1830  CASE(16);
1831  CASE(24);
1832  CASE(32);
1833  CASE(64);
1834  }
1835  return "UNKNOWN";
1836 #undef CASE
1837 }
1838 
1839 static bool entries_initfini_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state, bool initfini) {
1840  RzBinObject *o = bf->o;
1842  RzListIter *iter;
1843  RzBinAddr *entry = NULL;
1844  ut64 baddr = rz_bin_get_baddr(core->bin);
1845  ut64 laddr = rz_bin_get_laddr(core->bin);
1846  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
1847 
1849  rz_cmd_state_output_set_columnsf(state, "XXXXs", "vaddr", "paddr", "hvaddr", "haddr", "type");
1850 
1851  rz_list_foreach (entries, iter, entry) {
1852  ut64 paddr = entry->paddr;
1853  ut64 hpaddr = UT64_MAX;
1854  ut64 hvaddr = UT64_MAX;
1855  if (!initfini && entry->type != RZ_BIN_ENTRY_TYPE_PROGRAM) {
1856  continue;
1857  } else if (initfini && entry->type == RZ_BIN_ENTRY_TYPE_PROGRAM) {
1858  continue;
1859  }
1860  if (entry->hpaddr) {
1861  hpaddr = entry->hpaddr;
1862  if (entry->hvaddr) {
1863  hvaddr = rva(o, hpaddr, entry->hvaddr, va);
1864  }
1865  }
1866  ut64 at = rva(o, paddr, entry->vaddr, va);
1867  const char *type = rz_bin_entry_type_string(entry->type);
1868  if (!type) {
1869  type = "unknown";
1870  }
1871  switch (state->mode) {
1872  case RZ_OUTPUT_MODE_QUIET:
1873  rz_cons_printf("0x%08" PFMT64x "\n", at);
1874  break;
1875  case RZ_OUTPUT_MODE_JSON:
1876  pj_o(state->d.pj);
1877  pj_kn(state->d.pj, "vaddr", at);
1878  pj_kn(state->d.pj, "paddr", paddr);
1879  pj_kn(state->d.pj, "baddr", baddr);
1880  pj_kn(state->d.pj, "laddr", laddr);
1881  if (hvaddr != UT64_MAX) {
1882  pj_kn(state->d.pj, "hvaddr", hvaddr);
1883  }
1884  pj_kn(state->d.pj, "haddr", hpaddr);
1885  pj_ks(state->d.pj, "type", type);
1886  pj_end(state->d.pj);
1887  break;
1888  case RZ_OUTPUT_MODE_TABLE:
1889  rz_table_add_rowf(state->d.t, "XXXXs", at, paddr, hvaddr, hpaddr, type);
1890  break;
1891  default:
1893  break;
1894  }
1895  }
1896 
1898  return true;
1899 }
1900 
1902  rz_return_val_if_fail(core && state, false);
1903 
1904  return entries_initfini_print(core, bf, state, true);
1905 }
1906 
1908  rz_return_val_if_fail(core && state, false);
1909 
1910  return entries_initfini_print(core, bf, state, false);
1911 }
1912 
1917  rz_return_val_if_fail(s, false);
1918  /* workaround for some RzBinPlugins */
1919  if (s->is_imported) {
1920  return false;
1921  }
1922  return (s->bind && !strcmp(s->bind, RZ_BIN_BIND_GLOBAL_STR));
1923 }
1924 
1925 static bool is_in_symbol_range(ut64 sym_addr, ut64 sym_size, ut64 addr) {
1926  if (addr == sym_addr && sym_size == 0) {
1927  return true;
1928  }
1929  if (sym_size == 0) {
1930  return false;
1931  }
1932  return RZ_BETWEEN(sym_addr, addr, sym_addr + sym_size - 1);
1933 }
1934 
1935 static bool symbols_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state, RzCoreBinFilter *filter, bool only_export) {
1936  RzBinObject *o = bf->o;
1938  bool bin_demangle = rz_config_get_i(core->config, "bin.demangle");
1939  const char *lang = bin_demangle ? rz_config_get(core->config, "bin.lang") : NULL;
1940  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
1941  RzBinSymbol *symbol;
1942  RzListIter *iter;
1943 
1945  rz_cmd_state_output_set_columnsf(state, "dXXssnss", "nth", "paddr", "vaddr", "bind", "type", "size", "lib", "name");
1946 
1947  rz_list_foreach (symbols, iter, symbol) {
1948  if (!symbol->name) {
1949  continue;
1950  }
1951  if (only_export && !rz_core_sym_is_export(symbol)) {
1952  continue;
1953  }
1954  ut64 addr = rva(o, symbol->paddr, symbol->vaddr, va);
1955 
1956  if (filter && filter->offset != UT64_MAX) {
1957  if (!is_in_symbol_range(symbol->paddr, symbol->size, filter->offset) &&
1958  !is_in_symbol_range(addr, symbol->size, filter->offset)) {
1959  continue;
1960  }
1961  }
1962  if (filter && filter->name && strcmp(symbol->name, filter->name)) {
1963  continue;
1964  }
1965 
1966  RzBinSymNames sn = { 0 };
1967  rz_core_sym_name_init(core, &sn, symbol, lang);
1968  ut64 size = symbol->size;
1969 
1970  char addr_value[20];
1971  if (addr == UT64_MAX) {
1972  rz_strf(addr_value, "----------");
1973  } else {
1974  rz_strf(addr_value, "0x%08" PFMT64x, addr);
1975  }
1976 
1977  switch (state->mode) {
1978  case RZ_OUTPUT_MODE_QUIET:
1979  rz_cons_printf("%s %" PFMT64u " %s%s%s\n",
1980  addr_value, size,
1981  sn.libname ? sn.libname : "", sn.libname ? " " : "",
1982  sn.symbolname);
1983  break;
1985  rz_cons_printf("%s\n", sn.symbolname);
1986  break;
1987  case RZ_OUTPUT_MODE_JSON:
1988  pj_o(state->d.pj);
1989  pj_ks(state->d.pj, "name", sn.symbolname);
1990  if (sn.demname) {
1991  pj_ks(state->d.pj, "demname", sn.demname);
1992  }
1993  pj_ks(state->d.pj, "flagname", sn.nameflag);
1994  pj_ks(state->d.pj, "realname", symbol->name);
1995  pj_ki(state->d.pj, "ordinal", symbol->ordinal);
1996  pj_ks(state->d.pj, "bind", symbol->bind);
1997  pj_kn(state->d.pj, "size", size);
1998  pj_ks(state->d.pj, "type", symbol->type);
1999  if (addr != UT64_MAX) {
2000  pj_kn(state->d.pj, "vaddr", addr);
2001  }
2002  if (symbol->paddr != UT64_MAX) {
2003  pj_kn(state->d.pj, "paddr", symbol->paddr);
2004  }
2005  pj_kb(state->d.pj, "is_imported", symbol->is_imported);
2006  pj_ks(state->d.pj, "lib", rz_str_get(symbol->libname));
2007  pj_end(state->d.pj);
2008  break;
2009  case RZ_OUTPUT_MODE_TABLE:
2010  rz_table_add_rowf(state->d.t, "dXXssnss",
2011  symbol->ordinal,
2012  symbol->paddr,
2013  addr,
2014  symbol->bind ? symbol->bind : "NONE",
2015  symbol->type ? symbol->type : "NONE",
2016  size,
2017  rz_str_get(symbol->libname),
2019  break;
2020  default:
2022  break;
2023  }
2024  rz_core_sym_name_fini(&sn);
2025  }
2027  return true;
2028 }
2029 
2031  rz_return_val_if_fail(core && state, false);
2032 
2033  return symbols_print(core, bf, state, filter, false);
2034 }
2035 
2037  rz_return_val_if_fail(core && state, false);
2038 
2039  RzCoreBinFilter filter = { 0 };
2040  filter.offset = core->offset;
2041  return symbols_print(core, bf, state, &filter, false);
2042 }
2043 
2045  rz_return_val_if_fail(core && state, false);
2046 
2047  return symbols_print(core, bf, state, filter, true);
2048 }
2049 
2051  rz_return_val_if_fail(core && state, false);
2052 
2053  RzCoreBinFilter filter = { 0 };
2054  filter.offset = core->offset;
2055  return symbols_print(core, bf, state, &filter, true);
2056 }
2057 
2059  rz_return_val_if_fail(core && bf && bf->o && state, false);
2060 
2061  int bin_demangle = rz_config_get_i(core->config, "bin.demangle");
2062  bool keep_lib = rz_config_get_i(core->config, "bin.demangle.libs");
2063  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
2064  const RzList *imports = rz_bin_object_get_imports(bf->o);
2065  RzBinObject *o = bf->o;
2066  RzBinImport *import;
2067  RzListIter *iter;
2068 
2070  rz_cmd_state_output_set_columnsf(state, "nXssss", "nth", "vaddr", "bind", "type", "lib", "name");
2071 
2072  rz_list_foreach (imports, iter, import) {
2073  if (!import->name) {
2074  continue;
2075  }
2076 
2077  char *symname = import->name ? strdup(import->name) : NULL;
2078  char *libname = import->libname ? strdup(import->libname) : NULL;
2080  ut64 addr = sym ? rva(o, sym->paddr, sym->vaddr, va) : UT64_MAX;
2081 
2082  if (filter && filter->offset != UT64_MAX) {
2083  if (!is_in_symbol_range(addr, 1, filter->offset)) {
2084  goto next;
2085  }
2086  }
2087  if (filter && filter->name && strcmp(import->name, filter->name)) {
2088  goto next;
2089  }
2090 
2091  if (RZ_STR_ISNOTEMPTY(import->classname)) {
2092  char *tmp = rz_str_newf("%s.%s", import->classname, symname);
2093  if (tmp) {
2094  free(symname);
2095  symname = tmp;
2096  }
2097  }
2098 
2099  if (bin_demangle) {
2100  char *dname = rz_bin_demangle(core->bin->cur, NULL, symname, addr, keep_lib);
2101  if (dname) {
2102  free(symname);
2103  symname = dname;
2104  }
2105  }
2106 
2107  if (core->bin->prefix) {
2108  char *prname = rz_str_newf("%s.%s", core->bin->prefix, symname);
2109  free(symname);
2110  symname = prname;
2111  }
2112  switch (state->mode) {
2113  case RZ_OUTPUT_MODE_QUIET:
2114  rz_cons_printf("%s%s%s\n", libname ? libname : "", libname ? " " : "", symname);
2115  break;
2117  rz_cons_println(symname);
2118  break;
2119  case RZ_OUTPUT_MODE_JSON:
2120  pj_o(state->d.pj);
2121  pj_ki(state->d.pj, "ordinal", import->ordinal);
2122  if (import->bind) {
2123  pj_ks(state->d.pj, "bind", import->bind);
2124  }
2125  if (import->type) {
2126  pj_ks(state->d.pj, "type", import->type);
2127  }
2128  if (import->classname && import->classname[0]) {
2129  pj_ks(state->d.pj, "classname", import->classname);
2130  pj_ks(state->d.pj, "descriptor", import->descriptor);
2131  }
2132  pj_ks(state->d.pj, "name", symname);
2133  if (libname) {
2134  pj_ks(state->d.pj, "libname", libname);
2135  }
2136  if (addr != UT64_MAX) {
2137  pj_kn(state->d.pj, "plt", addr);
2138  }
2139  pj_end(state->d.pj);
2140  break;
2141  case RZ_OUTPUT_MODE_TABLE:
2142  rz_table_add_rowf(state->d.t, "nXssss",
2143  (ut64)import->ordinal,
2144  addr,
2145  import->bind ? import->bind : "NONE",
2146  import->type ? import->type : "NONE",
2147  libname ? libname : "",
2148  symname);
2149  break;
2150  default:
2152  break;
2153  }
2154  next:
2155  RZ_FREE(symname);
2156  RZ_FREE(libname);
2157  }
2158 
2160  return true;
2161 }
2162 
2164  rz_return_val_if_fail(core && bf && bf->o && state, false);
2165 
2166  const RzList *libs = rz_bin_object_get_libs(bf->o);
2167  RzListIter *iter;
2168  char *lib;
2169 
2171  rz_cmd_state_output_set_columnsf(state, "s", "library");
2172  rz_list_foreach (libs, iter, lib) {
2173  switch (state->mode) {
2174  case RZ_OUTPUT_MODE_JSON:
2175  pj_s(state->d.pj, lib);
2176  break;
2177  case RZ_OUTPUT_MODE_TABLE:
2178  rz_table_add_rowf(state->d.t, "s", lib);
2179  break;
2180  case RZ_OUTPUT_MODE_QUIET:
2181  rz_cons_printf("%s\n", lib);
2182  break;
2183  default:
2185  break;
2186  }
2187  }
2189  return true;
2190 }
2191 
2193  rz_return_val_if_fail(core && bf && bf->o && state, false);
2194 
2195  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
2197  if (!binmain) {
2198  return false;
2199  }
2200 
2201  ut64 addr = va ? rz_bin_object_addr_with_base(bf->o, binmain->vaddr) : binmain->paddr;
2202  rz_cmd_state_output_set_columnsf(state, "XX", "vaddr", "paddr");
2203 
2204  switch (state->mode) {
2205  case RZ_OUTPUT_MODE_QUIET:
2206  rz_cons_printf("%" PFMT64d, addr);
2207  break;
2208  case RZ_OUTPUT_MODE_JSON:
2209  pj_o(state->d.pj);
2210  pj_kn(state->d.pj, "vaddr", addr);
2211  pj_kn(state->d.pj, "paddr", binmain->paddr);
2212  pj_end(state->d.pj);
2213  break;
2214  case RZ_OUTPUT_MODE_TABLE:
2215  rz_table_add_rowf(state->d.t, "XX", addr, binmain->paddr);
2216  break;
2217  default:
2219  break;
2220  }
2221  return true;
2222 }
2223 
2225  rz_return_val_if_fail(core && bf && bf->o && state, false);
2226 
2227  RzBinObject *o = bf->o;
2228 
2229  bool bin_demangle = rz_config_get_i(core->config, "bin.demangle");
2230  bool keep_lib = rz_config_get_i(core->config, "bin.demangle.libs");
2231  const char *lang = rz_config_get(core->config, "bin.lang");
2232  int va = VA_TRUE; // XXX relocs always vaddr?
2233  char *name = NULL;
2234 
2236  if (!relocs) {
2237  RZ_LOG_WARN("Could not get relocations for current bin file.\n");
2238  return false;
2239  }
2240  bool have_targets = rz_bin_reloc_storage_targets_available(relocs);
2241  if (have_targets) {
2242  rz_cmd_state_output_set_columnsf(state, "XXXss", "vaddr", "paddr", "target", "type", "name");
2243  } else {
2244  rz_cmd_state_output_set_columnsf(state, "XXss", "vaddr", "paddr", "type", "name");
2245  }
2246 
2248  for (size_t i = 0; i < relocs->relocs_count; i++) {
2249  RzBinReloc *reloc = relocs->relocs[i];
2250  ut64 addr = rva(o, reloc->paddr, reloc->vaddr, va);
2251 
2252  switch (state->mode) {
2253  case RZ_OUTPUT_MODE_QUIET:
2254  rz_cons_printf("0x%08" PFMT64x " %s\n", addr, reloc->import ? reloc->import->name : "");
2255  break;
2256  case RZ_OUTPUT_MODE_JSON:
2257  pj_o(state->d.pj);
2258  char *mn = NULL;
2259  char *relname = NULL;
2260 
2261  // take care with very long symbol names! do not use sdb_fmt or similar
2262  if (reloc->import) {
2263  mn = rz_bin_demangle(core->bin->cur, lang, reloc->import->name, addr, keep_lib);
2264  relname = strdup(reloc->import->name);
2265  } else if (reloc->symbol) {
2266  mn = rz_bin_demangle(core->bin->cur, lang, reloc->symbol->name, addr, keep_lib);
2267  relname = strdup(reloc->symbol->name);
2268  }
2269 
2270  // check if name is available
2271  if (!RZ_STR_ISEMPTY(relname)) {
2272  pj_ks(state->d.pj, "name", relname);
2273  }
2274  pj_ks(state->d.pj, "demname", rz_str_get(mn));
2275  pj_ks(state->d.pj, "type", bin_reloc_type_name(reloc));
2276  pj_kn(state->d.pj, "vaddr", reloc->vaddr);
2277  pj_kn(state->d.pj, "paddr", reloc->paddr);
2278  if (rz_bin_reloc_has_target(reloc)) {
2279  pj_kn(state->d.pj, "target_vaddr", reloc->target_vaddr);
2280  }
2281  if (reloc->symbol) {
2282  pj_kn(state->d.pj, "sym_va", reloc->symbol->vaddr);
2283  }
2284  pj_kb(state->d.pj, "is_ifunc", reloc->is_ifunc);
2285  pj_end(state->d.pj);
2286 
2287  free(mn);
2288  free(relname);
2289  break;
2290  case RZ_OUTPUT_MODE_TABLE:
2291  name = reloc->import
2292  ? strdup(reloc->import->name)
2293  : reloc->symbol ? strdup(reloc->symbol->name)
2294  : NULL;
2295  if (bin_demangle) {
2296  char *mn = rz_bin_demangle(core->bin->cur, NULL, name, addr, keep_lib);
2297  if (RZ_STR_ISNOTEMPTY(mn)) {
2298  free(name);
2299  name = mn;
2300  }
2301  }
2302  char *reloc_name = construct_reloc_name(reloc, name);
2304  if (core->bin->prefix) {
2305  rz_strbuf_appendf(buf, "%s.", core->bin->prefix);
2306  }
2307  rz_strbuf_append(buf, rz_str_get(reloc_name));
2308  free(reloc_name);
2309  RZ_FREE(name);
2310  if (reloc->addend) {
2311  if ((reloc->import || reloc->symbol) && !rz_strbuf_is_empty(buf) && reloc->addend > 0) {
2312  rz_strbuf_append(buf, " +");
2313  }
2314  if (reloc->addend < 0) {
2315  rz_strbuf_appendf(buf, " - 0x%08" PFMT64x, -reloc->addend);
2316  } else {
2317  rz_strbuf_appendf(buf, " 0x%08" PFMT64x, reloc->addend);
2318  }
2319  }
2320  if (reloc->is_ifunc) {
2321  rz_strbuf_append(buf, " (ifunc)");
2322  }
2323  char *res = rz_strbuf_drain(buf);
2324  if (have_targets) {
2325  rz_table_add_rowf(state->d.t, "XXXss", addr, reloc->paddr, reloc->target_vaddr,
2326  bin_reloc_type_name(reloc), res);
2327  } else {
2328  rz_table_add_rowf(state->d.t, "XXss", addr, reloc->paddr,
2329  bin_reloc_type_name(reloc), res);
2330  }
2331  free(res);
2332  break;
2333  default:
2335  break;
2336  }
2337  }
2339  return true;
2340 }
2341 
2343  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
2344  if (va && !(section->perm & RZ_PERM_R)) {
2345  va = VA_NOREBASE;
2346  }
2347  return rva(o, section->paddr, section->vaddr, va);
2348 }
2349 
2350 static bool digests_pj_cb(void *user, const void *k, const void *v) {
2351  rz_return_val_if_fail(user && k && v, false);
2352  PJ *pj = user;
2353  pj_ks(pj, k, v);
2354  return true;
2355 }
2356 
2357 static void sections_print_json(RzCore *core, PJ *pj, RzBinObject *o, RzBinSection *section, RzList *hashes) {
2358  ut64 addr = get_section_addr(core, o, section);
2359  char perms[5];
2360  section_perms_str(perms, section->perm);
2361 
2362  pj_o(pj);
2363  pj_ks(pj, "name", section->name);
2364  pj_kN(pj, "size", section->size);
2365  pj_kN(pj, "vsize", section->vsize);
2366  pj_ks(pj, "perm", perms);
2367  if (!section->is_segment) {
2368  char *section_type = rz_bin_section_type_to_string(core->bin, section->type);
2369  if (section_type) {
2370  pj_ks(pj, "type", section_type);
2371  }
2372  free(section_type);
2373  }
2374  if (!section->is_segment) {
2376  if (!rz_list_empty(flags)) {
2377  RzListIter *it;
2378  char *pos;
2379  pj_ka(pj, "flags");
2380  rz_list_foreach (flags, it, pos) {
2381  pj_s(pj, pos);
2382  }
2383  pj_end(pj);
2384  }
2386  }
2387  pj_kN(pj, "paddr", section->paddr);
2388  pj_kN(pj, "vaddr", addr);
2389  if (section->align) {
2390  pj_kN(pj, "align", section->align);
2391  }
2392  if (hashes && section->size > 0) {
2393  HtPP *digests = rz_core_bin_create_digests(core, section->paddr, section->size, hashes);
2394  if (!digests) {
2395  pj_end(pj);
2396  return;
2397  }
2398  ht_pp_foreach(digests, digests_pj_cb, pj);
2399  ht_pp_free(digests);
2400  }
2401  pj_end(pj);
2402 }
2403 
2405  ut64 addr = get_section_addr(core, o, section);
2406  char perms[5];
2407  section_perms_str(perms, section->perm);
2408 
2409  char *section_type = NULL;
2410  if (!section->is_segment) {
2411  section_type = rz_bin_section_type_to_string(core->bin, section->type);
2412  }
2413  char *section_flags_str = NULL;
2414  if (!section->is_segment) {
2415  RzList *section_flags = rz_bin_section_flag_to_list(core->bin, section->flags);
2416  if (section_flags) {
2417  section_flags_str = rz_str_list_join(section_flags, ",");
2418  rz_list_free(section_flags);
2419  }
2420  }
2421 
2422  char *section_name = section->name;
2423  if (core->bin->prefix) {
2424  section_name = rz_str_newf("%s.%s", core->bin->prefix, section_name);
2425  }
2426 
2427  rz_table_add_rowf(t, "XxXxxss", section->paddr, section->size, addr, section->vsize, section->align, perms, section_name);
2428  if (!section->is_segment) {
2429  rz_table_add_row_columnsf(t, "ss", section_type, section_flags_str);
2430  }
2431  bool result = false;
2432  if (hashes && section->size > 0) {
2433  HtPP *digests = rz_core_bin_create_digests(core, section->paddr, section->size, hashes);
2434  if (!digests) {
2435  goto cleanup;
2436  }
2437  RzListIter *it;
2438  char *hash;
2439  bool found = false;
2440  rz_list_foreach (hashes, it, hash) {
2441  char *digest = ht_pp_find(digests, hash, &found);
2442  if (found && t) {
2443  rz_table_add_row_columnsf(t, "s", digest);
2444  }
2445  }
2446  ht_pp_free(digests);
2447  }
2448  result = true;
2449 cleanup:
2450  if (section_name != section->name) {
2451  free(section_name);
2452  }
2453  free(section_type);
2454  free(section_flags_str);
2455  return result;
2456 }
2457 
2459  RzListIter *iter;
2460  char *hashname;
2461 
2462  rz_cmd_state_output_set_columnsf(state, "XxXxssssx", "paddr", "size", "vaddr", "vsize", "align", "perm", "name", "type", "flags");
2463 
2464  rz_list_foreach (hashes, iter, hashname) {
2465  const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(core->hash, hashname);
2466  if (msg_plugin) {
2467  rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
2468  }
2469  }
2470 }
2471 
2473  rz_return_val_if_fail(core && bf && bf->o && state, false);
2474 
2475  RzBinObject *o = bf->o;
2477  if (!sections) {
2478  return false;
2479  }
2480 
2482  RzListIter *iter;
2483  RzOutputMode mode = state->mode;
2484  bool res = true;
2485 
2486  if (state->mode == RZ_OUTPUT_MODE_QUIET) {
2487  state->mode = RZ_OUTPUT_MODE_TABLE;
2488  state->d.t = rz_table_new();
2489  if (!state->d.t) {
2490  res = false;
2491  goto err;
2492  }
2493  }
2494 
2496  sections_headers_setup(core, state, hashes);
2497 
2498  rz_list_foreach (sections, iter, section) {
2499  if (filter && filter->offset != UT64_MAX) {
2500  if (!is_in_symbol_range(section->vaddr, section->vsize, filter->offset) &&
2501  !is_in_symbol_range(section->paddr, section->size, filter->offset)) {
2502  continue;
2503  }
2504  }
2505  if (filter && filter->name && section->name && strcmp(section->name, filter->name)) {
2506  continue;
2507  }
2508  switch (state->mode) {
2509  case RZ_OUTPUT_MODE_JSON:
2510  sections_print_json(core, state->d.pj, o, section, hashes);
2511  break;
2512  case RZ_OUTPUT_MODE_TABLE:
2513  res &= sections_print_table(core, state->d.t, o, section, hashes);
2514  break;
2515  default:
2517  break;
2518  }
2519  }
2520 
2522 
2523 err:
2524  if (mode == RZ_OUTPUT_MODE_QUIET) {
2525  if (state->d.t) {
2526  rz_table_query(state->d.t, "vaddr/cols/vsize/perm/name");
2527  char *s = rz_table_tostring(state->d.t);
2528  if (s) {
2529  rz_cons_printf("%s", s);
2530  free(s);
2531  }
2532  }
2533 
2534  state->mode = mode;
2535  rz_table_free(state->d.t);
2536  }
2538  return res;
2539 }
2540 
2542  rz_return_val_if_fail(core && state, false);
2543 
2544  RzCoreBinFilter filter = { 0 };
2545  filter.offset = core->offset;
2546  return rz_core_bin_sections_print(core, bf, state, &filter, hashes);
2547 }
2548 
2550  rz_return_val_if_fail(core && bf && state, false);
2551 
2552  RzCoreBinFilter filter = { 0 };
2553  filter.offset = core->offset;
2554  return rz_core_bin_segments_print(core, bf, state, &filter, hashes);
2555 }
2556 
2557 static bool core_basefind_progess_status(const RzBaseFindThreadInfo *th_info, void *user) {
2558  rz_cons_flush();
2559  rz_cons_printf("basefind: thread %u: 0x%08" PFMT64x " / 0x%08" PFMT64x " %u%%\n",
2560  th_info->thread_idx, th_info->current_address,
2561  th_info->end_address, th_info->percentage);
2562  rz_cons_flush();
2563  if ((th_info->thread_idx + 1) >= th_info->n_threads) {
2565  }
2566  return !rz_cons_is_breaked();
2567 }
2568 
2569 static bool core_basefind_check_ctrl_c(const RzBaseFindThreadInfo *th_info, void *user) {
2570  return !rz_cons_is_breaked();
2571 }
2572 
2574  rz_return_val_if_fail(core && state, false);
2575  RzListIter *it = NULL;
2576  RzBaseFindScore *pair = NULL;
2578  bool progress = rz_config_get_b(core->config, "basefind.progress");
2579  int begin_line = rz_cons_get_cur_line();
2580 
2581  options.pointer_size = pointer_size;
2582  options.start_address = rz_config_get_i(core->config, "basefind.search.start");
2583  options.end_address = rz_config_get_i(core->config, "basefind.search.end");
2584  options.alignment = rz_config_get_i(core->config, "basefind.alignment");
2585  options.max_threads = rz_config_get_i(core->config, "basefind.max.threads");
2586  options.min_score = rz_config_get_i(core->config, "basefind.min.score");
2587  options.min_string_len = rz_config_get_i(core->config, "basefind.min.string");
2589  options.user = NULL;
2590 
2591  RzList *scores = rz_basefind(core, &options);
2592 
2593  if (progress) {
2594  // ensure the last printed line is actually the last expected line
2595  // this depends on the number of the threads requested and available
2596  // this requires to be called before checking the results
2597  int n_cores = (int)rz_th_request_physical_cores(options.max_threads);
2598  rz_cons_gotoxy(1, begin_line + n_cores);
2599  }
2600 
2601  if (!scores) {
2602  return false;
2603  }
2604 
2606  rz_cmd_state_output_set_columnsf(state, "nX", "score", "candidate");
2607 
2608  rz_list_foreach (scores, it, pair) {
2609  switch (state->mode) {
2610  case RZ_OUTPUT_MODE_JSON:
2611  pj_o(state->d.pj);
2612  pj_kn(state->d.pj, "score", pair->score);
2613  pj_kn(state->d.pj, "candidate", pair->candidate);
2614  pj_end(state->d.pj);
2615  break;
2616  case RZ_OUTPUT_MODE_QUIET:
2617  rz_cons_printf("%u 0x%" PFMT64x "\n", pair->score, pair->candidate);
2618  break;
2619  case RZ_OUTPUT_MODE_TABLE:
2620  rz_table_add_rowf(state->d.t, "nX", pair->score, pair->candidate);
2621  break;
2622  default:
2624  break;
2625  }
2626  }
2627 
2629  rz_list_free(scores);
2630  return true;
2631 }
2632 
2634  rz_return_val_if_fail(core && bf && bf->o && state, false);
2635 
2636  RzBinObject *o = bf->o;
2637  RzList *segments = rz_bin_object_get_segments(o);
2638  if (!segments) {
2639  return false;
2640  }
2641 
2642  RzBinSection *segment;
2643  RzListIter *iter;
2644  char *hashname;
2645 
2647  rz_cmd_state_output_set_columnsf(state, "XxXxssx", "paddr", "size", "vaddr", "vsize", "align", "perm", "name");
2648 
2649  rz_list_foreach (hashes, iter, hashname) {
2650  const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(core->hash, hashname);
2651  if (msg_plugin) {
2652  rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
2653  }
2654  }
2655 
2656  rz_list_foreach (segments, iter, segment) {
2657  if (filter && filter->offset != UT64_MAX) {
2658  if (!is_in_symbol_range(segment->vaddr, segment->vsize, filter->offset) &&
2659  !is_in_symbol_range(segment->paddr, segment->size, filter->offset)) {
2660  continue;
2661  }
2662  }
2663  if (filter && filter->name && segment->name && strcmp(segment->name, filter->name)) {
2664  continue;
2665  }
2666  switch (state->mode) {
2667  case RZ_OUTPUT_MODE_JSON:
2668  sections_print_json(core, state->d.pj, o, segment, hashes);
2669  break;
2670  case RZ_OUTPUT_MODE_TABLE:
2671  sections_print_table(core, state->d.t, o, segment, hashes);
2672  break;
2673  default:
2675  break;
2676  }
2677  }
2678 
2680  rz_list_free(segments);
2681  return true;
2682 }
2683 
2684 static bool strings_print(RzCore *core, RzCmdStateOutput *state, const RzList *list) {
2685  bool b64str = rz_config_get_i(core->config, "bin.b64str");
2686  int va = (core->io->va || core->bin->is_debugger) ? VA_TRUE : VA_FALSE;
2687  RzBinObject *obj = rz_bin_cur_object(core->bin);
2688 
2689  RzListIter *iter;
2690  RzBinString *string;
2692 
2694  rz_cmd_state_output_set_columnsf(state, "nXXnnsss", "nth", "paddr", "vaddr", "len", "size", "section", "type", "string");
2695 
2696  RzBinString b64 = { 0 };
2697  rz_list_foreach (list, iter, string) {
2698  const char *section_name, *type_string;
2699  char quiet_val[20];
2700  ut64 paddr, vaddr;
2701  paddr = string->paddr;
2702  vaddr = obj ? rva(obj, paddr, string->vaddr, va) : paddr;
2703  if (!rz_bin_string_filter(core->bin, string->string, string->length, vaddr)) {
2704  continue;
2705  }
2706 
2707  section = obj ? rz_bin_get_section_at(obj, paddr, 0) : NULL;
2708  section_name = section ? section->name : "";
2709  type_string = rz_str_enc_as_string(string->type);
2710  if (b64str) {
2711  ut8 *s = rz_base64_decode_dyn(string->string, -1);
2712  if (s && *s && IS_PRINTABLE(*s)) {
2713  // TODO: add more checks
2714  free(b64.string);
2715  memcpy(&b64, string, sizeof(b64));
2716  b64.string = (char *)s;
2717  b64.size = strlen(b64.string);
2718  string = &b64;
2719  }
2720  }
2721 
2722  RzStrEscOptions opt = { 0 };
2723  opt.show_asciidot = false;
2724  opt.esc_bslash = true;
2726  char *escaped_string = rz_str_escape_utf8_keep_printable(string->string, &opt);
2727 
2728  switch (state->mode) {
2729  case RZ_OUTPUT_MODE_JSON: {
2730  int *block_list;
2731  pj_o(state->d.pj);
2732  pj_kn(state->d.pj, "vaddr", vaddr);
2733  pj_kn(state->d.pj, "paddr", paddr);
2734  pj_kn(state->d.pj, "ordinal", string->ordinal);
2735  pj_kn(state->d.pj, "size", string->size);
2736  pj_kn(state->d.pj, "length", string->length);
2737  pj_ks(state->d.pj, "section", section_name);
2738  pj_ks(state->d.pj, "type", type_string);
2739  // data itself may be encoded so use pj_ks
2740  pj_ks(state->d.pj, "string", escaped_string);
2741 
2742  switch (string->type) {
2743  case RZ_STRING_ENC_UTF8:
2744  case RZ_STRING_ENC_MUTF8:
2745  case RZ_STRING_ENC_UTF16LE:
2746  case RZ_STRING_ENC_UTF32LE:
2747  block_list = rz_utf_block_list((const ut8 *)string->string, -1, NULL);
2748  if (block_list) {
2749  if (block_list[0] == 0 && block_list[1] == -1) {
2750  /* Don't include block list if
2751  just Basic Latin (0x00 - 0x7F) */
2752  RZ_FREE(block_list);
2753  break;
2754  }
2755  int *block_ptr = block_list;
2756  pj_k(state->d.pj, "blocks");
2757  pj_a(state->d.pj);
2758  for (; *block_ptr != -1; block_ptr++) {
2759  const char *utfName = rz_utf_block_name(*block_ptr);
2760  pj_s(state->d.pj, utfName ? utfName : "");
2761  }
2762  pj_end(state->d.pj);
2763  RZ_FREE(block_list);
2764  }
2765  }
2766  pj_end(state->d.pj);
2767  break;
2768  }
2769  case RZ_OUTPUT_MODE_TABLE: {
2770  int *block_list;
2771  char *str = escaped_string;
2772  char *no_dbl_bslash_str = NULL;
2773  if (!core->print->esc_bslash) {
2774  char *ptr;
2775  for (ptr = str; *ptr; ptr++) {
2776  if (*ptr != '\\') {
2777  continue;
2778  }
2779  if (*(ptr + 1) == '\\') {
2780  if (!no_dbl_bslash_str) {
2781  no_dbl_bslash_str = strdup(str);
2782  if (!no_dbl_bslash_str) {
2783  break;
2784  }
2785  ptr = no_dbl_bslash_str + (ptr - str);
2786  }
2787  memmove(ptr + 1, ptr + 2, strlen(ptr + 2) + 1);
2788  }
2789  }
2790  if (no_dbl_bslash_str) {
2791  str = no_dbl_bslash_str;
2792  }
2793  }
2794 
2796  switch (string->type) {
2797  case RZ_STRING_ENC_UTF8:
2798  case RZ_STRING_ENC_MUTF8:
2799  case RZ_STRING_ENC_UTF16LE:
2800  case RZ_STRING_ENC_UTF32LE:
2801  block_list = rz_utf_block_list((const ut8 *)string->string, -1, NULL);
2802  if (block_list) {
2803  if (block_list[0] == 0 && block_list[1] == -1) {
2804  /* Don't show block list if
2805  just Basic Latin (0x00 - 0x7F) */
2806  free(block_list);
2807  break;
2808  }
2809  int *block_ptr = block_list;
2810  rz_strbuf_append(buf, " blocks=");
2811  for (; *block_ptr != -1; block_ptr++) {
2812  if (block_ptr != block_list) {
2813  rz_strbuf_append(buf, ",");
2814  }
2815  const char *name = rz_utf_block_name(*block_ptr);
2816  rz_strbuf_appendf(buf, "%s", name ? name : "");
2817  }
2818  free(block_list);
2819  }
2820  break;
2821  }
2822  char *bufstr = rz_strbuf_drain(buf);
2823  rz_table_add_rowf(state->d.t, "nXXddsss", (ut64)string->ordinal, paddr, vaddr,
2824  (int)string->length, (int)string->size, section_name,
2825  type_string, bufstr);
2826  free(bufstr);
2827  free(no_dbl_bslash_str);
2828  break;
2829  }
2830  case RZ_OUTPUT_MODE_QUIET:
2831  if (vaddr == UT64_MAX) {
2832  rz_strf(quiet_val, "----------");
2833  } else {
2834  rz_strf(quiet_val, "0x%" PFMT64x, vaddr);
2835  }
2836  rz_cons_printf("%s %d %d %s\n", quiet_val,
2837  string->size, string->length, escaped_string);
2838  break;
2840  rz_cons_printf("%s\n", escaped_string);
2841  break;
2842  default:
2844  break;
2845  }
2846  free(escaped_string);
2847  }
2848  RZ_FREE(b64.string);
2850  return true;
2851 }
2852 
2854  rz_return_val_if_fail(core && bf && state, false);
2855 
2856  const RzList *list = rz_bin_object_get_strings(bf->o);
2857  return strings_print(core, state, list);
2858 }
2859 
2860 /***
2861  * \brief Generates a RzList struct containing RzBinString from a given RzBinFile
2862  * \param core The RzCore instance
2863  * \param bf The RzBinFile to use for searching for strings
2864  * \return On success returns RzList pointer, otherwise NULL
2865  */
2867  rz_return_val_if_fail(core, NULL);
2868 
2869  bool new_bf = false;
2870  if (bf && strstr(bf->file, "malloc://")) {
2871  // sync bf->buf to search string on it
2872  ut8 *tmp = RZ_NEWS(ut8, bf->size);
2873  if (!tmp) {
2874  return NULL;
2875  }
2876  rz_io_read_at(core->io, 0, tmp, bf->size);
2877  rz_buf_write_at(bf->buf, 0, tmp, bf->size);
2878  }
2879  if (!core->file) {
2880  RZ_LOG_ERROR("Core file not open\n");
2881  return NULL;
2882  }
2883  if (!bf) {
2884  // TODO: manually creating an RzBinFile like this is a hack and abuse of RzBin API
2885  // If we don't want to use an RzBinFile for searching strings, the raw strings search
2886  // should be refactored out of bin.
2887  bf = RZ_NEW0(RzBinFile);
2888  if (!bf) {
2889  return NULL;
2890  }
2891  RzIODesc *desc = rz_io_desc_get(core->io, core->file->fd);
2892  if (!desc) {
2893  free(bf);
2894  return NULL;
2895  }
2896  bf->file = strdup(desc->name);
2897  bf->size = (int)rz_io_desc_size(desc);
2898  if (bf->size == UT64_MAX) {
2899  free(bf);
2900  return NULL;
2901  }
2902  bf->buf = rz_buf_new_with_io_fd(&core->bin->iob, core->file->fd);
2903  bf->o = NULL;
2904  bf->rbin = core->bin;
2905  new_bf = true;
2906  }
2907  size_t min = rz_config_get_i(core->config, "bin.minstr");
2908  RzList *l = rz_bin_file_strings(bf, min, true);
2909  if (new_bf) {
2910  rz_buf_free(bf->buf);
2911  free(bf->file);
2912  free(bf);
2913  }
2914  return l;
2915 }
2916 
2918  rz_return_val_if_fail(core && state, false);
2919 
2920  RzList *l = rz_core_bin_whole_strings(core, bf);
2921  if (!l) {
2922  return false;
2923  }
2924  bool res = strings_print(core, state, l);
2925  rz_list_free(l);
2926  return res;
2927 }
2928 
2929 static const char *get_filename(RzBinInfo *info, RzIODesc *desc) {
2930  if (info && info->file) {
2931  return info->file;
2932  }
2933  if (desc) {
2934  if (desc->name) {
2935  return desc->name;
2936  } else if (desc->uri) {
2937  return desc->uri;
2938  }
2939  }
2940  return "";
2941 }
2942 
2944  rz_return_val_if_fail(core && core->file && state, false);
2945 
2946  bool io_cache = rz_config_get_i(core->config, "io.cache");
2947  RzBinInfo *info = rz_bin_get_info(core->bin);
2948  int fd = rz_io_fd_get_current(core->io);
2949  RzIODesc *desc = rz_io_desc_get(core->io, fd);
2950  RzBinPlugin *plugin = rz_bin_file_cur_plugin(binfile);
2951 
2952  const char *filename = get_filename(info, desc);
2953  char *escaped = NULL;
2954 
2955  rz_cmd_state_output_set_columnsf(state, "ss", "field", "value");
2956 
2957  switch (state->mode) {
2958  case RZ_OUTPUT_MODE_QUIET:
2959  break;
2960  case RZ_OUTPUT_MODE_JSON:
2961  pj_o(state->d.pj);
2962  const char *file_tag = "file";
2963  if (rz_str_is_utf8(filename)) {
2964  pj_ks(state->d.pj, file_tag, filename);
2965  } else {
2966  pj_kr(state->d.pj, file_tag, (const ut8 *)filename, strlen(filename));
2967  }
2968  if (desc) {
2969  ut64 fsz = rz_io_desc_size(desc);
2970  pj_ki(state->d.pj, "fd", desc->fd);
2971  if (fsz != UT64_MAX) {
2972  char humansz[8];
2973  pj_kN(state->d.pj, "size", fsz);
2974  rz_num_units(humansz, sizeof(humansz), fsz);
2975  pj_ks(state->d.pj, "humansz", humansz);
2976  }
2977  pj_kb(state->d.pj, "iorw", io_cache || desc->perm & RZ_PERM_W);
2978  pj_ks(state->d.pj, "mode", rz_str_rwx_i(desc->perm & RZ_PERM_RWX));
2979  if (desc->referer && *desc->referer) {
2980  pj_ks(state->d.pj, "referer", desc->referer);
2981  }
2982  }
2983  pj_ki(state->d.pj, "block", core->blocksize);
2984  if (binfile) {
2985  if (binfile->curxtr) {
2986  pj_ks(state->d.pj, "packet", binfile->curxtr->name);
2987  }
2988  if (plugin) {
2989  pj_ks(state->d.pj, "format", plugin->name);
2990  }
2991  }
2992  pj_end(state->d.pj);
2993  break;
2994  case RZ_OUTPUT_MODE_TABLE: {
2996  if (desc) {
2997  rz_table_add_rowf(state->d.t, "sd", "fd", desc->fd);
2998  }
2999  RzStrEscOptions opt = { 0 };
3000  opt.show_asciidot = false;
3001  opt.esc_bslash = false;
3003  rz_table_add_rowf(state->d.t, "ss", "file", escaped);
3004  free(escaped);
3005  if (desc) {
3006  ut64 fsz = rz_io_desc_size(desc);
3007  if (fsz != UT64_MAX) {
3008  char humansz[8];
3009  rz_table_add_rowf(state->d.t, "sx", "size", fsz);
3010  rz_num_units(humansz, sizeof(humansz), fsz);
3011  rz_table_add_rowf(state->d.t, "ss", "humansz", humansz);
3012  }
3013  rz_table_add_rowf(state->d.t, "ss", "mode", rz_str_rwx_i(desc->perm & RZ_PERM_RWX));
3014  }
3015  if (plugin) {
3016  rz_table_add_rowf(state->d.t, "ss", "format", plugin->name);
3017  }
3018  if (desc) {
3019  table_add_row_bool(state->d.t, "iorw", io_cache || desc->perm & RZ_PERM_W);
3020  }
3021  rz_table_add_rowf(state->d.t, "sx", "block", core->blocksize);
3022  if (binfile && binfile->curxtr) {
3023  rz_table_add_rowf(state->d.t, "ss", "packet", binfile->curxtr->name);
3024  }
3025  if (desc && desc->referer && *desc->referer) {
3026  rz_table_add_rowf(state->d.t, "ss", "referer", desc->referer);
3027  }
3028  if (info) {
3029  rz_table_add_rowf(state->d.t, "ss", "type", info->type);
3030  }
3031  break;
3032  }
3033  default:
3035  break;
3036  }
3037  return true;
3038 }
3039 
3040 static const char *str2na(const char *s) {
3041  return RZ_STR_ISEMPTY(s) ? "N/A" : s;
3042 }
3043 
3045  rz_return_val_if_fail(core && state, false);
3046 
3047  RzBinInfo *info = rz_bin_get_info(core->bin);
3048  RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
3049  ut64 laddr = rz_bin_get_laddr(core->bin);
3050  if (!bf) {
3051  return false;
3052  }
3053  RzBinObject *obj = bf->o;
3054  const char *compiled = NULL;
3055  bool havecode;
3056  int bits;
3057 
3058  havecode = is_executable(obj) | (obj->entries != NULL);
3059  compiled = rz_core_bin_get_compile_time(bf);
3060  bits = (plugin && !strcmp(plugin->name, "any")) ? rz_config_get_i(core->config, "asm.bits") : info->bits;
3061  const char *endian = info->big_endian ? "BE" : "LE";
3062 
3063  char *tmp_buf;
3064  PJ *pj = state->d.pj;
3065  RzTable *t = state->d.t;
3066  int i, j, u, v, uv;
3067 
3068  switch (state->mode) {
3069  case RZ_OUTPUT_MODE_QUIET:
3070  rz_cons_printf("arch %s\n", info->arch);
3071  rz_cons_printf("cpu %s\n", str2na(info->cpu));
3072  rz_cons_printf("bits %d\n", bits);
3073  rz_cons_printf("os %s\n", info->os);
3074  rz_cons_printf("endian %s\n", info->big_endian ? "big" : "little");
3076  if (v != -1) {
3077  rz_cons_printf("minopsz %d\n", v);
3078  }
3080  if (v != -1) {
3081  rz_cons_printf("maxopsz %d\n", v);
3082  }
3084  if (v != -1) {
3085  rz_cons_printf("pcalign %d\n", v);
3086  }
3087  break;
3088  case RZ_OUTPUT_MODE_JSON:
3089  pj_o(pj);
3090  if (RZ_STR_ISNOTEMPTY(info->arch)) {
3091  pj_ks(pj, "arch", info->arch);
3092  }
3093  if (RZ_STR_ISNOTEMPTY(info->cpu)) {
3094  pj_ks(pj, "cpu", info->cpu);
3095  }
3096  pj_kn(pj, "baddr", rz_bin_get_baddr(core->bin));
3097  pj_kn(pj, "binsz", rz_bin_get_size(core->bin));
3098  if (RZ_STR_ISNOTEMPTY(info->rclass)) {
3099  pj_ks(pj, "bintype", info->rclass);
3100  }
3101  pj_ki(pj, "bits", bits);
3102  if (info->has_retguard != -1) {
3103  pj_kb(pj, "retguard", info->has_retguard);
3104  }
3105  if (RZ_STR_ISNOTEMPTY(info->bclass)) {
3106  pj_ks(pj, "class", info->bclass);
3107  }
3108  if (info->actual_checksum) {
3109  /* computed checksum */
3110  pj_ks(pj, "cmp.csum", info->actual_checksum);
3111  }
3112  if (compiled) {
3113  pj_ks(pj, "compiled", compiled);
3114  }
3115  if (info->compiler) {
3116  pj_ks(pj, "compiler", info->compiler);
3117  }
3118  if (info->debug_file_name) {
3119  pj_ks(pj, "dbg_file", info->debug_file_name);
3120  }
3121  pj_ks(pj, "endian", endian);
3122  if (info->rclass && !strcmp(info->rclass, "mdmp")) {
3123  tmp_buf = sdb_get(bf->sdb, "mdmp.flags", 0);
3124  if (tmp_buf) {
3125  pj_ks(pj, "flags", tmp_buf);
3126  free(tmp_buf);
3127  }
3128  }
3129  if (info->claimed_checksum) {
3130  /* checksum specified in header */
3131  pj_ks(pj, "hdr.csum", info->claimed_checksum);
3132  }
3133  if (info->guid) {
3134  pj_ks(pj, "guid", info->guid);
3135  }
3136  if (info->intrp) {
3137  pj_ks(pj, "intrp", info->intrp);
3138  }
3139  pj_kn(pj, "laddr", laddr);
3140  if (RZ_STR_ISNOTEMPTY(info->lang)) {
3141  pj_ks(pj, "lang", info->lang);
3142  }
3143  if (RZ_STR_ISNOTEMPTY(info->machine)) {
3144  pj_ks(pj, "machine", info->machine);
3145  }
3147  if (u != -1) {
3148  pj_ki(pj, "maxopsz", u);
3149  }
3151  if (v != -1) {
3152  pj_ki(pj, "minopsz", v);
3153  }
3154  if (RZ_STR_ISNOTEMPTY(info->os)) {
3155  pj_ks(pj, "os", info->os);
3156  }
3157  if (info->rclass && !strcmp(info->rclass, "pe")) {
3158  pj_kb(pj, "overlay", info->pe_overlay);
3159  }
3160  if (info->default_cc) {
3161  pj_ks(pj, "cc", info->default_cc);
3162  }
3163  uv = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_ALIGN);
3164  if (uv != -1) {
3165  pj_ki(pj, "pcalign", uv);
3166  }
3167 
3168  tmp_buf = sdb_get(obj->kv, "elf.relro", 0);
3169  if (tmp_buf) {
3170  pj_ks(pj, "relro", tmp_buf);
3171  free(tmp_buf);
3172  }
3173  if (info->rpath) {
3174  pj_ks(pj, "rpath", info->rpath);
3175  }
3176  if (info->rclass && !strcmp(info->rclass, "pe")) {
3177  // this should be moved if added to mach0 (or others)
3178  pj_kb(pj, "signed", info->signature);
3179  }
3180 
3181  if (info->rclass && !strcmp(info->rclass, "mdmp")) {
3182  v = sdb_num_get(bf->sdb, "mdmp.streams", 0);
3183  if (v != -1) {
3184  pj_ki(pj, "streams", v);
3185  }
3186  }
3188  pj_ks(pj, "subsys", info->subsystem);
3189  }
3190  pj_kb(pj, "stripped", RZ_BIN_DBG_STRIPPED & info->dbg_info);
3191  pj_kb(pj, "crypto", info->has_crypto);
3192  pj_kb(pj, "havecode", havecode);
3193  pj_kb(pj, "va", info->has_va);
3194  pj_kb(pj, "sanitiz", info->has_sanitizers);
3195  pj_kb(pj, "static", rz_bin_is_static(core->bin));
3196  pj_kb(pj, "linenum", RZ_BIN_DBG_LINENUMS & info->dbg_info);
3197  pj_kb(pj, "lsyms", RZ_BIN_DBG_SYMS & info->dbg_info);
3198  pj_kb(pj, "canary", info->has_canary);
3199  pj_kb(pj, "PIE", info->has_pi);
3200  pj_kb(pj, "RELROCS", RZ_BIN_DBG_RELOCS & info->dbg_info);
3201  pj_kb(pj, "NX", info->has_nx);
3202  for (i = 0; info->sum[i].type; i++) {
3203  RzBinHash *h = &info->sum[i];
3204  pj_ko(pj, h->type);
3205  char *buf = malloc(2 * h->len + 1);
3206  if (!buf) {
3207  pj_end(pj);
3208  break;
3209  }
3210  for (j = 0; j < h->len; j++) {
3211  snprintf(buf + 2 * j, 3, "%02x", h->buf[j]);
3212  }
3213  pj_ks(pj, "hex", buf);
3214  free(buf);
3215  pj_end(pj);
3216  }
3217  pj_end(pj);
3218 
3219  break;
3220  case RZ_OUTPUT_MODE_TABLE:
3221  rz_table_set_columnsf(t, "ss", "field", "value");
3223 
3224  rz_table_add_rowf(t, "ss", "arch", str2na(info->arch));
3225  rz_table_add_rowf(t, "ss", "cpu", str2na(info->cpu));
3226  rz_table_add_rowf(t, "sX", "baddr", rz_bin_get_baddr(core->bin));
3227  rz_table_add_rowf(t, "sX", "binsz", rz_bin_get_size(core->bin));
3228  rz_table_add_rowf(t, "ss", "bintype", str2na(info->rclass));
3229  rz_table_add_rowf(t, "sd", "bits", bits);
3230  if (info->has_retguard != -1) {
3231  table_add_row_bool(t, "retguard", info->has_retguard);
3232  }
3233  rz_table_add_rowf(t, "ss", "class", str2na(info->bclass));
3234  if (info->actual_checksum) {
3235  /* computed checksum */
3236  rz_table_add_rowf(t, "ss", "cmp.csum", info->actual_checksum);
3237  }
3238  if (compiled) {
3239  rz_table_add_rowf(t, "ss", "compiled", compiled);
3240  }
3241  rz_table_add_rowf(t, "ss", "compiler", str2na(info->compiler));
3242  rz_table_add_rowf(t, "ss", "dbg_file", str2na(info->debug_file_name));
3243  rz_table_add_rowf(t, "ss", "endian", str2na(endian));
3244  if (info->rclass && !strcmp(info->rclass, "mdmp")) {
3245  tmp_buf = sdb_get(bf->sdb, "mdmp.flags", 0);
3246  if (tmp_buf) {
3247  rz_table_add_rowf(t, "ss", "flags", tmp_buf);
3248  free(tmp_buf);
3249  }
3250  }
3251  /* checksum specified in header */
3252  rz_table_add_rowf(t, "ss", "hdr.csum", str2na(info->claimed_checksum));
3253  rz_table_add_rowf(t, "ss", "guid", str2na(info->guid));
3254  rz_table_add_rowf(t, "ss", "intrp", str2na(info->intrp));
3255  rz_table_add_rowf(t, "sX", "laddr", laddr);
3256  rz_table_add_rowf(t, "ss", "lang", str2na(info->lang));
3257  rz_table_add_rowf(t, "ss", "machine", str2na(info->machine));
3259  if (u != -1) {
3260  rz_table_add_rowf(t, "sd", "maxopsz", u);
3261  }
3263  if (v != -1) {
3264  rz_table_add_rowf(t, "sd", "minopsz", v);
3265  }
3266  rz_table_add_rowf(t, "ss", "os", str2na(info->os));
3267  if (info->rclass && !strcmp(info->rclass, "pe")) {
3268  table_add_row_bool(t, "overlay", info->pe_overlay);
3269  }
3270  rz_table_add_rowf(t, "ss", "cc", str2na(info->default_cc));
3271  uv = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_ALIGN);
3272  if (uv != -1) {
3273  rz_table_add_rowf(t, "sd", "pcalign", uv);
3274  }
3275 
3276  tmp_buf = sdb_get(obj->kv, "elf.relro", 0);
3277  if (tmp_buf) {
3278  rz_table_add_rowf(t, "ss", "relro", tmp_buf);
3279  free(tmp_buf);
3280  }
3281  rz_table_add_rowf(t, "ss", "rpath", str2na(info->rpath));
3282  if (info->rclass && !strcmp(info->rclass, "pe")) {
3283  // this should be moved if added to mach0 (or others)
3284  table_add_row_bool(t, "signed", info->signature);
3285  }
3286 
3287  if (info->rclass && !strcmp(info->rclass, "mdmp")) {
3288  v = sdb_num_get(bf->sdb, "mdmp.streams", 0);
3289  if (v != -1) {
3290  rz_table_add_rowf(t, "sd", "streams", v);
3291  }
3292  }
3293  rz_table_add_rowf(t, "ss", "subsys", info->subsystem);
3295  table_add_row_bool(t, "crypto", info->has_crypto);
3296  table_add_row_bool(t, "havecode", havecode);
3297  table_add_row_bool(t, "va", info->has_va);
3298  table_add_row_bool(t, "sanitiz", info->has_sanitizers);
3299  table_add_row_bool(t, "static", rz_bin_is_static(core->bin));
3302  table_add_row_bool(t, "canary", info->has_canary);
3303  table_add_row_bool(t, "PIE", info->has_pi);
3305  table_add_row_bool(t, "NX", info->has_nx);
3306 
3307  for (i = 0; info->sum[i].type; i++) {
3308  RzBinHash *h = &info->sum[i];
3309  char *buf = rz_hex_bin2strdup(h->buf, h->len);
3310  rz_table_add_rowf(t, "ss", h->type, buf);
3311  free(buf);
3312  }
3313  break;
3314  default:
3316  break;
3317  }
3318 
3319  return true;
3320 }
3321 
3322 static void flags_to_json(PJ *pj, int flags) {
3323  int i;
3324 
3325  pj_ka(pj, "flags");
3326  for (i = 0; i < 64; i++) {
3327  ut64 flag = flags & (1ULL << i);
3328  if (flag) {
3329  const char *flag_string = rz_bin_get_meth_flag_string(flag, false);
3330  if (flag_string) {
3331  pj_s(pj, flag_string);
3332  } else {
3333  pj_s(pj, sdb_fmt("0x%08" PFMT64x, flag));
3334  }
3335  }
3336  }
3337  pj_end(pj);
3338 }
3339 
3340 static char *get_rp(const char *rtype) {
3341  char *rp = NULL;
3342  switch (rtype[0]) {
3343  case 'v':
3344  rp = strdup("void");
3345  break;
3346  case 'c':
3347  rp = strdup("char");
3348  break;
3349  case 'i':
3350  rp = strdup("int");
3351  break;
3352  case 's':
3353  rp = strdup("short");
3354  break;
3355  case 'l':
3356  rp = strdup("long");
3357  break;
3358  case 'q':
3359  rp = strdup("long long");
3360  break;
3361  case 'C':
3362  rp = strdup("unsigned char");
3363  break;
3364  case 'I':
3365  rp = strdup("unsigned int");
3366  break;
3367  case 'S':
3368  rp = strdup("unsigned short");
3369  break;
3370  case 'L':
3371  rp = strdup("unsigned long");
3372  break;
3373  case 'Q':
3374  rp = strdup("unsigned long long");
3375  break;
3376  case 'f':
3377  rp = strdup("float");
3378  break;
3379  case 'd':
3380  rp = strdup("double");
3381  break;
3382  case 'D':
3383  rp = strdup("long double");
3384  break;
3385  case 'B':
3386  rp = strdup("bool");
3387  break;
3388  case '#':
3389  rp = strdup("CLASS");
3390  break;
3391  default:
3392  rp = strdup("unknown");
3393  break;
3394  }
3395  return rp;
3396 }
3397 
3398 // https://nshipster.com/type-encodings/
3399 static char *objc_type_toc(const char *objc_type) {
3400  if (!objc_type) {
3401  return strdup("void*");
3402  }
3403  if (*objc_type == '^' && objc_type[1] == '{') {
3404  char *a = strdup(objc_type + 2);
3405  char *b = strchr(a, '>');
3406  if (b) {
3407  *b = 0;
3408  }
3409  a[strlen(a) - 1] = 0;
3410  return a;
3411  }
3412  if (*objc_type == '<') {
3413  char *a = strdup(objc_type + 1);
3414  char *b = strchr(a, '>');
3415  if (b) {
3416  *b = 0;
3417  }
3418  return a;
3419  }
3420  if (!strcmp(objc_type, "f")) {
3421  return strdup("float");
3422  }
3423  if (!strcmp(objc_type, "d")) {
3424  return strdup("double");
3425  }
3426  if (!strcmp(objc_type, "i")) {
3427  return strdup("int");
3428  }
3429  if (!strcmp(objc_type, "s")) {
3430  return strdup("short");
3431  }
3432  if (!strcmp(objc_type, "l")) {
3433  return strdup("long");
3434  }
3435  if (!strcmp(objc_type, "L")) {
3436  return strdup("unsigned long");
3437  }
3438  if (!strcmp(objc_type, "*")) {
3439  return strdup("char*");
3440  }
3441  if (!strcmp(objc_type, "c")) {
3442  return strdup("bool");
3443  }
3444  if (!strcmp(objc_type, "v")) {
3445  return strdup("void");
3446  }
3447  if (!strcmp(objc_type, "#")) {
3448  return strdup("class");
3449  }
3450  if (!strcmp(objc_type, "B")) {
3451  return strdup("cxxbool");
3452  }
3453  if (!strcmp(objc_type, "Q")) {
3454  return strdup("uint64_t");
3455  }
3456  if (!strcmp(objc_type, "q")) {
3457  return strdup("long long");
3458  }
3459  if (!strcmp(objc_type, "C")) {
3460  return strdup("uint8_t");
3461  }
3462  if (strlen(objc_type) == 1) {
3463  eprintf("Unknown objc type '%s'\n", objc_type);
3464  }
3465  if (rz_str_startswith(objc_type, "@\"")) {
3466  char *s = rz_str_newf("struct %s", objc_type + 2);
3467  s[strlen(s) - 1] = '*';
3468  return s;
3469  }
3470  return strdup(objc_type);
3471 }
3472 
3473 static char *objc_name_toc(const char *objc_name) {
3474  const char *n = rz_str_lchr(objc_name, ')');
3475  char *s = strdup(n ? n + 1 : objc_name);
3476  char *p = strchr(s, '(');
3477  if (p) {
3478  *p = 0;
3479  }
3480  return s;
3481 }
3482 
3483 static void classdump_c(RzCore *r, RzBinClass *c) {
3484  rz_cons_printf("typedef struct class_%s {\n", c->name);
3485  RzListIter *iter2;
3486  RzBinField *f;
3487  rz_list_foreach (c->fields, iter2, f) {
3488  if (f->type && f->name) {
3489  char *n = objc_name_toc(f->name);
3490  char *t = objc_type_toc(f->type);
3491  rz_cons_printf(" %s %s; // %d\n", t, n, f->offset);
3492  free(t);
3493  free(n);
3494  }
3495  }
3496  rz_cons_printf("} %s;\n", c->name);
3497 }
3498 
3500  if (c->super) {
3501  rz_cons_printf("@interface %s : %s\n{\n", c->name, c->super);
3502  } else {
3503  rz_cons_printf("@interface %s\n{\n", c->name);
3504  }
3505  RzListIter *iter2, *iter3;
3506  RzBinField *f;
3507  RzBinSymbol *sym;
3508  rz_list_foreach (c->fields, iter2, f) {
3509  if (f->name && rz_regex_match("ivar", "e", f->name)) {
3510  rz_cons_printf(" %s %s\n", f->type, f->name);
3511  }
3512  }
3513  rz_cons_printf("}\n");
3514  rz_list_foreach (c->methods, iter3, sym) {
3515  if (sym->rtype && sym->rtype[0] != '@') {
3516  char *rp = get_rp(sym->rtype);
3517  rz_cons_printf("%s (%s) %s\n",
3518  strncmp(sym->type, RZ_BIN_TYPE_METH_STR, 4) ? "+" : "-",
3519  rp, sym->dname ? sym->dname : sym->name);
3520  free(rp);
3521  } else if (sym->type) {
3522  rz_cons_printf("%s (id) %s\n",
3523  strncmp(sym->type, RZ_BIN_TYPE_METH_STR, 4) ? "+" : "-",
3524  sym->dname ? sym->dname : sym->name);
3525  }
3526  }
3527  rz_cons_printf("@end\n");
3528 }
3529 
3530 static inline bool is_known_namespace(const char *string) {
3531  if (!strcmp(string, "std")) {
3532  return true;
3533  }
3534  return false;
3535 }
3536 
3537 #define CXX_BIN_VISIBILITY_FLAGS (RZ_BIN_METH_PUBLIC | RZ_BIN_METH_PRIVATE | RZ_BIN_METH_PROTECTED)
3538 static void classdump_cpp(RzCore *r, RzBinClass *c) {
3539  RzListIter *iter;
3540  RzBinField *f;
3541  RzBinSymbol *sym;
3542  ut64 used = UT64_MAX;
3543  bool has_methods = false;
3544  bool is_namespace = false;
3545 
3546  const char *visibility = "class";
3547  if (c->visibility_str) {
3548  visibility = c->visibility_str;
3549  is_namespace = !!strstr(visibility, "namespace");
3550  } else if (is_known_namespace(c->name)) {
3551  visibility = "namespace";
3552  is_namespace = true;
3553  }
3554 
3555  if (c->super) {
3556  rz_cons_printf("%s %s : public %s {\n", visibility, c->name, c->super);
3557  } else {
3558  rz_cons_printf("%s %s {\n", visibility, c->name);
3559  }
3560 
3561  if (rz_list_length(c->methods) > 0) {
3562  has_methods = true;
3563  rz_list_foreach (c->methods, iter, sym) {
3564  const char *type = sym->type ? sym->type : "void";
3565  const char *name = sym->dname ? sym->dname : sym->name;
3566 
3567  if (!is_namespace && used != (sym->method_flags & CXX_BIN_VISIBILITY_FLAGS)) {
3568  used = sym->method_flags & CXX_BIN_VISIBILITY_FLAGS;
3569  if (used & RZ_BIN_METH_PRIVATE) {
3570  rz_cons_print(" private:\n");
3571  } else if (used & RZ_BIN_METH_PROTECTED) {
3572  rz_cons_print(" protected:\n");
3573  } else {
3574  rz_cons_print(" public:\n");
3575  }
3576  }
3577  rz_cons_print(" ");
3578  if (sym->method_flags & RZ_BIN_METH_STATIC) {
3579  rz_cons_print("static ");
3580  }
3581 
3582  if (name[0] == '~' || strstr(name, c->name) == name) {
3583  rz_cons_print(name);
3584  } else {
3585  rz_cons_printf("%s %s", type, name);
3586  }
3587  if (sym->method_flags & RZ_BIN_METH_CONST) {
3588  rz_cons_print(" const");
3589  }
3590  if (sym->method_flags & RZ_BIN_METH_VIRTUAL) {
3591  rz_cons_print(" = 0;\n");
3592  } else {
3593  rz_cons_print(";\n");
3594  }
3595  }
3596  }
3597 
3598  if (rz_list_length(c->fields) > 0) {
3599  if (has_methods) {
3600  rz_cons_newline();
3601  }
3602  used = UT64_MAX;
3603  rz_list_foreach (c->fields, iter, f) {
3604  if (!is_namespace && used != (f->visibility & CXX_BIN_VISIBILITY_FLAGS)) {
3605  used = f->visibility & CXX_BIN_VISIBILITY_FLAGS;
3606  if (used & RZ_BIN_METH_PRIVATE) {
3607  rz_cons_print(" private:\n");
3608  } else if (used & RZ_BIN_METH_PUBLIC) {
3609  rz_cons_print(" public:\n");
3610  } else if (used & RZ_BIN_METH_PROTECTED) {
3611  rz_cons_print(" protected:\n");
3612  }
3613  }
3614  rz_cons_print(" ");
3615  if (f->visibility & RZ_BIN_METH_STATIC) {
3616  rz_cons_print("static ");
3617  }
3618  if (f->visibility & RZ_BIN_METH_CONST) {
3619  rz_cons_print("const ");
3620  }
3621  rz_cons_printf("%s %s;\n", f->type, f->name);
3622  }
3623  }
3624  rz_cons_printf("}\n");
3625 }
3626 #undef CXX_BIN_VISIBILITY_FLAGS
3627 
3628 static inline char *demangle_class(const char *classname) {
3629  if (!classname || classname[0] != 'L') {
3630  return strdup(classname ? classname : "?");
3631  }
3632  char *demangled = strdup(classname + 1);
3633  if (!demangled) {
3634  return strdup(classname);
3635  }
3636  rz_str_replace_ch(demangled, '/', '.', 1);
3637  demangled[strlen(demangled) - 1] = 0;
3638  return demangled;
3639 }
3640 
3641 static inline char *demangle_type(const char *any) {
3642  if (!any) {
3643  return strdup("unknown");
3644  }
3645  switch (any[0]) {
3646  case 'L': return rz_demangler_java(any);
3647  case 'B': return strdup("byte");
3648  case 'C': return strdup("char");
3649  case 'D': return strdup("double");
3650  case 'F': return strdup("float");
3651  case 'I': return strdup("int");
3652  case 'J': return strdup("long");
3653  case 'S': return strdup("short");
3654  case 'V': return strdup("void");
3655  case 'Z': return strdup("boolean");
3656  default: return strdup("unknown");
3657  }
3658 }
3659 
3660 static inline const char *resolve_java_visibility(const char *v) {
3661  return v ? v : "public";
3662 }
3663 
3665  RzBinField *f;
3666  RzListIter *iter2, *iter3;
3667  RzBinSymbol *sym;
3668  bool simplify = false;
3669  char *package = NULL, *classname = NULL;
3670  char *tmp = (char *)rz_str_rchr(c->name, NULL, '/');
3671  if (tmp) {
3672  package = demangle_class(c->name);
3673  classname = strdup(tmp + 1);
3674  classname[strlen(classname) - 1] = 0;
3675  simplify = true;
3676  } else {
3677  package = strdup("defpackage");
3678  classname = demangle_class(c->name);
3679  }
3680 
3681  rz_cons_printf("package %s;\n\n", package);
3682 
3683  const char *visibility = resolve_java_visibility(c->visibility_str);
3684  rz_cons_printf("%s class %s {\n", visibility, classname);
3685  rz_list_foreach (c->fields, iter2, f) {
3686  visibility = resolve_java_visibility(f->visibility_str);
3687  char *ftype = demangle_type(f->type);
3688  if (!ftype) {
3689  ftype = strdup(f->type);
3690  } else if (simplify && ftype && package && classname) {
3691  // hide the current package in the demangled value.
3692  ftype = rz_str_replace(ftype, package, classname, 1);
3693  }
3694  rz_cons_printf(" %s %s %s;\n", visibility, ftype, f->name);
3695  free(ftype);
3696  }
3697  if (!rz_list_empty(c->fields)) {
3698  rz_cons_newline();
3699  }
3700 
3701  rz_list_foreach (c->methods, iter3, sym) {
3702  const char *mn = sym->dname ? sym->dname : sym->name;
3703  visibility = resolve_java_visibility(sym->visibility_str);
3704  char *dem = rz_demangler_java(mn);
3705  if (!dem) {
3706  dem = strdup(mn);
3707  } else if (simplify && dem && package && classname) {
3708  // hide the current package in the demangled value.
3709  dem = rz_str_replace(dem, package, classname, 1);
3710  }
3711  // rename all <init> to class name
3712  dem = rz_str_replace(dem, "<init>", classname, 1);
3713  rz_cons_printf(" %s %s;\n", visibility, dem);
3714  free(dem);
3715  }
3716  free(package);
3717  free(classname);
3718  rz_cons_printf("}\n\n");
3719 }
3720 
3721 static void bin_class_print_rizin(RzCore *r, RzBinClass *c, ut64 at_min) {
3722  RzListIter *iter2;
3723  RzBinFile *bf = rz_bin_cur(r->bin);
3724  RzBinField *f;
3725  RzBinSymbol *sym;
3726 
3727  // class
3729  if (fn) {
3730  rz_cons_printf("\"f %s @ 0x%" PFMT64x "\"\n", fn, at_min);
3731  free(fn);
3732  }
3733 
3734  // super class
3736  if (fn) {
3737  rz_cons_printf("\"f %s @ %d\"\n", fn, c->index);
3738  free(fn);
3739  }
3740 
3741  // class fields
3742  rz_list_foreach (c->fields, iter2, f) {
3744  if (fn) {
3745  rz_cons_printf("\"f %s @ 0x%08" PFMT64x "\"\n", fn, f->vaddr);
3746  free(fn);
3747  }
3748  }
3749 
3750  // class methods
3751  rz_list_foreach (c->methods, iter2, sym) {
3752  char *fn = rz_core_bin_method_build_flag_name(c, sym);
3753  if (fn) {
3754  rz_cons_printf("\"f %s @ 0x%" PFMT64x "\"\n", fn, sym->vaddr);
3755  free(fn);
3756  }
3757  }
3758 
3759  // C struct
3760  if (bf->o->lang == RZ_BIN_LANGUAGE_C || bf->o->lang == RZ_BIN_LANGUAGE_CXX || bf->o->lang == RZ_BIN_LANGUAGE_OBJC) {
3761  rz_cons_printf("td \"struct %s {", c->name);
3762  rz_list_foreach (c->fields, iter2, f) {
3763  char *n = objc_name_toc(f->name);
3764  char *t = objc_type_toc(f->type);
3765  rz_cons_printf(" %s %s;", t, n);
3766  free(t);
3767  free(n);
3768  }
3769  rz_cons_printf("};\"\n");
3770  }
3771 }
3772 
3774  rz_return_val_if_fail(core && bf, false);
3775 
3776  RzBinClass *c;
3777  RzListIter *iter;
3778 
3779  const RzList *cs = rz_bin_object_get_classes(bf->o);
3780  if (!cs) {
3781  return false;
3782  }
3783 
3784  bool found = false;
3785  rz_list_foreach (cs, iter, c) {
3786  if (class_name && (!c->name || !strstr(c->name, class_name))) {
3787  continue;
3788  }
3789  found = true;
3790  switch (bf->o->lang & (~RZ_BIN_LANGUAGE_BLOCKS)) {
3793  case RZ_BIN_LANGUAGE_DART:
3794  case RZ_BIN_LANGUAGE_JAVA:
3795  classdump_java(core, c);
3796  break;
3797  case RZ_BIN_LANGUAGE_SWIFT:
3798  case RZ_BIN_LANGUAGE_OBJC:
3799  classdump_objc(core, c);
3800  break;
3801  case RZ_BIN_LANGUAGE_CXX:
3802  classdump_cpp(core, c);
3803  break;
3804  case RZ_BIN_LANGUAGE_C:
3805  classdump_c(core, c);
3806  break;
3807  default:
3808  return false;
3809  }
3810  }
3811  return found;
3812 }
3813 
3815  rz_return_val_if_fail(core && bf && bf->o && state, false);
3816 
3817  RzListIter *iter, *iter2;
3818  RzBinClass *c;
3819  RzBinField *f;
3820  int m = 0;
3821 
3822  const RzList *cs = rz_bin_object_get_classes(bf->o);
3823  if (!cs) {
3824  return false;
3825  }
3826 
3828  rz_cmd_state_output_set_columnsf(state, "Xissss", "address", "index", "class", "flags", "name", "type", NULL);
3829 
3830  rz_list_foreach (cs, iter, c) {
3831  if (class_name && (!c->name || strcmp(c->name, class_name))) {
3832  continue;
3833  }
3834 
3835  switch (state->mode) {
3836  case RZ_OUTPUT_MODE_QUIET:
3837  rz_list_foreach (c->fields, iter2, f) {
3838  char *mflags = rz_core_bin_method_flags_str(f->flags, 0);
3839  rz_cons_printf("0x%08" PFMT64x " field %d %s %s %s\n", f->vaddr, m, c->name, mflags, f->name);
3840  free(mflags);
3841  m++;
3842  }
3843  break;
3845  rz_list_foreach (c->fields, iter2, f) {
3846  rz_cons_printf("%s\n", f->name);
3847  }
3848  break;
3849  case RZ_OUTPUT_MODE_JSON:
3850  rz_list_foreach (c->fields, iter2, f) {
3851  pj_o(state->d.pj);
3852  if (f->type) {
3853  pj_ks(state->d.pj, "type", f->type);
3854  }
3855  pj_ks(state->d.pj, "name", f->name);
3856  pj_ks(state->d.pj, "class", c->name);
3857  if (f->flags) {
3858  flags_to_json(state->d.pj, f->flags);
3859  }
3860  pj_kN(state->d.pj, "addr", f->vaddr);
3861  pj_end(state->d.pj);
3862  }
3863  break;
3864  case RZ_OUTPUT_MODE_TABLE:
3865  rz_list_foreach (c->fields, iter2, f) {
3866  char *mflags = rz_core_bin_method_flags_str(f->flags, 0);
3867  rz_table_add_rowf(state->d.t, "Xissss", f->vaddr, m, c->name, mflags, f->name, f->type);
3868  free(mflags);
3869  m++;
3870  }
3871  break;
3872  default:
3874  break;
3875  }
3876  }
3878  return true;
3879 }
3880 
3882  rz_return_val_if_fail(core && bf && bf->o && state, false);
3883 
3884  RzListIter *iter, *iter2;
3885  RzBinClass *c;
3886  RzBinSymbol *sym;
3887  int m = 0;
3888 
3889  const RzList *cs = rz_bin_object_get_classes(bf->o);
3890  if (!cs) {
3891  return false;
3892  }
3893 
3895  rz_cmd_state_output_set_columnsf(state, "Xisss", "address", "index", "class", "flags", "name", NULL);
3896 
3897  rz_list_foreach (cs, iter, c) {
3898  if (class_name && (!c->name || strcmp(c->name, class_name))) {
3899  continue;
3900  }
3901 
3902  rz_list_foreach (c->methods, iter2, sym) {
3903  const char *name = sym->dname ? sym->dname : sym->name;
3904  char *mflags = rz_core_bin_method_flags_str(sym->method_flags, 0);
3905 
3906  switch (state->mode) {
3907  case RZ_OUTPUT_MODE_QUIET:
3908  rz_cons_printf("0x%08" PFMT64x " method %d %s %s %s\n", sym->vaddr, m, c->name, mflags, name);
3909  break;
3911  rz_cons_printf("%s\n", name);
3912  break;
3913  case RZ_OUTPUT_MODE_JSON:
3914  pj_o(state->d.pj);
3915  pj_ks(state->d.pj, "name", name);
3916  pj_ks(state->d.pj, "class", c->name);
3917  if (sym->method_flags) {
3918  flags_to_json(state->d.pj, sym->method_flags);
3919  }
3920  pj_kN(state->d.pj, "addr", sym->vaddr);
3921  pj_end(state->d.pj);
3922  break;
3923  case RZ_OUTPUT_MODE_TABLE:
3924  rz_table_add_rowf(state->d.t, "Xisss", sym->vaddr, m, c->name, mflags, name);
3925  break;
3926  default:
3928  break;
3929  }
3930 
3931  free(mflags);
3932  m++;
3933  }
3934  }
3936  return true;
3937 }
3938 
3940  rz_return_val_if_fail(core && bf && bf->o && state, false);
3941 
3942  RzListIter *iter, *iter2, *iter3;
3943  RzBinSymbol *sym;
3944  RzBinClass *c;
3945  RzBinField *f;
3946 
3947  const RzList *cs = rz_bin_object_get_classes(bf->o);
3948  if (!cs) {
3949  return false;
3950  }
3951 
3953  rz_cmd_state_output_set_columnsf(state, "XXXss", "address", "min", "max", "name", "super", NULL);
3954 
3955  if (state->mode == RZ_OUTPUT_MODE_RIZIN) {
3956  rz_cons_println("fs classes");
3957  }
3958 
3959  rz_list_foreach (cs, iter, c) {
3960  ut64 at_min = UT64_MAX;
3961  ut64 at_max = 0LL;
3962 
3963  rz_list_foreach (c->methods, iter2, sym) {
3964  if (sym->vaddr) {
3965  if (sym->vaddr < at_min) {
3966  at_min = sym->vaddr;
3967  }
3968  if (sym->vaddr + sym->size > at_max) {
3969  at_max = sym->vaddr + sym->size;
3970  }
3971  }
3972  }
3973  if (at_min == UT64_MAX) {
3974  at_min = c->addr;
3975  at_max = c->addr; // XXX + size?
3976  }
3977 
3978  switch (state->mode) {
3979  case RZ_OUTPUT_MODE_QUIET:
3980  rz_cons_printf("0x%08" PFMT64x " [0x%08" PFMT64x " - 0x%08" PFMT64x "] %s%s%s\n",
3981  c->addr, at_min, at_max, c->name, c->super ? " " : "",
3982  c->super ? c->super : "");
3983  break;
3985  rz_cons_printf("%s\n", c->name);
3986  break;
3987  case RZ_OUTPUT_MODE_JSON:
3988  pj_o(state->d.pj);
3989  pj_ks(state->d.pj, "classname", c->name);
3990  pj_kN(state->d.pj, "addr", c->addr);
3991  pj_ki(state->d.pj, "index", c->index);
3992  if (c->super) {
3993  pj_ks(state->d.pj, "visibility", c->visibility_str ? c->visibility_str : "");
3994  pj_ks(state->d.pj, "super", c->super);
3995  }
3996  pj_ka(state->d.pj, "methods");
3997  rz_list_foreach (c->methods, iter2, sym) {
3998  pj_o(state->d.pj);
3999  pj_ks(state->d.pj, "name", sym->name);
4000  if (sym->method_flags) {
4001  flags_to_json(state->d.pj, sym->method_flags);
4002  }
4003  pj_kN(state->d.pj, "addr", sym->vaddr);
4004  pj_end(state->d.pj);
4005  }
4006  pj_end(state->d.pj);
4007  pj_ka(state->d.pj, "fields");
4008  rz_list_foreach (c->fields, iter3, f) {
4009  pj_o(state->d.pj);
4010  pj_ks(state->d.pj, "name", f->name);
4011  if (f->type) {
4012  pj_ks(state->d.pj, "type", f->type);
4013  }
4014  if (f->flags) {
4015  flags_to_json(state->d.pj, f->flags);
4016  }
4017  pj_kN(state->d.pj, "addr", f->vaddr);
4018  pj_end(state->d.pj);
4019  }
4020  pj_end(state->d.pj);
4021  pj_end(state->d.pj);
4022  break;
4023  case RZ_OUTPUT_MODE_RIZIN:
4024  bin_class_print_rizin(core, c, at_min);
4025  break;
4026  case RZ_OUTPUT_MODE_TABLE:
4027  rz_table_add_rowf(state->d.t, "XXXss", c->addr, at_min, at_max, c->name, c->super);
4028  break;
4029  default:
4031  break;
4032  }
4033  }
4035  return true;
4036 }
4037 
4039  rz_return_val_if_fail(core && state, false);
4040 
4041  RzBinFile *cur = rz_bin_cur(core->bin);
4042  RzBinPlugin *plg = rz_bin_file_cur_plugin(cur);
4043  if (!plg || !plg->signature) {
4044  return false;
4045  }
4046 
4047  char *signature = plg->signature(cur, state->mode == RZ_OUTPUT_MODE_JSON);
4048  if (!signature) {
4049  return false;
4050  }
4051 
4052  switch (state->mode) {
4053  case RZ_OUTPUT_MODE_JSON:
4054  pj_o(state->d.pj);
4055  pj_k(state->d.pj, "signature");
4056  pj_raw(state->d.pj, signature);
4057  pj_end(state->d.pj);
4058  break;
4061  break;
4062  default:
4064  break;
4065  }
4066  free(signature);
4067  return true;
4068 }
4069 
4071  rz_return_val_if_fail(core && bf && bf->o && state, false);
4072 
4073  const RzList *fields = rz_bin_object_get_fields(bf->o);
4074  RzListIter *iter;
4075  RzBinField *field;
4076  bool haveComment;
4077 
4078  rz_cmd_state_output_set_columnsf(state, "XsXs", "paddr", "name", "vaddr", "comment");
4080  rz_list_foreach (fields, iter, field) {
4081  switch (state->mode) {
4082  case RZ_OUTPUT_MODE_JSON:
4083  pj_o(state->d.pj);
4084  pj_ks(state->d.pj, "name", field->name);
4085  pj_kN(state->d.pj, "vaddr", field->vaddr);
4086  pj_kN(state->d.pj, "paddr", field->paddr);
4087  if (field->comment && *field->comment) {
4088  pj_ks(state->d.pj, "comment", field->comment);
4089  }
4090  if (field->format && *field->format) {
4091  pj_ks(state->d.pj, "format", field->format);
4092  }
4093  char *o = rz_core_cmd_strf(core, "pfj%c%s@ 0x%" PFMT64x,
4094  field->format_named ? '.' : ' ', field->format, field->vaddr);
4095  if (o && *o) {
4096  rz_str_trim_tail(o);
4097  pj_k(state->d.pj, "pf");
4098  pj_j(state->d.pj, o);
4099  }
4100  free(o);
4101  pj_end(state->d.pj);
4102  break;
4103  case RZ_OUTPUT_MODE_TABLE:
4104  rz_table_add_rowf(state->d.t, "XsXs", field->paddr, field->name, field->vaddr, field->comment);
4105  break;
4106  case RZ_OUTPUT_MODE_QUIET:
4107  haveComment = RZ_STR_ISNOTEMPTY(field->comment);
4108  rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s%s%s\n",
4109  field->vaddr, field->paddr, field->name,
4110  haveComment ? "; " : "",
4111  haveComment ? field->comment : "");
4112  break;
4113  default:
4115  break;
4116  }
4117  }
4119  return true;
4120 }
4121 
4123  rz_return_val_if_fail(core, false);
4124 
4125  RzBinFile *cur = rz_bin_cur(core->bin);
4126  RzBinPlugin *plg = rz_bin_file_cur_plugin(cur);
4127  if (plg && plg->header) {
4128  plg->header(cur);
4129  }
4130  return true;
4131 }
4132 
4133 static int bin_trycatch(RzCore *core, PJ *pj, int mode) {
4134  RzBinFile *bf = rz_bin_cur(core->bin);
4135  RzListIter *iter;
4136  RzBinTrycatch *tc;
4138  int idx = 0;
4139  // FIXME: json mode
4140  rz_list_foreach (trycatch, iter, tc) {
4141  rz_cons_printf("f+ try.%d.%" PFMT64x ".from @ 0x%08" PFMT64x "\n", idx, tc->source, tc->from);
4142  rz_cons_printf("f+ try.%d.%" PFMT64x ".to @ 0x%08" PFMT64x "\n", idx, tc->source, tc->to);
4143  rz_cons_printf("f+ try.%d.%" PFMT64x ".catch @ 0x%08" PFMT64x "\n", idx, tc->source, tc->handler);
4144  if (tc->filter) {
4145  rz_cons_printf("f+ try.%d.%" PFMT64x ".filter @ 0x%08" PFMT64x "\n", idx, tc->source, tc->filter);
4146  }
4147  idx++;
4148  }
4149  return true;
4150 }
4151 
4152 static void bin_pe_versioninfo(RzCore *r, PJ *pj, int mode) {
4153  Sdb *sdb = NULL;
4154  int num_version = 0;
4155  int num_stringtable = 0;
4156  int num_string = 0;
4157  const char *format_version = "bin/cur/info/vs_version_info/VS_VERSIONINFO%d";
4158  const char *format_stringtable = "%s/string_file_info/stringtable%d";
4159  const char *format_string = "%s/string%d";
4160  if (!IS_MODE_JSON(mode)) {
4161  rz_cons_printf("=== VS_VERSIONINFO ===\n\n");
4162  } else {
4163  pj_o(pj);
4164  }
4165  do {
4166  char *path_version = sdb_fmt(format_version, num_version);
4167  if (!sdb_ns_path(r->sdb, path_version, 0)) {
4168  break;
4169  }
4170  if (IS_MODE_JSON(mode)) {
4171  pj_ko(pj, "VS_FIXEDFILEINFO");
4172  } else {
4173  rz_cons_printf("# VS_FIXEDFILEINFO\n\n");
4174  }
4175  const char *path_fixedfileinfo = sdb_fmt("%s/fixed_file_info", path_version);
4176  if (!(sdb = sdb_ns_path(r->sdb, path_fixedfileinfo, 0))) {
4177  if (IS_MODE_JSON(mode)) {
4178  pj_end(pj);
4179  }
4180  break;
4181  }
4182  ut32 file_version_ms = sdb_num_get(sdb, "FileVersionMS", 0);
4183  ut32 file_version_ls = sdb_num_get(sdb, "FileVersionLS", 0);
4184  char *file_version = rz_str_newf("%u.%u.%u.%u", file_version_ms >> 16, file_version_ms & 0xFFFF,
4185  file_version_ls >> 16, file_version_ls & 0xFFFF);
4186  ut32 product_version_ms = sdb_num_get(sdb, "ProductVersionMS", 0);
4187  ut32 product_version_ls = sdb_num_get(sdb, "ProductVersionLS", 0);
4188  char *product_version = rz_str_newf("%u.%u.%u.%u", product_version_ms >> 16, product_version_ms & 0xFFFF,
4189  product_version_ls >> 16, product_version_ls & 0xFFFF);
4190  if (IS_MODE_JSON(mode)) {
4191  pj_kn(pj, "Signature", sdb_num_get(sdb, "Signature", 0));
4192  pj_kn(pj, "StrucVersion", sdb_num_get(sdb, "StrucVersion", 0));
4193  pj_ks(pj, "FileVersion", file_version);
4194  pj_ks(pj, "ProductVersion", product_version);
4195  pj_kn(pj, "FileFlagsMask", sdb_num_get(sdb, "FileFlagsMask", 0));
4196  pj_kn(pj, "FileFlags", sdb_num_get(sdb, "FileFlags", 0));
4197  pj_kn(pj, "FileOS", sdb_num_get(sdb, "FileOS", 0));
4198  pj_kn(pj, "FileType", sdb_num_get(sdb, "FileType", 0));
4199  pj_kn(pj, "FileSubType", sdb_num_get(sdb, "FileSubType", 0));
4200  pj_end(pj);
4201  } else {
4202  rz_cons_printf(" Signature: 0x%" PFMT64x "\n", sdb_num_get(sdb, "Signature", 0));
4203  rz_cons_printf(" StrucVersion: 0x%" PFMT64x "\n", sdb_num_get(sdb, "StrucVersion", 0));
4204  rz_cons_printf(" FileVersion: %s\n", file_version);
4205  rz_cons_printf(" ProductVersion: %s\n", product_version);
4206  rz_cons_printf(" FileFlagsMask: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlagsMask", 0));
4207  rz_cons_printf(" FileFlags: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileFlags", 0));
4208  rz_cons_printf(" FileOS: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileOS", 0));
4209  rz_cons_printf(" FileType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileType", 0));
4210  rz_cons_printf(" FileSubType: 0x%" PFMT64x "\n", sdb_num_get(sdb, "FileSubType", 0));
4211  rz_cons_newline();
4212  }
4213  free(file_version);
4214  free(product_version);
4215 #if 0
4216  rz_cons_printf (" FileDate: %d.%d.%d.%d\n",
4217  sdb_num_get (sdb, "FileDateMS", 0) >> 16,
4218  sdb_num_get (sdb, "FileDateMS", 0) & 0xFFFF,
4219  sdb_num_get (sdb, "FileDateLS", 0) >> 16,
4220  sdb_num_get (sdb, "FileDateLS", 0) & 0xFFFF);
4221 #endif
4222  if (IS_MODE_JSON(mode)) {
4223  pj_ko(pj, "StringTable");
4224  } else {
4225  rz_cons_printf("# StringTable\n\n");
4226  }
4227  for (num_stringtable = 0; sdb; num_stringtable++) {
4228  char *path_stringtable = rz_str_newf(format_stringtable, path_version, num_stringtable);
4229  sdb = sdb_ns_path(r->sdb, path_stringtable, 0);
4230  for (num_string = 0; sdb; num_string++) {
4231  char *path_string = rz_str_newf(format_string, path_stringtable, num_string);
4232  sdb = sdb_ns_path(r->sdb, path_string, 0);
4233  if (sdb) {
4234  int lenkey = 0;
4235  int lenval = 0;
4236  ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key", 0), &lenkey);
4237  ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value", 0), &lenval);
4238  ut8 *key_utf8 = calloc(lenkey * 2, 1);
4239  ut8 *val_utf8 = calloc(lenval * 2, 1);
4240  if (rz_str_utf16_to_utf8(key_utf8, lenkey * 2, key_utf16, lenkey, true) < 0 || rz_str_utf16_to_utf8(val_utf8, lenval * 2, val_utf16, lenval, true) < 0) {
4241  eprintf("Warning: Cannot decode utf16 to utf8\n");
4242  } else if (IS_MODE_JSON(mode)) {
4243  pj_ks(pj, (char *)key_utf8, (char *)val_utf8);
4244  } else {
4245  rz_cons_printf(" %s: %s\n", (char *)key_utf8, (char *)val_utf8);
4246  }
4247  free(key_utf8);
4248  free(val_utf8);
4249  free(key_utf16);
4250  free(val_utf16);
4251  }
4252  free(path_string);
4253  }
4254  free(path_stringtable);
4255  }
4256  if (IS_MODE_JSON(mode)) {
4257  pj_end(pj);
4258  }
4259  num_version++;
4260  } while (sdb);
4261  if (IS_MODE_JSON(mode)) {
4262  pj_end(pj);
4263  }
4264 }
4265 
4266 static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode) {
4267  Sdb *sdb = sdb_ns_path(r->sdb, "bin/cur/info/versioninfo/versym", 0);
4268  if (!sdb) {
4269  return;
4270  }
4271 
4272  if (IS_MODE_JSON(mode)) {
4273  pj_ka(pj, "versym"); // "versym": [
4274  }
4275 
4276  const ut64 addr = sdb_num_get(sdb, "addr", 0);
4277  const ut64 offset = sdb_num_get(sdb, "offset", 0);
4278  const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0);
4279 
4280  if (IS_MODE_JSON(mode)) {
4281  pj_o(pj); // {
4282  pj_kn(pj, "address", addr);
4283  pj_kn(pj, "offset", offset);
4284  pj_ka(pj, "entries"); // "entries": [
4285  } else {
4286  rz_cons_printf("Version symbols has %" PFMT64u " entries:\n", num_entries);
4287  rz_cons_printf(" Addr: 0x%08" PFMT64x " Offset: 0x%08" PFMT64x "\n",
4288  (ut64)addr, (ut64)offset);
4289  }
4290 
4291  for (size_t i = 0; i < num_entries; i++) {
4292  const char *const key = sdb_fmt("entry%zu", i);
4293  const char *const value = sdb_const_get(sdb, key, 0);
4294 
4295  if (!value) {
4296  continue;
4297  }
4298 
4299  if (IS_MODE_JSON(mode)) {
4300  pj_o(pj);
4301  pj_kn(pj, "idx", (ut64)i);
4302  pj_ks(pj, "value", value);
4303  pj_end(pj);
4304  } else {
4305  rz_cons_printf(" 0x%08" PFMT64x ": ", (ut64)i);
4306  rz_cons_printf("%s\n", value);
4307  }
4308  }
4309 
4310  if (IS_MODE_JSON(mode)) {
4311  pj_end(pj); // ] entries
4312  pj_end(pj); // }
4313  pj_end(pj); // ] versym
4314  } else {
4315  rz_cons_printf("\n\n");
4316  }
4317 }
4318 
4319 static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode) {
4320  Sdb *sdb = sdb_ns_path(r->sdb, "bin/cur/info/versioninfo/verneed", 0);
4321  if (!sdb) {
4322  return;
4323  }
4324 
4325  if (IS_MODE_JSON(mode)) {
4326  pj_ka(pj, "verneed"); // "verneed": 1[
4327  }
4328 
4329  const ut64 address = sdb_num_get(sdb, "addr", 0);
4330  const ut64 offset = sdb_num_get(sdb, "offset", 0);
4331 
4332  if (IS_MODE_JSON(mode)) {
4333  pj_o(pj); // 1{
4334  pj_kn(pj, "address", address);
4335  pj_kn(pj, "offset", offset);
4336  pj_ka(pj, "entries"); // "entries": 2[
4337  } else {
4338  rz_cons_printf("Version need has %d entries:\n",
4339  (int)sdb_num_get(sdb, "num_entries", 0));
4340 
4341  rz_cons_printf(" Addr: 0x%08" PFMT64x, address);
4342 
4343  rz_cons_printf(" Offset: 0x%08" PFMT64x "\n", offset);
4344  }
4345 
4346  for (size_t num_version = 0;; num_version++) {
4347  const char *filename = NULL;
4348  int num_vernaux = 0;
4349 
4350  char *path_version = sdb_fmt("bin/cur/info/versioninfo/verneed/version%zu", num_version);
4351  sdb = sdb_ns_path(r->sdb, path_version, 0);
4352 
4353  if (!sdb) {
4354  break;
4355  }
4356 
4357  if (IS_MODE_JSON(mode)) {
4358  pj_o(pj); // 2{
4359  pj_kn(pj, "idx", sdb_num_get(sdb, "idx", 0));
4360  pj_ki(pj, "vn_version", (int)sdb_num_get(sdb, "vn_version", 0));
4361  } else {
4362  rz_cons_printf(" 0x%08" PFMT64x ": Version: %d",
4363  sdb_num_get(sdb, "idx", 0), (int)sdb_num_get(sdb, "vn_version", 0));
4364  }
4365 
4366  if ((filename = sdb_const_get(sdb, "file_name", 0))) {
4367  if (IS_MODE_JSON(mode)) {
4368  pj_ks(pj, "file_name", filename);
4369  } else {
4370  rz_cons_printf(" File: %s", filename);
4371  }
4372  }
4373 
4374  const int cnt = (int)sdb_num_get(sdb, "cnt", 0);
4375 
4376  if (IS_MODE_JSON(mode)) {
4377  pj_ki(pj, "cnt", cnt);
4378  } else {
4379  rz_cons_printf(" Cnt: %d\n", cnt);
4380  }
4381 
4382  if (IS_MODE_JSON(mode)) {
4383  pj_ka(pj, "vernaux"); // "vernaux": 3[
4384  }
4385 
4386  do {
4387  const char *const path_vernaux = sdb_fmt("%s/vernaux%d", path_version, num_vernaux++);
4388 
4389  sdb = sdb_ns_path(r->sdb, path_vernaux, 0);
4390  if (!sdb) {
4391  break;
4392  }
4393 
4394  const ut64 idx = sdb_num_get(sdb, "idx", 0);
4395  const char *const name = sdb_const_get(sdb, "name", 0);
4396  const char *const flags = sdb_const_get(sdb, "flags", 0);
4397  const int version = (int)sdb_num_get(sdb, "version", 0);
4398 
4399  if (IS_MODE_JSON(mode)) {
4400  pj_o(pj);
4401  pj_kn(pj, "idx", idx);
4402  pj_ks(pj, "name", name);
4403  pj_ks(pj, "flags", flags);
4404  pj_ki(pj, "version", version);
4405  pj_end(pj);
4406  } else {
4407  rz_cons_printf(" 0x%08" PFMT64x ": Name: %s", idx, name);
4408  rz_cons_printf(" Flags: %s Version: %d\n", flags, version);
4409  }
4410  } while (sdb);
4411 
4412  if (IS_MODE_JSON(mode)) {
4413  pj_end(pj); // 3] vernaux
4414  pj_end(pj); // 2}
4415  }
4416  }
4417 
4418  if (IS_MODE_JSON(mode)) {
4419  pj_end(pj); // 2] entries
4420  pj_end(pj); // 1}
4421  pj_end(pj); // 1] verneed
4422  }
4423 }
4424 
4425 static void bin_elf_versioninfo(RzCore *r, PJ *pj, int mode) {
4426  if (IS_MODE_JSON(mode)) {
4427  pj_o(pj);
4428  }
4431  if (IS_MODE_JSON(mode)) {
4432  pj_end(pj);
4433  }
4434 }
4435 
4436 static void bin_mach0_versioninfo(RzCore *r, PJ *pj, int mode) {
4437  /* TODO */
4438  if (IS_MODE_JSON(mode)) {
4439  pj_o(pj);
4440  pj_end(pj);
4441  }
4442 }
4443 
4444 static int bin_versioninfo(RzCore *r, PJ *pj, int mode) {
4445  const RzBinInfo *info = rz_bin_get_info(r->bin);
4446  if (!info || !info->rclass) {
4447  return false;
4448  }
4449  if (!strncmp("pe", info->rclass, 2)) {
4450  bin_pe_versioninfo(r, pj, mode);
4451  } else if (!strncmp("elf", info->rclass, 3)) {
4452  bin_elf_versioninfo(r, pj, mode);
4453  } else if (!strncmp("mach0", info->rclass, 5)) {
4455  } else {
4456  if (IS_MODE_JSON(mode)) {
4457  pj_o(pj);
4458  pj_end(pj);
4459  } else {
4460  rz_cons_println("Unknown format");
4461  }
4462  return false;
4463  }
4464  return true;
4465 }
4466 
4467 RZ_API int rz_core_bin_set_arch_bits(RzCore *r, const char *name, const char *arch, ut16 bits) {
4468  int fd = rz_io_fd_get_current(r->io);
4469  RzIODesc *desc = rz_io_desc_get(r->io, fd);
4470  RzBinFile *curfile, *binfile = NULL;
4471  if (!name) {
4472  if (!desc || !desc->name) {
4473  return false;
4474  }
4475  name = desc->name;
4476  }
4477  /* Check if the arch name is a valid name */
4478  if (!rz_asm_is_valid(r->rasm, arch)) {
4479  return false;
4480  }
4481  /* Find a file with the requested name/arch/bits */
4482  binfile = rz_bin_file_find_by_arch_bits(r->bin, arch, bits);
4483  if (!binfile) {
4484  return false;
4485  }
4486  if (!rz_bin_use_arch(r->bin, arch, bits, name)) {
4487  return false;
4488  }
4489  curfile = rz_bin_cur(r->bin);
4490  // set env if the binfile changed or we are dealing with xtr
4491  if (curfile != binfile || binfile->curxtr) {
4492  rz_core_bin_set_cur(r, binfile);
4493  if (binfile->o && binfile->o->info) {
4494  free(binfile->o->info->arch);
4495  binfile->o->info->arch = strdup(arch);
4496  binfile->o->info->bits = bits;
4497  }
4498  return rz_core_bin_apply_all_info(r, binfile);
4499  }
4500  return true;
4501 }
4502 
4504  RzBinFile *binfile = NULL;
4505  const char *name = NULL, *arch = NULL;
4506  ut16 bits = 0;
4507  if (!r) {
4508  return 0;
4509  }
4510  if (r->rasm) {
4511  bits = r->rasm->bits;
4512  if (r->rasm->cur) {
4513  arch = r->rasm->cur->arch;
4514  }
4515  }
4516  binfile = rz_bin_cur(r->bin);
4517  name = binfile ? binfile->file : NULL;
4518  if (binfile && binfile->curxtr) {
4519  rz_analysis_hint_clear(r->analysis);
4520  }
4522 }
4523 
4525  if (!rz_bin_select_bfid(core->bin, bfid)) {
4526  return false;
4527  }
4528  RzBinFile *bf = rz_bin_cur(core->bin);
4529  if (bf) {
4530  rz_io_use_fd(core->io, bf->fd);
4531  }
4532  return bf && rz_core_bin_apply_all_info(core, bf) && rz_core_block_read(core);
4533 }
4534 
4543  rz_bin_file_delete(core->bin, bf);
4544  bf = rz_bin_file_at(core->bin, core->offset);
4545  if (bf) {
4546  rz_io_use_fd(core->io, bf->fd);
4547  }
4548  return bf && rz_core_bin_apply_all_info(core, bf) && rz_core_block_read(core);
4549 }
4550 
4552  rz_return_if_fail(core && bf && bf->o);
4553 
4554  const char *name = bf ? bf->file : NULL;
4555  (void)rz_bin_get_info(core->bin); // XXX is this necssary for proper iniitialization
4556  ut32 bin_sz = bf ? bf->size : 0;
4557  RzBinObject *obj = bf->o;
4558  RzBinInfo *info = obj->info;
4559  ut8 bits = info ? info->bits : 0;
4560  const char *asmarch = rz_config_get(core->config, "asm.arch");
4561  const char *arch = info ? info->arch ? info->arch : asmarch : "unknown";
4562 
4563  switch (state->mode) {
4564  case RZ_OUTPUT_MODE_QUIET:
4565  rz_cons_printf("%d\n", bf->id);
4566  break;
4567  case RZ_OUTPUT_MODE_JSON:
4568  pj_o(state->d.pj);
4569  pj_ks(state->d.pj, "name", name ? name : "");
4570  pj_ki(state->d.pj, "iofd", bf->fd);
4571  pj_ki(state->d.pj, "bfid", bf->id);
4572  pj_ki(state->d.pj, "size", bin_sz);
4573  pj_ko(state->d.pj, "obj");
4574  pj_ks(state->d.pj, "arch", arch);
4575  pj_ki(state->d.pj, "bits", bits);
4576  pj_kN(state->d.pj, "binoffset", obj->boffset);
4577  pj_kN(state->d.pj, "objsize", obj->obj_size);
4578  pj_end(state->d.pj);
4579  pj_end(state->d.pj);
4580  break;
4582  rz_cons_printf("%d %d %s-%d ba:0x%08" PFMT64x " sz:%" PFMT64d " %s\n",
4583  bf->id, bf->fd, arch, bits, bf->o->opts.baseaddr, bf->o->size, name);
4584  break;
4585  case RZ_OUTPUT_MODE_TABLE:
4586  rz_table_add_rowf(state->d.t, "ddsXxs", bf->id, bf->fd,
4587  arch, bf->o->opts.baseaddr, bf->o->size, name);
4588  break;
4589  default:
4591  break;
4592  }
4593 }
4594 
4604  rz_return_val_if_fail(core && state, false);
4605 
4606  RzListIter *iter;
4607  RzBinFile *binfile = NULL;
4608  const RzList *binfiles = core->bin ? core->bin->binfiles : NULL;
4610  rz_cmd_state_output_set_columnsf(state, "ddsXxs", "id", "fd", "arch", "baddr", "size", "name");
4611  rz_list_foreach (binfiles, iter, binfile) {
4612  core_bin_file_print(core, binfile, state);
4613  }
4615  return true;
4616 }
4617 
4619  for (int i = 0; flags; flags >>= 1, i++) {
4620  if (!(flags & 1)) {
4621  continue;
4622  }
4623  const char *flag_string = rz_bin_get_meth_flag_string(1ULL << i, false);
4624  if (flag_string) {
4625  rz_strbuf_appendf(buf, ".%s", flag_string);
4626  }
4627  }
4628 }
4629 
4636  char *ret = NULL;
4637  if (!cls->name) {
4638  return NULL;
4639  }
4640 
4641  if (cls->visibility_str) {
4642  char *copy = strdup(cls->visibility_str);
4643  rz_str_replace_ch(copy, ' ', '.', 1);
4644  ret = rz_str_newf("class.%s.%s", copy, cls->name);
4645  free(copy);
4646  } else {
4647  ret = rz_str_newf("class.public.%s", cls->name);
4648  }
4649  rz_name_filter(ret, -1, true);
4650  return ret;
4651 }
4652 
4659  char *ret = NULL;
4660  if (!cls->name || !cls->super) {
4661  return NULL;
4662  }
4663 
4664  if (cls->visibility_str) {
4665  char *copy = strdup(cls->visibility_str);
4666  rz_str_replace_ch(copy, ' ', '.', 1);
4667  ret = rz_str_newf("super.%s.%s.%s", copy, cls->name, cls->super);
4668  free(copy);
4669  } else {
4670  ret = rz_str_newf("super.public.%s.%s", cls->name, cls->super);
4671  }
4672  rz_name_filter(ret, -1, true);
4673  return ret;
4674 }
4675 
4681  rz_return_val_if_fail(cls && meth, NULL);
4682  if (!cls->name || !meth->name) {
4683  return NULL;
4684  }
4685 
4686  RzStrBuf buf;
4687  rz_strbuf_initf(&buf, "method");
4688 
4689  if (meth->visibility_str) {
4690  char *copy = strdup(meth->visibility_str);
4691  rz_str_replace_ch(copy, ' ', '.', 1);
4692  rz_strbuf_appendf(&buf, ".%s", copy);
4693  free(copy);
4694  } else {
4695  resolve_method_flags(&buf, meth->method_flags);
4696  }
4697  const char *mn = meth->dname ? meth->dname : meth->name;
4698  rz_strbuf_appendf(&buf, ".%s.%s", cls->name, mn);
4699  char *ret = rz_strbuf_drain_nofree(&buf);
4700  rz_name_filter(ret, -1, true);
4701  return ret;
4702 }
4703 
4709  rz_return_val_if_fail(cls && field, NULL);
4710  if (!cls->name || !field->name) {
4711  return NULL;
4712  }
4713 
4714  RzStrBuf buf;
4715  rz_strbuf_initf(&buf, "field");
4716 
4717  if (field->visibility_str) {
4718  char *copy = strdup(field->visibility_str);
4719  rz_str_replace_ch(copy, ' ', '.', 1);
4720  rz_strbuf_appendf(&buf, ".%s", copy);
4721  free(copy);
4722  } else {
4723  resolve_method_flags(&buf, field->flags);
4724  }
4725  rz_strbuf_appendf(&buf, ".%s.%s", cls->name, field->name);
4726  char *ret = rz_strbuf_drain_nofree(&buf);
4727  rz_name_filter(ret, -1, true);
4728  return ret;
4729 }
4730 
4732  int i;
4733 
4734  RzStrBuf *buf = rz_strbuf_new("");
4735  if (IS_MODE_JSON(mode)) {
4736  if (!flags) {
4737  rz_strbuf_append(buf, "[]");
4738  goto out;
4739  }
4740  PJ *pj = pj_new();
4741  pj_a(pj);
4742  for (i = 0; i < 64; i++) {
4743  ut64 flag = flags & (1ULL << i);
4744  if (flag) {
4745  const char *flag_string = rz_bin_get_meth_flag_string(flag, false);
4746  if (flag_string) {
4747  pj_s(pj, flag_string);
4748  } else {
4749  pj_s(pj, sdb_fmt("0x%08" PFMT64x, flag));
4750  }
4751  }
4752  }
4753  pj_end(pj);
4755  pj_free(pj);
4756  } else {
4757  int pad_len = 4; // TODO: move to a config variable
4758  int len = 0;
4759  if (!flags) {
4760  goto padding;
4761  }
4762  for (i = 0; i < 64; i++) {
4763  ut64 flag = flags & (1ULL << i);
4764  if (flag) {
4765  const char *flag_string = rz_bin_get_meth_flag_string(flag, true);
4766  if (flag_string) {
4767  rz_strbuf_append(buf, flag_string);
4768  } else {
4769  rz_strbuf_append(buf, "?");
4770  }
4771  len++;
4772  }
4773  }
4774  padding:
4775  for (; len < pad_len; len++) {
4776  rz_strbuf_append(buf, " ");
4777  }
4778  }
4779 out:
4780  return rz_strbuf_drain(buf);
4781 }
4782 
4785 
4786  rz_cmd_state_output_set_columnsf(state, "sss", "type", "name", "description");
4787 
4788  switch (state->mode) {
4789  case RZ_OUTPUT_MODE_QUIET:
4790  rz_cons_printf("%s\n", bp->name);
4791  break;
4792  case RZ_OUTPUT_MODE_JSON:
4793  pj_o(state->d.pj);
4794  pj_ks(state->d.pj, "name", bp->name);
4795  pj_ks(state->d.pj, "description", bp->desc);
4796  if (bp->license) {
4797  pj_ks(state->d.pj, "license", bp->license);
4798  }
4799  if (bp->version) {
4800  pj_ks(state->d.pj, "version", bp->version);
4801  }
4802  if (bp->license) {
4803  pj_ks(state->d.pj, "author", bp->license);
4804  }
4805  pj_end(state->d.pj);
4806  break;
4808  rz_cons_printf("bin %-11s %s (%s) %s %s\n",
4809  bp->name, bp->desc, bp->license ? bp->license : "???",
4810  bp->version ? bp->version : "",
4811  bp->author ? bp->author : "");
4812  break;
4813  case RZ_OUTPUT_MODE_TABLE:
4814  rz_table_add_rowf(state->d.t, "sss", "bin", bp->name, bp->desc);
4815  break;
4816  default:
4819  }
4820  return RZ_CMD_STATUS_OK;
4821 }
4822 
4825 
4826  const char *name = NULL;
4827 
4828  rz_cmd_state_output_set_columnsf(state, "sss", "type", "name", "description");
4829  switch (state->mode) {
4830  case RZ_OUTPUT_MODE_QUIET:
4831  rz_cons_printf("%s\n", bx->name);
4832  break;
4833  case RZ_OUTPUT_MODE_JSON:
4834  pj_o(state->d.pj);
4835  pj_ks(state->d.pj, "name", bx->name);
4836  pj_ks(state->d.pj, "description", bx->desc);
4837  pj_ks(state->d.pj, "license", bx->license ? bx->license : "???");
4838  pj_end(state->d.pj);
4839  break;
4841  name = strncmp(bx->name, "xtr.", 4) ? bx->name : bx->name + 3;
4842  rz_cons_printf("xtr %-11s %s (%s)\n", name,
4843  bx->desc, bx->license ? bx->license : "???");
4844  break;
4845  case RZ_OUTPUT_MODE_TABLE:
4846  rz_table_add_rowf(state->d.t, "sss", "xtr", bx->name, bx->desc);
4847  break;
4848  default:
4851  }
4852  return RZ_CMD_STATUS_OK;
4853 }
4854 
4857 
4858  RzBinPlugin *bp;
4859  RzBinXtrPlugin *bx;
4860  RzListIter *iter;
4862 
4864  rz_list_foreach (bin->plugins, iter, bp) {
4866  if (status != RZ_CMD_STATUS_OK) {
4867  return status;
4868  }
4869  }
4870  rz_list_foreach (bin->binxtrs, iter, bx) {
4872  if (status != RZ_CMD_STATUS_OK) {
4873  return status;
4874  }
4875  }
4877  return RZ_CMD_STATUS_OK;
4878 }
4879 
4881  rz_return_val_if_fail(core && state, false);
4882 
4883  return bin_dwarf(core, bf, state);
4884 }
4885 
4887  RzBinInfo *info = rz_bin_get_info(core->bin);
4888  /* Autodetect local file */
4889  if (!info || !info->debug_file_name) {
4890  return NULL;
4891  }
4892  // Check raw path for debug filename
4893  bool file_found = rz_file_exists(info->debug_file_name);
4894  if (file_found) {
4895  return strdup(info->debug_file_name);
4896  }
4897  // Check debug filename basename in current directory
4899  file_found = rz_file_exists(basename);
4900  if (file_found) {
4901  return strdup(basename);
4902  }
4903  // Check if debug file is in file directory
4904  char *dir = rz_file_dirname(core->bin->cur->file);
4905  char *filename = rz_str_newf("%s/%s", dir, basename);
4906  free(dir);
4907  file_found = rz_file_exists(filename);
4908  if (file_found) {
4909  return filename;
4910  }
4911  free(filename);
4912 
4913  // Last chance: Check if file is in downstream symbol store
4914  const char *symstore_path = rz_config_get(core->config, "pdb.symstore");
4915  return rz_str_newf("%s" RZ_SYS_DIR "%s" RZ_SYS_DIR "%s" RZ_SYS_DIR "%s",
4916  symstore_path, basename, info->guid, basename);
4917 }
4918 
4919 static void bin_memory_print_rec(RzCmdStateOutput *state, RzBinMem *mirror, const RzList *mems, int perms) {
4920  RzListIter *it;
4921  RzBinMem *mem;
4922 
4923  rz_list_foreach (mems, it, mem) {
4924  switch (state->mode) {
4925  case RZ_OUTPUT_MODE_JSON:
4926  pj_o(state->d.pj);
4927  pj_ks(state->d.pj, "name", mem->name);
4928  pj_ki(state->d.pj, "size", mem->size);
4929  pj_kn(state->d.pj, "address", mem->addr);
4930  pj_ks(state->d.pj, "flags", rz_str_rwx_i(mem->perms & perms));
4931  if (mirror) {
4932  pj_ks(state->d.pj, "mirror", mirror->name);
4933  }
4934  pj_end(state->d.pj);
4935  break;
4936  case RZ_OUTPUT_MODE_TABLE:
4937  rz_table_add_rowf(state->d.t, "sxXss", mem->name, mem->size,
4938  mem->addr, rz_str_rwx_i(mem->perms & perms),
4939  mirror ? mirror->name : "");
4940  break;
4941  case RZ_OUTPUT_MODE_QUIET:
4942  rz_cons_printf("0x%08" PFMT64x "\n", mem->addr);
4943  break;
4944  default:
4946  break;
4947  }
4948 
4949  if (mem->mirrors) {
4950  bin_memory_print_rec(state, mem, mem->mirrors, mem->perms & perms);
4951  }
4952  }
4953 }
4954 
4956  rz_return_val_if_fail(core && bf && bf->o && state, false);
4957 
4959  rz_cmd_state_output_set_columnsf(state, "sxXss", "name", "size", "address", "flags", "mirror");
4960 
4961  const RzList *mems = rz_bin_object_get_mem(bf->o);
4962  bin_memory_print_rec(state, NULL, mems, 7);
4964  return true;
4965 }
4966 
4967 static void bin_resources_print_standard(RzCore *core, RzList *hashes, RzBinResource *resource) {
4968  char humansz[8];
4969  rz_num_units(humansz, sizeof(humansz), resource->size);
4970  rz_cons_printf("Resource %zd\n", resource->index);
4971  rz_cons_printf(" name: %s\n", resource->name);
4972  rz_cons_printf(" timestamp: %s\n", resource->time);
4973  rz_cons_printf(" vaddr: 0x%08" PFMT64x "\n", resource->vaddr);
4974  rz_cons_printf(" size: %s\n", humansz);
4975  rz_cons_printf(" type: %s\n", resource->type);
4976  rz_cons_printf(" language: %s\n", resource->language);
4977  if (hashes && resource->size > 0) {
4978  HtPP *digests = rz_core_bin_create_digests(core, resource->vaddr, resource->size, hashes);
4979  if (!digests) {
4980  return;
4981  }
4982  RzListIter *it = NULL;
4983  char *hash = NULL;
4984  bool found = false;
4985  rz_list_foreach (hashes, it, hash) {
4986  char *digest = ht_pp_find(digests, hash, &found);
4987  if (found) {
4988  rz_cons_printf(" %s: %s\n", hash, digest);
4989  }
4990  }
4991  ht_pp_free(digests);
4992  }
4993 }
4994 
4996  rz_table_add_rowf(state->d.t, "dssXxss", resource->index, resource->name,
4997  resource->type, resource->vaddr, resource->size, resource->language, resource->time);
4998  if (hashes && resource->size > 0) {
4999  HtPP *digests = rz_core_bin_create_digests(core, resource->vaddr, resource->size, hashes);
5000  if (!digests) {
5001  return;
5002  }
5003  RzListIter *it;
5004  char *hash;
5005  bool found = false;
5006  rz_list_foreach (hashes, it, hash) {
5007  char *digest = ht_pp_find(digests, hash, &found);
5008  if (found && state->d.t) {
5009  rz_table_add_row_columnsf(state->d.t, "s", digest);
5010  }
5011  }
5012  ht_pp_free(digests);
5013  }
5014 }
5015 
5016 static void bin_resources_print_json(RzCore *core, RzCmdStateOutput *state, RzList *hashes, RzBinResource *resource) {
5017  pj_o(state->d.pj);
5018  pj_ks(state->d.pj, "name", resource->name);
5019  pj_ki(state->d.pj, "index", resource->index);
5020  pj_ks(state->d.pj, "type", resource->type);
5021  pj_kn(state->d.pj, "vaddr", resource->vaddr);
5022  pj_ki(state->d.pj, "size", resource->size);
5023  pj_ks(state->d.pj, "lang", resource->language);
5024  pj_ks(state->d.pj, "timestamp", resource->time);
5025  if (hashes && resource->size > 0) {
5026  HtPP *digests = rz_core_bin_create_digests(core, resource->vaddr, resource->size, hashes);
5027  if (!digests) {
5028  goto end;
5029  }
5030  RzListIter *it;
5031  char *hash;
5032  bool found = false;
5033  rz_list_foreach (hashes, it, hash) {
5034  char *digest = ht_pp_find(digests, hash, &found);
5035  if (found && state->d.pj) {
5036  pj_ks(state->d.pj, hash, digest);
5037  }
5038  }
5039  ht_pp_free(digests);
5040  }
5041 end:
5042  pj_end(state->d.pj);
5043 }
5044 
5046  rz_return_val_if_fail(core && state && bf, false);
5047  RzBinResource *resource = NULL;
5048  RzListIter *it = NULL;
5049  char *hashname = NULL;
5050 
5052  rz_cmd_state_output_set_columnsf(state, "dssXxss", "index", "name", "type", "vaddr", "size", "lang", "timestamp");
5053 
5054  rz_list_foreach (hashes, it, hashname) {
5055  const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(core->hash, hashname);
5056  if (msg_plugin) {
5057  rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
5058  }
5059  }
5060 
5061  const RzList *resources = rz_bin_object_get_resources(bf->o);
5062 
5063  rz_list_foreach (resources, it, resource) {
5064  switch (state->mode) {
5066  bin_resources_print_standard(core, hashes, resource);
5067  break;
5068  case RZ_OUTPUT_MODE_TABLE:
5069  bin_resources_print_table(core, state, hashes, resource);
5070  break;
5071  case RZ_OUTPUT_MODE_JSON:
5072  bin_resources_print_json(core, state, hashes, resource);
5073  break;
5074  default:
5076  break;
5077  }
5078  }
5079 
5081  return true;
5082 }
5083 
5085  rz_return_val_if_fail(core && state, false);
5086 
5087  // TODO: add rz_bin_object_get_versions and switch to table + json output
5088  switch (state->mode) {
5091  break;
5092  case RZ_OUTPUT_MODE_JSON:
5093  bin_versioninfo(core, state->d.pj, RZ_MODE_JSON);
5094  break;
5095  default:
5097  break;
5098  }
5099  return true;
5100 }
5101 
5103  rz_return_val_if_fail(core && state, false);
5104 
5105  // TODO: add rz_bin_object_get_trycatch and switch to table + json output
5106  switch (state->mode) {
5107  case RZ_OUTPUT_MODE_RIZIN:
5109  break;
5110  default:
5112  break;
5113  }
5114  return true;
5115 }
5116 
5118  rz_return_val_if_fail(core && bf && bf->o && state, false);
5120 
5122  if (!maps) {
5123  return false;
5124  }
5125 
5126  rz_cmd_state_output_set_columnsf(state, "ss", "Segment", "Sections");
5128 
5132  const char *space = "";
5133  void **it;
5134 
5135  rz_table_add_rowf(state->d.t, "s", map->segment->name);
5136 
5137  rz_pvector_foreach (&map->sections, it) {
5138  RzBinSection *sect = *(RzBinSection **)it;
5139  rz_strbuf_appendf(sb, "%s%s", space, sect->name);
5140  space = " ";
5141  }
5143  rz_strbuf_free(sb);
5144  }
5146 
5148  return true;
5149 }
5150 
5152  rz_return_val_if_fail(core && state, false);
5153 
5154  ut64 size = rz_bin_get_size(core->bin);
5155  switch (state->mode) {
5156  case RZ_OUTPUT_MODE_JSON:
5157  pj_n(state->d.pj, size);
5158  break;
5159  case RZ_OUTPUT_MODE_RIZIN:
5160  rz_cons_printf("f bin_size @ %" PFMT64u "\n", size);
5161  break;
5163  rz_cons_printf("%" PFMT64u "\n", size);
5164  break;
5165  default:
5167  break;
5168  }
5169  return true;
5170 }
5171 
5172 struct arch_ctx {
5175  const char *arch;
5176  int bits;
5177  const char *machine;
5178 };
5179 
5180 static void print_arch(RzBin *bin, RzCmdStateOutput *state, struct arch_ctx *ctx, const char *flag, RzBinInfo *info) {
5181  char str_fmt[30];
5182  const char *fmt = "Xnss";
5183 
5184  switch (state->mode) {
5185  case RZ_OUTPUT_MODE_QUIET:
5186  rz_cons_printf("%s\n", ctx->arch);
5187  break;
5188  case RZ_OUTPUT_MODE_JSON:
5189  pj_o(state->d.pj);
5190  pj_ks(state->d.pj, "arch", ctx->arch);
5191  pj_ki(state->d.pj, "bits", ctx->bits);
5192  pj_kn(state->d.pj, "offset", ctx->offset);
5193  pj_kn(state->d.pj, "size", ctx->size);
5194  if (info && !strcmp(ctx->arch, "mips")) {
5195  pj_ks(state->d.pj, "isa", info->cpu);
5196  pj_ks(state->d.pj, "features", info->features);
5197  }
5198  if (ctx->machine) {
5199  pj_ks(state->d.pj, "machine", ctx->machine);
5200  }
5201  pj_end(state->d.pj);
5202  break;
5203  case RZ_OUTPUT_MODE_TABLE:
5204  if (flag && strcmp(flag, "unknown_flag")) {
5205  rz_strf(str_fmt, "%s_%i %s", ctx->arch, ctx->bits, flag);
5206  } else {
5207  rz_strf(str_fmt, "%s_%i", ctx->arch, ctx->bits);
5208  }
5209  rz_table_add_rowf(state->d.t, fmt, ctx->offset, ctx->size, str_fmt, ctx->machine);
5210  break;
5211  default:
5213  break;
5214  }
5215 }
5216 
5218  rz_return_val_if_fail(bin && state, false);
5219 
5220  RzBinFile *binfile = rz_bin_cur(bin);
5221  if (!binfile) {
5222  return false;
5223  }
5224 
5225  const char *fmt = "Xnss";
5227  rz_cmd_state_output_set_columnsf(state, fmt, "offset", "size", "arch", "machine", NULL);
5228 
5229  if (binfile->curxtr) {
5230  RzListIter *iter_xtr;
5231  RzBinXtrData *xtr_data;
5232  rz_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) {
5233  if (!xtr_data || !xtr_data->metadata ||
5234  !xtr_data->metadata->arch) {
5235  continue;
5236  }
5237  struct arch_ctx ctx = { 0 };
5238  ctx.offset = xtr_data->offset;
5239  ctx.size = xtr_data->size;
5240  ctx.arch = xtr_data->metadata->arch;
5241  ctx.bits = xtr_data->metadata->bits;
5242  ctx.machine = xtr_data->metadata->machine;
5243 
5244  print_arch(bin, state, &ctx, NULL, NULL);
5245  }
5246  } else {
5247  RzBinObject *obj = binfile->o;
5248  RzBinInfo *info = obj->info;
5249  struct arch_ctx ctx = { 0 };
5250  ctx.offset = obj->boffset;
5251  ctx.size = obj->obj_size;
5252  ctx.arch = info ? info->arch : "unk_0";
5253  ctx.bits = info ? info->bits : 0;
5254  ctx.machine = info ? info->machine : "unknown_machine";
5255 
5256  const char *h_flag = info ? info->head_flag : NULL;
5257  print_arch(bin, state, &ctx, h_flag, info);
5258  }
5259 
5261  return true;
5262 }
5263 
5265  rz_cons_push();
5266  RzPdb *pdb = rz_core_pdb_load_info(core, filename);
5267  if (!pdb) {
5268  return false;
5269  }
5270  rz_bin_pdb_free(pdb);
5271  const char *buf = rz_cons_get_buffer();
5272  if (!buf) {
5273  rz_cons_pop();
5274  return false;
5275  }
5276  char *s = strdup(buf);
5277  rz_cons_pop();
5278  if (!s) {
5279  return false;
5280  }
5281 
5283  free(s);
5284  return status == RZ_CMD_STATUS_OK;
5285 }
size_t len
Definition: 6502dis.c:15
const aarch64_field fields[]
Definition: aarch64-opc.c:205
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
#define mask()
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index ** i
Definition: index.h:629
#define R(x, b, m)
Definition: arc.h:168
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
static RzILOpEffect * cls(cs_insn *insn)
Definition: arm_il64.c:915
ut16 val
Definition: armass64_const.h:6
static bool err
Definition: armass.c:435
RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name)
Definition: asm.c:349
RZ_API bool rz_asm_use(RzAsm *a, const char *name)
Puts an Asm plugin in use and disables the previous one.
Definition: asm.c:429
RZ_API ut8 * sdb_decode(const char *in, int *len)
Definition: base64.c:37
RZ_API RZ_OWN RzList * rz_basefind(RZ_NONNULL RzCore *core, RZ_NONNULL RzBaseFindOpt *options)
Calculates a list of possible base addresses candidates using the strings position.
Definition: basefind.c:336
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API bool rz_bin_file_set_cur_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:258
RZ_API RzBinFile * rz_bin_file_find_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:226
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_API RzBinFile * rz_bin_file_find_by_arch_bits(RzBin *bin, const char *arch, int bits)
Definition: bfile.c:163
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
Definition: bfile.c:348
RZ_API bool rz_bin_file_set_cur_by_name(RzBin *bin, const char *name)
Definition: bfile.c:293
RZ_API RzList * rz_bin_file_get_trycatch(RZ_NONNULL RzBinFile *bf)
Definition: bfile.c:564
RZ_API RZ_OWN RzList * rz_bin_file_strings(RZ_NONNULL RzBinFile *bf, size_t min_length, bool raw_strings)
Generates a RzList struct containing RzBinString from a given RzBinFile.
Definition: bfile_string.c:325
RZ_API bool rz_bin_string_filter(RzBin *bin, const char *str, int len, ut64 addr)
Definition: filter.c:385
RZ_API const char * rz_bin_entry_type_string(int etype)
Definition: bin.c:912
RZ_DEPRECATE RZ_API RZ_BORROW RzBinInfo * rz_bin_get_info(RzBin *bin)
Definition: bin.c:585
RZ_API ut64 rz_bin_get_laddr(RzBin *bin)
Definition: bin.c:542
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API ut64 rz_bin_get_size(RzBin *bin)
Definition: bin.c:889
RZ_API RZ_OWN RzList * rz_bin_section_flag_to_list(RzBin *bin, ut64 flag)
Converts the RzBinSection flags to a list of string representations.
Definition: bin.c:1151
RZ_API RzBinFile * rz_bin_file_at(RzBin *bin, ut64 at)
Definition: bin.c:1160
RZ_API const char * rz_bin_symbol_name(RzBinSymbol *s)
Definition: bin.c:158
RZ_DEPRECATE RZ_API int rz_bin_is_static(RZ_NONNULL RzBin *bin)
Definition: bin.c:708
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
Definition: bin.c:696
RZ_API bool rz_bin_select_bfid(RzBin *bin, ut32 bf_id)
Definition: bin.c:833
RZ_API ut64 rz_bin_get_baddr(RzBin *bin)
Definition: bin.c:536
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
Definition: bin.c:611
RZ_API RZ_OWN char * rz_bin_demangle(RZ_NULLABLE RzBinFile *bf, RZ_NULLABLE const char *language, RZ_NULLABLE const char *symbol, ut64 vaddr, bool libs)
Demangles a symbol based on the language or the RzBinFile data.
Definition: bin.c:1295
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_strings(RZ_NONNULL RzBin *bin)
Definition: bin.c:690
RZ_API void rz_bin_options_init(RzBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, bool patch_relocs)
Definition: bin.c:75
RZ_API RzBinFile * rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt)
Definition: bin.c:200
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API const char * rz_bin_get_meth_flag_string(ut64 flag, bool compact)
Definition: bin.c:961
RZ_API bool rz_bin_use_arch(RzBin *bin, const char *arch, int bits, const char *name)
Definition: bin.c:787
RZ_API RZ_OWN char * rz_bin_section_type_to_string(RzBin *bin, int type)
Converts the RzBinSection type to the string representation.
Definition: bin.c:1133
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
static RzList * libs(RzBinFile *bf)
Definition: bin_coff.c:379
static SblHeader sb
Definition: bin_mbn.c:26
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
RzList * imports(RzBinFile *bf)
Definition: bin_ne.c:106
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
RzList * relocs(RzBinFile *bf)
Definition: bin_ne.c:114
static RzList * trycatch(RzBinFile *bf)
Definition: bin_pe64.c:393
static char * signature(RzBinFile *bf, bool json)
Definition: bin_pe.c:117
static const char * typeString(ut32 n, int *bits)
Definition: bin_symbols.c:62
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
const char * desc
Definition: bin_vsf.c:19
int bits(struct state *s, int need)
Definition: blast.c:72
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API const RzList * rz_bin_object_get_entries(RZ_NONNULL RzBinObject *obj)
Get list of RzBinAddr representing the entry points of the binary object.
Definition: bobj.c:710
RZ_API const RzList * rz_bin_object_get_classes(RZ_NONNULL RzBinObject *obj)
Get list of RzBinClass representing the classes (e.g. C++ classes) defined in the binary object.
Definition: bobj.c:790
RZ_API const RzList * rz_bin_object_get_imports(RZ_NONNULL RzBinObject *obj)
Get list of RzBinImport representing the imports of the binary object.
Definition: bobj.c:726
RZ_API const RzBinAddr * rz_bin_object_get_special_symbol(RzBinObject *o, RzBinSpecialSymbol sym)
Return the RzBinAddr structure representing the special symbol sym.
Definition: bobj.c:699
RZ_API const RzList * rz_bin_object_get_fields(RZ_NONNULL RzBinObject *obj)
Get list of RzBinField representing the fields of the binary object.
Definition: bobj.c:718
RZ_API RZ_OWN RzVector * rz_bin_object_sections_mapping_list(RZ_NONNULL RzBinObject *obj)
Get the mapping between segments and sections in the binary.
Definition: bobj.c:902
RZ_API const RzList * rz_bin_object_get_libs(RZ_NONNULL RzBinObject *obj)
Get list of char* representing the libraries used by the binary object.
Definition: bobj.c:742
RZ_API ut64 rz_bin_object_addr_with_base(RzBinObject *o, ut64 addr)
Put the given address on top of o's base address.
Definition: bobj.c:661
RZ_API RzBinSymbol * rz_bin_object_get_symbol_of_import(RzBinObject *o, RzBinImport *imp)
Find the symbol that represents the given import This is necessary for example to determine the addre...
Definition: bobj.c:616
RZ_API const RzList * rz_bin_object_get_strings(RZ_NONNULL RzBinObject *obj)
Get list of RzBinString representing the strings identified in the binary object.
Definition: bobj.c:798
RZ_API ut64 rz_bin_object_get_vaddr(RzBinObject *o, ut64 paddr, ut64 vaddr)
Definition: bobj.c:669
RZ_API const RzList * rz_bin_object_get_mem(RZ_NONNULL RzBinObject *obj)
Get list of RzBinMem representing the memory regions identified in the binary object.
Definition: bobj.c:809
RZ_API const RzList * rz_bin_object_get_resources(RZ_NONNULL RzBinObject *obj)
Get a list of RzBinResource representing the resources in the binary object.
Definition: bobj.c:825
RZ_API RZ_OWN RzList * rz_bin_object_get_segments(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSection representing only the segments of the binary object.
Definition: bobj.c:782
RZ_API RZ_OWN RzList * rz_bin_object_get_sections(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSection representing only the sections of the binary object.
Definition: bobj.c:774
RZ_API const RzList * rz_bin_object_get_symbols(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSymbol representing the symbols in the binary object.
Definition: bobj.c:817
RZ_API RzBinRelocStorage * rz_bin_object_patch_relocs(RzBinFile *bf, RzBinObject *o)
Definition: bobj.c:590
RZ_API ut64 rz_bin_reloc_size(RzBinReloc *reloc)
size of the reloc (where it is supposed to be patched) in bits
Definition: bobj.c:60
RZ_API int rz_type_parse_string_stateless(RzTypeParser *parser, const char *code, char **error_msg)
Parses the C type string reusing the existing parser state.
Definition: c_cpp_parser.c:227
RZ_API void rz_core_analysis_type_init(RzCore *core)
Definition: canalysis.c:6610
RZ_API void rz_core_analysis_cc_init(RzCore *core)
Definition: canalysis.c:6628
RZ_API bool rz_core_bin_class_as_source_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, const char *class_name)
Definition: cbin.c:3773
RZ_IPI RzCmdStatus rz_core_bin_plugin_print(const RzBinPlugin *bp, RzCmdStateOutput *state)
Definition: cbin.c:4783
RZ_API bool rz_core_sym_is_export(RZ_NONNULL RzBinSymbol *s)
Is RzBinSymbol exported?
Definition: cbin.c:1916
RZ_API bool rz_core_bin_exports_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzCoreBinFilter *filter)
Definition: cbin.c:2044
RZ_API char * rz_core_bin_method_flags_str(ut64 flags, int mode)
Definition: cbin.c:4731
RZ_API void rz_core_bin_export_info(RzCore *core, int mode)
Definition: cbin.c:108
RZ_API bool rz_core_bin_headers_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf)
Definition: cbin.c:4122
RZ_API void rz_core_bin_print_source_line_info(RzCore *core, const RzBinSourceLineInfo *li, RzCmdStateOutput *state)
Definition: cbin.c:1811
RZ_API void rz_core_sym_name_init(RZ_NONNULL RzCore *r, RZ_OUT RzBinSymNames *sn, RZ_NONNULL RzBinSymbol *sym, RZ_NULLABLE const char *lang)
Initlize sn.
Definition: cbin.c:1322
static int bin_trycatch(RzCore *core, PJ *pj, int mode)
Definition: cbin.c:4133
static void resolve_method_flags(RzStrBuf *buf, ut64 flags)
Definition: cbin.c:4618
RZ_API bool rz_core_bin_fields_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:4070
RZ_API bool rz_core_bin_apply_info(RzCore *r, RzBinFile *binfile, ut32 mask)
Definition: cbin.c:261
static const char * bin_reloc_type_name(RzBinReloc *reloc)
Definition: cbin.c:1825
RZ_API bool rz_core_bin_entries_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:1907
static bool is_in_symbol_range(ut64 sym_addr, ut64 sym_size, ut64 addr)
Definition: cbin.c:1925
RZ_API bool rz_core_bin_apply_main(RzCore *r, RzBinFile *binfile, bool va)
Definition: cbin.c:637
static bool is_known_namespace(const char *string)
Definition: cbin.c:3530
static void bin_resources_print_json(RzCore *core, RzCmdStateOutput *state, RzList *hashes, RzBinResource *resource)
Definition: cbin.c:5016
RZ_API RZ_OWN char * rz_core_bin_field_build_flag_name(RZ_NONNULL RzBinClass *cls, RZ_NONNULL RzBinField *field)
Returns the flag name of a class field.
Definition: cbin.c:4708
RZ_API bool rz_core_bin_apply_relocs(RzCore *core, RzBinFile *binfile, bool va_bool)
Definition: cbin.c:1206
RZ_API bool rz_core_bin_apply_maps(RzCore *core, RzBinFile *binfile, bool va)
Definition: cbin.c:887
RZ_API bool rz_core_bin_cur_symbol_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2036
static void reloc_set_flag(RzCore *r, RzBinReloc *reloc, const char *prefix, ut64 flag_addr)
Definition: cbin.c:1105
static const char * resolve_java_visibility(const char *v)
Definition: cbin.c:3660
static bool is_file_symbol(RzBinSymbol *s)
Definition: cbin.c:1044
RZ_API bool rz_core_bin_memory_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:4955
RZ_API bool rz_core_bin_whole_strings_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2917
RZ_API RZ_OWN HtPP * rz_core_bin_create_digests(RzCore *core, ut64 paddr, ut64 size, RzList *digests)
Create a hashtable of digests.
Definition: cbin.c:1641
static const char * get_filename(RzBinInfo *info, RzIODesc *desc)
Definition: cbin.c:2929
RZ_API bool rz_core_bin_signatures_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:4038
static bool meta_for_reloc(RzCore *r, RzBinObject *binobj, RzBinReloc *reloc, bool is_target, ut64 addr, RZ_OUT ut64 *size)
Definition: cbin.c:1006
static ut64 get_section_addr(RzCore *core, RzBinObject *o, RzBinSection *section)
Definition: cbin.c:2342
static void bin_class_print_rizin(RzCore *r, RzBinClass *c, ut64 at_min)
Definition: cbin.c:3721
RZ_API bool rz_core_bin_cur_export_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2050
RZ_API bool rz_core_bin_libs_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2163
static void classdump_objc(RzCore *r, RzBinClass *c)
Definition: cbin.c:3499
RZ_API bool rz_core_bin_apply_sections(RzCore *core, RzBinFile *binfile, bool va)
Definition: cbin.c:926
RZ_API bool rz_core_bin_apply_symbols(RzCore *core, RzBinFile *binfile, bool va)
Definition: cbin.c:1447
static char * demangle_class(const char *classname)
Definition: cbin.c:3628
RZ_API RZ_OWN RzList * rz_core_bin_whole_strings(RZ_NONNULL RzCore *core, RZ_NULLABLE RzBinFile *bf)
Definition: cbin.c:2866
#define VA_TRUE
Definition: cbin.c:20
RZ_API bool rz_core_bin_set_cur(RZ_NONNULL RzCore *core, RZ_NULLABLE RzBinFile *binfile)
Set binfile as current binfile.
Definition: cbin.c:1673
static bool strings_print(RzCore *core, RzCmdStateOutput *state, const RzList *list)
Definition: cbin.c:2684
RZ_API bool rz_core_bin_initfini_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:1901
RZ_API bool rz_core_bin_print(RzCore *core, RZ_NONNULL RzBinFile *bf, ut32 mask, RzCoreBinFilter *filter, RzCmdStateOutput *state, RzList *hashes)
Print (to RzCons or inside RzCmdStateOutput) the binary information specified in mask.
Definition: cbin.c:386
static bool is_initfini(RzBinAddr *entry)
Definition: cbin.c:688
static void section_perms_str(char *dst, int perms)
Write a section-specific permission string like srwx.
Definition: cbin.c:918
static bool is_file_reloc(RzBinReloc *r)
Definition: cbin.c:1053
static void classdump_c(RzCore *r, RzBinClass *c)
Definition: cbin.c:3483
static void add_map(RzCore *core, RZ_NULLABLE RzCoreFile *cf, RzBinFile *bf, RzBinMap *map, ut64 addr, int fd)
Definition: cbin.c:810
RZ_API RZ_OWN char * rz_core_bin_super_build_flag_name(RZ_NONNULL RzBinClass *cls)
Returns the flag name of a super class.
Definition: cbin.c:4657
static bool sections_print_table(RzCore *core, RzTable *t, RzBinObject *o, RzBinSection *section, RzList *hashes)
Definition: cbin.c:2404
RZ_API bool rz_core_bin_apply_dwarf(RzCore *core, RzBinFile *binfile)
Definition: cbin.c:654
static bool add_footer(RzCmdStateOutput *main_state, RzCmdStateOutput *state)
Definition: cbin.c:340
RZ_API int rz_core_bin_set_by_name(RzCore *core, const char *name)
Definition: cbin.c:253
#define IS_MODE_JSON(mode)
Definition: cbin.c:28
RZ_API bool rz_core_binfiles_delete(RzCore *core, RzBinFile *bf)
Close an opened binary file.
Definition: cbin.c:4542
RZ_API int rz_core_bin_set_by_fd(RzCore *core, ut64 bin_fd)
Definition: cbin.c:100
static char * objc_name_toc(const char *objc_name)
Definition: cbin.c:3473
RZ_API bool rz_core_bin_sections_mapping_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:5117
static bool io_create_mem_map(RzIO *io, RZ_NULLABLE RzCoreFile *cf, RzBinMap *map, ut64 at)
Create null-map for excessive vsize over psize.
Definition: cbin.c:769
RZ_API int rz_core_bin_update_arch_bits(RzCore *r)
Definition: cbin.c:4503
static bool core_basefind_progess_status(const RzBaseFindThreadInfo *th_info, void *user)
Definition: cbin.c:2557
RZ_API bool rz_core_binfiles_print(RzCore *core, RzCmdStateOutput *state)
Print all the opened binary files according to state.
Definition: cbin.c:4603
RZ_API RZ_OWN char * rz_core_bin_class_build_flag_name(RZ_NONNULL RzBinClass *cls)
Returns the flag name of a class.
Definition: cbin.c:4634
static const char * get_prefix_for_sym(RzBinSymbol *sym)
Definition: cbin.c:1286
static void set_bin_relocs(RzCore *r, RzBinObject *o, RzBinReloc *reloc, bool va, Sdb **db, char **sdb_module)
Definition: cbin.c:1144
RZ_API bool rz_core_bin_size_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:5151
RZ_API bool rz_core_bin_apply_config(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:582
RZ_API bool rz_core_bin_relocs_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2224
static void select_flag_space(RzCore *core, RzBinSymbol *symbol)
Definition: cbin.c:1437
static char * get_rp(const char *rtype)
Definition: cbin.c:3340
static void bin_elf_versioninfo_verneed(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4319
RZ_API bool rz_core_bin_resources_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RZ_NULLABLE RzList *hashes)
Definition: cbin.c:5045
static bool is_section_reloc(RzBinReloc *r)
Definition: cbin.c:1049
RZ_API void rz_core_bin_print_source_line_sample(RzCore *core, const RzBinSourceLineSample *s, RzCmdStateOutput *state)
Definition: cbin.c:1778
RZ_API bool rz_core_bin_archs_print(RZ_NONNULL RzBin *bin, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:5217
static RZ_NULLABLE RZ_BORROW const RzList * core_bin_strings(RzCore *r, RzBinFile *file)
Definition: cbin.c:1692
RZ_API bool rz_core_bin_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:3044
static bool is_special_symbol(RzBinSymbol *s)
Definition: cbin.c:1040
static bool core_basefind_check_ctrl_c(const RzBaseFindThreadInfo *th_info, void *user)
Definition: cbin.c:2569
#define is_invalid_address_va(va, vaddr, paddr)
Definition: cbin.c:15
static void handle_arm_entry(RzCore *core, RzBinObject *o, RzBinAddr *entry, int va)
Definition: cbin.c:1433
static void classdump_java(RzCore *r, RzBinClass *c)
Definition: cbin.c:3664
#define CASE(T)
RZ_API bool rz_core_bin_segments_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzCoreBinFilter *filter, RzList *hashes)
Definition: cbin.c:2633
static char * objc_type_toc(const char *objc_type)
Definition: cbin.c:3399
static void bin_mach0_versioninfo(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4436
RZ_API RzCmdStatus rz_core_bin_plugins_print(RzBin *bin, RzCmdStateOutput *state)
Definition: cbin.c:4855
#define IS_MODE_SET(mode)
Definition: cbin.c:25
RZ_API void rz_core_bin_options_init(RzCore *core, RZ_OUT RzBinOptions *opts, int fd, ut64 baseaddr, ut64 loadaddr)
Definition: cbin.c:87
RZ_API bool rz_core_bin_apply_imports(RzCore *core, RzBinFile *binfile, bool va)
Definition: cbin.c:1255
#define wrap_mode(header, default_mode, method)
static void digests_ht_free(HtPPKv *kv)
Definition: cbin.c:1629
RZ_API bool rz_core_bin_cur_section_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzList *hashes)
Definition: cbin.c:2541
static void table_add_row_bool(RzTable *t, const char *key, bool val)
Definition: cbin.c:43
static void bin_elf_versioninfo(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4425
static bool is_executable(RzBinObject *obj)
Definition: cbin.c:1716
static RzCmdStateOutput * add_header(RzCmdStateOutput *main_state, RzOutputMode default_mode, const char *header)
Definition: cbin.c:356
static int bin_versioninfo(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4444
RZ_API RZ_OWN char * rz_core_bin_method_build_flag_name(RZ_NONNULL RzBinClass *cls, RZ_NONNULL RzBinSymbol *meth)
Returns the flag name of a class method.
Definition: cbin.c:4680
#define MAXFLAG_LEN_DEFAULT
Definition: cbin.c:1302
#define CXX_BIN_VISIBILITY_FLAGS
Definition: cbin.c:3537
static char * construct_reloc_name(RZ_NONNULL RzBinReloc *reloc, RZ_NULLABLE const char *name)
Definition: cbin.c:1078
static void bin_memory_print_rec(RzCmdStateOutput *state, RzBinMem *mirror, const RzList *mems, int perms)
Definition: cbin.c:4919
RZ_API RZ_BORROW const char * rz_core_bin_get_compile_time(RZ_NONNULL RzBinFile *bf)
Get TimeDateStamp string from bf->sdb with key "info.image_file_header.TimeDateStamp_string".
Definition: cbin.c:1707
RZ_API bool rz_core_bin_strings_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2853
RZ_API bool rz_core_bin_symbols_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzCoreBinFilter *filter)
Definition: cbin.c:2030
RZ_API bool rz_core_bin_apply_resources(RzCore *core, RzBinFile *binfile)
Definition: cbin.c:1596
RZ_API bool rz_core_bin_classes_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:3939
RZ_API bool rz_core_bin_apply_strings(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:531
RZ_API RZ_OWN char * rz_core_bin_pdb_get_filename(RZ_NONNULL RzCore *core)
Definition: cbin.c:4886
static void bin_resources_print_standard(RzCore *core, RzList *hashes, RzBinResource *resource)
Definition: cbin.c:4967
static void bin_resources_print_table(RzCore *core, RzCmdStateOutput *state, RzList *hashes, RzBinResource *resource)
Definition: cbin.c:4995
static ut8 bin_reloc_size(RzBinReloc *reloc)
Definition: cbin.c:1057
#define IS_MODE_RZCMD(mode)
Definition: cbin.c:29
RZ_API bool rz_core_bin_dwarf_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:4880
RZ_API bool rz_core_bin_cur_segment_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzList *hashes)
Definition: cbin.c:2549
static bool symbols_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state, RzCoreBinFilter *filter, bool only_export)
Definition: cbin.c:1935
static bool bin_dwarf(RzCore *core, RzBinFile *binfile, RzCmdStateOutput *state)
Definition: cbin.c:1731
static void handle_arm_hint(RzCore *core, RzBinObject *o, ut64 paddr, ut64 vaddr, int bits, int va)
Definition: cbin.c:1406
RZ_API bool rz_core_bin_class_fields_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, const char *class_name)
Definition: cbin.c:3814
static RzIODesc * find_reusable_file(RzIO *io, RzCoreFile *cf, const char *uri, int perm)
Definition: cbin.c:751
RZ_API bool rz_core_bin_raise(RzCore *core, ut32 bfid)
Definition: cbin.c:4524
static void sections_headers_setup(RzCore *core, RzCmdStateOutput *state, RzList *hashes)
Definition: cbin.c:2458
RZ_API bool rz_core_bin_apply_entry(RzCore *core, RzBinFile *binfile, bool va)
Definition: cbin.c:699
static void sections_print_json(RzCore *core, PJ *pj, RzBinObject *o, RzBinSection *section, RzList *hashes)
Definition: cbin.c:2357
#define VA_NOREBASE
Definition: cbin.c:21
RZ_API bool rz_core_bin_load_structs(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file)
Definition: cbin.c:236
static void bin_pe_versioninfo(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4152
static void core_bin_file_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state)
Definition: cbin.c:4551
static char * demangle_type(const char *any)
Definition: cbin.c:3641
static void bin_elf_versioninfo_versym(RzCore *r, PJ *pj, int mode)
Definition: cbin.c:4266
RZ_IPI RzCmdStatus rz_core_binxtr_plugin_print(const RzBinXtrPlugin *bx, RzCmdStateOutput *state)
Definition: cbin.c:4823
#define VA_FALSE
Definition: cbin.c:19
RZ_API int rz_core_bin_set_arch_bits(RzCore *r, const char *name, const char *arch, ut16 bits)
Definition: cbin.c:4467
static void print_arch(RzBin *bin, RzCmdStateOutput *state, struct arch_ctx *ctx, const char *flag, RzBinInfo *info)
Definition: cbin.c:5180
static void sdb_concat_by_path(Sdb *s, const char *path)
Definition: cbin.c:575
RZ_API bool rz_core_file_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *binfile, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2943
static const char * str2na(const char *s)
Definition: cbin.c:3040
static char * resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal)
Definition: cbin.c:1071
RZ_API void rz_core_sym_name_fini(RZ_NULLABLE RzBinSymNames *sn)
RZ_FREE all member of sn (sn->*)
Definition: cbin.c:1371
static void handle_arm_special_symbol(RzCore *core, RzBinObject *o, RzBinSymbol *symbol, int va)
Definition: cbin.c:1387
RZ_API bool rz_core_bin_sections_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzCoreBinFilter *filter, RzList *hashes)
Definition: cbin.c:2472
static char * construct_symbol_flagname(const char *pfx, const char *libname, const char *symname, int len)
Definition: cbin.c:1304
static bool is_section_symbol(RzBinSymbol *s)
Definition: cbin.c:1032
RZ_API bool rz_core_bin_imports_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, RzCoreBinFilter *filter)
Definition: cbin.c:2058
static void classdump_cpp(RzCore *r, RzBinClass *c)
Definition: cbin.c:3538
static bool entries_initfini_print(RzCore *core, RzBinFile *bf, RzCmdStateOutput *state, bool initfini)
Definition: cbin.c:1839
#define is_invalid_address_va2(va, vaddr, paddr)
Definition: cbin.c:16
RZ_API bool rz_core_bin_apply_classes(RzCore *core, RzBinFile *binfile)
Definition: cbin.c:1552
static void handle_arm_symbol(RzCore *core, RzBinObject *o, RzBinSymbol *symbol, int va)
Definition: cbin.c:1429
static bool digests_pj_cb(void *user, const void *k, const void *v)
Definition: cbin.c:2350
static ut64 rva(RzBinObject *o, ut64 paddr, ut64 vaddr, int va)
Definition: cbin.c:77
static char * __filterQuotedShell(const char *arg)
Definition: cbin.c:49
static void flags_to_json(PJ *pj, int flags)
Definition: cbin.c:3322
RZ_API bool rz_core_bin_basefind_print(RzCore *core, ut32 pointer_size, RzCmdStateOutput *state)
Definition: cbin.c:2573
RZ_API bool rz_core_bin_pdb_load(RZ_NONNULL RzCore *core, RZ_NONNULL const char *filename)
Definition: cbin.c:5264
RZ_API bool rz_core_bin_versions_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:5084
RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:311
RZ_API bool rz_core_bin_trycatch_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:5102
RZ_API bool rz_core_bin_main_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state)
Definition: cbin.c:2192
RZ_API bool rz_core_bin_class_methods_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzCmdStateOutput *state, const char *class_name)
Definition: cbin.c:3881
RZ_API bool rz_analysis_cc_exist(RzAnalysis *analysis, const char *convention)
Definition: cc.c:116
RZ_API void rz_core_bin_dwarf_print_abbrev_section(const RzBinDwarfDebugAbbrev *da)
Definition: cdwarf.c:6
RZ_API void rz_core_bin_dwarf_print_debug_info(const RzBinDwarfDebugInfo *inf)
Definition: cdwarf.c:121
RZ_API void rz_core_bin_dwarf_print_line_units(RzList *lines)
Definition: cdwarf.c:343
RZ_API void rz_core_bin_dwarf_print_aranges(RzList *aranges)
Definition: cdwarf.c:222
RZ_API void rz_core_bin_dwarf_print_loc(HtUP *loc_table, int addr_size)
Definition: cdwarf.c:196
RZ_API ut32 rz_core_file_cur_fd(RzCore *core)
Definition: cfile.c:1584
RZ_IPI RzCoreIOMapInfo * rz_core_io_map_info_new(RzCoreFile *cf, int perm_orig)
Definition: cfile.c:1669
RZ_API RzCoreFile * rz_core_file_find_by_fd(RzCore *core, ut64 fd)
Definition: cfile.c:1528
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API RzCmdStatus rz_core_cmd_rzshell(RzCore *core, const char *cstr, int log)
Definition: cmd.c:5324
RZ_API void rz_cmd_state_output_free(RZ_NONNULL RzCmdStateOutput *state)
Free the RzCmdStateOutput structure and its inner fields appropriately.
Definition: cmd_api.c:2624
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
Definition: cmd_api.c:2634
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
static int value
Definition: cmd_api.c:93
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API const char * rz_cons_get_buffer(void)
Return the current RzCons buffer.
Definition: cons.c:819
RZ_API int rz_cons_get_cur_line(void)
Definition: cons.c:387
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API void rz_cons_gotoxy(int x, int y)
Definition: cons.c:724
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
#define RZ_API
RZ_API void rz_core_pdb_info_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzTypeDB *db, RZ_NONNULL RzPdb *pdb, RZ_NONNULL RzCmdStateOutput *state)
Print parsed PDB file info.
Definition: cpdb.c:273
RZ_API RzPdb * rz_core_pdb_load_info(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file)
Parse PDB file info and integrate with typedb.
Definition: cpdb.c:245
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
cs_arch arch
Definition: cstool.c:13
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
uint16_t ut16
uint32_t ut32
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
RZ_API RzBinDwarfDebugAbbrev * rz_bin_dwarf_parse_abbrev(RzBinFile *binfile)
Definition: dwarf.c:2144
RZ_API void rz_bin_dwarf_debug_abbrev_free(RzBinDwarfDebugAbbrev *da)
Definition: dwarf.c:1340
RZ_API void rz_bin_dwarf_line_info_free(RzBinDwarfLineInfo *li)
Definition: dwarf.c:1352
RZ_API void rz_bin_dwarf_loc_free(HtUP *loc_table)
Definition: dwarf.c:2283
RZ_API RzList * rz_bin_dwarf_parse_aranges(RzBinFile *binfile)
Definition: dwarf.c:2132
RZ_API RzBinDwarfDebugInfo * rz_bin_dwarf_parse_info(RzBinFile *binfile, RzBinDwarfDebugAbbrev *da)
Parses .debug_info section.
Definition: dwarf.c:2075
RZ_API HtUP * rz_bin_dwarf_parse_loc(RzBinFile *binfile, int addr_size)
Parses out the .debug_loc section into a table that maps each list as offset of a list -> LocationLis...
Definition: dwarf.c:2259
RZ_API void rz_bin_dwarf_debug_info_free(RzBinDwarfDebugInfo *inf)
Definition: dwarf.c:1407
RZ_API RzBinDwarfLineInfo * rz_bin_dwarf_parse_line(RzBinFile *binfile, RZ_NULLABLE RzBinDwarfDebugInfo *info, RzBinDwarfLineInfoMask mask)
Definition: dwarf.c:2119
RZ_API void rz_analysis_dwarf_process_info(const RzAnalysis *analysis, RzAnalysisDwarfContext *ctx)
Parses type and function information out of DWARF entries and stores them to the sdb for further use.
size_t map(int syms, int left, int len)
Definition: enough.c:237
void cleanup(void)
Definition: enough.c:244
RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment)
Definition: flag.c:564
RZ_API RzFlagItem * rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:494
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item)
Definition: flag.c:597
RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname)
Definition: flag.c:571
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
RZ_API void rz_type_db_format_set(RzTypeDB *typedb, const char *name, const char *fmt)
Definition: format.c:1912
RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int mode, int n)
Definition: format.c:1515
RZ_API RZ_OWN char * rz_type_format_data(const RzTypeDB *typedb, RzPrint *p, ut64 seek, const ut8 *b, const int len, const char *formatname, int mode, const char *setval, char *ofield)
Definition: format.c:2749
unsigned short prefix[65536]
Definition: gun.c:163
RZ_API RZ_OWN char * rz_hash_cfg_calculate_small_block_string(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NULLABLE ut32 *size, bool invert)
Definition: hash.c:545
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_name(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name)
Definition: hash.c:120
RZ_API void rz_analysis_hint_clear(RzAnalysis *a)
Definition: hint.c:85
RZ_API void rz_analysis_hint_set_bits(RzAnalysis *a, ut64 addr, int bits)
Definition: hint.c:288
RZ_API void rz_analysis_hint_set_size(RzAnalysis *a, ut64 addr, ut64 size)
Definition: hint.c:267
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
static char * rp[]
Definition: i8080dis.c:36
voidpf void uLong size
Definition: ioapi.h:138
const char * filename
Definition: ioapi.h:137
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
void * mem
Definition: libc.cpp:91
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define basename
Definition: libiberty.h:109
RZ_API RZ_OWN char * rz_demangler_java(RZ_NULLABLE const char *symbol)
Demangles java symbols.
Definition: demangler.c:38
static RzMain foo[]
Definition: main.c:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
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
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode dup
Definition: sflib.h:68
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
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")
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
#define ls_foreach(list, it, pos)
Definition: ls.h:31
char * dst
Definition: lz4.h:724
#define header(is_bt, len_min, ret_op)
RZ_API void MACH0_() patch_relocs(RzBinFile *bf, struct MACH0_(obj_t) *obj)
Patching of external relocs in a sparse overlay buffer.
Definition: mach0_relocs.c:614
RZ_API bool rz_meta_set_with_subtype(RzAnalysis *m, RzAnalysisMetaType type, int subtype, ut64 addr, ut64 size, const char *str)
Definition: meta.c:195
RZ_API bool rz_meta_set(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, ut64 size, const char *str)
Definition: meta.c:191
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
int idx
Definition: setup.py:197
RZ_API Sdb * sdb_ns_path(Sdb *s, const char *path, int create)
Definition: ns.c:213
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
RZ_API int sdb_num_add(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:18
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
int off
Definition: pal.c:13
RZ_API void rz_bin_pdb_free(RzPdb *pdb)
Free PDB instance.
Definition: pdb.c:366
static int is_arm(RzBinPEObj *bin)
Definition: pe_info.c:12
#define min(a, b)
Definition: qsort.h:83
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
#define RZ_ANALYSIS_ARCHINFO_ALIGN
Definition: rz_analysis.h:100
#define RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE
Definition: rz_analysis.h:99
@ RZ_META_TYPE_DATA
Definition: rz_analysis.h:289
@ RZ_META_TYPE_STRING
Definition: rz_analysis.h:291
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65
#define RZ_BIN_DBG_RELOCS
Definition: rz_bin.h:31
#define RZ_BIN_DBG_STRIPPED
Definition: rz_bin.h:27
@ RZ_BIN_LANGUAGE_GROOVY
Definition: rz_bin.h:157
@ RZ_BIN_LANGUAGE_OBJC
Definition: rz_bin.h:151
@ RZ_BIN_LANGUAGE_KOTLIN
Definition: rz_bin.h:156
@ RZ_BIN_LANGUAGE_C
Definition: rz_bin.h:148
@ RZ_BIN_LANGUAGE_JAVA
Definition: rz_bin.h:147
@ RZ_BIN_LANGUAGE_DART
Definition: rz_bin.h:158
@ RZ_BIN_LANGUAGE_CXX
Definition: rz_bin.h:150
@ RZ_BIN_LANGUAGE_SWIFT
Definition: rz_bin.h:152
@ RZ_BIN_LANGUAGE_BLOCKS
Definition: rz_bin.h:159
#define RZ_BIN_METH_VIRTUAL
Definition: rz_bin.h:92
#define RZ_BIN_ENTRY_TYPE_PREINIT
Definition: rz_bin.h:38
#define RZ_BIN_TYPE_OBJECT_STR
Definition: rz_bin.h:118
#define RZ_BIN_METH_PUBLIC
Definition: rz_bin.h:85
#define RZ_BIN_TYPE_NOTYPE_STR
Definition: rz_bin.h:117
#define RZ_BIN_TYPE_METH_STR
Definition: rz_bin.h:122
#define RZ_BIN_ENTRY_TYPE_FINI
Definition: rz_bin.h:36
@ RZ_BIN_SPECIAL_SYMBOL_MAIN
Definition: rz_bin.h:139
#define RZ_BIN_DBG_SYMS
Definition: rz_bin.h:30
#define RZ_BIN_ENTRY_TYPE_INIT
Definition: rz_bin.h:35
static bool rz_bin_reloc_storage_targets_available(RzBinRelocStorage *storage)
return true iff there is at least one reloc in the storage with a target address
Definition: rz_bin.h:744
#define RZ_BIN_ENTRY_TYPE_PROGRAM
Definition: rz_bin.h:33
static bool rz_bin_reloc_has_target(RzBinReloc *reloc)
Definition: rz_bin.h:828
#define RZ_BIN_METH_CONST
Definition: rz_bin.h:93
#define RZ_BIN_BIND_GLOBAL_STR
Definition: rz_bin.h:107
#define RZ_BIN_METH_STATIC
Definition: rz_bin.h:84
#define RZ_BIN_METH_PRIVATE
Definition: rz_bin.h:86
#define RZ_BIN_METH_PROTECTED
Definition: rz_bin.h:87
#define RZ_BIN_TYPE_FILE_STR
Definition: rz_bin.h:125
#define RZ_BIN_TYPE_SECTION_STR
Definition: rz_bin.h:124
#define RZ_BIN_DBG_LINENUMS
Definition: rz_bin.h:29
#define RZ_BIN_TYPE_SPECIAL_SYM_STR
Definition: rz_bin.h:133
@ RZ_BIN_DWARF_LINE_INFO_MASK_OPS
Definition: rz_bin_dwarf.h:908
@ RZ_BIN_DWARF_LINE_INFO_MASK_LINES
Definition: rz_bin_dwarf.h:909
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
Definition: buf.c:1197
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io_fd(RZ_NONNULL void *iob, int fd)
Creates a new buffer wrapping a file descriptor accessed through RzIOBind.
Definition: buf.c:490
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
#define RZ_FLAGS_FS_IMPORTS
Definition: rz_core.h:59
#define RZ_FLAGS_FS_SYMBOLS_SECTIONS
Definition: rz_core.h:68
#define RZ_FLAGS_FS_STRINGS
Definition: rz_core.h:66
#define RZ_FLAGS_FS_CLASSES
Definition: rz_core.h:57
#define RZ_FLAGS_FS_SECTIONS
Definition: rz_core.h:63
#define RZ_FLAGS_FS_RELOCS
Definition: rz_core.h:60
#define RZ_FLAGS_FS_SYMBOLS
Definition: rz_core.h:67
#define RZ_FLAGS_FS_SEGMENTS
Definition: rz_core.h:64
#define RZ_FLAGS_FS_RESOURCES
Definition: rz_core.h:62
RZ_API const char * rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path)
Definition: file.c:102
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
RZ_API char * rz_file_dirname(const char *path)
Definition: file.c:120
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
#define RZ_FLAG_NAME_SIZE
Definition: rz_flag.h:17
RZ_API char * rz_hex_bin2strdup(const ut8 *in, int len)
Definition: hex.c:415
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API RzIODesc * rz_io_open_at(RzIO *io, const char *uri, int flags, int mode, ut64 at, RZ_NULLABLE RZ_OUT RzIOMap **map)
Open a file and directly map it at the given offset.
Definition: io.c:177
RZ_API ut64 rz_io_desc_size(RzIODesc *desc)
Definition: io_desc.c:224
RZ_API RzIOMap * rz_io_map_add_batch(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:155
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
RZ_API int rz_io_fd_get_current(RzIO *io)
Definition: io_fd.c:135
RZ_API RzIODesc * rz_io_open_nomap(RzIO *io, const char *uri, int flags, int mode)
Definition: io.c:145
RZ_API bool rz_io_use_fd(RzIO *io, int fd)
Definition: io_fd.c:118
RZ_API int rz_io_pread_at(RzIO *io, ut64 paddr, ut8 *buf, int len)
Definition: io.c:269
RZ_API bool rz_io_desc_is_dbg(RzIODesc *desc)
Definition: io_desc.c:303
RZ_API bool rz_io_desc_close(RzIODesc *desc)
Definition: io_desc.c:165
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API char * rz_num_units(char *buf, size_t len, ut64 number)
Definition: unum.c:108
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
RZ_API void pj_raw(PJ *j, const char *k)
Definition: pj.c:7
RZ_API PJ * pj_j(PJ *j, const char *k)
Definition: pj.c:243
RZ_API PJ * pj_ko(PJ *j, const char *k)
Definition: pj.c:156
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
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_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_n(PJ *j, ut64 n)
Definition: pj.c:252
RZ_API PJ * pj_kr(PJ *j, const char *k, const ut8 *v, size_t v_len)
Definition: pj.c:236
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 PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:142
RZ_API bool rz_spaces_push(RzSpaces *sp, const char *name)
Definition: spaces.c:177
RZ_API bool rz_spaces_pop(RzSpaces *sp)
Definition: spaces.c:185
RZ_API int rz_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, bool little_endian)
Definition: str.c:2884
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API RZ_BORROW char * rz_str_trim_tail(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string and replaces them w...
Definition: str_trim.c:125
RZ_API char * rz_str_escape_utf8_keep_printable(const char *buf, RzStrEscOptions *opt)
Definition: str.c:1703
RZ_API const char * rz_str_rchr(const char *base, const char *p, int ch)
Definition: str.c:829
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
RZ_API bool rz_str_is_utf8(RZ_NONNULL const char *str)
Returns true if the input string is correctly UTF-8-encoded.
Definition: str.c:2023
RZ_API void rz_str_case(char *str, bool up)
Definition: str.c:341
RZ_API const char * rz_str_enc_as_string(RzStrEnc enc)
Definition: str.c:44
static const char * rz_str_get_null(const char *str)
Definition: rz_str.h:190
@ RZ_STRING_ENC_UTF32LE
Definition: rz_str.h:24
@ RZ_STRING_ENC_MUTF8
Definition: rz_str.h:22
@ RZ_STRING_ENC_UTF8
Definition: rz_str.h:21
@ RZ_STRING_ENC_UTF16LE
Definition: rz_str.h:23
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char * rz_str_escape_utf8(const char *buf, RzStrEscOptions *opt)
Definition: str.c:1699
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
Definition: str.c:139
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
RZ_API char * rz_str_list_join(RzList *str, const char *sep)
Definition: str.c:3849
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define IS_PRINTABLE(x)
Definition: rz_str_util.h:10
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
Definition: strbuf.c:349
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API const char * rz_strbuf_initf(RzStrBuf *sb, const char *fmt,...)
Definition: strbuf.c:38
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API bool rz_strbuf_is_empty(RzStrBuf *sb)
Definition: strbuf.c:24
RZ_API void rz_table_hide_header(RzTable *t)
Definition: table.c:1201
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API bool rz_table_query(RzTable *t, const char *q)
Definition: table.c:1050
RZ_API void rz_table_add_row_columnsf(RzTable *t, const char *fmt,...)
Definition: table.c:289
RZ_API void rz_table_set_columnsf(RzTable *t, const char *fmt,...)
Specify the types and names of the referenced table.
Definition: table.c:234
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103
RZ_API RzTableColumnType * rz_table_type(const char *name)
Definition: table.c:24
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define RZ_SYS_DIR
Definition: rz_types.h:218
#define PFMT64d
Definition: rz_types.h:394
#define RZ_JOIN_3_PATHS(p1, p2, p3)
Definition: rz_types.h:225
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define PFMT32u
Definition: rz_types.h:409
#define RZ_MODE_SET
Definition: rz_types.h:27
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_NEW(x)
Definition: rz_types.h:285
#define RZ_PERM_W
Definition: rz_types.h:94
#define RZ_PERM_X
Definition: rz_types.h:95
#define RZ_PERM_SHAR
Definition: rz_types.h:100
#define RZ_MODE_PRINT
Definition: rz_types.h:25
#define RZ_MODE_JSON
Definition: rz_types.h:29
#define PFMT64u
Definition: rz_types.h:395
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_LONG_JSON
Definition: rz_types.h:45
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define RZ_PERM_RWX
Definition: rz_types.h:98
#define RZ_FREE(x)
Definition: rz_types.h:369
#define PFMT64x
Definition: rz_types.h:393
#define RZ_BORROW
Definition: rz_types.h:63
#define UT64_MAX
Definition: rz_types_base.h:86
#define RZ_BETWEEN(x, y, z)
#define UT64_ADD_OVFCHK(x, y)
#define RZ_SDB_TYPES
Definition: rz_userconf.h:83
#define RZ_SDB_FORMAT
Definition: rz_userconf.h:87
RZ_API int * rz_utf_block_list(const ut8 *str, int len, int **freq_list)
Definition: utf8.c:754
RZ_API const char * rz_utf_block_name(int idx)
Definition: utf8.c:484
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
RZ_API void rz_vector_free(RzVector *vec)
Definition: vector.c:75
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
#define toupper(c)
Definition: safe-ctype.h:147
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
Definition: sdb.c:47
RZ_API void sdb_close(Sdb *s)
Definition: sdb.c:416
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:290
RZ_API bool sdb_merge(Sdb *d, Sdb *s)
Definition: sdb.c:144
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API const char * sdb_const_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:279
RZ_API SdbList * sdb_foreach_list(Sdb *s, bool sorted)
Definition: sdb.c:630
static char * sdbkv_key(const SdbKv *kv)
Definition: sdbht.h:21
static char * sdbkv_value(const SdbKv *kv)
Definition: sdbht.h:25
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
static int
Definition: sfsocketcall.h:114
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define c(i)
Definition: sha256.c:43
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Line info of all compilation units from the entire debug_line section.
Definition: rz_bin_dwarf.h:901
Group together some common options used by string escaping functions.
Definition: rz_str.h:39
bool esc_bslash
When true, backslashes \ are quoted with \\
Definition: rz_str.h:41
bool show_asciidot
When true, dots . are placed instead of unprintable characters.
Definition: rz_str.h:40
bool esc_double_quotes
When true, double quotes "</tt> are quoted with <tt>\\"
Definition: rz_str.h:42
const char * arch
Definition: cbin.c:5175
ut64 offset
Definition: cbin.c:5173
ut64 size
Definition: cbin.c:5174
int bits
Definition: cbin.c:5176
const char * machine
Definition: cbin.c:5177
Definition: malloc.c:26
Definition: inftree9.h:24
Definition: zipcmp.c:77
Definition: gzappend.c:170
Definition: ls.h:17
Definition: ls.h:22
Definition: sftypes.h:77
Definition: z80asm.h:102
char name[1]
Definition: z80asm.h:104
Definition: rz_pj.h:12
RzSpaces meta_spaces
Definition: rz_analysis.h:601
RzTypeDB * typedb
Definition: rz_analysis.h:602
ut32 n_threads
Total number of search threads.
Definition: rz_basefind.h:25
ut64 current_address
Thread related search address (current).
Definition: rz_basefind.h:28
ut32 percentage
Progress made by the search thread.
Definition: rz_basefind.h:30
ut32 thread_idx
Sesarch thread number.
Definition: rz_basefind.h:26
ut64 end_address
Thread related search address (end).
Definition: rz_basefind.h:29
ut64 candidate
Candidate physical base address.
Definition: rz_basefind.h:20
ut32 score
Score of the candidate address.
Definition: rz_basefind.h:21
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187
char * comment
Definition: rz_bin.h:770
ut64 vaddr
Definition: rz_bin.h:762
char * format
Definition: rz_bin.h:771
char * name
Definition: rz_bin.h:767
ut64 paddr
Definition: rz_bin.h:763
bool format_named
Definition: rz_bin.h:772
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300
struct rz_bin_xtr_plugin_t * curxtr
Definition: rz_bin.h:312
char * file
Definition: rz_bin.h:299
RzList * xtr_data
Definition: rz_bin.h:314
const char * type
Definition: rz_bin.h:195
char * libname
Definition: rz_bin.h:702
char * name
Definition: rz_bin.h:701
int has_va
Definition: rz_bin.h:228
char * claimed_checksum
Definition: rz_bin.h:237
char * type
Definition: rz_bin.h:211
int has_crypto
Definition: rz_bin.h:233
char * intrp
Definition: rz_bin.h:243
int has_canary
Definition: rz_bin.h:230
char * default_cc
Definition: rz_bin.h:225
char * os
Definition: rz_bin.h:219
char * head_flag
Definition: rz_bin.h:217
char * subsystem
Definition: rz_bin.h:220
int has_pi
Definition: rz_bin.h:229
int has_nx
Definition: rz_bin.h:234
char * machine
Definition: rz_bin.h:216
const char * lang
Definition: rz_bin.h:224
char * bclass
Definition: rz_bin.h:212
char * guid
Definition: rz_bin.h:222
char * file
Definition: rz_bin.h:210
char * debug_file_name
Definition: rz_bin.h:223
ut64 dbg_info
Definition: rz_bin.h:240
RzBinHash sum[3]
Definition: rz_bin.h:241
int has_retguard
Definition: rz_bin.h:231
char * features
Definition: rz_bin.h:218
bool signature
Definition: rz_bin.h:239
int pe_overlay
Definition: rz_bin.h:238
char * rpath
Definition: rz_bin.h:221
char * cpu
Definition: rz_bin.h:215
char * actual_checksum
Definition: rz_bin.h:236
char * rclass
Definition: rz_bin.h:213
char * arch
Definition: rz_bin.h:214
char * compiler
Definition: rz_bin.h:244
int has_sanitizers
Definition: rz_bin.h:232
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
char * name
Definition: rz_bin.h:780
RzList * classes
Definition: rz_bin.h:281
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260
RzList * imports
Definition: rz_bin.h:268
RzList * maps
Definition: rz_bin.h:266
ut64 boffset
Definition: rz_bin.h:262
RzList * entries
Definition: rz_bin.h:276
RzBinLanguage lang
Definition: rz_bin.h:290
RzBinSourceLineInfo * lines
Definition: rz_bin.h:284
RzBinInfo * info
Definition: rz_bin.h:287
RZ_DEPRECATE RZ_BORROW Sdb * kv
deprecated, put info in C structures instead of this (holds a copy of another pointer....
Definition: rz_bin.h:291
RzList * sections
Definition: rz_bin.h:267
ut64 obj_size
Definition: rz_bin.h:264
RzBinRelocStorage * relocs
Definition: rz_bin.h:279
char * desc
Definition: rz_bin.h:510
void(* header)(RzBinFile *bf)
Definition: rz_bin.h:542
char * name
Definition: rz_bin.h:509
char * license
Definition: rz_bin.h:513
char * version
Definition: rz_bin.h:512
char * author
Definition: rz_bin.h:511
char *(* signature)(RzBinFile *bf, bool json)
Definition: rz_bin.h:543
Efficient storage of relocations to query by address.
Definition: rz_bin.h:732
ut64 paddr
the paddr where the value should be patched into
Definition: rz_bin.h:717
RzBinRelocType type
Definition: rz_bin.h:712
ut64 vaddr
the vaddr where the value should be patched into
Definition: rz_bin.h:716
ut64 target_vaddr
the target address that the patched reloc points to
Definition: rz_bin.h:718
RzBinImport * import
Definition: rz_bin.h:714
bool is_ifunc
Definition: rz_bin.h:726
st64 addend
Definition: rz_bin.h:715
RzBinSymbol * symbol
Definition: rz_bin.h:713
char * language
Definition: rz_bin.h:794
size_t index
Definition: rz_bin.h:788
char * name
Definition: rz_bin.h:619
RzBinSourceLineSample * samples
All source line references for given adresses.
Definition: rz_bin.h:486
A single sample of source line info for a specific address.
Definition: rz_bin.h:441
ut32 ordinal
Definition: rz_bin.h:755
char * string
Definition: rz_bin.h:752
Store some display name from RzBinSymbol.
Definition: rz_core.h:426
char * methname
methods [class]::[method]
Definition: rz_core.h:436
char * demname
demangled raw symbol name
Definition: rz_core.h:432
char * methflag
methods flag sym.[class].[method]
Definition: rz_core.h:437
char * nameflag
flag name for symbol
Definition: rz_core.h:431
char * symbolname
display symbol name
Definition: rz_core.h:429
char * classname
classname
Definition: rz_core.h:434
char * libname
name of the lib this symbol is specific to, if any
Definition: rz_core.h:430
char * demflag
flag name for demangled symbol
Definition: rz_core.h:433
const char * bind
Definition: rz_bin.h:681
char * visibility_str
Definition: rz_bin.h:686
bool is_imported
Definition: rz_bin.h:684
const char * rtype
Definition: rz_bin.h:683
const char * type
Definition: rz_bin.h:682
char * name
Definition: rz_bin.h:675
ut32 ordinal
Definition: rz_bin.h:692
char * dname
Definition: rz_bin.h:676
ut64 method_flags
Definition: rz_bin.h:696
char * libname
Definition: rz_bin.h:677
bool verbose
Definition: rz_bin.h:359
int is_debugger
Definition: rz_bin.h:350
char * prefix
Definition: rz_bin.h:356
RzList * binfiles
Definition: rz_bin.h:344
const char * file
Definition: rz_bin.h:329
RzBinXtrMetadata * metadata
Definition: rz_bin.h:386
Represent the output state of a command handler.
Definition: rz_cmd.h:91
RzOutputMode mode
Definition: rz_cmd.h:95
union rz_cmd_state_output_t::@259 d
RzPVector extra_files
additional files opened during mapping, for example for zeroed maps
Definition: rz_core.h:156
RzBin * bin
Definition: rz_core.h:298
ut64 offset
Definition: rz_core.h:301
RzAnalysis * analysis
Definition: rz_core.h:322
RzIO * io
Definition: rz_core.h:313
RzNum * num
Definition: rz_core.h:316
Sdb * sdb
Definition: rz_core.h:365
RzFlag * flags
Definition: rz_core.h:330
RzPrint * print
Definition: rz_core.h:327
RzHash * hash
Definition: rz_core.h:389
RzConfig * config
Definition: rz_core.h:300
ut64 offset
Definition: rz_flag.h:38
char * comment
Definition: rz_flag.h:42
bool demangled
Definition: rz_flag.h:37
st64 base
Definition: rz_flag.h:48
const char * name
Definition: rz_hash.h:27
int perm
Definition: rz_io.h:97
void * user
Uninterpreted data to be injected from outside.
Definition: rz_io.h:159
RZ_NULLABLE char * name
Definition: rz_io.h:151
Definition: rz_io.h:59
int va
Definition: rz_io.h:63
bool esc_bslash
Definition: rz_print.h:161
RzTypeParser * parser
Definition: rz_type.h:37
Definition: sdbht.h:14
Definition: sdb.h:63
uint32_t flags
uint32_t size
uint32_t align
Definition: dis.h:43
int pos
Definition: main.c:11
#define bool
Definition: sysdefs.h:146
RZ_API size_t rz_th_request_physical_cores(size_t max_cores)
Returns the maximum number of cores available regardless of the number of cores requested....
Definition: thread_pool.c:78
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int baseaddr
Definition: z80asm.c:79
static int addr
Definition: z80asm.c:58