372 bool forcequit =
false;
373 bool haveRarunProfile =
false;
379 const char *prj =
NULL;
382 bool do_connect =
false;
383 bool fullfile =
false;
384 bool zerosep =
false;
388 LOAD_BIN_STRUCTURES_ONLY } load_bin = LOAD_BIN_ALL;
393 bool do_list_io_plugins =
false;
396 const char *asmarch =
NULL;
397 const char *asmos =
NULL;
398 const char *forcebin =
NULL;
399 const char *asmbits =
NULL;
400 char *customRarunProfile =
NULL;
403 bool quietLeak =
false;
405 const char *s_seek =
NULL;
406 bool compute_hashes =
true;
413 #define LISTS_FREE() \
415 rz_list_free(cmds); \
416 rz_list_free(evals); \
417 rz_list_free(files); \
418 rz_list_free(prefiles); \
421 bool noStderr =
false;
425 sigemptyset(&sigBlockMask);
427 rz_signal_sigmask(SIG_BLOCK, &sigBlockMask,
NULL);
437 char *fmt = (sysdbg && *sysdbg)
464 r->io->envprofile = envprofile;
468 if (argc > 2 && !strcmp(
argv[1],
"-") && !strcmp(
argv[2],
"-i")) {
475 if (argc == 2 && !strcmp(
argv[1],
"-H")) {
483 char *debugbackend =
strdup(
"native");
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");
519 do_analysis += do_analysis ? 1 : 2;
537 case 'd':
debug = 1;
break;
540 RZ_LOG_ERROR(
"Sorry. No debugger backend available.\n");
549 if (!strcmp(opt.
arg,
"?")) {
560 if (!strcmp(opt.
arg,
"q")) {
603 do_list_io_plugins =
true;
615 if (load_bin == LOAD_BIN_ALL) {
616 load_bin = LOAD_BIN_NOTHING;
617 }
else if (load_bin == LOAD_BIN_NOTHING) {
618 load_bin = LOAD_BIN_STRUCTURES_ONLY;
647 RZ_LOG_ERROR(
"Cannot open empty rz-run profile path\n");
651 haveRarunProfile =
true;
665 eprintf(
"WARNING: -t is temporarily disabled!\n");
670 compute_hashes =
false;
677 free(customRarunProfile);
683 free(customRarunProfile);
700 if (-1 ==
close(2)) {
707 int new_stderr = open(nul,
O_RDWR);
708 if (-1 == new_stderr) {
714 if (2 != new_stderr) {
715 if (-1 ==
dup2(new_stderr, 2)) {
721 if (-1 ==
close(new_stderr)) {
730 const char *dbg_profile =
rz_config_get(
r->config,
"dbg.profile");
731 if (dbg_profile && *dbg_profile) {
734 char *program = strstr(
msg,
"program=");
738 p = strstr(program,
"\r\n");
740 p = strchr(program,
'\n');
749 eprintf(
"Cannot read dbg.profile '%s'\n", dbg_profile);
757 if (pfile && !*pfile) {
763 if (do_list_io_plugins) {
789 if (customRarunProfile) {
791 if (!
rz_file_dump(tfn, (
const ut8 *)customRarunProfile, strlen(customRarunProfile), 0)) {
792 eprintf(
"Cannot create %s\n", tfn);
794 haveRarunProfile =
true;
800 if (opt.
ind >= argc && !haveRarunProfile) {
806 const char *
src = haveRarunProfile ? pfile :
argv[opt.
ind];
810 char *
p = strstr(uri,
"://");
814 if (!strcmp(uri,
"winedbg")) {
815 debugbackend =
strdup(
"io");
846 const char *uri =
argv[opt.
ind];
847 if (opt.
ind >= argc) {
853 if (strstr(uri,
"://")) {
883 RZ_LOG_ERROR(
"Error: Cannot debug directories, yet.\n");
899 int result = _setmode(_fileno(stdin), _O_BINARY);
909 const char *con_dev =
"CON";
911 const char *con_dev =
"/dev/tty";
914 const char *scr_interactive =
rz_config_get(
r->config,
"scr.interactive");
953 if (opt.
ind >= argc) {
961 if (strcmp(debugbackend,
"dmp")) {
964 if (strcmp(debugbackend,
"native")) {
965 if (!haveRarunProfile) {
969 if (strcmp(debugbackend,
"winkd")) {
972 if (!strstr(pfile,
"://")) {
977 if (!strcmp(debugbackend,
"gdb") || !strcmp(debugbackend,
"dmp")) {
996 filepath = iod->
name;
1006 iod->
name = (
char *)filepath;
1017 const char *
f = (haveRarunProfile && pfile) ? pfile :
argv[opt.
ind];
1018 is_gdb = (!memcmp(
f,
"gdb://",
RZ_MIN(
f ? strlen(
f) : 0, 6)));
1020 pfile =
strdup(
"dbg://");
1025 char *
path, *escaped_path;
1026 if (strchr(
f,
'/')) {
1052 while (opt.
ind < argc) {
1073 const char *dbg_profile =
rz_config_get(
r->config,
"dbg.profile");
1074 if (opt.
ind == argc && dbg_profile && *dbg_profile) {
1086 if (opt.
ind < argc) {
1088 while (opt.
ind < argc) {
1099 eprintf(
"rz_io_create: Permission denied.\n");
1107 if (load_bin == LOAD_BIN_ALL) {
1108 const char *filepath =
NULL;
1112 filepath = filepath ? filepath + 3 : pfile;
1114 if (
r->file && iod && (iod->
fd ==
r->file->fd) && iod->
name) {
1115 filepath = iod->
name;
1124 eprintf(
"Warning: Don't use -B on unknown files. Consider using -m.\n");
1128 if (load_bin == LOAD_BIN_STRUCTURES_ONLY) {
1149 opt.sz = 1024 * 1024 * 1;
1171 if (load_bin == LOAD_BIN_ALL) {
1177 if (obj && obj->
info) {
1178 if (
r->dbg->verbose) {
1181 #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ && __x86_64__
1183 if (bitness == 32) {
1184 eprintf(
"glibc.fc_offset = 0x00148\n");
1203 if (pfile && *pfile) {
1206 RZ_LOG_ERROR(
"[w] Cannot open '%s' for writing.\n", pfile);
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;
1229 rz_list_foreach (evals,
iter, cmdn) {
1269 if (o && o->
info && compute_hashes) {
1292 if (iod && !strstr(iod->
uri,
"://")) {
1297 if (!quiet &&
path && *
path && npath && strcmp(
path, npath)) {
1298 eprintf(
"WARNING: file.path change: %s => %s\n",
path, npath);
1303 rz_list_foreach (evals,
iter, cmdn) {
1309 rz_flag_space_set(
r->flags,
NULL);
1313 const char *uri_splitter = strstr(
f,
"://");
1314 const char *
path = uri_splitter ? uri_splitter + 3 :
f;
1318 if (isInteractive &&
rz_cons_yesno(
'n',
"Do you want to run the '%s' script? (y/N) ",
path)) {
1327 rz_list_foreach (evals,
iter, cmdn) {
1349 if (do_analysis > 0) {
1350 switch (do_analysis) {
1358 #if UNCOLORIZE_NONTTY
1408 rz_flag_space_set(
r->flags,
NULL);
1411 ret =
r->num->value;
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;
1421 if (
rz_cons_yesno(
'y',
"There are running background tasks. Do you want to kill them? (Y/n)")) {
1430 if (no_question_debug) {
1438 rz_cons_yesno(
'y',
"Do you want to kill the process? (Y/n)")) {
1453 if (no_question_save) {
1454 if (prj && *prj && y_save_project) {
1458 question =
rz_str_newf(
"Do you want to save the '%s' project? (Y/n)", prj);
1490 ret =
r->num->value;
RZ_API RZ_OWN RzList * rz_bin_file_set_hashes(RzBin *bin, RZ_OWN RzList *new_hashes)
Set file_hashes on current RzBinInfo.
RZ_API RZ_OWN RzList * rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64 limit)
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
RZ_API RzBinFile * rz_bin_open_io(RzBin *bin, RzBinOptions *opt)
RZ_API void rz_bin_force_plugin(RzBin *bin, const char *name)
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_sections(RZ_NONNULL RzBin *bin)
static ut64 baddr(RzBinFile *bf)
static RzList * maps(RzBinFile *bf)
RzList * sections(RzBinFile *bf)
RZ_API void rz_core_bin_options_init(RzCore *core, RZ_OUT RzBinOptions *opts, int fd, ut64 baseaddr, ut64 loadaddr)
RZ_API bool rz_core_bin_load_structs(RZ_NONNULL RzCore *core, RZ_NONNULL const char *file)
RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile)
RZ_API void rz_core_parse_rizinrc(RzCore *r)
RZ_API void rz_core_debug_map_update_flags(RzCore *core)
RZ_API RzCmdStatus rz_core_debug_plugins_print(RzCore *core, RzCmdStateOutput *state)
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.
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr)
RZ_API int rz_core_setup_debugger(RzCore *r, const char *debugbackend, bool attach)
RZ_API int rz_core_block_read(RzCore *core)
RZ_API RzCmdStatus rz_core_io_plugins_print(RzIO *io, RzCmdStateOutput *state)
Print the registered IO plugins according to state.
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
RZ_API int rz_core_cmd_file(RzCore *core, const char *file)
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
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.
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
RZ_API bool rz_core_project_load_for_cli(RzCore *core, const char *file, bool load_bin_io)
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
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.
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API void rz_cons_zero(void)
RZ_API void rz_cons_set_raw(bool is_raw)
RZ_API RzCons * rz_cons_new(void)
RZ_API bool rz_cons_isatty(void)
RZ_API void rz_cons_reset(void)
RZ_API RzCons * rz_cons_free(void)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static fork const void static count close
RZ_API int rz_line_hist_save(RZ_NONNULL const char *path)
Save the history of commands executed until now to file path.
size_t map(int syms, int left, int len)
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
RZ_API void rz_core_fortune_print_random(RzCore *core)
RZ_API void rz_core_prompt_loop(RzCore *r)
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
RZ_API void rz_core_free(RzCore *c)
RZ_API RzCore * rz_core_new(void)
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 ...
RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig)
RZ_API int rz_debug_detach(RzDebug *dbg, int pid)
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
static bool mustSaveHistory(RzConfig *c)
static bool has_file_arg(int argc, const char **argv, RzGetopt *opt)
RZ_API int rz_main_rizin(int argc, const char **argv)
static bool is_valid_gdb_file(RzCoreFile *fh)
static void set_color_default(RzCore *r)
static int main_help(int line)
static int rz_main_version_verify(int show)
static bool is_valid_dmp_file(RzCoreFile *fh)
static char * get_file_in_cur_dir(const char *filepath)
static bool run_commands(RzCore *r, RzList *cmds, RzList *files, bool quiet, int do_analysis)
static int main_print_var(const char *var_name)
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
RZ_API int rz_core_loadlibs(RzCore *core, int where)
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
static uint32_t const uint8_t uint32_t uint32_t limit
RZ_API bool rz_debug_use(RzDebug *dbg, const char *str)
RZ_API RZ_NONNULL const char * rz_project_err_message(RzProjectErr err)
RZ_API RzProjectErr rz_project_save_file(RzCore *core, const char *file, bool compress)
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
RZ_API char * rz_file_temp(const char *prefix)
RZ_API char * rz_stdin_slurp(int *sz)
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
RZ_API char * rz_file_path(const char *bin)
RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr)
RZ_API int rz_getopt_next(RzGetopt *opt)
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
RZ_API ut64 rz_io_desc_size(RzIODesc *desc)
RZ_API RZ_BORROW RzPVector * rz_io_maps(RzIO *io)
Returns the pointer to vector containing maps list.
RZ_API int rz_io_fd_get_current(RzIO *io)
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
RZ_API RzIOMap * rz_io_map_new(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
RZ_API int rz_lib_open(RzLib *lib, const char *file)
RZ_API int rz_main_version_print(const char *program)
RZ_API int rz_main_rz_find(int argc, const char **argv)
RZ_API int rz_main_rz_diff(int argc, const char **argv)
RZ_API int rz_main_rz_ax(int argc, const char **argv)
RZ_API int rz_main_rz_asm(int argc, const char **argv)
RZ_API int rz_main_rz_gg(int argc, const char **argv)
RZ_API int rz_main_rz_bin(int argc, const char **argv)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API RZ_OWN char * rz_path_home_history(void)
Return the path for the command history file.
enum rz_project_err RzProjectErr
RZ_API char * rz_run_get_environ_profile(char **env)
#define RZ_STR_ISNOTEMPTY(x)
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)
#define RZ_STR_ISEMPTY(x)
RZ_API char * rz_str_prepend(char *ptr, const char *string)
RZ_API char * rz_str_arg_escape(const char *arg)
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
RZ_API void rz_sys_env_init(void)
RZ_API bool rz_sys_getenv_asbool(const char *key)
Return true if the environment variable has the value 1, false otherwise.
RZ_API bool rz_sys_chdir(RZ_NONNULL const char *s)
Change current directory to s, taking care of home expansion ~.
RZ_API int rz_sys_crash_handler(const char *cmd)
RZ_API int rz_sys_sleep(int secs)
Sleep for secs seconds.
RZ_API char ** rz_sys_get_environ(void)
#define rz_xfreopen(pathname, mode, stream)
@ RZ_OUTPUT_MODE_STANDARD
#define rz_pvector_foreach(vec, it)
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
static struct sockaddr static addrlen static backlog const void msg
XX curplugin == o->plugin.
Represent the output state of a command handler.
struct rz_io_plugin_t * plugin
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id)
RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler)
RZ_API void rz_core_task_sync_end(RzCoreTaskScheduler *scheduler)
RZ_API int rz_core_task_running_tasks_count(RzCoreTaskScheduler *scheduler)
RZ_API void rz_core_task_sync_begin(RzCoreTaskScheduler *scheduler)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]