Rizin
unix-like reverse engineering framework and cli tools
cil.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2020 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2009-2020 nibble <nibble.ds@gmail.com>
3 // SPDX-FileCopyrightText: 2021 heersin <teablearcher@gmail.com>
4 // SPDX-License-Identifier: LGPL-3.0-only
5 
6 #include <string.h>
7 
8 #include <rz_types.h>
9 #include <rz_list.h>
10 #include <rz_flag.h>
11 #include <rz_core.h>
12 #include <rz_bin.h>
13 #include <ht_uu.h>
15 
16 #include "core_private.h"
17 
18 static void core_esil_init(RzCore *core) {
19  unsigned int addrsize = rz_config_get_i(core->config, "esil.addr.size");
20  int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
21  int iotrap = rz_config_get_i(core->config, "esil.iotrap");
22  int romem = rz_config_get_i(core->config, "esil.romem");
23  int stats = rz_config_get_i(core->config, "esil.stats");
24  int noNULL = rz_config_get_i(core->config, "esil.noNULL");
25  int verbose = rz_config_get_i(core->config, "esil.verbose");
26  RzAnalysisEsil *esil = NULL;
27  if (!(esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
28  return;
29  }
30  rz_analysis_esil_setup(esil, core->analysis, romem, stats, noNULL); // setup io
31  core->analysis->esil = esil;
32  esil->verbose = verbose;
33  const char *s = rz_config_get(core->config, "cmd.esil.intr");
34  if (s) {
35  char *my = strdup(s);
36  if (my) {
37  rz_config_set(core->config, "cmd.esil.intr", my);
38  free(my);
39  }
40  }
41 }
42 
44  if (core->analysis->esil) {
45  return;
46  }
47  core_esil_init(core);
48 }
49 
55  rz_return_if_fail(core && core->analysis);
56  rz_analysis_esil_free(core->analysis->esil);
57  core_esil_init(core);
58  // reinitialize
59  rz_reg_set_value_by_role(core->analysis->reg, RZ_REG_NAME_PC, core->offset);
60 }
61 
67  rz_return_if_fail(core && core->analysis);
68  RzAnalysisEsil *esil = core->analysis->esil;
69  if (esil) {
70  sdb_reset(esil->stats);
71  }
73  core->analysis->esil = NULL;
74 }
75 
76 static void initialize_stack(RzCore *core, ut64 addr, ut64 size) {
77  const char *mode = rz_config_get(core->config, "esil.fillstack");
78  if (mode && *mode && *mode != '0') {
79  const ut64 bs = 4096 * 32;
80  ut64 i;
81  for (i = 0; i < size; i += bs) {
82  ut64 left = RZ_MIN(bs, size - i);
83  // rz_core_cmdf (core, "wx 10203040 @ 0x%llx", addr);
84  switch (*mode) {
85  case 'd': { // "debrujn"
86  ut8 *buf = (ut8 *)rz_debruijn_pattern(left, 0, NULL);
87  if (buf) {
88  if (!rz_core_write_at(core, addr + i, buf, left)) {
89  eprintf("Couldn't write at %" PFMT64x "\n", addr + i);
90  }
91  free(buf);
92  } else {
93  eprintf("Couldn't generate pattern of length %" PFMT64d "\n", left);
94  }
95  } break;
96  case 's': // "seq"
97  rz_core_cmdf(core, "woe 1 0xff 1 4 @ 0x%" PFMT64x "!0x%" PFMT64x, addr + i, left);
98  break;
99  case 'r': // "random"
100  rz_core_cmdf(core, "woR %" PFMT64u " @ 0x%" PFMT64x "!0x%" PFMT64x, left, addr + i, left);
101  break;
102  case 'z': // "zero"
103  case '0':
104  rz_core_cmdf(core, "wow 00 @ 0x%" PFMT64x "!0x%" PFMT64x, addr + i, left);
105  break;
106  }
107  }
108  }
109 }
110 
111 static char *get_esil_stack_name(RzCore *core, const char *name, ut64 *addr, ut32 *size) {
112  ut64 sx_addr = rz_config_get_i(core->config, "esil.stack.addr");
113  ut32 sx_size = rz_config_get_i(core->config, "esil.stack.size");
114  RzIOMap *map = rz_io_map_get(core->io, sx_addr);
115  if (map) {
116  sx_addr = UT64_MAX;
117  }
118  if (sx_addr == UT64_MAX) {
119  const ut64 align = 0x10000000;
120  sx_addr = rz_io_map_next_available(core->io, core->offset, sx_size, align);
121  }
122  if (*addr != UT64_MAX) {
123  sx_addr = *addr;
124  }
125  if (*size != UT32_MAX) {
126  sx_size = *size;
127  }
128  if (sx_size < 1) {
129  sx_size = 0xf0000;
130  }
131  *addr = sx_addr;
132  *size = sx_size;
133  if (RZ_STR_ISEMPTY(name)) {
134  return rz_str_newf("mem.0x%" PFMT64x "_0x%x", sx_addr, sx_size);
135  } else {
136  return rz_str_newf("mem.%s", name);
137  }
138 }
139 
150  rz_return_if_fail(core && core->analysis);
151  ut64 current_offset = core->offset;
153  RzAnalysisEsil *esil = core->analysis->esil;
154  if (!esil) {
155  eprintf("Cannot initialize ESIL\n");
156  return;
157  }
158  RzIOMap *stack_map;
159  if (!name && addr == UT64_MAX && size == UT32_MAX) {
160  const char *fi = sdb_const_get(core->sdb, "aeim.fd", 0);
161  if (fi) {
162  // Close the fd associated with the aeim stack
163  ut64 fd = sdb_atoi(fi);
164  (void)rz_io_fd_close(core->io, fd);
165  }
166  }
167  const char *pattern = rz_config_get(core->config, "esil.stack.pattern");
168  char *stack_name = get_esil_stack_name(core, name, &addr, &size);
169 
170  char uri[32];
171  rz_strf(uri, "malloc://%u", size);
172  esil->stack_fd = rz_io_fd_open(core->io, uri, RZ_PERM_RW, 0);
173  if (!(stack_map = rz_io_map_add(core->io, esil->stack_fd, RZ_PERM_RW, 0LL, addr, size))) {
174  rz_io_fd_close(core->io, esil->stack_fd);
175  eprintf("Cannot create map for tha stack, fd %d got closed again\n", esil->stack_fd);
176  free(stack_name);
177  esil->stack_fd = 0;
178  return;
179  }
180  rz_io_map_set_name(stack_map, stack_name);
181  free(stack_name);
182  char val[128], *v;
183  v = sdb_itoa(esil->stack_fd, val, 10);
184  sdb_set(core->sdb, "aeim.fd", v, 0);
185 
186  rz_config_set_b(core->config, "io.va", true);
187  if (pattern && *pattern) {
188  switch (*pattern) {
189  case '0':
190  // do nothing
191  break;
192  case 'd':
193  rz_core_cmdf(core, "wopD %d @ 0x%" PFMT64x, size, addr);
194  break;
195  case 'i':
196  rz_core_cmdf(core, "woe 0 255 1 @ 0x%" PFMT64x "!%d", addr, size);
197  break;
198  case 'w':
199  rz_core_cmdf(core, "woe 0 0xffff 1 4 @ 0x%" PFMT64x "!%d", addr, size);
200  break;
201  }
202  }
203  rz_reg_set_value_by_role(core->analysis->reg, RZ_REG_NAME_SP, addr + (size / 2)); // size / 2 to have free space in both directions
204  rz_reg_set_value_by_role(core->analysis->reg, RZ_REG_NAME_BP, addr + (size / 2));
205  rz_reg_set_value_by_role(core->analysis->reg, RZ_REG_NAME_PC, current_offset);
207  esil->stack_addr = addr;
208  esil->stack_size = size;
209  initialize_stack(core, addr, size);
210  rz_core_seek(core, current_offset, false);
211 }
212 
215  RzAnalysisEsil *esil = core->analysis->esil;
216  ut64 addr = 0x100000;
217  ut32 size = 0xf0000;
218  RzFlagItem *fi = rz_flag_get(core->flags, "aeim.stack");
219  if (fi) {
220  addr = fi->offset;
221  size = fi->size;
222  } else {
224  }
225  if (esil) {
226  esil->stack_addr = addr;
227  esil->stack_size = size;
228  }
229  initialize_stack(core, addr, size);
230  return;
231 }
232 
242  rz_return_if_fail(core && core->analysis);
244  RzAnalysisEsil *esil = core->analysis->esil;
245  char *stack_name = get_esil_stack_name(core, name, &addr, &size);
246  if (esil && esil->stack_fd > 2) { // 0, 1, 2 are reserved for stdio/stderr
247  rz_io_fd_close(core->io, esil->stack_fd);
248  // no need to kill the maps, rz_io_map_cleanup does that for us in the close
249  esil->stack_fd = 0;
250  } else {
251  eprintf("Cannot deinitialize %s\n", stack_name);
252  }
253  rz_flag_unset_name(core->flags, stack_name);
254  rz_flag_unset_name(core->flags, "aeim.stack");
255  sdb_unset(core->sdb, "aeim.fd", 0);
256  free(stack_name);
257 }
258 
265  rz_return_if_fail(core);
266  rz_core_analysis_set_reg(core, "PC", core->offset);
267 }
268 
271  ut64 until_addr = UT64_MAX;
272  if (op && op->type == RZ_ANALYSIS_OP_TYPE_CALL) {
273  until_addr = op->addr + op->size;
274  }
275  rz_core_esil_step(core, until_addr, NULL, NULL, false);
278 }
279 
281  rz_core_esil_step(core, addr, NULL, NULL, true);
283 }
284 
286  rz_core_esil_step(core, UT64_MAX, expr, NULL, true);
288 }
289 
291  RzListIter *it;
292  RzAnalysisFunction *fcn;
293  rz_list_foreach (core->analysis->fcns, it, fcn) {
296  rz_core_analysis_esil(core, from, to - from, fcn);
297  }
298 }
299 
305 RZ_IPI void rz_core_analysis_esil_emulate(RzCore *core, ut64 addr, ut64 until_addr, int off) {
306  RzAnalysisEsil *esil = core->analysis->esil;
307  int i = 0, j = 0;
308  ut8 *buf = NULL;
309  RzAnalysisOp aop = { 0 };
310  int ret, bsize = RZ_MAX(4096, core->blocksize);
311  const int mininstrsz = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE);
312  const int minopcode = RZ_MAX(1, mininstrsz);
313  const char *pc = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_PC);
314  int stacksize = rz_config_get_i(core->config, "esil.stack.depth");
315  int iotrap = rz_config_get_i(core->config, "esil.iotrap");
316  ut64 addrsize = rz_config_get_i(core->config, "esil.addr.size");
317 
318  if (!esil) {
319  eprintf("Warning: cmd_espc: creating new esil instance\n");
320  if (!(esil = rz_analysis_esil_new(stacksize, iotrap, addrsize))) {
321  return;
322  }
323  core->analysis->esil = esil;
324  }
325  buf = malloc(bsize);
326  if (!buf) {
327  eprintf("Cannot allocate %d byte(s)\n", bsize);
328  return;
329  }
330  if (addr == -1) {
331  addr = rz_reg_getv(core->analysis->reg, pc);
332  }
333  (void)rz_analysis_esil_setup(core->analysis->esil, core->analysis, 0, 0, 0); // int romem, int stats, int nonull) {
334  ut64 cursp = rz_reg_getv(core->analysis->reg, "SP");
335  ut64 oldoff = core->offset;
337  for (i = 0, j = 0; j < off; i++, j++) {
338  if (rz_cons_is_breaked()) {
339  break;
340  }
341  if (i >= (bsize - 32)) {
342  i = 0;
343  eprintf("Warning: Chomp\n");
344  }
345  if (!i) {
346  rz_io_read_at(core->io, addr, buf, bsize);
347  }
348  if (addr == until_addr) {
349  break;
350  }
351  ret = rz_analysis_op(core->analysis, &aop, addr, buf + i, bsize - i, flags);
352  if (ret < 1) {
353  eprintf("Failed analysis at 0x%08" PFMT64x "\n", addr);
354  break;
355  }
356  // skip calls and such
357  if (aop.type == RZ_ANALYSIS_OP_TYPE_CALL) {
358  // nothing
359  } else {
360  rz_reg_setv(core->analysis->reg, "PC", aop.addr + aop.size);
361  const char *e = RZ_STRBUF_SAFEGET(&aop.esil);
362  if (e && *e) {
363  // eprintf (" 0x%08llx %d %s\n", aop.addr, ret, aop.mnemonic);
364  (void)rz_analysis_esil_parse(esil, e);
365  }
366  }
367  int inc = (core->search->align > 0) ? core->search->align - 1 : ret - 1;
368  if (inc < 0) {
369  inc = minopcode;
370  }
371  i += inc;
372  addr += ret; // aop.size;
373  rz_analysis_op_fini(&aop);
374  }
375  rz_core_seek(core, oldoff, true);
376  rz_reg_setv(core->analysis->reg, "SP", cursp);
377  free(buf);
378 }
379 
382  if (!bb) {
383  RZ_LOG_ERROR("Cannot find basic block for 0x%08" PFMT64x "\n", core->offset);
384  return;
385  }
387 }
388 
390  RzRegItem *r = rz_reg_get(core->analysis->reg, regname, -1);
391  if (!r) {
392  int role = rz_reg_get_name_idx(regname);
393  if (role != -1) {
394  const char *alias = rz_reg_get_name(core->analysis->reg, role);
395  if (alias) {
396  r = rz_reg_get(core->analysis->reg, alias, -1);
397  }
398  }
399  }
400  if (!r) {
401  eprintf("ar: Unknown register '%s'\n", regname);
402  return -1;
403  }
404  rz_reg_set_value(core->analysis->reg, r, val);
406  return 0;
407 }
408 
410  RzIOMap *map;
411  RzListIter *iter;
412  RzList *list = rz_core_get_boundaries_prot(core, -1, NULL, "analysis");
413  if (!list) {
414  return;
415  }
416  if (!strcmp("range", rz_config_get(core->config, "analysis.in"))) {
417  ut64 from = rz_config_get_i(core->config, "analysis.from");
418  ut64 to = rz_config_get_i(core->config, "analysis.to");
419  if (to > from) {
421  } else {
422  eprintf("Assert: analysis.from > analysis.to\n");
423  }
424  } else {
425  rz_list_foreach (list, iter, map) {
426  if (map->perm & RZ_PERM_X) {
427  rz_core_analysis_esil(core, map->itv.addr, map->itv.size, NULL);
428  }
429  }
430  }
432 }
433 
436  if (core->analysis->il_vm) {
437  // initialize the program counter with the current offset
440  }
441 }
442 
451 RZ_IPI bool rz_core_analysis_il_vm_set(RzCore *core, const char *var_name, ut64 value) {
452  rz_return_val_if_fail(core && core->analysis && var_name, false);
453 
454  RzAnalysisILVM *vm = core->analysis->il_vm;
455  if (!vm) {
456  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
457  return false;
458  }
459 
460  if (!strcmp(var_name, "PC")) {
462  rz_bv_free(vm->vm->pc);
463  vm->vm->pc = bv;
464  return true;
465  }
466 
467  RzILVar *var = rz_il_vm_get_var(vm->vm, RZ_IL_VAR_KIND_GLOBAL, var_name);
468  if (!var) {
469  return false;
470  }
471  RzILVal *val = NULL;
472  switch (var->sort.type) {
475  break;
478  break;
479  }
480  if (val) {
481  rz_il_vm_set_global_var(vm->vm, var_name, val);
482  }
483  return true;
484 }
485 
486 typedef struct il_print_t {
488  const char *name;
489  void *ptr;
491 #define p_sb(x) ((RzStrBuf *)x)
492 #define p_tbl(x) ((RzTable *)x)
493 #define p_pj(x) ((PJ *)x)
494 
496  switch (p->mode) {
498  rz_strbuf_appendf(p_sb(p->ptr), " %s: %s", p->name, rz_str_bool(value));
499  break;
501  rz_table_add_rowf(p_tbl(p->ptr), "sss", p->name, "bool", rz_str_bool(value));
502  break;
503  case RZ_OUTPUT_MODE_JSON:
504  pj_kb(p_pj(p->ptr), p->name, value);
505  break;
506  default:
507  rz_cons_printf("%s\n", rz_str_bool(value));
508  break;
509  }
510 }
511 
513  char *hex = rz_bv_as_hex_string(number, true);
514  switch (p->mode) {
516  rz_strbuf_appendf(p_sb(p->ptr), " %s: %s", p->name, hex);
517  break;
519  rz_table_add_rowf(p_tbl(p->ptr), "sss", p->name, "bitv", hex);
520  break;
521  case RZ_OUTPUT_MODE_JSON:
522  pj_ks(p_pj(p->ptr), p->name, hex);
523  break;
524  default:
525  rz_cons_printf("%s\n", hex);
526  break;
527  }
528  free(hex);
529 }
530 
531 RZ_IPI void rz_core_analysis_il_vm_status(RzCore *core, const char *var_name, RzOutputMode mode) {
532  RzAnalysisILVM *vm = core->analysis->il_vm;
533  if (!vm) {
534  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
535  return;
536  }
537 
538  ILPrint p = { 0 };
539  p.mode = mode;
540 
541  switch (mode) {
543  p.ptr = rz_strbuf_new("");
544  break;
546  p.ptr = rz_table_new();
547  rz_table_set_columnsf(p_tbl(p.ptr), "sss", "variable", "type", "value");
548  break;
549  case RZ_OUTPUT_MODE_JSON:
550  p.ptr = pj_new();
551  pj_o(p_pj(p.ptr));
552  break;
553  default:
554  break;
555  }
556 
557  if (!var_name || !strcmp(var_name, "PC")) {
558  p.name = "PC";
560  }
561 
563  if (global_vars) {
564  void **it;
565  rz_pvector_foreach (global_vars, it) {
566  RzILVar *var = *it;
567  if (var_name && strcmp(var_name, var->name)) {
568  continue;
569  }
570  p.name = var->name;
572  if (!val) {
573  continue;
574  }
575  switch (val->type) {
577  rzil_print_register_bitv(val->data.bv, &p);
578  break;
580  rzil_print_register_bool(val->data.b->b, &p);
581  break;
582  default:
584  break;
585  }
586  if (var_name) {
587  break;
588  }
589  if (rz_strbuf_length(p_sb(p.ptr)) > 95) {
590  rz_cons_printf("%s\n", rz_strbuf_get(p_sb(p.ptr)));
591  rz_strbuf_fini(p_sb(p.ptr));
592  }
593  }
594  rz_pvector_free(global_vars);
595  }
596 
597  char *out = NULL;
598  switch (mode) {
600  if (rz_strbuf_length(p_sb(p.ptr)) > 0) {
601  out = rz_strbuf_drain(p_sb(p.ptr));
602  } else {
603  rz_strbuf_free(p_sb(p.ptr));
604  return;
605  }
606  break;
608  out = rz_table_tostring((RzTable *)p.ptr);
609  rz_table_free(p_tbl(p.ptr));
610  break;
611  case RZ_OUTPUT_MODE_JSON:
612  pj_end(p_pj(p.ptr));
613  out = pj_drain(p_pj(p.ptr));
614  break;
615  default:
616  return;
617  }
618 
619  rz_cons_printf("%s\n", out);
620  free(out);
621 }
622 #undef p_sb
623 #undef p_tbl
624 #undef p_pj
625 
631  if (!core->analysis || !core->analysis->il_vm) {
632  RZ_LOG_ERROR("RzIL: Run 'aezi' first to initialize the VM\n");
633  return false;
634  }
636  switch (r) {
639  return true;
641  RZ_LOG_ERROR("RzIL: invalid instruction or lifting not implemented at address 0x%08" PFMT64x "\n",
643  break;
644  default:
645  RZ_LOG_ERROR("RzIL: stepping failed.\n");
646  break;
647  }
648  return false;
649 }
650 
656  if (!rz_core_il_step(core)) {
657  return false;
658  }
659 
660  if (!core->analysis || !core->analysis->il_vm) {
661  return false;
662  }
663 
664  RzILVM *vm = core->analysis->il_vm->vm;
665 
666  RzStrBuf *sb = NULL;
667  RzListIter *it;
668  RzILEvent *evt;
669 
670  bool evt_read = rz_config_get_b(core->config, "rzil.step.events.read");
671  bool evt_write = rz_config_get_b(core->config, "rzil.step.events.write");
672 
673  if (!evt_read && !evt_write) {
674  RZ_LOG_ERROR("RzIL: cannot print events when all the events are disabled.");
675  RZ_LOG_ERROR("RzIL: please set 'rzil.step.events.read' or/and 'rzil.step.events.write' to true and try again.");
676  return false;
677  }
678 
679  if (!pj) {
680  sb = rz_strbuf_new("");
681  }
682  rz_list_foreach (vm->events, it, evt) {
683  if (!evt_read && (evt->type == RZ_IL_EVENT_MEM_READ || evt->type == RZ_IL_EVENT_VAR_READ)) {
684  continue;
685  } else if (!evt_write && (evt->type != RZ_IL_EVENT_MEM_READ && evt->type != RZ_IL_EVENT_VAR_READ)) {
686  continue;
687  }
688  if (!pj) {
690  rz_strbuf_append(sb, "\n");
691  } else {
692  rz_il_event_json(evt, pj);
693  }
694  }
695  if (!pj) {
696  rz_cons_print(rz_strbuf_get(sb));
698  }
699  return true;
700 }
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API ut64 rz_analysis_function_min_addr(RzAnalysisFunction *fcn)
Definition: function.c:323
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
#define e(frag)
RZ_API bool rz_analysis_il_vm_setup(RzAnalysis *analysis)
Definition: analysis_il.c:285
RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg)
Definition: analysis_il.c:240
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index ** i
Definition: index.h:629
ut16 val
Definition: armass64_const.h:6
static SblHeader sb
Definition: bin_mbn.c:26
RZ_API RzAnalysisBlock * rz_analysis_find_most_relevant_block_in(RzAnalysis *analysis, ut64 off)
Definition: block.c:997
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
RZ_API void rz_core_analysis_esil(RzCore *core, ut64 addr, ut64 size, RZ_NULLABLE RzAnalysisFunction *fcn)
Definition: canalysis.c:4499
RZ_IPI void rz_core_analysis_esil_emulate(RzCore *core, ut64 addr, ut64 until_addr, int off)
Definition: cil.c:305
RZ_IPI void rz_core_analysis_esil_init_mem_p(RzCore *core)
Definition: cil.c:213
RZ_IPI void rz_core_analysis_esil_emulate_bb(RzCore *core)
Definition: cil.c:380
struct il_print_t ILPrint
RZ_IPI bool rz_core_analysis_il_vm_set(RzCore *core, const char *var_name, ut64 value)
Set a vm variable from user input.
Definition: cil.c:451
RZ_IPI void rz_core_analysis_esil_references_all_functions(RzCore *core)
Definition: cil.c:290
static void rzil_print_register_bitv(RzBitVector *number, ILPrint *p)
Definition: cil.c:512
RZ_API void rz_core_analysis_esil_init_mem(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Definition: cil.c:149
RZ_IPI void rz_core_analysis_esil_default(RzCore *core)
Definition: cil.c:409
static void initialize_stack(RzCore *core, ut64 addr, ut64 size)
Definition: cil.c:76
RZ_IPI bool rz_core_analysis_il_step_with_events(RzCore *core, PJ *pj)
Definition: cil.c:655
RZ_API void rz_core_analysis_esil_init_regs(RZ_NONNULL RzCore *core)
Definition: cil.c:264
static void rzil_print_register_bool(bool value, ILPrint *p)
Definition: cil.c:495
static void core_esil_init(RzCore *core)
Definition: cil.c:18
RZ_IPI void rz_core_analysis_esil_init(RzCore *core)
Definition: cil.c:43
RZ_IPI void rz_core_analysis_esil_step_over_until(RzCore *core, ut64 addr)
Definition: cil.c:280
RZ_IPI bool rz_core_il_step(RzCore *core)
Definition: cil.c:630
RZ_IPI void rz_core_analysis_il_vm_status(RzCore *core, const char *var_name, RzOutputMode mode)
Definition: cil.c:531
RZ_IPI int rz_core_analysis_set_reg(RzCore *core, const char *regname, ut64 val)
Definition: cil.c:389
RZ_API void rz_core_analysis_esil_step_over(RZ_NONNULL RzCore *core)
Definition: cil.c:269
#define p_sb(x)
Definition: cil.c:491
RZ_API void rz_core_analysis_esil_reinit(RZ_NONNULL RzCore *core)
Reinitialize ESIL.
Definition: cil.c:54
#define p_tbl(x)
Definition: cil.c:492
#define p_pj(x)
Definition: cil.c:493
static char * get_esil_stack_name(RzCore *core, const char *name, ut64 *addr, ut32 *size)
Definition: cil.c:111
RZ_API void rz_core_analysis_esil_deinit(RZ_NONNULL RzCore *core)
Deinitialize ESIL.
Definition: cil.c:66
RZ_IPI void rz_core_analysis_esil_step_over_untilexpr(RzCore *core, const char *expr)
Definition: cil.c:285
RZ_API void rz_core_analysis_esil_init_mem_del(RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
Remove ESIL VM stack.
Definition: cil.c:241
RZ_IPI void rz_core_analysis_il_reinit(RzCore *core)
Definition: cil.c:434
RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size)
Definition: cio.c:145
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver)
Definition: cmd_analysis.c:860
static int value
Definition: cmd_api.c:93
RZ_API RZ_OWN RzList * rz_core_get_boundaries_prot(RzCore *core, int perm, const char *mode, const char *prefix)
Definition: cmd_search.c:577
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 RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API RzConfigNode * rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name, bool value)
Definition: config.c:201
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
#define RZ_API
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
uint32_t ut32
const char * v
Definition: dsignal.c:12
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API RzAnalysisEsil * rz_analysis_esil_new(int stacksize, int iotrap, unsigned int addrsize)
Definition: esil.c:85
RZ_API bool rz_analysis_esil_setup(RzAnalysisEsil *esil, RzAnalysis *analysis, int romem, int stats, int nonull)
Definition: esil.c:3298
RZ_API bool rz_analysis_esil_parse(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:2998
RZ_API void rz_analysis_esil_free(RzAnalysisEsil *esil)
Definition: esil.c:163
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzILVal * rz_il_value_new_bitv(RZ_NONNULL RzBitVector *bv)
Definition: value.c:28
RZ_API RZ_OWN RzILVal * rz_il_value_new_bool(RZ_NONNULL RzILBool *b)
Definition: value.c:43
RZ_API void rz_il_event_json(RZ_NONNULL RzILEvent *evt, RZ_NONNULL PJ *pj)
Definition: il_export.c:797
RZ_API void rz_il_event_stringify(RZ_NONNULL const RzILEvent *evt, RZ_NONNULL RzStrBuf *sb)
Definition: il_export.c:753
RZ_API void rz_il_vm_set_global_var(RZ_NONNULL RzILVM *vm, RZ_NONNULL const char *name, RZ_OWN RzILVal *val)
Definition: il_vm.c:193
RZ_API RZ_OWN RzPVector * rz_il_vm_get_all_vars(RZ_NONNULL RzILVM *vm, RzILVarKind kind)
Definition: il_vm.c:256
RZ_API RZ_BORROW RzILVal * rz_il_vm_get_var_value(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:264
RZ_API RZ_BORROW RzILVar * rz_il_vm_get_var(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:251
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void * malloc(size_t size)
Definition: malloc.c:123
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
int off
Definition: pal.c:13
static const char hex[16]
Definition: print.c:21
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API int rz_reg_get_name_idx(const char *type)
Definition: reg.c:102
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
RZ_API bool rz_reg_set_value_by_role(RzReg *reg, RzRegisterId role, ut64 val)
Definition: rvalue.c:269
RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role)
Definition: rvalue.c:181
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
RzAnalysisILStepResult
Definition: rz_analysis.h:1161
@ RZ_ANALYSIS_IL_STEP_INVALID_OP
Definition: rz_analysis.h:1165
@ RZ_ANALYSIS_IL_STEP_RESULT_SUCCESS
Definition: rz_analysis.h:1162
@ RZ_ANALYSIS_OP_MASK_DISASM
Definition: rz_analysis.h:445
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
@ RZ_ANALYSIS_OP_MASK_HINT
Definition: rz_analysis.h:443
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#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 void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
RZ_API RZ_OWN char * rz_bv_as_hex_string(RZ_NONNULL RzBitVector *bv, bool pad)
Definition: bitvector.c:121
RZ_API RZ_OWN char * rz_debruijn_pattern(int size, int start, const char *charset)
Generate a cyclic pattern following the Debruijn pattern.
Definition: debruijn.c:80
@ RZ_IL_EVENT_VAR_READ
Definition: rz_il_events.h:23
@ RZ_IL_EVENT_MEM_READ
Definition: rz_il_events.h:22
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API int rz_io_fd_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io_fd.c:6
RZ_API ut64 rz_io_map_next_available(RzIO *io, ut64 addr, ut64 size, ut64 load_align)
Definition: io_map.c:347
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RZ_API void rz_io_map_set_name(RzIOMap *map, const char *name)
Definition: io_map.c:332
RZ_API RzIOMap * rz_io_map_add(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:151
RZ_API bool rz_io_fd_close(RzIO *io, int fd)
Definition: io_fd.c:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API char * pj_drain(PJ *j)
Definition: pj.c:50
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
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 void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
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 int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
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 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
#define PFMT64d
Definition: rz_types.h:394
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_PERM_X
Definition: rz_types.h:95
#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_STANDARD
Definition: rz_types.h:39
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)
#define UT32_MAX
Definition: rz_types_base.h:99
#define RZ_MAX(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API void sdb_reset(Sdb *s)
Definition: sdb.c:433
RZ_API const char * sdb_const_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:279
RZ_API int sdb_unset(Sdb *s, const char *key, ut32 cas)
Definition: sdb.c:294
RZ_API char * sdb_itoa(ut64 n, char *s, int base)
Definition: util.c:38
RZ_API ut64 sdb_atoi(const char *s)
Definition: util.c:88
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 struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
@ RZ_IL_TYPE_PURE_BOOL
Definition: sort.h:24
@ RZ_IL_TYPE_PURE_BITVECTOR
Definition: sort.h:25
structure for bitvector
Definition: rz_bitvector.h:19
ut32 len
number of bits – virtual / logical
Definition: rz_bitvector.h:25
RzOutputMode mode
Definition: cil.c:487
void * ptr
Definition: cil.c:489
const char * name
Definition: cil.c:488
Definition: z80asm.h:102
Definition: rz_pj.h:12
RzAnalysis * analysis
Definition: rz_analysis.h:1043
High-level RzIL vm to emulate disassembled code.
Definition: rz_analysis.h:1155
RZ_NONNULL RzILVM * vm
low-level vm to execute IL code
Definition: rz_analysis.h:1156
RzList * fcns
Definition: rz_analysis.h:565
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584
RzAnalysisILVM * il_vm
user-faced VM, NEVER use this for any analysis passes!
Definition: rz_analysis.h:585
RzSearch * search
Definition: rz_core.h:331
ut64 offset
Definition: rz_core.h:301
RzAnalysis * analysis
Definition: rz_core.h:322
RzIO * io
Definition: rz_core.h:313
RzFlag * flags
Definition: rz_core.h:330
ut32 blocksize
Definition: rz_core.h:303
RzConfig * config
Definition: rz_core.h:300
ut64 offset
Definition: rz_flag.h:38
struct rz_il_sort_pure_t::@283::@284 bv
union rz_il_sort_pure_t::@283 props
RzILTypePure type
Definition: sort.h:29
Definition of a variable inside the vm.
Definition: variable.h:19
RzILSortPure sort
"type" of the variable
Definition: variable.h:21
char * name
Definition: variable.h:20
RzILEventId type
Definition: rz_il_events.h:56
Low-level VM to execute raw IL code.
Definition: rz_il_vm.h:37
RzList * events
List of events that has happened in the last step.
Definition: rz_il_vm.h:49
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
Definition: dis.c:32
@ RZ_IL_VAR_KIND_GLOBAL
global var, usually bound to a physical representation like a register.
Definition: variable.h:47
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static char * regname(int reg)
Definition: dis.c:71
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int verbose
Definition: z80asm.c:73
static int addr
Definition: z80asm.c:58