Rizin
unix-like reverse engineering framework and cli tools
core.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_core.h>
5 #include <rz_socket.h>
6 #include <rz_cmp.h>
7 #include <config.h>
8 #include <rz_util.h>
9 #if __UNIX__
10 #include <signal.h>
11 #endif
12 #include "core_private.h"
13 
14 #define DB core->sdb
15 
16 RZ_LIB_VERSION(rz_core);
17 
23 };
24 
25 extern bool rz_core_is_project(RzCore *core, const char *name);
26 
33 RZ_API void rz_core_notify_begin(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format, ...) {
34  rz_return_if_fail(core && format);
35  va_list args;
36  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
37  bool verbose = rz_config_get_b(core->config, "scr.prompt");
38  if (!verbose) {
39  return;
40  }
41  va_start(args, format);
42  if (use_color) {
43  fprintf(stderr, "[ ] " Color_YELLOW);
44  vfprintf(stderr, format, args);
45  fprintf(stderr, "\r[" Color_RESET);
46  } else {
47  fprintf(stderr, "[ ] ");
48  vfprintf(stderr, format, args);
49  fprintf(stderr, "\r[");
50  }
51  va_end(args);
52 }
53 
60 RZ_API void rz_core_notify_done(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format, ...) {
61  rz_return_if_fail(core && format);
62  va_list args;
63  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
64  bool verbose = rz_config_get_b(core->config, "scr.prompt");
65  if (!verbose) {
66  return;
67  }
68  va_start(args, format);
69  if (use_color) {
70  fprintf(stderr, "\r" Color_GREEN "[x]" Color_RESET " ");
71  vfprintf(stderr, format, args);
72  fprintf(stderr, "\n");
73  } else {
74  fprintf(stderr, "\r[x] ");
75  vfprintf(stderr, format, args);
76  fprintf(stderr, "\n");
77  }
78  va_end(args);
79 }
80 
87 RZ_API void rz_core_notify_error(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format, ...) {
88  rz_return_if_fail(core && format);
89  va_list args;
90  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
91  bool verbose = rz_config_get_b(core->config, "scr.prompt");
92  if (!verbose) {
93  return;
94  }
95  va_start(args, format);
96  if (use_color) {
97  fprintf(stderr, "\r" Color_RED "[!]" Color_RESET " ");
98  vfprintf(stderr, format, args);
99  fprintf(stderr, "\n");
100  } else {
101  fprintf(stderr, "\r[!] ");
102  vfprintf(stderr, format, args);
103  fprintf(stderr, "\n");
104  }
105  va_end(args);
106 }
107 
108 static int on_fcn_new(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn) {
109  RzCore *core = (RzCore *)_user;
110  const char *cmd = rz_config_get(core->config, "cmd.fcn.new");
111  if (cmd && *cmd) {
112  ut64 oaddr = core->offset;
113  ut64 addr = fcn->addr;
114  rz_core_seek(core, addr, true);
115  rz_core_cmd0(core, cmd);
116  rz_core_seek(core, oaddr, true);
117  }
118  return 0;
119 }
120 
121 static int on_fcn_delete(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn) {
122  RzCore *core = (RzCore *)_user;
123  const char *cmd = rz_config_get(core->config, "cmd.fcn.delete");
124  if (cmd && *cmd) {
125  ut64 oaddr = core->offset;
126  ut64 addr = fcn->addr;
127  rz_core_seek(core, addr, true);
128  rz_core_cmd0(core, cmd);
129  rz_core_seek(core, oaddr, true);
130  }
131  return 0;
132 }
133 
134 static int on_fcn_rename(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn, const char *oname) {
135  RzCore *core = (RzCore *)_user;
136  const char *cmd = rz_config_get(core->config, "cmd.fcn.rename");
137  if (cmd && *cmd) {
138  // XXX: wat do with old name here?
139  ut64 oaddr = core->offset;
140  ut64 addr = fcn->addr;
141  rz_core_seek(core, addr, true);
142  rz_core_cmd0(core, cmd);
143  rz_core_seek(core, oaddr, true);
144  }
145  return 0;
146 }
147 
149  const char *cmdbp = rz_config_get(core->config, "cmd.bp");
150  const bool cmdbp_exists = (cmdbp && *cmdbp);
151  const bool bpcmd_exists = (bpi->data && bpi->data[0]);
152  const bool may_output = (cmdbp_exists || bpcmd_exists);
153  if (may_output) {
154  rz_cons_push();
155  }
156  if (cmdbp_exists) {
157  rz_core_cmd0(core, cmdbp);
158  }
159  if (bpcmd_exists) {
160  rz_core_cmd0(core, bpi->data);
161  }
162  if (may_output) {
163  rz_cons_set_flush(true);
164  rz_cons_flush();
165  rz_cons_pop();
166  }
167 }
168 
169 static void rz_core_debug_syscall_hit(RzCore *core) {
170  const char *cmdhit = rz_config_get(core->config, "cmd.onsyscall");
171 
172  if (cmdhit && cmdhit[0] != 0) {
173  rz_core_cmd0(core, cmdhit);
174  rz_cons_flush();
175  }
176 }
177 
179  if (size < 1 || addr == UT64_MAX) {
180  return NULL;
181  }
182  RzBinFile *bf = rz_bin_cur(core->bin);
183  if (!bf || !bf->o || !bf->o->relocs) {
184  return NULL;
185  }
187 }
188 
191  RzBinFile *bf = rz_bin_cur(core->bin);
192  if (!bf || !bf->o || !bf->o->relocs) {
193  return NULL;
194  }
196 }
197 
198 /* returns the address of a jmp/call given a shortcut by the user or UT64_MAX
199  * if there's no valid shortcut. When is_asmqjmps_letter is true, the string
200  * should be of the form XYZWu, where XYZW are uppercase letters and u is a
201  * lowercase one. If is_asmqjmps_letter is false, the string should be a number
202  * between 1 and 9 included. */
204  if (!core->asmqjmps) {
205  return UT64_MAX;
206  }
207  if (core->is_asmqjmps_letter) {
208  int i, pos = 0;
209  int len = strlen(str);
210  for (i = 0; i < len - 1; i++) {
211  if (!isupper((ut8)str[i])) {
212  return UT64_MAX;
213  }
215  pos += str[i] - 'A' + 1;
216  }
217  if (!islower((ut8)str[i])) {
218  return UT64_MAX;
219  }
221  pos += str[i] - 'a';
222  if (pos < core->asmqjmps_count) {
223  return core->asmqjmps[pos + 1];
224  }
225  } else if (str[0] > '0' && str[1] <= '9') {
226  int pos = str[0] - '0';
227  if (pos <= core->asmqjmps_count) {
228  return core->asmqjmps[pos];
229  }
230  }
231  return UT64_MAX;
232 }
233 
239  bool found = false;
240  if (!core->asmqjmps) {
241  return NULL;
242  }
243  if (core->is_asmqjmps_letter) {
245  return NULL;
246  }
247  if (core->asmqjmps_count >= core->asmqjmps_size - 2) {
248  core->asmqjmps = realloc(core->asmqjmps, core->asmqjmps_size * 2 * sizeof(ut64));
249  if (!core->asmqjmps) {
250  return NULL;
251  }
252  core->asmqjmps_size *= 2;
253  }
254  }
255  if (core->asmqjmps_count < core->asmqjmps_size - 1) {
256  int i = 0;
257  char t[RZ_CORE_ASMQJMPS_LEN_LETTERS + 1] = { 0 };
258  for (i = 0; i < core->asmqjmps_count + 1; i++) {
259  if (core->asmqjmps[i] == addr) {
260  found = true;
261  break;
262  }
263  }
264  if (!found) {
265  i = ++core->asmqjmps_count;
266  core->asmqjmps[i] = addr;
267  }
268  // This check makes pos never be <1, thefor not fill 't' with trash
269  if (i < 1) {
270  return NULL;
271  }
272  rz_core_set_asmqjmps(core, t, sizeof(t), i);
273  return strdup(t);
274  }
275  return NULL;
276 }
277 
278 /* returns in str a string that represents the shortcut to access the asmqjmp
279  * at position pos. When is_asmqjmps_letter is true, pos is converted into a
280  * multiletter shortcut of the form XYWZu and returned (see rz_core_get_asmqjmps
281  * for more info). Otherwise, the shortcut is the string representation of pos. */
282 RZ_API void rz_core_set_asmqjmps(RzCore *core, char *str, size_t len, int pos) {
283  if (core->is_asmqjmps_letter) {
284  int i, j = 0;
285  // if (pos > 0) {
286  pos--;
288  for (i = 0; i < RZ_CORE_ASMQJMPS_LEN_LETTERS - 1; i++) {
289  int div = pos / letter_divs[i];
290  pos %= letter_divs[i];
291  if (div > 0 && j < len) {
292  str[j++] = 'A' + div - 1;
293  }
294  }
295  if (j < len) {
296  int div = pos % RZ_CORE_ASMQJMPS_LETTERS;
297  str[j++] = 'a' + div;
298  }
299  str[j] = '\0';
300  } else {
301  snprintf(str, len, "%d", pos);
302  }
303 }
304 
305 static void setab(RzCore *core, const char *arch, int bits) {
306  if (arch) {
307  rz_config_set(core->config, "asm.arch", arch);
308  }
309  if (bits > 0) {
310  rz_config_set_i(core->config, "asm.bits", bits);
311  }
312 }
313 
314 static const char *getName(RzCore *core, ut64 addr) {
315  RzFlagItem *item = rz_flag_get_i(core->flags, addr);
316  if (item) {
317  if (core->flags->realnames) {
318  return item->realname
319  ? item->realname
320  : item->name;
321  }
322  return item->name;
323  }
324  return NULL;
325 }
326 
327 static char *getNameDelta(RzCore *core, ut64 addr) {
328  RzFlagItem *item = rz_flag_get_at(core->flags, addr, true);
329  if (item) {
330  if (item->offset != addr) {
331  const char *name = core->flags->realnames
332  ? item->realname
333  : item->name;
334  return rz_str_newf("%s+%" PFMT64u, name, addr - item->offset);
335  }
336  return strdup(item->name);
337  }
338  return NULL;
339 }
340 
341 static void archbits(RzCore *core, ut64 addr) {
343 }
344 
345 static ut64 cfggeti(RzCore *core, const char *k) {
346  return rz_config_get_i(core->config, k);
347 }
348 
349 static const char *cfgget(RzCore *core, const char *k) {
350  return rz_config_get(core->config, k);
351 }
352 
353 static bool cfgseti(RzCore *core, const char *k, ut64 v) {
354  return rz_config_set_i(core->config, k, v);
355 }
356 
357 static bool cfgset(RzCore *core, const char *k, const char *v) {
358  return rz_config_set(core->config, k, v);
359 }
360 
361 static ut64 numget(RzCore *core, const char *k) {
362  return rz_num_math(core->num, k);
363 }
364 
365 static const RzList *__flagsGet(RzCore *core, ut64 offset) {
366  return rz_flag_get_list(core->flags, offset);
367 }
368 
370  bnd->core = core;
373  bnd->cmd = (RzCoreCmd)rz_core_cmd0;
374  bnd->cmdf = (RzCoreCmdF)rz_core_cmdf;
378  bnd->setab = (RzCoreSetArchBits)setab;
379  bnd->getName = (RzCoreGetName)getName;
383  bnd->cfgGet = (RzCoreConfigGet)cfgget;
385  bnd->cfgSet = (RzCoreConfigSet)cfgset;
386  bnd->numGet = (RzCoreNumGet)numget;
389  return true;
390 }
391 
393  return (RzCore *)(size_t)p;
394 }
395 
397  return (RzCore *)p;
398 }
399 
400 static ut64 getref(RzCore *core, int n, char t, int type) {
402  RzListIter *iter;
403  RzAnalysisXRef *r;
404  RzList *list;
405  int i = 0;
406  if (!fcn) {
407  return UT64_MAX;
408  }
409  if (t == 'r') {
411  } else {
413  }
414  rz_list_foreach (list, iter, r) {
415  if (r->type == type) {
416  if (i == n) {
417  ut64 addr = t == 'r' ? r->to : r->from;
419  return addr;
420  }
421  i++;
422  }
423  }
425 
426  return UT64_MAX;
427 }
428 
430  RzListIter *iter;
431  RzAnalysisBlock *bb;
432  rz_list_foreach (fcn->bbs, iter, bb) {
433  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
434  return bb->ninstr;
435  }
436  }
437  return UT64_MAX;
438 }
439 
441  RzListIter *iter;
442  RzAnalysisBlock *bb;
443  rz_list_foreach (fcn->bbs, iter, bb) {
444  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
445  return bb->addr;
446  }
447  }
448  return UT64_MAX;
449 }
450 
452  RzListIter *iter;
453  RzAnalysisBlock *bb;
454  rz_list_foreach (fcn->bbs, iter, bb) {
455  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
456  return bb->jump;
457  }
458  }
459  return UT64_MAX;
460 }
461 
463  RzListIter *iter;
464  RzAnalysisBlock *bb;
465  rz_list_foreach (fcn->bbs, iter, bb) {
466  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
467  return bb->fail;
468  }
469  }
470  return UT64_MAX;
471 }
472 
474  RzListIter *iter;
475  RzAnalysisBlock *bb;
476  rz_list_foreach (fcn->bbs, iter, bb) {
477  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
478  return bb->size;
479  }
480  }
481  return 0;
482 }
483 
484 static const char *str_callback(RzNum *user, ut64 off, int *ok) {
485  RzFlag *f = (RzFlag *)user;
486  if (ok) {
487  *ok = 0;
488  }
489  if (f) {
490  RzFlagItem *item = rz_flag_get_i(f, off);
491  if (item) {
492  if (ok) {
493  *ok = true;
494  }
495  return item->name;
496  }
497  }
498  return NULL;
499 }
500 
501 static ut64 num_callback(RzNum *userptr, const char *str, int *ok) {
502  RzCore *core = (RzCore *)userptr; // XXX ?
503  RzAnalysisFunction *fcn;
504  char *ptr, *bptr, *out = NULL;
505  RzFlagItem *flag;
506  RzBinSection *s;
508  ut64 ret = 0;
509 
510  if (ok) {
511  *ok = false;
512  }
513  switch (*str) {
514  case '.':
515  if (str[1] == '.') {
516  if (ok) {
517  *ok = true;
518  }
519  return rz_num_tail(core->num, core->offset, str + 2);
520  }
521  if (core->num->nc.curr_tok == '+') {
522  ut64 off = core->num->nc.number_value.n;
523  if (!off) {
524  off = core->offset;
525  }
527  if (fcn) {
528  if (ok) {
529  *ok = true;
530  }
532  if (dst == UT64_MAX) {
533  dst = fcn->addr;
534  }
535  st64 delta = dst - off;
536  if (delta < 0) {
537  core->num->nc.curr_tok = '-';
538  delta = off - dst;
539  }
540  return delta;
541  }
542  }
543  break;
544  case '[': {
545  ut64 n = 0LL;
546  int refsz = core->rasm->bits / 8;
547  const char *p = NULL;
548  if (strlen(str) > 5) {
549  p = strchr(str + 5, ':');
550  }
551  if (p) {
552  refsz = atoi(str + 1);
553  str = p;
554  }
555  // push state
556  if (str[0] && str[1]) {
557  const char *q;
558  char *o = strdup(str + 1);
559  if (o) {
560  q = rz_num_calc_index(core->num, NULL);
561  if (q) {
562  if (rz_str_replace_char(o, ']', 0) > 0) {
563  n = rz_num_math(core->num, o);
564  if (core->num->nc.errors) {
565  return 0;
566  }
567  rz_num_calc_index(core->num, q);
568  }
569  }
570  free(o);
571  }
572  } else {
573  return 0;
574  }
575  // pop state
576  if (ok) {
577  *ok = 1;
578  }
579  ut8 buf[sizeof(ut64)] = RZ_EMPTY;
580  (void)rz_io_read_at(core->io, n, buf, RZ_MIN(sizeof(buf), refsz));
581  switch (refsz) {
582  case 8:
583  return rz_read_ble64(buf, core->print->big_endian);
584  case 4:
585  return rz_read_ble32(buf, core->print->big_endian);
586  case 2:
587  return rz_read_ble16(buf, core->print->big_endian);
588  case 1:
589  return rz_read_ble8(buf);
590  default:
591  eprintf("Invalid reference size: %d (%s)\n", refsz, str);
592  return 0LL;
593  }
594  } break;
595  case '$':
596  if (ok) {
597  *ok = 1;
598  }
599  // TODO: group analop-dependant vars after a char, so i can filter
601  rz_analysis_op_fini(&op); // we don't need strings or pointers, just values, which are not nullified in fini
602  // XXX the above line is assuming op after fini keeps jump, fail, ptr, val, size and rz_analysis_op_is_eob()
603  switch (str[1]) {
604  case '.': // can use pc, sp, a0, a1, ...
605  return rz_debug_reg_get(core->dbg, str + 2);
606  case 'k': // $k{kv}
607  if (str[2] != '{') {
608  eprintf("Expected '{' after 'k'.\n");
609  break;
610  }
611  bptr = strdup(str + 3);
612  ptr = strchr(bptr, '}');
613  if (!ptr) {
614  // invalid json
615  free(bptr);
616  break;
617  }
618  *ptr = '\0';
619  ret = 0LL;
620  out = sdb_querys(core->sdb, NULL, 0, bptr);
621  if (out && *out) {
622  if (strstr(out, "$k{")) {
623  eprintf("Recursivity is not permitted here\n");
624  } else {
625  ret = rz_num_math(core->num, out);
626  }
627  }
628  free(bptr);
629  free(out);
630  return ret;
631  case '{': // ${ev} eval var
632  bptr = strdup(str + 2);
633  ptr = strchr(bptr, '}');
634  if (ptr) {
635  ptr[0] = '\0';
636  ut64 ret = rz_config_get_i(core->config, bptr);
637  free(bptr);
638  return ret;
639  }
640  // take flag here
641  free(bptr);
642  break;
643  case 'c': // $c console width
644  return rz_cons_get_size(NULL);
645  case 'r': // $r
646  if (str[2] == '{') {
647  bptr = strdup(str + 3);
648  ptr = strchr(bptr, '}');
649  if (!ptr) {
650  free(bptr);
651  break;
652  }
653  *ptr = 0;
654  return rz_core_reg_getv_by_role_or_name(core, bptr);
655  free(bptr);
656  return 0; // UT64_MAX;
657  } else {
658  int rows;
659  (void)rz_cons_get_size(&rows);
660  return rows;
661  }
662  break;
663  case 'e': // $e
664  if (str[2] == '{') { // $e{flag} flag off + size
665  char *flagName = strdup(str + 3);
666  int flagLength = strlen(flagName);
667  if (flagLength > 0) {
668  flagName[flagLength - 1] = 0;
669  }
670  RzFlagItem *flag = rz_flag_get(core->flags, flagName);
671  free(flagName);
672  if (flag) {
673  return flag->offset + flag->size;
674  }
675  return UT64_MAX;
676  }
677  return rz_analysis_op_is_eob(&op);
678  case 'j': // $j jump address
679  return op.jump;
680  case 'p': // $p
681  return rz_sys_getpid();
682  case 'P': // $P
683  return core->dbg->pid > 0 ? core->dbg->pid : 0;
684  case 'f': // $f jump fail address
685  if (str[2] == 'l') { // $fl flag length
686  RzFlagItem *fi = rz_flag_get_i(core->flags, core->offset);
687  if (fi) {
688  return fi->size;
689  }
690  return 0;
691  }
692  return op.fail;
693  case 'm': // $m memref
694  return op.ptr;
695  case 'B': // $B base address
696  case 'M': { // $M map address
697  ut64 lower = UT64_MAX;
698  ut64 size = 0LL;
699  RzIOMap *map = rz_io_map_get(core->io, core->offset);
700  if (map) {
701  lower = rz_itv_begin(map->itv);
702  size = rz_itv_size(map->itv);
703  }
704 
705  if (str[1] == 'B') {
706  /* clear lower bits of the lowest map address to define the base address */
707  const int clear_bits = 16;
708  lower >>= clear_bits;
709  lower <<= clear_bits;
710  }
711  if (str[2] == 'M') {
712  return size;
713  }
714  return (lower == UT64_MAX) ? 0LL : lower;
715  } break;
716  case 'v': // $v immediate value
717  return op.val;
718  case 'l': // $l opcode length
719  return op.size;
720  case 'b': // $b
721  return core->blocksize;
722  case 's': // $s file size
723  if (str[2] == '{') { // $s{flag} flag size
724  bptr = strdup(str + 3);
725  ptr = strchr(bptr, '}');
726  if (!ptr) {
727  // invalid json
728  free(bptr);
729  break;
730  }
731  *ptr = '\0';
732  RzFlagItem *flag = rz_flag_get(core->flags, bptr);
733  ret = flag ? flag->size : 0LL; // flag
734  free(bptr);
735  free(out);
736  return ret;
737  } else if (core->file) {
738  return rz_io_fd_size(core->io, core->file->fd);
739  }
740  return 0LL;
741  case 'w': // $w word size
742  return rz_config_get_i(core->config, "asm.bits") / 8;
743  case 'S': // $S section offset
744  {
745  RzBinObject *bo = rz_bin_cur_object(core->bin);
746  if (bo && (s = rz_bin_get_section_at(bo, core->offset, true))) {
747  return (str[2] == 'S' ? s->size : s->vaddr);
748  }
749  }
750  return 0LL;
751  case 'D': // $D
752  if (str[2] == 'B') { // $DD
753  return rz_debug_get_baddr(core->dbg, NULL);
754  } else if (IS_DIGIT(str[2])) {
755  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_DATA);
756  } else {
757  RzDebugMap *map;
758  RzListIter *iter;
759  rz_list_foreach (core->dbg->maps, iter, map) {
760  if (core->offset >= map->addr && core->offset < map->addr_end) {
761  return (str[2] == 'D') ? map->size : map->addr;
762  }
763  }
764  }
765  return 0LL; // maybe // return UT64_MAX;
766  case '?': // $?
767  return core->num->value; // rc;
768  case '$': // $$ offset
769  return str[2] == '$' ? core->prompt_offset : core->offset;
770  case 'o': { // $o
772  return s ? core->offset - s->vaddr + s->paddr : core->offset;
773  break;
774  }
775  case 'O': // $O
776  if (core->print->cur_enabled) {
777  return core->offset + core->print->cur;
778  }
779  return core->offset;
780  case 'C': // $C nth call
781  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_CALL);
782  case 'J': // $J nth jump
783  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_CODE);
784  case 'X': // $X nth xref
785  return getref(core, atoi(str + 2), 'x', RZ_ANALYSIS_XREF_TYPE_CALL);
786  case 'F': // $F function size
787  fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
788  if (fcn) {
789  switch (str[2]) {
790  /* function bounds (uppercase) */
791  case 'B': return fcn->addr; // begin
792  case 'E': return rz_analysis_function_max_addr(fcn); // end
793  case 'S': return (str[3] == 'S') ? rz_analysis_function_realsize(fcn) : rz_analysis_function_linear_size(fcn);
794  case 'I': return fcn->ninstr;
795  /* basic blocks (lowercase) */
796  case 'b': return bbBegin(fcn, core->offset);
797  case 'e': return bbBegin(fcn, core->offset) + bbSize(fcn, core->offset);
798  case 'i': return bbInstructions(fcn, core->offset);
799  case 's': return bbSize(fcn, core->offset);
800  case 'j': return bbJump(fcn, core->offset); // jump
801  case 'f': return bbFail(fcn, core->offset); // fail
802  }
803  return fcn->addr;
804  }
805  return 0;
806  }
807  break;
808  default:
809  if (*str >= 'A') {
810  // NOTE: functions override flags
812  if (fcn) {
813  if (ok) {
814  *ok = true;
815  }
816  return fcn->addr;
817  }
818 #if 0
819  ut64 addr = rz_analysis_fcn_label_get (core->analysis, core->offset, str);
820  if (addr != 0) {
821  ret = addr;
822  } else {
823  ...
824  }
825 #endif
826  if ((flag = rz_flag_get(core->flags, str))) {
827  ret = flag->offset;
828  if (ok) {
829  *ok = true;
830  }
831  return ret;
832  }
833 
834  // check for reg alias
835  RzReg *reg = rz_core_reg_default(core);
836  struct rz_reg_item_t *r = rz_reg_get(reg, str, -1);
837  if (!r) {
838  int role = rz_reg_get_name_idx(str);
839  if (role != -1) {
840  const char *alias = rz_reg_get_name(reg, role);
841  if (alias) {
842  r = rz_reg_get(reg, alias, -1);
843  if (r) {
844  if (ok) {
845  *ok = true;
846  }
847  ret = rz_reg_get_value(reg, r);
848  return ret;
849  }
850  }
851  }
852  } else {
853  if (ok) {
854  *ok = true;
855  }
856  ret = rz_reg_get_value(reg, r);
857  return ret;
858  }
859  }
860  break;
861  }
862 
863  return ret;
864 }
865 
867  RzCore *c = RZ_NEW0(RzCore);
868  if (c) {
869  rz_core_init(c);
870  }
871  return c;
872 }
873 
874 /*-----------------------------------*/
875 #define rizin_argc (sizeof(rizin_argv) / sizeof(const char *) - 1)
876 
877 static const char *rizin_argv[] = {
878  "whereis", "which", "ls", "rm", "mkdir", "pwd", "cat", "sort", "uniq", "join", "less", "exit", "quit",
879  "#?", "#!", "#sha1", "#crc32", "#pcprint", "#sha256", "#sha512", "#md4", "#md5",
880  "#!python", "#!vala", "#!pipe",
881  "*?", "*", "$",
882  "(", "(*", "(-", "()", ".?", ".", "..", "...", ".:", ".--", ".-", ".!", ".(", "./", ".*",
883  "_?", "_",
884  "R?", "R", "R<", "R!", "R+", "R-", "R=", "R!=", "R=!", "R:", "R&:",
885  "Rg?", "Rg", "Rg!", "Rh?", "Rh", "Rh-", "Rh--", "Rh*", "Rh&", "RH?", "RH", "RH&",
886  "<",
887  "/?", "/", "/j", "/j!", "/j!x", "/+", "//", "/a", "/a1", "/ab", "/ad", "/aa", "/as", "/asl", "/at", "/atl", "/af", "/afl", "/ae", "/aej", "/ai", "/aij",
888  "/c", "/ca", "/car", "/d", "/e", "/E", "/Ej", "/f", "/F", "/g", "/gg", "/h", "/ht", "/i", "/m", "/mb", "/mm",
889  "/o", "/O", "/p", "/P", "/s", "/s*", "/r?", "/r", "/ra", "/rc", "/re", "/rr", "/rw", "/rc",
890  "/R",
891  "/v?", "/v", "/v1", "/v2", "/v4", "/v8",
892  "/V?", "/V", "/V1", "/V2", "/V4", "/V8",
893  "/w", "/wi", "/x", "/z",
894  "!?", "!", "!!", "!!!", "!!!-", "!-", "!-*", "!=!",
895  "a?", "a", "aa", "aa*",
896  "aaa", "aac", "aac*", "aad", "aae", "aaf", "aai", "aaij", "aan", "aang", "aao", "aap",
897  "aar?", "aar", "aar*", "aarj", "aas", "aat", "aaT", "aau", "aav",
898  "a8", "ab",
899  "acl", "acll", "aclj", "acl*", "ac?", "ac", "ac-", "acn", "acv", "acvf", "acv-", "acb", "acb-", "acm", "acm-", "acmn",
900  "aC?", "ad", "ad4", "ad8", "adf", "adfg", "adt", "adk",
901  "ae?", "ae??", "ae", "aea", "aeA", "aeaf", "aeAf", "aeC", "aec?", "aec", "aecb", "aecs", "aecc", "aecu", "aecue",
902  "aef", "aefa",
903  "aei", "aeim", "aeip", "aek", "aek-", "aeli", "aelir", "aep?", "aep", "aep-", "aepc",
904  "aets?", "aets+", "aets-", "aes", "aesp", "aesb", "aeso", "aesou", "aess", "aesu", "aesue", "aetr", "aex",
905  "aF",
906  "ag?", "ag", "aga", "agA", "agc", "agC", "agd", "agf", "agi", "agr", "agR", "agx", "agg", "ag-",
907  "agn?", "agn", "agn-", "age?", "age", "age-",
908  "agl", "agfl",
909  "ah?", "ah", "ah.", "ah-", "ah*", "aha", "ahb", "ahc", "ahe", "ahf", "ahh", "ahi?", "ahi", "ahj", "aho",
910  "ahp", "ahr", "ahs", "ahS", "aht",
911  "ai", "aL", "an",
912  "ao?", "ao", "aoj", "aoe", "aor", "aos", "aom", "aod", "aoda", "aoc", "ao*",
913  "aO", "ap",
914  "ar?", "ar", "ar0", "ara?", "ara", "ara+", "ara-", "aras", "arA", "arC", "arr", "arrj", "ar=",
915  "arb", "arc", "ard", "arn", "aro", "arp?", "arp", "arpi", "arpg", "arp.", "arpj",
916  "ars", "art", "arw",
917  "as?", "as", "asc", "asca", "asf", "asj", "asl", "ask",
918  "av?", "av", "avj", "av*", "avr", "avra", "avraj", "avrr", "avrD",
919  "at",
920  "b?", "b", "b+", "b-", "bf", "bm",
921  "c?", "c", "c1", "c2", "c4", "c8", "cc", "ccd", "cf", "cg?", "cg", "cgf", "cgff", "cgfc", "cgfn", "cgo",
922  "cu?", "cu", "cu1", "cu2", "cu4", "cu8", "cud",
923  "cv", "cv1", "cv2", "cv4", "cv8",
924  "cV", "cV1", "cV2", "cV4", "cV8",
925  "cw?", "cw", "cw*", "cwr", "cwu",
926  "cx", "cx*", "cX",
927  "cl", "cls", "clear",
928  "d?", "db ", "db-", "db-*", "db.", "dbj", "dbc", "dbC", "dbd", "dbe", "dbs", "dbf", "dbm", "dbn",
929  "db?", "dbi", "dbi.", "dbix", "dbic", "dbie", "dbid", "dbis", "dbite", "dbitd", "dbits", "dbh", "dbh-",
930  "dbt", "dbt*", "dbt=", "dbtv", "dbtj", "dbta", "dbte", "dbtd", "dbts", "dbx", "dbw",
931  "dc?", "dc", "dca", "dcb", "dcc", "dccu", "dcf", "dck", "dcp", "dcr", "dcs", "dcs*", "dct", "dcu", "dcu.",
932  "dd?", "dd", "dd-", "dd*", "dds", "ddd", "ddr", "ddw",
933  "de",
934  "dg",
935  "dH",
936  "di?", "di", "di*", "diq", "dij",
937  "dk?", "dk", "dko", "dkj",
938  "dL?", "dL", "dLq", "dLj",
939  "dm?", "dm", "dm=", "dm.", "dm*", "dm-", "dmd",
940  "dmh?", "dmh", "dmha", "dmhb", "dmhbg", "dmhc", "dmhf", "dmhg", "dmhi", "dmhm", "dmht",
941  "dmi?", "dmi", "dmi*", "dmi.", "dmiv",
942  "dmj",
943  "dml?", "dml",
944  "dmm?", "dmm", "dmm*", "dmm.", "dmmj",
945  "dmp?", "dmp",
946  "dms?", "dms", "dmsj", "dms*", "dms-", "dmsA", "dmsC", "dmsd", "dmsw", "dmsa", "dmsf", "dmst",
947  "dmS", "dmS*",
948  "do?", "do", "dor", "doo",
949  "dp?", "dp", "dpj", "dpl", "dplj", "dp-", "dp=", "dpa", "dpc", "dpc*", "dpe", "dpf", "dpk", "dpn", "dptn", "dpt",
950  "dr?", "dr", "drpj", "drr", "drrj", "drs", "drs+", "drs-", "drt", "drt*", "drtj", "drw", "drx", "drx-",
951  ".dr*", ".dr-",
952  "ds?", "ds", "dsb", "dsf", "dsi", "dsl", "dso", "dsp", "dss", "dsu", "dsui", "dsuo", "dsue", "dsuf",
953  "dt?", "dt", "dt%", "dt*", "dt+", "dt-", "dt=", "dtD", "dta", "dtc", "dtd", "dte", "dte-*", "dtei", "dtek",
954  "dtg", "dtg*", "dtgi",
955  "dtr",
956  "dts?", "dts", "dts+", "dts-", "dtsf", "dtst", "dtsC", "dtt",
957  "dw",
958  "dx?", "dx", "dxa", "dxe", "dxr", "dxs",
959  "e?", "e", "e-", "e*", "e!", "ec", "ee?", "ee", "?ed", "ed", "ej", "env", "er", "es"
960  "et",
961  "ev", "evj",
962  "ec?", "ec", "ec*", "ecd", "ecr", "ecs", "ecj", "ecc", "eco", "ecp", "ecn",
963  "ecH?", "ecH", "ecHi", "ecHw", "ecH-",
964  "f?", "f", "f.", "f*", "f-", "f--", "f+", "f=", "fa", "fb", "fc?", "fc", "fC", "fe-", "fe",
965  "ff", "fi", "fg", "fj",
966  "fl", "fla", "fm", "fn", "fnj", "fo", "fO", "fr", "fR", "fR?",
967  "fV", "fx", "fq",
968  "g?", "g", "gw", "gc", "gl?", "gl", "gs", "gi", "gp", "ge", "gr", "gS",
969  "i?", "i", "ij", "iA", "ia", "ib", "ic", "icc", "iC",
970  "id?", "id", "idp", "idpi", "idpi*", "idpd", "iD", "ie", "iee", "iE", "iE.",
971  "ih", "iHH", "ii", "iI", "ik", "il", "iL", "im", "iM", "io", "iO?", "iO",
972  "ir", "iR", "is", "is.", "iS", "iS.", "iS=", "iSS",
973  "it", "iV", "iX", "iz", "izj", "izz", "izzz", "iz-", "iZ",
974  "k?", "k", "ko", "kd", "ks", "kj",
975  "l",
976  "L?", "L", "L-", "Ll", "LL", "La", "Lc", "Ld", "Lh", "Li", "Lo",
977  "o?", "o", "o-", "o--", "o+", "oa", "oa-", "oq", "o*", "o.", "o=",
978  "ob?", "ob", "ob*", "obo", "oba", "obf", "obj", "obr", "ob-", "ob-*",
979  "oc", "of", "oi", "oj", "oL", "om", "on",
980  "oo?", "oo", "oo+", "oob", "ood", "oom", "oon", "oon+", "oonn", "oonn+",
981  "op", "opn", "opp", "opr", "ox",
982  "p?", "p-", "p=", "p2", "p3", "p6?", "p6", "p6d", "p6e", "p8?", "p8", "p8f", "p8j",
983  "pa?", "paD", "pad", "pade", "pae", "pA",
984  "pb?", "pb", "pB", "pxb", "pB?",
985  "pc?", "pc", "pc*", "pca", "pcA", "pcd", "pch", "pcj", "pcp", "pcs", "pcS", "pcw",
986  "pC?", "pC", "pCa", "pCA", "pCc", "pCd", "pCD", "pCx", "pCw",
987  "pd?", "pd", "pd--", "pD", "pda", "pdb", "pdC", "pdf", "pdi", "pdj", "pdJ",
988  "pdk", "pdl", "pdp", "pdr", "pdr.", "pdR", "pds?", "pds", "pdsb", "pdsf", "pdt",
989  "pD",
990  "pf?", "pf", "pf??", "pf???", "pf.", "pfj", "pfj.", "pf*", "pf*.", "pfd", "pfd.",
991  "pfo", "pfq", "pfv", "pfv.", "pfs", "pfs.",
992  "pF?", "pF", "pFa", "pFaq", "pFo", "pFp", "pFx",
993  "pg?", "pg", "pg*", "pg-*",
994  "ph?", "ph", "ph=",
995  "pi?", "pi", "pia", "pib", "pie", "pif?", "pif", "pifc", "pifcj", "pifj", "pir",
996  "pI?", "pI", "pIa", "pIb", "pIe", "pIf?", "pIf", "pIfc", "pIfcj", "pIfj", "pIr",
997  "pj?", "pj", "pj.", "pj..",
998  "pk?", "pk", "pK?", "pK",
999  "pm?", "pm",
1000  "pr?", "pr", "prc", "prx", "prg?", "prg", "prgi", "prgo", "prz",
1001  "ps?", "ps", "psb", "psi", "psj", "psp", "pss", "psu", "psw", "psW", "psx", "psz", "ps+",
1002  "pt?", "pt", "pt.", "ptd", "pth", "ptn",
1003  "pu?", "pu", "puw", "pU",
1004  "pv?", "pv", "pv1", "pv2", "pv4", "pv8", "pvz", "pvj", "pvh", "pv1j", "pv2j", "pv4j", "pv8j",
1005  "pv1h", "pv2h", "pv4h", "pv8h",
1006  "px?", "px", "px/", "px0", "pxa", "pxA?", "pxA", "pxb", "pxc", "pxd?", "pxd", "pxd2", "pxd4", "pxd8",
1007  "pxe", "pxf", "pxh", "pxH", "pxi", "pxl", "pxo", "pxq", "pxq", "pxQ", "pxQq", "pxr", "pxrj",
1008  "pxs", "pxt", "pxt*", "pxt.", "pxw", "pxW", "pxWq", "pxx", "pxX",
1009  "pz?", "pz", "pzp", "pzf", "pzs", "pz0", "pzF", "pze", "pzh",
1010  "P?", "P", "Pc", "Pd", "Pi", "Pn", "Pnj", "Po", "Ps", "PS", "P-",
1011  "q?", "q", "q!", "q!!", "q!!!", "qy", "qn", "qyy", "qyn", "qny", "qnn",
1012  "r?", "r", "r-", "r+", "rh",
1013  "s?", "s", "s:", "s-", "s-*", "s--", "s+", "s++", "sj", "s*", "s=", "s!", "s/", "s/x", "s.", "sa", "sb",
1014  "sC?", "sC", "sC*",
1015  "sf", "sf.", "sg", "sG", "sl?", "sn", "sp", "so", "sr", "ss",
1016  "t?", "t", "tj", "t*", "t-", "t-*", "ta", "tb", "tc", "te?", "te", "tej", "teb", "tec",
1017  "td?", "td", "td-", "tf", "tk", "tl", "tn", "to", "tos", "tp", "tpx", "ts?", "ts", "tsj", "ts*", "tsc", "tss",
1018  "tu?", "tu", "tuj", "tu*", "tuc", "tt?", "tt", "ttj", "ttc",
1019  "T?", "T", "T*", "T-", "Tl", "Tj", "Tm", "Ts", "TT", "T=", "T=.", "T=&",
1020  "u?", "u", "uw", "us", "uc",
1021  "v", "V", "v!", "vv", "vV", "vVV", "VV",
1022  "w?", "w", "w1+", "w1-", "w2+", "w2-", "w4+", "w4-", "w8+", "w8-",
1023  "w0", "w", "w6", "w6d", "w6e", "wa", "wa*", "waf", "wao?", "wao",
1024  "wA?", "wA", "wB", "wB-", "wc", "wcj", "wc-", "wc+", "wc*", "wcr", "wci", "wcp", "wcp*", "wcpi",
1025  "wd", "we?", "we", "wen", "weN", "wes", "wex", "weX",
1026  "wf?", "wf", "wff", "wfs", "wF", "wh", "wm",
1027  "wo?", "wo", "wo2", "wo4", "woa", "woA", "wod", "woD", "woe", "woE", "wol", "wom", "woo",
1028  "wop?", "wop", "wopD", "wopD*", "wopO",
1029  "wp?", "wp", "wr", "ws",
1030  "wt?", "wt", "wta", "wtf", "wtf!", "wtff", "wts",
1031  "wu",
1032  "wv?", "wv", "wv1", "wv2", "wv4", "wv8",
1033  "ww",
1034  "wx?", "wx", "wxf", "wxs",
1035  "wz",
1036  "x?", "x", "x/", "x0", "xa", "xA?", "xA", "xb", "xc", "xd?", "xd", "xd2", "xd4", "xd8",
1037  "xe", "xf", "xh", "xH", "xi", "xl", "xo", "xq", "xq", "xQ", "xQq", "xr", "xrj",
1038  "xs", "xt", "xt*", "xt.", "xw", "xW", "xWq", "xx", "xX",
1039  "y?", "y", "yz", "yp", "yx", "ys", "yt", "ytf", "yf", "yfa", "yfx", "yw", "ywx", "yy",
1040  "z?", "z", "z*", "zj", "z-", "z-*",
1041  "za?", "za??", "za", "zaf", "zaF", "zg",
1042  "zo?", "zo", "zoz", "zos",
1043  "zf?", "zfd", "zfs", "zfz",
1044  "z/?", "z/", "z/*",
1045  "zc",
1046  "zs?", "zs", "zs-", "zs-*", "zs+", "zsr",
1047  "zi",
1048  "?", "?v", "?$?", "?@?", "?>?",
1049  NULL
1050 };
1051 
1052 static void autocomplete_process_path(RzLineCompletion *completion, const char *str, const char *path) {
1053  char *lpath = NULL, *dirname = NULL, *basename = NULL;
1054  char *home = NULL, *filename = NULL, *p = NULL;
1055  int n = 0;
1056  RzList *list;
1057  RzListIter *iter;
1058 
1059  if (!path) {
1060  goto out;
1061  }
1062 
1063  lpath = rz_str_new(path);
1064 #if __WINDOWS__
1065  rz_str_replace_ch(lpath, '/', '\\', true);
1066 #endif
1067  p = (char *)rz_str_last(lpath, RZ_SYS_DIR);
1068  if (p) {
1069  *p = 0;
1070  if (p == lpath) { // /xxx
1071 #if __WINDOWS__
1072  dirname = strdup("\\.\\");
1073 #else
1074  dirname = rz_str_new(RZ_SYS_DIR);
1075 #endif
1076  } else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy
1077  dirname = rz_str_home(lpath + 2);
1078  } else if (lpath[0] == '~') { // ~/xxx
1079  if (!(home = rz_str_home(NULL))) {
1080  goto out;
1081  }
1082  dirname = rz_str_newf("%s%s", home, RZ_SYS_DIR);
1083  free(home);
1084  } else if (lpath[0] == '.' || lpath[0] == RZ_SYS_DIR[0]) { // ./xxx/yyy || /xxx/yyy
1085  dirname = rz_str_newf("%s%s", lpath, RZ_SYS_DIR);
1086  } else { // xxx/yyy
1087  char *fmt = ".%s%s%s";
1088 #if __WINDOWS__
1089  if (strchr(path, ':')) {
1090  fmt = "%.0s%s%s";
1091  }
1092 #endif
1093  dirname = rz_str_newf(fmt, RZ_SYS_DIR, lpath, RZ_SYS_DIR);
1094  }
1095  basename = rz_str_new(p + 1);
1096  } else { // xxx
1097  dirname = rz_str_newf(".%s", RZ_SYS_DIR);
1098  basename = rz_str_new(lpath);
1099  }
1100 
1101  if (!dirname || !basename) {
1102  goto out;
1103  }
1104 
1105  list = rz_sys_dir(dirname);
1106  n = strlen(basename);
1107  bool chgdir = !strncmp(str, "cd ", 3);
1108  if (list) {
1109  rz_list_foreach (list, iter, filename) {
1110  if (*filename == '.') {
1111  continue;
1112  }
1113  if (!basename[0] || !strncmp(filename, basename, n)) {
1114  char *tmpstring = rz_str_newf("%s%s", dirname, filename);
1115  if (rz_file_is_directory(tmpstring)) {
1116  char *s = rz_str_newf("%s%s", tmpstring, RZ_SYS_DIR);
1117  rz_line_completion_push(completion, s);
1118  free(s);
1119  } else if (!chgdir) {
1120  rz_line_completion_push(completion, tmpstring);
1121  }
1122  free(tmpstring);
1123  }
1124  }
1125  rz_list_free(list);
1126  }
1127 out:
1128  free(lpath);
1129  free(dirname);
1130  free(basename);
1131 }
1132 
1133 static void autocompleteFilename(RzLineCompletion *completion, RzLineBuffer *buf, char **extra_paths, int narg) {
1134  char *args = NULL, *input = NULL;
1135  int n = 0, i = 0;
1136  char *pipe = strchr(buf->data, '>');
1137  if (pipe) {
1138  args = rz_str_new(pipe + 1);
1139  } else {
1140  args = rz_str_new(buf->data);
1141  }
1142  if (!args) {
1143  goto out;
1144  }
1145 
1146  n = rz_str_word_set0(args);
1147  if (n < narg) {
1148  goto out;
1149  }
1150 
1152  if (!input) {
1153  goto out;
1154  }
1155  const char *tinput = rz_str_trim_head_ro(input);
1156 
1157  autocomplete_process_path(completion, buf->data, tinput);
1158 
1159  if (input[0] == '/' || input[0] == '.' || !extra_paths) {
1160  goto out;
1161  }
1162 
1163  for (i = 0; extra_paths[i]; i++) {
1164  char *s = rz_str_newf("%s%s%s", extra_paths[i], RZ_SYS_DIR, tinput);
1165  if (!s) {
1166  break;
1167  }
1168  autocomplete_process_path(completion, buf->data, s);
1169  free(s);
1170  }
1171 out:
1172  free(args);
1173  free(input);
1174 }
1175 
1176 #define ADDARG(x) \
1177  if (!strncmp(buf->data + chr, x, strlen(buf->data + chr))) { \
1178  rz_line_completion_push(completion, x); \
1179  }
1180 
1182  RzCoreAutocomplete *a = core ? core->autocomplete : NULL;
1183  int i;
1184  if (a) {
1185  for (i = 0; i < a->n_subcmds; i++) {
1186  if (buf->data[0] == 0 || !strncmp(a->subcmds[i]->cmd, buf->data, a->subcmds[i]->length)) {
1187  rz_line_completion_push(completion, a->subcmds[i]->cmd);
1188  }
1189  }
1190  } else {
1191  for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
1192  int length = strlen(rizin_argv[i]);
1193  if (!strncmp(rizin_argv[i], buf->data, length)) {
1194  rz_line_completion_push(completion, rizin_argv[i]);
1195  }
1196  }
1197  }
1198 }
1199 
1200 static void autocomplete_evals(RzCore *core, RzLineCompletion *completion, const char *str) {
1202  RzConfigNode *bt;
1203  RzListIter *iter;
1204  const char *tmp = strrchr(str, ' ');
1205  if (tmp) {
1206  str = tmp + 1;
1207  }
1208  size_t n = strlen(str);
1209  rz_list_foreach (core->config->nodes, iter, bt) {
1210  if (!strncmp(bt->name, str, n)) {
1211  rz_line_completion_push(completion, bt->name);
1212  }
1213  }
1214 }
1215 
1216 static void autocomplete_minus(RzCore *core, RzLineCompletion *completion, const char *str) {
1218  int count;
1219  int length = strlen(str);
1220  char **keys = rz_cmd_alias_keys(core->rcmd, &count);
1221  if (!keys) {
1222  return;
1223  }
1224  int i;
1225  for (i = 0; i < count; i++) {
1226  if (!strncmp(keys[i], str, length)) {
1227  rz_line_completion_push(completion, keys[i]);
1228  }
1229  }
1230 }
1231 
1232 static void autocomplete_breakpoints(RzCore *core, RzLineCompletion *completion, const char *str) {
1234  RzListIter *iter;
1235  RzBreakpoint *bp = core->dbg->bp;
1237  int n = strlen(str);
1238  rz_list_foreach (bp->bps, iter, b) {
1239  char *addr = rz_str_newf("0x%" PFMT64x "", b->addr);
1240  if (!strncmp(addr, str, n)) {
1241  rz_line_completion_push(completion, addr);
1242  }
1243  free(addr);
1244  }
1245 }
1246 
1247 static bool add_argv(RzFlagItem *fi, void *user) {
1248  RzLineCompletion *completion = user;
1249  rz_line_completion_push(completion, fi->name);
1250  return true;
1251 }
1252 
1253 static void autocomplete_flags(RzCore *core, RzLineCompletion *completion, const char *str) {
1255  int n = strlen(str);
1256  rz_flag_foreach_prefix(core->flags, str, n, add_argv, completion);
1257 }
1258 
1259 // TODO: Should be refactored
1260 static void autocomplete_sdb(RzCore *core, RzLineCompletion *completion, const char *str) {
1261  rz_return_if_fail(core && completion && str);
1262  char *pipe = strchr(str, '>');
1263  Sdb *sdb = core->sdb;
1264  char *lpath = NULL, *p1 = NULL, *out = NULL, *p2 = NULL;
1265  char *cur_pos = NULL, *cur_cmd = NULL, *next_cmd = NULL;
1266  char *temp_cmd = NULL, *temp_pos = NULL, *key = NULL;
1267  if (pipe) {
1268  str = rz_str_trim_head_ro(pipe + 1);
1269  }
1270  lpath = rz_str_new(str);
1271  p1 = strchr(lpath, '/');
1272  if (p1) {
1273  *p1 = 0;
1274  char *ns = p1 + 1;
1275  p2 = strchr(ns, '/');
1276  if (!p2) { // analysis/m
1277  char *tmp = p1 + 1;
1278  int n = strlen(tmp);
1279  out = sdb_querys(sdb, NULL, 0, "analysis/**");
1280  if (!out) {
1281  return;
1282  }
1283  while (*out) {
1284  cur_pos = strchr(out, '\n');
1285  if (!cur_pos) {
1286  break;
1287  }
1288  cur_cmd = rz_str_ndup(out, cur_pos - out);
1289  if (!strncmp(tmp, cur_cmd, n)) {
1290  char *cmplt = rz_str_newf("analysis/%s/", cur_cmd);
1291  rz_line_completion_push(completion, cmplt);
1292  free(cmplt);
1293  }
1294  out += cur_pos - out + 1;
1295  }
1296 
1297  } else { // analysis/meta/*
1298  char *tmp = p2 + 1;
1299  int n = strlen(tmp);
1300  char *spltr = strchr(ns, '/');
1301  *spltr = 0;
1302  next_cmd = rz_str_newf("analysis/%s/*", ns);
1303  out = sdb_querys(sdb, NULL, 0, next_cmd);
1304  if (!out) {
1305  free(lpath);
1306  return;
1307  }
1308  while (*out) {
1309  temp_pos = strchr(out, '\n');
1310  if (!temp_pos) {
1311  break;
1312  }
1313  temp_cmd = rz_str_ndup(out, temp_pos - out); // contains the key=value pair
1314  key = strchr(temp_cmd, '=');
1315  *key = 0;
1316  if (!strncmp(tmp, temp_cmd, n)) {
1317  char *cmplt = rz_str_newf("analysis/%s/%s", ns, temp_cmd);
1318  rz_line_completion_push(completion, cmplt);
1319  free(cmplt);
1320  }
1321  out += temp_pos - out + 1;
1322  }
1323  }
1324  } else {
1325  int n = strlen(lpath);
1326  if (!strncmp(lpath, "analysis", n)) {
1327  rz_line_completion_push(completion, "analysis/");
1328  }
1329  }
1330 }
1331 
1332 static void autocomplete_flagspaces(RzCore *core, RzLineCompletion *completion, const char *msg) {
1334  int length = strlen(msg);
1335  RzFlag *flag = core->flags;
1336  RzSpaceIter it;
1337  RzSpace *s;
1338  rz_flag_space_foreach(flag, it, s) {
1339  if (!strncmp(msg, s->name, length)) {
1340  rz_line_completion_push(completion, s->name);
1341  }
1342  }
1343 
1344  if (strlen(msg) == 0) {
1345  rz_line_completion_push(completion, "*");
1346  }
1347 }
1348 
1349 static void autocomplete_functions(RzCore *core, RzLineCompletion *completion, const char *str) {
1351  RzListIter *iter;
1352  RzAnalysisFunction *fcn;
1353  int n = strlen(str);
1354  rz_list_foreach (core->analysis->fcns, iter, fcn) {
1355  char *name = rz_core_analysis_fcn_name(core, fcn);
1356  if (!strncmp(name, str, n)) {
1357  rz_line_completion_push(completion, name);
1358  }
1359  free(name);
1360  }
1361 }
1362 
1363 static void autocomplete_macro(RzCore *core, RzLineCompletion *completion, const char *str) {
1364  rz_return_if_fail(core && core->rcmd && completion && str);
1365  RzCmdMacroItem *item;
1366  RzListIter *iter;
1367  size_t n = strlen(str);
1368  rz_list_foreach (core->rcmd->macro.macros, iter, item) {
1369  char *p = item->name;
1370  if (!*str || !strncmp(str, p, n)) {
1371  char *buf = rz_str_newf("%s%s)", str, p);
1372  if (buf) {
1373  rz_line_completion_push(completion, buf);
1374  free(buf);
1375  }
1376  }
1377  }
1378 }
1379 
1380 static void autocomplete_file(RzLineCompletion *completion, const char *str) {
1382  char *pipe = strchr(str, '>');
1383 
1384  if (pipe) {
1385  str = rz_str_trim_head_ro(pipe + 1);
1386  }
1387  if (str && !*str) {
1388  autocomplete_process_path(completion, str, "./");
1389  } else {
1390  autocomplete_process_path(completion, str, str);
1391  }
1392 }
1393 
1394 static void autocomplete_theme(RzCore *core, RzLineCompletion *completion, const char *str) {
1396  int len = strlen(str);
1397  char *theme;
1398  RzListIter *iter;
1399  RzList *themes = rz_core_theme_list(core);
1400  rz_list_foreach (themes, iter, theme) {
1401  if (!len || !strncmp(str, theme, len)) {
1402  rz_line_completion_push(completion, theme);
1403  }
1404  }
1405  rz_list_free(themes);
1406 }
1407 
1408 static bool find_e_opts(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf) {
1409  const char *pattern = "e (.*)=";
1410  RzRegex *rx = rz_regex_new(pattern, "e");
1411  const size_t nmatch = 2;
1412  RzRegexMatch pmatch[2] = { 0 };
1413  bool ret = false;
1414 
1415  if (rz_regex_exec(rx, buf->data, nmatch, pmatch, 1)) {
1416  goto out;
1417  }
1418  int i;
1419  char *str = NULL, *sp;
1420  for (i = pmatch[1].rm_so; i < pmatch[1].rm_eo; i++) {
1421  str = rz_str_appendch(str, buf->data[i]);
1422  }
1423  if (!str) {
1424  goto out;
1425  }
1426  if ((sp = strchr(str, ' '))) {
1427  // if the name contains a space, just null
1428  *sp = 0;
1429  }
1430  RzConfigNode *node = rz_config_node_get(core->config, str);
1431  if (sp) {
1432  // if nulled, then restore.
1433  *sp = ' ';
1434  }
1435  if (!node) {
1436  return false;
1437  }
1438  RzListIter *iter;
1439  char *option;
1440  char *p = (char *)strchr(buf->data, '=');
1441  p = rz_str_ichr(p + 1, ' ');
1442  int n = strlen(p);
1443  rz_list_foreach (node->options, iter, option) {
1444  if (!strncmp(option, p, n)) {
1445  rz_line_completion_push(completion, option);
1446  }
1447  }
1448  completion->opt = true;
1449  ret = true;
1450 
1451 out:
1452  rz_regex_free(rx);
1453  return ret;
1454 }
1455 
1456 static bool find_autocomplete(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf) {
1457  RzCoreAutocomplete *child = NULL;
1458  RzCoreAutocomplete *parent = core->autocomplete;
1459  const char *p = buf->data;
1460  if (!*p) {
1461  return false;
1462  }
1463  char arg[256];
1464  arg[0] = 0;
1465  while (*p) {
1466  const char *e = rz_str_trim_head_wp(p);
1467  if (!e || (e - p) >= 256 || e == p) {
1468  return false;
1469  }
1470  memcpy(arg, p, e - p);
1471  arg[e - p] = 0;
1472  child = rz_core_autocomplete_find(parent, arg, false);
1473  if (child && child->length < buf->length && p[child->length] == ' ') {
1474  // if is spaced then i can provide the
1475  // next subtree as suggestion..
1476  p = rz_str_trim_head_ro(p + child->length);
1477  if (child->type == RZ_CORE_AUTOCMPLT_OPTN) {
1478  continue;
1479  }
1480  parent = child;
1481  } else {
1482  break;
1483  }
1484  }
1485  int i;
1486  /* if something went wrong this will prevent bad behavior */
1487  rz_line_completion_clear(completion);
1488  switch (parent->type) {
1490  autocomplete_functions(core, completion, p);
1491  // fallthrough
1493  autocomplete_flags(core, completion, p);
1494  break;
1496  autocomplete_flagspaces(core, completion, p);
1497  break;
1498  case RZ_CORE_AUTOCMPLT_FCN:
1499  autocomplete_functions(core, completion, p);
1500  break;
1502  autocomplete_evals(core, completion, p);
1503  break;
1505  autocomplete_minus(core, completion, p);
1506  break;
1508  autocomplete_breakpoints(core, completion, p);
1509  break;
1511  autocomplete_macro(core, completion, p);
1512  break;
1514  autocomplete_file(completion, p);
1515  break;
1517  autocomplete_theme(core, completion, p);
1518  break;
1519  case RZ_CORE_AUTOCMPLT_SDB:
1520  autocomplete_sdb(core, completion, p);
1521  break;
1523  // handled before
1524  break;
1525  default:
1526  if (rz_config_get_i(core->config, "cfg.newtab")) {
1528  for (i = 0; arg[i] && desc; i++) {
1529  ut8 c = arg[i];
1530  desc = c < RZ_ARRAY_SIZE(desc->sub) ? desc->sub[c] : NULL;
1531  }
1532  if (desc && desc->help_msg) {
1533  rz_core_cmd_help(core, desc->help_msg);
1534  rz_cons_flush();
1535  return true;
1536  }
1537  // fallback to command listing
1538  }
1539  int length = strlen(arg);
1540  for (i = 0; i < parent->n_subcmds; i++) {
1541  if (!strncmp(arg, parent->subcmds[i]->cmd, length)) {
1542  rz_line_completion_push(completion, parent->subcmds[i]->cmd);
1543  }
1544  }
1545  break;
1546  }
1547  return true;
1548 }
1549 
1551  if (!core) {
1552  autocomplete_default(core, completion, buf);
1553  return;
1554  }
1555  rz_line_completion_clear(completion);
1556  char *pipe = strchr(buf->data, '>');
1557  char *ptr = strchr(buf->data, '@');
1558  if (pipe && strchr(pipe + 1, ' ') && buf->data + buf->index >= pipe) {
1559  autocompleteFilename(completion, buf, NULL, 1);
1560  } else if (ptr && strchr(ptr + 1, ' ') && buf->data + buf->index >= ptr) {
1561  int sdelta, n;
1562  ptr = (char *)rz_str_trim_head_ro(ptr + 1);
1563  n = strlen(ptr); //(buf->data+sdelta);
1564  sdelta = (int)(size_t)(ptr - buf->data);
1565  rz_flag_foreach_prefix(core->flags, buf->data + sdelta, n, add_argv, completion);
1566  } else if (!strncmp(buf->data, "#!pipe ", 7)) {
1567  if (strchr(buf->data + 7, ' ')) {
1568  autocompleteFilename(completion, buf, NULL, 2);
1569  } else {
1570  int chr = 7;
1571  ADDARG("node");
1572  ADDARG("vala");
1573  ADDARG("ruby");
1574  ADDARG("newlisp");
1575  ADDARG("perl");
1576  ADDARG("python");
1577  }
1578  } else if (!strncmp(buf->data, "ec ", 3)) {
1579  if (strchr(buf->data + 3, ' ')) {
1580  autocompleteFilename(completion, buf, NULL, 2);
1581  } else {
1582  int chr = 3;
1583  ADDARG("comment")
1584  ADDARG("usrcmt")
1585  ADDARG("args")
1586  ADDARG("fname")
1587  ADDARG("floc")
1588  ADDARG("fline")
1589  ADDARG("flag")
1590  ADDARG("label")
1591  ADDARG("help")
1592  ADDARG("flow")
1593  ADDARG("prompt")
1594  ADDARG("offset")
1595  ADDARG("input")
1596  ADDARG("invalid")
1597  ADDARG("other")
1598  ADDARG("b0x00")
1599  ADDARG("b0x7f")
1600  ADDARG("b0xff")
1601  ADDARG("math")
1602  ADDARG("bin")
1603  ADDARG("btext")
1604  ADDARG("push")
1605  ADDARG("pop")
1606  ADDARG("crypto")
1607  ADDARG("jmp")
1608  ADDARG("cjmp")
1609  ADDARG("call")
1610  ADDARG("nop")
1611  ADDARG("ret")
1612  ADDARG("trap")
1613  ADDARG("swi")
1614  ADDARG("cmp")
1615  ADDARG("reg")
1616  ADDARG("creg")
1617  ADDARG("num")
1618  ADDARG("mov")
1619  ADDARG("func_var")
1620  ADDARG("func_var_type")
1621  ADDARG("func_var_addr")
1622  ADDARG("widget_bg")
1623  ADDARG("widget_sel")
1624  ADDARG("ai.read")
1625  ADDARG("ai.write")
1626  ADDARG("ai.exec")
1627  ADDARG("ai.seq")
1628  ADDARG("ai.ascii")
1629  ADDARG("ai.unmap")
1630  ADDARG("graph.box")
1631  ADDARG("graph.box2")
1632  ADDARG("graph.box3")
1633  ADDARG("graph.box4")
1634  ADDARG("graph.true")
1635  ADDARG("graph.false")
1636  ADDARG("graph.ujump")
1637  ADDARG("graph.current")
1638  ADDARG("graph.traced")
1639  ADDARG("gui.cflow")
1640  ADDARG("gui.dataoffset")
1641  ADDARG("gui.background")
1642  ADDARG("gui.alt_background")
1643  ADDARG("gui.border")
1644  }
1645  } else if ((!strncmp(buf->data, "afvn ", 5)) || (!strncmp(buf->data, "afan ", 5))) {
1646  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
1647  RzList *vars;
1648  if (!strncmp(buf->data, "afvn ", 5)) {
1649  vars = rz_analysis_var_list(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV);
1650  } else {
1651  vars = rz_list_new(); // TODO rz_analysis_var_list (core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_ARG);
1652  }
1653  const char *f_ptr, *l_ptr;
1654  RzAnalysisVar *var;
1655  int len = strlen(buf->data);
1656 
1657  f_ptr = rz_sub_str_lchr(buf->data, 0, buf->index, ' ');
1658  f_ptr = f_ptr != NULL ? f_ptr + 1 : buf->data;
1659  l_ptr = rz_sub_str_rchr(buf->data, buf->index, len, ' ');
1660  if (!l_ptr) {
1661  l_ptr = buf->data + len;
1662  }
1663  RzListIter *iter;
1664  rz_list_foreach (vars, iter, var) {
1665  if (!strncmp(f_ptr, var->name, l_ptr - f_ptr)) {
1666  rz_line_completion_push(completion, var->name);
1667  }
1668  }
1669  rz_list_free(vars);
1670  } else if (!strncmp(buf->data, "$", 1)) {
1671  int i;
1672  for (i = 0; i < core->rcmd->aliases.count; i++) {
1673  const char *key = core->rcmd->aliases.keys[i];
1674  int len = strlen(buf->data);
1675  if (!len || !strncmp(buf->data, key, len)) {
1676  rz_line_completion_push(completion, key);
1677  }
1678  }
1679  } else if (find_e_opts(core, completion, buf)) {
1680  return;
1681  } else if (prompt_type == RZ_LINE_PROMPT_OFFSET) {
1682  autocomplete_flags(core, completion, buf->data);
1683  } else if (prompt_type == RZ_LINE_PROMPT_FILE) {
1684  autocomplete_file(completion, buf->data);
1685  } else if (!find_autocomplete(core, completion, buf)) {
1686  autocomplete_default(core, completion, buf);
1687  }
1688 }
1689 
1691  return rz_core_autocomplete_rzshell((RzCore *)user, buf, prompt_type);
1692 }
1693 
1694 RZ_API int rz_core_fgets(char *buf, int len, void *user) {
1695  RzCore *core = (RzCore *)user;
1696  RzCons *cons = rz_cons_singleton();
1697  RzLine *rzline = cons->line;
1698  bool prompt = cons->context->is_interactive;
1699  buf[0] = '\0';
1700  if (prompt) {
1702  rzline->ns_completion.run_user = core;
1703  rzline->completion.run = NULL;
1704  } else {
1705  rzline->history.data = NULL;
1706  rz_line_completion_set(&rzline->completion, 0, NULL);
1707  rzline->completion.run = NULL;
1708  rzline->completion.run_user = NULL;
1709  }
1710  const char *ptr = rz_line_readline();
1711  if (!ptr) {
1712  return -1;
1713  }
1714  return rz_str_ncpy(buf, ptr, len - 1);
1715 }
1716 
1717 static const char *rz_core_print_offname(void *p, ut64 addr) {
1718  RzCore *c = (RzCore *)p;
1719  RzFlagItem *item = rz_flag_get_i(c->flags, addr);
1720  return item ? item->name : NULL;
1721 }
1722 
1723 static int rz_core_print_offsize(void *p, ut64 addr) {
1724  RzCore *c = (RzCore *)p;
1725  RzFlagItem *item = rz_flag_get_i(c->flags, addr);
1726  return item ? item->size : -1;
1727 }
1728 
1732 static int __disasm(void *_core, ut64 addr) {
1733  RzCore *core = _core;
1734  ut64 prevaddr = core->offset;
1735 
1736  rz_core_seek(core, addr, true);
1737  int len = rz_core_print_disasm_instructions(core, 0, 1);
1738  rz_core_seek(core, prevaddr, true);
1739 
1740  return len;
1741 }
1742 
1743 static void update_sdb(RzCore *core) {
1744  Sdb *d;
1745  RzBinObject *o;
1746  if (!core) {
1747  return;
1748  }
1749  // SDB// analysis/
1750  if (core->analysis && core->analysis->sdb) {
1751  sdb_ns_set(DB, "analysis", core->analysis->sdb);
1752  }
1753  // SDB// bin/
1754  if (core->bin && core->bin->sdb) {
1755  sdb_ns_set(DB, "bin", core->bin->sdb);
1756  }
1757  // SDB// bin/info
1758  o = rz_bin_cur_object(core->bin);
1759  if (o) {
1760  sdb_ns_set(sdb_ns(DB, "bin", 1), "info", o->kv);
1761  }
1762  // sdb_ns_set (core->sdb, "flags", core->flags->sdb);
1763  // sdb_ns_set (core->sdb, "bin", core->bin->sdb);
1764  // SDB// syscall/
1765  if (core->rasm && core->rasm->syscall && core->rasm->syscall->db) {
1766  sdb_ns_set(DB, "syscall", core->rasm->syscall->db);
1767  }
1768  d = sdb_ns(DB, "debug", 1);
1769  if (core->dbg->sgnls) {
1770  sdb_ns_set(d, "signals", core->dbg->sgnls);
1771  }
1772 }
1773 
1774 #define MINLEN 1
1775 static int is_string(const ut8 *buf, int size, int *len) {
1776  int i;
1777  if (size < 1) {
1778  return 0;
1779  }
1780  if (size > 3 && buf[0] && !buf[1] && buf[2] && !buf[3]) {
1781  *len = 1; // XXX: TODO: Measure wide string length
1782  return 2; // is wide
1783  }
1784  for (i = 0; i < size; i++) {
1785  if (!buf[i] && i > MINLEN) {
1786  *len = i;
1787  return 1;
1788  }
1789  if (buf[i] == 10 || buf[i] == 13 || buf[i] == 9) {
1790  continue;
1791  }
1792  if (buf[i] < 32 || buf[i] > 127) {
1793  // not ascii text
1794  return 0;
1795  }
1796  if (!IS_PRINTABLE(buf[i])) {
1797  *len = i;
1798  return 0;
1799  }
1800  }
1801  *len = i;
1802  return 1;
1803 }
1804 
1806  if (mode) {
1807  PJ *pj = (mode == 'j') ? pj_new() : NULL;
1808  const int hex_depth = 1; // r_config_get_i (core->config, "hex.depth");
1809  char *res = rz_core_analysis_hasrefs_to_depth(core, value, pj, hex_depth);
1810  if (pj) {
1811  free(res);
1812  return pj_drain(pj);
1813  }
1814  return res;
1815  }
1816  RzFlagItem *fi = rz_flag_get_i(core->flags, value);
1817  return fi ? strdup(fi->name) : NULL;
1818 }
1819 
1820 static char *getvalue(ut64 value, int bits) {
1821  switch (bits) {
1822  case 16: // umf, not in sync with pxr
1823  {
1824  st16 v = (st16)(value & UT16_MAX);
1825  st16 h = UT16_MAX / 0x100;
1826  if (v > -h && v < h) {
1827  return rz_str_newf("%hd", v);
1828  }
1829  } break;
1830  case 32: {
1831  st32 v = (st32)(value & UT32_MAX);
1832  st32 h = UT32_MAX / 0x10000;
1833  if (v > -h && v < h) {
1834  return rz_str_newf("%d", v);
1835  }
1836  } break;
1837  case 64: {
1838  st64 v = (st64)(value);
1839  st64 h = UT64_MAX / 0x1000000;
1840  if (v > -h && v < h) {
1841  return rz_str_newf("%" PFMT64d, v);
1842  }
1843  } break;
1844  }
1845  return NULL;
1846 }
1847 
1848 /*
1849  pxr logic is dupplicated in other places
1850  * ai, ad
1851  * no json support
1852 */
1854  const int bits = core->rasm->bits;
1855  rz_return_val_if_fail(core, NULL);
1857  if (pj) {
1858  pj_o(pj);
1859  pj_kn(pj, "addr", value);
1860  }
1861  if (depth < 1 || value == UT64_MAX) {
1862  if (pj) {
1863  pj_end(pj);
1864  }
1865  return NULL;
1866  }
1867 
1868  char *val = getvalue(value, bits);
1869  if (val) {
1870  if (pj) {
1871  pj_ks(pj, "value", val);
1872  } else {
1873  rz_strbuf_appendf(s, "%s ", val);
1874  }
1875  RZ_FREE(val);
1876  }
1877 
1878  if (value && value != UT64_MAX) {
1880  if (map && map->name && map->name[0]) {
1881  if (pj) {
1882  pj_ks(pj, "map", map->name);
1883  } else {
1884  rz_strbuf_appendf(s, "%s ", map->name);
1885  }
1886  }
1887  }
1889  RzBinObject *obj = rz_bin_cur_object(core->bin);
1890  RzBinSection *sect = value && obj ? rz_bin_get_section_at(obj, value, true) : NULL;
1892  // Do not repeat "stack" or "heap" words unnecessarily.
1893  if (sect && sect->name[0]) {
1894  if (pj) {
1895  pj_ks(pj, "section", sect->name);
1896  } else {
1897  rz_strbuf_appendf(s, "%s ", sect->name);
1898  }
1899  }
1900  }
1901  if (value != 0 && value != UT64_MAX) {
1902  if (pj) {
1903  RzListIter *iter;
1904  RzFlagItem *f;
1905  const RzList *flags = rz_flag_get_list(core->flags, value);
1906  if (flags && !rz_list_empty(flags)) {
1907  pj_ka(pj, "flags");
1908  rz_list_foreach (flags, iter, f) {
1909  pj_s(pj, f->name);
1910  }
1911  pj_end(pj);
1912  }
1913  } else {
1914  char *flags = rz_flag_get_liststr(core->flags, value);
1915  if (flags) {
1916  rz_strbuf_appendf(s, "%s ", flags);
1917  free(flags);
1918  }
1919  }
1920  }
1922  if (fcn) {
1923  if (pj) {
1924  pj_ks(pj, "fcn", fcn->name);
1925  } else {
1926  rz_strbuf_appendf(s, "%s ", fcn->name);
1927  }
1928  }
1929  if (type) {
1930  const char *c = rz_core_analysis_optype_colorfor(core, value, true);
1931  const char *cend = (c && *c) ? Color_RESET : "";
1932  if (!c) {
1933  c = "";
1934  }
1935  if (pj) {
1936  pj_ka(pj, "attr");
1937  }
1939  if (pj) {
1940  pj_s(pj, "heap");
1941  } else {
1942  rz_strbuf_appendf(s, "%sheap%s ", c, cend);
1943  }
1944  } else if (type & RZ_ANALYSIS_ADDR_TYPE_STACK) {
1945  if (pj) {
1946  pj_s(pj, "stack");
1947  } else {
1948  rz_strbuf_appendf(s, "%sstack%s ", c, cend);
1949  }
1950  }
1952  if (pj) {
1953  pj_s(pj, "program");
1954  } else {
1955  rz_strbuf_appendf(s, "%sprogram%s ", c, cend);
1956  }
1957  }
1959  if (pj) {
1960  pj_s(pj, "library");
1961  } else {
1962  rz_strbuf_appendf(s, "%slibrary%s ", c, cend);
1963  }
1964  }
1966  if (pj) {
1967  pj_s(pj, "ascii");
1968  } else {
1969  rz_strbuf_appendf(s, "%sascii%s ('%c') ", c, cend, (char)value);
1970  }
1971  }
1973  if (pj) {
1974  pj_s(pj, "sequence");
1975  } else {
1976  rz_strbuf_appendf(s, "%ssequence%s ", c, cend);
1977  }
1978  }
1979  if (pj) {
1981  pj_s(pj, "R");
1982  }
1984  pj_s(pj, "W");
1985  }
1987  pj_s(pj, "X");
1988  }
1989  } else {
1991  rz_strbuf_appendf(s, "%sR%s ", c, cend);
1992  }
1994  rz_strbuf_appendf(s, "%sW%s ", c, cend);
1995  }
1997  RzAsmOp op;
1998  ut8 buf[32];
1999  rz_strbuf_appendf(s, "%sX%s ", c, cend);
2000  /* instruction disassembly */
2001  rz_io_read_at(core->io, value, buf, sizeof(buf));
2002  rz_asm_set_pc(core->rasm, value);
2003  rz_asm_disassemble(core->rasm, &op, buf, sizeof(buf));
2004  rz_strbuf_appendf(s, "'%s' ", rz_asm_op_get_asm(&op));
2005  /* get library name */
2006  { // NOTE: dup for mapname?
2007  RzDebugMap *map;
2008  RzListIter *iter;
2009  rz_list_foreach (core->dbg->maps, iter, map) {
2010  if ((value >= map->addr) &&
2011  (value < map->addr_end)) {
2012  const char *lastslash = rz_str_lchr(map->name, '/');
2013  rz_strbuf_appendf(s, "'%s' ", lastslash ? lastslash + 1 : map->name);
2014  break;
2015  }
2016  }
2017  }
2018  } else if (type & RZ_ANALYSIS_ADDR_TYPE_READ) {
2019  ut8 buf[32];
2020  ut32 *n32 = (ut32 *)buf;
2021  ut64 *n64 = (ut64 *)buf;
2022  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2023  ut64 n = (bits == 64) ? *n64 : *n32;
2024  rz_strbuf_appendf(s, "0x%" PFMT64x " ", n);
2025  }
2026  }
2027  }
2028  if (pj) {
2029  pj_end(pj);
2030  }
2031  }
2032  {
2033  ut8 buf[128], widebuf[256];
2034  const char *c = rz_config_get_i(core->config, "scr.color") ? core->cons->context->pal.ai_ascii : "";
2035  const char *cend = (c && *c) ? Color_RESET : "";
2036  int len, r;
2037  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2038  buf[sizeof(buf) - 1] = 0;
2039  switch (is_string(buf, sizeof(buf), &len)) {
2040  case 1:
2041  if (pj) {
2042  pj_ks(pj, "string", (const char *)buf);
2043  } else {
2044  rz_strbuf_appendf(s, "%s%s%s ", c, buf, cend);
2045  }
2046  break;
2047  case 2:
2048  r = rz_utf8_encode_str((const RzRune *)buf, widebuf, sizeof(widebuf) - 1);
2049  if (r == -1) {
2050  eprintf("Something was wrong with refs\n");
2051  } else {
2052  if (pj) {
2053  pj_ks(pj, "string", (const char *)widebuf);
2054  } else {
2055  rz_strbuf_appendf(s, "%s%s%s ", c, widebuf, cend);
2056  }
2057  }
2058  break;
2059  }
2060  }
2061  }
2063  // Try to telescope further, but only several levels deep.
2064  ut8 buf[32];
2065  ut32 *n32 = (ut32 *)buf;
2066  ut64 *n64 = (ut64 *)buf;
2067  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2068  ut64 n = (bits == 64) ? *n64 : *n32;
2069  if (n != value) {
2070  if (pj) {
2071  pj_k(pj, "ref");
2072  }
2073  char *rrstr = rz_core_analysis_hasrefs_to_depth(core, n, pj, depth - 1);
2074  if (rrstr) {
2075  if (!pj && rrstr[0]) {
2076  rz_strbuf_appendf(s, " -> %s", rrstr);
2077  }
2078  free(rrstr);
2079  }
2080  }
2081  }
2082  }
2083  if (pj) {
2084  pj_end(pj);
2085  }
2086  char *res = rz_strbuf_drain(s);
2087  rz_str_trim_tail(res);
2088  return res;
2089 }
2090 
2092  if (core) {
2093  const char *type = rz_meta_get_string(core->analysis, RZ_META_TYPE_VARTYPE, addr);
2094  const char *cmt = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, addr);
2095  if (type && cmt) {
2096  return rz_str_newf("%s %s", type, cmt);
2097  }
2098  if (type) {
2099  return strdup(type);
2100  }
2101  if (cmt) {
2102  return strdup(cmt);
2103  }
2104  }
2105  return NULL;
2106 }
2107 
2109  ut64 type;
2110  if (!(core->print->flags & RZ_PRINT_FLAGS_COLOR)) {
2111  return NULL;
2112  }
2113  if (!rz_config_get_i(core->config, "scr.color")) {
2114  return NULL;
2115  }
2118  return core->cons->context->pal.ai_exec; // Color_RED;
2119  }
2121  return core->cons->context->pal.ai_write; // Color_BLUE;
2122  }
2124  return core->cons->context->pal.ai_read; // Color_GREEN;
2125  }
2127  return core->cons->context->pal.ai_seq; // Color_MAGENTA;
2128  }
2130  return core->cons->context->pal.ai_ascii; // Color_YELLOW;
2131  }
2132  return NULL;
2133 }
2134 
2135 static int mywrite(const ut8 *buf, int len) {
2136  return rz_cons_memcat((const char *)buf, len);
2137 }
2138 
2139 static bool exists_var(RzPrint *print, ut64 func_addr, char *str) {
2140  RzAnalysis *analysis = ((RzCore *)(print->user))->analysis;
2141  RzAnalysisFunction *fcn = rz_analysis_get_function_at(analysis, func_addr);
2142  if (!fcn) {
2143  return false;
2144  }
2146 }
2147 
2148 static bool rz_core_analysis_read_at(struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len) {
2149  return rz_io_read_at(analysis->iob.io, addr, buf, len);
2150 }
2151 
2152 static void rz_core_break(RzCore *core) {
2153 }
2154 
2155 static void *rz_core_sleep_begin(RzCore *core) {
2156  RzCoreTask *task = rz_core_task_self(&core->tasks);
2157  if (task) {
2159  }
2160  return task;
2161 }
2162 
2163 static void rz_core_sleep_end(RzCore *core, void *user) {
2164  RzCoreTask *task = (RzCoreTask *)user;
2165  if (task) {
2166  rz_core_task_sleep_end(task);
2167  }
2168 }
2169 
2170 static void __foreach(RzCore *core, const char **cmds, int type) {
2171  int i;
2172  for (i = 0; cmds[i]; i++) {
2173  rz_core_autocomplete_add(core->autocomplete, cmds[i], type, true);
2174  }
2175 }
2176 
2178  const char *fcns[] = {
2179  "afcf", "afn", NULL
2180  };
2181  const char *seeks[] = {
2182  "s", NULL
2183  };
2184  const char *flags[] = {
2185  "*", "s", "s+", "b", "f", "fg", "?", "?v", "ad", "bf", "c1", "db", "dbw",
2186  "f-", "fr", "tf", "/a", "/v", "/r", "/re", "aav", "aep", "aef",
2187  "afc", "axg", "axt", "axf", "dcu", "ag", "agfl", "aecu", "aesu", "aeim", NULL
2188  };
2189  const char *evals[] = {
2190  "e", "ee", "et", "e?", "e!", "ev", "evj", NULL
2191  };
2192  const char *breaks[] = {
2193  "db-", "dbc", "dbC", "dbd", "dbe", "dbs", "dbi", "dbte", "dbtd", "dbts", NULL
2194  };
2195  const char *files[] = {
2196  ".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!vala",
2197  "#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o",
2198  "idp", "idpi", "L", "obf", "o+", "oc",
2199  "rizin", "rz-agent", "rz-asm", "rz-ax", "rz-bin", "rz-diff", "rz-find", "rz-gg", "rz-hash", "rz-pm", "rz-run", "rz-sign",
2200  "cd", "ls", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
2201  "/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "vi",
2202  "less", "head", "Ps", "Pl", NULL
2203  };
2205  __foreach(core, seeks, RZ_CORE_AUTOCMPLT_SEEK);
2206  __foreach(core, fcns, RZ_CORE_AUTOCMPLT_FCN);
2207  __foreach(core, evals, RZ_CORE_AUTOCMPLT_EVAL);
2208  __foreach(core, breaks, RZ_CORE_AUTOCMPLT_BRKP);
2210 
2215  "-l", RZ_CORE_AUTOCMPLT_FILE, true);
2218  /* macros */
2221  /* just for hints */
2222  int i;
2223  for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
2224  if (!rz_core_autocomplete_find(core->autocomplete, rizin_argv[i], true)) {
2226  }
2227  }
2228 }
2229 
2230 static void __init_autocomplete(RzCore *core) {
2232  if (core->autocomplete_type == AUTOCOMPLETE_DEFAULT) {
2234  }
2235 }
2236 
2237 static const char *colorfor_cb(void *user, ut64 addr, bool verbose) {
2239 }
2240 
2241 static char *hasrefs_cb(void *user, ut64 addr, int mode) {
2242  return rz_core_analysis_hasrefs((RzCore *)user, addr, mode);
2243 }
2244 
2245 static const char *get_section_name(void *user, ut64 addr) {
2246  return rz_core_get_section_name((RzCore *)user, addr);
2247 }
2248 
2249 static char *get_comments_cb(void *user, ut64 addr) {
2250  return rz_core_analysis_get_comments((RzCore *)user, addr);
2251 }
2252 
2254  rz_flag_space_push(f, RZ_FLAGS_FS_CLASSES);
2255  RzFlagItem *res = rz_flag_set(f, name, addr, size);
2256  rz_flag_space_pop(f);
2257  return res;
2258 }
2259 
2260 static RzFlagItem *core_flg_class_get(RzFlag *f, const char *name) {
2261  rz_flag_space_push(f, RZ_FLAGS_FS_CLASSES);
2262  RzFlagItem *res = rz_flag_get(f, name);
2263  rz_flag_space_pop(f);
2264  return res;
2265 }
2266 
2268  rz_flag_space_push(f, RZ_FLAGS_FS_FUNCTIONS);
2269  RzFlagItem *res = rz_flag_set(f, name, addr, size);
2270  rz_flag_space_pop(f);
2271  return res;
2272 }
2273 
2275  rz_return_if_fail(core);
2277  __init_autocomplete(core);
2278 }
2279 
2281  return rz_flag_get_by_spaces(f, off,
2293  NULL);
2294 }
2295 
2296 #if __WINDOWS__
2297 // XXX move to rcons?
2298 static int win_eprintf(const char *format, ...) {
2299  va_list ap;
2300  va_start(ap, format);
2301  rz_cons_win_vhprintf(STD_ERROR_HANDLE, false, format, ap);
2302  va_end(ap);
2303  return 0;
2304 }
2305 #endif
2306 
2307 static bool bp_is_mapped(ut64 addr, int perm, void *user) {
2308  RzCore *core = user;
2309  if (rz_core_is_debug(core)) {
2310  // RzList *maps = core->dbg->maps;
2311  RzDebugMap *map = NULL;
2312  RzListIter *iter = NULL;
2313 
2314  rz_list_foreach (core->dbg->maps, iter, map) {
2315  if (addr < map->addr || addr >= map->addr_end) {
2316  continue;
2317  }
2318  if (perm <= 0 || (map->perm & perm)) {
2319  return true;
2320  }
2321  }
2322  return false;
2323  }
2324 
2325  return rz_io_map_is_mapped(core->io, addr);
2326 }
2327 
2328 static void bp_maps_sync(void *user) {
2329  RzCore *core = user;
2330  if (rz_core_is_debug(core)) {
2331  rz_debug_map_sync(core->dbg);
2332  }
2333 }
2334 
2335 static int bp_bits_at(ut64 addr, void *user) {
2336  RzCore *core = user;
2337  int r = 0;
2338  rz_core_arch_bits_at(core, addr, &r, NULL);
2339  return r ? r : core->analysis->bits;
2340 }
2341 
2342 static void ev_iowrite_cb(RzEvent *ev, int type, void *user, void *data) {
2343  RzCore *core = user;
2344  RzEventIOWrite *iow = data;
2345  if (rz_config_get_i(core->config, "analysis.detectwrites")) {
2347  if (core->cons->event_resize && core->cons->event_data) {
2348  // Force a reload of the graph
2349  core->cons->event_resize(core->cons->event_data);
2350  }
2351  }
2352 }
2353 
2358 
2359 static void ev_iodescclose_cb(RzEvent *ev, int type, void *user, void *data) {
2360  RzEventIODescClose *ioc = data;
2361  rz_core_file_io_desc_closed(user, ioc->desc);
2362 }
2363 
2364 static void ev_iomapdel_cb(RzEvent *ev, int type, void *user, void *data) {
2365  RzEventIOMapDel *iod = data;
2366  rz_core_file_io_map_deleted(user, iod->map);
2367 }
2368 
2369 static void ev_binfiledel_cb(RzEvent *ev, int type, void *user, void *data) {
2370  RzEventBinFileDel *bev = data;
2371  rz_core_file_bin_file_deleted(user, bev->bf);
2372  rz_core_vfile_bin_file_deleted(user, bev->bf);
2373 }
2374 
2375 RZ_IPI void rz_core_task_ctx_switch(RzCoreTask *next, void *user);
2376 RZ_IPI void rz_core_task_break_cb(RzCoreTask *task, void *user);
2378 
2380 
2382  core->blocksize = RZ_CORE_BLOCKSIZE;
2383  core->block = (ut8 *)calloc(RZ_CORE_BLOCKSIZE + 1, 1);
2384  if (!core->block) {
2385  eprintf("Cannot allocate %d byte(s)\n", RZ_CORE_BLOCKSIZE);
2386  /* XXX memory leak */
2387  return false;
2388  }
2389  core->ev = rz_event_new(core);
2390  core->max_cmd_depth = RZ_CONS_CMD_DEPTH + 1;
2391  core->sdb = sdb_new(NULL, "rzkv.sdb", 0); // XXX: path must be in home?
2392  rz_core_seek_reset(core);
2393  core->lastsearch = NULL;
2394  core->cmdfilter = NULL;
2395  core->curtheme = strdup("default");
2396  core->switch_file_view = 0;
2397  core->cmdremote = 0;
2398  core->incomment = false;
2399  core->config = NULL;
2400  core->http_up = false;
2402  core->print = rz_print_new();
2404  rz_core_bind(core, &(core->print->coreb));
2405  core->print->user = core;
2406  core->print->num = core->num;
2409  core->print->cb_printf = rz_cons_printf;
2410  core->visual_is_inputing = false;
2411  core->visual_inputing = NULL;
2412 #if __WINDOWS__
2413  core->print->cb_eprintf = win_eprintf;
2414 #endif
2416  core->print->write = mywrite;
2417  core->print->exists_var = exists_var;
2418  core->print->disasm = __disasm;
2419  core->print->colorfor = colorfor_cb;
2420  core->print->hasrefs = hasrefs_cb;
2423  core->print->use_comments = false;
2424  rz_core_rtr_init(core);
2425  core->rtr_n = 0;
2428  core->watchers = rz_list_new();
2430  core->scriptstack = rz_list_new();
2431  core->scriptstack->free = (RzListFree)free;
2432  core->times = RZ_NEW0(RzCoreTimes);
2433  core->vmode = false;
2434  core->printidx = 0;
2435  core->lastcmd = NULL;
2436  core->cmdlog = NULL;
2437  core->stkcmd = NULL;
2438  core->cmdqueue = NULL;
2439  core->cmdrepeat = true;
2440  core->yank_buf = rz_buf_new_with_bytes(NULL, 0);
2441  core->num = rz_num_new(&num_callback, &str_callback, core);
2442  core->egg = rz_egg_new();
2444 
2445  core->fixedarch = false;
2446  core->fixedbits = false;
2447 
2448  /* initialize libraries */
2449  core->cons = rz_cons_new();
2450  if (core->cons->refcnt == 1) {
2451  core->cons = rz_cons_singleton();
2452  if (core->cons->line) {
2453  core->cons->line->user = core;
2454  core->cons->line->cb_editor =
2456  core->cons->line->cb_fkey = core->cons->cb_fkey;
2457  }
2458 #if __EMSCRIPTEN__
2459  core->cons->user_fgets = NULL;
2460 #else
2461  core->cons->user_fgets = (void *)rz_core_fgets;
2462  core->cons->user_fgets_user = core;
2463 #endif
2464  char *history = rz_path_home_history();
2465  rz_line_hist_load(history);
2466  free(history);
2467  }
2468  core->print->cons = core->cons;
2469  rz_cons_bind(&core->print->consbind);
2470 
2471  // We save the old num ad user, in order to restore it after free
2472  core->lang = rz_lang_new();
2473  core->lang->cmd_str = (char *(*)(void *, const char *))rz_core_cmd_str;
2474  core->lang->cmdf = (int (*)(void *, const char *, ...))rz_core_cmdf;
2475  rz_core_bind_cons(core);
2476  core->lang->cb_printf = rz_cons_printf;
2477  rz_lang_define(core->lang, "RzCore", "core", core);
2478  rz_lang_set_user_ptr(core->lang, core);
2479  core->rasm = rz_asm_new();
2480  core->rasm->num = core->num;
2481  core->rasm->core = core;
2482  core->analysis = rz_analysis_new();
2484  core->analysis->ev = core->ev;
2487  core->analysis->cb.on_fcn_new = on_fcn_new;
2490  core->rasm->syscall = rz_syscall_ref(core->analysis->syscall); // BIND syscall analysis/asm
2491  core->analysis->core = core;
2492  core->parser = rz_parse_new();
2493  rz_analysis_bind(core->analysis, &(core->parser->analb));
2496  rz_parse_set_user_ptr(core->parser, core);
2497  core->bin = rz_bin_new();
2499  rz_cons_bind(&core->bin->consb);
2500  // XXX we shuold use RzConsBind instead of this hardcoded pointer
2502  rz_bin_set_user_ptr(core->bin, core);
2503  core->io = rz_io_new();
2508  core->io->ff = 1;
2510  core->flags = rz_flag_new();
2511  core->graph = rz_agraph_new(rz_cons_canvas_new(1, 1));
2512  core->graph->need_reload_nodes = false;
2514  if (sizeof(ut64) * core->asmqjmps_size < core->asmqjmps_size) {
2515  core->asmqjmps_size = 0;
2516  core->asmqjmps = NULL;
2517  } else {
2518  core->asmqjmps = RZ_NEWS(ut64, core->asmqjmps_size);
2519  }
2520  core->hash = rz_hash_new();
2521 
2522  rz_bin_bind(core->bin, &(core->rasm->binb));
2523  rz_bin_bind(core->bin, &(core->analysis->binb));
2524  rz_bin_bind(core->bin, &(core->analysis->binb));
2525 
2526  rz_io_bind(core->io, &(core->search->iob));
2527  rz_io_bind(core->io, &(core->print->iob));
2528  rz_io_bind(core->io, &(core->analysis->iob));
2529  rz_io_bind(core->io, &(core->analysis->typedb->iob));
2530  rz_io_bind(core->io, &(core->bin->iob));
2531  rz_flag_bind(core->flags, &(core->analysis->flb));
2535  rz_analysis_bind(core->analysis, &(core->parser->analb));
2538 
2539  rz_core_bind(core, &(core->analysis->coreb));
2540 
2541  core->file = NULL;
2543  core->offset = 0LL;
2544  core->prompt_offset = 0LL;
2545  rz_core_cmd_init(core);
2546  rz_core_plugin_init(core);
2547 
2548  RzBreakpointContext bp_ctx = {
2549  .user = core,
2550  .is_mapped = bp_is_mapped,
2551  .maps_sync = bp_maps_sync,
2552  .bits_at = bp_bits_at
2553  };
2554  core->dbg = rz_debug_new(&bp_ctx);
2555 
2556  rz_io_bind(core->io, &(core->dbg->iob));
2557  rz_io_bind(core->io, &(core->dbg->bp->iob));
2558  rz_core_bind(core, &core->dbg->corebind);
2559  rz_core_bind(core, &core->io->corebind);
2560  core->dbg->analysis = core->analysis; // XXX: dupped instance.. can cause lost pointerz
2561  // rz_debug_use (core->dbg, "native");
2562  // XXX pushing uninitialized regstate results in trashed reg values
2563  // rz_reg_arena_push (core->dbg->reg); // create a 2 level register state stack
2564  // core->dbg->analysis->reg = core->analysis->reg; // XXX: dupped instance.. can cause lost pointerz
2565  core->io->cb_printf = rz_cons_printf;
2566  core->dbg->cb_printf = rz_cons_printf;
2567  core->dbg->bp->cb_printf = rz_cons_printf;
2568  core->dbg->ev = core->ev;
2569  // initialize config before any corebind
2570  rz_core_config_init(core);
2571 
2572  rz_core_loadlibs_init(core);
2573 
2574  // TODO: get arch from rz_bin or from native arch
2575  rz_asm_use(core->rasm, RZ_SYS_ARCH);
2577  if (RZ_SYS_BITS & RZ_SYS_BITS_64) {
2578  rz_config_set_i(core->config, "asm.bits", 64);
2579  } else {
2580  if (RZ_SYS_BITS & RZ_SYS_BITS_32) {
2581  rz_config_set_i(core->config, "asm.bits", 32);
2582  }
2583  }
2584  rz_config_set(core->config, "asm.arch", RZ_SYS_ARCH);
2585  rz_bp_use(core->dbg->bp, RZ_SYS_ARCH);
2586  update_sdb(core);
2587  {
2588  char *a = rz_path_system(RZ_FLAGS);
2589  if (a) {
2590  char *file = rz_file_path_join(a, "tags.rz");
2591  (void)rz_core_run_script(core, file);
2592  free(file);
2593  free(a);
2594  }
2595  }
2597  __init_autocomplete(core);
2598  return 0;
2599 }
2600 
2601 RZ_API void __cons_cb_fkey(RzCore *core, int fkey) {
2602  char buf[32];
2603  snprintf(buf, sizeof(buf), "key.f%d", fkey);
2604  const char *v = rz_config_get(core->config, buf);
2605  if (v && *v) {
2606  rz_cons_printf("%s\n", v);
2607  rz_core_cmd0(core, v);
2608  rz_cons_flush();
2609  }
2610 }
2611 
2613  core->cons->num = core->num;
2620  core->cons->user = (void *)core;
2621 }
2622 
2624  if (!c) {
2625  return;
2626  }
2628  rz_core_task_break_all(&c->tasks);
2629  rz_core_task_join(&c->tasks, NULL, -1);
2630  rz_core_wait(c);
2631  // avoid double free
2632  RZ_FREE_CUSTOM(c->hash, rz_hash_free);
2633  RZ_FREE_CUSTOM(c->ropchain, rz_list_free);
2635  RZ_FREE(c->cmdlog);
2636  RZ_FREE(c->lastsearch);
2637  RZ_FREE(c->cons->pager);
2638  RZ_FREE(c->cmdqueue);
2639  RZ_FREE(c->lastcmd);
2640  RZ_FREE(c->stkcmd);
2641  RZ_FREE_CUSTOM(c->visual.tabs, rz_list_free);
2642  RZ_FREE(c->block);
2643  RZ_FREE_CUSTOM(c->autocomplete, rz_core_autocomplete_free);
2644 
2645  RZ_FREE_CUSTOM(c->gadgets, rz_list_free);
2646  RZ_FREE_CUSTOM(c->num, rz_num_free);
2647  RZ_FREE(c->table_query);
2648  RZ_FREE_CUSTOM(c->io, rz_io_free);
2649  RZ_FREE_CUSTOM(c->files, rz_list_free);
2650  RZ_FREE_CUSTOM(c->watchers, rz_list_free);
2651  RZ_FREE_CUSTOM(c->scriptstack, rz_list_free);
2652  rz_core_task_scheduler_fini(&c->tasks);
2653  RZ_FREE_CUSTOM(c->rcmd, rz_cmd_free);
2654  RZ_FREE_CUSTOM(c->cmd_descriptors, rz_list_free);
2655  RZ_FREE_CUSTOM(c->analysis, rz_analysis_free);
2656  RZ_FREE_CUSTOM(c->rasm, rz_asm_free);
2657  RZ_FREE_CUSTOM(c->print, rz_print_free);
2658  RZ_FREE_CUSTOM(c->bin, rz_bin_free);
2659  RZ_FREE_CUSTOM(c->lang, rz_lang_free);
2661  RZ_FREE_CUSTOM(c->config, rz_config_free);
2662  /* after rz_config_free, the value of I.teefile is trashed */
2663  /* rconfig doesnt knows how to deinitialize vars, so we
2664  should probably need to add a rz_config_free_payload callback */
2665  rz_cons_free();
2666  rz_cons_singleton()->teefile = NULL; // HACK
2667  RZ_FREE_CUSTOM(c->search, rz_search_free);
2668  RZ_FREE_CUSTOM(c->flags, rz_flag_free);
2669  RZ_FREE_CUSTOM(c->egg, rz_egg_free);
2670  RZ_FREE_CUSTOM(c->lib, rz_lib_free);
2671  RZ_FREE_CUSTOM(c->yank_buf, rz_buf_free);
2672  RZ_FREE_CUSTOM(c->graph, rz_agraph_free);
2673  RZ_FREE(c->visual_inputing);
2674  RZ_FREE(c->asmqjmps);
2675  RZ_FREE_CUSTOM(c->sdb, sdb_free);
2676  RZ_FREE_CUSTOM(c->parser, rz_parse_free);
2677  RZ_FREE(c->times);
2679  RZ_FREE(c->rtr_host);
2680  RZ_FREE(c->curtheme);
2681 }
2682 
2684  rz_core_fini(c);
2685  free(c);
2686 }
2687 
2689  int ret;
2690  do {
2691  if (rz_config_get_b(r->config, "dbg.status")) {
2693  }
2694  int err = rz_core_prompt(r, false);
2695  if (err < 1) {
2696  // handle ^D
2697  r->num->value = 0; // r.num->value will be read by rz_main_rizin() after calling this fcn
2698  break;
2699  }
2700  /* -1 means invalid command, -2 means quit prompt loop */
2701  if ((ret = rz_core_prompt_exec(r)) == -2) {
2702  break;
2703  }
2704  } while (ret != RZ_CORE_CMD_EXIT);
2705 }
2706 
2707 static bool prompt_add_file(RzCore *core, RzStrBuf *sb, bool add_sep) {
2708  if (!rz_config_get_b(core->config, "scr.prompt.file") || !core->io->desc) {
2709  return add_sep;
2710  }
2711  if (add_sep) {
2712  rz_strbuf_append(sb, ":");
2713  }
2715  return true;
2716 }
2717 
2718 static bool prompt_add_section(RzCore *core, RzStrBuf *sb, bool add_sep) {
2719  if (!rz_config_get_b(core->config, "scr.prompt.sect")) {
2720  return add_sep;
2721  }
2722  const RzBinSection *sec = rz_bin_get_section_at(rz_bin_cur_object(core->bin), core->offset, true);
2723  if (!sec) {
2724  return add_sep;
2725  }
2726  if (add_sep) {
2727  rz_strbuf_append(sb, ":");
2728  }
2729  rz_strbuf_append(sb, sec->name);
2730  return true;
2731 }
2732 
2733 static bool prompt_add_offset(RzCore *core, RzStrBuf *sb, bool add_sep) {
2734  if (add_sep) {
2735  rz_strbuf_append(sb, ":");
2736  }
2737  if (rz_config_get_b(core->config, "scr.prompt.flag")) {
2738  const RzFlagItem *f = rz_flag_get_at(core->flags, core->offset, true);
2739  if (f) {
2740  if (f->offset < core->offset) {
2741  rz_strbuf_appendf(sb, "%s + %" PFMT64u, f->name, core->offset - f->offset);
2742  } else {
2743  rz_strbuf_appendf(sb, "%s", f->name);
2744  }
2745  if (rz_config_get_b(core->config, "scr.prompt.flag.only")) {
2746  return true;
2747  }
2748 
2749  rz_strbuf_append(sb, ":");
2750  }
2751  }
2752 
2753  if (rz_config_get_b(core->config, "asm.segoff")) {
2754  ut32 a, b;
2755  unsigned int seggrn = rz_config_get_i(core->config, "asm.seggrn");
2756 
2757  a = ((core->offset >> 16) << (16 - seggrn));
2758  b = (core->offset & 0xffff);
2759  rz_strbuf_appendf(sb, "%04x:%04x", a, b);
2760  } else {
2761  if (core->print->wide_offsets && core->dbg->bits & RZ_SYS_BITS_64) {
2762  rz_strbuf_appendf(sb, "0x%016" PFMT64x, core->offset);
2763  } else {
2764  rz_strbuf_appendf(sb, "0x%08" PFMT64x, core->offset);
2765  }
2766  }
2767  return true;
2768 }
2769 
2770 static void set_prompt(RzCore *r) {
2771  const char *cmdprompt = rz_config_get(r->config, "cmd.prompt");
2772  const char *BEGIN = "";
2773  const char *END = "";
2774  const char *remote = "";
2775 
2776  if (cmdprompt && *cmdprompt) {
2777  rz_core_cmd(r, cmdprompt, 0);
2778  }
2779 
2780  if (r->cmdremote) {
2781  char *s = rz_core_cmd_str(r, "s");
2782  r->offset = rz_num_math(NULL, s);
2783  free(s);
2784  remote = "R!";
2785  }
2786 
2787  if (rz_config_get_i(r->config, "scr.color")) {
2788  BEGIN = r->cons->context->pal.prompt;
2789  END = r->cons->context->pal.reset;
2790  }
2791 
2792  RzStrBuf prompt_ct;
2793  rz_strbuf_init(&prompt_ct);
2794  rz_strbuf_appendf(&prompt_ct, "%s[%s", BEGIN, remote);
2795  bool added = prompt_add_file(r, &prompt_ct, false);
2796  added = prompt_add_section(r, &prompt_ct, added);
2797  added = prompt_add_offset(r, &prompt_ct, added);
2798  rz_strbuf_appendf(&prompt_ct, "]>%s ", END);
2799 
2800  char *prompt = rz_strbuf_drain_nofree(&prompt_ct);
2802  free(prompt);
2803 }
2804 
2805 RZ_API int rz_core_prompt(RzCore *r, int sync) {
2806  char line[4096];
2807 
2808  int rnv = r->num->value;
2809  set_prompt(r);
2810  int ret = rz_cons_fgets(line, sizeof(line), 0, NULL);
2811  if (ret == -2) {
2812  return RZ_CORE_CMD_EXIT; // ^D
2813  }
2814  if (ret == -1) {
2815  return false; // FD READ ERROR
2816  }
2817  r->num->value = rnv;
2818  if (sync) {
2819  return rz_core_prompt_exec(r);
2820  }
2821  free(r->cmdqueue);
2822  r->cmdqueue = strdup(line);
2823  if (r->scr_gadgets && *line && *line != 'q') {
2825  }
2826  r->num->value = r->rc;
2827  return true;
2828 }
2829 
2831  int ret = rz_core_cmd(r, r->cmdqueue, true);
2832  r->rc = r->num->value;
2833  // int ret = rz_core_cmd (r, r->cmdqueue, true);
2834  rz_cons_echo(NULL);
2835  rz_cons_flush();
2836  if (r->cons && r->cons->line && r->cons->line->zerosep) {
2837  rz_cons_zero();
2838  }
2839  return ret;
2840 }
2841 
2842 RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize) {
2843  ut8 *bump;
2844  if (bsize == core->blocksize) {
2845  return true;
2846  }
2847  if (bsize > core->blocksize_max) {
2848  RZ_LOG_ERROR("Block size %d is too big\n", bsize);
2849  return false;
2850  }
2851  if (bsize < 1) {
2852  bsize = 1;
2853  } else if (core->blocksize_max && bsize > core->blocksize_max) {
2854  RZ_LOG_ERROR("block size is bigger than its max (check `bm` command). set to 0x%x\n", core->blocksize_max);
2855  bsize = core->blocksize_max;
2856  }
2857  bump = realloc(core->block, bsize + 1);
2858  if (!bump) {
2859  RZ_LOG_ERROR("Oops. cannot allocate that much (%u)\n", bsize);
2860  return false;
2861  }
2862  core->block = bump;
2863  core->blocksize = bsize;
2864  memset(core->block, 0xff, core->blocksize);
2865  rz_core_seek(core, core->offset, true);
2866  return true;
2867 }
2868 
2870  RzAsmOp op = { 0 };
2871  ut8 buf[64];
2872  rz_asm_set_pc(core->rasm, addr);
2873  rz_io_read_at(core->io, addr, buf, sizeof(buf));
2874  int ret = rz_asm_disassemble(core->rasm, &op, buf, sizeof(buf));
2875  char *str = (ret > 0) ? strdup(rz_strbuf_get(&op.buf_asm)) : NULL;
2876  rz_asm_op_fini(&op);
2877  return str;
2878 }
2879 
2881  ut8 buf[64];
2883  rz_io_read_at(core->io, addr, buf, sizeof(buf));
2884  rz_analysis_op(core->analysis, op, addr, buf, sizeof(buf), mask);
2885  return op;
2886 }
2887 
2888 typedef struct {
2891  bool listener;
2892 } RzIORap;
2893 
2894 static void rap_break(void *u) {
2895  RzIORap *rior = (RzIORap *)u;
2896  if (u) {
2897  rz_socket_close(rior->fd);
2898  rior->fd = NULL;
2899  }
2900 }
2901 
2902 // TODO: PLEASE move into core/io/rap? */
2903 // TODO: use static buffer instead of mallocs all the time. it's network!
2905  // TODO: use rz_socket_rap_server API instead of duplicating the logic
2906  ut8 cmd, flg, *ptr = NULL, buf[1024];
2907  int i, pipefd = -1;
2908  ut64 x;
2909 
2910  RzIORap *rior = (RzIORap *)file->data;
2911  if (!rior || !rior->fd) {
2912  eprintf("rap: cannot listen.\n");
2913  return false;
2914  }
2915  RzSocket *fd = rior->fd;
2916  eprintf("RAP Server started (rap.loop=%s)\n",
2917  rz_config_get(core->config, "rap.loop"));
2919 reaccept:
2920  while (!rz_cons_is_breaked()) {
2922  if (!c) {
2923  break;
2924  }
2925  if (rz_cons_is_breaked()) {
2926  goto out_of_function;
2927  }
2928  if (!c) {
2929  eprintf("rap: cannot accept\n");
2930  rz_socket_free(c);
2931  goto out_of_function;
2932  }
2933  eprintf("rap: client connected\n");
2934  for (; !rz_cons_is_breaked();) {
2935  if (!rz_socket_read_block(c, &cmd, 1)) {
2936  eprintf("rap: connection closed\n");
2937  if (rz_config_get_i(core->config, "rap.loop")) {
2938  eprintf("rap: waiting for new connection\n");
2939  rz_socket_free(c);
2940  goto reaccept;
2941  }
2942  goto out_of_function;
2943  }
2944  switch (cmd) {
2945  case RAP_PACKET_OPEN:
2946  rz_socket_read_block(c, &flg, 1); // flags
2947  eprintf("open (%d): ", cmd);
2948  rz_socket_read_block(c, &cmd, 1); // len
2949  pipefd = -1;
2950  if (UT8_ADD_OVFCHK(cmd, 1)) {
2951  goto out_of_function;
2952  }
2953  ptr = malloc((size_t)cmd + 1);
2954  if (!ptr) {
2955  eprintf("Cannot malloc in rmt-open len = %d\n", cmd);
2956  } else {
2957  ut64 baddr = rz_config_get_i(core->config, "bin.laddr");
2958  rz_socket_read_block(c, ptr, cmd);
2959  ptr[cmd] = 0;
2960  ut32 perm = RZ_PERM_R;
2961  if (flg & RZ_PERM_W) {
2962  perm |= RZ_PERM_W;
2963  }
2964  if (rz_core_file_open(core, (const char *)ptr, perm, 0)) {
2965  int fd = rz_io_fd_get_current(core->io);
2966  rz_core_bin_load(core, NULL, baddr);
2967  rz_io_map_add(core->io, fd, perm, 0, 0, rz_io_fd_size(core->io, fd));
2968  if (core->file) {
2969  pipefd = fd;
2970  } else {
2971  pipefd = -1;
2972  }
2973  eprintf("(flags: %d) len: %d filename: '%s'\n",
2974  flg, cmd, ptr); // config.file);
2975  } else {
2976  eprintf("Cannot open file (%s)\n", ptr);
2977  rz_socket_close(c);
2978  if (rz_config_get_i(core->config, "rap.loop")) {
2979  eprintf("rap: waiting for new connection\n");
2980  rz_socket_free(c);
2981  goto reaccept;
2982  }
2983  goto out_of_function; // XXX: Close connection and goto accept
2984  }
2985  }
2987  rz_write_be32(buf + 1, pipefd);
2988  rz_socket_write(c, buf, 5);
2989  rz_socket_flush(c);
2990  RZ_FREE(ptr);
2991  break;
2992  case RAP_PACKET_READ:
2993  rz_socket_read_block(c, (ut8 *)&buf, 4);
2994  i = rz_read_be32(buf);
2995  ptr = (ut8 *)malloc(i + core->blocksize + 5);
2996  if (ptr) {
2997  rz_core_block_read(core);
2998  ptr[0] = RAP_PACKET_READ | RAP_PACKET_REPLY;
2999  if (i > RAP_PACKET_MAX) {
3000  i = RAP_PACKET_MAX;
3001  }
3002  if (i > core->blocksize) {
3003  rz_core_block_size(core, i);
3004  }
3005  if (i + 128 < core->blocksize) {
3006  rz_core_block_size(core, i);
3007  }
3008  rz_write_be32(ptr + 1, i);
3009  memcpy(ptr + 5, core->block, i); // core->blocksize);
3010  rz_socket_write(c, ptr, i + 5);
3011  rz_socket_flush(c);
3012  RZ_FREE(ptr);
3013  } else {
3014  eprintf("Cannot read %d byte(s)\n", i);
3015  rz_socket_free(c);
3016  // TODO: reply error here
3017  goto out_of_function;
3018  }
3019  break;
3020  case RAP_PACKET_CMD: {
3021  char *cmd = NULL, *cmd_output = NULL;
3022  char bufr[8], *bufw = NULL;
3023  ut32 cmd_len = 0;
3024  int i;
3025 
3026  /* read */
3027  rz_socket_read_block(c, (ut8 *)&bufr, 4);
3028  i = rz_read_be32(bufr);
3029  if (i > 0 && i < RAP_PACKET_MAX) {
3030  if ((cmd = malloc(i + 1))) {
3031  rz_socket_read_block(c, (ut8 *)cmd, i);
3032  cmd[i] = '\0';
3033  int scr_interactive = rz_config_get_i(core->config, "scr.interactive");
3034  rz_config_set_i(core->config, "scr.interactive", 0);
3035  cmd_output = rz_core_cmd_str(core, cmd);
3036  rz_config_set_i(core->config, "scr.interactive", scr_interactive);
3037  free(cmd);
3038  } else {
3039  eprintf("rap: cannot malloc\n");
3040  }
3041  } else {
3042  eprintf("rap: invalid length '%d'\n", i);
3043  }
3044  /* write */
3045  if (cmd_output) {
3046  cmd_len = strlen(cmd_output) + 1;
3047  } else {
3048  cmd_output = strdup("");
3049  cmd_len = 0;
3050  }
3051 #if DEMO_SERVER_SENDS_CMD_TO_CLIENT
3052  static bool once = true;
3053  /* TODO: server can reply a command request to the client only here */
3054  if (once) {
3055  const char *cmd = "pd 4";
3056  int cmd_len = strlen(cmd) + 1;
3057  ut8 *b = malloc(cmd_len + 5);
3058  b[0] = RAP_PACKET_CMD;
3059  rz_write_be32(b + 1, cmd_len);
3060  strcpy((char *)b + 5, cmd);
3061  rz_socket_write(c, b, 5 + cmd_len);
3062  rz_socket_flush(c);
3063 
3064  /* read response */
3065  rz_socket_read_block(c, b, 5);
3066  if (b[0] == (RAP_PACKET_CMD | RAP_PACKET_REPLY)) {
3067  ut32 n = rz_read_be32(b + 1);
3068  eprintf("REPLY %d\n", n);
3069  if (n > 0) {
3070  ut8 *res = calloc(1, n);
3071  rz_socket_read_block(c, res, n);
3072  eprintf("RESPONSE(%s)\n", (const char *)res);
3073  free(res);
3074  }
3075  }
3076  rz_socket_flush(c);
3077  free(b);
3078  once = false;
3079  }
3080 #endif
3081  bufw = malloc(cmd_len + 5);
3082  bufw[0] = (ut8)(RAP_PACKET_CMD | RAP_PACKET_REPLY);
3083  rz_write_be32(bufw + 1, cmd_len);
3084  memcpy(bufw + 5, cmd_output, cmd_len);
3085  rz_socket_write(c, bufw, cmd_len + 5);
3086  rz_socket_flush(c);
3087  free(bufw);
3088  free(cmd_output);
3089  break;
3090  }
3091  case RAP_PACKET_WRITE:
3092  rz_socket_read_block(c, buf, 4);
3093  x = rz_read_at_be32(buf, 0);
3094  ptr = malloc(x);
3095  rz_socket_read_block(c, ptr, x);
3096  int ret = rz_core_write_at(core, core->offset, ptr, x);
3098  rz_write_be32(buf + 1, ret);
3099  rz_socket_write(c, buf, 5);
3100  rz_socket_flush(c);
3101  RZ_FREE(ptr);
3102  break;
3103  case RAP_PACKET_SEEK:
3104  rz_socket_read_block(c, buf, 9);
3105  x = rz_read_at_be64(buf, 1);
3106  if (buf[0] == 2) {
3107  if (core->file) {
3108  x = rz_io_fd_size(core->io, core->file->fd);
3109  } else {
3110  x = 0;
3111  }
3112  } else {
3113  if (buf[0] == 0) {
3114  rz_core_seek(core, x, true); // buf[0]);
3115  }
3116  x = core->offset;
3117  }
3119  rz_write_be64(buf + 1, x);
3120  rz_socket_write(c, buf, 9);
3121  rz_socket_flush(c);
3122  break;
3123  case RAP_PACKET_CLOSE:
3124  // XXX : proper shutdown
3125  rz_socket_read_block(c, buf, 4);
3126  i = rz_read_be32(buf);
3127  {
3128  // FIXME: Use rz_socket_close
3129  int ret = close(i);
3130  rz_write_be32(buf + 1, ret);
3132  rz_socket_write(c, buf, 5);
3133  rz_socket_flush(c);
3134  }
3135  break;
3136  default:
3137  if (cmd == 'G') {
3138  // silly http emulation over rap://
3139  char line[256] = { 0 };
3140  rz_socket_read_block(c, (ut8 *)line, sizeof(line));
3141  if (!strncmp(line, "ET /cmd/", 8)) {
3142  char *cmd = line + 8;
3143  char *http = strstr(cmd, "HTTP");
3144  if (http) {
3145  *http = 0;
3146  http--;
3147  if (*http == ' ') {
3148  *http = 0;
3149  }
3150  }
3152  char *res = rz_core_cmd_str(core, cmd);
3153  if (res) {
3154  rz_socket_printf(c, "HTTP/1.0 %d %s\r\n%s"
3155  "Connection: close\r\nContent-Length: %d\r\n\r\n",
3156  200, "OK", "", -1); // strlen (res));
3157  rz_socket_write(c, res, strlen(res));
3158  free(res);
3159  }
3160  rz_socket_flush(c);
3161  rz_socket_close(c);
3162  }
3163  } else {
3164  eprintf("[rap] unknown command 0x%02x\n", cmd);
3165  rz_socket_close(c);
3166  RZ_FREE(ptr);
3167  }
3168  if (rz_config_get_i(core->config, "rap.loop")) {
3169  eprintf("rap: waiting for new connection\n");
3170  rz_socket_free(c);
3171  goto reaccept;
3172  }
3173  goto out_of_function;
3174  }
3175  }
3176  eprintf("client: disconnected\n");
3177  rz_socket_free(c);
3178  }
3179 out_of_function:
3181  return false;
3182 }
3183 
3185  int ret, len = core->blocksize;
3186  ut8 *buf = malloc(len);
3187  if (!buf) {
3188  eprintf("Cannot allocate blocksize\n");
3189  return false;
3190  }
3191  while (from < to) {
3192  ut64 delta = to - from;
3193  if (delta < len) {
3194  len = (int)delta;
3195  }
3196  if (!rz_io_read_at(core->io, from, buf, len)) {
3197  eprintf("Cannot read at 0x%" PFMT64x "\n", from);
3198  break;
3199  }
3200  for (ret = 0; ret < len;) {
3201  int done = cb(core, from, buf + ret, len - ret);
3202  if (done < 1) { /* interrupted */
3203  free(buf);
3204  return false;
3205  }
3206  ret += done;
3207  }
3208  from += len;
3209  }
3210  free(buf);
3211  return true;
3212 }
3213 
3214 RZ_API RZ_OWN char *rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str) {
3215  const bool interactive = rz_cons_is_interactive();
3216  if (!interactive) {
3217  return NULL;
3218  }
3219 
3220  const char *editor = rz_config_get(core->config, "cfg.editor");
3221  if (RZ_STR_ISEMPTY(editor)) {
3222  RZ_LOG_ERROR("Please set \"cfg.editor\" to run the editor");
3223  return NULL;
3224  }
3225  char *name = NULL, *ret = NULL;
3226  int fd;
3227 
3228  bool readonly = false;
3229  if (file && *file != '*') {
3230  name = strdup(file);
3231  fd = rz_sys_open(file, O_RDWR, 0644);
3232  if (fd == -1) {
3233  fd = rz_sys_open(file, O_RDWR | O_CREAT, 0644);
3234  if (fd == -1) {
3235  fd = rz_sys_open(file, O_RDONLY, 0644);
3236  readonly = true;
3237  }
3238  }
3239  } else {
3240  fd = rz_file_mkstemp(file, &name);
3241  }
3242  if (fd == -1) {
3243  free(name);
3244  return NULL;
3245  }
3246  if (readonly) {
3247  eprintf("Opening in read-only\n");
3248  } else {
3249  if (str) {
3250  const size_t str_len = strlen(str);
3251  if (write(fd, str, str_len) != str_len) {
3252  close(fd);
3253  free(name);
3254  return NULL;
3255  }
3256  }
3257  }
3258  close(fd);
3259 
3260  if (name) {
3261  char *escaped_name = rz_str_escape_sh(name);
3262  rz_sys_cmdf("%s \"%s\"", editor, escaped_name);
3263  free(escaped_name);
3264  }
3265  size_t len = 0;
3266  ret = name ? rz_file_slurp(name, &len) : 0;
3267  if (ret) {
3268  if (len && ret[len - 1] == '\n') {
3269  ret[len - 1] = 0; // chop
3270  }
3271  if (!file) {
3272  rz_file_rm(name);
3273  }
3274  }
3275  free(name);
3276  return ret;
3277 }
3278 
3279 /* weak getters */
3281  return core->cons;
3282 }
3283 
3285  return core->config;
3286 }
3287 
3289  return core->bin;
3290 }
3291 
3292 RZ_API RzBuffer *rz_core_syscallf(RzCore *core, const char *name, const char *fmt, ...) {
3293  char str[1024];
3294  RzBuffer *buf;
3295  va_list ap;
3296  va_start(ap, fmt);
3297 
3298  vsnprintf(str, sizeof(str), fmt, ap);
3299  buf = rz_core_syscall(core, name, str);
3300 
3301  va_end(ap);
3302  return buf;
3303 }
3304 
3305 RZ_API RzBuffer *rz_core_syscall(RzCore *core, const char *name, const char *args) {
3306  RzBuffer *b = NULL;
3307  char code[1024];
3308  int num;
3309 
3310  // arch check
3311  if (strcmp(core->analysis->cur->arch, "x86")) {
3312  eprintf("architecture not yet supported!\n");
3313  return 0;
3314  }
3315 
3317 
3318  // bits check
3319  switch (core->rasm->bits) {
3320  case 32:
3321  if (strcmp(name, "setup") && !num) {
3322  eprintf("syscall not found!\n");
3323  return 0;
3324  }
3325  break;
3326  case 64:
3327  if (strcmp(name, "read") && !num) {
3328  eprintf("syscall not found!\n");
3329  return 0;
3330  }
3331  break;
3332  default:
3333  eprintf("syscall not found!\n");
3334  return 0;
3335  }
3336 
3337  snprintf(code, sizeof(code),
3338  "sc@syscall(%d);\n"
3339  "main@global(0) { sc(%s);\n"
3340  ":int3\n"
3341  "}\n",
3342  num, args);
3343  rz_egg_reset(core->egg);
3344  // TODO: setup arch/bits/os?
3345  rz_egg_load(core->egg, code, 0);
3346 
3347  if (!rz_egg_compile(core->egg)) {
3348  eprintf("Cannot compile.\n");
3349  }
3350  if (!rz_egg_assemble(core->egg)) {
3351  eprintf("rz_egg_assemble: invalid assembly\n");
3352  }
3353  if ((b = rz_egg_get_bin(core->egg))) {
3354 #if 0
3355  if (b->length > 0) {
3356  for (i = 0; i < b->length; i++) {
3357  rz_cons_printf ("%02x", b->buf[i]);
3358  }
3359  rz_cons_printf ("\n");
3360  }
3361 #endif
3362  }
3363  return b;
3364 }
3365 
3367  if (!parent || !cmd || type < 0 || type >= RZ_CORE_AUTOCMPLT_END) {
3368  return NULL;
3369  }
3371  if (!autocmpl) {
3372  return NULL;
3373  }
3374  RzCoreAutocomplete **updated = realloc(parent->subcmds, (parent->n_subcmds + 1) * sizeof(RzCoreAutocomplete *));
3375  if (!updated) {
3376  free(autocmpl);
3377  return NULL;
3378  }
3379  parent->subcmds = updated;
3380  parent->subcmds[parent->n_subcmds] = autocmpl;
3381  parent->n_subcmds++;
3382  autocmpl->cmd = strdup(cmd);
3383  autocmpl->locked = lock;
3384  autocmpl->type = type;
3385  autocmpl->length = strlen(cmd);
3386  return autocmpl;
3387 }
3388 
3390  if (!obj) {
3391  return;
3392  }
3393  int i;
3394  for (i = 0; i < obj->n_subcmds; i++) {
3396  obj->subcmds[i] = NULL;
3397  }
3398  free(obj->subcmds);
3399  free((char *)obj->cmd);
3400  free(obj);
3401 }
3402 
3404  if (!parent || !cmd) {
3405  return false;
3406  }
3407  int len = strlen(cmd);
3408  int i;
3409  for (i = 0; i < parent->n_subcmds; i++) {
3410  if (exact && len == parent->subcmds[i]->length && !strncmp(cmd, parent->subcmds[i]->cmd, len)) {
3411  return parent->subcmds[i];
3412  } else if (!exact && !strncmp(cmd, parent->subcmds[i]->cmd, len)) {
3413  return parent->subcmds[i];
3414  }
3415  }
3416  return NULL;
3417 }
3418 
3420  if (!parent || !cmd) {
3421  return false;
3422  }
3423  int i, j;
3424  for (i = 0; i < parent->n_subcmds; i++) {
3425  RzCoreAutocomplete *ac = parent->subcmds[i];
3426  if (ac->locked) {
3427  continue;
3428  }
3429  // if (!strncmp (parent->subcmds[i]->cmd, cmd, parent->subcmds[i]->length)) {
3430  if (rz_str_glob(ac->cmd, cmd)) {
3431  for (j = i + 1; j < parent->n_subcmds; j++) {
3432  parent->subcmds[j - 1] = parent->subcmds[j];
3433  parent->subcmds[j] = NULL;
3434  }
3436  RzCoreAutocomplete **updated = realloc(parent->subcmds, (parent->n_subcmds - 1) * sizeof(RzCoreAutocomplete *));
3437  if (!updated && (parent->n_subcmds - 1) > 0) {
3438  eprintf("Something really bad has happen.. this should never ever happen..\n");
3439  return false;
3440  }
3441  parent->subcmds = updated;
3442  parent->n_subcmds--;
3443  i--;
3444  }
3445  }
3446  return false;
3447 }
3448 
3450  RzTable *table = rz_table_new();
3451  if (table) {
3452  table->cons = core->cons;
3453  }
3454  return table;
3455 }
3456 
3458  PJ *pj = state->d.pj;
3459  switch (state->mode) {
3460  case RZ_OUTPUT_MODE_JSON: {
3461  pj_o(pj);
3462  pj_ks(pj, "name", cp->name);
3463  pj_ks(pj, "description", cp->desc);
3464  pj_ks(pj, "author", cp->author);
3465  pj_ks(pj, "version", cp->version);
3466  pj_ks(pj, "license", license);
3467  pj_end(pj);
3468  break;
3469  }
3470  case RZ_OUTPUT_MODE_STANDARD: {
3471  rz_cons_printf("%s: %s (Made by %s, v%s, %s)\n",
3472  cp->name, cp->desc, cp->author, cp->version, license);
3473  break;
3474  }
3475  default: {
3478  }
3479  }
3480  return RZ_CMD_STATUS_OK;
3481 }
3482 
3484  RzListIter *iter;
3485  RzCorePlugin *cp;
3487  if (!core) {
3488  return RZ_CMD_STATUS_ERROR;
3489  }
3491  rz_list_foreach (core->plugins, iter, cp) {
3492  const char *license = cp->license
3493  ? cp->license
3494  : "???";
3495  status = rz_core_core_plugin_print(cp, state, license);
3496  if (status != RZ_CMD_STATUS_OK) {
3497  return status;
3498  }
3499  }
3501  return RZ_CMD_STATUS_OK;
3502 }
size_t len
Definition: 6502dis.c:15
ut8 op
Definition: 6502dis.c:13
RZ_API void rz_agraph_free(RzAGraph *g)
Definition: agraph.c:3909
RZ_API RzAGraph * rz_agraph_new(RzConsCanvas *can)
Definition: agraph.c:3922
RZ_API RzAnalysisFunction * rz_analysis_get_function_at(RzAnalysis *analysis, ut64 addr)
Definition: function.c:184
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API ut64 rz_analysis_function_linear_size(RzAnalysisFunction *fcn)
Definition: function.c:318
RZ_API ut64 rz_analysis_function_realsize(const RzAnalysisFunction *fcn)
Definition: function.c:338
RZ_API RzAnalysis * rz_analysis_free(RzAnalysis *a)
Definition: analysis.c:137
RZ_API void rz_analysis_bind(RzAnalysis *analysis, RzAnalysisBind *b)
Definition: analysis.c:661
RZ_API RzAnalysis * rz_analysis_new(void)
Definition: analysis.c:63
RZ_API bool rz_analysis_use(RzAnalysis *analysis, const char *name)
Definition: analysis.c:184
RZ_API bool rz_analysis_op_is_eob(RzAnalysisOp *op)
Definition: analysis.c:414
#define e(frag)
#define mask()
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_API void rz_asm_op_fini(RzAsmOp *op)
Definition: aop.c:21
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
lzma_index ** i
Definition: index.h:629
ut16 val
Definition: armass64_const.h:6
static bool err
Definition: armass.c:435
RZ_API void rz_asm_free(RzAsm *a)
Definition: asm.c:315
RZ_API RzAsm * rz_asm_new(void)
Definition: asm.c:262
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
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 int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
RZ_API RzBin * rz_bin_new(void)
Definition: bin.c:716
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API void rz_bin_bind(RzBin *bin, RzBinBind *b)
Definition: bin.c:851
RZ_API void rz_bin_set_user_ptr(RzBin *bin, void *user)
Definition: bin.c:839
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 RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API void rz_bin_free(RzBin *bin)
Definition: bin.c:440
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
static SblHeader sb
Definition: bin_mbn.c:26
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 RzBinReloc * rz_bin_reloc_storage_get_reloc_to(RzBinRelocStorage *storage, ut64 vaddr)
Get a reloc that points exactly to vaddr or NULL.
Definition: bobj.c:173
RZ_API RzBinReloc * rz_bin_reloc_storage_get_reloc_in(RzBinRelocStorage *storage, ut64 vaddr, ut64 size)
Get the reloc with the lowest vaddr that starts inside the given interval.
Definition: bobj.c:154
RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name)
Definition: bp_plugin.c:47
RZ_API char * rz_core_analysis_fcn_name(RzCore *core, RzAnalysisFunction *fcn)
Definition: canalysis.c:2647
RZ_API ut64 rz_core_analysis_address(RzCore *core, ut64 addr)
Definition: canalysis.c:168
RZ_API void rz_core_analysis_type_init(RzCore *core)
Definition: canalysis.c:6610
RZ_API RzConsCanvas * rz_cons_canvas_new(int w, int h)
Definition: canvas.c:223
RZ_API RzLineNSCompletionResult * rz_core_autocomplete_rzshell(RzCore *core, RzLineBuffer *buf, RzLinePromptType prompt_type)
Definition: cautocmpl.c:1048
RZ_API bool rz_core_bin_apply_info(RzCore *r, RzBinFile *binfile, ut32 mask)
Definition: cbin.c:261
RZ_API int rz_core_config_init(RzCore *core)
Definition: cconfig.c:2830
RZ_IPI void rz_core_debug_print_status(RzCore *core)
Definition: cdebug.c:356
RZ_API bool rz_core_is_debug(RzCore *core)
Check whether the core is in debug mode (equivalent to cfg.debug)
Definition: cdebug.c:13
RZ_API RZ_BORROW RzCoreFile * rz_core_file_open(RZ_NONNULL RzCore *r, RZ_NONNULL const char *file, int flags, ut64 loadaddr)
Tries to open the file as is, otherwise tries as is a compilation of files.
Definition: cfile.c:1182
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr)
Definition: cfile.c:942
RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size)
Definition: cio.c:145
RZ_API void rz_core_arch_bits_at(RzCore *core, ut64 addr, RZ_OUT RZ_NULLABLE int *bits, RZ_OUT RZ_BORROW RZ_NULLABLE const char **arch)
Definition: cio.c:97
RZ_API void rz_core_seek_arch_bits(RzCore *core, ut64 addr)
Definition: cio.c:132
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log)
Definition: cmd.c:5328
RZ_API bool rz_core_run_script(RzCore *core, RZ_NONNULL const char *file)
Definition: cmd.c:457
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
RZ_API void rz_core_cmd_init(RzCore *core)
Definition: cmd.c:5562
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
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
RZ_API RzCmd * rz_cmd_free(RzCmd *cmd)
Definition: cmd_api.c:208
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 char ** rz_cmd_alias_keys(RzCmd *cmd, int *sz)
Definition: cmd_api.c:412
static RzCore * _core
Definition: cmd_debug.c:1622
RZ_API RZ_OWN RzList * rz_core_theme_list(RZ_NONNULL RzCore *core)
Returns the list of the rizin themes.
Definition: cmd_eval.c:119
RZ_API void rz_core_gadget_free(RzCoreGadget *g)
Frees a visual print gadget.
Definition: cmd_print.c:1174
RZ_API void rz_core_gadget_print(RzCore *core)
Prints or displays the print gadgets while in visual mode.
Definition: cmd_print.c:1185
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 RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:48
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_config_free(RzConfig *cfg)
Definition: config.c:523
RZ_API void rz_cons_zero(void)
Definition: cons.c:1749
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API int rz_cons_memcat(const char *str, int len)
Definition: cons.c:1224
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_bind(RzConsBind *bind)
Definition: cons.c:1910
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API RzCons * rz_cons_new(void)
Definition: cons.c:589
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void rz_cons_echo(const char *msg)
Definition: cons.c:939
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
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_set_flush(bool flush)
Set whether RzCons should flush content to screen or not.
Definition: cons.c:2006
RZ_API RzCons * rz_cons_free(void)
Definition: cons.c:658
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 bool rz_core_plugin_init(RzCore *core)
Definition: cplugin.c:37
RZ_API bool rz_core_plugin_fini(RzCore *core)
Definition: cplugin.c:12
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
RZ_API ut64 rz_core_reg_getv_by_role_or_name(RzCore *core, const char *name)
rz_reg_getv_by_role_or_name() on rz_core_reg_default()
Definition: creg.c:24
#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 fork write
Definition: sflib.h:33
static static fork const void static count close
Definition: sflib.h:33
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 cmd
Definition: sflib.h:79
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
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 static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define ut8
Definition: dcpu16.h:8
uint32_t ut32
RZ_API const char * rz_line_readline(void)
Definition: dietline.c:913
RZ_API int rz_line_hist_load(RZ_NONNULL const char *path)
Load the history of commands from path.
Definition: dietline.c:474
RZ_API const char * rz_core_get_section_name(RzCore *core, ut64 addr)
Definition: disasm.c:457
RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes)
Definition: disasm.c:6030
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
RZ_API void rz_egg_free(RzEgg *egg)
Definition: egg.c:111
RZ_API RzEgg * rz_egg_new(void)
Definition: egg.c:44
RZ_API int rz_egg_compile(RzEgg *egg)
Definition: egg.c:394
RZ_API RzBuffer * rz_egg_get_bin(RzEgg *egg)
Definition: egg.c:423
RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format)
Definition: egg.c:202
RZ_API bool rz_egg_assemble(RzEgg *egg)
Definition: egg.c:390
RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os)
Definition: egg.c:139
struct tab * done
Definition: enough.c:233
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzAnalysisFunction * rz_analysis_get_function_byname(RzAnalysis *a, const char *name)
Definition: fcn.c:1729
RZ_API void rz_analysis_update_analysis_range(RzAnalysis *analysis, ut64 addr, int size)
Definition: fcn.c:2396
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void rz_flag_bind(RzFlag *f, RzFlagBind *fb)
Definition: flag.c:752
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
RZ_API RzFlag * rz_flag_free(RzFlag *f)
Definition: flag.c:271
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
Definition: flag.c:804
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API char * rz_flag_get_liststr(RzFlag *f, ut64 off)
Definition: flag.c:480
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 RzFlagItem * rz_flag_get_by_spaces(RzFlag *f, ut64 off,...)
Definition: flag.c:326
RZ_API RzFlag * rz_flag_new(void)
Definition: flag.c:220
RZ_API void rz_core_cmpwatch_free(RzCoreCmpWatcher *w)
Definition: cmp.c:300
RZ_API void rz_hash_free(RzHash *rh)
Definition: hash.c:597
RZ_API RzHash * rz_hash_new(void)
Definition: hash.c:585
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
RZ_API int rz_cons_fgets(char *buf, int len, int argc, const char **argv)
Definition: input.c:339
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
vsnprintf
Definition: kernel.h:366
RZ_API const char * rz_analysis_function_get_label_at(RzAnalysisFunction *fcn, ut64 addr)
Definition: labels.c:15
RZ_API ut64 rz_analysis_function_get_label(RzAnalysisFunction *fcn, const char *name)
Definition: labels.c:9
#define reg(n)
RZ_API void rz_lang_free(RzLang *lang)
Definition: lang.c:46
RZ_API RzLang * rz_lang_new(void)
Definition: lang.c:20
RZ_API void rz_lang_set_user_ptr(RzLang *lang, void *user)
Definition: lang.c:61
RZ_API bool rz_lang_define(RzLang *lang, const char *type, const char *name, void *value)
Definition: lang.c:65
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
void * p
Definition: libc.cpp:67
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define basename
Definition: libiberty.h:109
#define MINLEN
Definition: core.c:1774
RZ_API RzAnalysisOp * rz_core_op_analysis(RzCore *core, ut64 addr, RzAnalysisOpMask mask)
Definition: core.c:2880
static const char * cfgget(RzCore *core, const char *k)
Definition: core.c:349
RZ_API int rz_core_prompt(RzCore *r, int sync)
Definition: core.c:2805
RZ_API RzCmdStatus rz_core_core_plugin_print(RzCorePlugin *cp, RzCmdStateOutput *state, const char *license)
Definition: core.c:3457
static char * getvalue(ut64 value, int bits)
Definition: core.c:1820
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
static void autocomplete_flags(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1253
static ut64 numget(RzCore *core, const char *k)
Definition: core.c:361
static RzFlagItem * core_flg_class_set(RzFlag *f, const char *name, ut64 addr, ut32 size)
Definition: core.c:2253
RZ_API RzTable * rz_core_table(RzCore *core)
Definition: core.c:3449
static ut64 getref(RzCore *core, int n, char t, int type)
Definition: core.c:400
RZ_API RzBinReloc * rz_core_getreloc(RzCore *core, ut64 addr, int size)
Definition: core.c:178
static const char * str_callback(RzNum *user, ut64 off, int *ok)
Definition: core.c:484
static void set_prompt(RzCore *r)
Definition: core.c:2770
RZ_IPI RzIOPlugin rz_core_io_plugin_vfile
IO Plugin that opens RzBinVirtualFiles supplied by the plugin of an RzBinFile.
Definition: cvfile.c:134
static void autocomplete_theme(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1394
RZ_IPI void rz_core_file_io_desc_closed(RzCore *core, RzIODesc *desc)
Definition: cfile.c:1271
static const char * rizin_argv[]
Definition: core.c:877
RZ_API ut64 rz_core_get_asmqjmps(RzCore *core, const char *str)
Definition: core.c:203
static int on_fcn_new(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
Definition: core.c:108
static ut64 bbSize(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:473
static ut64 letter_divs[RZ_CORE_ASMQJMPS_LEN_LETTERS - 1]
Definition: core.c:18
static void ev_iomapdel_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2364
RZ_API void rz_core_autocomplete_reload(RzCore *core)
Definition: core.c:2274
static ut64 bbJump(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:451
RZ_API const char * rz_core_analysis_optype_colorfor(RzCore *core, ut64 addr, bool verbose)
Definition: core.c:2108
static void autocomplete_process_path(RzLineCompletion *completion, const char *str, const char *path)
Definition: core.c:1052
static void autocomplete_file(RzLineCompletion *completion, const char *str)
Definition: core.c:1380
RZ_API int rz_core_bind(RzCore *core, RzCoreBind *bnd)
Definition: core.c:369
static int __disasm(void *_core, ut64 addr)
Definition: core.c:1732
#define rizin_argc
Definition: core.c:875
RZ_LIB_VERSION(rz_core)
RZ_API int rz_core_search_cb(RzCore *core, ut64 from, ut64 to, RzCoreSearchCallback cb)
Definition: core.c:3184
static bool rz_core_analysis_read_at(struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len)
Definition: core.c:2148
RZ_API void rz_core_autocomplete_free(RzCoreAutocomplete *obj)
Definition: core.c:3389
static void autocomplete_default(RZ_NULLABLE RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1181
static bool exists_var(RzPrint *print, ut64 func_addr, char *str)
Definition: core.c:2139
RZ_API void rz_core_notify_begin(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the beginning of a task.
Definition: core.c:33
bool rz_core_is_project(RzCore *core, const char *name)
static bool cfgseti(RzCore *core, const char *k, ut64 v)
Definition: core.c:353
static void setab(RzCore *core, const char *arch, int bits)
Definition: core.c:305
static const char * getName(RzCore *core, ut64 addr)
Definition: core.c:314
RZ_API RzCoreAutocomplete * rz_core_autocomplete_find(RzCoreAutocomplete *parent, const char *cmd, bool exact)
Definition: core.c:3403
RZ_API void rz_core_prompt_loop(RzCore *r)
Definition: core.c:2688
static void bp_maps_sync(void *user)
Definition: core.c:2328
RZ_API void rz_core_bind_cons(RzCore *core)
Definition: core.c:2612
RZ_IPI void rz_core_task_ctx_switch(RzCoreTask *next, void *user)
Definition: task.c:727
RZ_API RzBuffer * rz_core_syscall(RzCore *core, const char *name, const char *args)
Definition: core.c:3305
RZ_API void rz_core_fini(RzCore *c)
Definition: core.c:2623
static ut64 bbInstructions(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:429
RZ_API RzCore * rz_core_ncast(ut64 p)
Definition: core.c:392
static RzLineNSCompletionResult * rzshell_autocomplete(RzLineBuffer *buf, RzLinePromptType prompt_type, void *user)
Definition: core.c:1690
static char * get_comments_cb(void *user, ut64 addr)
Definition: core.c:2249
static void rap_break(void *u)
Definition: core.c:2894
RZ_API void rz_core_autocomplete(RZ_NULLABLE RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf, RzLinePromptType prompt_type)
Definition: core.c:1550
static ut64 cfggeti(RzCore *core, const char *k)
Definition: core.c:345
static int bp_bits_at(ut64 addr, void *user)
Definition: core.c:2335
static ut64 bbBegin(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:440
static void autocomplete_minus(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1216
RZ_API RzCmdStatus rz_core_core_plugins_print(RzCore *core, RzCmdStateOutput *state)
Definition: core.c:3483
static void __init_autocomplete_default(RzCore *core)
Definition: core.c:2177
RZ_API RzBuffer * rz_core_syscallf(RzCore *core, const char *name, const char *fmt,...)
Definition: core.c:3292
static void update_sdb(RzCore *core)
Definition: core.c:1743
static bool prompt_add_section(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2718
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
static const RzList * __flagsGet(RzCore *core, ut64 offset)
Definition: core.c:365
RZ_API RzCoreAutocomplete * rz_core_autocomplete_add(RzCoreAutocomplete *parent, const char *cmd, int type, bool lock)
Definition: core.c:3366
static void autocomplete_functions(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1349
static int on_fcn_rename(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn, const char *oname)
Definition: core.c:134
RZ_API char * rz_core_analysis_get_comments(RzCore *core, ut64 addr)
Definition: core.c:2091
RZ_API void rz_core_free(RzCore *c)
Definition: core.c:2683
RZ_IPI void rz_core_vfile_bin_file_deleted(RzCore *core, RzBinFile *bf)
Definition: cvfile.c:156
RZ_API void rz_core_notify_done(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the end of a task which succeeded.
Definition: core.c:60
static void autocomplete_flagspaces(RzCore *core, RzLineCompletion *completion, const char *msg)
Definition: core.c:1332
static ut64 num_callback(RzNum *userptr, const char *str, int *ok)
Definition: core.c:501
static void ev_binfiledel_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2369
RZ_API int rz_core_fgets(char *buf, int len, void *user)
Definition: core.c:1694
static bool cfgset(RzCore *core, const char *k, const char *v)
Definition: core.c:357
static void autocompleteFilename(RzLineCompletion *completion, RzLineBuffer *buf, char **extra_paths, int narg)
Definition: core.c:1133
static const char * get_section_name(void *user, ut64 addr)
Definition: core.c:2245
static int rz_core_print_offsize(void *p, ut64 addr)
Definition: core.c:1723
static void * rz_core_sleep_begin(RzCore *core)
Definition: core.c:2155
RZ_API bool rz_core_autocomplete_remove(RzCoreAutocomplete *parent, const char *cmd)
Definition: core.c:3419
RZ_API void rz_core_notify_error(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the end of a task which errored.
Definition: core.c:87
static void rz_core_debug_breakpoint_hit(RzCore *core, RzBreakpointItem *bpi)
Definition: core.c:148
static bool prompt_add_offset(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2733
RZ_IPI void rz_core_file_io_map_deleted(RzCore *core, RzIOMap *map)
Definition: cfile.c:1280
static void ev_iowrite_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2342
#define DB
Definition: core.c:14
static const char * colorfor_cb(void *user, ut64 addr, bool verbose)
Definition: core.c:2237
static int on_fcn_delete(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
Definition: core.c:121
static void autocomplete_evals(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1200
RZ_API bool rz_core_init(RzCore *core)
Definition: core.c:2381
static int mywrite(const ut8 *buf, int len)
Definition: core.c:2135
RZ_IPI void rz_core_file_bin_file_deleted(RzCore *core, RzBinFile *bf)
Definition: cfile.c:1290
RZ_API char * rz_core_op_str(RzCore *core, ut64 addr)
Definition: core.c:2869
RZ_API RzCons * rz_core_get_cons(RzCore *core)
Definition: core.c:3280
static RzFlagItem * core_flg_fcn_set(RzFlag *f, const char *name, ut64 addr, ut32 size)
Definition: core.c:2267
static bool find_e_opts(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1408
RZ_API RzCore * rz_core_cast(void *p)
Definition: core.c:396
RZ_API void rz_core_set_asmqjmps(RzCore *core, char *str, size_t len, int pos)
Definition: core.c:282
static void rz_core_break(RzCore *core)
Definition: core.c:2152
RZ_API void __cons_cb_fkey(RzCore *core, int fkey)
Definition: core.c:2601
RZ_API RzBin * rz_core_get_bin(RzCore *core)
Definition: core.c:3288
static void __init_autocomplete(RzCore *core)
Definition: core.c:2230
RZ_API RzConfig * rz_core_get_config(RzCore *core)
Definition: core.c:3284
RZ_API char * rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode)
Definition: core.c:1805
static const char * rz_core_print_offname(void *p, ut64 addr)
Definition: core.c:1717
RZ_API char * rz_core_add_asmqjmp(RzCore *core, ut64 addr)
Definition: core.c:238
static int is_string(const ut8 *buf, int size, int *len)
Definition: core.c:1775
static void ev_iodescclose_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2359
static void archbits(RzCore *core, ut64 addr)
Definition: core.c:341
#define ADDARG(x)
Definition: core.c:1176
static void autocomplete_macro(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1363
static ut64 bbFail(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:462
static bool find_autocomplete(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1456
RZ_IPI void rz_core_task_break_cb(RzCoreTask *task, void *user)
Definition: task.c:738
RZ_API RzCore * rz_core_new(void)
Definition: core.c:866
static bool add_argv(RzFlagItem *fi, void *user)
Definition: core.c:1247
static void __foreach(RzCore *core, const char **cmds, int type)
Definition: core.c:2170
RZ_API RzBinReloc * rz_core_get_reloc_to(RzCore *core, ut64 addr)
Definition: core.c:189
RZ_API char * rz_core_analysis_hasrefs_to_depth(RzCore *core, ut64 value, PJ *pj, int depth)
Definition: core.c:1853
static char * getNameDelta(RzCore *core, ut64 addr)
Definition: core.c:327
static bool bp_is_mapped(ut64 addr, int perm, void *user)
Definition: core.c:2307
static char * hasrefs_cb(void *user, ut64 addr, int mode)
Definition: core.c:2241
static void rz_core_sleep_end(RzCore *core, void *user)
Definition: core.c:2163
static RzFlagItem * core_flg_class_get(RzFlag *f, const char *name)
Definition: core.c:2260
RZ_IPI void rz_core_file_free(RzCoreFile *cf)
Definition: cfile.c:26
RZ_API int rz_core_prompt_exec(RzCore *r)
Definition: core.c:2830
static bool prompt_add_file(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2707
RZ_API bool rz_core_serve(RzCore *core, RzIODesc *file)
Definition: core.c:2904
static void rz_core_debug_syscall_hit(RzCore *core)
Definition: core.c:169
static void autocomplete_breakpoints(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1232
static void autocomplete_sdb(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1260
RZ_API RZ_OWN RzDebug * rz_debug_new(RZ_BORROW RZ_NONNULL RzBreakpointContext *bp_ctx)
Definition: debug.c:359
RZ_API RzDebug * rz_debug_free(RzDebug *dbg)
Definition: debug.c:416
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
Definition: debug.c:1682
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API char * sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd)
Definition: query.c:164
RZ_API void rz_core_loadlibs_init(RzCore *core)
Definition: libs.c:89
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API void rz_line_set_prompt(const char *prompt)
Definition: line.c:56
RZ_API void rz_line_completion_push(RzLineCompletion *completion, const char *str)
Definition: line.c:79
RZ_API void rz_line_completion_set(RzLineCompletion *completion, int argc, const char **argv)
Definition: line.c:95
RZ_API void rz_line_completion_clear(RzLineCompletion *completion)
Definition: line.c:109
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 static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
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 static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname pipe
Definition: sflib.h:73
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
@ ok
Definition: lz4.c:1706
char * dst
Definition: lz4.h:724
RZ_API const char * rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr)
Definition: meta.c:146
int args
Definition: mipsasm.c:18
int x
Definition: mipsasm.c:20
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
line
Definition: setup.py:34
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
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
static struct @218 keys[]
int off
Definition: pal.c:13
RZ_API char * rz_cons_rainbow_get(int idx, int last, bool bg)
Definition: pal.c:673
RZ_API void rz_parse_set_user_ptr(RzParse *p, void *user)
Definition: parse.c:175
RZ_API void rz_parse_free(RzParse *p)
Definition: parse.c:40
RZ_API RzParse * rz_parse_new(void)
Definition: parse.c:16
RZ_API RzPrint * rz_print_new(void)
Definition: print.c:56
RZ_API RzPrint * rz_print_free(RzPrint *p)
Definition: print.c:101
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
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API bool rz_core_rtr_init(RZ_NONNULL RzCore *core)
Allocates core rtr structure.
Definition: rtr.c:1020
static RzSocket * s
Definition: rtr.c:28
RZ_API void rz_core_wait(RzCore *core)
Definition: rtr.c:52
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
#define RZ_ANALYSIS_ADDR_TYPE_STACK
Definition: rz_analysis.h:91
#define RZ_ANALYSIS_ADDR_TYPE_SEQUENCE
Definition: rz_analysis.h:96
#define RZ_ANALYSIS_ADDR_TYPE_ASCII
Definition: rz_analysis.h:95
#define RZ_ANALYSIS_ADDR_TYPE_EXEC
Definition: rz_analysis.h:85
@ RZ_ANALYSIS_XREF_TYPE_CODE
Definition: rz_analysis.h:900
@ RZ_ANALYSIS_XREF_TYPE_CALL
Definition: rz_analysis.h:901
@ RZ_ANALYSIS_XREF_TYPE_DATA
Definition: rz_analysis.h:902
#define RZ_ANALYSIS_ADDR_TYPE_HEAP
Definition: rz_analysis.h:90
#define RZ_ANALYSIS_ADDR_TYPE_LIBRARY
Definition: rz_analysis.h:94
@ RZ_META_TYPE_VARTYPE
Definition: rz_analysis.h:297
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295
#define RZ_ANALYSIS_ADDR_TYPE_WRITE
Definition: rz_analysis.h:87
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
@ RZ_ANALYSIS_VAR_KIND_BPV
Definition: rz_analysis.h:704
#define RZ_ANALYSIS_ADDR_TYPE_READ
Definition: rz_analysis.h:86
#define RZ_ANALYSIS_ADDR_TYPE_PROGRAM
Definition: rz_analysis.h:93
#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
const char *(* RzCoreGetName)(void *core, ut64 off)
Definition: rz_bind.h:19
ut64(* RzCoreNumGet)(void *core, const char *str)
Definition: rz_bind.h:26
ut64(* RzCoreConfigGetI)(void *core, const char *key)
Definition: rz_bind.h:22
char *(* RzCoreGetNameDelta)(void *core, ut64 off)
Definition: rz_bind.h:20
char *(* RzCoreCmdStr)(void *core, const char *cmd)
Definition: rz_bind.h:15
void(* RzCorePuts)(const char *cmd)
Definition: rz_bind.h:17
int(* RzCoreCmd)(void *core, const char *cmd)
Definition: rz_bind.h:11
bool(* RzCoreConfigSet)(void *core, const char *key, const char *value)
Definition: rz_bind.h:24
bool(* RzCoreBinApplyInfo)(void *core, void *binfile, ut32 mask)
Definition: rz_bind.h:28
char *(* RzCoreCmdStrF)(void *core, const char *cmd,...)
Definition: rz_bind.h:16
void(* RzCoreSetArchBits)(void *core, const char *arch, int bits)
Definition: rz_bind.h:18
void(* RzCoreSeekArchBits)(void *core, ut64 addr)
Definition: rz_bind.h:21
bool(* RzCoreConfigSetI)(void *core, const char *key, ut64 value)
Definition: rz_bind.h:25
const char *(* RzCoreConfigGet)(void *core, const char *key)
Definition: rz_bind.h:23
void(* RzCoreDebugSyscallHit)(void *core)
Definition: rz_bind.h:14
int(* RzCoreCmdF)(void *user, const char *fmt,...)
Definition: rz_bind.h:12
const RzList *(* RzCoreFlagsGet)(void *core, ut64 offset)
Definition: rz_bind.h:27
int(* RzCoreDebugBpHit)(void *core, void *bp)
Definition: rz_bind.h:13
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
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
void(* RzConsQueueTaskOneshot)(void *core, void *task, void *user)
Definition: rz_cons.h:438
#define Color_RESET
Definition: rz_cons.h:617
#define RZ_CONS_CMD_DEPTH
Definition: rz_cons.h:55
void(* RzConsFunctionKey)(void *core, int fkey)
Definition: rz_cons.h:439
#define Color_GREEN
Definition: rz_cons.h:627
#define Color_RED
Definition: rz_cons.h:623
RzLinePromptType
Definition: rz_cons.h:1037
@ RZ_LINE_PROMPT_OFFSET
Definition: rz_cons.h:1038
@ RZ_LINE_PROMPT_FILE
Definition: rz_cons.h:1039
void *(* RzConsSleepBeginCallback)(void *core)
Definition: rz_cons.h:436
#define Color_YELLOW
Definition: rz_cons.h:631
void(* RzConsSleepEndCallback)(void *core, void *user)
Definition: rz_cons.h:437
char *(* RzLineEditorCb)(void *core, const char *str)
Definition: rz_cons.h:1084
char *(* RzConsEditorCallback)(void *core, const char *file, const char *str)
Definition: rz_cons.h:433
void(* RzConsBreakCallback)(void *core)
Definition: rz_cons.h:435
#define RZ_FLAGS_FS_IMPORTS
Definition: rz_core.h:59
#define RZ_CORE_BLOCKSIZE_MAX
Definition: rz_core.h:47
#define RZ_CORE_ASMQJMPS_MAX_LETTERS
Definition: rz_core.h:185
#define RZ_FLAGS_FS_SYMBOLS_SECTIONS
Definition: rz_core.h:68
#define RZ_CORE_BLOCKSIZE
Definition: rz_core.h:46
#define RZ_CORE_ASMQJMPS_NUM
Definition: rz_core.h:183
@ RZ_CORE_AUTOCMPLT_FCN
Definition: rz_core.h:193
@ RZ_CORE_AUTOCMPLT_BRKP
Definition: rz_core.h:196
@ RZ_CORE_AUTOCMPLT_END
Definition: rz_core.h:204
@ RZ_CORE_AUTOCMPLT_OPTN
Definition: rz_core.h:200
@ RZ_CORE_AUTOCMPLT_MACR
Definition: rz_core.h:197
@ RZ_CORE_AUTOCMPLT_DFLT
Definition: rz_core.h:189
@ RZ_CORE_AUTOCMPLT_EVAL
Definition: rz_core.h:194
@ RZ_CORE_AUTOCMPLT_FILE
Definition: rz_core.h:198
@ RZ_CORE_AUTOCMPLT_SDB
Definition: rz_core.h:202
@ RZ_CORE_AUTOCMPLT_FLAG
Definition: rz_core.h:190
@ RZ_CORE_AUTOCMPLT_MINS
Definition: rz_core.h:195
@ RZ_CORE_AUTOCMPLT_THME
Definition: rz_core.h:199
@ RZ_CORE_AUTOCMPLT_FLSP
Definition: rz_core.h:191
@ RZ_CORE_AUTOCMPLT_SEEK
Definition: rz_core.h:192
#define RZ_CORE_CMD_EXIT
Definition: rz_core.h:44
#define RZ_CORE_ASMQJMPS_LETTERS
Definition: rz_core.h:184
#define RZ_FLAGS_FS_STRINGS
Definition: rz_core.h:66
int(* RzCoreSearchCallback)(RzCore *core, ut64 from, ut8 *buf, int len)
Definition: rz_core.h:419
#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
@ AUTOCOMPLETE_DEFAULT
Definition: rz_core.h:136
#define RZ_FLAGS_FS_SEGMENTS
Definition: rz_core.h:64
struct rz_core_task_t RzCoreTask
Definition: rz_core.h:254
#define RZ_FLAGS_FS_SIGNS
Definition: rz_core.h:65
#define RZ_CORE_ASMQJMPS_LEN_LETTERS
Definition: rz_core.h:186
#define RZ_FLAGS_FS_RESOURCES
Definition: rz_core.h:62
#define RZ_FLAGS_FS_FUNCTIONS
Definition: rz_core.h:58
static ut64 rz_read_ble64(const void *src, bool big_endian)
Definition: rz_endian.h:501
static ut8 rz_read_ble8(const void *src)
Definition: rz_endian.h:12
static void rz_write_be64(void *dest, ut64 val)
Definition: rz_endian.h:119
static ut64 rz_read_at_be64(const void *src, size_t offset)
Definition: rz_endian.h:114
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
static ut32 rz_read_at_be32(const void *src, size_t offset)
Definition: rz_endian.h:93
static ut32 rz_read_be32(const void *src)
Definition: rz_endian.h:87
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98
RZ_API void rz_event_free(RzEvent *ev)
Definition: event.c:37
@ RZ_EVENT_IO_DESC_CLOSE
Definition: rz_event.h:43
@ RZ_EVENT_IO_MAP_DEL
Definition: rz_event.h:44
@ RZ_EVENT_BIN_FILE_DEL
Definition: rz_event.h:45
@ RZ_EVENT_IO_WRITE
Definition: rz_event.h:42
RZ_API RzEvent * rz_event_new(void *user)
Definition: event.c:17
RZ_API RzEventCallbackHandle rz_event_hook(RzEvent *ev, int type, RzEventCallback cb, void *user)
Definition: event.c:58
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
RZ_API bool rz_file_is_directory(const char *str)
Definition: file.c:167
RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname)
Definition: file.c:1058
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
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
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API void rz_io_free(RzIO *io)
Definition: io.c:126
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd)
Definition: io.c:550
RZ_API bool rz_io_map_is_mapped(RzIO *io, ut64 addr)
Definition: io_map.c:181
RZ_API int rz_io_fd_get_current(RzIO *io)
Definition: io_fd.c:135
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 RzIO * rz_io_new(void)
Definition: io.c:110
RZ_API bool rz_io_plugin_add(RzIO *io, RZ_BORROW RzIOPlugin *plugin)
Definition: io_plugin.c:12
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
RZ_API void rz_lib_free(RzLib *lib)
Definition: lib.c:189
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
Definition: unum.c:775
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
Definition: unum.c:75
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API const char * rz_num_calc_index(RzNum *num, const char *p)
Definition: calc.c:288
RZ_API void rz_num_free(RzNum *num)
Definition: unum.c:87
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 RZ_OWN char * rz_path_home_history(void)
Return the path for the command history file.
Definition: path.c:212
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 char * pj_drain(PJ *j)
Definition: pj.c:50
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 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_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
#define RZ_PRINT_FLAGS_COLOR
Definition: rz_print.h:15
RZ_API RzRegex * rz_regex_new(const char *pattern, const char *cflags)
Definition: regcomp.c:183
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
Definition: regexec.c:149
RZ_API void rz_regex_free(RzRegex *)
Definition: regcomp.c:249
@ RZ_SEARCH_KEYWORD
Definition: rz_search.h:17
RZ_API int rz_socket_close(RzSocket *s)
Definition: socket.c:419
RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len)
Definition: socket.c:808
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
Definition: socket.c:582
RZ_API int rz_socket_flush(RzSocket *s)
Definition: socket.c:677
RZ_API void rz_socket_printf(RzSocket *s, const char *fmt,...) RZ_PRINTF_CHECK(2
@ RAP_PACKET_MAX
Definition: rz_socket.h:179
@ RAP_PACKET_READ
Definition: rz_socket.h:172
@ RAP_PACKET_SEEK
Definition: rz_socket.h:174
@ RAP_PACKET_OPEN
Definition: rz_socket.h:171
@ RAP_PACKET_CMD
Definition: rz_socket.h:177
@ RAP_PACKET_REPLY
Definition: rz_socket.h:178
@ RAP_PACKET_CLOSE
Definition: rz_socket.h:175
@ RAP_PACKET_WRITE
Definition: rz_socket.h:173
RZ_API int rz_socket_free(RzSocket *s)
Definition: socket.c:453
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
Definition: socket.c:724
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
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 const char * rz_str_trim_head_wp(const char *str)
Definition: str_trim.c:95
RZ_API char * rz_str_ichr(char *str, char chr)
Definition: str.c:660
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
Definition: str.c:923
RZ_API char * rz_str_home(const char *str)
Definition: str.c:354
RZ_API bool rz_str_glob(const char *str, const char *glob)
Definition: str.c:2368
RZ_API const char * rz_str_last(const char *in, const char *ch)
Definition: str.c:3565
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char RZ_API char * rz_str_appendch(char *x, char y)
Definition: str.c:1105
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
Definition: str.c:139
RZ_API const char * rz_sub_str_rchr(const char *str, int start, int end, char chr)
Definition: str.c:690
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
RZ_API const char * rz_sub_str_lchr(const char *str, int start, int end, char chr)
Definition: str.c:682
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
RZ_API void rz_str_uri_decode(char *buf)
Definition: str.c:2845
RZ_API char * rz_str_escape_sh(const char *buf)
Definition: str.c:1560
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
#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 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 bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
RZ_API int rz_sys_cmdf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_open(const char *path, int perm, int mode)
Definition: sys.c:1740
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216
RZ_API int rz_sys_getpid(void)
Definition: sys.c:1164
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103
#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 ZERO_FILL(x)
Definition: rz_types.h:281
#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 RZ_SYS_BITS
Definition: rz_types.h:520
#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
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_SYS_ARCH
Definition: rz_types.h:519
#define RZ_SYS_OS
Definition: rz_types.h:587
#define RZ_FREE_CUSTOM(x, y)
Definition: rz_types.h:375
#define PFMT64u
Definition: rz_types.h:395
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define RZ_FREE(x)
Definition: rz_types.h:369
#define PFMT64x
Definition: rz_types.h:393
#define RZ_EMPTY
Definition: rz_types_base.h:68
#define RZ_MIN(x, y)
#define st64
Definition: rz_types_base.h:10
#define UT32_MAX
Definition: rz_types_base.h:99
#define UT64_MAX
Definition: rz_types_base.h:86
#define RZ_BETWEEN(x, y, z)
#define st16
Definition: rz_types_base.h:14
#define st32
Definition: rz_types_base.h:12
#define UT16_MAX
#define UT8_ADD_OVFCHK(x, y)
#define RZ_FLAGS
Definition: rz_userconf.h:78
RZ_API int rz_utf8_encode_str(const RzRune *str, ut8 *dst, const int dst_length)
Definition: utf8.c:559
ut32 RzRune
Definition: rz_utf8.h:13
#define islower(c)
Definition: safe-ctype.h:135
#define isupper(c)
Definition: safe-ctype.h:143
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
Definition: sdb.c:47
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API RzSearch * rz_search_new(int mode)
Definition: search.c:19
RZ_API RzSearch * rz_search_free(RzSearch *s)
Definition: search.c:52
RZ_API void rz_core_seek_reset(RzCore *core)
Definition: seek.c:388
RZ_API void rz_core_seek_free(RzCore *core)
Definition: seek.c:398
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
static int
Definition: sfsocketcall.h:114
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define O_CREAT
Definition: sftypes.h:489
int size_t
Definition: sftypes.h:40
#define O_RDONLY
Definition: sftypes.h:486
#define O_RDWR
Definition: sftypes.h:488
#define d(i)
Definition: sha256.c:44
#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
Definition: core.c:2888
RzSocket * client
Definition: core.c:2890
RzSocket * fd
Definition: core.c:2889
bool listener
Definition: core.c:2891
void * cons
Definition: rz_table.h:53
Definition: inftree9.h:24
Definition: gzappend.c:170
Definition: z80asm.h:102
Definition: getopt.h:84
Definition: rz_pj.h:12
int(* on_fcn_delete)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn)
Definition: rz_analysis.h:499
int(* on_fcn_rename)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn, const char *oldname)
Definition: rz_analysis.h:500
int(* on_fcn_new)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn)
Definition: rz_analysis.h:498
RzFlagSet flg_class_set
Definition: rz_analysis.h:576
RzAnalysisCallbacks cb
Definition: rz_analysis.h:607
RzFlagGetAtAddr flag_get
Definition: rz_analysis.h:616
bool(* read_at)(struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len)
Definition: rz_analysis.h:614
RzEvent * ev
Definition: rz_analysis.h:617
RzList * fcns
Definition: rz_analysis.h:565
struct rz_analysis_plugin_t * cur
Definition: rz_analysis.h:586
RzBinBind binb
Definition: rz_analysis.h:579
RzFlagGet flg_class_get
Definition: rz_analysis.h:577
RzSyscall * syscall
Definition: rz_analysis.h:570
RzFlagBind flb
Definition: rz_analysis.h:575
RzIOBind iob
Definition: rz_analysis.h:574
RzTypeDB * typedb
Definition: rz_analysis.h:602
RzFlagSet flg_fcn_set
Definition: rz_analysis.h:578
RzCoreBind coreb
Definition: rz_analysis.h:580
bool need_reload_nodes
Definition: rz_agraph.h:68
RzNum * num
Definition: rz_asm.h:114
int bits
Definition: rz_asm.h:100
RzSyscall * syscall
Definition: rz_asm.h:113
void * core
Definition: rz_asm.h:104
RzBinBind binb
Definition: rz_asm.h:109
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
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
RzBinRelocStorage * relocs
Definition: rz_bin.h:279
char * name
Definition: rz_bin.h:619
PrintfCallback cb_printf
Definition: rz_bin.h:345
RzConsBind consb
Definition: rz_bin.h:348
RzEvent * event
Definition: rz_bin.h:333
RzIOBind iob
Definition: rz_bin.h:347
RZ_DEPRECATE Sdb * sdb
Definition: rz_bin.h:340
Outer context of mappings/etc. in which the RzBreakpoint instance will operate in....
Definition: rz_bp.h:71
void * user
Definition: rz_bp.h:72
char * data
Definition: rz_bp.h:59
Definition: rz_bp.h:78
PrintfCallback cb_printf
Definition: rz_bp.h:88
RzIOBind iob
Definition: rz_bp.h:84
RzList * bps
Definition: rz_bp.h:93
RzList * macros
Definition: rz_cmd.h:148
Represent the output state of a command handler.
Definition: rz_cmd.h:91
RzCmdMacro macro
Definition: rz_cmd.h:482
RzList * options
Definition: rz_config.h:47
RzList * nodes
Definition: rz_config.h:56
RzConsPrintablePalette pal
Definition: rz_cons.h:491
bool is_interactive
Definition: rz_cons.h:485
struct rz_line_t * line
Definition: rz_cons.h:553
const char * teefile
Definition: rz_cons.h:519
RzNum * num
Definition: rz_cons.h:543
RzConsSleepBeginCallback cb_sleep_begin
Definition: rz_cons.h:528
RzConsEvent event_resize
Definition: rz_cons.h:522
void * user_fgets_user
Definition: rz_cons.h:521
void * event_data
Definition: rz_cons.h:523
RzConsSleepEndCallback cb_sleep_end
Definition: rz_cons.h:529
int refcnt
Definition: rz_cons.h:555
RzConsContext * context
Definition: rz_cons.h:502
RzConsBreakCallback cb_break
Definition: rz_cons.h:527
RzConsQueueTaskOneshot cb_task_oneshot
Definition: rz_cons.h:531
void * user
Definition: rz_cons.h:534
RzConsEditorCallback cb_editor
Definition: rz_cons.h:526
RzConsFunctionKey cb_fkey
Definition: rz_cons.h:532
int(* user_fgets)(char *buf, int len, void *user)
Definition: rz_cons.h:520
struct rz_core_autocomplete_t ** subcmds
Definition: rz_core.h:213
const char * cmd
Definition: rz_core.h:208
RzCoreConfigSet cfgSet
Definition: rz_bind.h:45
RzCoreSetArchBits setab
Definition: rz_bind.h:39
RzCoreBinApplyInfo applyBinInfo
Definition: rz_bind.h:49
RzCoreFlagsGet flagsGet
Definition: rz_bind.h:48
RzCoreCmd cmd
Definition: rz_bind.h:32
RzCoreCmdStr cmdstr
Definition: rz_bind.h:34
RzCoreCmdStrF cmdstrf
Definition: rz_bind.h:35
RzCoreConfigSetI cfgSetI
Definition: rz_bind.h:46
RzCoreConfigGet cfgGet
Definition: rz_bind.h:44
RzCoreNumGet numGet
Definition: rz_bind.h:47
void * core
Definition: rz_bind.h:31
RzCoreDebugSyscallHit syshit
Definition: rz_bind.h:38
RzCoreDebugBpHit bphit
Definition: rz_bind.h:37
RzCoreGetNameDelta getNameDelta
Definition: rz_bind.h:41
RzCoreGetName getName
Definition: rz_bind.h:40
RzCorePuts puts
Definition: rz_bind.h:36
RzCoreSeekArchBits archbits
Definition: rz_bind.h:42
RzCoreCmdF cmdf
Definition: rz_bind.h:33
RzCoreConfigGetI cfggeti
Definition: rz_bind.h:43
const char * license
Definition: rz_core.h:126
const char * version
Definition: rz_core.h:128
const char * desc
Definition: rz_core.h:125
const char * author
Definition: rz_core.h:127
const char * name
Definition: rz_core.h:124
bool vmode
Definition: rz_core.h:309
RzBuffer * yank_buf
Definition: rz_core.h:306
RzCons * cons
Definition: rz_core.h:312
char * cmdlog
Definition: rz_core.h:340
RzCoreAutocomplete * autocomplete
Definition: rz_core.h:380
RzCoreVisualMode printidx
Definition: rz_core.h:357
int cmdrepeat
Definition: rz_core.h:341
bool visual_is_inputing
Definition: rz_core.h:353
RzList * files
Definition: rz_core.h:315
RzSearch * search
Definition: rz_core.h:331
RzEgg * egg
Definition: rz_core.h:332
RzCmd * rcmd
Definition: rz_core.h:319
char * cmdqueue
Definition: rz_core.h:336
RzBin * bin
Definition: rz_core.h:298
ut64 offset
Definition: rz_core.h:301
RzAsm * rasm
Definition: rz_core.h:323
char * lastcmd
Definition: rz_core.h:337
RzLang * lang
Definition: rz_core.h:328
int max_cmd_depth
Definition: rz_core.h:363
ut32 blocksize_max
Definition: rz_core.h:304
RzAnalysis * analysis
Definition: rz_core.h:322
int rtr_n
Definition: rz_core.h:344
RzDebug * dbg
Definition: rz_core.h:329
RzIO * io
Definition: rz_core.h:313
RzEvent * ev
Definition: rz_core.h:383
RzList * ropchain
Definition: rz_core.h:387
int asmqjmps_size
Definition: rz_core.h:348
int asmqjmps_count
Definition: rz_core.h:347
RzCmdDescriptor root_cmd_descriptor
Definition: rz_core.h:320
RzNum * num
Definition: rz_core.h:316
bool fixedbits
Definition: rz_core.h:375
ut64 * asmqjmps
Definition: rz_core.h:346
RzList * scriptstack
Definition: rz_core.h:361
RzAGraph * graph
Definition: rz_core.h:333
RzList * watchers
Definition: rz_core.h:360
RzList * plugins
List of registered core plugins.
Definition: rz_core.h:299
RzParse * parser
Definition: rz_core.h:326
RzCoreTaskScheduler tasks
Definition: rz_core.h:362
int autocomplete_type
Definition: rz_core.h:381
int incomment
Definition: rz_core.h:366
ut64 prompt_offset
Definition: rz_core.h:302
Sdb * sdb
Definition: rz_core.h:365
char * stkcmd
Definition: rz_core.h:358
ut8 * block
Definition: rz_core.h:305
RzList * gadgets
Definition: rz_core.h:384
RzFlag * flags
Definition: rz_core.h:330
char * cmdfilter
Definition: rz_core.h:371
ut8 switch_file_view
Definition: rz_core.h:364
char * curtheme
Definition: rz_core.h:372
bool fixedarch
Definition: rz_core.h:376
RzPrint * print
Definition: rz_core.h:327
char * cmdremote
Definition: rz_core.h:369
RzHash * hash
Definition: rz_core.h:389
char * lastsearch
Definition: rz_core.h:370
RzCoreFile * file
Definition: rz_core.h:314
ut32 blocksize
Definition: rz_core.h:303
char * visual_inputing
Definition: rz_core.h:354
bool is_asmqjmps_letter
Definition: rz_core.h:349
RzConfig * config
Definition: rz_core.h:300
RzCoreTimes * times
Definition: rz_core.h:325
int http_up
Definition: rz_core.h:355
RzCoreBind corebind
Definition: rz_debug.h:314
PrintfCallback cb_printf
Definition: rz_debug.h:292
RzList * maps
Definition: rz_debug.h:306
RzEvent * ev
Definition: rz_debug.h:302
RzAnalysis * analysis
Definition: rz_debug.h:305
Sdb * sgnls
Definition: rz_debug.h:313
int bits
Definition: rz_debug.h:243
RzIOBind iob
Definition: rz_debug.h:293
RzBreakpoint * bp
Definition: rz_debug.h:288
RzIOMap * map
Definition: rz_io.h:186
ut64 offset
Definition: rz_flag.h:38
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35
bool realnames
Definition: rz_flag.h:49
RzIO * io
Definition: rz_io.h:232
char * name
Definition: rz_io.h:99
int ff
Definition: rz_io.h:64
RzCoreBind corebind
Definition: rz_io.h:92
RzEvent * event
Definition: rz_io.h:90
PrintfCallback cb_printf
Definition: rz_io.h:91
struct rz_io_desc_t * desc
Definition: rz_io.h:60
RzCoreCmdStrCallback cmd_str
Definition: rz_lang.h:23
PrintfCallback cb_printf
Definition: rz_lang.h:22
RzCoreCmdfCallback cmdf
Definition: rz_lang.h:24
RzLineCompletionCb run
Definition: rz_cons.h:1048
void * run_user
Definition: rz_cons.h:1049
char ** data
Definition: rz_cons.h:1012
void * run_user
User data that can be passed to the callback.
Definition: rz_cons.h:1081
RzLineNSCompletionCb run
Callback function that is called when autocompletion is required. (e.g. TAB is pressed)
Definition: rz_cons.h:1080
void * user
Definition: rz_cons.h:1108
RzLineCompletion completion
Definition: rz_cons.h:1089
RzLineHistory history
Definition: rz_cons.h:1092
RzLineEditorCb cb_editor
Definition: rz_cons.h:1097
RzLineNSCompletion ns_completion
Definition: rz_cons.h:1090
RzConsFunctionKey cb_fkey
Definition: rz_cons.h:1099
RzListFree free
Definition: rz_list.h:21
RzNumCalcValue number_value
Definition: rz_num.h:48
RzNumCalcToken curr_tok
Definition: rz_num.h:47
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67
ut64 value
Definition: rz_num.h:63
RzFlagGetAtAddr flag_get
Definition: rz_parse.h:40
RzAnalysisBind analb
Definition: rz_parse.h:39
RzAnalysisLabelAt label_get
Definition: rz_parse.h:41
RzAnalysisVarList varlist
Definition: rz_parse.h:36
RzCons * cons
Definition: rz_print.h:154
RzPrintNameCallback offname
Definition: rz_print.h:147
RzConsBind consbind
Definition: rz_print.h:155
RzPrintSectionGet get_section_name
Definition: rz_print.h:152
int(* write)(const unsigned char *buf, int len)
Definition: rz_print.h:117
PrintfCallback cb_printf
Definition: rz_print.h:118
int(* disasm)(void *p, ut64 addr)
Definition: rz_print.h:122
int big_endian
Definition: rz_print.h:124
RzPrintSizeCallback offsize
Definition: rz_print.h:148
bool(* exists_var)(struct rz_print_t *print, ut64 func_addr, char *str)
Definition: rz_print.h:160
void * user
Definition: rz_print.h:110
PrintfCallback cb_eprintf
Definition: rz_print.h:119
RzPrintHasRefs hasrefs
Definition: rz_print.h:150
int flags
Definition: rz_print.h:137
RzPrintColorFor colorfor
Definition: rz_print.h:149
RzNum * num
Definition: rz_print.h:156
bool use_comments
Definition: rz_print.h:139
RzPrintCommentCallback get_comments
Definition: rz_print.h:151
bool wide_offsets
Definition: rz_print.h:162
char *(* cb_color)(int idx, int last, bool bg)
Definition: rz_print.h:120
RzCoreBind coreb
Definition: rz_print.h:113
bool cur_enabled
Definition: rz_print.h:130
RzIOBind iob
Definition: rz_print.h:111
st64 rm_eo
Definition: rz_regex.h:18
RzIOBind iob
Definition: rz_search.h:73
RzIOBind iob
Definition: rz_type.h:39
Definition: sdb.h:63
Definition: dis.h:43
int pos
Definition: main.c:11
ut8 * buf
Definition: core.c:75
RZ_API RzSyscall * rz_syscall_ref(RzSyscall *sc)
Definition: syscall.c:12
RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str)
Definition: syscall.c:376
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id)
Definition: task.c:96
RZ_API void rz_core_task_scheduler_init(RzCoreTaskScheduler *sched, RzCoreTaskContextSwitch ctx_switch, void *ctx_switch_user, RzCoreTaskBreak break_cb, void *break_cb_user)
Definition: task.c:7
RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler)
Definition: task.c:495
RZ_API void rz_core_task_scheduler_fini(RzCoreTaskScheduler *tasks)
Definition: task.c:27
RZ_API void rz_core_task_enqueue_oneshot(RzCoreTaskScheduler *scheduler, RzCoreTaskOneShot func, void *user)
Definition: task.c:391
RZ_API void rz_core_task_sleep_end(RzCoreTask *task)
Definition: task.c:442
RZ_API void rz_core_task_sleep_begin(RzCoreTask *task)
Definition: task.c:438
RZ_API RzCoreTask * rz_core_task_self(RzCoreTaskScheduler *scheduler)
Definition: task.c:446
static uv_once_t once
Definition: threadpool.c:32
static void lock(volatile int *lk)
Definition: malloc.c:61
Definition: dis.c:32
RZ_API RzList * rz_analysis_var_list(RzAnalysis *a, RzAnalysisFunction *fcn, int kind)
Definition: var.c:1154
RZ_API RZ_BORROW RzAnalysisVar * rz_analysis_function_get_var_byname(RzAnalysisFunction *fcn, const char *name)
Definition: var.c:247
RZ_DEPRECATE RZ_API RzList * rz_analysis_function_get_var_fields(RzAnalysisFunction *fcn, int kind)
Definition: var.c:1166
static char * prompt(const char *str, const char *txt)
Definition: vmenus.c:30
static int option
Definition: vmenus.c:2426
static st64 delta
Definition: vmenus.c:2425
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
RZ_API RzList * rz_analysis_function_get_xrefs_to(RzAnalysisFunction *fcn)
Definition: xrefs.c:302
RZ_API RzList * rz_analysis_function_get_xrefs_from(RzAnalysisFunction *fcn)
Definition: xrefs.c:297
static const z80_opcode fd[]
Definition: z80_tab.h:997
static const char * cb[]
Definition: z80_tab.h:176
static int sp
Definition: z80asm.c:91
static int verbose
Definition: z80asm.c:73
static int addr
Definition: z80asm.c:58
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)