Rizin
unix-like reverse engineering framework and cli tools
rizin.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 #define USE_THREADS 1
5 #define ALLOW_THREADED 0
6 #define UNCOLORIZE_NONTTY 0
7 
8 #include <rz_core.h>
9 #include <rz_demangler.h>
10 #include <rz_project.h>
11 #include <rz_flirt.h>
12 #include <rz_socket.h>
13 
15  RzIODesc *d = fh && fh->core ? rz_io_desc_get(fh->core->io, fh->fd) : NULL;
16  return d && strncmp(d->name, "gdb://", 6);
17 }
18 
20  RzIODesc *d = fh && fh->core ? rz_io_desc_get(fh->core->io, fh->fd) : NULL;
21  return d && strncmp(d->name, "dmp://", 6);
22 }
23 
24 static char *get_file_in_cur_dir(const char *filepath) {
25  filepath = rz_file_basename(filepath);
26  if (rz_file_exists(filepath) && !rz_file_is_directory(filepath)) {
27  return rz_file_abspath(filepath);
28  }
29  return NULL;
30 }
31 
32 static int rz_main_version_verify(int show) {
33  int i, ret;
34  typedef const char *(*vc)();
35  const char *base = RZ_VERSION;
36  struct vcs_t {
37  const char *name;
38  vc callback;
39  } vcs[] = {
40  { "rz_analysis", rz_analysis_version },
41  { "rz_lib", rz_lib_version },
42  { "rz_egg", rz_egg_version },
43  { "rz_asm", rz_asm_version },
44  { "rz_bin", rz_bin_version },
45  { "rz_cons", rz_cons_version },
46  { "rz_flag", rz_flag_version },
47  { "rz_core", rz_core_version },
48  { "rz_crypto", rz_crypto_version },
49  { "rz_bp", rz_bp_version },
50  { "rz_debug", rz_debug_version },
51  { "rz_main", rz_main_version },
52  { "rz_hash", rz_hash_version },
53  { "rz_io", rz_io_version },
54 #if !USE_LIB_MAGIC
55  { "rz_magic", rz_magic_version },
56 #endif
57  { "rz_parse", rz_parse_version },
58  { "rz_reg", rz_reg_version },
59  { "rz_sign", rz_sign_version },
60  { "rz_search", rz_search_version },
61  { "rz_syscall", rz_syscall_version },
62  { "rz_util", rz_util_version },
63  { "rz_diff", rz_diff_version },
64  { "rz_demangler", rz_demangler_version },
65  /* ... */
66  { NULL, NULL }
67  };
68 
69  if (show) {
70  printf("%s rizin\n", base);
71  }
72  for (i = ret = 0; vcs[i].name; i++) {
73  struct vcs_t *v = &vcs[i];
74  const char *name = v->callback();
75  if (!ret && strcmp(base, name)) {
76  ret = 1;
77  }
78  if (show) {
79  printf("%s %s\n", name, v->name);
80  }
81  }
82  if (ret) {
83  if (show) {
84  eprintf("WARNING: rizin library versions mismatch!\n");
85  } else {
86  eprintf("WARNING: rizin library versions mismatch! See rizin -V\n");
87  }
88  }
89  return ret;
90 }
91 
92 static int main_help(int line) {
93  if (line < 2) {
94  printf("Usage: rizin [-ACdfLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]\n"
95  " [-s addr] [-B baddr] [-m maddr] [-c cmd] [-e k=v] file|pid|-|--|=\n");
96  }
97  if (line != 1) {
98  printf(
99  " -- run rizin without opening any file\n"
100  " = same as 'rizin malloc://512'\n"
101  " - read file from stdin \n"
102  " -= perform R=! command to run all commands remotely\n"
103  " -0 print \\x00 after init and every command\n"
104  " -2 close stderr file descriptor (silent warning messages)\n"
105  " -a [arch] set asm.arch\n"
106  " -A run 'aaa' command to analyze all referenced code\n"
107  " -b [bits] set asm.bits\n"
108  " -B [baddr] set base address for PIE binaries\n"
109  " -c 'cmd..' execute rizin command\n"
110  " -C file is host:port (alias for -cR+http://%%s/cmd/)\n"
111  " -d debug the executable 'file' or running process 'pid'\n"
112  " -D [backend] enable debug mode (e cfg.debug=true)\n"
113  " -e k=v evaluate config var\n"
114  " -f block size = file size\n"
115  " -F [binplug] force to use that rbin plugin\n"
116  " -h, -hh show help message, -hh for long\n"
117  " -H ([var]) display variable\n"
118  " -i [file] run script file\n"
119  " -I [file] run script file before the file is opened\n"
120  " -k [OS/kern] set asm.os (linux, macos, w32, netbsd, ...)\n"
121  " -l [lib] load plugin file\n"
122  " -L list supported IO plugins\n"
123  " -m [addr] map file at given address (loadaddr)\n"
124  " -M do not demangle symbol names\n"
125  " -n, -nn do not load RzBin info (-nn only load bin structures)\n"
126  " -N do not load user settings and scripts\n"
127  " -NN do not load any script or plugin\n"
128  " -q quiet mode (no prompt) and quit after -i\n"
129  " -qq quit after running all -c and -i\n"
130  " -Q quiet mode (no prompt) and quit faster (quickLeak=true)\n"
131  " -p [p.rzdb] load project file\n"
132  " -r [rz-run] specify rz-run profile to load (same as -e dbg.profile=X)\n"
133  " -R [rule] specify custom rz-run directive\n"
134  " -s [addr] initial seek\n"
136  " -t load rz-bin info in thread\n"
137 #endif
138  " -T do not compute file hashes\n"
139  " -u set bin.filter=false to get raw sym/sec/cls names\n"
140  " -v, -V show rizin version (-V show lib versions)\n"
141  " -w open file in write mode\n"
142  " -x open without exec-flag (asm.emu will not work), See io.exec\n"
143  " -X same as -e bin.usextr=false (useful for dyldcache)\n"
144  " -z, -zz do not load strings or load them even in raw\n");
145  }
146  if (line == 2) {
147  char *datahome = rz_path_home_prefix(RZ_DATADIR);
148  char *incdir = rz_path_incdir();
149  char *libdir = rz_path_libdir();
150  char *home_rc = rz_path_home_rc();
151  char *home_config_rc = rz_path_home_config_rc();
152  char *home_config_rcdir = rz_path_home_config_rcdir();
153  char *system_rc = rz_path_system_rc();
154  char *binrc_dir = rz_path_home_prefix(RZ_BINRC);
155  char *binrc = rz_file_path_join(binrc_dir, "bin-<format>");
156  char *system_magic = rz_path_system(RZ_SDB_MAGIC);
157  char *home_plugins = rz_path_home_prefix(RZ_PLUGINS);
158  char *system_plugins = rz_path_system(RZ_PLUGINS);
159  char *system_sigdb = rz_path_system(RZ_SIGDB);
160  char *dirPrefix = rz_path_prefix(NULL);
161  // clang-format off
162  printf(
163  "Scripts:\n"
164  " system %s\n"
165  " user %s %s (and %s)\n"
166  " file ${filename}.rz\n"
167  "Plugins:\n"
168  " binrc %s (elf, elf64, mach0, ..)\n"
169  " RZ_USER_PLUGINS %s\n"
170  " RZ_LIBR_PLUGINS %s\n"
171  "Environment:\n"
172  " RZ_DEBUG if defined, show error messages and crash signal\n"
173  " RZ_DEBUG_ASSERT=1 set a breakpoint when hitting an assert\n"
174  " RZ_MAGICPATH %s\n"
175  " RZ_NOPLUGINS do not load rizin shared plugins\n"
176  " RZ_RCFILE %s (user preferences, batch script)\n"
177  " RZ_RDATAHOME %s\n"
178  " RZ_VERSION contains the current version of rizin\n"
179  "Paths:\n"
180  " RZ_PREFIX %s\n"
181  " RZ_INCDIR %s\n"
182  " RZ_LIBDIR %s\n"
183  " RZ_SIGDB %s\n"
184  " RZ_LIBEXT " RZ_LIB_EXT "\n",
185  system_rc,
186  home_rc, home_config_rc, home_config_rcdir,
187  binrc,
188  home_plugins,
189  system_plugins,
190  system_magic,
191  home_rc,
192  datahome,
193  dirPrefix,
194  incdir,
195  libdir,
196  system_sigdb);
197  // clang-format on
198  free(datahome);
199  free(incdir);
200  free(libdir);
201  free(home_rc);
202  free(home_config_rc);
203  free(home_config_rcdir);
204  free(system_rc);
205  free(binrc_dir);
206  free(binrc);
207  free(system_magic);
208  free(home_plugins);
209  free(system_plugins);
210  free(system_sigdb);
211  free(dirPrefix);
212  }
213  return 0;
214 }
215 
216 static int main_print_var(const char *var_name) {
217  int i = 0;
218  char *prefix = rz_path_prefix(NULL);
219  char *incdir = rz_path_incdir();
220  char *libdir = rz_path_libdir();
221  char *confighome = rz_path_home_config();
222  char *datahome = rz_path_home_prefix(RZ_DATADIR);
223  char *cachehome = rz_path_home_cache();
224  char *homeplugins = rz_path_home_prefix(RZ_PLUGINS);
225  char *sigdbdir = rz_path_system(RZ_SIGDB);
226  char *plugins = rz_path_system(RZ_PLUGINS);
227  char *magicpath = rz_path_system(RZ_SDB_MAGIC);
228  const char *is_portable = RZ_IS_PORTABLE ? "1" : "0";
229  struct rizin_var_t {
230  const char *name;
231  const char *value;
232  } rz_vars[] = {
233  { "RZ_VERSION", RZ_VERSION },
234  { "RZ_PREFIX", prefix },
235  { "RZ_MAGICPATH", magicpath },
236  { "RZ_INCDIR", incdir },
237  { "RZ_LIBDIR", libdir },
238  { "RZ_SIGDB", sigdbdir },
239  { "RZ_LIBEXT", RZ_LIB_EXT },
240  { "RZ_RCONFIGHOME", confighome },
241  { "RZ_RDATAHOME", datahome },
242  { "RZ_RCACHEHOME", cachehome },
243  { "RZ_LIBR_PLUGINS", plugins },
244  { "RZ_USER_PLUGINS", homeplugins },
245  { "RZ_IS_PORTABLE", is_portable },
246  { NULL, NULL }
247  };
248  int delta = 0;
249  if (var_name && strncmp(var_name, "RZ_", 3)) {
250  delta = 3;
251  }
252  if (var_name) {
253  while (rz_vars[i].name) {
254  if (!strcmp(rz_vars[i].name + delta, var_name)) {
255  printf("%s\n", rz_vars[i].value);
256  break;
257  }
258  i++;
259  }
260  } else {
261  while (rz_vars[i].name) {
262  printf("%s=%s\n", rz_vars[i].name, rz_vars[i].value);
263  i++;
264  }
265  }
266  free(incdir);
267  free(libdir);
268  free(confighome);
269  free(datahome);
270  free(cachehome);
271  free(homeplugins);
272  free(sigdbdir);
273  free(plugins);
274  free(magicpath);
275  free(prefix);
276  return 0;
277 }
278 
279 static bool run_commands(RzCore *r, RzList *cmds, RzList *files, bool quiet, int do_analysis) {
280  RzListIter *iter;
281  const char *cmdn;
282  const char *file;
283  int ret;
284  /* -i */
285  rz_list_foreach (files, iter, file) {
286  if (!rz_file_exists(file)) {
287  RZ_LOG_ERROR("Script '%s' not found.\n", file);
288  goto beach;
289  }
290  ret = rz_core_run_script(r, file);
291  if (ret == -2) {
292  RZ_LOG_ERROR("[c] Cannot open '%s'\n", file);
293  }
294  if (ret < 0 || (ret == 0 && quiet)) {
295  rz_cons_flush();
296  return false;
297  }
298  }
299  /* -c */
300  rz_list_foreach (cmds, iter, cmdn) {
301  // rz_core_cmd0 (r, cmdn);
302  rz_core_cmd_lines(r, cmdn);
303  rz_cons_flush();
304  }
305 beach:
306  if (quiet) {
307  if (do_analysis) {
308  return true;
309  }
310  if (cmds && !rz_list_empty(cmds)) {
311  return true;
312  }
313  if (!rz_list_empty(files)) {
314  return true;
315  }
316  }
317  return false;
318 }
319 
320 static bool mustSaveHistory(RzConfig *c) {
321  if (!rz_config_get_i(c, "scr.histsave")) {
322  return false;
323  }
324  if (!rz_cons_is_interactive()) {
325  return false;
326  }
327  return true;
328 }
329 
330 // Try to set the correct scr.color for the current terminal.
331 static void set_color_default(RzCore *r) {
332 #ifdef __WINDOWS__
333  char *alacritty = rz_sys_getenv("ALACRITTY_LOG");
334  if (alacritty) {
335  // Despite the setting of env vars to the contrary, Alacritty on
336  // Windows may not actually support >16 colors out-of-the-box
337  // (https://github.com/jwilm/alacritty/issues/1662).
338  // TODO: Windows 10 version check.
339  rz_config_set_i(r->config, "scr.color", COLOR_MODE_16);
340  free(alacritty);
341  return;
342  }
343 #endif
344  char *tmp = rz_sys_getenv("COLORTERM");
345  if (tmp) {
346  if ((rz_str_endswith(tmp, "truecolor") || rz_str_endswith(tmp, "24bit"))) {
347  rz_config_set_i(r->config, "scr.color", COLOR_MODE_16M);
348  }
349  } else {
350  tmp = rz_sys_getenv("TERM");
351  if (!tmp) {
352  return;
353  }
354  if (rz_str_endswith(tmp, "truecolor") || rz_str_endswith(tmp, "24bit")) {
355  rz_config_set_i(r->config, "scr.color", COLOR_MODE_16M);
356  } else if (rz_str_endswith(tmp, "256color")) {
357  rz_config_set_i(r->config, "scr.color", COLOR_MODE_256);
358  } else if (!strcmp(tmp, "dumb")) {
359  // Dumb terminals don't get color by default.
360  rz_config_set_i(r->config, "scr.color", COLOR_MODE_DISABLED);
361  }
362  }
363  free(tmp);
364 }
365 
366 static bool has_file_arg(int argc, const char **argv, RzGetopt *opt) {
367  return (argc >= 2 && argv[opt->ind] && strcmp(argv[opt->ind], "--")) || ((!strcmp(argv[opt->ind - 1], "--") && argv[opt->ind]));
368 }
369 
370 RZ_API int rz_main_rizin(int argc, const char **argv) {
371  RzCore *r;
372  bool forcequit = false;
373  bool haveRarunProfile = false;
374  RzListIter *iter;
375  int do_analysis = 0;
376  char *cmdn, *tmp;
377  RzCoreFile *fh = NULL;
378  RzIODesc *iod = NULL;
379  const char *prj = NULL;
380  int debug = 0;
381  int zflag = 0;
382  bool do_connect = false;
383  bool fullfile = false;
384  bool zerosep = false;
385  int help = 0;
386  enum { LOAD_BIN_ALL,
387  LOAD_BIN_NOTHING,
388  LOAD_BIN_STRUCTURES_ONLY } load_bin = LOAD_BIN_ALL;
389  bool run_rc = true;
390  int ret, c, perms = RZ_PERM_RX;
391  ut64 baddr = UT64_MAX;
392  ut64 seek = UT64_MAX;
393  bool do_list_io_plugins = false;
394  char *file = NULL;
395  char *pfile = NULL;
396  const char *asmarch = NULL;
397  const char *asmos = NULL;
398  const char *forcebin = NULL;
399  const char *asmbits = NULL;
400  char *customRarunProfile = NULL;
401  ut64 mapaddr = 0LL;
402  bool quiet = false;
403  bool quietLeak = false;
404  int is_gdb = false;
405  const char *s_seek = NULL;
406  bool compute_hashes = true;
407  RzList *cmds = rz_list_new();
408  RzList *evals = rz_list_new();
409  RzList *files = rz_list_new();
410  RzList *prefiles = rz_list_new();
411  RzCmdStateOutput state = { 0 };
412 
413 #define LISTS_FREE() \
414  { \
415  rz_list_free(cmds); \
416  rz_list_free(evals); \
417  rz_list_free(files); \
418  rz_list_free(prefiles); \
419  }
420 
421  bool noStderr = false;
422 
423 #ifdef __UNIX
424  sigset_t sigBlockMask;
425  sigemptyset(&sigBlockMask);
426  sigaddset(&sigBlockMask, SIGWINCH);
427  rz_signal_sigmask(SIG_BLOCK, &sigBlockMask, NULL);
428 #endif
429 
430  rz_sys_env_init();
431  // Create rz-run profile with startup environ
432  char **env = rz_sys_get_environ();
433  char *envprofile = rz_run_get_environ_profile(env);
434 
435  if (rz_sys_getenv_asbool("RZ_DEBUG")) {
436  char *sysdbg = rz_sys_getenv("RZ_DEBUG_TOOL");
437  char *fmt = (sysdbg && *sysdbg)
438  ? rz_str_newf("%s %%d", sysdbg)
439 #if __APPLE__
440  : rz_str_newf("lldb -p %%d");
441 #else
442  : rz_str_newf("gdb --pid %%d");
443 #endif
445  free(fmt);
446  free(sysdbg);
447  }
448 
449  r = rz_core_new();
450  if (!r) {
451  RZ_LOG_ERROR("Cannot initialize RzCore\n");
452  LISTS_FREE();
453  free(envprofile);
454  return 1;
455  }
456  r->rz_main_rizin = rz_main_rizin;
457  r->rz_main_rz_diff = rz_main_rz_diff;
458  r->rz_main_rz_find = rz_main_rz_find;
459  r->rz_main_rz_bin = rz_main_rz_bin;
460  r->rz_main_rz_gg = rz_main_rz_gg;
461  r->rz_main_rz_asm = rz_main_rz_asm;
462  r->rz_main_rz_ax = rz_main_rz_ax;
463 
464  r->io->envprofile = envprofile;
465 
466  rz_core_task_sync_begin(&r->tasks);
467  // HACK TO PERMIT '#!/usr/bin/rz - -i' hashbangs
468  if (argc > 2 && !strcmp(argv[1], "-") && !strcmp(argv[2], "-i")) {
469  argv[1] = argv[0];
470  argc--;
471  argv++;
472  }
473 
474  // -H option without argument
475  if (argc == 2 && !strcmp(argv[1], "-H")) {
477  LISTS_FREE();
478  return 0;
479  }
480 
482  bool load_l = true;
483  char *debugbackend = strdup("native");
484 
485  RzGetopt opt;
486  rz_getopt_init(&opt, argc, argv, "=02AMCwxfF:H:hm:e:nk:NdqQs:p:b:B:a:Lui:I:l:R:r:c:D:vVSTzuXt");
487  while (argc >= 2 && (c = rz_getopt_next(&opt)) != -1) {
488  switch (c) {
489  case '-':
490  RZ_LOG_ERROR("%c: invalid combinations of argument flags - %s\n", opt.opt, opt.argv[2]);
491  ret = 1;
492  goto beach;
493  break;
494  case '=':
495  RZ_FREE(r->cmdremote);
496  r->cmdremote = strdup("");
497  break;
498  case '2':
499  noStderr = true;
500  break;
501  case '0':
502  zerosep = true;
503  /* implicit -q */
504  rz_config_set(r->config, "scr.interactive", "false");
505  rz_config_set(r->config, "scr.prompt", "false");
506  rz_config_set_i(r->config, "scr.color", COLOR_MODE_DISABLED);
507  quiet = true;
508  break;
509  case 'u':
510  rz_config_set(r->config, "bin.filter", "false");
511  break;
512  case 'a':
513  asmarch = opt.arg;
514  break;
515  case 'z':
516  zflag++;
517  break;
518  case 'A':
519  do_analysis += do_analysis ? 1 : 2;
520  break;
521  case 'b':
522  asmbits = opt.arg;
523  break;
524  case 'B':
525  baddr = rz_num_math(r->num, opt.arg);
526  break;
527  case 'X':
528  rz_config_set(r->config, "bin.usextr", "false");
529  break;
530  case 'c':
531  rz_list_append(cmds, (void *)opt.arg);
532  break;
533  case 'C':
534  do_connect = true;
535  break;
536 #if DEBUGGER
537  case 'd': debug = 1; break;
538 #else
539  case 'd':
540  RZ_LOG_ERROR("Sorry. No debugger backend available.\n");
541  return 1;
542 #endif
543  case 'D': {
544  debug = 2;
545  free(debugbackend);
546  debugbackend = strdup(opt.arg);
547  RzCmdStateOutput state = { 0 };
549  if (!strcmp(opt.arg, "?")) {
553  rz_cons_flush();
554  LISTS_FREE();
555  return 0;
556  }
557  break;
558  }
559  case 'e':
560  if (!strcmp(opt.arg, "q")) {
561  rz_core_cmd0(r, "eq");
562  } else {
563  rz_config_eval(r->config, opt.arg);
564  rz_list_append(evals, (void *)opt.arg);
565  }
566  break;
567  case 'f':
568  fullfile = true;
569  break;
570  case 'F':
571  forcebin = opt.arg;
572  break;
573  case 'h':
574  help++;
575  break;
576  case 'H':
577  main_print_var(opt.arg);
578  LISTS_FREE();
579  return 0;
580  case 'i':
581  if (RZ_STR_ISEMPTY(opt.arg)) {
582  RZ_LOG_ERROR("Cannot open empty script path\n");
583  ret = 1;
584  goto beach;
585  }
586  rz_list_append(files, (void *)opt.arg);
587  break;
588  case 'I':
589  if (RZ_STR_ISEMPTY(opt.arg)) {
590  RZ_LOG_ERROR("Cannot open empty script path\n");
591  ret = 1;
592  goto beach;
593  }
594  rz_list_append(prefiles, (void *)opt.arg);
595  break;
596  case 'k':
597  asmos = opt.arg;
598  break;
599  case 'l':
600  rz_lib_open(r->lib, opt.arg);
601  break;
602  case 'L':
603  do_list_io_plugins = true;
604  break;
605  case 'm':
606  mapaddr = rz_num_math(r->num, opt.arg);
607  s_seek = opt.arg;
608  rz_config_set_i(r->config, "file.offset", mapaddr);
609  break;
610  case 'M':
611  rz_config_set(r->config, "bin.demangle", "false");
612  rz_config_set(r->config, "asm.demangle", "false");
613  break;
614  case 'n':
615  if (load_bin == LOAD_BIN_ALL) { // "-n"
616  load_bin = LOAD_BIN_NOTHING;
617  } else if (load_bin == LOAD_BIN_NOTHING) { // second n => "-nn"
618  load_bin = LOAD_BIN_STRUCTURES_ONLY;
619  }
620  rz_config_set(r->config, "file.info", "false");
621  break;
622  case 'N':
623  if (run_rc) {
624  run_rc = false;
625  } else {
626  load_l = false;
627  }
628  break;
629  case 'p':
630  prj = *opt.arg ? opt.arg : NULL;
631  break;
632  case 'Q':
633  quiet = true;
634  quietLeak = true;
635  break;
636  case 'q':
637  rz_config_set(r->config, "scr.interactive", "false");
638  rz_config_set(r->config, "scr.prompt", "false");
639  rz_config_set(r->config, "cfg.fortunes", "false");
640  if (quiet) {
641  forcequit = true;
642  }
643  quiet = true;
644  break;
645  case 'r':
646  if (RZ_STR_ISEMPTY(opt.arg)) {
647  RZ_LOG_ERROR("Cannot open empty rz-run profile path\n");
648  ret = 1;
649  goto beach;
650  }
651  haveRarunProfile = true;
652  rz_config_set(r->config, "dbg.profile", opt.arg);
653  break;
654  case 'R':
655  customRarunProfile = rz_str_appendf(customRarunProfile, "%s\n", opt.arg);
656  break;
657  case 's':
658  s_seek = opt.arg;
659  break;
660 #if USE_THREADS
661  case 't':
662 #if ALLOW_THREADED
663  threaded = true;
664 #else
665  eprintf("WARNING: -t is temporarily disabled!\n");
666 #endif
667  break;
668 #endif
669  case 'T':
670  compute_hashes = false;
671  break;
672  case 'v':
673  if (quiet) {
674  printf("%s\n", RZ_VERSION);
675  LISTS_FREE();
676  RZ_FREE(debugbackend);
677  free(customRarunProfile);
678  return 0;
679  } else {
681  LISTS_FREE();
682  RZ_FREE(debugbackend);
683  free(customRarunProfile);
684  return rz_main_version_print("rizin");
685  }
686  case 'V':
687  return rz_main_version_verify(1);
688  case 'w':
689  perms |= RZ_PERM_W;
690  break;
691  case 'x':
692  perms &= ~RZ_PERM_X;
693  rz_config_set(r->config, "io.exec", "false");
694  break;
695  default:
696  help++;
697  }
698  }
699  if (noStderr) {
700  if (-1 == close(2)) {
701  RZ_LOG_ERROR("Failed to close stderr");
702  LISTS_FREE();
703  RZ_FREE(debugbackend);
704  return 1;
705  }
706  const char nul[] = RZ_SYS_DEVNULL;
707  int new_stderr = open(nul, O_RDWR);
708  if (-1 == new_stderr) {
709  RZ_LOG_ERROR("Failed to open %s", nul);
710  LISTS_FREE();
711  RZ_FREE(debugbackend);
712  return 1;
713  }
714  if (2 != new_stderr) {
715  if (-1 == dup2(new_stderr, 2)) {
716  RZ_LOG_ERROR("Failed to dup2 stderr");
717  LISTS_FREE();
718  RZ_FREE(debugbackend);
719  return 1;
720  }
721  if (-1 == close(new_stderr)) {
722  RZ_LOG_ERROR("Failed to close %s", nul);
723  LISTS_FREE();
724  RZ_FREE(debugbackend);
725  return 1;
726  }
727  }
728  }
729  {
730  const char *dbg_profile = rz_config_get(r->config, "dbg.profile");
731  if (dbg_profile && *dbg_profile) {
732  char *msg = rz_file_slurp(dbg_profile, NULL);
733  if (msg) {
734  char *program = strstr(msg, "program=");
735  if (program) {
736  program += 8;
737  char *p = 0;
738  p = strstr(program, "\r\n");
739  if (!p) {
740  p = strchr(program, '\n');
741  }
742  if (p) {
743  *p = 0;
744  pfile = strdup(program);
745  }
746  }
747  free(msg);
748  } else {
749  eprintf("Cannot read dbg.profile '%s'\n", dbg_profile);
750  pfile = NULL; // strdup ("");
751  }
752  } else {
753  pfile = argv[opt.ind] ? strdup(argv[opt.ind]) : NULL;
754  }
755  }
756 
757  if (pfile && !*pfile) {
758  RZ_LOG_ERROR("Cannot open empty path\n");
759  ret = 1;
760  goto beach;
761  }
762 
763  if (do_list_io_plugins) {
764  if (rz_config_get_i(r->config, "cfg.plugins")) {
765  rz_core_loadlibs(r, RZ_CORE_LOADLIBS_ALL);
766  }
767  run_commands(r, NULL, prefiles, false, do_analysis);
768  run_commands(r, cmds, files, quiet, do_analysis);
769  if (quietLeak) {
770  exit(0);
771  }
776  rz_cons_flush();
777  LISTS_FREE();
778  free(pfile);
779  RZ_FREE(debugbackend);
780  return 0;
781  }
782 
783  if (help > 0) {
784  LISTS_FREE();
785  free(pfile);
786  RZ_FREE(debugbackend);
787  return main_help(help > 1 ? 2 : 0);
788  }
789  if (customRarunProfile) {
790  char *tfn = rz_file_temp(".rz-run");
791  if (!rz_file_dump(tfn, (const ut8 *)customRarunProfile, strlen(customRarunProfile), 0)) {
792  eprintf("Cannot create %s\n", tfn);
793  } else {
794  haveRarunProfile = true;
795  rz_config_set(r->config, "dbg.profile", tfn);
796  }
797  free(tfn);
798  }
799  if (debug == 1) {
800  if (opt.ind >= argc && !haveRarunProfile) {
801  RZ_LOG_ERROR("Missing argument for -d\n");
802  LISTS_FREE();
803  RZ_FREE(debugbackend);
804  return 1;
805  }
806  const char *src = haveRarunProfile ? pfile : argv[opt.ind];
807  if (src && *src) {
808  char *uri = strdup(src);
809  if (uri) {
810  char *p = strstr(uri, "://");
811  if (p) {
812  *p = 0;
813  // TODO: this must be specified by the io plugin, not hardcoded here
814  if (!strcmp(uri, "winedbg")) {
815  debugbackend = strdup("io");
816  } else {
817  debugbackend = uri;
818  uri = NULL;
819  }
820  debug = 2;
821  }
822  free(uri);
823  }
824  }
825  }
826 
827  tmp = NULL;
828  if (!load_l || (tmp = rz_sys_getenv("RZ_NOPLUGINS"))) {
829  rz_config_set_i(r->config, "cfg.plugins", 0);
830  free(tmp);
831  }
832  if (rz_config_get_i(r->config, "cfg.plugins")) {
833  rz_core_loadlibs(r, RZ_CORE_LOADLIBS_ALL);
834  }
835  run_commands(r, NULL, prefiles, false, do_analysis);
836  rz_list_free(prefiles);
837  prefiles = NULL;
838 
839  rz_bin_force_plugin(r->bin, forcebin);
840 
841  if (prj) {
842  rz_core_project_load_for_cli(r, prj, !pfile);
843  }
844 
845  if (do_connect) {
846  const char *uri = argv[opt.ind];
847  if (opt.ind >= argc) {
848  RZ_LOG_ERROR("Missing URI for -C\n");
849  LISTS_FREE();
850  RZ_FREE(debugbackend);
851  return 1;
852  }
853  if (strstr(uri, "://")) {
854  rz_core_cmdf(r, "R+ %s", uri);
855  } else {
856  argv[opt.ind] = rz_str_newf("http://%s/cmd/", argv[opt.ind]);
857  rz_core_cmdf(r, "R+ %s", argv[opt.ind]);
858  }
859  rz_core_cmd0(r, "R!=");
860  argv[opt.ind] = "-";
861  }
862 
863  switch (zflag) {
864  case 1:
865  rz_config_set(r->config, "bin.strings", "false");
866  break;
867  default:
868  break;
869  }
870  if (zflag > 3) {
871  eprintf("Sleeping now...\n");
872  rz_sys_sleep(zflag);
873  }
874 
875  if (run_rc) {
877  } else {
878  rz_config_set(r->config, "scr.utf8", "false");
879  }
880 
881  if (pfile && rz_file_is_directory(pfile)) {
882  if (debug) {
883  RZ_LOG_ERROR("Error: Cannot debug directories, yet.\n");
884  LISTS_FREE();
885  free(pfile);
886  RZ_FREE(debugbackend);
887  return 1;
888  }
889  if (rz_sys_chdir(argv[opt.ind])) {
890  RZ_LOG_ERROR("[d] Cannot open directory\n");
891  LISTS_FREE();
892  free(pfile);
893  RZ_FREE(debugbackend);
894  return 1;
895  }
896  } else if (argv[opt.ind] && !strcmp(argv[opt.ind], "-")) {
897  int sz;
898 #if __WINDOWS__
899  int result = _setmode(_fileno(stdin), _O_BINARY);
900  if (result == -1) {
901  RZ_LOG_ERROR("Cannot set stdin to binary mode");
902  return 1;
903  }
904 #endif
905  /* stdin/batch mode */
906  char *buf = rz_stdin_slurp(&sz);
907  eprintf("^D\n");
908 #if __WINDOWS__
909  const char *con_dev = "CON";
910 #else
911  const char *con_dev = "/dev/tty";
912 #endif
913  ut64 scr_color = rz_config_get_i(r->config, "scr.color");
914  const char *scr_interactive = rz_config_get(r->config, "scr.interactive");
915  while (rz_cons_free())
916  ;
917  rz_xfreopen(con_dev, "r", stdin);
918  rz_cons_new();
919  rz_config_set_i(r->config, "scr.color", scr_color);
920  rz_config_set(r->config, "scr.interactive", scr_interactive);
921  if (buf && sz > 0) {
922  char *path = rz_str_newf("malloc://%d", sz);
923  fh = rz_core_file_open(r, path, perms, mapaddr);
924  if (!fh) {
925  rz_cons_flush();
926  free(buf);
927  RZ_LOG_ERROR("[=] Cannot open '%s'\n", path);
928  LISTS_FREE();
929  free(path);
930  return 1;
931  }
932  rz_io_map_new(r->io, fh->fd, 7, 0LL, mapaddr,
933  rz_io_fd_size(r->io, fh->fd));
934  rz_io_write_at(r->io, mapaddr, (const ut8 *)buf, sz);
936  free(buf);
937  free(path);
938  // TODO: load rbin thing
939  } else {
940  RZ_LOG_ERROR("Cannot slurp from stdin\n");
941  free(buf);
942  LISTS_FREE();
943  return 1;
944  }
945  } else if (has_file_arg(argc, argv, &opt)) {
946  if (debug) {
947  if (asmbits) {
948  rz_config_set(r->config, "asm.bits", asmbits);
949  }
950  rz_config_set(r->config, "search.in", "dbg.map"); // implicit?
951  rz_config_set(r->config, "cfg.debug", "true");
952  perms = RZ_PERM_RWX;
953  if (opt.ind >= argc) {
954  RZ_LOG_ERROR("No program given to -d\n");
955  LISTS_FREE();
956  RZ_FREE(debugbackend);
957  return 1;
958  }
959  if (debug == 2) {
960  // autodetect backend with -D
961  if (strcmp(debugbackend, "dmp")) {
962  rz_config_set(r->config, "dbg.backend", debugbackend);
963  }
964  if (strcmp(debugbackend, "native")) {
965  if (!haveRarunProfile) {
966  pfile = strdup(argv[opt.ind++]);
967  }
968  // If plugin is winkd we should keep RWX permission to be able to write to the fd
969  if (strcmp(debugbackend, "winkd")) {
970  perms = RZ_PERM_RX; // XXX. should work with rw too
971  }
972  if (!strstr(pfile, "://")) {
973  opt.ind--; // take filename
974  }
975  fh = rz_core_file_open(r, pfile, perms, mapaddr);
976  iod = (r->io && fh) ? rz_io_desc_get(r->io, fh->fd) : NULL;
977  if (!strcmp(debugbackend, "gdb") || !strcmp(debugbackend, "dmp")) {
978  const char *filepath = rz_config_get(r->config, "dbg.exe.path");
979  ut64 addr = baddr;
980  if (addr == UINT64_MAX) {
981  addr = rz_config_get_i(r->config, "bin.baddr");
982  }
983  if (RZ_STR_ISNOTEMPTY(filepath) && rz_file_exists(filepath) && !rz_file_is_directory(filepath)) {
984  char *newpath = rz_file_abspath(filepath);
985  if (newpath) {
986  if (iod) {
987  free(iod->name);
988  iod->name = newpath;
989  }
990  if (addr == UINT64_MAX) {
991  addr = rz_debug_get_baddr(r->dbg, newpath);
992  }
994  }
995  } else if (is_valid_gdb_file(fh) || is_valid_dmp_file(fh)) {
996  filepath = iod->name;
997  if (RZ_STR_ISNOTEMPTY(filepath) && rz_file_exists(filepath) && !rz_file_is_directory(filepath)) {
998  if (addr == UINT64_MAX) {
999  addr = rz_debug_get_baddr(r->dbg, filepath);
1000  }
1001  rz_core_bin_load(r, filepath, addr);
1002  } else if ((filepath = get_file_in_cur_dir(filepath))) {
1003  // Present in local directory
1004  if (iod) {
1005  free(iod->name);
1006  iod->name = (char *)filepath;
1007  }
1008  if (addr == UINT64_MAX) {
1009  addr = rz_debug_get_baddr(r->dbg, filepath);
1010  }
1012  }
1013  }
1014  }
1015  }
1016  } else {
1017  const char *f = (haveRarunProfile && pfile) ? pfile : argv[opt.ind];
1018  is_gdb = (!memcmp(f, "gdb://", RZ_MIN(f ? strlen(f) : 0, 6)));
1019  if (!is_gdb) {
1020  pfile = strdup("dbg://");
1021  }
1022 #if __UNIX__
1023  /* implicit ./ to make unix behave like windows */
1024  if (f) {
1025  char *path, *escaped_path;
1026  if (strchr(f, '/')) {
1027  // f is a path
1028  path = strdup(f);
1029  } else {
1030  // f is a filename
1031  if (rz_file_exists(f)) {
1032  path = rz_str_prepend(strdup(f), "./");
1033  } else {
1034  path = rz_file_path(f);
1035  }
1036  }
1037  escaped_path = rz_str_arg_escape(path);
1038  pfile = rz_str_append(pfile, escaped_path);
1039  file = pfile; // probably leaks
1040  RZ_FREE(escaped_path);
1041  RZ_FREE(path);
1042  }
1043 #else
1044  if (f) {
1045  char *escaped_path = rz_str_arg_escape(f);
1046  pfile = rz_str_append(pfile, escaped_path);
1047  free(escaped_path);
1048  file = pfile; // rz_str_append (file, escaped_path);
1049  }
1050 #endif
1051  opt.ind++;
1052  while (opt.ind < argc) {
1053  char *escaped_arg = rz_str_arg_escape(argv[opt.ind]);
1054  file = rz_str_append(file, " ");
1055  file = rz_str_append(file, escaped_arg);
1056  free(escaped_arg);
1057  opt.ind++;
1058  }
1059  pfile = file;
1060  }
1061  }
1062  if (asmarch) {
1063  rz_config_set(r->config, "asm.arch", asmarch);
1064  }
1065  if (asmbits) {
1066  rz_config_set(r->config, "asm.bits", asmbits);
1067  }
1068  if (asmos) {
1069  rz_config_set(r->config, "asm.os", asmos);
1070  }
1071 
1072  if (!debug || debug == 2) {
1073  const char *dbg_profile = rz_config_get(r->config, "dbg.profile");
1074  if (opt.ind == argc && dbg_profile && *dbg_profile) {
1075  if (RZ_STR_ISEMPTY(pfile)) {
1076  RZ_LOG_ERROR("Missing file to open\n");
1077  ret = 1;
1078  RZ_FREE(debugbackend);
1079  goto beach;
1080  }
1081  fh = rz_core_file_open(r, pfile, perms, mapaddr);
1082  if (fh) {
1083  rz_core_bin_load(r, pfile, baddr);
1084  }
1085  }
1086  if (opt.ind < argc) {
1087  RZ_FREE(pfile);
1088  while (opt.ind < argc) {
1089  pfile = strdup(argv[opt.ind++]);
1090  fh = rz_core_file_open(r, pfile, perms, mapaddr);
1091  if (!fh && perms & RZ_PERM_W) {
1092  perms |= RZ_PERM_CREAT;
1093  fh = rz_core_file_open(r, pfile, perms, mapaddr);
1094  }
1095  if (perms & RZ_PERM_CREAT) {
1096  if (fh) {
1097  rz_config_set_i(r->config, "io.va", false);
1098  } else {
1099  eprintf("rz_io_create: Permission denied.\n");
1100  }
1101  }
1102  if (fh) {
1103  iod = r->io ? rz_io_desc_get(r->io, fh->fd) : NULL;
1104  if (iod && perms & RZ_PERM_X) {
1105  iod->perm |= RZ_PERM_X;
1106  }
1107  if (load_bin == LOAD_BIN_ALL) {
1108  const char *filepath = NULL;
1109  if (debug) {
1110  // XXX: incorrect for PIE binaries
1111  filepath = file ? strstr(file, "://") : NULL;
1112  filepath = filepath ? filepath + 3 : pfile;
1113  }
1114  if (r->file && iod && (iod->fd == r->file->fd) && iod->name) {
1115  filepath = iod->name;
1116  }
1117  /* Load rbin info from rz dbg:// or rz /bin/ls */
1118  /* the baddr should be set manually here */
1119  (void)rz_core_bin_load(r, filepath, baddr);
1120  // check if bin info is loaded and complain if -B was used
1121  RzBinFile *bi = rz_bin_cur(r->bin);
1122  bool haveBinInfo = bi && bi->o && bi->o->info && bi->o->info->type;
1123  if (!haveBinInfo && baddr != UT64_MAX) {
1124  eprintf("Warning: Don't use -B on unknown files. Consider using -m.\n");
1125  }
1126  } else {
1127  rz_io_map_new(r->io, iod->fd, perms, 0LL, mapaddr, rz_io_desc_size(iod));
1128  if (load_bin == LOAD_BIN_STRUCTURES_ONLY) {
1130  }
1131  }
1132  }
1133  }
1134  } else {
1135  if (fh) {
1136  iod = r->io ? rz_io_desc_get(r->io, fh->fd) : NULL;
1137  if (iod) {
1138  perms = iod->perm;
1139  rz_io_map_new(r->io, iod->fd, perms, 0LL, 0LL, rz_io_desc_size(iod));
1140  }
1141  }
1142  }
1143  if (mapaddr) {
1144  if (rz_config_get_i(r->config, "file.info")) {
1145  int fd = rz_io_fd_get_current(r->io);
1146  RzIODesc *desc = rz_io_desc_get(r->io, fd);
1147  if (desc) {
1148  RzBinOptions opt;
1149  opt.sz = 1024 * 1024 * 1;
1150  rz_core_bin_options_init(r, &opt, desc->fd, mapaddr, 0);
1151  RzBinFile *bf = rz_bin_open_io(r->bin, &opt);
1153  }
1154  }
1155  }
1156  } else {
1157  RzCoreFile *f = rz_core_file_open(r, pfile, perms, mapaddr);
1158  if (f) {
1159  fh = f;
1160  }
1161  if (fh) {
1162  rz_debug_use(r->dbg, is_gdb ? "gdb" : debugbackend);
1163  }
1164  /* load symbols when doing rz -d ls */
1165  // NOTE: the baddr is redefined to support PIE/ASLR
1166  baddr = rz_debug_get_baddr(r->dbg, pfile);
1167 
1168  if (baddr != UT64_MAX && baddr != 0 && r->dbg->verbose) {
1169  eprintf("bin.baddr 0x%08" PFMT64x "\n", baddr);
1170  }
1171  if (load_bin == LOAD_BIN_ALL) {
1172  if (baddr && baddr != UT64_MAX && r->dbg->verbose) {
1173  eprintf("Using 0x%" PFMT64x "\n", baddr);
1174  }
1175  if (rz_core_bin_load(r, pfile, baddr)) {
1176  RzBinObject *obj = rz_bin_cur_object(r->bin);
1177  if (obj && obj->info) {
1178  if (r->dbg->verbose) {
1179  eprintf("asm.bits %d\n", obj->info->bits);
1180  }
1181 #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ && __x86_64__
1182  ut64 bitness = rz_config_get_i(r->config, "asm.bits");
1183  if (bitness == 32) {
1184  eprintf("glibc.fc_offset = 0x00148\n");
1185  rz_config_set_i(r->config, "dbg.glibc.fc_offset", 0x00148);
1186  }
1187 #endif
1188  }
1189  }
1190  }
1192  // Set Thumb Mode if necessary
1193  RzRegItem *thumb_reg = rz_reg_get(r->dbg->reg, "thumb", RZ_REG_TYPE_ANY);
1194  if (thumb_reg && rz_reg_get_value(r->dbg->reg, thumb_reg)) {
1195  rz_config_set_i(r->config, "asm.bits", 16);
1196  }
1197  rz_cons_reset();
1198  }
1199  if (!pfile) {
1200  pfile = file;
1201  }
1202  if (!fh && !prj) {
1203  if (pfile && *pfile) {
1204  rz_cons_flush();
1205  if (perms & RZ_PERM_W) {
1206  RZ_LOG_ERROR("[w] Cannot open '%s' for writing.\n", pfile);
1207  } else {
1208  RZ_LOG_ERROR("[r] Cannot open '%s'\n", pfile);
1209  }
1210  } else {
1211  RZ_LOG_ERROR("Missing file to open\n");
1212  }
1213  ret = 1;
1214  goto beach;
1215  }
1216  if (!r->file) { // no given file
1217  ret = 1;
1218  goto beach;
1219  }
1220  if (r->bin->cur && r->bin->cur->o && r->bin->cur->o->info && r->bin->cur->o->info->rclass && !strcmp("fs", r->bin->cur->o->info->rclass)) {
1221  const char *fstype = r->bin->cur->o->info->bclass;
1222  rz_core_cmdf(r, "m /root %s @ 0", fstype);
1223  }
1224  rz_core_cmd0(r, "R!"); // initalize io subsystem
1225  iod = r->io && fh ? rz_io_desc_get(r->io, fh->fd) : NULL;
1226  if (mapaddr) {
1227  rz_core_seek(r, mapaddr, true);
1228  }
1229  rz_list_foreach (evals, iter, cmdn) {
1230  rz_config_eval(r->config, cmdn);
1231  rz_cons_flush();
1232  }
1233  if (asmarch) {
1234  rz_config_set(r->config, "asm.arch", asmarch);
1235  }
1236  if (asmbits) {
1237  rz_config_set(r->config, "asm.bits", asmbits);
1238  }
1239  if (asmos) {
1240  rz_config_set(r->config, "asm.os", asmos);
1241  }
1242 
1243  debug = r->file && iod && (r->file->fd == iod->fd) && iod->plugin &&
1244  (iod->plugin->isdbg || (debug == 2 && !strcmp(iod->plugin->name, "dmp")));
1245  if (debug) {
1246  rz_core_setup_debugger(r, debugbackend, baddr == UT64_MAX);
1247  }
1248  RZ_FREE(debugbackend);
1249  RzBinObject *o = rz_bin_cur_object(r->bin);
1250  if (!debug && o && !o->regstate) {
1251  RzFlagItem *fi = rz_flag_get(r->flags, "entry0");
1252  if (fi) {
1253  rz_core_seek(r, fi->offset, true);
1254  } else {
1255  if (o) {
1257  RzListIter *iter;
1258  RzBinSection *s;
1259  rz_list_foreach (sections, iter, s) {
1260  if (s->perm & RZ_PERM_X) {
1261  ut64 addr = s->vaddr ? s->vaddr : s->paddr;
1262  rz_core_seek(r, addr, true);
1263  break;
1264  }
1265  }
1266  }
1267  }
1268  }
1269  if (o && o->info && compute_hashes) {
1270  // TODO: recall with limit=0 ?
1271  ut64 limit = rz_config_get_i(r->config, "bin.hashlimit");
1272  RzBinFile *bf = r->bin->cur;
1273  if (bf) {
1274  RzList *old_hashes = rz_bin_file_set_hashes(r->bin, rz_bin_file_compute_hashes(r->bin, bf, limit));
1275  rz_list_free(old_hashes);
1276  }
1277  }
1278  if (s_seek) {
1279  seek = rz_num_math(r->num, s_seek);
1280  if (seek != UT64_MAX) {
1281  rz_core_seek(r, seek, true);
1282  }
1283  }
1284 
1285  if (fullfile) {
1287  }
1288 
1289  rz_core_seek(r, r->offset, true); // read current block
1290 
1291  /* check if file.path has changed */
1292  if (iod && !strstr(iod->uri, "://")) {
1293  const char *npath;
1294  char *path = strdup(rz_config_get(r->config, "file.path"));
1295  iod = r->io ? rz_io_desc_get(r->io, fh->fd) : NULL;
1296  npath = rz_config_get(r->config, "file.path");
1297  if (!quiet && path && *path && npath && strcmp(path, npath)) {
1298  eprintf("WARNING: file.path change: %s => %s\n", path, npath);
1299  }
1300  free(path);
1301  }
1302 
1303  rz_list_foreach (evals, iter, cmdn) {
1304  rz_config_eval(r->config, cmdn);
1305  rz_cons_flush();
1306  }
1307 
1308  // no flagspace selected by default the beginning
1309  rz_flag_space_set(r->flags, NULL);
1310  /* load <file>.rz */
1311  {
1312  char *f = rz_str_newf("%s.rz", pfile);
1313  const char *uri_splitter = strstr(f, "://");
1314  const char *path = uri_splitter ? uri_splitter + 3 : f;
1315  if (rz_file_exists(path)) {
1316  // TODO: should 'q' unset the interactive bit?
1317  bool isInteractive = rz_cons_is_interactive();
1318  if (isInteractive && rz_cons_yesno('n', "Do you want to run the '%s' script? (y/N) ", path)) {
1320  }
1321  }
1322  free(f);
1323  }
1324  } else {
1326 
1327  rz_list_foreach (evals, iter, cmdn) {
1328  rz_config_eval(r->config, cmdn);
1329  rz_cons_flush();
1330  }
1331  if (asmarch) {
1332  rz_config_set(r->config, "asm.arch", asmarch);
1333  }
1334  if (asmbits) {
1335  rz_config_set(r->config, "asm.bits", asmbits);
1336  }
1337  if (asmos) {
1338  rz_config_set(r->config, "asm.os", asmos);
1339  }
1340  }
1341  {
1342  char *global_rc = rz_path_system_rc();
1343  if (rz_file_exists(global_rc)) {
1344  (void)rz_core_run_script(r, global_rc);
1345  }
1346  free(global_rc);
1347  }
1348 
1349  if (do_analysis > 0) {
1350  switch (do_analysis) {
1351  case 1: rz_core_cmd0(r, "aa"); break;
1352  case 2: rz_core_cmd0(r, "aaa"); break;
1353  case 3: rz_core_cmd0(r, "aaaa"); break;
1354  default: rz_core_cmd0(r, "aaaaa"); break;
1355  }
1356  rz_cons_flush();
1357  }
1358 #if UNCOLORIZE_NONTTY
1359 #if __UNIX__
1360  if (!rz_cons_isatty()) {
1361  rz_config_set_i(r->config, "scr.color", COLOR_MODE_DISABLED);
1362  }
1363 #endif
1364 #endif
1365  if (fullfile) {
1367  }
1368  if (perms & RZ_PERM_W) {
1369  RzPVector *maps = rz_io_maps(r->io);
1370  void **it;
1371  rz_pvector_foreach (maps, it) {
1372  RzIOMap *map = *it;
1373  map->perm |= RZ_PERM_W;
1374  }
1375  }
1376  ret = run_commands(r, cmds, files, quiet, do_analysis);
1377  rz_list_free(cmds);
1378  rz_list_free(evals);
1380  cmds = evals = files = NULL;
1381  if (forcequit) {
1382  ret = 1;
1383  }
1384  if (ret) {
1385  ret = 0;
1386  goto beach;
1387  }
1388  if (rz_config_get_i(r->config, "scr.prompt")) {
1389  if (run_rc && rz_config_get_i(r->config, "cfg.fortunes")) {
1391  rz_cons_flush();
1392  }
1393  }
1394  if (quiet) {
1395  rz_config_set(r->config, "scr.wheel", "false");
1396  rz_config_set(r->config, "scr.interactive", "false");
1397  rz_config_set(r->config, "scr.prompt", "false");
1398  }
1399  r->num->value = 0;
1400  if (zerosep) {
1401  rz_cons_zero();
1402  }
1403  if (seek != UT64_MAX) {
1404  rz_core_seek(r, seek, true);
1405  }
1406 
1407  // no flagspace selected by default the beginning
1408  rz_flag_space_set(r->flags, NULL);
1409  for (;;) {
1411  ret = r->num->value;
1412  debug = rz_config_get_i(r->config, "cfg.debug");
1413  if (ret != -1 && rz_cons_is_interactive()) {
1414  char *question;
1415  bool no_question_debug = ret & 1;
1416  bool no_question_save = (ret & 2) >> 1;
1417  bool y_kill_debug = (ret & 4) >> 2;
1418  bool y_save_project = (ret & 8) >> 3;
1419 
1420  if (rz_core_task_running_tasks_count(&r->tasks) > 0) {
1421  if (rz_cons_yesno('y', "There are running background tasks. Do you want to kill them? (Y/n)")) {
1422  rz_core_task_break_all(&r->tasks);
1423  rz_core_task_join(&r->tasks, r->tasks.main_task, -1);
1424  } else {
1425  continue;
1426  }
1427  }
1428 
1429  if (debug) {
1430  if (no_question_debug) {
1431  if (rz_config_get_i(r->config, "dbg.exitkills") && y_kill_debug) {
1432  rz_debug_kill(r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL
1433  }
1434  } else {
1435  if (rz_cons_yesno('y', "Do you want to quit? (Y/n)")) {
1436  if (rz_config_get_i(r->config, "dbg.exitkills") &&
1437  rz_debug_can_kill(r->dbg) &&
1438  rz_cons_yesno('y', "Do you want to kill the process? (Y/n)")) {
1439  rz_debug_kill(r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL
1440  }
1441  // Even if killed above, we must still detach, otherwise
1442  // there will be a zombie on macOS!
1443  rz_debug_detach(r->dbg, r->dbg->pid);
1444  } else {
1445  continue;
1446  }
1447  }
1448  }
1449 
1450  prj = rz_config_get(r->config, "prj.file");
1451  bool compress = rz_config_get_b(r->config, "prj.compress");
1453  if (no_question_save) {
1454  if (prj && *prj && y_save_project) {
1455  prj_err = rz_project_save_file(r, prj, compress);
1456  }
1457  } else {
1458  question = rz_str_newf("Do you want to save the '%s' project? (Y/n)", prj);
1459  if (prj && *prj && rz_cons_yesno('y', "%s", question)) {
1460  prj_err = rz_project_save_file(r, prj, compress);
1461  }
1462  free(question);
1463  }
1464  if (prj_err != RZ_PROJECT_ERR_SUCCESS) {
1465  RZ_LOG_ERROR("Failed to save project: %s\n", rz_project_err_message(prj_err));
1466  continue;
1467  }
1468 
1469  if (rz_config_get_i(r->config, "scr.confirmquit")) {
1470  if (!rz_cons_yesno('n', "Do you want to quit? (Y/n)")) {
1471  continue;
1472  }
1473  }
1474  } else {
1475  // rz_core_project_save (r, prj);
1476  if (debug && rz_config_get_i(r->config, "dbg.exitkills")) {
1477  rz_debug_kill(r->dbg, 0, false, 9); // KILL
1478  }
1479  }
1480  break;
1481  }
1482 
1483  if (mustSaveHistory(r->config)) {
1484  char *history = rz_path_home_history();
1485  rz_line_hist_save(history);
1486  free(history);
1487  }
1488 
1489  /* capture return value */
1490  ret = r->num->value;
1491 beach:
1492  if (quietLeak) {
1493  exit(ret);
1494  return ret;
1495  }
1496 
1497  rz_core_task_sync_end(&r->tasks);
1498 
1499  // not really needed, cause rz_core_fini will close the file
1500  // and this fh may be come stale during the command
1501  // execution.
1502  // rz_core_file_close (r, fh);
1503  rz_core_free(r);
1504  rz_cons_set_raw(0);
1505  rz_cons_free();
1506  LISTS_FREE();
1507  free(debugbackend);
1508  RZ_FREE(pfile);
1509  return ret;
1510 }
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
RZ_API RZ_OWN RzList * rz_bin_file_set_hashes(RzBin *bin, RZ_OWN RzList *new_hashes)
Set file_hashes on current RzBinInfo.
Definition: bfile.c:488
RZ_API RZ_OWN RzList * rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64 limit)
Definition: bfile.c:411
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_API void rz_bin_force_plugin(RzBin *bin, const char *name)
Definition: bin.c:906
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_sections(RZ_NONNULL RzBin *bin)
Definition: bin.c:597
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
const char * desc
Definition: bin_vsf.c:19
FILE * fh
Definition: cabinfo.c:52
RZ_API void rz_core_bin_options_init(RzCore *core, RZ_OUT RzBinOptions *opts, int fd, ut64 baseaddr, ut64 loadaddr)
Definition: cbin.c:87
RZ_API bool rz_core_bin_load_structs(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file)
Definition: cbin.c:236
RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:311
RZ_API void rz_core_parse_rizinrc(RzCore *r)
Definition: cconfig.c:3704
RZ_API void rz_core_debug_map_update_flags(RzCore *core)
Definition: cdebug.c:462
RZ_API RzCmdStatus rz_core_debug_plugins_print(RzCore *core, RzCmdStateOutput *state)
Definition: cdebug.c:329
RZ_API RZ_BORROW RzCoreFile * rz_core_file_open(RZ_NONNULL RzCore *r, RZ_NONNULL const char *file, int flags, ut64 loadaddr)
Tries to open the file as is, otherwise tries as is a compilation of files.
Definition: cfile.c:1182
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr)
Definition: cfile.c:942
RZ_API int rz_core_setup_debugger(RzCore *r, const char *debugbackend, bool attach)
Definition: cio.c:7
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API RzCmdStatus rz_core_io_plugins_print(RzIO *io, RzCmdStateOutput *state)
Print the registered IO plugins according to state.
Definition: cio.c:481
RZ_API int rz_core_cmd_lines(RzCore *core, const char *lines)
Definition: cmd.c:5336
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API int rz_core_cmd_file(RzCore *core, const char *file)
Definition: cmd.c:5341
RZ_API bool rz_core_run_script(RzCore *core, RZ_NONNULL const char *file)
Definition: cmd.c:457
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
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_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
Definition: cmd_api.c:2603
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 bool rz_core_project_load_for_cli(RzCore *core, const char *file, bool load_bin_io)
Definition: cmd_project.c:6
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:68
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 bool rz_config_eval(RZ_NONNULL RzConfig *cfg, RZ_NONNULL const char *str)
Sets the configuration variable and its value passed as argument.
Definition: config.c:575
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_cons_zero(void)
Definition: cons.c:1749
RZ_API void rz_cons_set_raw(bool is_raw)
Definition: cons.c:1617
RZ_API RzCons * rz_cons_new(void)
Definition: cons.c:589
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
RZ_API bool rz_cons_isatty(void)
Definition: cons.c:1341
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_API void rz_cons_reset(void)
Definition: cons.c:804
RZ_API RzCons * rz_cons_free(void)
Definition: cons.c:658
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static fork const void static count close
Definition: sflib.h:33
RZ_API int rz_line_hist_save(RZ_NONNULL const char *path)
Save the history of commands executed until now to file path.
Definition: dietline.c:497
const char * v
Definition: dsignal.c:12
size_t map(int syms, int left, int len)
Definition: enough.c:237
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RZ_API void rz_core_fortune_print_random(RzCore *core)
Definition: fortune.c:60
unsigned short prefix[65536]
Definition: gun.c:163
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API bool rz_cons_yesno(int def, const char *fmt,...)
Definition: input.c:666
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
RZ_API void rz_core_prompt_loop(RzCore *r)
Definition: core.c:2688
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
RZ_API void rz_core_free(RzCore *c)
Definition: core.c:2683
RZ_API RzCore * rz_core_new(void)
Definition: core.c:866
RZ_API bool rz_debug_can_kill(RzDebug *dbg)
check whether rz_debug_kill() will not definitely fail (for example because kill is unimplemented by ...
Definition: debug.c:1594
RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug.c:1598
RZ_API int rz_debug_detach(RzDebug *dbg, int pid)
Definition: debug.c:583
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
Definition: debug.c:1682
static bool mustSaveHistory(RzConfig *c)
Definition: rizin.c:320
#define ALLOW_THREADED
Definition: rizin.c:5
static bool has_file_arg(int argc, const char **argv, RzGetopt *opt)
Definition: rizin.c:366
#define LISTS_FREE()
RZ_API int rz_main_rizin(int argc, const char **argv)
Definition: rizin.c:370
static bool is_valid_gdb_file(RzCoreFile *fh)
Definition: rizin.c:14
static void set_color_default(RzCore *r)
Definition: rizin.c:331
static int main_help(int line)
Definition: rizin.c:92
static int rz_main_version_verify(int show)
Definition: rizin.c:32
static bool is_valid_dmp_file(RzCoreFile *fh)
Definition: rizin.c:19
#define USE_THREADS
Definition: rizin.c:4
static char * get_file_in_cur_dir(const char *filepath)
Definition: rizin.c:24
static bool run_commands(RzCore *r, RzList *cmds, RzList *files, bool quiet, int do_analysis)
Definition: rizin.c:279
static int main_print_var(const char *var_name)
Definition: rizin.c:216
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_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
RZ_API int rz_core_loadlibs(RzCore *core, int where)
Definition: libs.c:119
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 static handler static getegid char static len static pgid const char static path dup2
Definition: sflib.h:94
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
line
Definition: setup.py:34
const char * name
Definition: op.c:541
RZ_API bool rz_debug_use(RzDebug *dbg, const char *str)
Definition: plugin.c:17
RZ_API RZ_NONNULL const char * rz_project_err_message(RzProjectErr err)
Definition: project.c:11
RZ_API RzProjectErr rz_project_save_file(RzCore *core, const char *file, bool compress)
Definition: project.c:42
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
#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
@ COLOR_MODE_16
Definition: rz_cons.h:443
@ COLOR_MODE_16M
Definition: rz_cons.h:445
@ COLOR_MODE_256
Definition: rz_cons.h:444
@ COLOR_MODE_DISABLED
Definition: rz_cons.h:442
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_is_directory(const char *str)
Definition: file.c:167
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
RZ_API char * rz_stdin_slurp(int *sz)
Definition: file.c:408
RZ_API char * rz_file_abspath(const char *file)
Definition: file.c:267
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 char * rz_file_path(const char *bin)
Definition: file.c:354
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr)
Definition: getopt.c:17
RZ_API int rz_getopt_next(RzGetopt *opt)
Definition: getopt.c:29
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RZ_API ut64 rz_io_desc_size(RzIODesc *desc)
Definition: io_desc.c:224
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
RZ_API RZ_BORROW RzPVector * rz_io_maps(RzIO *io)
Returns the pointer to vector containing maps list.
Definition: io_map.c:435
RZ_API int rz_io_fd_get_current(RzIO *io)
Definition: io_fd.c:135
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
RZ_API RzIOMap * rz_io_map_new(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:50
RZ_API int rz_lib_open(RzLib *lib, const char *file)
Definition: lib.c:281
#define RZ_LIB_EXT
Definition: rz_lib.h:31
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API int rz_main_version_print(const char *program)
Definition: main.c:49
RZ_API int rz_main_rz_find(int argc, const char **argv)
Definition: rz-find.c:474
RZ_API int rz_main_rz_diff(int argc, const char **argv)
Definition: rz-diff.c:2254
RZ_API int rz_main_rz_ax(int argc, const char **argv)
Definition: rz-ax.c:721
RZ_API int rz_main_rz_asm(int argc, const char **argv)
RZ_API int rz_main_rz_gg(int argc, const char **argv)
Definition: rz-gg.c:116
RZ_API int rz_main_rz_bin(int argc, const char **argv)
Definition: rz-bin.c:681
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API RZ_OWN char * rz_path_home_config(void)
Return the home directory for config files (e.g. ~/.config/rizin)
Definition: path.c:198
RZ_API RZ_OWN char * rz_path_system_rc(void)
Return the system path of the global rizinrc file.
Definition: path.c:169
RZ_API RZ_OWN char * rz_path_incdir(void)
Return the directory where include files are placed.
Definition: path.c:141
RZ_API RZ_OWN char * rz_path_home_config_rc(void)
Return the path of the rizinrc file in the home config directory.
Definition: path.c:226
RZ_API RZ_OWN char * rz_path_home_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the home prefix.
Definition: path.c:182
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
RZ_API RZ_OWN char * rz_path_home_cache(void)
Return the home directory for cache files (e.g. ~/.cache/rizin)
Definition: path.c:205
RZ_API RZ_OWN char * rz_path_home_history(void)
Return the path for the command history file.
Definition: path.c:212
RZ_API RZ_OWN char * rz_path_libdir(void)
Return the directory where the Rizin libraries are placed.
Definition: path.c:155
RZ_API RZ_OWN char * rz_path_prefix(RZ_NULLABLE const char *path)
Return path prefixed by the Rizin install prefix.
Definition: path.c:121
RZ_API RZ_OWN char * rz_path_home_config_rcdir(void)
Return the home directory of config rizinrc.d.
Definition: path.c:233
RZ_API RZ_OWN char * rz_path_home_rc(void)
Return the path of the rizinrc file in the home directory.
Definition: path.c:219
@ RZ_PROJECT_ERR_SUCCESS
Definition: rz_project.h:20
enum rz_project_err RzProjectErr
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
RZ_API char * rz_run_get_environ_profile(char **env)
Definition: run.c:1329
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char * rz_str_prepend(char *ptr, const char *string)
Definition: str.c:1027
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API char * rz_str_arg_escape(const char *arg)
Definition: str.c:2413
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
Definition: sys.c:483
RZ_API void rz_sys_env_init(void)
Definition: sys.c:1108
RZ_API bool rz_sys_getenv_asbool(const char *key)
Return true if the environment variable has the value 1, false otherwise.
Definition: sys.c:511
#define RZ_SYS_DEVNULL
Definition: rz_sys.h:10
RZ_API bool rz_sys_chdir(RZ_NONNULL const char *s)
Change current directory to s, taking care of home expansion ~.
Definition: sys.c:532
RZ_API int rz_sys_crash_handler(const char *cmd)
Definition: sys.c:457
RZ_API int rz_sys_sleep(int secs)
Sleep for secs seconds.
Definition: sys.c:300
RZ_API char ** rz_sys_get_environ(void)
Definition: sys.c:1115
#define RZ_PERM_CREAT
Definition: rz_types.h:103
#define RZ_PERM_W
Definition: rz_types.h:94
#define rz_xfreopen(pathname, mode, stream)
Definition: rz_types.h:644
#define RZ_PERM_X
Definition: rz_types.h:95
#define RZ_PERM_RX
Definition: rz_types.h:97
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define RZ_PERM_RWX
Definition: rz_types.h:98
#define RZ_FREE(x)
Definition: rz_types.h:369
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
#define RZ_PLUGINS
Definition: rz_userconf.h:72
#define RZ_SIGDB
Definition: rz_userconf.h:75
#define RZ_IS_PORTABLE
Definition: rz_userconf.h:60
#define RZ_DATADIR
Definition: rz_userconf.h:73
#define RZ_SDB_MAGIC
Definition: rz_userconf.h:86
#define RZ_BINRC
Definition: rz_userconf.h:90
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
#define RZ_VERSION
Definition: rz_version.h:8
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define O_RDWR
Definition: sftypes.h:488
int sigset_t
Definition: sftypes.h:63
#define d(i)
Definition: sha256.c:44
#define f(i)
Definition: sha256.c:46
#define c(i)
Definition: sha256.c:43
#define UINT64_MAX
Definition: gzappend.c:170
Definition: z80asm.h:102
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
char * type
Definition: rz_bin.h:211
RzBinInfo * info
Definition: rz_bin.h:287
char * regstate
Definition: rz_bin.h:286
Represent the output state of a command handler.
Definition: rz_cmd.h:91
ut64 offset
Definition: rz_flag.h:38
const char ** argv
Definition: rz_getopt.h:18
const char * arg
Definition: rz_getopt.h:15
char * name
Definition: rz_io.h:99
int fd
Definition: rz_io.h:96
char * uri
Definition: rz_io.h:98
struct rz_io_plugin_t * plugin
Definition: rz_io.h:103
int perm
Definition: rz_io.h:97
const char * name
Definition: rz_io.h:115
bool isdbg
Definition: rz_io.h:124
Definition: dis.h:43
static char ** env
Definition: sys.c:32
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id)
Definition: task.c:96
RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler)
Definition: task.c:495
RZ_API void rz_core_task_sync_end(RzCoreTaskScheduler *scheduler)
Definition: task.c:432
RZ_API int rz_core_task_running_tasks_count(RzCoreTaskScheduler *scheduler)
Definition: task.c:71
RZ_API void rz_core_task_sync_begin(RzCoreTaskScheduler *scheduler)
Definition: task.c:421
static int debug
Definition: visual.c:21
static st64 delta
Definition: vmenus.c:2425
#define SIGWINCH
Definition: win.h:88
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int file
Definition: z80asm.c:58
static int addr
Definition: z80asm.c:58
static int seek(char *argv[])