Rizin
unix-like reverse engineering framework and cli tools
cmd_debug.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_debug.h>
6 #include <sdb.h>
7 #define TN_KEY_LEN 32
8 #define TN_KEY_FMT "%" PFMT64u
9 
10 #include "rz_heap_glibc.h"
11 
12 #if HAVE_JEMALLOC
13 #include "rz_heap_jemalloc.h"
14 #include "../linux_heap_jemalloc.c"
15 #endif
16 
17 #include "../core_private.h"
18 
19 #define CMD_CHECK_DEBUG_DEAD(core) \
20  do { \
21  if (rz_debug_is_dead(core->dbg)) { \
22  rz_cons_println("Debugging is not enabled. Run ood?"); \
23  return RZ_CMD_STATUS_ERROR; \
24  } \
25  } while (0)
26 
27 static const char *help_msg_d[] = {
28  "Usage:", "d", " # Debug commands",
29  "db", "[?]", "Breakpoints commands",
30  "dbt", "[?]", "Display backtrace based on dbg.btdepth and dbg.btalgo",
31  "dc", "[?]", "Continue execution",
32  "dd", "[?]", "File descriptors (!fd in r1)",
33  "de", "[-sc] [perm] [rm] [e]", "Debug with ESIL (see de?)",
34  "dg", " <file>", "Generate a core-file (WIP)",
35  "dH", " [handler]", "Transplant process to a new handler",
36  "di", "[?]", "Show debugger backend information (See dh)",
37  "dk", "[?]", "List, send, get, set, signal handlers of child",
38  "dL", "[?]", "List or set debugger handler",
39  "dm", "[?]", "Show memory maps",
40  "do", "[?]", "Open process (reload, alias for 'oo')",
41  "doc", "", "Close debug session",
42  "dp", "[?]", "List, attach to process or thread id",
43  "dr", "[?]", "Cpu registers",
44  "ds", "[?]", "Step, over, source line",
45  "dt", "[?]", "Display instruction traces",
46  "dw", " <pid>", "Block prompt until pid dies",
47 #if __WINDOWS__
48  "dW", "", "List process windows",
49  "dWi", "", "Identify window under cursor",
50 #endif
51  "dx", "[?]", "Inject and run code on target process (See gs)",
52  NULL
53 };
54 
55 static const char *help_msg_dcs[] = {
56  "Usage:", "dcs", " Continue until syscall",
57  "dcs", "", "Continue until next syscall",
58  "dcs [str]", "", "Continue until next call to the 'str' syscall",
59  "dcs", "*", "Trace all syscalls, a la strace",
60  NULL
61 };
62 
63 static const char *help_msg_dcu[] = {
64  "Usage:", "dcu", " Continue until address",
65  "dcu.", "", "Alias for dcu $$ (continue until current address",
66  "dcu", " address", "Continue until address",
67  "dcu", " [..tail]", "Continue until the range",
68  "dcu", " [from] [to]", "Continue until the range",
69  NULL
70 };
71 
72 static const char *help_msg_dd[] = {
73  "Usage: dd", "", "Descriptors commands",
74  "dd", "", "List file descriptors",
75  "dd", " <file>", "Open and map that file into the UI",
76  "dd-", "<fd>", "Close stdout fd",
77  "dd*", "", "List file descriptors (in rizin commands)",
78  "dds", " <fd> <off>", "Seek given fd)",
79  "ddd", " <fd1> <fd2>", "Dup2 from fd1 to fd2",
80  "ddr", " <fd> <size>", "Read N bytes from fd",
81  "ddw", " <fd> <hexpairs>", "Write N bytes to fd",
82  NULL
83 };
84 
85 static const char *help_msg_de[] = {
86  "Usage:", "de", "[-sc] [perm] [rm] [expr]",
87  "de", "", "List esil watchpoints",
88  "de-*", "", "Delete all esil watchpoints",
89  "de", " [perm] [rm] [addr|reg|from..to]", "Stop on condition",
90  "dec", "", "Continue execution until matching expression",
91  "des", "[?] [N]", "Step-in N instructions with esildebug",
92  "desu", " [addr]", "Esildebug until specific address",
93  NULL
94 };
95 
96 static const char *help_msg_des[] = {
97  "Usage:", "des", "[u] [arg]",
98  "des", " [N]", "step-in N instructions with esildebug",
99  "desu", " [addr]", "esildebug until specific address",
100  NULL
101 };
102 
103 static const char *help_msg_di[] = {
104  "Usage: di", "", "Debugger target information",
105  "di", "", "Show debugger target information",
106  "di*", "", "Same as above, but in rizin commands",
107  "diq", "", "Same as above, but in one line",
108  "dij", "", "Same as above, but in JSON format",
109  "dif", " [$a] [$b]", "Compare two files (or $alias files)",
110  NULL
111 };
112 
113 static const char *help_msg_dk[] = {
114  "Usage: dk", "", "Signal commands",
115  "dk", "", "List all signal handlers of child process",
116  "dk", " <signal>", "Send KILL signal to child",
117  "dk", " <signal>=1", "Set signal handler for <signal> in child",
118  "dk?", "<signal>", "Name/signum resolver",
119  "dko", "[?] <signal>", "Reset skip or cont options for given signal",
120  "dko", " <signal> [|skip|cont]", "On signal SKIP handler or CONT into",
121  "dkj", "", "List all signal handlers in JSON",
122  NULL
123 };
124 
125 static const char *help_msg_dko[] = {
126  "Usage:", "dko", " # Signal handling commands",
127  "dko", "", "List existing signal handling",
128  "dko", " [signal]", "Clear handling for a signal",
129  "dko", " [signal] [skip|cont]", "Set handling for a signal",
130  NULL
131 };
132 
133 static const char *help_msg_dmi[] = {
134  "Usage: dmi", "", " # List/Load Symbols",
135  "dmi", "[j|q|*] [libname] [symname]", "List symbols of target lib",
136  "dmia", "[j|q|*] [libname]", "List all info of target lib",
137  "dmi*", "", "List symbols of target lib in rizin commands",
138  "dmi.", "", "List closest symbol to the current address",
139  "dmiv", "", "Show address of given symbol for given lib",
140  NULL
141 };
142 
143 static const char *help_msg_dp[] = {
144  "Usage:", "dp", " # Process commands",
145  "dp", "", "List current pid and children",
146  "dp", " <pid>", "List children of pid",
147  "dpj", " <pid>", "List children of pid in JSON format",
148  "dpl", "", "List all attachable pids",
149  "dplj", "", "List all attachable pids in JSON format",
150  "dp-", " <pid>", "Detach select pid",
151  "dp=", "<pid>", "Select pid",
152  "dpa", " <pid>", "Attach and select pid",
153  "dpc", "", "Select forked pid (see dbg.forks)",
154  "dpc*", "", "Display forked pid (see dbg.forks)",
155  "dpe", "", "Show path to executable",
156  "dpf", "", "Attach to pid like file fd // HACK",
157  "dpk", " <pid> [<signal>]", "Send signal to process (default 0)",
158  "dpn", "", "Create new process (fork)",
159  "dptn", "", "Create new thread (clone)",
160  "dpt", "", "List threads of current pid",
161  "dptj", "", "List threads of current pid in JSON format",
162  "dpt", " <pid>", "List threads of process",
163  "dptj", " <pid>", "List threads of process in JSON format",
164  "dpt=", "<thread>", "Attach to thread",
165  NULL
166 };
167 
168 static const char *help_msg_dx[] = {
169  "Usage: dx", "", " # Code injection commands",
170  "dx", " <opcode>...", "Inject opcodes",
171  "dxa", " nop", "Assemble code and inject",
172  "dxe", " egg-expr", "Compile egg expression and inject it",
173  "dxr", " <opcode>...", "Inject opcodes and restore state",
174  "dxs", " write 1, 0x8048, 12", "Syscall injection (see gs)",
175  "\nExamples:", "", "",
176  "dx", " 9090", "Inject two x86 nop",
177  "\"dxa mov eax,6;mov ebx,0;int 0x80\"", "", "Inject and restore state",
178  NULL
179 };
180 
184 };
185 
186 struct trace_node {
188  int refs;
189 };
190 
191 // XXX those tmp files are never removed and we shuoldnt use files for this
192 static void set_profile_string(RzCore *core, const char *str) {
193  char *file = strdup(rz_config_get(core->config, "dbg.profile"));
194  if (RZ_STR_ISEMPTY(file)) {
195  free(file);
196  file = rz_file_temp("rz-run");
197  rz_config_set(core->config, "dbg.profile", file);
198  }
199  rz_file_dump(file, (const ut8 *)str, (int)strlen(str), 0);
200  rz_file_dump(file, (const ut8 *)"\n", 1, 1);
201  free(file);
202 }
203 
204 static void cmd_debug_cont_syscall(RzCore *core, const char *_str) {
205  // TODO : handle more than one stopping syscall
206  int i, *syscalls = NULL;
207  int count = 0;
208  if (_str && *_str) {
209  char *str = strdup(_str);
211  syscalls = calloc(sizeof(int), count);
212  for (i = 0; i < count; i++) {
213  const char *sysnumstr = rz_str_word_get0(str, i);
214  int sig = (int)rz_num_math(core->num, sysnumstr);
215  if (sig == -1) { // trace ALL syscalls
216  syscalls[i] = -1;
217  } else if (sig == 0) {
218  sig = rz_syscall_get_num(core->analysis->syscall, sysnumstr);
219  if (sig == -1) {
220  eprintf("Unknown syscall number\n");
221  free(str);
222  free(syscalls);
223  return;
224  }
225  syscalls[i] = sig;
226  }
227  }
228  eprintf("Running child until syscalls:");
229  for (i = 0; i < count; i++) {
230  eprintf("%d ", syscalls[i]);
231  }
232  eprintf("\n");
233  free(str);
234  } else {
235  eprintf("Running child until next syscall\n");
236  }
237  rz_reg_arena_swap(core->dbg->reg, true);
238  rz_debug_continue_syscalls(core->dbg, syscalls, count);
239  free(syscalls);
240 }
241 
242 static RzGraphNode *get_graphtrace_node(RzGraph *g, Sdb *nodes, struct trace_node *tn) {
243  RzGraphNode *gn;
244  char tn_key[TN_KEY_LEN];
245 
246  snprintf(tn_key, TN_KEY_LEN, TN_KEY_FMT, tn->addr);
247  gn = (RzGraphNode *)(size_t)sdb_num_get(nodes, tn_key, NULL);
248  if (!gn) {
249  gn = rz_graph_add_node(g, tn);
250  sdb_num_set(nodes, tn_key, (ut64)(size_t)gn, 0);
251  }
252  return gn;
253 }
254 
256  struct dot_trace_ght *data = (struct dot_trace_ght *)vis->data;
257  struct trace_node *tn = n->data;
258  if (tn)
259  get_graphtrace_node(data->graph, data->graphnodes, tn);
260 }
261 
263  struct dot_trace_ght *data = (struct dot_trace_ght *)vis->data;
264  RzGraph *g = data->graph;
265  Sdb *gnodes = data->graphnodes;
266  RTreeNode *parent = n->parent;
267  struct trace_node *tn = n->data;
268  struct trace_node *tn_parent = parent->data;
269 
270  if (tn && tn_parent) {
271  RzGraphNode *gn = get_graphtrace_node(g, gnodes, tn);
272  RzGraphNode *gn_parent = get_graphtrace_node(g, gnodes, tn_parent);
273 
274  if (!rz_graph_adjacent(g, gn_parent, gn))
275  rz_graph_add_edge(g, gn_parent, gn);
276  }
277 }
278 
279 static void dot_trace_traverse(RzCore *core, RTree *t, int fmt) {
280  const char *gfont = rz_config_get(core->config, "graph.font");
281  struct dot_trace_ght aux_data;
282  RTreeVisitor vis = { 0 };
283  const RzList *nodes;
284  RzListIter *iter;
285  RzGraphNode *n;
286 
287  if (fmt == 'i') {
288  rz_core_agraph_reset(core);
289  rz_core_cmd0(core, ".dtg*");
291  return;
292  }
293  aux_data.graph = rz_graph_new();
294  aux_data.graphnodes = sdb_new0();
295 
296  /* build a callgraph from the execution trace */
297  vis.data = &aux_data;
298  vis.pre_visit = (RTreeNodeVisitCb)dot_trace_create_node;
299  vis.discover_child = (RTreeNodeVisitCb)dot_trace_discover_child;
300  rz_tree_bfs(t, &vis);
301 
302  /* traverse the callgraph to print the dot file */
303  nodes = rz_graph_get_nodes(aux_data.graph);
304  if (fmt == 0) {
305  rz_cons_printf("digraph code {\n"
306  "graph [bgcolor=white];\n"
307  " node [color=lightgray, style=filled"
308  " shape=box fontname=\"%s\" fontsize=\"8\"];\n",
309  gfont);
310  }
311  rz_list_foreach (nodes, iter, n) {
312  struct trace_node *tn = (struct trace_node *)n->data;
313  const RzList *neighbours = rz_graph_get_neighbours(aux_data.graph, n);
314  RzListIter *it_n;
315  RzGraphNode *w;
316 
317  if (!fmt && tn) {
318  rz_cons_printf("\"0x%08" PFMT64x "\" [URL=\"0x%08" PFMT64x
319  "\" color=\"lightgray\" label=\"0x%08" PFMT64x
320  " (%d)\"]\n",
321  tn->addr, tn->addr, tn->addr, tn->refs);
322  }
323  rz_list_foreach (neighbours, it_n, w) {
324  struct trace_node *tv = (struct trace_node *)w->data;
325 
326  if (tv && tn) {
327  if (fmt) {
328  rz_cons_printf("agn 0x%08" PFMT64x "\n", tn->addr);
329  rz_cons_printf("agn 0x%08" PFMT64x "\n", tv->addr);
330  rz_cons_printf("age 0x%08" PFMT64x " 0x%08" PFMT64x "\n",
331  tn->addr, tv->addr);
332  } else {
333  rz_cons_printf("\"0x%08" PFMT64x "\" -> \"0x%08" PFMT64x
334  "\" [color=\"red\"];\n",
335  tn->addr, tv->addr);
336  }
337  }
338  }
339  }
340  if (!fmt) {
341  rz_cons_printf("}\n");
342  }
343 
344  rz_graph_free(aux_data.graph);
345  sdb_free(aux_data.graphnodes);
346 }
347 
348 /* TODO: refactor all those step_until* function into a single one
349  * TODO: handle when the process is dead
350  * TODO: handle ^C */
351 
352 static int step_until(RzCore *core, ut64 addr) {
353  ut64 off = rz_debug_reg_get(core->dbg, "PC");
354  if (!off) {
355  eprintf("Cannot 'drn PC'\n");
356  return false;
357  }
358  if (!addr) {
359  eprintf("Cannot continue until address 0\n");
360  return false;
361  }
363  do {
364  if (rz_cons_is_breaked()) {
365  core->break_loop = true;
366  break;
367  }
368  if (rz_debug_is_dead(core->dbg)) {
369  core->break_loop = true;
370  break;
371  }
372  rz_debug_step(core->dbg, 1);
373  off = rz_debug_reg_get(core->dbg, "PC");
374  // check breakpoint here
375  } while (off != addr);
378  return true;
379 }
380 
381 static int step_until_esil(RzCore *core, const char *esilstr) {
382  if (!core || !esilstr || !core->dbg || !core->dbg->analysis || !core->dbg->analysis->esil) {
383  eprintf("Not initialized %p. Run 'aei' first.\n", core->analysis->esil);
384  return false;
385  }
387  for (;;) {
388  if (rz_cons_is_breaked()) {
389  core->break_loop = true;
390  break;
391  }
392  if (rz_debug_is_dead(core->dbg)) {
393  core->break_loop = true;
394  break;
395  }
396  rz_debug_step(core->dbg, 1);
397  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
398  if (rz_analysis_esil_condition(core->analysis->esil, esilstr)) {
399  eprintf("ESIL BREAK!\n");
400  break;
401  }
402  }
405  return true;
406 }
407 
408 static bool is_repeatable_inst(RzCore *core, ut64 addr) {
409  // we have read the bytes already
411  bool ret = op && ((op->prefix & RZ_ANALYSIS_OP_PREFIX_REP) || (op->prefix & RZ_ANALYSIS_OP_PREFIX_REPNE));
413  return ret;
414 }
415 
416 static bool step_until_inst(RzCore *core, const char *instr, bool regex) {
417  rz_return_val_if_fail(core, false);
418  instr = rz_str_trim_head_ro(instr);
419  if (!instr || !core->dbg) {
420  RZ_LOG_ERROR("wrong debugger state\n");
421  return false;
422  }
423  RzAsmOp asmop;
424  ut8 buf[32];
425  ut64 pc;
426  int ret;
427  bool is_x86 = rz_str_startswith(rz_config_get(core->config, "asm.arch"), "x86");
429  for (;;) {
430  if (rz_cons_is_breaked()) {
431  break;
432  }
433  if (rz_debug_is_dead(core->dbg)) {
434  break;
435  }
436  pc = rz_debug_reg_get(core->dbg, "PC");
437  if (is_x86 && is_repeatable_inst(core, pc)) {
438  rz_debug_step_over(core->dbg, 1);
439  } else {
440  rz_debug_step(core->dbg, 1);
441  }
442  pc = rz_debug_reg_get(core->dbg, "PC");
443  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
444  /* TODO: disassemble instruction and strstr */
445  rz_asm_set_pc(core->rasm, pc);
446  // TODO: speedup if instructions are in the same block as the previous
447  rz_io_read_at(core->io, pc, buf, sizeof(buf));
448  ret = rz_asm_disassemble(core->rasm, &asmop, buf, sizeof(buf));
449  eprintf("0x%08" PFMT64x " %d %s\n", pc, ret, rz_asm_op_get_asm(&asmop)); // asmop.buf_asm);
450  if (ret > 0) {
451  const char *buf_asm = rz_asm_op_get_asm(&asmop);
452  if (regex) {
453  if (rz_regex_match(instr, "e", buf_asm)) {
454  eprintf("Stop.\n");
455  break;
456  }
457  } else {
458  if (strstr(buf_asm, instr)) {
459  eprintf("Stop.\n");
460  break;
461  }
462  }
463  }
464  }
467  return true;
468 }
469 
475  ut64 follow = rz_config_get_i(core->config, "dbg.follow");
476  if (follow <= 0) {
477  return;
478  }
479  ut64 pc = rz_debug_reg_get(core->dbg, "PC");
480  if ((pc < core->offset) || (pc > (core->offset + follow))) {
481  rz_core_seek_to_register(core, "PC", false);
482  }
484 }
485 
486 static bool step_until_optype(RzCore *core, RzList *optypes_list) {
488  ut8 buf[32];
489  ut64 pc;
490  int res = true;
491 
492  RzListIter *iter;
493  char *optype;
494 
495  if (!core || !core->dbg) {
496  RZ_LOG_ERROR("wrong state\n");
497  res = false;
498  goto end;
499  }
500  if (!optypes_list) {
501  RZ_LOG_ERROR("missing optypes. Usage example: 'dsuo ucall ujmp'\n");
502  res = false;
503  goto end;
504  }
505 
506  bool debugMode = rz_config_get_b(core->config, "cfg.debug");
507 
509  for (;;) {
510  if (rz_cons_is_breaked()) {
511  core->break_loop = true;
512  break;
513  }
514  if (debugMode) {
515  if (rz_debug_is_dead(core->dbg)) {
516  core->break_loop = true;
517  break;
518  }
519  rz_debug_step(core->dbg, 1);
520  pc = rz_debug_reg_get(core->dbg, core->dbg->reg->name[RZ_REG_NAME_PC]);
521  // 'Copy' from rz_debug_step_soft
522  if (!core->dbg->iob.read_at) {
523  RZ_LOG_ERROR("ERROR\n");
524  res = false;
525  goto cleanup_after_push;
526  }
527  if (!core->dbg->iob.read_at(core->dbg->iob.io, pc, buf, sizeof(buf))) {
528  RZ_LOG_ERROR("ERROR\n");
529  res = false;
530  goto cleanup_after_push;
531  }
532  } else {
533  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
534  pc = rz_reg_getv(core->analysis->reg, "PC");
535  }
536  rz_io_read_at(core->io, pc, buf, sizeof(buf));
537 
538  if (rz_analysis_op(core->dbg->analysis, &op, pc, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC) < 1) {
539  RZ_LOG_ERROR("rz_analysis_op failed\n");
540  res = false;
541  goto cleanup_after_push;
542  }
543 
544  // This is slow because we do lots of strcmp's.
545  // To improve this, the function rz_analysis_optype_string_to_int should be implemented
546  // I also don't check if the opcode type exists.
547  const char *optype_str = rz_analysis_optype_to_string(op.type);
548  rz_list_foreach (optypes_list, iter, optype) {
549  if (!strcmp(optype_str, optype)) {
550  goto cleanup_after_push;
551  }
552  }
553  }
554 
555 cleanup_after_push:
558 end:
559  return res;
560 }
561 
562 static int step_until_flag(RzCore *core, const char *flagstr) {
563  const RzList *list;
564  RzListIter *iter;
565  RzFlagItem *flag;
566  ut64 pc;
567 
568  if (!core || !flagstr || !core->dbg) {
569  RZ_LOG_ERROR("wrong state\n");
570  return false;
571  }
573  for (;;) {
574  if (rz_cons_is_breaked()) {
575  break;
576  }
577  if (rz_debug_is_dead(core->dbg)) {
578  break;
579  }
580  rz_debug_step(core->dbg, 1);
581  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
582  pc = rz_debug_reg_get(core->dbg, "PC");
583  list = rz_flag_get_list(core->flags, pc);
584  rz_list_foreach (list, iter, flag) {
585  if (flag->realname && strstr(flag->realname, flagstr)) {
586  rz_cons_printf("[ 0x%08" PFMT64x " ] %s\n",
587  flag->offset, flag->realname);
588  goto beach;
589  }
590  }
591  }
592 beach:
595  return true;
596 }
597 
598 static bool step_line(RzCore *core, int times) {
599  char file[512], file2[512];
600  int find_meta, line = -1, line2 = -1;
601  char *tmp_ptr = NULL;
602  ut64 off = rz_debug_reg_get(core->dbg, "PC");
603  if (off == 0LL) {
604  RZ_LOG_ERROR("cannot 'drn PC'\n");
605  return false;
606  }
607  file[0] = 0;
608  file2[0] = 0;
609  if (rz_bin_addr2line(core->bin, off, file, sizeof(file), &line)) {
610  char *ptr = rz_file_slurp_line(file, line, 0);
611  RZ_LOG_INFO("--> 0x%08" PFMT64x " %s : %d\n", off, file, line);
612  RZ_LOG_INFO("--> %s\n", ptr);
613  find_meta = false;
614  free(ptr);
615  } else {
616  RZ_LOG_INFO("--> Stepping until dwarf line\n");
617  find_meta = true;
618  }
619  do {
620  rz_debug_step(core->dbg, 1);
621  off = rz_debug_reg_get(core->dbg, "PC");
622  if (!rz_bin_addr2line(core->bin, off, file2, sizeof(file2), &line2)) {
623  if (find_meta) {
624  continue;
625  }
627  RZ_LOG_ERROR("cannot retrieve dwarf info at 0x%08" PFMT64x "\n", off);
628  return false;
629  }
630  } while (!strcmp(file, file2) && line == line2);
631 
632  RZ_LOG_INFO("--> 0x%08" PFMT64x " %s : %d\n", off, file2, line2);
633  tmp_ptr = rz_file_slurp_line(file2, line2, 0);
634  RZ_LOG_INFO("--> %s\n", tmp_ptr);
635  free(tmp_ptr);
637  return true;
638 }
639 
640 static void cmd_debug_pid(RzCore *core, const char *input) {
641  int pid, sig;
642  const char *ptr;
643  switch (input[1]) {
644  case '\0': // "dp"
645  eprintf("Selected: %d %d\n", core->dbg->pid, core->dbg->tid);
646  rz_debug_pid_list(core->dbg, core->dbg->pid, 0);
647  break;
648  case '-': // "dp-"
649  if (input[2] == ' ') {
650  rz_debug_detach(core->dbg, rz_num_math(core->num, input + 2));
651  } else {
652  rz_debug_detach(core->dbg, core->dbg->pid);
653  }
654  break;
655  case 'c': // "dpc"
656  if (core->dbg->forked_pid != -1) {
657  if (input[2] == '*') {
658  eprintf("dp %d\n", core->dbg->forked_pid);
659  } else {
660  rz_debug_select(core->dbg, core->dbg->forked_pid, core->dbg->tid);
661  core->dbg->main_pid = core->dbg->forked_pid;
662  core->dbg->n_threads = 0;
663  core->dbg->forked_pid = -1;
664  }
665  } else {
666  eprintf("No recently forked children\n");
667  }
668  break;
669  case 'k': // "dpk"
670  /* stop, print, pass -- just use flags*/
671  /* XXX: not for threads? signal is for a whole process!! */
672  /* XXX: but we want fine-grained access to process resources */
673  pid = atoi(input + 2);
674  if (pid > 0) {
675  ptr = rz_str_trim_head_ro(input + 2);
676  ptr = strchr(ptr, ' ');
677  sig = ptr ? atoi(ptr + 1) : 0;
678  eprintf("Sending signal '%d' to pid '%d'\n", sig, pid);
679  rz_debug_kill(core->dbg, pid, false, sig);
680  } else
681  eprintf("cmd_debug_pid: Invalid arguments (%s)\n", input);
682  break;
683  case 'n': // "dpn"
684  eprintf("TODO: debug_fork: %d\n", rz_debug_child_fork(core->dbg));
685  break;
686  case 't': // "dpt"
687  switch (input[2]) {
688  case '\0': // "dpt"
689  rz_debug_thread_list(core->dbg, core->dbg->pid, 0);
690  break;
691  case 'j': // "dptj"
692  if (input[3] != ' ') { // "dptj"
693  rz_debug_thread_list(core->dbg, core->dbg->pid, 'j');
694  } else { // "dptj "
695  rz_debug_thread_list(core->dbg, atoi(input + 3), 'j');
696  }
697  break;
698  case ' ': // "dpt "
699  rz_debug_thread_list(core->dbg, atoi(input + 2), 0);
700  break;
701  case '=': // "dpt="
702  rz_debug_select(core->dbg, core->dbg->pid,
703  (int)rz_num_math(core->num, input + 3));
704  break;
705  case 'n': // "dptn"
706  eprintf("TODO: debug_clone: %d\n", rz_debug_child_clone(core->dbg));
707  break;
708  case '?': // "dpt?"
709  default:
711  break;
712  }
713  break;
714  case 'a': // "dpa"
715  if (input[2]) {
716  int pid = rz_num_math(core->num, input + 2);
717  rz_core_debug_attach(core, pid);
718  } else {
719  rz_core_debug_attach(core, 0);
720  }
721  break;
722  case 'f': // "dpf"
723  if (core->file && core->io) {
724  rz_debug_select(core->dbg, rz_io_fd_get_pid(core->io, core->file->fd),
725  rz_io_fd_get_tid(core->io, core->file->fd));
726  }
727  break;
728  case '=': // "dp="
729  rz_debug_select(core->dbg,
730  (int)rz_num_math(core->num, input + 2), core->dbg->tid);
731  core->dbg->main_pid = rz_num_math(core->num, input + 2);
732  break;
733  case 'l': // "dpl"
734  switch (input[2]) {
735  case '\0': // "dpl"
736  rz_debug_pid_list(core->dbg, 0, 0);
737  break;
738  case 'j': // "dplj"
739  rz_debug_pid_list(core->dbg, 0, 'j');
740  break;
741  }
742  break;
743  case 'j': // "dpj"
744  switch (input[2]) {
745  case '\0': // "dpj"
746  rz_debug_pid_list(core->dbg, core->dbg->pid, 'j');
747  break;
748  case ' ': // "dpj "
749  rz_debug_pid_list(core->dbg,
750  (int)RZ_MAX(0, (int)rz_num_math(core->num, input + 2)), 'j');
751  break;
752  }
753  break;
754  case 'e': // "dpe"
755  {
756  int pid = (input[2] == ' ') ? atoi(input + 2) : core->dbg->pid;
757  char *exe = rz_sys_pid_to_path(pid);
758  if (exe) {
759  rz_cons_println(exe);
760  free(exe);
761  }
762  } break;
763  case ' ': // "dp "
764  rz_debug_pid_list(core->dbg,
765  (int)RZ_MAX(0, (int)rz_num_math(core->num, input + 2)), 0);
766  break;
767  case '?': // "dp?"
768  default:
770  break;
771  }
772 }
773 
774 static void cmd_debug_backtrace(RzCore *core, ut64 len) {
776  ut64 addr;
777  if (!len) {
778  rz_bp_traptrace_list(core->dbg->bp);
779  } else {
780  ut64 oaddr = 0LL;
781  eprintf("Trap tracing 0x%08" PFMT64x "-0x%08" PFMT64x "\n",
782  core->offset, core->offset + len);
783  rz_reg_arena_swap(core->dbg->reg, true);
784  rz_bp_traptrace_reset(core->dbg->bp, true);
785  rz_bp_traptrace_add(core->dbg->bp, core->offset, core->offset + len);
786  rz_bp_traptrace_enable(core->dbg->bp, true);
787  do {
788  ut8 buf[32];
789  rz_debug_continue(core->dbg);
790  addr = rz_debug_reg_get(core->dbg, "PC");
791  if (!addr) {
792  eprintf("pc=0\n");
793  break;
794  }
795  if (addr == oaddr) {
796  eprintf("pc=opc\n");
797  break;
798  }
799  oaddr = addr;
800  /* XXX Bottleneck..we need to reuse the bytes read by traptrace */
801  // XXX Do asm.arch should define the max size of opcode?
802  rz_io_read_at(core->io, addr, buf, 32); // XXX longer opcodes?
804  } while (rz_bp_traptrace_at(core->dbg->bp, addr, analop.size));
805  rz_bp_traptrace_enable(core->dbg->bp, false);
806  }
807 }
808 
809 #define MAX_MAP_SIZE (1024 * 1024 * 512)
810 static int dump_maps(RzCore *core, int perm, const char *filename) {
811  RzDebugMap *map;
812  RzListIter *iter;
813  rz_debug_map_sync(core->dbg); // update process memory maps
814  ut64 addr = core->offset;
815  int do_dump = false;
816  int ret = !rz_list_empty(core->dbg->maps);
817  rz_list_foreach (core->dbg->maps, iter, map) {
818  do_dump = false;
819  if (perm == -1) {
820  if (addr >= map->addr && addr < map->addr_end) {
821  do_dump = true;
822  }
823  } else if (perm == 0) {
824  do_dump = true;
825  } else if (perm == (map->perm & perm)) {
826  do_dump = true;
827  }
828  if (do_dump) {
829  ut8 *buf = malloc(map->size);
830  // TODO: use mmap here. we need a portable implementation
831  if (!buf) {
832  eprintf("Cannot allocate 0x%08" PFMT64x " bytes\n", map->size);
833  free(buf);
835  continue;
836  }
837  if (map->size > MAX_MAP_SIZE) {
838  eprintf("Do not dumping 0x%08" PFMT64x " because it's too big\n", map->addr);
839  free(buf);
840  continue;
841  }
842  rz_io_read_at(core->io, map->addr, buf, map->size);
843  char *file = filename
844  ? strdup(filename)
845  : rz_str_newf("0x%08" PFMT64x "-0x%08" PFMT64x "-%s.dmp",
846  map->addr, map->addr_end, rz_str_rwx_i(map->perm));
847  if (!rz_file_dump(file, buf, map->size, 0)) {
848  eprintf("Cannot write '%s'\n", file);
849  ret = 0;
850  } else {
851  eprintf("Dumped %d byte(s) into %s\n", (int)map->size, file);
852  }
853  free(file);
854  free(buf);
855  }
856  }
857  // eprintf ("No debug region found here\n");
858  return ret;
859 }
860 
861 static void cmd_debug_current_modules(RzCore *core, RzOutputMode mode) { // "dmm"
862  ut64 addr = core->offset;
863  RzDebugMap *map;
864  RzList *list;
865  RzListIter *iter;
866  list = rz_debug_modules_list(core->dbg);
867  rz_list_foreach (list, iter, map) {
868  if (!(addr >= map->addr && addr < map->addr_end)) {
869  continue;
870  }
871  if (mode == RZ_OUTPUT_MODE_STANDARD) {
872  rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", map->addr, map->addr_end, map->file);
873  } else if (mode == RZ_OUTPUT_MODE_RIZIN) {
874  /* Escape backslashes (e.g. for Windows). */
875  char *escaped_path = rz_str_escape(map->file);
876  char *filtered_name = strdup(map->name);
877  rz_name_filter(filtered_name, 0, true);
878  rz_cons_printf("f mod.%s @ 0x%08" PFMT64x "\n",
879  filtered_name, map->addr);
880  rz_cons_printf("oba 0x%08" PFMT64x " %s\n", map->addr, escaped_path);
881  free(escaped_path);
882  free(filtered_name);
883  }
884  }
886 }
887 
888 static void cmd_debug_modules(RzCore *core, RzCmdStateOutput *state) { // "dmm"
889  RzDebugMap *map;
890  RzList *list;
891  RzListIter *iter;
892  PJ *pj = state->d.pj;
893  RzOutputMode mode = state->mode;
895  list = rz_debug_modules_list(core->dbg);
896  rz_list_foreach (list, iter, map) {
897  if (mode == RZ_OUTPUT_MODE_STANDARD) {
898  rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", map->addr, map->addr_end, map->file);
899  } else if (mode == RZ_OUTPUT_MODE_JSON) {
900  /* Escape backslashes (e.g. for Windows). */
901  pj_o(pj);
902  pj_kn(pj, "addr", map->addr);
903  pj_kn(pj, "addr_end", map->addr_end);
904  pj_ks(pj, "file", map->file);
905  pj_ks(pj, "name", map->name);
906  pj_end(pj);
907  } else if (mode == RZ_OUTPUT_MODE_RIZIN) {
908  /* Escape backslashes (e.g. for Windows). */
909  char *escaped_path = rz_str_escape(map->file);
910  char *filtered_name = strdup(map->name);
911  rz_name_filter(filtered_name, 0, true);
912  rz_cons_printf("f mod.%s @ 0x%08" PFMT64x "\n",
913  filtered_name, map->addr);
914  rz_cons_printf("oba 0x%08" PFMT64x " %s\n", map->addr, escaped_path);
915  free(escaped_path);
916  free(filtered_name);
917  }
918  }
921 }
922 
923 static ut64 addroflib(RzCore *core, const char *libname) {
924  RzListIter *iter;
925  RzDebugMap *map;
926  if (!core || !libname) {
927  return UT64_MAX;
928  }
929  rz_debug_map_sync(core->dbg);
930  // RzList *list = rz_debug_native_modules_get (core->dbg);
932  rz_list_foreach (list, iter, map) {
933  if (strstr(rz_file_basename(map->name), libname)) {
934  return map->addr;
935  }
936  }
937  rz_list_foreach (core->dbg->maps, iter, map) {
938  if (strstr(rz_file_basename(map->name), libname)) {
939  return map->addr;
940  }
941  }
942  return UT64_MAX;
943 }
944 
946  RzListIter *iter;
947  RzDebugMap *map;
948 
949  rz_debug_map_sync(core->dbg);
951  rz_list_foreach (list, iter, map) {
952  if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
953  return map;
954  }
955  }
956  rz_list_foreach (core->dbg->maps, iter, map) {
957  if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
958  return map;
959  }
960  }
961  return NULL;
962 }
963 
965  switch (mode) {
966  case RZ_MODE_PRINT:
967  default:
969  case RZ_MODE_JSON:
970  return RZ_OUTPUT_MODE_JSON;
971  case RZ_MODE_SIMPLE:
972  return RZ_OUTPUT_MODE_QUIET;
973  case RZ_MODE_SIMPLEST:
975  case RZ_MODE_RIZINCMD:
976  return RZ_OUTPUT_MODE_RIZIN;
977  }
978 }
979 
980 static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, PJ *pj,
981  int mode, bool symbols_only, RzCoreBinFilter *filter) {
982  int fd;
983  if ((fd = rz_io_fd_open(core->io, file, RZ_PERM_R, 0)) == -1) {
984  return false;
985  }
986  RzBinOptions opt = { 0 };
987  opt.obj_opts.elf_load_sections = true;
988  opt.obj_opts.elf_checks_sections = true;
989  opt.obj_opts.elf_checks_segments = true;
990  opt.fd = fd;
991  opt.sz = rz_io_fd_size(core->io, fd);
992  opt.obj_opts.baseaddr = baseaddr;
993  RzBinFile *obf = rz_bin_cur(core->bin);
994  RzBinFile *bf = rz_bin_open_io(core->bin, &opt);
995  if (!bf) {
996  rz_io_fd_close(core->io, fd);
997  return false;
998  }
999  int action = RZ_CORE_BIN_ACC_ALL & ~RZ_CORE_BIN_ACC_INFO;
1000  if (symbols_only || filter->name) {
1001  action = RZ_CORE_BIN_ACC_SYMBOLS;
1002  } else if (mode == RZ_MODE_SET || mode == RZ_MODE_RIZINCMD) {
1003  action &= ~RZ_CORE_BIN_ACC_ENTRIES & ~RZ_CORE_BIN_ACC_MAIN & ~RZ_CORE_BIN_ACC_MAPS;
1004  }
1005  if (mode == RZ_MODE_SET) {
1006  rz_core_bin_apply_info(core, core->bin->cur, action);
1007  } else {
1010  rz_core_bin_print(core, bf, action, filter, &state, NULL);
1013  }
1014  rz_bin_file_delete(core->bin, bf);
1015  rz_bin_file_set_cur_binfile(core->bin, obf);
1016  rz_io_fd_close(core->io, fd);
1017  return true;
1018 }
1019 
1020 // dm
1022  CMD_CHECK_DEBUG_DEAD(core);
1023  rz_debug_map_sync(core->dbg); // update process memory maps
1024  rz_core_debug_map_print(core, core->offset, state);
1025  return RZ_CMD_STATUS_OK;
1026 }
1027 
1028 // dma
1030  CMD_CHECK_DEBUG_DEAD(core);
1031  ut64 addr = core->offset;
1032  int size = (int)rz_num_math(core->num, argv[1]);
1033  rz_debug_map_alloc(core->dbg, addr, size, false);
1034  return RZ_CMD_STATUS_OK;
1035 }
1036 
1037 // dmm
1039  CMD_CHECK_DEBUG_DEAD(core);
1040  cmd_debug_modules(core, state);
1041  return RZ_CMD_STATUS_OK;
1042 }
1043 
1044 // dmm.
1046  CMD_CHECK_DEBUG_DEAD(core);
1048  return RZ_CMD_STATUS_OK;
1049 }
1050 
1051 // dm-
1053  CMD_CHECK_DEBUG_DEAD(core);
1054  RzListIter *iter;
1055  RzDebugMap *map;
1056  ut64 addr = core->offset;
1057  rz_list_foreach (core->dbg->maps, iter, map) {
1058  if (addr >= map->addr && addr < map->addr_end) {
1059  rz_debug_map_dealloc(core->dbg, map);
1060  rz_debug_map_sync(core->dbg);
1061  return RZ_CMD_STATUS_OK;
1062  }
1063  }
1064  eprintf("The address doesn't match with any map.\n");
1065  return RZ_CMD_STATUS_ERROR;
1066 }
1067 
1068 // dm=
1070  CMD_CHECK_DEBUG_DEAD(core);
1071  rz_debug_map_sync(core->dbg);
1072  rz_debug_map_list_visual(core->dbg, core->offset, argv[0] + 2,
1073  rz_config_get_i(core->config, "scr.color"));
1074  return RZ_CMD_STATUS_OK;
1075 }
1076 
1077 // dm.
1079  CMD_CHECK_DEBUG_DEAD(core);
1080  ut64 addr = core->offset;
1081  // RZ_OUTPUT_MODE_LONG is workaround for '.'
1082  RzCmdStateOutput state = { 0 };
1087  rz_cons_flush();
1088  return RZ_CMD_STATUS_OK;
1089 }
1090 
1091 // dmd
1093  CMD_CHECK_DEBUG_DEAD(core);
1094  if (argc == 2) {
1095  dump_maps(core, -1, argv[1]);
1096  } else if (argc == 1) {
1097  dump_maps(core, -1, NULL);
1098  }
1099  return RZ_CMD_STATUS_OK;
1100 }
1101 
1102 // dmda
1104  CMD_CHECK_DEBUG_DEAD(core);
1105  dump_maps(core, 0, NULL);
1106  return RZ_CMD_STATUS_OK;
1107 }
1108 
1109 // dmdw
1111  CMD_CHECK_DEBUG_DEAD(core);
1112  dump_maps(core, RZ_PERM_RW, NULL);
1113  return RZ_CMD_STATUS_OK;
1114 }
1115 
1116 // dmi
1117 RZ_IPI int rz_cmd_debug_dmi(void *data, const char *input) {
1118  RzCore *core = (RzCore *)data;
1119  CMD_CHECK_DEBUG_DEAD(core);
1120  RzListIter *iter;
1121  RzDebugMap *map;
1122  ut64 addr = core->offset;
1123  switch (input[0]) {
1124  case '\0': // "dmi" alias of "dmm"
1125  {
1126  RzCmdStateOutput state = { 0 };
1128  cmd_debug_modules(core, &state);
1131  rz_cons_flush();
1132  break;
1133  }
1134  case ' ': // "dmi "
1135  case '*': // "dmi*"
1136  case 'v': // "dmiv"
1137  case 'j': // "dmij"
1138  case 'q': // "dmiq"
1139  case 'a': // "dmia"
1140  {
1141  const char *libname = NULL, *symname = NULL, *a0;
1142  int mode;
1143  ut64 baddr = 0LL;
1144  char *ptr;
1145  int i = 1;
1146  bool symbols_only = true;
1147  if (input[0] == 'a') {
1148  symbols_only = false;
1149  input++;
1150  }
1151  PJ *pj = NULL;
1152  switch (input[0]) {
1153  case 's':
1154  mode = RZ_MODE_SET;
1155  break;
1156  case '*':
1158  break;
1159  case 'j':
1160  mode = RZ_MODE_JSON;
1161  pj = pj_new();
1162  if (!pj) {
1163  return false;
1164  }
1165  break;
1166  case 'q':
1167  mode = input[1] == 'q' ? input++, RZ_MODE_SIMPLEST : RZ_MODE_SIMPLE;
1168  break;
1169  default:
1170  mode = RZ_MODE_PRINT;
1171  break;
1172  }
1173  ptr = strdup(input[0] ? rz_str_trim_head_ro(input + 1) : "");
1174  if (!ptr || !*ptr) {
1175  rz_core_cmd(core, "dmm", 0);
1176  free(ptr);
1177  pj_free(pj);
1178  break;
1179  }
1180  if (symbols_only) {
1181  i = rz_str_word_set0(ptr);
1182  }
1183  switch (i) {
1184  case 2:
1185  symname = rz_str_word_get0(ptr, 1);
1186  // fall through
1187  case 1:
1188  a0 = rz_str_word_get0(ptr, 0);
1189  addr = rz_num_get(core->num, a0);
1190  if (!addr || addr == UT64_MAX) {
1191  libname = rz_str_word_get0(ptr, 0);
1192  }
1193  break;
1194  }
1195  if (libname && !addr) {
1196  addr = addroflib(core, rz_file_basename(libname));
1197  if (addr == UT64_MAX) {
1198  eprintf("Unknown library, or not found in dm\n");
1199  }
1200  }
1201  map = get_closest_map(core, addr);
1202  if (map) {
1203  RzCoreBinFilter filter;
1204  filter.offset = UT64_MAX;
1205  filter.name = (char *)symname;
1206  baddr = map->addr;
1207 
1208  if (libname) {
1209  const char *file = map->file ? map->file : map->name;
1210  char *newfile = NULL;
1211  if (!rz_file_exists(file)) {
1212  newfile = rz_file_temp("memlib");
1213  if (newfile) {
1214  file = newfile;
1215  rz_core_dump(core, file, baddr, map->size, false);
1216  }
1217  }
1218  get_bin_info(core, file, baddr, pj, mode, symbols_only, &filter);
1219  if (newfile) {
1220  if (!rz_file_rm(newfile)) {
1221  eprintf("Error when removing %s\n", newfile);
1222  }
1223  free(newfile);
1224  }
1225  } else {
1226  RzBinFile *bf = rz_bin_cur(core->bin);
1227  if (bf) {
1228  rz_bin_set_baddr(core->bin, map->addr);
1231  rz_core_bin_print(core, bf, RZ_CORE_BIN_ACC_SYMBOLS, &filter, &state, NULL);
1234  rz_bin_set_baddr(core->bin, baddr);
1235  }
1236  }
1237  }
1238  if (mode == RZ_MODE_JSON) {
1240  pj_free(pj);
1241  }
1242  free(ptr);
1243  } break;
1244  case '.': // "dmi."
1245  {
1246  map = get_closest_map(core, addr);
1247  if (map) {
1248  ut64 closest_addr = UT64_MAX;
1250  RzBinSymbol *symbol, *closest_symbol = NULL;
1251 
1252  rz_list_foreach (symbols, iter, symbol) {
1253  if (symbol->vaddr > addr) {
1254  if (symbol->vaddr - addr < closest_addr) {
1255  closest_addr = symbol->vaddr - addr;
1256  closest_symbol = symbol;
1257  }
1258  } else {
1259  if (addr - symbol->vaddr < closest_addr) {
1260  closest_addr = addr - symbol->vaddr;
1261  closest_symbol = symbol;
1262  }
1263  }
1264  }
1265  RzBinFile *bf = rz_bin_cur(core->bin);
1266  if (closest_symbol && bf) {
1267  RzCoreBinFilter filter;
1268  filter.offset = UT64_MAX;
1269  filter.name = (char *)closest_symbol->name;
1270 
1271  rz_bin_set_baddr(core->bin, map->addr);
1274  rz_core_bin_print(core, bf, RZ_CORE_BIN_ACC_SYMBOLS, &filter, &state, NULL);
1277  }
1278  }
1279  } break;
1280  default:
1282  break;
1283  }
1284  return RZ_CMD_STATUS_OK;
1285 }
1286 
1287 // dmp
1289  CMD_CHECK_DEBUG_DEAD(core);
1290  RzListIter *iter;
1291  RzDebugMap *map;
1292  ut64 addr = 0, size = 0;
1293  int perms;
1294  if (argc == 3) { // dmp <size> <perms> @ <addr>
1295  addr = core->offset;
1296  size = rz_num_math(core->num, argv[1]);
1297  perms = rz_str_rwx(argv[2]);
1298  rz_debug_map_protect(core->dbg, addr, (int)size, perms);
1299  } else if (argc == 2) { // dmp <perms>
1300  addr = UT64_MAX;
1301  rz_list_foreach (core->dbg->maps, iter, map) {
1302  if (core->offset >= map->addr && core->offset < map->addr_end) {
1303  addr = map->addr;
1304  size = map->size;
1305  break;
1306  }
1307  }
1308  perms = rz_str_rwx(argv[1]);
1309  if (addr != UT64_MAX && perms >= 0) {
1310  rz_debug_map_protect(core->dbg, addr, (int)size, perms);
1311  } else {
1312  return RZ_CMD_STATUS_ERROR;
1313  }
1314  }
1315  return RZ_CMD_STATUS_OK;
1316 }
1317 
1319  CMD_CHECK_DEBUG_DEAD(core);
1320  RzListIter *iter;
1321  RzDebugMap *map;
1322  ut64 addr;
1323  const char *libname = NULL, *sectname = NULL, *mode = "";
1324  ut64 baddr = 0LL;
1325  if (m == RZ_OUTPUT_MODE_RIZIN) {
1326  mode = "-r ";
1327  }
1328  addr = UT64_MAX;
1329  if (argc == 3) {
1330  sectname = argv[2];
1331  }
1332  if (argc >= 2) {
1333  if (IS_DIGIT(*argv[1])) {
1334  const char *a0 = argv[1];
1335  addr = rz_num_math(core->num, a0);
1336  } else {
1337  addr = UT64_MAX;
1338  }
1339  if (!addr || addr == UT64_MAX) {
1340  libname = argv[1];
1341  }
1342  }
1343  rz_debug_map_sync(core->dbg); // update process memory maps
1345  rz_list_foreach (list, iter, map) {
1346  if ((!libname ||
1347  (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) ||
1348  (libname != NULL && (strstr(map->name, libname))))) {
1349  baddr = map->addr;
1350  char *res;
1351  const char *file = map->file ? map->file : map->name;
1352  char *name = rz_str_escape((char *)rz_file_basename(file));
1353  char *filesc = rz_str_escape(file);
1354  /* TODO: do not spawn. use RzBin API */
1355  if (sectname) {
1356  char *sect = rz_str_escape(sectname);
1357  res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\" | grep \"%s\"", name, mode, baddr, filesc, sect);
1358  free(sect);
1359  } else {
1360  res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\"", name, mode, baddr, filesc);
1361  }
1362  free(filesc);
1363  rz_cons_println(res);
1364  free(name);
1365  free(res);
1366  if (libname || addr != UT64_MAX) { // only single match requested
1367  break;
1368  }
1369  }
1370  }
1371  return RZ_CMD_STATUS_OK;
1372 }
1373 // dml
1374 RZ_IPI RzCmdStatus rz_cmd_debug_dml_handler(RzCore *core, int argc, const char **argv) {
1375  CMD_CHECK_DEBUG_DEAD(core);
1376  RzListIter *iter;
1377  RzDebugMap *map;
1378  ut64 addr = core->offset;
1379  rz_debug_map_sync(core->dbg); // update process memory maps
1380  rz_list_foreach (core->dbg->maps, iter, map) {
1381  if (addr >= map->addr && addr < map->addr_end) {
1382  size_t sz;
1383  char *buf = rz_file_slurp(argv[1], &sz);
1384  // TODO: use mmap here. we need a portable implementation
1385  if (!buf) {
1386  eprintf("Cannot allocate 0x%08" PFMT64x " byte(s)\n", map->size);
1387  return RZ_CMD_STATUS_ERROR;
1388  }
1389  rz_io_write_at(core->io, map->addr, (const ut8 *)buf, sz);
1390  if (sz != map->size)
1391  eprintf("File size differs from region size (%" PFMT64u " vs %" PFMT64d ")\n",
1392  (ut64)sz, map->size);
1393  eprintf("Loaded %" PFMT64u " byte(s) into the map region at 0x%08" PFMT64x "\n",
1394  (ut64)sz, map->addr);
1395  free(buf);
1396  return RZ_CMD_STATUS_OK;
1397  }
1398  }
1399  eprintf("No debug region found here\n");
1400  return RZ_CMD_STATUS_ERROR;
1401 }
1402 
1403 // dmL
1404 RZ_IPI RzCmdStatus rz_cmd_debug_dmL_handler(RzCore *core, int argc, const char **argv) {
1405  CMD_CHECK_DEBUG_DEAD(core);
1406  int size;
1407  ut64 addr;
1408  addr = core->offset;
1409  size = (int)rz_num_math(core->num, argv[1]);
1410  rz_debug_map_alloc(core->dbg, addr, size, true);
1411  return RZ_CMD_STATUS_OK;
1412 }
1413 
1414 // dmx
1415 RZ_IPI int rz_cmd_debug_heap_jemalloc(void *data, const char *input) {
1416  RzCore *core = (RzCore *)data;
1417  CMD_CHECK_DEBUG_DEAD(core);
1418 #if HAVE_JEMALLOC
1419  if (core->rasm->bits == 64) {
1420  return cmd_dbg_map_jemalloc_64(core, input);
1421  } else {
1422  return cmd_dbg_map_jemalloc_32(core, input);
1423  }
1424 #endif
1425  return RZ_CMD_STATUS_ERROR;
1426 }
1427 
1428 static void foreach_reg_set_or_clear(RzCore *core, bool set) {
1429  RzReg *reg = rz_core_reg_default(core);
1431  RzListIter *it;
1432  RzRegItem *reg_item;
1433  rz_list_foreach (regs, it, reg_item) {
1434  if (set) {
1435  const ut64 value = rz_reg_get_value(reg, reg_item);
1436  rz_flag_set(core->flags, reg_item->name, value, reg_item->size / 8);
1437  } else {
1438  rz_flag_unset_name(core->flags, reg_item->name);
1439  }
1440  }
1441 }
1442 
1444  rz_flag_space_push(core->flags, RZ_FLAGS_FS_REGISTERS);
1445  foreach_reg_set_or_clear(core, true);
1446  rz_flag_space_pop(core->flags);
1447 }
1448 
1450  foreach_reg_set_or_clear(core, false);
1451 }
1452 
1453 static void backtrace_vars(RzCore *core, RzList *frames) {
1454  RzDebugFrame *f;
1455  RzListIter *iter;
1456  // analysis vs debug ?
1457  const char *sp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SP);
1458  const char *bp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_BP);
1459  if (!sp) {
1460  sp = "SP";
1461  }
1462  if (!bp) {
1463  bp = "BP";
1464  }
1465  RzReg *r = core->analysis->reg;
1466  ut64 dsp = rz_reg_getv(r, sp);
1467  ut64 dbp = rz_reg_getv(r, bp);
1468  int n = 0;
1469  rz_list_foreach (frames, iter, f) {
1470  ut64 s = f->sp ? f->sp : dsp;
1471  ut64 b = f->bp ? f->bp : dbp;
1472  rz_reg_setv(r, bp, s);
1473  rz_reg_setv(r, sp, b);
1475  char flagdesc[1024], flagdesc2[1024];
1476  RzFlagItem *fi = rz_flag_get_at(core->flags, f->addr, true);
1477  flagdesc[0] = flagdesc2[0] = 0;
1478  if (fi) {
1479  if (fi->offset != f->addr) {
1480  int delta = (int)(f->addr - fi->offset);
1481  if (delta > 0) {
1482  snprintf(flagdesc, sizeof(flagdesc),
1483  "%s+%d", fi->name, delta);
1484  } else if (delta < 0) {
1485  snprintf(flagdesc, sizeof(flagdesc),
1486  "%s%d", fi->name, delta);
1487  } else {
1488  snprintf(flagdesc, sizeof(flagdesc),
1489  "%s", fi->name);
1490  }
1491  } else {
1492  snprintf(flagdesc, sizeof(flagdesc),
1493  "%s", fi->name);
1494  }
1495  }
1497  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, f->addr, 0);
1498  // char *str = rz_str_newf ("[frame %d]", n);
1499  rz_cons_printf("%d 0x%08" PFMT64x " sp: 0x%08" PFMT64x " %-5d"
1500  "[%s] %s %s\n",
1501  n, f->addr, f->sp, (int)f->size,
1502  fcn ? fcn->name : "??", flagdesc, flagdesc2);
1503  rz_cons_push();
1504  char *res = rz_core_analysis_all_vars_display(core, fcn, true);
1505  rz_cons_pop();
1506  rz_cons_printf("%s", res);
1507  free(res);
1508  n++;
1509  }
1510  rz_reg_setv(r, bp, dbp);
1511  rz_reg_setv(r, sp, dsp);
1512 }
1513 
1514 static void asciiart_backtrace(RzCore *core, RzList *frames) {
1515  // TODO: show local variables
1516  // TODO: show function/flags/symbols related
1517  // TODO: show contents of stack
1518  // TODO: honor scr.color
1519  RzDebugFrame *f;
1520  RzListIter *iter;
1521  bool mymap = false;
1522  // analysis vs debug ?
1523  const char *sp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SP);
1524  const char *bp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_BP);
1525  if (!sp) {
1526  sp = "SP";
1527  }
1528  if (!bp) {
1529  bp = "BP";
1530  }
1531  ut64 dsp = rz_reg_getv(core->analysis->reg, sp);
1532  ut64 dbp = rz_reg_getv(core->analysis->reg, bp);
1533  RzDebugMap *map = rz_debug_map_get(core->dbg, dsp);
1534  if (!map) {
1535  mymap = true;
1536  map = RZ_NEW0(RzDebugMap);
1537  map->addr = UT64_MAX;
1538  map->addr_end = UT64_MAX;
1539  }
1540 
1541  rz_cons_printf("0x%016" PFMT64x " STACK END ^^^\n", map->addr);
1542  rz_cons_printf("0x%016" PFMT64x " STACK POINTER: %s\n", dsp, sp);
1543  rz_cons_printf(" .------------------------.\n");
1544  int n = 0;
1545  rz_list_foreach (frames, iter, f) {
1546  ut64 s = f->sp ? f->sp : dsp;
1547  ut64 b = f->bp ? f->bp : dbp;
1548  char *str = rz_str_newf("[frame %d]", n);
1549  rz_cons_printf("0x%016" PFMT64x " |%4s %10s | ; size %" PFMTDPTR "\n", s, sp, str, (ptrdiff_t)(s - b));
1550  free(str);
1551  rz_cons_printf(" | ... |\n");
1552  rz_cons_printf("0x%016" PFMT64x " |%4s 0x%016" PFMT64x " | %s\n", b, bp, f->addr, "; return address");
1553  rz_cons_printf(" )------------------------(\n");
1554  // eprintf ("0x%08llx 0x%08llx 0x%08llx\n", f->addr, s, b);
1555  n++;
1556  }
1557  rz_cons_printf(" | ... |\n");
1558  rz_cons_printf(" `------------------------'\n");
1559  rz_cons_printf("0x%016" PFMT64x " STACK BOTTOM\n", map->addr_end);
1560  if (mymap) {
1562  }
1563 }
1564 
1566  RzDebug *dbg = (RzDebug *)u;
1567  rz_debug_stop(dbg);
1568 }
1569 
1570 #if __WINDOWS__
1571 #include "..\debug\p\native\windows\windows_message.h"
1572 #endif
1573 
1574 RZ_IPI void rz_core_debug_bp_add(RzCore *core, ut64 addr, const char *arg_perm, bool hwbp, bool watch) {
1575  RzBreakpointItem *bpi;
1576  int rw = 0;
1577 
1578  if (watch) {
1579  rw = rz_str_rwx(arg_perm);
1580  rw &= RZ_PERM_RWX; // filter out the rwx bits only
1581  if (rw == 0) {
1582  RZ_LOG_WARN("Invalid permissions provided for setting watchpoint. Defaulting to \"rw\".\n");
1583  rw = RZ_PERM_RW;
1584  }
1585  }
1586  bpi = rz_debug_bp_add(core->dbg, addr, hwbp, watch, rw, NULL, 0);
1587  if (!bpi) {
1588  RZ_LOG_ERROR("Cannot set breakpoint at 0x%" PFMT64x "\n", addr);
1589  return;
1590  }
1592  if (f) {
1593  if (addr > f->offset) {
1594  char *name = rz_str_newf("%s+0x%" PFMT64x, f->name, addr - f->offset);
1595  rz_bp_item_set_name(bpi, name);
1596  free(name);
1597  } else {
1598  bpi->name = strdup(f->name);
1599  }
1600  } else {
1601  char *name = rz_str_newf("0x%08" PFMT64x, addr);
1602  rz_bp_item_set_name(bpi, name);
1603  free(name);
1604  }
1605 }
1606 
1607 static RTreeNode *add_trace_tree_child(HtUP *ht, RTree *t, RTreeNode *cur, ut64 addr) {
1608  struct trace_node *t_node = ht_up_find(ht, addr, NULL);
1609  if (!t_node) {
1610  t_node = RZ_NEW0(struct trace_node);
1611  if (t_node) {
1612  t_node->addr = addr;
1613  t_node->refs = 1;
1614  ht_up_insert(ht, addr, t_node);
1615  }
1616  } else {
1617  t_node->refs++;
1618  }
1619  return rz_tree_add_node(t, cur, t_node);
1620 }
1621 
1622 static RzCore *_core = NULL;
1623 
1625  const char *name = "";
1626  struct trace_node *tn = n->data;
1627  unsigned int i;
1628  if (!tn)
1629  return;
1630  for (i = 0; i < n->depth - 1; i++) {
1631  rz_cons_printf(" ");
1632  }
1633  if (_core) {
1634  RzFlagItem *f = rz_flag_get_at(_core->flags, tn->addr, true);
1635  if (f) {
1636  name = f->name;
1637  }
1638  }
1639  rz_cons_printf(" 0x%08" PFMT64x " refs %d %s\n", tn->addr, tn->refs, name);
1640 }
1641 
1642 static void trace_traverse(RTree *t) {
1643  RTreeVisitor vis = { 0 };
1644 
1645  /* clear the line on stderr, because somebody has written there */
1646  fprintf(stderr, "\x1b[2K\r");
1647  fflush(stderr);
1649  rz_tree_dfs(t, &vis);
1650 }
1651 
1652 static void do_debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr) {
1653  bool trace_libs = rz_config_get_i(core->config, "dbg.trace.libs");
1654  bool shallow_trace = rz_config_get_i(core->config, "dbg.trace.inrange");
1655  HtUP *tracenodes = core->dbg->tracenodes;
1656  RTree *tr = core->dbg->tree;
1657  RzDebug *dbg = core->dbg;
1658  ut64 debug_to = UT64_MAX;
1659  RTreeNode *cur;
1660  ut64 addr = 0;
1661  int n = 0;
1662 
1663  if (!trace_libs) {
1664 #if NOOP
1665  RzList *bounds = rz_core_get_boundaries_prot(core, -1, "dbg.program", "search");
1666  rz_list_free(bounds);
1667 #endif
1668  }
1669 
1670  /* set root if not already present */
1672  cur = tr->root;
1673 
1674  while (true) {
1675  ut8 buf[32];
1676  RzAnalysisOp aop;
1677  int addr_in_range;
1678 
1679  if (rz_cons_is_breaked()) {
1680  break;
1681  }
1682  if (rz_debug_is_dead(dbg)) {
1683  break;
1684  }
1685  if (debug_to != UT64_MAX && !rz_debug_continue_until(dbg, debug_to)) {
1686  break;
1687  }
1688  if (!rz_debug_step(dbg, 1)) {
1689  break;
1690  }
1691  debug_to = UT64_MAX;
1692  if (!rz_debug_reg_sync(dbg, RZ_REG_TYPE_GPR, false)) {
1693  break;
1694  }
1695  addr = rz_debug_reg_get(dbg, "PC");
1696  if (addr == final_addr) {
1697  // we finished the tracing so break the loop
1698  break;
1699  }
1700  addr_in_range = addr >= from && addr < to;
1701 
1702  rz_io_read_at(core->io, addr, buf, sizeof(buf));
1703  rz_analysis_op(core->analysis, &aop, addr, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC);
1704  eprintf("%d %" PFMT64x "\r", n++, addr);
1705  switch (aop.type) {
1710  ut64 called_addr;
1711  int called_in_range;
1712  // store regs
1713  // step into
1714  // get pc
1715  rz_debug_step(dbg, 1);
1717  called_addr = rz_debug_reg_get(dbg, "PC");
1718  called_in_range = called_addr >= from && called_addr < to;
1719  if (!called_in_range && addr_in_range && !shallow_trace) {
1720  debug_to = addr + aop.size;
1721  }
1722  if (addr_in_range || shallow_trace) {
1723  cur = add_trace_tree_child(tracenodes, tr, cur, addr);
1724  if (debug_to != UT64_MAX) {
1725  cur = cur->parent;
1726  }
1727  }
1728  // TODO: push pc+aop.length into the call path stack
1729  break;
1730  }
1731  case RZ_ANALYSIS_OP_TYPE_CALL: {
1732  int called_in_range = aop.jump >= from && aop.jump < to;
1733  if (!called_in_range && addr_in_range && !shallow_trace) {
1734  debug_to = aop.addr + aop.size;
1735  }
1736  if (addr_in_range || shallow_trace) {
1737  cur = add_trace_tree_child(tracenodes, tr, cur, addr);
1738  if (debug_to != UT64_MAX) {
1739  cur = cur->parent;
1740  }
1741  }
1742  break;
1743  }
1745  if (cur != tr->root) {
1746  cur = cur->parent;
1747  }
1748  break;
1749  }
1750  }
1751 }
1752 
1753 static void debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr) {
1754  RzBreakpointItem *bp_final = NULL;
1755  int t = core->dbg->trace->enabled;
1756 
1757  if (rz_debug_is_dead(core->dbg)) {
1758  eprintf("No process to debug.");
1759  return;
1760  }
1761  core->dbg->trace->enabled = 0;
1763  rz_reg_arena_swap(core->dbg->reg, true);
1764  if (final_addr != UT64_MAX) {
1765  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
1766  bp_final = rz_debug_bp_add(core->dbg, final_addr, hwbp, false, 0, NULL, 0);
1767  if (!bp_final) {
1768  eprintf("Cannot set breakpoint at final address (%" PFMT64x ")\n", final_addr);
1769  }
1770  }
1771  do_debug_trace_calls(core, from, to, final_addr);
1772  if (bp_final) {
1773  rz_bp_del(core->dbg->bp, final_addr);
1774  }
1775  _core = core;
1776  trace_traverse(core->dbg->tree);
1777  core->dbg->trace->enabled = t;
1779 }
1780 
1781 static void rz_core_debug_esil(RzCore *core, const char *input) {
1782  switch (input[0]) {
1783  case '\0': // "de"
1784  // list
1786  break;
1787  case ' ': // "de "
1788  {
1789  char *line = strdup(input + 1);
1790  char *p, *q;
1791  int done = 0;
1792  int perm = 0, dev = 0;
1793  p = strchr(line, ' ');
1794  if (p) {
1795  *p++ = 0;
1796  if (strchr(line, 'r'))
1797  perm |= RZ_PERM_R;
1798  if (strchr(line, 'w'))
1799  perm |= RZ_PERM_W;
1800  if (strchr(line, 'x'))
1801  perm |= RZ_PERM_X;
1802  q = strchr(p, ' ');
1803  if (q) {
1804  *q++ = 0;
1805  dev = p[0];
1806  if (q) {
1807  rz_debug_esil_watch(core->dbg, perm, dev, q);
1808  done = 1;
1809  }
1810  }
1811  }
1812  if (!done) {
1813  const char *help_de_msg[] = {
1814  "Usage:", "de", " [perm] [reg|mem] [expr]",
1815  NULL
1816  };
1817  rz_core_cmd_help(core, help_de_msg);
1818  }
1819  free(line);
1820  } break;
1821  case '-': // "de-"
1823  break;
1824  case 'c': // "dec"
1825  if (rz_debug_esil_watch_empty(core->dbg)) {
1826  eprintf("Error: no esil watchpoints defined\n");
1827  } else {
1829  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1830  rz_debug_esil_continue(core->dbg);
1831  }
1832  break;
1833  case 's': // "des"
1834  if (input[1] == 'u' && input[2] == ' ') { // "desu"
1835  ut64 addr, naddr, fin = rz_num_math(core->num, input + 2);
1837  addr = rz_debug_reg_get(core->dbg, "PC");
1838  while (addr != fin) {
1839  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1840  rz_debug_esil_step(core->dbg, 1);
1841  naddr = rz_debug_reg_get(core->dbg, "PC");
1842  if (naddr == addr) {
1843  eprintf("Detected loophole\n");
1844  break;
1845  }
1846  addr = naddr;
1847  }
1848  } else if (input[1] == '?' || !input[1]) {
1850  } else {
1852  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1853  // continue
1854  rz_debug_esil_step(core->dbg, rz_num_math(core->num, input + 1));
1855  }
1856  break;
1857  case '?': // "de?"
1858  default: {
1860  // TODO #7967 help refactor: move to detail
1861  rz_cons_printf("Examples:\n"
1862  " de r r rip # stop when reads rip\n"
1863  " de rw m ADDR # stop when read or write in ADDR\n"
1864  " de w r rdx # stop when rdx register is modified\n"
1865  " de x m FROM..TO # stop when rip in range\n");
1866  } break;
1867  }
1868 }
1869 
1870 static void rz_core_debug_kill(RzCore *core, const char *input) {
1871  if (!input || *input == '?') {
1872  if (input && input[1]) {
1873  const char *signame, *arg = input + 1;
1874  int signum = atoi(arg);
1875  if (signum > 0) {
1876  signame = rz_signal_to_string(signum);
1877  if (signame)
1878  rz_cons_println(signame);
1879  } else {
1881  if (signum > 0) {
1882  rz_cons_printf("%d\n", signum);
1883  }
1884  }
1885  } else {
1887  }
1888  } else if (*input == 'o') {
1889  switch (input[1]) {
1890  case 0: // "dko" - list signal skip/conts
1892  break;
1893  case ' ': // dko SIGNAL
1894  if (input[2]) {
1895  char *p, *name = strdup(input + 2);
1896  int signum = atoi(name);
1897  p = strchr(name, ' ');
1898  if (p)
1899  *p++ = 0; /* got SIGNAL and an action */
1900  // Actions:
1901  // - pass
1902  // - trace
1903  // - stop
1904  if (signum < 1)
1906  if (signum > 0) {
1907  if (!p || !p[0]) { // stop (the usual)
1908  rz_debug_signal_setup(core->dbg, signum, 0);
1909  } else if (*p == 's') { // skip
1911  } else if (*p == 'c') { // cont
1913  } else {
1914  eprintf("Invalid option: %s\n", p);
1915  }
1916  } else {
1917  eprintf("Invalid signal: %s\n", input + 2);
1918  }
1919  free(name);
1920  break;
1921  }
1922  /* fall through */
1923  case '?':
1924  default: {
1926  // TODO #7967 help refactor: move to detail
1927  rz_cons_println("NOTE: [signal] can be a number or a string that resolves with dk?\n"
1928  " skip means do not enter into the signal handler\n"
1929  " continue means enter into the signal handler");
1930  }
1931  }
1932  } else if (*input == 'j') {
1934  } else if (!*input) {
1936  } else {
1937  int sig = atoi(input);
1938  char *p = strchr(input, '=');
1939  if (p) {
1940  rz_debug_kill_setup(core->dbg, sig, rz_num_math(core->num, p + 1));
1941  } else {
1942  rz_debug_kill(core->dbg, core->dbg->pid, core->dbg->tid, sig);
1943  }
1944  }
1945 }
1946 
1947 static bool cmd_dcu(RzCore *core, const char *input) {
1948  const char *ptr = NULL;
1949  ut64 from, to, pc;
1950  bool dcu_range = false;
1951  bool invalid = (!input[0] || !input[1] || !input[2]);
1952  if (invalid || (input[2] != ' ' && input[2] != '.')) {
1954  return false;
1955  }
1956  to = UT64_MAX;
1957  if (input[2] == '.') {
1958  ptr = strchr(input + 3, ' ');
1959  if (ptr) { // TODO: put '\0' in *ptr to avoid
1960  from = rz_num_tail(core->num, core->offset, input + 2);
1961  if (ptr[1] == '.') {
1962  to = rz_num_tail(core->num, core->offset, ptr + 2);
1963  } else {
1964  to = rz_num_math(core->num, ptr + 1);
1965  }
1966  dcu_range = true;
1967  } else {
1968  from = rz_num_tail(core->num, core->offset, input + 2);
1969  }
1970  } else {
1971  ptr = strchr(input + 3, ' ');
1972  if (ptr) { // TODO: put '\0' in *ptr to avoid
1973  from = rz_num_math(core->num, input + 3);
1974  if (ptr[1] == '.') {
1975  to = rz_num_tail(core->num, core->offset, ptr + 2);
1976  } else {
1977  to = rz_num_math(core->num, ptr + 1);
1978  }
1979  dcu_range = true;
1980  } else {
1981  from = rz_num_math(core->num, input + 3);
1982  }
1983  }
1984  if (core->num->nc.errors && rz_cons_is_interactive()) {
1985  eprintf("Cannot continue until unknown address '%s'\n", core->num->nc.calc_buf);
1986  return false;
1987  }
1988  if (to == UT64_MAX) {
1989  to = from;
1990  }
1991  if (dcu_range) {
1993  do {
1994  if (rz_cons_is_breaked()) {
1995  break;
1996  }
1997  rz_debug_step(core->dbg, 1);
1998  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
1999  pc = rz_debug_reg_get(core->dbg, "PC");
2000  eprintf("Continue 0x%08" PFMT64x " > 0x%08" PFMT64x " < 0x%08" PFMT64x "\n",
2001  from, pc, to);
2002  } while (pc < from || pc > to);
2004  } else {
2005  return rz_core_debug_continue_until(core, from, to);
2006  }
2007  return true;
2008 }
2009 
2010 // dsu
2012  rz_reg_arena_swap(core->dbg->reg, true);
2013  step_until(core, rz_num_math(core->num, argv[1]));
2015  return RZ_CMD_STATUS_OK;
2016 }
2017 
2018 // dsui
2020  if (!step_until_inst(core, argv[1], false)) {
2021  return RZ_CMD_STATUS_ERROR;
2022  }
2024  return RZ_CMD_STATUS_OK;
2025 }
2026 
2027 // dsuir
2029  if (!step_until_inst(core, argv[1], true)) {
2030  return RZ_CMD_STATUS_ERROR;
2031  }
2033  return RZ_CMD_STATUS_OK;
2034 }
2035 
2036 // dsuo
2038  RzList *optypes_list = rz_list_new_from_array((const void **)argv + 1, argc - 1);
2039  step_until_optype(core, optypes_list);
2041  rz_list_free(optypes_list);
2042  return RZ_CMD_STATUS_OK;
2043 }
2044 
2045 // dsue
2047  step_until_esil(core, argv[1]);
2049  return RZ_CMD_STATUS_OK;
2050 }
2051 
2052 // dsuf
2054  step_until_flag(core, argv[1]);
2056  return RZ_CMD_STATUS_OK;
2057 }
2058 
2059 // dt
2060 RZ_IPI RzCmdStatus rz_cmd_debug_trace_handler(RzCore *core, int argc, const char **argv) {
2061  RzDebugTracepoint *t = rz_debug_trace_get(core->dbg, core->offset);
2062  if (!t) {
2063  RZ_LOG_ERROR("Cannot find any debug trace at address %" PFMT64x ".\n", core->offset);
2064  return RZ_CMD_STATUS_ERROR;
2065  }
2066 
2067  rz_cons_printf("offset = 0x%" PFMT64x "\n", t->addr);
2068  rz_cons_printf("opsize = %d\n", t->size);
2069  rz_cons_printf("times = %d\n", t->times);
2070  rz_cons_printf("count = %d\n", t->count);
2071  return RZ_CMD_STATUS_OK;
2072 }
2073 
2074 // dtl
2076  rz_debug_trace_print(core->dbg, state, core->offset);
2077  return RZ_CMD_STATUS_OK;
2078 }
2079 
2080 // dtl=
2082  rz_debug_traces_ascii(core->dbg, core->offset);
2083  return RZ_CMD_STATUS_OK;
2084 }
2085 
2086 // dt+
2088  int count = argc > 1 ? rz_num_math(core->num, argv[1]) : 1;
2090  if (!op) {
2091  RZ_LOG_ERROR("Cannot analyze opcode at 0x%08" PFMT64x "\n", core->offset);
2092  return RZ_CMD_STATUS_ERROR;
2093  }
2094 
2095  RzDebugTracepoint *tp = rz_debug_trace_add(core->dbg, core->offset, op->size);
2096  if (!tp) {
2098  return RZ_CMD_STATUS_ERROR;
2099  }
2100  tp->count = count;
2102  return RZ_CMD_STATUS_OK;
2103 }
2104 
2105 // dt++
2107  for (int i = 1; i < argc; ++i) {
2108  ut64 addr = rz_num_get(NULL, argv[i]);
2109  RzDebugTracepoint *t = rz_debug_trace_add(core->dbg, addr, 1);
2110  if (!t) {
2111  RZ_LOG_ERROR("Cannot add trace at address %" PFMT64x ".\n", addr);
2112  return RZ_CMD_STATUS_ERROR;
2113  }
2114  }
2115  return RZ_CMD_STATUS_OK;
2116 }
2117 
2118 // dt-
2120  rz_tree_reset(core->dbg->tree);
2121  rz_debug_trace_free(core->dbg->trace);
2123  core->dbg->trace = rz_debug_trace_new();
2124  return RZ_CMD_STATUS_OK;
2125 }
2126 
2127 // dta
2128 RZ_IPI int rz_cmd_debug_trace_addr(void *data, const char *input) {
2129  RzCore *core = (RzCore *)data;
2130  rz_debug_trace_at(core->dbg, input);
2131  return 0;
2132 }
2133 
2134 // dtc
2136  ut64 from = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
2137  ut64 to = argc > 2 ? rz_num_math(core->num, argv[2]) : UT64_MAX;
2138  ut64 addr = argc > 3 ? rz_num_math(core->num, argv[3]) : UT64_MAX;
2139 
2140  debug_trace_calls(core, from, to, addr);
2141  return RZ_CMD_STATUS_OK;
2142 }
2143 
2144 // dte
2147  int idx = rz_num_math(core->num, argv[1]);
2149  return RZ_CMD_STATUS_OK;
2150 }
2151 
2152 // dtel
2156  return RZ_CMD_STATUS_OK;
2157 }
2158 
2159 // dte-*
2162  if (core->analysis->esil) {
2165  }
2166  return RZ_CMD_STATUS_OK;
2167 }
2168 
2169 // dtei
2173  if (!op) {
2174  RZ_LOG_ERROR("Cannot analyze opcode at 0x%08" PFMT64x "\n", core->offset);
2175  return RZ_CMD_STATUS_ERROR;
2176  }
2179  return RZ_CMD_STATUS_OK;
2180 }
2181 
2182 // dtg
2185  return RZ_CMD_STATUS_OK;
2186 }
2187 
2188 // dtgi
2190  dot_trace_traverse(core, core->dbg->tree, 'i');
2191  return RZ_CMD_STATUS_OK;
2192 }
2193 
2194 // dts+
2196  if (rz_debug_is_dead(core->dbg)) {
2197  RZ_LOG_ERROR("Cannot start session outside of debug mode, run ood?\n");
2198  return RZ_CMD_STATUS_ERROR;
2199  }
2200  if (core->dbg->session) {
2201  RZ_LOG_ERROR("Session already started\n");
2202  return RZ_CMD_STATUS_ERROR;
2203  }
2204  core->dbg->session = rz_debug_session_new();
2206  return RZ_CMD_STATUS_OK;
2207 }
2208 
2209 // dts-
2211  if (!core->dbg->session) {
2212  RZ_LOG_ERROR("No session started\n");
2213  return RZ_CMD_STATUS_ERROR;
2214  }
2216  core->dbg->session = NULL;
2217  return RZ_CMD_STATUS_OK;
2218 }
2219 
2220 // dtst
2222  if (!core->dbg->session) {
2223  RZ_LOG_ERROR("No session started\n");
2224  return RZ_CMD_STATUS_ERROR;
2225  }
2226  rz_debug_session_save(core->dbg->session, argv[1]);
2227  return RZ_CMD_STATUS_OK;
2228 }
2229 
2230 // dtsf
2232  if (core->dbg->session) {
2234  core->dbg->session = NULL;
2235  }
2236  core->dbg->session = rz_debug_session_new();
2237  rz_debug_session_load(core->dbg, argv[1]);
2238  return RZ_CMD_STATUS_OK;
2239 }
2240 
2241 // dtsm
2243  if (core->dbg->session) {
2245  }
2246  return RZ_CMD_STATUS_OK;
2247 }
2248 
2249 // dtt
2251  int tag = rz_num_math(core->num, argv[1]);
2252  rz_debug_trace_tag(core->dbg, tag);
2253  return RZ_CMD_STATUS_OK;
2254 }
2255 
2256 static char *get_corefile_name(const char *raw_name, int pid) {
2257  return (!*raw_name) ? rz_str_newf("core.%u", pid) : rz_str_trim_dup(raw_name);
2258 }
2259 
2260 static ut8 *getFileData(RzCore *core, const char *arg) {
2261  if (*arg == '$') {
2262  return (ut8 *)rz_cmd_alias_get(core->rcmd, arg, 1);
2263  }
2264  return (ut8 *)rz_file_slurp(arg, NULL);
2265 }
2266 
2267 static void consumeBuffer(RzBuffer *buf, const char *cmd, const char *errmsg) {
2268  if (!buf) {
2269  if (errmsg) {
2270  rz_cons_printf("%s\n", errmsg);
2271  }
2272  return;
2273  }
2274  if (cmd) {
2275  rz_cons_printf("%s", cmd);
2276  }
2277  int i;
2278  rz_buf_seek(buf, 0, RZ_BUF_SET);
2279  for (i = 0; i < rz_buf_size(buf); i++) {
2280  ut8 tmp;
2281  if (!rz_buf_read8(buf, &tmp)) {
2282  return;
2283  }
2284  rz_cons_printf("%02x", tmp);
2285  }
2286  rz_cons_printf("\n");
2287 }
2288 
2289 RZ_IPI int rz_cmd_debug(void *data, const char *input) {
2290  RzCore *core = (RzCore *)data;
2291  int follow = 0;
2292 
2293  if (!strncmp(input, "ate", 3)) {
2294  char *now = rz_time_date_now_to_string();
2295  rz_cons_printf("%s\n", now);
2296  free(now);
2297  return 0;
2298  }
2299 
2300  switch (input[0]) {
2301  case 'd': // "ddd"
2302  switch (input[1]) {
2303  case '\0': // "ddd"
2304  rz_debug_desc_list(core->dbg, 0);
2305  break;
2306  case '*': // "dtd*"
2307  rz_debug_desc_list(core->dbg, 1);
2308  break;
2309  case 's': // "dtds"
2310  {
2311  ut64 off = UT64_MAX;
2312  int fd = atoi(input + 2);
2313  char *str = strchr(input + 2, ' ');
2314  if (str)
2315  off = rz_num_math(core->num, str + 1);
2316  if (off == UT64_MAX || !rz_debug_desc_seek(core->dbg, fd, off)) {
2317  RzBuffer *buf = rz_core_syscallf(core, "lseek", "%d, 0x%" PFMT64x ", %d", fd, off, 0);
2318  consumeBuffer(buf, "dx ", "Cannot seek");
2319  }
2320  } break;
2321  case 't': { // "ddt" <ttypath>
2322  RzBuffer *buf = rz_core_syscall(core, "close", 0);
2323  consumeBuffer(buf, "dx ", "Cannot close");
2324  break;
2325  }
2326  case 'd': // "ddd"
2327  {
2328  ut64 newfd = UT64_MAX;
2329  int fd = atoi(input + 2);
2330  char *str = strchr(input + 3, ' ');
2331  if (str)
2332  newfd = rz_num_math(core->num, str + 1);
2333  if (newfd == UT64_MAX || !rz_debug_desc_dup(core->dbg, fd, newfd)) {
2334  RzBuffer *buf = rz_core_syscallf(core, "dup2", "%d, %d", fd, (int)newfd);
2335  if (buf) {
2336  consumeBuffer(buf, "dx ", NULL);
2337  } else {
2338  eprintf("Cannot dup %d %d\n", fd, (int)newfd);
2339  }
2340  }
2341  } break;
2342  case 'r': {
2343  ut64 off = UT64_MAX;
2344  ut64 len = UT64_MAX;
2345  int fd = atoi(input + 2);
2346  char *str = strchr(input + 2, ' ');
2347  if (str)
2348  off = rz_num_math(core->num, str + 1);
2349  if (str)
2350  str = strchr(str + 1, ' ');
2351  if (str)
2352  len = rz_num_math(core->num, str + 1);
2353  if (len == UT64_MAX || off == UT64_MAX ||
2354  !rz_debug_desc_read(core->dbg, fd, off, len)) {
2355  consumeBuffer(rz_core_syscallf(core, "read", "%d, 0x%" PFMT64x ", %d",
2356  fd, off, (int)len),
2357  "dx ", "Cannot read");
2358  }
2359  } break;
2360  case 'w': {
2361  ut64 off = UT64_MAX;
2362  ut64 len = UT64_MAX;
2363  int fd = atoi(input + 2);
2364  char *str = strchr(input + 2, ' ');
2365  if (str)
2366  off = rz_num_math(core->num, str + 1);
2367  if (str)
2368  str = strchr(str + 1, ' ');
2369  if (str)
2370  len = rz_num_math(core->num, str + 1);
2371  if (len == UT64_MAX || off == UT64_MAX ||
2372  !rz_debug_desc_write(core->dbg, fd, off, len)) {
2373  RzBuffer *buf = rz_core_syscallf(core, "write", "%d, 0x%" PFMT64x ", %d", fd, off, (int)len);
2374  consumeBuffer(buf, "dx ", "Cannot write");
2375  }
2376  break;
2377  }
2378  case '-': // "dd-"
2379  {
2380  int fd = atoi(input + 2);
2381  // rz_core_cmdf (core, "dxs close %d", (int)rz_num_math ( core->num, input + 2));
2382  RzBuffer *buf = rz_core_syscallf(core, "close", "%d", fd);
2383  consumeBuffer(buf, "dx ", "Cannot close");
2384  break;
2385  }
2386  case ' ': // "dd"
2387  {
2388  // TODO: handle read, readwrite, append
2389  RzBuffer *buf = rz_core_syscallf(core, "open", "%s, %d, %d", input + 2, 2, 0644);
2390  consumeBuffer(buf, "dx ", "Cannot open");
2391  break;
2392  }
2393  case '?':
2394  default:
2396  break;
2397  }
2398  break;
2399  case 'H': // "dH"
2400  eprintf("TODO: transplant process\n");
2401  break;
2402  case 'p': // "dp"
2403  cmd_debug_pid(core, input);
2404  break;
2405  case 'i': // "di"
2406  {
2407  RzDebugInfo *rdi = rz_debug_info(core->dbg, input + 2);
2409  char *escaped_str;
2410  switch (input[1]) {
2411  case '\0': // "di"
2412 #define P rz_cons_printf
2413 #define PS(X, Y) \
2414  { \
2415  escaped_str = rz_str_escape(Y); \
2416  rz_cons_printf(X, escaped_str); \
2417  free(escaped_str); \
2418  }
2419  if (rdi) {
2420  const char *s = rz_signal_to_string(core->dbg->reason.signum);
2421  P("type=%s\n", rz_debug_reason_to_string(core->dbg->reason.type));
2422  P("signal=%s\n", s ? s : "none");
2423  P("signum=%d\n", core->dbg->reason.signum);
2424  P("sigpid=%d\n", core->dbg->reason.tid);
2425  P("addr=0x%" PFMT64x "\n", core->dbg->reason.addr);
2426  P("bp_addr=0x%" PFMT64x "\n", core->dbg->reason.bp_addr);
2427  P("inbp=%s\n", rz_str_bool(core->dbg->reason.bp_addr));
2428  P("baddr=0x%" PFMT64x "\n", rz_debug_get_baddr(core->dbg, NULL));
2429  P("pid=%d\n", rdi->pid);
2430  P("tid=%d\n", rdi->tid);
2431  P("stopaddr=0x%" PFMT64x "\n", core->dbg->stopaddr);
2432  if (rdi->uid != -1) {
2433  P("uid=%d\n", rdi->uid);
2434  }
2435  if (rdi->gid != -1) {
2436  P("gid=%d\n", rdi->gid);
2437  }
2438  if (rdi->usr) {
2439  P("usr=%s\n", rdi->usr);
2440  }
2441  if (rdi->exe && *rdi->exe) {
2442  P("exe=%s\n", rdi->exe);
2443  }
2444  if (rdi->cmdline && *rdi->cmdline) {
2445  P("cmdline=%s\n", rdi->cmdline);
2446  }
2447  if (rdi->cwd && *rdi->cwd) {
2448  P("cwd=%s\n", rdi->cwd);
2449  }
2450  if (rdi->kernel_stack && *rdi->kernel_stack) {
2451  P("kernel_stack=\n%s\n", rdi->kernel_stack);
2452  }
2453  }
2454  if (stop != -1) {
2455  P("stopreason=%d\n", stop);
2456  }
2457  break;
2458  case 'f': // "dif" "diff"
2459  if (input[1] == '?') {
2460  eprintf("Usage: dif $a $b # diff two alias files\n");
2461  } else {
2462  char *arg = strchr(input, ' ');
2463  if (arg) {
2465  char *arg2 = strchr(arg, ' ');
2466  if (arg2) {
2467  *arg2++ = 0;
2468  char *a = (char *)getFileData(core, arg);
2469  char *b = (char *)getFileData(core, arg2);
2470  if (a && b) {
2471  RzDiff *dff = rz_diff_lines_new(a, b, NULL);
2472  char *uni = rz_diff_unified_text(dff, arg, arg2, false, false);
2473  rz_diff_free(dff);
2474  rz_cons_printf("%s\n", uni);
2475  free(uni);
2476  } else {
2477  eprintf("Cannot open those alias files\n");
2478  }
2479  free(a);
2480  free(b);
2481  }
2482  free(arg);
2483  } else {
2484  eprintf("Usage: dif $a $b # diff two alias files\n");
2485  }
2486  }
2487  break;
2488  case '*': // "di*"
2489  if (rdi) {
2490  rz_cons_printf("f dbg.signal @ %d\n", core->dbg->reason.signum);
2491  rz_cons_printf("f dbg.sigpid @ %d\n", core->dbg->reason.tid);
2492  rz_cons_printf("f dbg.inbp @ %d\n", core->dbg->reason.bp_addr ? 1 : 0);
2493  rz_cons_printf("f dbg.sigaddr @ 0x%" PFMT64x "\n", core->dbg->reason.addr);
2494  rz_cons_printf("f dbg.baddr @ 0x%" PFMT64x "\n", rz_debug_get_baddr(core->dbg, NULL));
2495  rz_cons_printf("f dbg.pid @ %d\n", rdi->pid);
2496  rz_cons_printf("f dbg.tid @ %d\n", rdi->tid);
2497  rz_cons_printf("f dbg.uid @ %d\n", rdi->uid);
2498  rz_cons_printf("f dbg.gid @ %d\n", rdi->gid);
2499  }
2500  break;
2501  case 'j': // "dij"
2502  P("{");
2503  if (rdi) {
2504  const char *s = rz_signal_to_string(core->dbg->reason.signum);
2505  P("\"type\":\"%s\",", rz_debug_reason_to_string(core->dbg->reason.type));
2506  P("\"signal\":\"%s\",", s ? s : "none");
2507  P("\"signum\":%d,", core->dbg->reason.signum);
2508  P("\"sigpid\":%d,", core->dbg->reason.tid);
2509  P("\"addr\":%" PFMT64d ",", core->dbg->reason.addr);
2510  P("\"inbp\":%s,", rz_str_bool(core->dbg->reason.bp_addr));
2511  P("\"baddr\":%" PFMT64d ",", rz_debug_get_baddr(core->dbg, NULL));
2512  P("\"stopaddr\":%" PFMT64d ",", core->dbg->stopaddr);
2513  P("\"pid\":%d,", rdi->pid);
2514  P("\"tid\":%d,", rdi->tid);
2515  P("\"uid\":%d,", rdi->uid);
2516  P("\"gid\":%d,", rdi->gid);
2517  if (rdi->usr) {
2518  PS("\"usr\":\"%s\",", rdi->usr);
2519  }
2520  if (rdi->exe) {
2521  PS("\"exe\":\"%s\",", rdi->exe);
2522  }
2523  if (rdi->cmdline) {
2524  PS("\"cmdline\":\"%s\",", rdi->cmdline);
2525  }
2526  if (rdi->cwd) {
2527  PS("\"cwd\":\"%s\",", rdi->cwd);
2528  }
2529  }
2530  P("\"stopreason\":%d}\n", stop);
2531  break;
2532 #undef P
2533 #undef PS
2534  case 'q': {
2535  const char *r = rz_debug_reason_to_string(core->dbg->reason.type);
2536  if (!r) {
2537  r = "none";
2538  }
2539  rz_cons_printf("%s at 0x%08" PFMT64x "\n", r, core->dbg->stopaddr);
2540  } break;
2541  case '?': // "di?"
2542  default:
2544  break;
2545  }
2547  } break;
2548  case 'e': // "de"
2549  rz_core_debug_esil(core, input + 1);
2550  break;
2551  case 'g': // "dg"
2552  if (core->dbg->cur && core->dbg->cur->gcore) {
2553  if (core->dbg->pid == -1) {
2554  eprintf("Not debugging, can't write core.\n");
2555  break;
2556  }
2557  char *corefile = get_corefile_name(input + 1, core->dbg->pid);
2558  eprintf("Writing to file '%s'\n", corefile);
2559  rz_file_rm(corefile);
2560  RzBuffer *dst = rz_buf_new_file(corefile, O_RDWR | O_CREAT, 0644);
2561  if (dst) {
2562  if (!core->dbg->cur->gcore(core->dbg, corefile, dst)) {
2563  eprintf("dg: coredump failed\n");
2564  }
2565  rz_buf_free(dst);
2566  } else {
2567  perror("rz_buf_new_file");
2568  }
2569  free(corefile);
2570  }
2571  break;
2572  case 'k': // "dk"
2573  rz_core_debug_kill(core, input + 1);
2574  break;
2575 #if __WINDOWS__
2576  case 'W': // "dW"
2577  if (input[1] == 'i') {
2579  } else {
2580  rz_w32_print_windows(core->dbg);
2581  }
2582  break;
2583 #endif
2584  case 'w': // "dw"
2586  for (; !rz_cons_is_breaked();) {
2587  int pid = atoi(input + 1);
2588  // int opid = core->dbg->pid = pid;
2589  int res = rz_debug_kill(core->dbg, pid, 0, 0);
2590  if (!res) {
2591  break;
2592  }
2593  rz_sys_usleep(200);
2594  }
2596  break;
2597  case 'x': // "dx"
2598  switch (input[1]) {
2599  case ' ': { // "dx "
2600  ut8 bytes[4096];
2601  if (strlen(input + 2) < 4096) {
2602  int bytes_len = rz_hex_str2bin(input + 2, bytes);
2603  if (bytes_len > 0)
2604  rz_debug_execute(core->dbg,
2605  bytes, bytes_len, 0);
2606  else
2607  eprintf("Invalid hexpairs\n");
2608  } else
2609  eprintf("Injection opcodes so long\n");
2610  break;
2611  }
2612  case 'a': { // "dxa"
2613  RzAsmCode *acode;
2614  rz_asm_set_pc(core->rasm, core->offset);
2615  acode = rz_asm_massemble(core->rasm, input + 2);
2616  if (acode) {
2617  rz_reg_arena_push(core->dbg->reg);
2618  rz_debug_execute(core->dbg, acode->bytes, acode->len, 0);
2619  rz_reg_arena_pop(core->dbg->reg);
2620  }
2621  rz_asm_code_free(acode);
2622  break;
2623  }
2624  case 'e': { // "dxe"
2625  RzEgg *egg = core->egg;
2626  RzBuffer *b;
2627  const char *asm_arch = rz_config_get(core->config, "asm.arch");
2628  int asm_bits = rz_config_get_i(core->config, "asm.bits");
2629  const char *asm_os = rz_config_get(core->config, "asm.os");
2630  rz_egg_setup(egg, asm_arch, asm_bits, 0, asm_os);
2631  rz_egg_reset(egg);
2632  rz_egg_load(egg, input + 1, 0);
2633  rz_egg_compile(egg);
2634  b = rz_egg_get_bin(egg);
2635  rz_asm_set_pc(core->rasm, core->offset);
2636  rz_reg_arena_push(core->dbg->reg);
2637  ut64 tmpsz;
2638  const ut8 *tmp = rz_buf_data(b, &tmpsz);
2639  rz_debug_execute(core->dbg, tmp, tmpsz, 0);
2640  rz_reg_arena_pop(core->dbg->reg);
2641  break;
2642  }
2643  case 'r': // "dxr"
2644  rz_reg_arena_push(core->dbg->reg);
2645  if (input[2] == ' ') {
2646  ut8 bytes[4096];
2647  if (strlen(input + 2) < 4096) {
2648  int bytes_len = rz_hex_str2bin(input + 2,
2649  bytes);
2650  if (bytes_len > 0) {
2651  rz_debug_execute(core->dbg,
2652  bytes, bytes_len,
2653  0);
2654  } else {
2655  eprintf("Invalid hexpairs\n");
2656  }
2657  } else
2658  eprintf("Injection opcodes so long\n");
2659  }
2660  rz_reg_arena_pop(core->dbg->reg);
2661  break;
2662  case 's': // "dxs"
2663  if (input[2]) {
2664  char *str;
2665  str = rz_core_cmd_str(core, sdb_fmt("gs %s", input + 2));
2666  rz_core_cmdf(core, "dx %s", str); //`gs %s`", input + 2);
2667  free(str);
2668  } else {
2669  eprintf("Missing parameter used in gs by dxs\n");
2670  }
2671  break;
2672  case '?': // "dx?"
2673  default:
2675  break;
2676  }
2677  break;
2678  case '?': // "d?"
2679  default:
2681  break;
2682  }
2683  if (follow > 0) {
2685  }
2686  return 0;
2687 }
2688 
2689 // db
2691  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
2692  rz_core_debug_bp_add(core, core->offset, NULL, hwbp, false);
2693  return RZ_CMD_STATUS_OK;
2694 }
2695 
2696 // dbl
2700  RzListIter *iter;
2701  PJ *pj = state->d.pj;
2702  RzTable *t = state->d.t;
2704  rz_cmd_state_output_set_columnsf(state, "XXdsssssssss", "start", "end", "size",
2705  "perm", "hwsw", "type", "state", "valid", "cmd", "cond", "name", "module");
2706 
2707  rz_list_foreach (core->dbg->bp->bps, iter, b) {
2708  switch (state->mode) {
2710  rz_cons_printf("0x%08" PFMT64x " - 0x%08" PFMT64x
2711  " %d %s %s %s %s %s cmd=\"%s\" cond=\"%s\" "
2712  "name=\"%s\" module=\"%s\"\n",
2713  b->addr, b->addr + b->size, b->size,
2714  rz_str_rwx_i(b->perm),
2715  b->hw ? "hw" : "sw",
2716  b->trace ? "trace" : "break",
2717  b->enabled ? "enabled" : "disabled",
2718  rz_bp_is_valid(core->dbg->bp, b) ? "valid" : "invalid",
2719  rz_str_get(b->data),
2720  rz_str_get(b->cond),
2721  rz_str_get(b->name),
2722  rz_str_get(b->module_name));
2723  break;
2724  case RZ_OUTPUT_MODE_TABLE:
2725  rz_table_add_rowf(t, "XXdsssssssss", b->addr, b->addr + b->size, b->size,
2726  rz_str_rwx_i(b->perm), b->hw ? "hw" : "sw", b->trace ? "trace" : "break",
2727  b->enabled ? "enabled" : "disabled", rz_bp_is_valid(core->dbg->bp, b) ? "valid" : "invalid",
2728  rz_str_get(b->data), rz_str_get(b->cond), rz_str_get(b->name), rz_str_get(b->module_name));
2729  break;
2730  case RZ_OUTPUT_MODE_RIZIN:
2731  if (b->module_name) {
2732  rz_cons_printf("dbm %s %" PFMT64d "\n", b->module_name, b->module_delta);
2733  } else {
2734  rz_cons_printf("db @ 0x%08" PFMT64x "\n", b->addr);
2735  }
2736  break;
2737  case RZ_OUTPUT_MODE_JSON:
2738  pj_o(pj);
2739  pj_kN(pj, "addr", b->addr);
2740  pj_ki(pj, "size", b->size);
2741  pj_ks(pj, "perm", rz_str_rwx_i(b->perm));
2742  pj_kb(pj, "hw", b->hw);
2743  pj_kb(pj, "trace", b->trace);
2744  pj_kb(pj, "enabled", b->enabled);
2745  pj_kb(pj, "valid", rz_bp_is_valid(core->dbg->bp, b));
2746  pj_ks(pj, "data", rz_str_get(b->data));
2747  pj_ks(pj, "cond", rz_str_get(b->cond));
2748  pj_end(pj);
2749  break;
2750  case RZ_OUTPUT_MODE_QUIET:
2751  rz_cons_printf("0x%08" PFMT64x "\n", b->addr);
2752  break;
2753  default:
2755  break;
2756  }
2757  }
2759 
2760  return RZ_CMD_STATUS_OK;
2761 }
2762 
2763 // dbH
2765  rz_core_debug_bp_add(core, core->offset, NULL, true, false);
2766  return RZ_CMD_STATUS_OK;
2767 }
2768 
2769 // db-
2771  if (!rz_bp_del(core->dbg->bp, core->offset)) {
2772  RZ_LOG_ERROR("Failed to delete breakpoint at 0x%" PFMT64x "\n", core->offset);
2773  }
2774  return RZ_CMD_STATUS_OK;
2775 }
2776 
2777 // db-*
2779  if (!rz_bp_del_all(core->dbg->bp)) {
2780  RZ_LOG_ERROR("Failed to delete all breakpoints\n");
2781  return RZ_CMD_STATUS_ERROR;
2782  }
2783  return RZ_CMD_STATUS_OK;
2784 }
2785 
2786 // db.
2788  RzBreakpointItem *cur = rz_bp_get_at(core->dbg->bp, core->offset);
2789  if (!cur) {
2790  rz_cons_printf("No breakpoint found at current offset (0x%" PFMT64x ")\n", core->offset);
2791  return RZ_CMD_STATUS_ERROR;
2792  }
2793  rz_cons_printf("breakpoint %s %s %s\n", rz_str_rwx_i(cur->perm), cur->enabled ? "enabled" : "disabled", cur->name ? cur->name : "");
2794  return RZ_CMD_STATUS_OK;
2795 }
2796 
2797 // dbc
2799  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2800  if (!bp) {
2801  RZ_LOG_ERROR("No breakpoint defined at 0x%08" PFMT64x "\n", core->offset);
2802  return RZ_CMD_STATUS_ERROR;
2803  }
2804  if (!rz_bp_item_set_data(bp, argv[1])) {
2805  RZ_LOG_ERROR("Failed to set data for breakpoint at 0x%08" PFMT64x "\n", core->offset);
2806  return RZ_CMD_STATUS_ERROR;
2807  }
2808  return RZ_CMD_STATUS_OK;
2809 }
2810 
2811 // dbC
2813  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2814  if (!bp) {
2815  RZ_LOG_ERROR("No breakpoint defined at 0x%08" PFMT64x "\n", core->offset);
2816  return RZ_CMD_STATUS_ERROR;
2817  }
2818  if (!rz_bp_item_set_cond(bp, argv[1])) {
2819  RZ_LOG_ERROR("Failed to set condition for breakpoint at 0x%08" PFMT64x "\n", core->offset);
2820  return RZ_CMD_STATUS_ERROR;
2821  }
2822  return RZ_CMD_STATUS_OK;
2823 }
2824 
2825 // dbd
2827  if (!rz_bp_enable(core->dbg->bp, core->offset, false, 1)) {
2828  RZ_LOG_ERROR("Failed to disable breakpoint at 0x%" PFMT64x "\n", core->offset);
2829  }
2830  return RZ_CMD_STATUS_OK;
2831 }
2832 
2833 // dbe
2835  if (!rz_bp_enable(core->dbg->bp, core->offset, true, 1)) { // correct value of count?
2836  RZ_LOG_ERROR("Failed to enable breakpoint at 0x%" PFMT64x "\n", core->offset);
2837  }
2838  return RZ_CMD_STATUS_OK;
2839 }
2840 
2841 // dbs
2844  return RZ_CMD_STATUS_OK;
2845 }
2846 
2847 // dbf
2850  return RZ_CMD_STATUS_OK;
2851 }
2852 
2853 // dbm
2855  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
2856  ut64 delta = rz_num_math(core->num, argv[2]);
2857  RzBreakpointItem *bp = rz_debug_bp_add(core->dbg, 0, hwbp, false, 0, argv[1], delta);
2858  if (!bp) {
2859  RZ_LOG_ERROR("Cannot set breakpoint.\n");
2860  }
2861  return RZ_CMD_STATUS_OK;
2862 }
2863 
2864 // dbn
2866  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2867  if (!bp) {
2868  RZ_LOG_ERROR("No breakpoint found at 0x%08" PFMT64x "\n", core->offset);
2869  return RZ_CMD_STATUS_ERROR;
2870  } else if (argc == 1) {
2871  if (bp->name) {
2872  rz_cons_println(bp->name);
2873  }
2874  } else if (argc == 2) {
2875  rz_bp_item_set_name(bp, argv[1]);
2876  }
2877  return RZ_CMD_STATUS_OK;
2878 }
2879 
2880 // dbi
2882  const int index = rz_bp_get_index_at(core->dbg->bp, core->offset);
2883  if (index == -1) {
2884  RZ_LOG_ERROR("No breakpoint found at %" PFMT64x "\n", core->offset);
2885  } else {
2886  rz_cons_printf("%d\n", index);
2887  }
2888  return RZ_CMD_STATUS_OK;
2889 }
2890 
2891 // dbil
2893  RzBreakpointItem *bpi;
2894  RzListIter *iter;
2895  unsigned int index = 0;
2896  rz_list_foreach (core->dbg->bp->bps, iter, bpi) {
2897  if (!bpi) {
2898  RZ_LOG_ERROR("Unable to find breakpoint at index %d\n", index);
2899  } else {
2900  rz_cons_printf("%d 0x%08" PFMT64x " E:%d T:%d\n", index, bpi->addr, bpi->enabled, bpi->trace);
2901  }
2902  index++;
2903  }
2904  return RZ_CMD_STATUS_OK;
2905 }
2906 
2907 // dbi-
2909  ut64 addr;
2910  for (int i = 1; i < argc; i++) {
2911  addr = rz_num_math(core->num, argv[i]);
2912  if (!rz_bp_del_index(core->dbg->bp, addr)) {
2913  RZ_LOG_ERROR("No breakpoint found at %" PFMT64x "\n", addr);
2914  }
2915  }
2916  return RZ_CMD_STATUS_OK;
2917 }
2918 
2919 // dbix
2921  int index = rz_num_math(core->num, argv[1]);
2922  RzBreakpointItem *bpi = rz_bp_get_index(core->dbg->bp, index);
2923  rz_bp_item_set_expr(bpi, argv[2]);
2924  return RZ_CMD_STATUS_OK;
2925 }
2926 
2927 // dbic
2929  int index = rz_num_math(core->num, argv[1]);
2930  RzBreakpointItem *bpi = rz_bp_get_index(core->dbg->bp, index);
2931  rz_bp_item_set_data(bpi, argv[2]);
2932  return RZ_CMD_STATUS_OK;
2933 }
2934 
2935 // dbie
2937  RzBreakpointItem *bpi;
2938  int index = rz_num_math(core->num, argv[1]);
2939  bpi = rz_bp_get_index(core->dbg->bp, index);
2940  if (!bpi) {
2941  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2942  return RZ_CMD_STATUS_ERROR;
2943  }
2944  bpi->enabled = true;
2945  return RZ_CMD_STATUS_OK;
2946 }
2947 
2948 // dbid
2950  RzBreakpointItem *bpi;
2951  int index = rz_num_math(core->num, argv[1]);
2952  bpi = rz_bp_get_index(core->dbg->bp, index);
2953  if (!bpi) {
2954  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2955  return RZ_CMD_STATUS_ERROR;
2956  }
2957  bpi->enabled = false;
2958  return RZ_CMD_STATUS_OK;
2959 }
2960 
2961 // dbis
2963  RzBreakpointItem *bpi;
2964  int index = rz_num_math(core->num, argv[1]);
2965  bpi = rz_bp_get_index(core->dbg->bp, index);
2966  if (!bpi) {
2967  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2968  return RZ_CMD_STATUS_ERROR;
2969  }
2970  bpi->enabled = !bpi->enabled;
2971  return RZ_CMD_STATUS_OK;
2972 }
2973 
2974 // dbite
2976  RzBreakpointItem *bpi;
2977  int index = rz_num_math(core->num, argv[1]);
2978  bpi = rz_bp_get_index(core->dbg->bp, index);
2979  if (!bpi) {
2980  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2981  return RZ_CMD_STATUS_ERROR;
2982  }
2983  bpi->trace = true;
2984  return RZ_CMD_STATUS_OK;
2985 }
2986 
2987 // dbitd
2989  RzBreakpointItem *bpi;
2990  int index = rz_num_math(core->num, argv[1]);
2991  bpi = rz_bp_get_index(core->dbg->bp, index);
2992  if (!bpi) {
2993  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2994  return RZ_CMD_STATUS_ERROR;
2995  }
2996  bpi->trace = false;
2997  return RZ_CMD_STATUS_OK;
2998 }
2999 
3000 // dbits
3002  RzBreakpointItem *bpi;
3003  int index = rz_num_math(core->num, argv[1]);
3004  bpi = rz_bp_get_index(core->dbg->bp, index);
3005  if (!bpi) {
3006  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
3007  return RZ_CMD_STATUS_ERROR;
3008  }
3009  bpi->trace = !bpi->enabled;
3010  return RZ_CMD_STATUS_OK;
3011 }
3012 
3013 // dbh
3015  if (argc == 1) {
3016  rz_bp_plugin_list(core->dbg->bp);
3017  } else if (argc == 2) {
3018  if (!rz_bp_use(core->dbg->bp, argv[1])) {
3019  RZ_LOG_ERROR("Failed to set breakpoint plugin handler to %s\n", argv[1]);
3020  return RZ_CMD_STATUS_ERROR;
3021  }
3022  }
3023  return RZ_CMD_STATUS_OK;
3024 }
3025 
3026 // dbh-
3028  for (int i = 1; i < argc; i++) {
3029  if (!rz_bp_plugin_del(core->dbg->bp, argv[i])) {
3030  RZ_LOG_ERROR("Failed to delete breakpoint plugin handler: %s\n", argv[i]);
3031  }
3032  }
3033  return RZ_CMD_STATUS_OK;
3034 }
3035 
3036 // dbt
3039  if (!list) {
3040  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3041  return RZ_CMD_STATUS_ERROR;
3042  }
3043  RzOutputMode mode = state->mode;
3044  if (mode == RZ_OUTPUT_MODE_RIZIN) {
3046  rz_cons_printf("f-bt.*\n");
3047  }
3048 
3049  int i = 0;
3050  RzListIter *iter;
3051  RzBacktrace *bt;
3052  PJ *pj = state->d.pj;
3054  rz_list_foreach (list, iter, bt) {
3055  switch (mode) {
3056  case RZ_OUTPUT_MODE_STANDARD: {
3057  rz_cons_printf("%d %s sp: %s %-5d"
3058  "[%s] %s %s\n",
3059  i++, bt->pcstr, bt->spstr, bt->frame->size, bt->fcn ? bt->fcn->name : "??", rz_str_get(bt->flagdesc), rz_str_get(bt->flagdesc2));
3060  break;
3061  }
3062  case RZ_OUTPUT_MODE_RIZIN: {
3063  rz_cons_printf("f bt.frame%d @ 0x%08" PFMT64x "\n", i, bt->frame->addr);
3064  rz_cons_printf("f bt.frame%d.stack %d @ 0x%08" PFMT64x "\n", i, bt->frame->size, bt->frame->sp);
3065  i++;
3066  break;
3067  }
3068  case RZ_OUTPUT_MODE_JSON: {
3069  pj_o(pj);
3070  pj_ki(pj, "idx", i);
3071  pj_kn(pj, "pc", bt->frame->addr);
3072  pj_kn(pj, "sp", bt->frame->sp);
3073  pj_ki(pj, "frame_size", bt->frame->size);
3074  pj_ks(pj, "fname", bt->fcn ? bt->fcn->name : "");
3075  pj_ks(pj, "desc", bt->desc);
3076  pj_end(pj);
3077  i++;
3078  break;
3079  }
3080  case RZ_OUTPUT_MODE_QUIET: {
3081  rz_cons_printf("%s\n", bt->pcstr);
3082  break;
3083  }
3084  default:
3086  break;
3087  }
3088  }
3090  rz_list_free(list);
3091  return RZ_CMD_STATUS_OK;
3092 }
3093 
3094 // dbt=
3096  int mode = 0;
3097  if (argc > 1) {
3098  if (!strcmp(argv[1], "b")) {
3099  mode = 1;
3100  } else if (!strcmp(argv[1], "s")) {
3101  mode = 2;
3102  }
3103  }
3104  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3105  if (!list) {
3106  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3107  return RZ_CMD_STATUS_ERROR;
3108  }
3109  int i = 0;
3110  RzListIter *iter;
3111  RzDebugFrame *frame;
3113  rz_list_foreach (list, iter, frame) {
3114  if (i != 0) {
3115  rz_cons_printf(" ");
3116  }
3117  switch (mode) {
3118  case 0:
3119  rz_cons_printf("0x08%" PFMT64x, frame->addr);
3120  break;
3121  case 1:
3122  rz_cons_printf("0x08%" PFMT64x, frame->bp);
3123  break;
3124  case 2:
3125  rz_cons_printf("0x08%" PFMT64x, frame->sp);
3126  break;
3127  }
3128  }
3129  rz_cons_newline();
3130  rz_list_free(list);
3131  return RZ_CMD_STATUS_OK;
3132 }
3133 
3134 // dbtv
3136  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3137  if (!list) {
3138  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3139  return RZ_CMD_STATUS_ERROR;
3140  }
3141  backtrace_vars(core, list);
3142  rz_list_free(list);
3143  return RZ_CMD_STATUS_OK;
3144 }
3145 
3146 // dbta
3148  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3149  if (!list) {
3150  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3151  return RZ_CMD_STATUS_ERROR;
3152  }
3153  asciiart_backtrace(core, list);
3154  rz_list_free(list);
3155  return RZ_CMD_STATUS_OK;
3156 }
3157 
3158 // dbte
3160  if (!rz_bp_set_trace(core->dbg->bp, core->offset, true)) {
3161  RZ_LOG_ERROR("Failed to enable trace for breakpoint at 0x%" PFMT64x "\n", core->offset);
3162  }
3163  return RZ_CMD_STATUS_OK;
3164 }
3165 
3166 // dbtd
3168  if (!rz_bp_set_trace(core->dbg->bp, core->offset, false)) {
3169  RZ_LOG_ERROR("Failed to enable trace for breakpoint at 0x%" PFMT64x "\n", core->offset);
3170  }
3171  return RZ_CMD_STATUS_OK;
3172 }
3173 
3174 // dbts
3176  RzBreakpointItem *bpi = rz_bp_get_in(core->dbg->bp, core->offset, 0);
3177  if (!bpi) {
3178  RZ_LOG_ERROR("No breakpoint found at 0x%" PFMT64x "\n", core->offset);
3179  } else {
3180  bpi->trace = !bpi->trace;
3181  }
3182  return RZ_CMD_STATUS_OK;
3183 }
3184 
3185 // dbx
3187  if (argc == 1) {
3188  RzBreakpointItem *bpi;
3189  RzListIter *iter;
3190  rz_list_foreach (core->dbg->bp->bps, iter, bpi) {
3191  rz_cons_printf("0x%08" PFMT64x " %s\n", bpi->addr, rz_str_get(bpi->expr));
3192  }
3193  } else if (argc == 2) {
3194  RzBreakpointItem *bpi = rz_bp_get_at(core->dbg->bp, core->offset);
3195  if (!bpi) {
3196  RZ_LOG_ERROR("No breakpoint found at current offset: 0x%" PFMT64x "\n", core->offset);
3197  return RZ_CMD_STATUS_ERROR;
3198  }
3199  if (!rz_bp_item_set_expr(bpi, argv[1])) {
3200  RZ_LOG_ERROR("Failed to set expression\n");
3201  return RZ_CMD_STATUS_ERROR;
3202  }
3203  }
3204  return RZ_CMD_STATUS_OK;
3205 }
3206 
3207 // dbw
3209  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
3210  rz_core_debug_bp_add(core, core->offset, argv[1], hwbp, true);
3211  return RZ_CMD_STATUS_OK;
3212 }
3213 
3214 // dbW
3216 #if __WINDOWS__
3217  bool res;
3218  if (argc > 2) {
3219  res = rz_w32_add_winmsg_breakpoint(core->dbg, argv[1], argv[2]);
3220  } else {
3221  res = rz_w32_add_winmsg_breakpoint(core->dbg, argv[1], NULL);
3222  }
3223  if (res) {
3224  rz_cons_print("Breakpoint set.\n");
3225  } else {
3226  rz_cons_print("Breakpoint not set.\n");
3227  }
3228 #else
3229  RZ_LOG_ERROR("This command is only meant for Windows systems and cannot be used by your system\n");
3230 #endif
3231 
3232  return RZ_CMD_STATUS_OK;
3233 }
3234 
3235 // dc
3237  CMD_CHECK_DEBUG_DEAD(core);
3239 
3240  if (argc == 2) {
3241  int old_pid = core->dbg->pid;
3242  // using rz_num instead of atoi
3243  int pid = rz_num_math(core->num, argv[1]);
3244  rz_debug_select(core->dbg, pid, core->dbg->tid);
3245  rz_core_debug_continue(core);
3246  rz_debug_select(core->dbg, old_pid, core->dbg->tid);
3247  } else {
3248  rz_core_debug_continue(core);
3249  }
3250 
3253  return RZ_CMD_STATUS_OK;
3254 }
3255 
3256 // dcb
3258  CMD_CHECK_DEBUG_DEAD(core);
3260 
3261  if (!rz_debug_continue_back(core->dbg)) {
3262  eprintf("cannot continue back\n");
3263  return RZ_CMD_STATUS_ERROR;
3264  }
3265 
3268  return RZ_CMD_STATUS_OK;
3269 }
3270 
3271 // dcc
3273  CMD_CHECK_DEBUG_DEAD(core);
3275  rz_reg_arena_swap(core->dbg->reg, true);
3276 
3278 
3281  return RZ_CMD_STATUS_OK;
3282 }
3283 
3284 // dccu
3286  CMD_CHECK_DEBUG_DEAD(core);
3288 
3290 
3293  return RZ_CMD_STATUS_OK;
3294 }
3295 
3296 // dce
3298  CMD_CHECK_DEBUG_DEAD(core);
3300  rz_reg_arena_swap(core->dbg->reg, true);
3304  return RZ_CMD_STATUS_OK;
3305 }
3306 
3307 // dcf
3309  CMD_CHECK_DEBUG_DEAD(core);
3311 
3312  eprintf("[+] Running 'dcs vfork fork clone' behind the scenes...\n");
3313  // we should stop in fork, vfork, and clone syscalls
3314  cmd_debug_cont_syscall(core, "vfork fork clone");
3315 
3318  return RZ_CMD_STATUS_OK;
3319 }
3320 
3321 // dck
3323  CMD_CHECK_DEBUG_DEAD(core);
3325 
3326  rz_reg_arena_swap(core->dbg->reg, true);
3327  int signum = rz_num_math(core->num, argv[1]);
3328 
3329  if (argc == 3) {
3330  int old_pid = core->dbg->pid;
3331  int old_tid = core->dbg->tid;
3332  int pid = rz_num_math(core->num, argv[2]);
3333  int tid = pid; // XXX
3334  rz_debug_select(core->dbg, pid, tid);
3336  rz_debug_select(core->dbg, old_pid, old_tid);
3337  } else {
3339  }
3340 
3343  return RZ_CMD_STATUS_OK;
3344 }
3345 
3346 // dcp
3348  CMD_CHECK_DEBUG_DEAD(core);
3350  RzIOMap *s;
3351  ut64 pc;
3352  int n = 0;
3353  bool t = core->dbg->trace->enabled;
3354  core->dbg->trace->enabled = false;
3356  do {
3357  rz_debug_step(core->dbg, 1);
3358  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
3359  pc = rz_debug_reg_get(core->dbg, "PC");
3360  eprintf(" %d %" PFMT64x "\r", n++, pc);
3361  s = rz_io_map_get(core->io, pc);
3362  if (rz_cons_is_breaked()) {
3363  break;
3364  }
3365  } while (!s);
3366  eprintf("\n");
3367  core->dbg->trace->enabled = t;
3369  return RZ_CMD_STATUS_OK;
3370 }
3371 
3372 // dcr
3374  CMD_CHECK_DEBUG_DEAD(core);
3376 
3377  rz_reg_arena_swap(core->dbg->reg, true);
3379 
3382  return RZ_CMD_STATUS_OK;
3383 }
3384 
3385 // dct
3387  CMD_CHECK_DEBUG_DEAD(core);
3389  if (argc == 1) {
3390  cmd_debug_backtrace(core, 0);
3391  } else {
3392  cmd_debug_backtrace(core, rz_num_math(core->num, argv[1]));
3393  }
3396  return RZ_CMD_STATUS_OK;
3397 }
3398 
3399 // dcs
3400 RZ_IPI int rz_cmd_debug_continue_syscall(void *data, const char *input) {
3401  RzCore *core = (RzCore *)data;
3402  CMD_CHECK_DEBUG_DEAD(core);
3404  switch (input[0]) {
3405  case '*':
3406  cmd_debug_cont_syscall(core, "-1");
3407  break;
3408  case ' ':
3409  cmd_debug_cont_syscall(core, input + 2);
3410  break;
3411  case '\0':
3413  break;
3414  default:
3415  case '?':
3417  break;
3418  }
3421  return RZ_CMD_STATUS_OK;
3422 }
3423 
3424 // dcu
3425 RZ_IPI int rz_cmd_debug_continue_until(void *data, const char *input) {
3426  RzCore *core = (RzCore *)data;
3427  CMD_CHECK_DEBUG_DEAD(core);
3429  if (input[0] == '?') {
3431  } else if (input[0] == '.' || input[0] == '\0') {
3432  cmd_dcu(core, "cu $$");
3433  } else {
3434  char *tmpinp = rz_str_newf("cu %s", input + 1);
3435  cmd_dcu(core, tmpinp);
3436  free(tmpinp);
3437  }
3440  return RZ_CMD_STATUS_OK;
3441 }
3442 
3444  return rz_core_debug_plugins_print(core, state);
3445 }
3446 
3448  return bool2status(rz_config_set(core->config, "dbg.backend", argv[1]));
3449 }
3450 
3451 // dor
3453  RzList *list = rz_list_new();
3454  int i;
3455  for (i = 1; i < argc; i++) {
3456  RzList *l = rz_str_split_duplist_n(argv[i], "=", 1, false);
3457  if (!l) {
3458  rz_list_free(list);
3459  return RZ_CMD_STATUS_ERROR;
3460  }
3461  size_t llen = rz_list_length(l);
3462  if (llen < 2) {
3463  rz_list_free(list);
3464  rz_list_free(l);
3465  return RZ_CMD_STATUS_ERROR;
3466  }
3467  char *key = rz_list_get_n(l, 0);
3468  char *val = rz_list_get_n(l, 1);
3469  if (RZ_STR_ISEMPTY(key) || RZ_STR_ISEMPTY(val)) {
3470  RZ_LOG_ERROR("Make sure to use the format <key>=<value> without spaces.\n");
3471  rz_list_free(l);
3472  continue;
3473  }
3474  rz_list_append(list, (void *)argv[i]);
3475  rz_list_free(l);
3476  }
3477  char *str = rz_list_to_str(list, '\n');
3478  set_profile_string(core, str);
3479  free(str);
3480  rz_list_free(list);
3481  return RZ_CMD_STATUS_OK;
3482 }
3483 
3484 // doe
3486  char *out = rz_core_editor(core, NULL, core->io->envprofile);
3487  if (!out) {
3488  return RZ_CMD_STATUS_ERROR;
3489  }
3490  free(core->io->envprofile);
3491  core->io->envprofile = out;
3492  rz_cons_printf("%s\n", core->io->envprofile);
3493  return RZ_CMD_STATUS_OK;
3494 }
3495 
3496 // doc
3498  CMD_CHECK_DEBUG_DEAD(core);
3500 }
3501 
3502 // ds
3503 RZ_IPI RzCmdStatus rz_cmd_debug_step_handler(RzCore *core, int argc, const char **argv) {
3504  const int times = (int)rz_num_math(core->num, argv[1]);
3505  bool ret = rz_core_debug_step_one(core, times);
3507  return bool2status(ret);
3508 }
3509 
3510 // dsb
3512  CMD_CHECK_DEBUG_DEAD(core);
3513  const int times = (int)rz_num_math(core->num, argv[1]);
3514  bool ret = rz_core_debug_step_back(core, times);
3516  return bool2status(ret);
3517 }
3518 
3519 // dsf
3521  CMD_CHECK_DEBUG_DEAD(core);
3522  bool ret = rz_core_debug_step_until_frame(core);
3524  return bool2status(ret);
3525 }
3526 
3527 // dsi
3529  CMD_CHECK_DEBUG_DEAD(core);
3530  int n = 0;
3532  do {
3533  if (rz_cons_is_breaked()) {
3534  break;
3535  }
3536  rz_debug_step(core->dbg, 1);
3537  if (rz_debug_is_dead(core->dbg)) {
3538  core->break_loop = true;
3539  break;
3540  }
3542  n++;
3543  } while (!rz_num_conditional(core->num, argv[1]));
3545  RZ_LOG_INFO("stopped after %d instructions\n", n);
3547  return RZ_CMD_STATUS_OK;
3548 }
3549 
3550 // dsl
3552  CMD_CHECK_DEBUG_DEAD(core);
3553  const int times = (int)rz_num_math(core->num, argv[1]);
3554  rz_reg_arena_swap(core->dbg->reg, true);
3555  bool ret = step_line(core, times);
3557  return bool2status(ret);
3558 }
3559 
3560 // dso
3562  CMD_CHECK_DEBUG_DEAD(core);
3563  const int times = (int)rz_num_math(core->num, argv[1]);
3564  bool ret = rz_core_debug_step_over(core, times);
3566  return bool2status(ret);
3567 }
3568 
3569 // dsp
3571  CMD_CHECK_DEBUG_DEAD(core);
3572  const int times = (int)rz_num_math(core->num, argv[1]);
3573  rz_reg_arena_swap(core->dbg->reg, true);
3574  ut8 buf[64];
3575  for (int i = 0; i < times; i++) {
3576  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
3577  ut64 addr = rz_debug_reg_get(core->dbg, "PC");
3578  rz_io_read_at(core->io, addr, buf, sizeof(buf));
3579  RzAnalysisOp aop;
3580  rz_analysis_op(core->analysis, &aop, addr, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC);
3581  if (aop.type == RZ_ANALYSIS_OP_TYPE_CALL) {
3582  RzBinObject *o = rz_bin_cur_object(core->bin);
3583  RzBinSection *s = rz_bin_get_section_at(o, aop.jump, true);
3584  if (!s) {
3585  rz_debug_step_over(core->dbg, times);
3586  continue;
3587  }
3588  }
3589  rz_debug_step(core->dbg, 1);
3590  }
3593  return RZ_CMD_STATUS_OK;
3594 }
3595 
3596 // dss
3598  CMD_CHECK_DEBUG_DEAD(core);
3599  const int times = (int)rz_num_math(core->num, argv[1]);
3600  bool ret = rz_core_debug_step_skip(core, times);
3602  return bool2status(ret);
3603 }
3604 
3605 #define CMD_REGS_PREFIX debug
3606 #define CMD_REGS_REG_PATH dbg->reg
3607 static bool cmd_regs_sync(RzCore *core, RzRegisterType type, bool write) {
3608  return rz_debug_reg_sync(core->dbg, type, write);
3609 }
3610 #define CMD_REGS_SYNC cmd_regs_sync
3611 #include "cmd_regs_meta.inc"
3612 #undef CMD_REGS_PREFIX
3613 #undef CMD_REGS_REG_PATH
3614 #undef CMD_REGS_SYNC
3615 
3617  const RzList *list = rz_reg_get_list(core->dbg->reg, RZ_REG_TYPE_GPR);
3619 }
3620 
3621 RZ_IPI RzCmdStatus rz_debug_drx_handler(RzCore *core, int argc, const char **argv) {
3622  if (argc <= 1) {
3623  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3624  rz_debug_drx_list(core->dbg);
3625  return RZ_CMD_STATUS_OK;
3626  }
3627  if (argc != 5) {
3628  return RZ_CMD_STATUS_WRONG_ARGS;
3629  }
3630  int n = (int)rz_num_math(core->num, argv[1]);
3631  ut64 off = rz_num_math(core->num, argv[2]);
3632  int len = (int)rz_num_math(core->num, argv[3]);
3633  int perm = rz_str_rwx(argv[4]);
3634  if (len == -1) {
3635  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3636  rz_debug_drx_set(core->dbg, n, 0, 0, 0, 0);
3637  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3638  } else {
3639  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3640  rz_debug_drx_set(core->dbg, n, off, len, perm, 0);
3641  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3642  }
3643  return RZ_CMD_STATUS_OK;
3644 }
3645 
3646 RZ_IPI RzCmdStatus rz_debug_drx_unset_handler(RzCore *core, int argc, const char **argv) {
3648  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3649  rz_debug_drx_unset(core->dbg, atoi(argv[1] + 2));
3650  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3651  return RZ_CMD_STATUS_OK;
3652 }
size_t len
Definition: 6502dis.c:15
ut8 op
Definition: 6502dis.c:13
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
static char * regs[]
Definition: analysis_sh.c:203
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
lzma_index ** i
Definition: index.h:629
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236
RZ_API void rz_reg_arena_pop(RzReg *reg)
Definition: arena.c:216
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
ut16 val
Definition: armass64_const.h:6
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
static ut8 bytes[32]
Definition: asm_arc.c:23
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API RzBinFile * rz_bin_open_io(RzBin *bin, RzBinOptions *opt)
Definition: bin.c:283
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
Definition: bin.c:696
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_set_baddr(RzBin *bin, ut64 baddr)
Definition: bin.c:549
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API bool rz_bp_is_valid(RzBreakpoint *bp, RzBreakpointItem *b)
Definition: bp.c:406
RZ_API int rz_bp_del_index(RzBreakpoint *bp, int idx)
Definition: bp.c:364
RZ_API RzBreakpointItem * rz_bp_get_in(RzBreakpoint *bp, ut64 addr, int perm)
Definition: bp.c:139
RZ_API RzBreakpointItem * rz_bp_get_index(RzBreakpoint *bp, int idx)
Definition: bp.c:347
RZ_API int rz_bp_get_index_at(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:354
RZ_API int rz_bp_set_trace(RzBreakpoint *bp, ut64 addr, int set)
Definition: bp.c:329
RZ_API bool rz_bp_item_set_data(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *data)
set the data for a RzBreakpointItem
Definition: bp.c:445
RZ_API RZ_BORROW RzBreakpointItem * rz_bp_get_at(RZ_NONNULL RzBreakpoint *bp, ut64 addr)
Get the breakpoint at exactly addr.
Definition: bp.c:102
RZ_API bool rz_bp_del(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:315
RZ_API bool rz_bp_del_all(RzBreakpoint *bp)
Definition: bp.c:303
RZ_API RzBreakpointItem * rz_bp_enable(RzBreakpoint *bp, ut64 addr, int set, int count)
Definition: bp.c:152
RZ_API bool rz_bp_item_set_cond(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *cond)
set the condition for a RzBreakpointItem
Definition: bp.c:423
RZ_API bool rz_bp_item_set_name(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *name)
set the name for a RzBreakpointItem
Definition: bp.c:489
RZ_API bool rz_bp_item_set_expr(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *expr)
set the expr for a RzBreakpointItem
Definition: bp.c:467
RZ_API void rz_bp_plugin_list(RzBreakpoint *bp)
Definition: bp_plugin.c:61
RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name)
Definition: bp_plugin.c:47
RZ_API int rz_bp_plugin_del(RzBreakpoint *bp, const char *name)
Definition: bp_plugin.c:6
RZ_API int rz_bp_traptrace_at(RzBreakpoint *bp, ut64 from, int len)
Definition: bp_traptrace.c:161
RZ_API void rz_bp_traptrace_list(RzBreakpoint *bp)
Definition: bp_traptrace.c:148
RZ_API void rz_bp_traptrace_enable(RzBreakpoint *bp, int enable)
Definition: bp_traptrace.c:25
RZ_API int rz_bp_traptrace_add(RzBreakpoint *bp, ut64 from, ut64 to)
Definition: bp_traptrace.c:71
RZ_API void rz_bp_traptrace_reset(RzBreakpoint *bp, int hard)
Definition: bp_traptrace.c:34
RZ_IPI void rz_core_agraph_print_interactive(RzCore *core)
Definition: cagraph.c:88
RZ_IPI void rz_core_agraph_reset(RzCore *core)
Definition: cagraph.c:8
RZ_IPI char * rz_core_analysis_all_vars_display(RzCore *core, RzAnalysisFunction *fcn, bool add_name)
Definition: canalysis.c:6206
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
RZ_API bool rz_core_bin_apply_info(RzCore *r, RzBinFile *binfile, ut32 mask)
Definition: cbin.c:261
RZ_API bool rz_core_bin_print(RzCore *core, RZ_NONNULL RzBinFile *bf, ut32 mask, RzCoreBinFilter *filter, RzCmdStateOutput *state, RzList *hashes)
Print (to RzCons or inside RzCmdStateOutput) the binary information specified in mask.
Definition: cbin.c:386
RZ_API void rz_core_debug_bp_add_noreturn_func(RzCore *core)
Put a breakpoint into every no-return function.
Definition: cdebug.c:256
RZ_API void rz_core_debug_map_print(RzCore *core, ut64 addr, RzCmdStateOutput *state)
Definition: cdebug.c:481
RZ_API bool rz_core_debug_step_over(RzCore *core, int steps)
Step over.
Definition: cdebug.c:802
RZ_API void rz_core_debug_breakpoint_toggle(RZ_NONNULL RzCore *core, ut64 addr)
Toggle breakpoint.
Definition: cdebug.c:235
RZ_API bool rz_core_debug_step_skip(RzCore *core, int times)
Skip operations.
Definition: cdebug.c:831
RZ_API bool rz_core_debug_step_back(RzCore *core, int steps)
Step back.
Definition: cdebug.c:777
RZ_IPI void rz_core_debug_continue(RzCore *core)
Definition: cdebug.c:81
RZ_API bool rz_core_debug_step_until_frame(RzCore *core)
Step until end of frame.
Definition: cdebug.c:745
RZ_API void rz_debug_trace_print(RzDebug *dbg, RzCmdStateOutput *state, ut64 offset)
Definition: cdebug.c:658
RZ_IPI void rz_core_debug_sync_bits(RzCore *core)
Definition: cdebug.c:184
RZ_API void rz_debug_map_list_visual(RzDebug *dbg, ut64 addr, const char *input, int colors)
Definition: cdebug.c:638
RZ_API RZ_OWN RzList * rz_core_debug_backtraces(RzCore *core)
Get backtraces based on dbg.btdepth and dbg.btalgo.
Definition: cdebug.c:926
RZ_API void rz_debug_traces_ascii(RzDebug *dbg, ut64 offset)
Definition: cdebug.c:688
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to)
Definition: cdebug.c:98
RZ_API bool rz_core_debug_process_close(RzCore *core)
Close debug process (Kill debugee and all child processes)
Definition: cdebug.c:707
RZ_API RzCmdStatus rz_core_debug_plugins_print(RzCore *core, RzCmdStateOutput *state)
Definition: cdebug.c:329
RZ_IPI void rz_core_debug_attach(RzCore *core, int pid)
Definition: cdebug.c:284
RZ_API bool rz_core_debug_step_one(RzCore *core, int times)
Definition: cdebug.c:56
RZ_IPI void rz_core_analysis_esil_init(RzCore *core)
Definition: cil.c:43
RZ_API void rz_core_analysis_esil_reinit(RZ_NONNULL RzCore *core)
Reinitialize ESIL.
Definition: cil.c:54
RZ_API bool rz_core_dump(RzCore *core, const char *file, ut64 addr, ut64 size, int append)
Definition: cio.c:50
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 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 int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver)
Definition: cmd_analysis.c:860
RZ_IPI int rz_output_mode_to_char(RzOutputMode mode)
Definition: cmd_api.c:73
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
Definition: cmd_api.c:2634
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
Definition: cmd_api.c:2603
RZ_API char * rz_cmd_alias_get(RzCmd *cmd, const char *k, int remote)
Definition: cmd_api.c:501
static int value
Definition: cmd_api.c:93
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
Definition: cmd_api.c:2668
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_IPI RzCmdStatus rz_cmd_debug_traces_reset_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2119
RZ_IPI int rz_cmd_debug(void *data, const char *input)
Definition: cmd_debug.c:2289
RZ_IPI RzCmdStatus rz_cmd_debug_add_hw_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2764
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_optype_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2037
RZ_IPI RzCmdStatus rz_cmd_debug_dmS_handler(RzCore *core, int argc, const char **argv, RzOutputMode m)
Definition: cmd_debug.c:1318
static void cmd_debug_current_modules(RzCore *core, RzOutputMode mode)
Definition: cmd_debug.c:861
RZ_IPI RzCmdStatus rz_cmd_debug_step_prog_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3570
static const char * help_msg_di[]
Definition: cmd_debug.c:103
RZ_IPI RzCmdStatus rz_cmd_debug_continue_unknown_call_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3285
#define MAX_MAP_SIZE
Definition: cmd_debug.c:809
static bool step_until_optype(RzCore *core, RzList *optypes_list)
Definition: cmd_debug.c:486
RZ_IPI RzCmdStatus rz_cmd_debug_stop_trace_session_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2210
#define PS(X, Y)
RZ_IPI RzCmdStatus rz_debug_drx_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3621
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2011
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_oneline_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3095
static void cmd_debug_modules(RzCore *core, RzCmdStateOutput *state)
Definition: cmd_debug.c:888
RZ_IPI int rz_cmd_debug_trace_addr(void *data, const char *input)
Definition: cmd_debug.c:2128
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2842
RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3452
static int step_until_flag(RzCore *core, const char *flagstr)
Definition: cmd_debug.c:562
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_flag_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2053
RZ_IPI RzCmdStatus rz_cmd_debug_start_trace_session_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2195
static RzOutputMode rad2mode(int mode)
Definition: cmd_debug.c:964
RZ_IPI RzCmdStatus rz_cmd_debug_bp_plugin_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3014
RZ_IPI RzCmdStatus rz_cmd_debug_trace_tag_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2250
static const char * help_msg_de[]
Definition: cmd_debug.c:85
RZ_IPI RzCmdStatus rz_cmd_debug_bt_enable_bp_trace_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3159
#define P
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:3037
RZ_IPI RzCmdStatus rz_cmd_debug_trace_interactive_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2189
RZ_IPI RzCmdStatus rz_cmd_debug_map_current_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1078
RZ_IPI RzCmdStatus rz_cmd_debug_traces_ascii_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2081
static const char * help_msg_des[]
Definition: cmd_debug.c:96
RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:1021
RZ_IPI RzCmdStatus rz_cmd_debug_continue_send_signal_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3322
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1092
static const char * help_msg_dcu[]
Definition: cmd_debug.c:63
static char * get_corefile_name(const char *raw_name, int pid)
Definition: cmd_debug.c:2256
RZ_IPI RzCmdStatus rz_cmd_debug_set_cond_bp_win_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3215
RZ_IPI RzCmdStatus rz_cmd_debug_step_line_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3551
RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_i_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2170
RZ_IPI RzCmdStatus rz_cmd_debug_dmL_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1404
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_noreturn_func_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2848
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_plugin_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3027
static void set_profile_string(RzCore *core, const char *str)
Definition: cmd_debug.c:192
static void dot_trace_discover_child(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:262
static void cmd_debug_backtrace(RzCore *core, ut64 len)
Definition: cmd_debug.c:774
static int step_until(RzCore *core, ut64 addr)
Definition: cmd_debug.c:352
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2936
static void debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr)
Definition: cmd_debug.c:1753
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_trace_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2975
RZ_IPI RzCmdStatus rz_cmd_debug_step_frame_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3520
RZ_IPI RzCmdStatus rz_cmd_debug_set_expr_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2920
static const char * help_msg_d[]
Definition: cmd_debug.c:27
RZ_IPI int rz_cmd_debug_continue_syscall(void *data, const char *input)
Definition: cmd_debug.c:3400
RZ_IPI RzCmdStatus rz_cmd_debug_command_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2798
static RzGraphNode * get_graphtrace_node(RzGraph *g, Sdb *nodes, struct trace_node *tn)
Definition: cmd_debug.c:242
RZ_IPI RzCmdStatus rz_cmd_debug_continue_call_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3272
RZ_IPI RzCmdStatus rz_cmd_debug_continue_ret_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3373
static void cmd_debug_cont_syscall(RzCore *core, const char *_str)
Definition: cmd_debug.c:204
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2019
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2826
RZ_IPI RzCmdStatus rz_cmd_debug_allocate_maps_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1029
static const char * help_msg_dd[]
Definition: cmd_debug.c:72
static void dot_trace_traverse(RzCore *core, RTree *t, int fmt)
Definition: cmd_debug.c:279
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_ascii_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3147
static void cmd_debug_pid(RzCore *core, const char *input)
Definition: cmd_debug.c:640
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_module_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2854
#define TN_KEY_LEN
Definition: cmd_debug.c:7
RZ_IPI RzCmdStatus rz_cmd_debug_deallocate_map_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1052
RZ_IPI RzCmdStatus rz_cmd_debug_add_watchpoint_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3208
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2962
RZ_IPI RzCmdStatus rz_cmd_debug_continue_mapped_io_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3347
RZ_IPI RzCmdStatus rz_cmd_debug_trace_calls_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2135
RZ_IPI RzCmdStatus rz_cmd_debug_bp_set_expr_cur_offset_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3186
static RTreeNode * add_trace_tree_child(HtUP *ht, RTree *t, RTreeNode *cur, ut64 addr)
Definition: cmd_debug.c:1607
RZ_IPI void rz_core_static_debug_stop(void *u)
Definition: cmd_debug.c:1565
RZ_IPI RzCmdStatus rz_cmd_debug_continue_exception_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3297
RZ_IPI RzCmdStatus rz_cmd_debug_modules_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:1038
RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2087
RZ_IPI RzCmdStatus rz_cmd_debug_save_trace_session_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2221
static const char * help_msg_dmi[]
Definition: cmd_debug.c:133
static void consumeBuffer(RzBuffer *buf, const char *cmd, const char *errmsg)
Definition: cmd_debug.c:2267
RZ_IPI RzCmdStatus rz_cmd_debug_continue_back_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3257
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_trace_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3001
static void trace_traverse_pre(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:1624
static ut8 * getFileData(RzCore *core, const char *arg)
Definition: cmd_debug.c:2260
RZ_API void rz_core_dbg_follow_seek_register(RzCore *core)
Seek to PC if needed.
Definition: cmd_debug.c:474
RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_indexes_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2892
static int step_until_esil(RzCore *core, const char *esilstr)
Definition: cmd_debug.c:381
RZ_IPI RzCmdStatus rz_cmd_debug_handler_set_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3447
RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:2697
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_esil_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2046
static RzCore * _core
Definition: cmd_debug.c:1622
RZ_IPI RzCmdStatus rz_cmd_debug_show_cur_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2787
RZ_IPI RzCmdStatus rz_cmd_debug_step_back_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3511
static const char * help_msg_dp[]
Definition: cmd_debug.c:143
static ut64 addroflib(RzCore *core, const char *libname)
Definition: cmd_debug.c:923
RZ_API void rz_core_debug_clear_register_flags(RzCore *core)
Definition: cmd_debug.c:1449
RZ_IPI RzCmdStatus rz_cmd_debug_process_close_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3497
RZ_IPI RzCmdStatus rz_cmd_debug_bt_disable_bp_trace_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3167
RZ_IPI RzCmdStatus rz_cmd_debug_dml_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1374
RZ_IPI int rz_cmd_debug_continue_until(void *data, const char *input)
Definition: cmd_debug.c:3425
RZ_IPI RzCmdStatus rz_cmd_debug_handler_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:3443
RZ_IPI RzCmdStatus rz_cmd_debug_trace_esils_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2153
RZ_IPI RzCmdStatus rz_cmd_debug_list_trace_session_mmap_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2242
RZ_IPI RzCmdStatus rz_cmd_debug_load_trace_session_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2231
static const char * help_msg_dko[]
Definition: cmd_debug.c:125
RZ_IPI RzCmdStatus rz_debug_memory_permission_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1288
RZ_IPI RzCmdStatus rz_cmd_debug_step_over_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3561
static void do_debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr)
Definition: cmd_debug.c:1652
static void dot_trace_create_node(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:255
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2834
static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, PJ *pj, int mode, bool symbols_only, RzCoreBinFilter *filter)
Definition: cmd_debug.c:980
RZ_IPI RzCmdStatus rz_cmd_debug_trace_esil_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2145
RZ_IPI RzCmdStatus rz_cmd_debug_continue_execution_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3236
static const char * help_msg_dk[]
Definition: cmd_debug.c:113
RZ_IPI RzCmdStatus rz_cmd_debug_remove_all_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2778
RZ_IPI RzCmdStatus rz_cmd_debug_run_command_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2928
RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_edit_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3485
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2690
RZ_IPI RzCmdStatus rz_cmd_debug_traces_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_debug.c:2075
RZ_IPI RzCmdStatus rz_cmd_debug_current_modules_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode)
Definition: cmd_debug.c:1045
RZ_IPI RzCmdStatus rz_cmd_debug_step_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3503
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2908
RZ_IPI int rz_cmd_debug_dmi(void *data, const char *input)
Definition: cmd_debug.c:1117
RZ_IPI RzCmdStatus rz_cmd_debug_step_cond_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3528
static void asciiart_backtrace(RzCore *core, RzList *frames)
Definition: cmd_debug.c:1514
RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_addrs_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2106
static void trace_traverse(RTree *t)
Definition: cmd_debug.c:1642
RZ_IPI int rz_cmd_debug_heap_jemalloc(void *data, const char *input)
Definition: cmd_debug.c:1415
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_all_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1103
static void foreach_reg_set_or_clear(RzCore *core, bool set)
Definition: cmd_debug.c:1428
#define CMD_CHECK_DEBUG_DEAD(core)
Definition: cmd_debug.c:19
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_trace_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2988
static void backtrace_vars(RzCore *core, RzList *frames)
Definition: cmd_debug.c:1453
static bool cmd_regs_sync(RzCore *core, RzRegisterType type, bool write)
Definition: cmd_debug.c:3607
static RzDebugMap * get_closest_map(RzCore *core, ut64 addr)
Definition: cmd_debug.c:945
RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_ascii_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1069
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_local_vars_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3135
RZ_API void rz_core_debug_ri(RzCore *core)
Definition: cmd_debug.c:3616
static const char * help_msg_dcs[]
Definition: cmd_debug.c:55
RZ_IPI RzCmdStatus rz_cmd_debug_trace_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2060
static bool step_until_inst(RzCore *core, const char *instr, bool regex)
Definition: cmd_debug.c:416
RZ_IPI RzCmdStatus rz_cmd_debug_show_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2881
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2770
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_index_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2949
RZ_IPI RzCmdStatus rz_debug_drx_unset_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3646
RZ_IPI RzCmdStatus rz_cmd_debug_continue_fork_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3308
RZ_IPI RzCmdStatus rz_cmd_debug_step_skip_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3597
RZ_IPI RzCmdStatus rz_cmd_debug_trace_graph_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode)
Definition: cmd_debug.c:2183
static void rz_core_debug_esil(RzCore *core, const char *input)
Definition: cmd_debug.c:1781
static bool cmd_dcu(RzCore *core, const char *input)
Definition: cmd_debug.c:1947
RZ_IPI RzCmdStatus rz_cmd_debug_name_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2865
RZ_IPI RzCmdStatus rz_cmd_debug_bt_toggle_bp_trace_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3175
static bool is_repeatable_inst(RzCore *core, ut64 addr)
Definition: cmd_debug.c:408
RZ_IPI RzCmdStatus rz_cmd_debug_add_cond_bp_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2812
RZ_IPI void rz_core_debug_bp_add(RzCore *core, ut64 addr, const char *arg_perm, bool hwbp, bool watch)
Definition: cmd_debug.c:1574
#define TN_KEY_FMT
Definition: cmd_debug.c:8
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_regex_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2028
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_writable_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:1110
RZ_API void rz_core_debug_set_register_flags(RzCore *core)
Definition: cmd_debug.c:1443
static int dump_maps(RzCore *core, int perm, const char *filename)
Definition: cmd_debug.c:810
RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_delete_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:2160
static bool step_line(RzCore *core, int times)
Definition: cmd_debug.c:598
RZ_IPI RzCmdStatus rz_cmd_debug_continue_traptrace_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_debug.c:3386
static void rz_core_debug_kill(RzCore *core, const char *input)
Definition: cmd_debug.c:1870
static const char * help_msg_dx[]
Definition: cmd_debug.c:168
RZ_IPI void rz_regs_show_valgroup(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
Definition: cmd_regs.c:423
RZ_API RZ_OWN RzList * rz_core_get_boundaries_prot(RzCore *core, int perm, const char *mode, const char *prefix)
Definition: cmd_search.c:577
RZ_IPI bool rz_core_seek_to_register(RzCore *core, const char *regname, bool is_silent)
Definition: cmd_seek.c:22
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API 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_println(const char *str)
Definition: cons.c:233
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
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
#define w
Definition: crypto_rc6.c:13
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 tv
Definition: sflib.h:79
static static fork write
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
RZ_DEPRECATE RZ_API bool rz_bin_addr2line(RzBin *bin, ut64 addr, char *file, int len, int *line)
Definition: dbginfo.c:194
RZ_API int rz_debug_desc_seek(RzDebug *dbg, int fd, ut64 addr)
Definition: ddesc.c:57
RZ_API int rz_debug_desc_list(RzDebug *dbg, int rad)
Definition: ddesc.c:71
RZ_API int rz_debug_desc_dup(RzDebug *dbg, int fd, int newfd)
Definition: ddesc.c:43
RZ_API int rz_debug_desc_write(RzDebug *dbg, int fd, ut64 addr, int len)
Definition: ddesc.c:64
RZ_API int rz_debug_desc_read(RzDebug *dbg, int fd, ut64 addr, int len)
Definition: ddesc.c:50
RZ_API ut64 rz_debug_esil_continue(RzDebug *dbg)
Definition: desil.c:304
RzDebug * dbg
Definition: desil.c:30
RZ_API ut64 rz_debug_esil_step(RzDebug *dbg, ut32 count)
Definition: desil.c:280
RZ_API void rz_debug_esil_prestep(RzDebug *d, int p)
Definition: desil.c:214
RZ_API void rz_debug_esil_watch_list(RzDebug *dbg)
Definition: desil.c:341
RZ_API int rz_debug_esil_watch_empty(RzDebug *dbg)
Definition: desil.c:313
RZ_API void rz_debug_esil_watch_reset(RzDebug *dbg)
Definition: desil.c:336
RZ_API void rz_debug_esil_watch(RzDebug *dbg, int rwx, int dev, const char *expr)
Definition: desil.c:317
RZ_API RZ_OWN RzDiff * rz_diff_lines_new(RZ_BORROW const char *a, RZ_BORROW const char *b, RZ_NULLABLE RzDiffIgnoreLine ignore)
Returns the structure needed to diff lines.
Definition: diff.c:219
RZ_API void rz_diff_free(RZ_NULLABLE RzDiff *diff)
frees the diff structure
Definition: diff.c:295
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
RZ_API void rz_debug_map_free(RzDebugMap *map)
Definition: dmap.c:77
RZ_API int rz_debug_map_dealloc(RzDebug *dbg, RzDebugMap *map)
Definition: dmap.c:54
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33
RZ_API RzDebugMap * rz_debug_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp)
Definition: dmap.c:46
RZ_API RzList * rz_debug_modules_list(RzDebug *dbg)
Definition: dmap.c:29
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
RZ_API void rz_debug_session_free(RzDebugSession *session)
Definition: dsession.c:11
RZ_API bool rz_debug_add_checkpoint(RzDebug *dbg)
Definition: dsession.c:58
RZ_API RzDebugSession * rz_debug_session_new(void)
Definition: dsession.c:33
RZ_API bool rz_debug_session_save(RzDebugSession *session, const char *path)
Definition: dsession.c:445
RZ_API void rz_debug_session_list_memory(RzDebug *dbg)
Definition: dsession.c:185
RZ_API bool rz_debug_session_load(RzDebug *dbg, const char *path)
Definition: dsession.c:727
RZ_API void rz_debug_signal_setup(RzDebug *dbg, int num, int opt)
Definition: dsignal.c:147
RZ_API void rz_debug_signal_list(RzDebug *dbg, RzOutputMode mode)
Definition: dsignal.c:119
RZ_API int rz_debug_kill_setup(RzDebug *dbg, int sig, int action)
Definition: dsignal.c:171
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
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_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os)
Definition: egg.c:139
struct @667 g
struct tab * done
Definition: enough.c:233
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API int rz_analysis_esil_condition(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:3113
RZ_API void rz_analysis_esil_trace_list(RzAnalysisEsil *esil)
Definition: esil_trace.c:434
RZ_API void rz_analysis_esil_trace_op(RzAnalysisEsil *esil, RZ_NONNULL RzAnalysisOp *op)
Definition: esil_trace.c:271
RZ_API void rz_analysis_esil_trace_show(RzAnalysisEsil *esil, int idx)
Definition: esil_trace.c:456
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_analysis_il_trace_instruction_free(RzILTraceInstruction *instruction)
Definition: il_trace.c:53
a0
Definition: insn-good.s.cs:704
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
#define reg(n)
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
RZ_API RzAnalysisOp * rz_core_op_analysis(RzCore *core, ut64 addr, RzAnalysisOpMask mask)
Definition: core.c:2880
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
RZ_API RzBuffer * rz_core_syscall(RzCore *core, const char *name, const char *args)
Definition: core.c:3305
RZ_API RzBuffer * rz_core_syscallf(RzCore *core, const char *name, const char *fmt,...)
Definition: core.c:3292
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug.c:1598
RZ_API int rz_debug_drx_set(RzDebug *dbg, int idx, ut64 addr, int len, int rwx, int g)
Definition: debug.c:1668
RZ_API int rz_debug_step_over(RzDebug *dbg, int steps)
Definition: debug.c:1033
RZ_API int rz_debug_step(RzDebug *dbg, int steps)
Definition: debug.c:962
RZ_API int rz_debug_map_protect(RzDebug *dbg, ut64 addr, int size, int perms)
Definition: debug.c:1655
RZ_API RZ_BORROW RzBreakpointItem * rz_debug_bp_add(RZ_NONNULL RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, RZ_NULLABLE const char *module, st64 m_delta)
Definition: debug.c:270
RZ_API int rz_debug_continue_until_optype(RzDebug *dbg, int type, int over)
Definition: debug.c:1345
RZ_API bool rz_debug_continue_back(RzDebug *dbg)
Definition: debug.c:1442
RZ_API int rz_debug_continue_until(RzDebug *dbg, ut64 addr)
Definition: debug.c:1434
RZ_API int rz_debug_drx_unset(RzDebug *dbg, int idx)
Definition: debug.c:1675
RZ_API int rz_debug_detach(RzDebug *dbg, int pid)
Definition: debug.c:583
RZ_API const char * rz_debug_reason_to_string(int type)
Definition: debug.c:639
RZ_API int rz_debug_continue(RzDebug *dbg)
Definition: debug.c:1332
RZ_API int rz_debug_stop(RzDebug *dbg)
Definition: debug.c:458
RZ_API int rz_debug_continue_syscalls(RzDebug *dbg, int *sc, int n_sc)
Definition: debug.c:1507
RZ_API int rz_debug_child_clone(RzDebug *dbg)
Definition: debug.c:1626
RZ_API int rz_debug_child_fork(RzDebug *dbg)
Definition: debug.c:1620
RZ_API RzDebugInfo * rz_debug_info(RzDebug *dbg, const char *arg)
Definition: debug.c:18
RZ_API void rz_debug_tracenodes_reset(RzDebug *dbg)
Definition: debug.c:411
RZ_API void rz_debug_drx_list(RzDebug *dbg)
Definition: debug.c:1662
RZ_API int rz_debug_continue_pass_exception(RzDebug *dbg)
Definition: debug.c:1336
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
Definition: debug.c:1682
RZ_API ut64 rz_debug_execute(RzDebug *dbg, const ut8 *buf, int len, int restore)
Definition: debug.c:510
RZ_API bool rz_debug_is_dead(RzDebug *dbg)
Definition: debug.c:1632
RZ_API int rz_debug_continue_kill(RzDebug *dbg, int sig)
Definition: debug.c:1141
RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid)
Definition: debug.c:595
RZ_API RzList * rz_debug_frames(RzDebug *dbg, ut64 at)
Definition: debug.c:1612
RZ_API RzDebugReasonType rz_debug_stop_reason(RzDebug *dbg)
Definition: debug.c:670
RZ_API void rz_debug_info_free(RzDebugInfo *rdi)
Definition: debug.c:28
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void rz_list_reverse(RZ_NONNULL RzList *list)
Reverses the list.
Definition: list.c:477
RZ_API RZ_OWN RzList * rz_list_new_from_array(RZ_NONNULL const void **arr, size_t arr_size)
Allocates a new RzList and adds an array elements to it.
Definition: list.c:260
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_OWN char * rz_list_to_str(RZ_NONNULL RzList *list, char ch)
Casts a RzList containg strings into a concatenated string.
Definition: list.c:785
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd times
Definition: sflib.h:70
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 pid
Definition: sflib.h:64
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 dev
Definition: sflib.h:88
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
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 unsigned long static filedes void static end_data_segment signum
Definition: sflib.h:79
char * dst
Definition: lz4.h:724
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
line
Definition: setup.py:34
int idx
Definition: setup.py:197
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
RZ_API const char * rz_analysis_optype_to_string(int type)
Definition: op.c:310
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
int off
Definition: pal.c:13
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185
ut8 optype
Definition: pic_pic18.c:32
RZ_API int rz_debug_pid_list(RzDebug *dbg, int pid, char fmt)
Definition: pid.c:34
RZ_API int rz_debug_thread_list(RzDebug *dbg, int pid, char fmt)
Definition: pid.c:74
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
#define eprintf(x, y...)
Definition: rlcc.c:7
static RzSocket * s
Definition: rtr.c:28
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
@ RZ_ANALYSIS_OP_PREFIX_REP
Definition: rz_analysis.h:348
@ RZ_ANALYSIS_OP_PREFIX_REPNE
Definition: rz_analysis.h:349
@ RZ_ANALYSIS_OP_MASK_ALL
Definition: rz_analysis.h:447
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
@ RZ_ANALYSIS_OP_MASK_HINT
Definition: rz_analysis.h:443
@ RZ_ANALYSIS_OP_TYPE_ICALL
Definition: rz_analysis.h:381
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_RCALL
Definition: rz_analysis.h:380
@ RZ_ANALYSIS_OP_TYPE_IRCALL
Definition: rz_analysis.h:382
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
RZ_API bool rz_buf_read8(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the cursor in the buffer.
Definition: buf.c:860
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
Definition: buf.c:317
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_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
#define RZ_FLAGS_FS_REGISTERS
Definition: rz_core.h:61
RzDebugReasonType
Definition: rz_debug.h:89
@ RZ_DBG_SIGNAL_CONT
Definition: rz_debug.h:71
@ RZ_DBG_SIGNAL_SKIP
Definition: rz_debug.h:72
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
RZ_API char * rz_file_temp(const char *prefix)
Definition: file.c:1048
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
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_dump(const char *file, const ut8 *buf, int len, bool append)
Definition: file.c:838
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
RZ_API bool RZ_API char * rz_file_slurp_line(const char *file, int line, int context)
Definition: file.c:673
RZ_API RzGraph * rz_graph_new(void)
Definition: graph.c:108
RZ_API bool rz_graph_adjacent(const RzGraph *g, const RzGraphNode *from, const RzGraphNode *to)
Definition: graph.c:270
RZ_API const RzList * rz_graph_get_nodes(const RzGraph *g)
Definition: graph.c:265
RZ_API const RzList * rz_graph_get_neighbours(const RzGraph *g, const RzGraphNode *n)
Definition: graph.c:245
RZ_API void rz_graph_add_edge(RzGraph *g, RzGraphNode *from, RzGraphNode *to)
Definition: graph.c:199
RZ_API void rz_graph_free(RzGraph *g)
Definition: graph.c:124
RZ_API RzGraphNode * rz_graph_add_node(RzGraph *g, void *data)
Definition: graph.c:153
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
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 int rz_io_fd_get_tid(RzIO *io, int fd)
Definition: io_fd.c:100
RZ_API int rz_io_fd_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io_fd.c:6
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
RZ_API int rz_io_fd_get_pid(RzIO *io, int fd)
Definition: io_fd.c:92
RZ_API bool rz_io_fd_close(RzIO *io, int fd)
Definition: io_fd.c:11
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
Definition: unum.c:775
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API int rz_num_conditional(RzNum *num, const char *str)
Definition: unum.c:603
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RzRegisterType
Definition: rz_reg.h:20
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
@ RZ_REG_TYPE_DRX
Definition: rz_reg.h:22
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:142
RZ_API const char * rz_signal_to_string(int code)
Definition: signal.c:63
RZ_API int rz_signal_from_string(const char *str)
Definition: signal.c:52
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
RZ_API RzList * rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3485
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
RZ_API char * rz_sys_cmd_strf(const char *cmd,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_sys_pid_to_path(int pid)
Definition: sys.c:920
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
Definition: sys.c:317
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RZ_API RZ_OWN char * rz_time_date_now_to_string(void)
Returns the timestamp in string format of the current time (now)
Definition: time.c:278
RZ_API RTreeNode * rz_tree_add_node(RTree *t, RTreeNode *node, void *child_data)
Definition: tree.c:99
RZ_API void rz_tree_reset(RTree *t)
Definition: tree.c:85
RZ_API void rz_tree_bfs(RTree *t, RTreeVisitor *vis)
Definition: tree.c:132
void(* RTreeNodeVisitCb)(RTreeNode *n, RTreeVisitor *vis)
Definition: rz_tree.h:27
RZ_API void rz_tree_dfs(RTree *t, RTreeVisitor *vis)
Definition: tree.c:124
#define PFMT64d
Definition: rz_types.h:394
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_MODE_SET
Definition: rz_types.h:27
#define RZ_MODE_SIMPLEST
Definition: rz_types.h:31
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_PERM_W
Definition: rz_types.h:94
#define RZ_MODE_RIZINCMD
Definition: rz_types.h:26
#define RZ_PERM_X
Definition: rz_types.h:95
#define RZ_MODE_PRINT
Definition: rz_types.h:25
#define RZ_MODE_JSON
Definition: rz_types.h:29
#define RZ_MODE_SIMPLE
Definition: rz_types.h:28
#define PFMT64u
Definition: rz_types.h:395
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define RZ_PERM_RWX
Definition: rz_types.h:98
#define PFMT64x
Definition: rz_types.h:393
#define PFMTDPTR
Definition: rz_types.h:405
#define RZ_MAX(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
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 int
Definition: sfsocketcall.h:114
#define O_CREAT
Definition: sftypes.h:489
#define O_RDWR
Definition: sftypes.h:488
int ptrdiff_t
Definition: sftypes.h:68
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
#define tr(opcode, mask, lose, flags)
RzGraph * graph
Definition: cmd_debug.c:182
Sdb * graphnodes
Definition: cmd_debug.c:183
Definition: gzappend.c:170
Definition: z80asm.h:102
Definition: op.c:222
Definition: rz_pj.h:12
RzAnalysisEsilTrace * trace
Definition: rz_analysis.h:1077
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584
RzSyscall * syscall
Definition: rz_analysis.h:570
ut8 * bytes
Definition: rz_asm.h:80
int bits
Definition: rz_asm.h:100
char * flagdesc2
Definition: rz_debug.h:427
char * pcstr
Definition: rz_debug.h:424
char * flagdesc
Definition: rz_debug.h:426
RzDebugFrame * frame
Definition: rz_debug.h:421
char * spstr
Definition: rz_debug.h:425
char * desc
Definition: rz_debug.h:423
RzAnalysisFunction * fcn
Definition: rz_debug.h:422
XX curplugin == o->plugin.
Definition: rz_bin.h:298
char * name
Definition: rz_bin.h:675
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
Definition: rz_bin.h:330
char * expr
Definition: rz_bp.h:61
int perm
Definition: rz_bp.h:49
char * name
Definition: rz_bp.h:42
ut64 addr
Definition: rz_bp.h:45
int enabled
Definition: rz_bp.h:53
int trace
Definition: rz_bp.h:51
RzList * bps
Definition: rz_bp.h:93
Represent the output state of a command handler.
Definition: rz_cmd.h:91
bool break_loop
Definition: rz_core.h:373
RzEgg * egg
Definition: rz_core.h:332
RzCmd * rcmd
Definition: rz_core.h:319
RzBin * bin
Definition: rz_core.h:298
ut64 offset
Definition: rz_core.h:301
RzAsm * rasm
Definition: rz_core.h:323
RzAnalysis * analysis
Definition: rz_core.h:322
RzDebug * dbg
Definition: rz_core.h:329
RzIO * io
Definition: rz_core.h:313
RzNum * num
Definition: rz_core.h:316
RzFlag * flags
Definition: rz_core.h:330
RzCoreFile * file
Definition: rz_core.h:314
RzConfig * config
Definition: rz_core.h:300
bool(* gcore)(RzDebug *dbg, char *path, RzBuffer *dest)
Definition: rz_debug.h:385
RzDebugSession * session
Definition: rz_debug.h:311
int forked_pid
Definition: rz_debug.h:249
ut64 stopaddr
Definition: rz_debug.h:278
RzList * maps
Definition: rz_debug.h:306
RzDebugReason reason
Definition: rz_debug.h:276
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295
RzDebugTrace * trace
Definition: rz_debug.h:281
RzAnalysis * analysis
Definition: rz_debug.h:305
RTree * tree
Definition: rz_debug.h:283
int n_threads
Definition: rz_debug.h:250
HtUP * tracenodes
Definition: rz_debug.h:282
RzReg * reg
Definition: rz_debug.h:286
RzIOBind iob
Definition: rz_debug.h:293
int main_pid
Definition: rz_debug.h:246
RzBreakpoint * bp
Definition: rz_debug.h:288
Definition: diff.c:89
ut64 offset
Definition: rz_flag.h:38
char * realname
Definition: rz_flag.h:36
char * name
Definition: rz_flag.h:35
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
char * envprofile
Definition: rz_io.h:82
const char * calc_buf
Definition: rz_num.h:54
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120
char * name
Definition: rz_reg.h:118
char * name[RZ_REG_NAME_LAST]
Definition: rz_reg.h:149
struct rz_tree_node_t * parent
Definition: rz_tree.h:8
void(* pre_visit)(RTreeNode *, struct rz_tree_visitor_t *)
Definition: rz_tree.h:22
Definition: sdb.h:63
Definition: dis.h:43
ut64 addr
Definition: cmd_debug.c:187
RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str)
Definition: syscall.c:376
RZ_API void rz_debug_trace_at(RzDebug *dbg, const char *str)
Definition: trace.c:194
RZ_API int rz_debug_trace_tag(RzDebug *dbg, int tag)
Definition: trace.c:41
RZ_API RzDebugTracepoint * rz_debug_trace_add(RzDebug *dbg, ut64 addr, int size)
Definition: trace.c:261
RZ_API RzDebugTracepoint * rz_debug_trace_get(RzDebug *dbg, ut64 addr)
Definition: trace.c:200
RZ_API void rz_debug_trace_free(RzDebugTrace *trace)
Definition: trace.c:29
RZ_API RzDebugTrace * rz_debug_trace_new(void)
Definition: trace.c:7
RZ_API RZ_OWN char * rz_diff_unified_text(RZ_NONNULL RzDiff *diff, RZ_NULLABLE const char *from, RZ_NULLABLE const char *to, bool show_time, bool color)
Produces a diff output with A and B inputs presented immediately adjacent to each other.
Definition: unified_diff.c:333
Definition: dis.c:32
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 void rz_w32_identify_window(void)
RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *msg_name, const char *window_id)
RZ_API void rz_w32_print_windows(RzDebug *dbg)
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int sp
Definition: z80asm.c:91
static int baseaddr
Definition: z80asm.c:79
static int addr
Definition: z80asm.c:58
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)