Rizin
unix-like reverse engineering framework and cli tools
cil.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_list.h>
#include <rz_flag.h>
#include <rz_core.h>
#include <rz_bin.h>
#include <ht_uu.h>
#include <rz_util/rz_graph_drawable.h>
#include "core_private.h"

Go to the source code of this file.

Classes

struct  il_print_t
 

Macros

#define p_sb(x)   ((RzStrBuf *)x)
 
#define p_tbl(x)   ((RzTable *)x)
 
#define p_pj(x)   ((PJ *)x)
 

Typedefs

typedef struct il_print_t ILPrint
 

Functions

static void core_esil_init (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_init (RzCore *core)
 
RZ_API void rz_core_analysis_esil_reinit (RZ_NONNULL RzCore *core)
 Reinitialize ESIL. More...
 
RZ_API void rz_core_analysis_esil_deinit (RZ_NONNULL RzCore *core)
 Deinitialize ESIL. More...
 
static void initialize_stack (RzCore *core, ut64 addr, ut64 size)
 
static char * get_esil_stack_name (RzCore *core, const char *name, ut64 *addr, ut32 *size)
 
RZ_API void rz_core_analysis_esil_init_mem (RZ_NONNULL RzCore *core, RZ_NULLABLE const char *name, ut64 addr, ut32 size)
 
RZ_IPI void rz_core_analysis_esil_init_mem_p (RzCore *core)
 
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. More...
 
RZ_API void rz_core_analysis_esil_init_regs (RZ_NONNULL RzCore *core)
 
RZ_API void rz_core_analysis_esil_step_over (RZ_NONNULL RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_step_over_until (RzCore *core, ut64 addr)
 
RZ_IPI void rz_core_analysis_esil_step_over_untilexpr (RzCore *core, const char *expr)
 
RZ_IPI void rz_core_analysis_esil_references_all_functions (RzCore *core)
 
RZ_IPI void rz_core_analysis_esil_emulate (RzCore *core, ut64 addr, ut64 until_addr, int off)
 
RZ_IPI void rz_core_analysis_esil_emulate_bb (RzCore *core)
 
RZ_IPI int rz_core_analysis_set_reg (RzCore *core, const char *regname, ut64 val)
 
RZ_IPI void rz_core_analysis_esil_default (RzCore *core)
 
RZ_IPI void rz_core_analysis_il_reinit (RzCore *core)
 
RZ_IPI bool rz_core_analysis_il_vm_set (RzCore *core, const char *var_name, ut64 value)
 Set a vm variable from user input. More...
 
static void rzil_print_register_bool (bool value, ILPrint *p)
 
static void rzil_print_register_bitv (RzBitVector *number, ILPrint *p)
 
RZ_IPI void rz_core_analysis_il_vm_status (RzCore *core, const char *var_name, RzOutputMode mode)
 
RZ_IPI bool rz_core_il_step (RzCore *core)
 
RZ_IPI bool rz_core_analysis_il_step_with_events (RzCore *core, PJ *pj)
 

Macro Definition Documentation

◆ p_pj

#define p_pj (   x)    ((PJ *)x)

Definition at line 493 of file cil.c.

◆ p_sb

#define p_sb (   x)    ((RzStrBuf *)x)

Definition at line 491 of file cil.c.

◆ p_tbl

#define p_tbl (   x)    ((RzTable *)x)

Definition at line 492 of file cil.c.

Typedef Documentation

◆ ILPrint

typedef struct il_print_t ILPrint

Function Documentation

◆ core_esil_init()

static void core_esil_init ( RzCore core)
static

Definition at line 18 of file cil.c.

18  {
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 }
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
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
#define NULL
Definition: cris-opc.c:27
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 void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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 RzSocket * s
Definition: rtr.c:28
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584
RzAnalysis * analysis
Definition: rz_core.h:322
RzConfig * config
Definition: rz_core.h:300
static int verbose
Definition: z80asm.c:73

References rz_core_t::analysis, rz_core_t::config, rz_analysis_t::esil, free(), NULL, rz_analysis_esil_new(), rz_analysis_esil_setup(), rz_config_get(), rz_config_get_i(), rz_config_set(), s, strdup(), verbose, and rz_analysis_esil_t::verbose.

Referenced by rz_core_analysis_esil_init(), and rz_core_analysis_esil_reinit().

◆ get_esil_stack_name()

static char* get_esil_stack_name ( RzCore core,
const char *  name,
ut64 addr,
ut32 size 
)
static

Definition at line 111 of file cil.c.

111  {
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 }
uint32_t ut32
size_t map(int syms, int left, int len)
Definition: enough.c:237
voidpf void uLong size
Definition: ioapi.h:138
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 char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
#define PFMT64x
Definition: rz_types.h:393
#define UT32_MAX
Definition: rz_types_base.h:99
#define UT64_MAX
Definition: rz_types_base.h:86
Definition: z80asm.h:102
ut64 offset
Definition: rz_core.h:301
RzIO * io
Definition: rz_core.h:313
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, rz_core_t::config, rz_core_t::io, map(), rz_core_t::offset, PFMT64x, rz_config_get_i(), rz_io_map_get(), rz_io_map_next_available(), RZ_STR_ISEMPTY, rz_str_newf(), UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_core_analysis_esil_init_mem(), and rz_core_analysis_esil_init_mem_del().

◆ initialize_stack()

static void initialize_stack ( RzCore core,
ut64  addr,
ut64  size 
)
static

Definition at line 76 of file cil.c.

76  {
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 }
lzma_index ** i
Definition: index.h:629
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
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define eprintf(x, y...)
Definition: rlcc.c:7
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
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64u
Definition: rz_types.h:395
#define RZ_MIN(x, y)

References addr, rz_core_t::config, eprintf, free(), i, NULL, PFMT64d, PFMT64u, PFMT64x, rz_config_get(), rz_core_cmdf(), rz_core_write_at(), rz_debruijn_pattern(), RZ_MIN, and ut64().

Referenced by rz_core_analysis_esil_init_mem(), and rz_core_analysis_esil_init_mem_p().

◆ rz_core_analysis_esil_default()

RZ_IPI void rz_core_analysis_esil_default ( RzCore core)

Definition at line 409 of file cil.c.

409  {
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 }
RZ_API void rz_core_analysis_esil(RzCore *core, ut64 addr, ut64 size, RZ_NULLABLE RzAnalysisFunction *fcn)
Definition: canalysis.c:4499
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
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
#define RZ_PERM_X
Definition: rz_types.h:95
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

References rz_core_t::config, eprintf, from, list(), map(), NULL, rz_config_get(), rz_config_get_i(), rz_core_analysis_esil(), rz_core_get_boundaries_prot(), rz_list_free(), RZ_PERM_X, to, and ut64().

Referenced by objc_analyze(), and rz_analysis_all_esil_handler().

◆ rz_core_analysis_esil_deinit()

RZ_API void rz_core_analysis_esil_deinit ( RZ_NONNULL RzCore core)

Deinitialize ESIL.

Parameters
coreRzCore reference

Definition at line 66 of file cil.c.

66  {
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 }
RZ_API void rz_analysis_esil_free(RzAnalysisEsil *esil)
Definition: esil.c:163
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API void sdb_reset(Sdb *s)
Definition: sdb.c:433
RzAnalysis * analysis
Definition: rz_analysis.h:1043

References rz_analysis_esil_t::analysis, rz_analysis_t::esil, NULL, rz_analysis_esil_free(), rz_return_if_fail, sdb_reset(), and rz_analysis_esil_t::stats.

Referenced by rz_analysis_esil_deinit_handler().

◆ rz_core_analysis_esil_emulate()

RZ_IPI void rz_core_analysis_esil_emulate ( RzCore core,
ut64  addr,
ut64  until_addr,
int  off 
)

Emulate n_instr instructions from addr. If until_addr is specified and that address is met before all the instructions are emulated, stop there.

Definition at line 305 of file cil.c.

305  {
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 }
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
#define e(frag)
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API bool rz_analysis_esil_parse(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:2998
void * malloc(size_t size)
Definition: malloc.c:123
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
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
@ 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
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
#define RZ_MAX(x, y)
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
RzSearch * search
Definition: rz_core.h:331
ut32 blocksize
Definition: rz_core.h:303
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References addr, rz_analysis_op_t::addr, rz_search_t::align, rz_core_t::analysis, rz_core_t::blocksize, rz_core_t::config, e, eprintf, rz_analysis_t::esil, rz_analysis_op_t::esil, flags, free(), i, if(), rz_core_t::io, malloc(), NULL, off, rz_core_t::offset, pc, PFMT64x, rz_analysis_t::reg, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE, rz_analysis_esil_new(), rz_analysis_esil_parse(), rz_analysis_esil_setup(), rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_DISASM, RZ_ANALYSIS_OP_MASK_ESIL, RZ_ANALYSIS_OP_MASK_HINT, RZ_ANALYSIS_OP_TYPE_CALL, rz_config_get_i(), rz_cons_is_breaked(), rz_core_seek(), rz_io_read_at(), RZ_MAX, rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_PC, rz_reg_setv(), RZ_STRBUF_SAFEGET, rz_core_t::search, rz_analysis_op_t::size, rz_analysis_op_t::type, and ut64().

Referenced by rz_core_analysis_esil_emulate_bb(), rz_il_step_evaluate_handler(), and rz_il_step_handler().

◆ rz_core_analysis_esil_emulate_bb()

RZ_IPI void rz_core_analysis_esil_emulate_bb ( RzCore core)

Definition at line 380 of file cil.c.

380  {
382  if (!bb) {
383  RZ_LOG_ERROR("Cannot find basic block for 0x%08" PFMT64x "\n", core->offset);
384  return;
385  }
387 }
RZ_API RzAnalysisBlock * rz_analysis_find_most_relevant_block_in(RzAnalysis *analysis, ut64 off)
Definition: block.c:997
RZ_IPI void rz_core_analysis_esil_emulate(RzCore *core, ut64 addr, ut64 until_addr, int off)
Definition: cil.c:305
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58

References rz_analysis_bb_t::addr, rz_core_t::analysis, rz_analysis_bb_t::ninstr, rz_core_t::offset, PFMT64x, rz_analysis_find_most_relevant_block_in(), rz_core_analysis_esil_emulate(), RZ_LOG_ERROR, and UT64_MAX.

Referenced by cmd_analysis_esil().

◆ rz_core_analysis_esil_init()

◆ rz_core_analysis_esil_init_mem()

RZ_API void rz_core_analysis_esil_init_mem ( RZ_NONNULL RzCore core,
RZ_NULLABLE const char *  name,
ut64  addr,
ut32  size 
)

Initialize ESIL memory stack region.

Parameters
coreRzCore reference
nameOptional name of the memory stack region. If NULL, a name is computed automatically based on addr and size
addrBase address of the stack region, if UT64_MAX it is automatically computed
sizeSize of the stack region, if UT32_MAX it is automatically computed

Definition at line 149 of file cil.c.

149  {
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 }
ut16 val
Definition: armass64_const.h:6
static void initialize_stack(RzCore *core, ut64 addr, ut64 size)
Definition: cil.c:76
RZ_IPI void rz_core_analysis_esil_init(RzCore *core)
Definition: cil.c:43
static char * get_esil_stack_name(RzCore *core, const char *name, ut64 *addr, ut32 *size)
Definition: cil.c:111
RZ_API RzConfigNode * rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name, bool value)
Definition: config.c:201
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
const char * v
Definition: dsignal.c:12
RZ_API bool rz_reg_set_value_by_role(RzReg *reg, RzRegisterId role, ut64 val)
Definition: rvalue.c:269
RZ_API int rz_io_fd_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io_fd.c:6
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
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_PERM_RW
Definition: rz_types.h:96
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API const char * sdb_const_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:279
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
static const z80_opcode fd[]
Definition: z80_tab.h:997

References addr, rz_analysis_esil_t::analysis, eprintf, rz_analysis_t::esil, fd, free(), get_esil_stack_name(), initialize_stack(), PFMT64x, rz_config_get(), rz_config_set_b(), rz_core_analysis_esil_init(), rz_core_cmdf(), rz_core_reg_update_flags(), rz_core_seek(), rz_io_fd_close(), rz_io_fd_open(), rz_io_map_add(), rz_io_map_set_name(), RZ_PERM_RW, RZ_REG_NAME_BP, RZ_REG_NAME_PC, RZ_REG_NAME_SP, rz_reg_set_value_by_role(), rz_return_if_fail, rz_strf, sdb_atoi(), sdb_const_get(), sdb_itoa(), sdb_set(), rz_analysis_esil_t::stack_addr, rz_analysis_esil_t::stack_fd, rz_analysis_esil_t::stack_size, UT32_MAX, ut64(), UT64_MAX, v, and val.

Referenced by __analysis_esil_function(), __esil_init(), rz_analysis_aefa(), rz_analysis_esil_init_mem_handler(), rz_core_analysis_esil(), rz_core_analysis_esil_init_mem_p(), rz_core_analysis_types_propagation(), rz_core_disasm_pde(), and rz_core_link_stroff().

◆ rz_core_analysis_esil_init_mem_del()

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.

Parameters
coreRzCore reference
nameOptional name of the memory stack region. If NULL, a name is computed automatically based on addr and size
addrBase address of the stack region, if UT64_MAX it is automatically computed
sizeSize of the stack region, if UT32_MAX it is automatically computed

Definition at line 241 of file cil.c.

241  {
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 }
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
RZ_API int sdb_unset(Sdb *s, const char *key, ut32 cas)
Definition: sdb.c:294

References addr, rz_analysis_esil_t::analysis, eprintf, rz_analysis_t::esil, free(), get_esil_stack_name(), rz_core_analysis_esil_init(), rz_flag_unset_name(), rz_io_fd_close(), rz_return_if_fail, sdb_unset(), and rz_analysis_esil_t::stack_fd.

Referenced by rz_analysis_esil_init_mem_remove_handler(), rz_core_analysis_types_propagation(), and rz_core_link_stroff().

◆ rz_core_analysis_esil_init_mem_p()

RZ_IPI void rz_core_analysis_esil_init_mem_p ( RzCore core)

Definition at line 213 of file cil.c.

213  {
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 }
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_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RzFlag * flags
Definition: rz_core.h:330
ut64 offset
Definition: rz_flag.h:38

References addr, rz_core_t::analysis, rz_analysis_t::esil, rz_core_t::flags, initialize_stack(), NULL, rz_flag_item_t::offset, rz_core_analysis_esil_init(), rz_core_analysis_esil_init_mem(), rz_flag_get(), rz_flag_item_t::size, rz_analysis_esil_t::stack_addr, rz_analysis_esil_t::stack_size, UT32_MAX, ut64(), and UT64_MAX.

Referenced by rz_analysis_esil_init_mem_p_handler().

◆ rz_core_analysis_esil_init_regs()

RZ_API void rz_core_analysis_esil_init_regs ( RZ_NONNULL RzCore core)

Initialize ESIL registers.

Parameters
coreRzCore reference

Definition at line 264 of file cil.c.

264  {
265  rz_return_if_fail(core);
266  rz_core_analysis_set_reg(core, "PC", core->offset);
267 }
RZ_IPI int rz_core_analysis_set_reg(RzCore *core, const char *regname, ut64 val)
Definition: cil.c:389

References rz_core_analysis_set_reg(), and rz_return_if_fail.

Referenced by __esil_init().

◆ rz_core_analysis_esil_references_all_functions()

RZ_IPI void rz_core_analysis_esil_references_all_functions ( RzCore core)

Definition at line 290 of file cil.c.

290  {
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 }
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
RzList * fcns
Definition: rz_analysis.h:565

References rz_core_t::analysis, rz_analysis_t::fcns, from, rz_analysis_function_max_addr(), rz_analysis_function_min_addr(), rz_core_analysis_esil(), to, and ut64().

Referenced by rz_analysis_all_esil_functions_handler(), and rz_core_analysis_everything().

◆ rz_core_analysis_esil_reinit()

RZ_API void rz_core_analysis_esil_reinit ( RZ_NONNULL RzCore core)

Reinitialize ESIL.

Parameters
coreRzCore reference

Definition at line 54 of file cil.c.

54  {
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 }

References core_esil_init(), rz_analysis_esil_free(), RZ_REG_NAME_PC, rz_reg_set_value_by_role(), and rz_return_if_fail.

Referenced by do_esil_search(), rz_analysis_esil_init_handler(), rz_core_analysis_esil(), rz_core_debug_esil(), and rz_core_disasm_pde().

◆ rz_core_analysis_esil_step_over()

RZ_API void rz_core_analysis_esil_step_over ( RZ_NONNULL RzCore core)

Definition at line 269 of file cil.c.

269  {
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 }
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
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
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
Definition: dis.c:32

References NULL, rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_HINT, RZ_ANALYSIS_OP_TYPE_CALL, rz_core_analysis_op(), rz_core_esil_step(), rz_core_reg_update_flags(), rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_PC, ut64(), and UT64_MAX.

Referenced by rz_analysis_aefa(), rz_core_debug_single_step_over(), rz_core_debug_step_over(), and rz_il_step_over_handler().

◆ rz_core_analysis_esil_step_over_until()

RZ_IPI void rz_core_analysis_esil_step_over_until ( RzCore core,
ut64  addr 
)

◆ rz_core_analysis_esil_step_over_untilexpr()

RZ_IPI void rz_core_analysis_esil_step_over_untilexpr ( RzCore core,
const char *  expr 
)

Definition at line 285 of file cil.c.

285  {
286  rz_core_esil_step(core, UT64_MAX, expr, NULL, true);
288 }
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167

References expr(), NULL, rz_core_esil_step(), rz_core_reg_update_flags(), and UT64_MAX.

Referenced by rz_il_step_skip_until_expr_handler(), and rz_il_step_until_expr_handler().

◆ rz_core_analysis_il_reinit()

RZ_IPI void rz_core_analysis_il_reinit ( RzCore core)

Definition at line 434 of file cil.c.

434  {
436  if (core->analysis->il_vm) {
437  // initialize the program counter with the current offset
440  }
441 }
RZ_API bool rz_analysis_il_vm_setup(RzAnalysis *analysis)
Definition: analysis_il.c:285
RzAnalysisILVM * il_vm
user-faced VM, NEVER use this for any analysis passes!
Definition: rz_analysis.h:585

References rz_core_t::analysis, rz_analysis_t::il_vm, rz_core_t::offset, rz_analysis_t::reg, rz_analysis_il_vm_setup(), rz_core_reg_update_flags(), RZ_REG_NAME_PC, and rz_reg_set_value_by_role().

Referenced by rz_il_vm_initialize_handler().

◆ rz_core_analysis_il_step_with_events()

RZ_IPI bool rz_core_analysis_il_step_with_events ( RzCore core,
PJ pj 
)

Perform a single step at the PC given by analysis->reg in RzIL and print any events that happened

Returns
false if an error occured (e.g. invalid op)

Definition at line 655 of file cil.c.

655  {
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 }
static SblHeader sb
Definition: bin_mbn.c:26
RZ_IPI bool rz_core_il_step(RzCore *core)
Definition: cil.c:630
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
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_IL_EVENT_VAR_READ
Definition: rz_il_events.h:23
@ RZ_IL_EVENT_MEM_READ
Definition: rz_il_events.h:22
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 RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_NONNULL RzILVM * vm
low-level vm to execute IL code
Definition: rz_analysis.h:1156
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

References rz_core_t::analysis, rz_core_t::config, rz_il_vm_t::events, rz_analysis_t::il_vm, NULL, rz_config_get_b(), rz_core_il_step(), rz_il_event_json(), RZ_IL_EVENT_MEM_READ, rz_il_event_stringify(), RZ_IL_EVENT_VAR_READ, RZ_LOG_ERROR, rz_strbuf_append(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_new(), sb, rz_il_vm_event_t::type, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_step_with_events_handler().

◆ rz_core_analysis_il_vm_set()

RZ_IPI bool rz_core_analysis_il_vm_set ( RzCore core,
const char *  var_name,
ut64  value 
)

Set a vm variable from user input.

Returns
whether the set succeeded

Sets the given var, or "PC" to the given value. The type of the variable is handled dynamically. This is intended for setting from user input only.

Definition at line 451 of file cil.c.

451  {
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 }
RZ_API RzILBool * rz_il_bool_new(bool true_or_false)
Definition: bool.c:11
static int value
Definition: cmd_api.c:93
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_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_BORROW RzILVar * rz_il_vm_get_var(RZ_NONNULL RzILVM *vm, RzILVarKind kind, const char *name)
Definition: il_vm.c:251
#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_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
High-level RzIL vm to emulate disassembled code.
Definition: rz_analysis.h:1155
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
RzBitVector * pc
Program Counter of VM.
Definition: rz_il_vm.h:46
@ RZ_IL_VAR_KIND_GLOBAL
global var, usually bound to a physical representation like a register.
Definition: variable.h:47

References rz_core_t::analysis, rz_il_sort_pure_t::bv, rz_analysis_t::il_vm, bitvector_t::len, NULL, rz_il_vm_t::pc, rz_il_sort_pure_t::props, rz_bv_free(), rz_bv_new_from_ut64(), rz_il_bool_new(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, rz_il_value_new_bitv(), rz_il_value_new_bool(), RZ_IL_VAR_KIND_GLOBAL, rz_il_vm_get_var(), rz_il_vm_set_global_var(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_il_var_t::sort, rz_il_sort_pure_t::type, val, value, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_status_handler().

◆ rz_core_analysis_il_vm_status()

RZ_IPI void rz_core_analysis_il_vm_status ( RzCore core,
const char *  var_name,
RzOutputMode  mode 
)

Definition at line 531 of file cil.c.

531  {
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 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static void rzil_print_register_bitv(RzBitVector *number, ILPrint *p)
Definition: cil.c:512
static void rzil_print_register_bool(bool value, ILPrint *p)
Definition: cil.c:495
#define p_sb(x)
Definition: cil.c:491
#define p_tbl(x)
Definition: cil.c:492
#define p_pj(x)
Definition: cil.c:493
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
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
void * p
Definition: libc.cpp:67
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API PJ * pj_new(void)
Definition: pj.c:25
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 RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
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
@ 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
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
char * name
Definition: variable.h:20

References rz_core_t::analysis, free(), rz_analysis_t::il_vm, rz_il_var_t::name, NULL, out, p, p_pj, p_sb, p_tbl, rz_il_vm_t::pc, pj_drain(), pj_end(), pj_new(), pj_o(), rz_cons_printf(), RZ_IL_TYPE_PURE_BITVECTOR, RZ_IL_TYPE_PURE_BOOL, RZ_IL_VAR_KIND_GLOBAL, rz_il_vm_get_all_vars(), rz_il_vm_get_var_value(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_pvector_foreach, rz_pvector_free(), rz_strbuf_drain(), rz_strbuf_fini(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_length(), rz_strbuf_new(), rz_table_free(), rz_table_new(), rz_table_set_columnsf(), rz_table_tostring(), rz_warn_if_reached, rzil_print_register_bitv(), rzil_print_register_bool(), val, and rz_analysis_il_vm_t::vm.

Referenced by rz_il_vm_status_handler().

◆ rz_core_analysis_set_reg()

RZ_IPI int rz_core_analysis_set_reg ( RzCore core,
const char *  regname,
ut64  val 
)

Definition at line 389 of file cil.c.

389  {
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 }
#define r
Definition: crypto_rc6.c:12
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API int rz_reg_get_name_idx(const char *type)
Definition: reg.c:102
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186
static char * regname(int reg)
Definition: dis.c:71

References rz_core_t::analysis, eprintf, r, rz_analysis_t::reg, regname(), rz_core_reg_update_flags(), rz_reg_get(), rz_reg_get_name(), rz_reg_get_name_idx(), rz_reg_set_value(), and val.

Referenced by cmd_analysis_esil(), rz_analysis_aefa(), rz_analysis_esil_init_p_handler(), rz_core_analysis_esil_init_regs(), and rz_core_visual_cmd().

◆ rz_core_il_step()

RZ_IPI bool rz_core_il_step ( RzCore core)

Perform a single step at the PC given by analysis->reg in RzIL

Returns
false if an error occured (e.g. invalid op)

Definition at line 630 of file cil.c.

630  {
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 }
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
RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role)
Definition: rvalue.c:181
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

References rz_core_t::analysis, rz_analysis_t::il_vm, PFMT64x, r, rz_analysis_t::reg, RZ_ANALYSIS_IL_STEP_INVALID_OP, RZ_ANALYSIS_IL_STEP_RESULT_SUCCESS, rz_analysis_il_vm_step(), rz_core_reg_update_flags(), RZ_LOG_ERROR, rz_reg_get_value_by_role(), and RZ_REG_NAME_PC.

Referenced by rz_core_analysis_il_step_with_events(), rz_il_vm_step_handler(), and rz_il_vm_step_until_addr_handler().

◆ rzil_print_register_bitv()

static void rzil_print_register_bitv ( RzBitVector number,
ILPrint p 
)
static

Definition at line 512 of file cil.c.

512  {
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 }
static const char hex[16]
Definition: print.c:21
RZ_API RZ_OWN char * rz_bv_as_hex_string(RZ_NONNULL RzBitVector *bv, bool pad)
Definition: bitvector.c:121
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316

References free(), hex, p, p_pj, p_sb, p_tbl, pj_ks(), rz_bv_as_hex_string(), rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_strbuf_appendf(), and rz_table_add_rowf().

Referenced by rz_core_analysis_il_vm_status().

◆ rzil_print_register_bool()

static void rzil_print_register_bool ( bool  value,
ILPrint p 
)
static

Definition at line 495 of file cil.c.

495  {
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 }
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896

References p, p_pj, p_sb, p_tbl, pj_kb(), rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_str_bool(), rz_strbuf_appendf(), rz_table_add_rowf(), and value.

Referenced by rz_core_analysis_il_vm_status().