Rizin
unix-like reverse engineering framework and cli tools
cmd_open.c File Reference
#include <rz_bin.h>
#include <rz_debug.h>
#include <rz_core.h>
#include <rz_io.h>
#include "../core_private.h"

Go to the source code of this file.

Classes

struct  open_list_ascii_data_t
 

Functions

static bool core_bin_reload (RzCore *r, const char *file, ut64 baseaddr)
 
static bool reopen_in_malloc_cb (void *user, void *data, ut32 id)
 
RZ_API void rz_core_file_reopen_in_malloc (RzCore *core)
 
static bool init_desc_list_visual_cb (void *user, void *data, ut32 id)
 
static bool desc_list_visual_cb (void *user, void *data, ut32 id)
 
static bool desc_list_quiet_cb (void *user, void *data, ut32 id)
 
static bool desc_list_cb (void *user, void *data, ut32 id)
 
static bool desc_list_json_cb (void *user, void *data, ut32 id)
 
static bool desc_list_table_cb (void *user, void *data, ut32 id)
 
RZ_IPI RzCmdStatus rz_open_close_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_close_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_list_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_arch_bits_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_use_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus prioritize_file (RzCore *core, int fd)
 
RZ_IPI RzCmdStatus rz_open_prioritize_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_prioritize_next_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_prioritize_prev_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_prioritize_next_rotate_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_remove_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_remove_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_list_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_all_fd_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_relocate_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_relocate_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_resize_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_prioritize_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_prioritize_binid_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_deprioritize_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_prioritize_fd_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_name_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_name_del_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_name_id_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_name_id_del_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_map_fd_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_flags_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_flags_global_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_maps_map_handler (RzCore *core, int argc, const char **argv)
 
static void open_maps_show (RzCore *core, RzCmdStateOutput *state, RzIOMap *map, bool seek_inside)
 
static void open_maps_list (RzCore *core, RzCmdStateOutput *state, int fd)
 
RZ_IPI RzCmdStatus rz_open_maps_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_open_maps_list_cur_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_open_binary_select_id_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_select_fd_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_del_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_del_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_open_binary_show_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_list_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_add_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_rebase_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_binary_reload_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_write_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_open_show_current_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_open_exchange_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus open_core_file (RzCore *core, const char *filename)
 
RZ_IPI RzCmdStatus rz_open_core_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_malloc_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus open_nobin_file (RzCore *core, const char *uri, ut64 addr, int perms)
 
RZ_IPI RzCmdStatus rz_open_nobin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_open_nobin_write_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_write_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_binary_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_core_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_debug_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_debug_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_debug_rzrun_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_malloc_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_nobin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_nobin_write_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus reopen_nobin_headers (RzCore *core, int add_perms)
 
RZ_IPI RzCmdStatus rz_reopen_nobin_headers_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_reopen_nobin_write_headers_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ core_bin_reload()

static bool core_bin_reload ( RzCore r,
const char *  file,
ut64  baseaddr 
)
static

Definition at line 15 of file cmd_open.c.

15  {
17  if (!cf) {
18  return false;
19  }
20  RzBinFile *obf = rz_bin_file_find_by_fd(r->bin, cf->fd);
21  if (!obf) {
22  return false;
23  }
24  RzBinFile *nbf = rz_bin_reload(r->bin, obf, baseaddr);
25  if (!nbf) {
26  return false;
27  }
29  return true;
30 }
RZ_API RzBinFile * rz_bin_file_find_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:226
RZ_API RzBinFile * rz_bin_reload(RzBin *bin, RzBinFile *bf, ut64 baseaddr)
Definition: bin.c:216
RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:311
RZ_API RzCoreFile * rz_core_file_cur(RzCore *r)
Definition: cfile.c:1591
#define r
Definition: crypto_rc6.c:12
XX curplugin == o->plugin.
Definition: rz_bin.h:298
static int baseaddr
Definition: z80asm.c:79

References baseaddr, rz_core_file_t::fd, r, rz_bin_file_find_by_fd(), rz_bin_reload(), rz_core_bin_apply_all_info(), and rz_core_file_cur().

Referenced by rz_open_binary_reload_handler().

◆ desc_list_cb()

static bool desc_list_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 112 of file cmd_open.c.

112  {
113  RzPrint *p = (RzPrint *)user;
114  RzIODesc *desc = (RzIODesc *)data;
115  p->cb_printf("%2d %c %s 0x%08" PFMT64x " %s\n", desc->fd,
116  (desc->io && (desc->io->desc == desc)) ? '*' : '-',
117  rz_str_rwx_i(desc->perm), rz_io_desc_size(desc), desc->uri);
118  return true;
119 }
const char * desc
Definition: bin_vsf.c:19
void * p
Definition: libc.cpp:67
RZ_API ut64 rz_io_desc_size(RzIODesc *desc)
Definition: io_desc.c:224
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
#define PFMT64x
Definition: rz_types.h:393

References desc, p, PFMT64x, rz_io_desc_size(), and rz_str_rwx_i().

Referenced by rz_open_list_handler(), and rz_open_show_current_handler().

◆ desc_list_json_cb()

static bool desc_list_json_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 121 of file cmd_open.c.

121  {
122  PJ *pj = (PJ *)user;
123  RzIODesc *desc = (RzIODesc *)data;
124  // TODO: from is always 0? See librz/core/file.c:945
125  ut64 from = 0LL;
126  pj_o(pj);
127  pj_kb(pj, "raised", desc->io && (desc->io->desc == desc));
128  pj_kN(pj, "fd", desc->fd);
129  pj_ks(pj, "uri", desc->uri);
130  pj_kn(pj, "from", from);
131  pj_kb(pj, "writable", desc->perm & RZ_PERM_W);
132  pj_kN(pj, "size", rz_io_desc_size(desc));
133  pj_end(pj);
134  return true;
135 }
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_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
#define RZ_PERM_W
Definition: rz_types.h:94
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
Definition: rz_pj.h:12
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References desc, from, pj_end(), pj_kb(), pj_kN(), pj_kn(), pj_ks(), pj_o(), rz_io_desc_size(), RZ_PERM_W, and ut64().

Referenced by rz_open_list_handler(), and rz_open_show_current_handler().

◆ desc_list_quiet_cb()

static bool desc_list_quiet_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 105 of file cmd_open.c.

105  {
106  RzPrint *p = (RzPrint *)user;
107  RzIODesc *desc = (RzIODesc *)data;
108  p->cb_printf("%d\n", desc->fd);
109  return true;
110 }

References desc, and p.

Referenced by rz_open_list_handler(), and rz_open_show_current_handler().

◆ desc_list_table_cb()

static bool desc_list_table_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 137 of file cmd_open.c.

137  {
138  RzTable *t = (RzTable *)user;
139  RzIODesc *desc = (RzIODesc *)data;
140  rz_table_add_rowf(t, "dbsXs", desc->fd, desc->io && (desc->io->desc == desc),
141  rz_str_rwx_i(desc->perm), rz_io_desc_size(desc), desc->uri);
142  return true;
143 }
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316

References desc, rz_io_desc_size(), rz_str_rwx_i(), and rz_table_add_rowf().

Referenced by rz_open_list_handler(), and rz_open_show_current_handler().

◆ desc_list_visual_cb()

static bool desc_list_visual_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 90 of file cmd_open.c.

90  {
91  struct open_list_ascii_data_t *u = (struct open_list_ascii_data_t *)user;
92  RzPrint *p = u->p;
93  RzIODesc *desc = (RzIODesc *)data;
95  rz_cons_printf("%2d %c %s 0x%08" PFMT64x " ", desc->fd,
96  (desc->io && (desc->io->desc == desc)) ? '*' : '-', rz_str_rwx_i(desc->perm), sz);
97  int flags = p->flags;
98  p->flags &= ~RZ_PRINT_FLAGS_HEADER;
99  rz_print_progressbar(p, sz * 100 / u->fdsz, rz_cons_get_size(NULL) - 40);
100  p->flags = flags;
101  rz_cons_printf(" %s\n", desc->uri);
102  return true;
103 }
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_print_progressbar(RzPrint *p, int pc, int _cols)
Definition: print.c:1259
#define RZ_PRINT_FLAGS_HEADER
Definition: rz_print.h:18
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References desc, open_list_ascii_data_t::fdsz, flags, NULL, open_list_ascii_data_t::p, p, PFMT64x, rz_cons_get_size(), rz_cons_printf(), rz_io_desc_size(), RZ_PRINT_FLAGS_HEADER, rz_print_progressbar(), rz_str_rwx_i(), and ut64().

Referenced by rz_open_list_ascii_handler().

◆ init_desc_list_visual_cb()

static bool init_desc_list_visual_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 80 of file cmd_open.c.

80  {
81  struct open_list_ascii_data_t *u = (struct open_list_ascii_data_t *)user;
82  RzIODesc *desc = (RzIODesc *)data;
84  if (sz > u->fdsz) {
85  u->fdsz = sz;
86  }
87  return true;
88 }

References desc, open_list_ascii_data_t::fdsz, rz_io_desc_size(), and ut64().

Referenced by rz_open_list_ascii_handler().

◆ open_core_file()

static RzCmdStatus open_core_file ( RzCore core,
const char *  filename 
)
static

Definition at line 885 of file cmd_open.c.

885  {
886  if (core->tasks.current_task != core->tasks.main_task) {
887  RZ_LOG_ERROR("This command can only be executed on the main task!\n");
888  return RZ_CMD_STATUS_ERROR;
889  }
891  rz_core_fini(core);
892  rz_core_init(core);
894  if (!rz_core_file_open(core, filename, RZ_PERM_R, 0)) {
895  RZ_LOG_ERROR("Cannot open file '%s'\n", filename);
896  return RZ_CMD_STATUS_ERROR;
897  }
898  ut64 baddr = rz_config_get_i(core->config, "bin.baddr");
899  return bool2status(rz_core_bin_load(core, NULL, baddr));
900 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
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 ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
const char * filename
Definition: ioapi.h:137
RZ_API void rz_core_fini(RzCore *c)
Definition: core.c:2623
RZ_API bool rz_core_init(RzCore *core)
Definition: core.c:2381
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_PERM_R
Definition: rz_types.h:93
RzCoreTaskScheduler tasks
Definition: rz_core.h:362
RzConfig * config
Definition: rz_core.h:300
struct rz_core_task_t * current_task
Definition: rz_core.h:276
struct rz_core_task_t * main_task
Definition: rz_core.h:277
RZ_API void rz_core_task_sync_end(RzCoreTaskScheduler *scheduler)
Definition: task.c:432
RZ_API void rz_core_task_sync_begin(RzCoreTaskScheduler *scheduler)
Definition: task.c:421

References baddr(), bool2status(), rz_core_t::config, rz_core_tasks_t::current_task, rz_core_tasks_t::main_task, NULL, RZ_CMD_STATUS_ERROR, rz_config_get_i(), rz_core_bin_load(), rz_core_file_open(), rz_core_fini(), rz_core_init(), rz_core_task_sync_begin(), rz_core_task_sync_end(), RZ_LOG_ERROR, RZ_PERM_R, rz_core_t::tasks, and ut64().

Referenced by rz_open_core_file_handler(), and rz_reopen_core_handler().

◆ open_maps_list()

static void open_maps_list ( RzCore core,
RzCmdStateOutput state,
int  fd 
)
static

Definition at line 608 of file cmd_open.c.

608  {
609  RzPVector *maps = rz_io_maps(core->io);
610  void **it;
611 
613  rz_cmd_state_output_set_columnsf(state, "ddxxxxxss", "id", "fd", "pa", "pa_end", "size", "va", "va_end", "perm", "name");
614  if (state->mode == RZ_OUTPUT_MODE_TABLE) {
615  state->d.t->showFancy = true;
616  }
617  RzIOMap *at_seek = NULL;
618  if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
619  at_seek = rz_io_map_get(core->io, core->offset);
620  }
621  rz_pvector_foreach (maps, it) {
622  RzIOMap *map = *it;
623  if (fd >= 0 && map->fd != fd) {
624  continue;
625  }
626  open_maps_show(core, state, map, map == at_seek);
627  }
629 }
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
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_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
static void open_maps_show(RzCore *core, RzCmdStateOutput *state, RzIOMap *map, bool seek_inside)
Definition: cmd_open.c:575
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RZ_API RZ_BORROW RzPVector * rz_io_maps(RzIO *io)
Returns the pointer to vector containing maps list.
Definition: io_map.c:435
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
ut64 offset
Definition: rz_core.h:301
RzIO * io
Definition: rz_core.h:313
Definition: dis.h:43
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, rz_core_t::io, map(), maps(), NULL, rz_core_t::offset, open_maps_show(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cmd_state_output_set_columnsf(), rz_io_map_get(), rz_io_maps(), RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, and rz_pvector_foreach.

Referenced by rz_open_maps_list_handler().

◆ open_maps_show()

static void open_maps_show ( RzCore core,
RzCmdStateOutput state,
RzIOMap map,
bool  seek_inside 
)
static

Definition at line 575 of file cmd_open.c.

575  {
576  switch (state->mode) {
578  rz_cons_printf("%d %d\n", map->fd, map->id);
579  break;
582  break;
583  case RZ_OUTPUT_MODE_JSON:
584  pj_o(state->d.pj);
585  pj_ki(state->d.pj, "map", map->id);
586  pj_ki(state->d.pj, "fd", map->fd);
587  pj_kn(state->d.pj, "delta", map->delta);
588  pj_kn(state->d.pj, "from", rz_io_map_get_from(map));
589  pj_kn(state->d.pj, "to", rz_itv_end(map->itv));
590  pj_ks(state->d.pj, "perm", rz_str_rwx_i(map->perm));
591  pj_ks(state->d.pj, "name", rz_str_get(map->name));
592  pj_end(state->d.pj);
593  break;
595  rz_table_add_rowf(state->d.t, "ddxxxxxss",
596  map->id, map->fd, map->delta, map->delta + rz_itv_size(map->itv), rz_itv_size(map->itv),
598  break;
599  default:
600  rz_cons_printf("%2d fd: %i +0x%08" PFMT64x " 0x%08" PFMT64x " %c 0x%08" PFMT64x " %s %s\n",
601  map->id, map->fd,
602  map->delta, rz_io_map_get_from(map), seek_inside ? '*' : '-', rz_io_map_get_to(map),
603  rz_str_rwx_i(map->perm), rz_str_get(map->name));
604  break;
605  }
606 }
#define rz_io_map_get_from(map)
Definition: rz_io.h:19
#define rz_io_map_get_to(map)
Definition: rz_io.h:20
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
@ 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

References map(), PFMT64x, pj_end(), pj_ki(), pj_kn(), pj_ks(), pj_o(), rz_cons_printf(), rz_io_map_get_from, rz_io_map_get_to, rz_itv_end(), rz_itv_size(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_QUIETEST, RZ_OUTPUT_MODE_TABLE, rz_str_get(), rz_str_rwx_i(), and rz_table_add_rowf().

Referenced by open_maps_list(), and rz_open_maps_list_cur_handler().

◆ open_nobin_file()

static RzCmdStatus open_nobin_file ( RzCore core,
const char *  uri,
ut64  addr,
int  perms 
)
static

Definition at line 946 of file cmd_open.c.

946  {
947  if (!strcmp(uri, "=")) {
948  uri = "malloc://512";
949  }
950 
951  RzIODesc *desc = rz_io_open_at(core->io, uri, perms, 0644, addr, NULL);
952  if (!desc || desc->fd == -1) {
953  RZ_LOG_ERROR("Cannot open '%s' at %" PFMT64x ".\n", uri, addr);
954  return RZ_CMD_STATUS_ERROR;
955  }
956 
957  core->num->value = desc->fd;
958  rz_core_block_read(core);
959  return RZ_CMD_STATUS_OK;
960 }
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
RZ_API RzIODesc * rz_io_open_at(RzIO *io, const char *uri, int flags, int mode, ut64 at, RZ_NULLABLE RZ_OUT RzIOMap **map)
Open a file and directly map it at the given offset.
Definition: io.c:177
RzNum * num
Definition: rz_core.h:316
ut64 value
Definition: rz_num.h:63
static int addr
Definition: z80asm.c:58

References addr, desc, rz_core_t::io, NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_open_at(), RZ_LOG_ERROR, and rz_num_t::value.

Referenced by rz_open_nobin_handler(), and rz_open_nobin_write_handler().

◆ prioritize_file()

static RzCmdStatus prioritize_file ( RzCore core,
int  fd 
)
static

Definition at line 212 of file cmd_open.c.

212  {
213  if (fd <= 0) {
214  RZ_LOG_ERROR("Wrong file descriptor %d\n", fd);
215  return RZ_CMD_STATUS_ERROR;
216  }
217  int curfd = rz_io_fd_get_current(core->io);
218  if (fd == curfd) {
219  return RZ_CMD_STATUS_OK;
220  }
221 
222  if (!rz_io_use_fd(core->io, fd)) {
223  RZ_LOG_ERROR("Could not use IO fd %d\n", fd);
224  return RZ_CMD_STATUS_ERROR;
225  }
226  rz_core_block_read(core);
227  RzBinFile *bf = rz_bin_file_find_by_fd(core->bin, fd);
228  if (bf && !rz_core_bin_raise(core, bf->id)) {
229  RZ_LOG_ERROR("Could not use bin id %d\n", bf->id);
230  return RZ_CMD_STATUS_ERROR;
231  }
232  return RZ_CMD_STATUS_OK;
233 }
RZ_API bool rz_core_bin_raise(RzCore *core, ut32 bfid)
Definition: cbin.c:4524
RZ_API int rz_io_fd_get_current(RzIO *io)
Definition: io_fd.c:135
RZ_API bool rz_io_use_fd(RzIO *io, int fd)
Definition: io_fd.c:118
RzBin * bin
Definition: rz_core.h:298

References rz_core_t::bin, fd, rz_bin_file_t::id, rz_core_t::io, rz_bin_file_find_by_fd(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_raise(), rz_core_block_read(), rz_io_fd_get_current(), rz_io_use_fd(), and RZ_LOG_ERROR.

Referenced by rz_open_prioritize_handler(), rz_open_prioritize_next_handler(), rz_open_prioritize_next_rotate_handler(), and rz_open_prioritize_prev_handler().

◆ reopen_in_malloc_cb()

static bool reopen_in_malloc_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 32 of file cmd_open.c.

32  {
33  RzIO *io = (RzIO *)user;
34  RzIODesc *desc = (RzIODesc *)data;
35 
37  return true;
38  }
39 
40  if (strstr(desc->uri, "://")) {
41  return true;
42  }
43 
45 
46  char *uri = rz_str_newf("malloc://%" PFMT64u, size);
47  if (!uri) {
48  return false;
49  }
50 
51  ut8 *buf = malloc(size);
52  // if malloc fails, we can just abort the loop by returning false
53  if (!buf) {
54  free(uri);
55  return false;
56  }
57 
58  RzIODesc *ndesc = rz_io_open_nomap(io, uri, RZ_PERM_RW, 0);
59  free(uri);
60  if (!ndesc) {
61  free(buf);
62  return false;
63  }
64 
65  rz_io_desc_read_at(desc, 0LL, buf, (int)size); // that cast o_O
66  rz_io_desc_write_at(ndesc, 0LL, buf, (int)size);
67  free(buf);
68  rz_io_desc_exchange(io, desc->fd, ndesc->fd);
69 
71  return true;
72 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API bool rz_io_desc_is_blockdevice(RzIODesc *desc)
Definition: io_desc.c:261
RZ_API bool rz_io_desc_exchange(RzIO *io, int fd, int fdx)
Definition: io_desc.c:275
RZ_API int rz_io_desc_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len)
Definition: io_desc.c:351
RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len)
Definition: io_desc.c:358
RZ_API RzIODesc * rz_io_open_nomap(RzIO *io, const char *uri, int flags, int mode)
Definition: io.c:145
RZ_API bool rz_io_desc_is_dbg(RzIODesc *desc)
Definition: io_desc.c:303
RZ_API bool rz_io_desc_close(RzIODesc *desc)
Definition: io_desc.c:165
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_PERM_RW
Definition: rz_types.h:96
#define PFMT64u
Definition: rz_types.h:395
int fd
Definition: rz_io.h:96
Definition: rz_io.h:59

References desc, rz_io_desc_t::fd, free(), malloc(), PFMT64u, rz_io_desc_close(), rz_io_desc_exchange(), rz_io_desc_is_blockdevice(), rz_io_desc_is_dbg(), rz_io_desc_read_at(), rz_io_desc_size(), rz_io_desc_write_at(), rz_io_open_nomap(), RZ_PERM_RW, rz_str_newf(), and ut64().

Referenced by rz_core_file_reopen_in_malloc().

◆ reopen_nobin_headers()

static RzCmdStatus reopen_nobin_headers ( RzCore core,
int  add_perms 
)
static

Definition at line 1081 of file cmd_open.c.

1081  {
1082  RzIODesc *desc = rz_io_desc_get(core->io, core->file->fd);
1083  if (!desc) {
1084  RZ_LOG_ERROR("Could not find current file.\n");
1085  return RZ_CMD_STATUS_ERROR;
1086  }
1087  int perms = core->io->desc->perm | add_perms;
1088  char *fname = strdup(desc->name);
1089  if (!fname) {
1090  return RZ_CMD_STATUS_ERROR;
1091  }
1092  if (!rz_core_bin_load_structs(core, fname)) {
1093  RZ_LOG_WARN("Could not load file format information for '%s'.\n", fname);
1094  }
1095  bool res = rz_core_file_reopen(core, fname, perms, 0);
1096  free(fname);
1097  return bool2status(res);
1098 }
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_file_reopen(RzCore *core, const char *args, int perm, int loadbin)
Definition: cfile.c:322
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")
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RzCoreFile * file
Definition: rz_core.h:314
int perm
Definition: rz_io.h:97
struct rz_io_desc_t * desc
Definition: rz_io.h:60

References bool2status(), desc, rz_io_t::desc, rz_core_file_t::fd, rz_core_t::file, create_tags_rz::fname, free(), rz_core_t::io, rz_io_desc_t::perm, RZ_CMD_STATUS_ERROR, rz_core_bin_load_structs(), rz_core_file_reopen(), rz_io_desc_get(), RZ_LOG_ERROR, RZ_LOG_WARN, and strdup().

Referenced by rz_reopen_nobin_headers_handler(), and rz_reopen_nobin_write_headers_handler().

◆ rz_core_file_reopen_in_malloc()

RZ_API void rz_core_file_reopen_in_malloc ( RzCore core)

Definition at line 74 of file cmd_open.c.

74  {
75  if (core && core->io && core->io->files) {
77  }
78 }
static bool reopen_in_malloc_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:32
RZ_API bool rz_id_storage_foreach(RzIDStorage *storage, RzIDStorageForeachCb cb, void *user)
Definition: idpool.c:254
RzIDStorage * files
Definition: rz_io.h:75

References rz_io_t::files, rz_core_t::io, reopen_in_malloc_cb(), and rz_id_storage_foreach().

Referenced by rz_reopen_malloc_handler().

◆ rz_open_arch_bits_handler()

RZ_IPI RzCmdStatus rz_open_arch_bits_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 179 of file cmd_open.c.

179  {
180  const char *filename = argc > 3 ? argv[3] : NULL;
181  ut16 bits = rz_num_math(core->num, argv[2]);
182  const char *arch = argv[1];
183 
184  int res = rz_core_bin_set_arch_bits(core, filename, arch, bits);
185  return res ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
186 }
int bits(struct state *s, int need)
Definition: blast.c:72
RZ_API int rz_core_bin_set_arch_bits(RzCore *r, const char *name, const char *arch, ut16 bits)
Definition: cbin.c:4467
cs_arch arch
Definition: cstool.c:13
uint16_t ut16
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456

References arch, argv, bits(), NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_set_arch_bits(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_add_handler()

RZ_IPI RzCmdStatus rz_open_binary_add_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 737 of file cmd_open.c.

737  {
738  ut64 loadaddr = rz_num_math(core->num, argv[1]);
739  int fd = rz_io_fd_get_current(core->io);
740  RzIODesc *desc = rz_io_desc_get(core->io, fd);
741  if (!desc) {
742  RZ_LOG_ERROR("Could not determine any opened file with fd %d\n", fd);
743  return RZ_CMD_STATUS_ERROR;
744  }
745  RzBinOptions opt;
746  opt.sz = 1024 * 1024 * 1;
747  rz_core_bin_options_init(core, &opt, desc->fd, core->offset, loadaddr);
748  RzBinFile *bf = rz_bin_open_io(core->bin, &opt);
749  rz_core_bin_apply_all_info(core, bf);
750  return RZ_CMD_STATUS_OK;
751 }
RZ_API RzBinFile * rz_bin_open_io(RzBin *bin, RzBinOptions *opt)
Definition: bin.c:283
RZ_API void rz_core_bin_options_init(RzCore *core, RZ_OUT RzBinOptions *opts, int fd, ut64 baseaddr, ut64 loadaddr)
Definition: cbin.c:87

References argv, rz_core_t::bin, desc, fd, rz_core_t::io, rz_core_t::num, rz_core_t::offset, rz_bin_open_io(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_apply_all_info(), rz_core_bin_options_init(), rz_io_desc_get(), rz_io_fd_get_current(), RZ_LOG_ERROR, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_del_all_handler()

RZ_IPI RzCmdStatus rz_open_binary_del_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 688 of file cmd_open.c.

688  {
690  return RZ_CMD_STATUS_OK;
691 }
RZ_API ut64 rz_bin_file_delete_all(RzBin *bin)
Definition: bfile.c:199

References rz_core_t::bin, rz_bin_file_delete_all(), and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_del_handler()

RZ_IPI RzCmdStatus rz_open_binary_del_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 674 of file cmd_open.c.

674  {
675  ut32 id = (ut32)rz_num_math(NULL, argv[1]);
676  RzBinFile *bf = rz_bin_file_find_by_id(core->bin, id);
677  if (!bf) {
678  RZ_LOG_ERROR("Could not find any binary file with id %d.\n", id);
679  return RZ_CMD_STATUS_ERROR;
680  }
681  if (!rz_core_binfiles_delete(core, bf)) {
682  RZ_LOG_ERROR("Could not delete binary file with id %d\n", id);
683  return RZ_CMD_STATUS_ERROR;
684  }
685  return RZ_CMD_STATUS_OK;
686 }
RZ_API RzBinFile * rz_bin_file_find_by_id(RzBin *bin, ut32 bf_id)
Definition: bfile.c:188
RZ_API bool rz_core_binfiles_delete(RzCore *core, RzBinFile *bf)
Close an opened binary file.
Definition: cbin.c:4542
uint32_t ut32

References argv, rz_core_t::bin, NULL, rz_bin_file_find_by_id(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_binfiles_delete(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_file_handler()

RZ_IPI RzCmdStatus rz_open_binary_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 753 of file cmd_open.c.

753  {
754  int saved_fd = rz_io_fd_get_current(core->io);
756  RzListIter *iter;
757 
758  RzIODesc *desc = NULL;
759  if (argc > 1) {
760  desc = rz_io_open(core->io, argv[1], RZ_PERM_R, 0);
761  if (!desc) {
762  RZ_LOG_ERROR("Could not open file %s\n", argv[1]);
764  return RZ_CMD_STATUS_ERROR;
765  }
766  rz_list_append(files, (void *)(size_t)desc->fd);
767  } else {
768  RzList *ofiles = rz_id_storage_list(core->io->files);
769  RzIODesc *desc;
770  rz_list_foreach (ofiles, iter, desc) {
771  rz_list_append(files, (void *)(size_t)desc->fd);
772  }
773  }
774 
775  void *_fd;
776  rz_list_foreach (files, iter, _fd) {
777  RzBinOptions opt;
778  int fd = (size_t)_fd;
779  rz_core_bin_options_init(core, &opt, fd, core->offset, 0);
780  RzBinFile *bf = rz_bin_open_io(core->bin, &opt);
781  rz_core_bin_apply_all_info(core, bf);
782  }
784 
786  rz_io_use_fd(core->io, saved_fd);
787  return RZ_CMD_STATUS_OK;
788 }
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 RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_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 RzList * rz_id_storage_list(RzIDStorage *s)
Definition: idpool.c:283
RZ_API RzIODesc * rz_io_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io.c:156
int size_t
Definition: sftypes.h:40

References argv, rz_core_t::bin, desc, fd, rz_io_t::files, files, rz_core_t::io, NULL, rz_core_t::offset, rz_bin_open_io(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_apply_all_info(), rz_core_bin_options_init(), rz_id_storage_list(), rz_io_desc_close(), rz_io_fd_get_current(), rz_io_open(), rz_io_use_fd(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, and RZ_PERM_R.

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_list_ascii_handler()

RZ_IPI RzCmdStatus rz_open_binary_list_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 706 of file cmd_open.c.

706  {
707  RzBin *bin = core->bin;
708  if (!bin) {
709  return RZ_CMD_STATUS_ERROR;
710  }
712  if (!list) {
713  return RZ_CMD_STATUS_ERROR;
714  }
715  RzListIter *iter;
716  RzBinFile *bf = NULL;
717  rz_list_foreach (bin->binfiles, iter, bf) {
718  char temp[64];
719  RzInterval inter = (RzInterval){ bf->o->opts.baseaddr, bf->o->size };
720  RzListInfo *info = rz_listinfo_new(bf->file, inter, inter, -1, sdb_itoa(bf->fd, temp, 10));
721  if (!info) {
722  break;
723  }
725  }
726  RzTable *table = rz_core_table(core);
727  rz_table_visual_list(table, list, core->offset, core->blocksize,
728  rz_cons_get_size(NULL), rz_config_get_i(core->config, "scr.color"));
729  char *table_text = rz_table_tostring(table);
730  rz_cons_printf("\n%s\n", table_text);
731  rz_free(table_text);
732  rz_table_free(table);
734  return RZ_CMD_STATUS_OK;
735 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RZ_API RzTable * rz_core_table(RzCore *core)
Definition: core.c:3449
static void list(RzEgg *egg)
Definition: rz-gg.c:52
#define rz_free(x)
Definition: rz_alloc.h:44
struct rz_interval_t RzInterval
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API void rz_table_visual_list(RzTable *table, RzList *list, ut64 seek, ut64 len, int width, bool va)
Definition: table.c:1205
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510
RZ_API char * sdb_itoa(ut64 n, char *s, int base)
Definition: util.c:38
Definition: malloc.c:26
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
RzBinObject * o
Definition: rz_bin.h:305
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300
char * file
Definition: rz_bin.h:299
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260
ut32 blocksize
Definition: rz_core.h:303
RZ_API RzListInfo * rz_listinfo_new(const char *name, RzInterval pitv, RzInterval vitv, int perm, const char *extra)
Definition: visual.c:4020
RZ_API void rz_listinfo_free(RzListInfo *info)
Definition: visual.c:4032

References rz_bin_file_load_options_t::baseaddr, rz_core_t::bin, rz_core_t::blocksize, rz_core_t::config, rz_bin_file_t::fd, rz_bin_file_t::file, info(), list(), NULL, rz_bin_file_t::o, rz_core_t::offset, rz_bin_object_t::opts, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_cons_get_size(), rz_cons_printf(), rz_core_table(), rz_free, rz_list_append(), rz_list_free(), rz_list_newf(), rz_listinfo_free(), rz_listinfo_new(), rz_table_free(), rz_table_tostring(), rz_table_visual_list(), sdb_itoa(), and rz_bin_object_t::size.

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_list_handler()

RZ_IPI RzCmdStatus rz_open_binary_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 693 of file cmd_open.c.

693  {
695  return RZ_CMD_STATUS_OK;
696 }
RZ_API bool rz_core_binfiles_print(RzCore *core, RzCmdStateOutput *state)
Print all the opened binary files according to state.
Definition: cbin.c:4603

References RZ_CMD_STATUS_OK, and rz_core_binfiles_print().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_rebase_handler()

RZ_IPI RzCmdStatus rz_open_binary_rebase_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 790 of file cmd_open.c.

790  {
791  rz_core_bin_rebase(core, rz_num_math(core->num, argv[1]));
793  return RZ_CMD_STATUS_OK;
794 }
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API int rz_core_bin_rebase(RzCore *core, ut64 baddr)
Definition: cfile.c:822

References argv, rz_core_t::bin, rz_core_t::num, rz_bin_cur(), RZ_CMD_STATUS_OK, rz_core_bin_apply_all_info(), rz_core_bin_rebase(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_reload_handler()

RZ_IPI RzCmdStatus rz_open_binary_reload_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 796 of file cmd_open.c.

796  {
797  // XXX: this will reload the bin using the buffer.
798  // An assumption is made that assumes there is an underlying
799  // plugin that will be used to load the bin (e.g. malloc://)
800  // TODO: Might be nice to reload a bin at a specified offset?
801  core_bin_reload(core, NULL, rz_num_math(core->num, argv[1]));
802  rz_core_block_read(core);
803  return RZ_CMD_STATUS_OK;
804 }
static bool core_bin_reload(RzCore *r, const char *file, ut64 baseaddr)
Definition: cmd_open.c:15

References argv, core_bin_reload(), NULL, rz_core_t::num, RZ_CMD_STATUS_OK, rz_core_block_read(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_select_fd_handler()

RZ_IPI RzCmdStatus rz_open_binary_select_fd_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 660 of file cmd_open.c.

660  {
661  ut32 fd = rz_num_math(NULL, argv[1]);
662  RzBinFile *bf = rz_bin_file_find_by_fd(core->bin, fd);
663  if (!bf) {
664  RZ_LOG_ERROR("Could not find any binary file for fd %d.\n", fd);
665  return RZ_CMD_STATUS_ERROR;
666  }
667  if (!rz_core_bin_raise(core, bf->id)) {
668  eprintf("Could not select the binary file for fd %d.\n", fd);
669  return RZ_CMD_STATUS_ERROR;
670  }
671  return RZ_CMD_STATUS_OK;
672 }
#define eprintf(x, y...)
Definition: rlcc.c:7

References argv, rz_core_t::bin, eprintf, fd, rz_bin_file_t::id, NULL, rz_bin_file_find_by_fd(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_raise(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_select_id_handler()

RZ_IPI RzCmdStatus rz_open_binary_select_id_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 651 of file cmd_open.c.

651  {
652  ut32 id = (ut32)rz_num_math(NULL, argv[1]);
653  if (!rz_core_bin_raise(core, id)) {
654  RZ_LOG_ERROR("Could not select binary file with id %d\n", id);
655  return RZ_CMD_STATUS_ERROR;
656  }
657  return RZ_CMD_STATUS_OK;
658 }

References argv, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_raise(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_binary_show_handler()

RZ_IPI RzCmdStatus rz_open_binary_show_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 698 of file cmd_open.c.

698  {
699  RzBinFile *bf = rz_bin_file_at(core->bin, core->offset);
700  if (bf) {
701  rz_cons_printf("%d\n", bf->id);
702  }
703  return RZ_CMD_STATUS_OK;
704 }
RZ_API RzBinFile * rz_bin_file_at(RzBin *bin, ut64 at)
Definition: bin.c:1160

References rz_core_t::bin, rz_bin_file_t::id, rz_core_t::offset, rz_bin_file_at(), RZ_CMD_STATUS_OK, and rz_cons_printf().

Referenced by rzshell_cmddescs_init().

◆ rz_open_close_all_handler()

RZ_IPI RzCmdStatus rz_open_close_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 158 of file cmd_open.c.

158  {
159  rz_core_file_close_fd(core, -1);
160  rz_io_close_all(core->io);
162 
163  // TODO: Move to a-- ?
165  // TODO: Move to f-- ?
166  rz_flag_unset_all(core->flags);
167  RZ_LOG_INFO("Close all files\n");
168  return RZ_CMD_STATUS_OK;
169 }
RZ_API void rz_analysis_purge(RzAnalysis *analysis)
Definition: analysis.c:433
RZ_API bool rz_core_file_close_fd(RzCore *core, int fd)
Definition: cfile.c:1510
RZ_API void rz_flag_unset_all(RzFlag *f)
Definition: flag.c:677
RZ_API int rz_io_close_all(RzIO *io)
Definition: io.c:258
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
RzAnalysis * analysis
Definition: rz_core.h:322
RzFlag * flags
Definition: rz_core.h:330

References rz_core_t::analysis, rz_core_t::bin, rz_core_t::flags, rz_core_t::io, rz_analysis_purge(), rz_bin_file_delete_all(), RZ_CMD_STATUS_OK, rz_core_file_close_fd(), rz_flag_unset_all(), rz_io_close_all(), and RZ_LOG_INFO.

Referenced by rzshell_cmddescs_init().

◆ rz_open_close_handler()

RZ_IPI RzCmdStatus rz_open_close_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 145 of file cmd_open.c.

145  {
146  if (!rz_num_is_valid_input(NULL, argv[1])) {
147  RZ_LOG_ERROR("Invalid fd: %s\n", argv[1]);
148  return RZ_CMD_STATUS_ERROR;
149  }
150  int fd = (int)rz_num_math(NULL, argv[1]);
151  if (!rz_core_file_close_fd(core, fd)) {
152  RZ_LOG_ERROR("Unable to find file descriptor %d\n", fd);
153  return RZ_CMD_STATUS_ERROR;
154  }
155  return RZ_CMD_STATUS_OK;
156 }
RZ_API int rz_num_is_valid_input(RzNum *num, const char *input_value)
Definition: unum.c:676
static int
Definition: sfsocketcall.h:114

References argv, fd, int, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_file_close_fd(), RZ_LOG_ERROR, rz_num_is_valid_input(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_core_file_handler()

RZ_IPI RzCmdStatus rz_open_core_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 902 of file cmd_open.c.

902  {
903  return open_core_file(core, argv[1]);
904 }
static RzCmdStatus open_core_file(RzCore *core, const char *filename)
Definition: cmd_open.c:885

References argv, and open_core_file().

Referenced by rzshell_cmddescs_init().

◆ rz_open_exchange_handler()

RZ_IPI RzCmdStatus rz_open_exchange_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 873 of file cmd_open.c.

873  {
874  int fd = (int)rz_num_math(NULL, argv[1]);
875  int fdx = (int)rz_num_math(NULL, argv[2]);
876  if ((fdx == -1) || (fd == -1) || (fdx == fd)) {
877  RZ_LOG_ERROR("Could not exchange file descriptor %d and %d.\n", fd, fdx);
878  return RZ_CMD_STATUS_ERROR;
879  }
880  rz_io_desc_exchange(core->io, fd, fdx);
881  rz_core_block_read(core);
882  return RZ_CMD_STATUS_OK;
883 }

References argv, fd, int, rz_core_t::io, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_desc_exchange(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_handler()

RZ_IPI RzCmdStatus rz_open_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 806 of file cmd_open.c.

806  {
807  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
808  int perms = argc > 3 ? rz_str_rwx(argv[3]) : RZ_PERM_R;
809  return bool2status(rz_core_file_open_load(core, argv[1], addr, perms, false));
810 }
RZ_API bool rz_core_file_open_load(RZ_NONNULL RzCore *core, RZ_NONNULL const char *filepath, ut64 addr, int perms, bool write_mode)
Tries to open the file, load binary info and make RzIOMap.
Definition: cfile.c:189
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318

References addr, argv, bool2status(), rz_core_t::num, rz_core_file_open_load(), rz_num_math(), RZ_PERM_R, rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_list_ascii_handler()

RZ_IPI RzCmdStatus rz_open_list_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 170 of file cmd_open.c.

170  {
171  struct open_list_ascii_data_t data = { 0 };
172  data.p = core->print;
173  data.fdsz = 0;
176  return RZ_CMD_STATUS_OK;
177 }
static bool desc_list_visual_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:90
static bool init_desc_list_visual_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:80
RzPrint * print
Definition: rz_core.h:327

References desc_list_visual_cb(), open_list_ascii_data_t::fdsz, rz_io_t::files, init_desc_list_visual_cb(), rz_core_t::io, open_list_ascii_data_t::p, rz_core_t::print, RZ_CMD_STATUS_OK, and rz_id_storage_foreach().

Referenced by rzshell_cmddescs_init().

◆ rz_open_list_handler()

RZ_IPI RzCmdStatus rz_open_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 818 of file cmd_open.c.

818  {
820  rz_cmd_state_output_set_columnsf(state, "dbsXs", "fd", "raised", "perm", "size", "uri");
821  switch (state->mode) {
824  break;
825  case RZ_OUTPUT_MODE_JSON:
827  break;
830  break;
833  break;
834  default:
835  break;
836  }
838  return RZ_CMD_STATUS_OK;
839 }
static bool desc_list_table_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:137
static bool desc_list_json_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:121
static bool desc_list_quiet_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:105
static bool desc_list_cb(void *user, void *data, ut32 id)
Definition: cmd_open.c:112

References desc_list_cb(), desc_list_json_cb(), desc_list_quiet_cb(), desc_list_table_cb(), rz_io_t::files, rz_core_t::io, rz_core_t::print, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_OK, rz_id_storage_foreach(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, and RZ_OUTPUT_MODE_TABLE.

Referenced by rzshell_cmddescs_init().

◆ rz_open_malloc_handler()

RZ_IPI RzCmdStatus rz_open_malloc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 906 of file cmd_open.c.

906  {
907  int len = (int)rz_num_math(core->num, argv[1]);
908  if (len < 0) {
909  RZ_LOG_ERROR("Invalid length %d.\n", len);
910  return RZ_CMD_STATUS_ERROR;
911  }
912 
914  ut8 *data = RZ_NEWS(ut8, len);
915  if (!data) {
916  return RZ_CMD_STATUS_ERROR;
917  }
918  if (!rz_io_read_at(core->io, core->offset, data, len)) {
919  RZ_LOG_ERROR("Cannot read %d bytes from current offset.\n", len);
920  goto err;
921  }
922 
923  char uri[100];
924  rz_strf(uri, "malloc://%d", len);
925  RzCoreFile *cfile = rz_core_file_open(core, uri, RZ_PERM_RWX, 0);
926  if (!cfile) {
927  RZ_LOG_ERROR("Cannot open '%s'.\n", uri);
928  goto err;
929  }
930 
931  if (!rz_core_bin_load(core, uri, 0)) {
932  RZ_LOG_ERROR("Cannot load binary info of '%s'.\n", uri);
933  goto err;
934  }
935 
936  RzIODesc *desc = rz_io_desc_get(core->io, cfile->fd);
938  rz_io_desc_write_at(desc, 0, data, len);
939  res = RZ_CMD_STATUS_OK;
940 
941 err:
942  free(data);
943  return res;
944 }
size_t len
Definition: 6502dis.c:15
static bool err
Definition: armass.c:435
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35
enum rz_cmd_status_t RzCmdStatus
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define RZ_PERM_RWX
Definition: rz_types.h:98

References argv, benchmark::cfile, desc, err, free(), int, rz_core_t::io, len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_load(), rz_core_file_open(), rz_io_desc_get(), rz_io_desc_write_at(), rz_io_read_at(), RZ_LOG_ERROR, RZ_NEWS, rz_num_math(), RZ_PERM_RWX, rz_strf, and rz_warn_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_all_fd_handler()

RZ_IPI RzCmdStatus rz_open_maps_all_fd_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 304 of file cmd_open.c.

304  {
305  ut32 fd = argc > 1 ? rz_num_math(NULL, argv[1]) : rz_io_fd_get_current(core->io);
306  RzIODesc *desc = rz_io_desc_get(core->io, fd);
307  if (!desc) {
308  RZ_LOG_ERROR("Could not find any file descriptor with fd %d\n", fd);
309  return RZ_CMD_STATUS_ERROR;
310  }
311  RzIOMap *map = rz_io_map_add(core->io, fd, desc->perm, 0, 0, UT64_MAX);
312  if (!map) {
313  RZ_LOG_ERROR("Could not create a IO map for file descriptor %d\n", fd);
314  return RZ_CMD_STATUS_ERROR;
315  }
316  rz_io_map_set_name(map, desc->name);
317  return RZ_CMD_STATUS_OK;
318 }
RZ_API void rz_io_map_set_name(RzIOMap *map, const char *name)
Definition: io_map.c:332
RZ_API RzIOMap * rz_io_map_add(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:151
#define UT64_MAX
Definition: rz_types_base.h:86

References argv, desc, fd, rz_core_t::io, map(), NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_desc_get(), rz_io_fd_get_current(), rz_io_map_add(), rz_io_map_set_name(), RZ_LOG_ERROR, rz_num_math(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_deprioritize_handler()

RZ_IPI RzCmdStatus rz_open_maps_deprioritize_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 409 of file cmd_open.c.

409  {
410  ut32 id = (ut32)rz_num_math(core->num, argv[1]);
411  if (!rz_io_map_exists_for_id(core->io, id)) {
412  RZ_LOG_ERROR("Cannot find any map with mapid %d\n", id);
413  return RZ_CMD_STATUS_ERROR;
414  }
415  rz_io_map_depriorize(core->io, id);
416  rz_core_block_read(core);
417  return RZ_CMD_STATUS_OK;
418 }
RZ_API bool rz_io_map_exists_for_id(RzIO *io, ut32 id)
Definition: io_map.c:124
RZ_API bool rz_io_map_depriorize(RzIO *io, ut32 id)
Definition: io_map.c:248

References argv, rz_core_t::io, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_map_depriorize(), rz_io_map_exists_for_id(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_flags_global_handler()

RZ_IPI RzCmdStatus rz_open_maps_flags_global_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 510 of file cmd_open.c.

510  {
511  const char *arg = argv[1];
512  enum mode {
513  ADD,
514  DEL,
515  SET,
516  } mode = SET;
517  if (arg[0] == '+') {
518  mode = ADD;
519  arg++;
520  } else if (arg[0] == '-') {
521  mode = DEL;
522  arg++;
523  }
524  int perm = rz_str_rwx(arg);
525  RzPVector *maps = rz_io_maps(core->io);
526  void **it;
527  rz_pvector_foreach (maps, it) {
528  RzIOMap *map = *it;
529  switch (mode) {
530  case ADD:
531  map->perm |= perm;
532  break;
533  case DEL:
534  map->perm &= ~perm;
535  break;
536  case SET:
537  map->perm = perm;
538  break;
539  }
540  }
541  return RZ_CMD_STATUS_OK;
542 }
const char int mode
Definition: ioapi.h:137
#define ADD
Definition: rsp_idec.c:200
@ DEL
Definition: rz_cons.h:1228

References ADD, argv, DEL, rz_core_t::io, map(), maps(), RZ_CMD_STATUS_OK, rz_io_maps(), rz_pvector_foreach, and rz_str_rwx().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_flags_handler()

RZ_IPI RzCmdStatus rz_open_maps_flags_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 488 of file cmd_open.c.

488  {
489  int perm = rz_str_rwx(argv[1]);
490  RzIOMap *map = NULL;
491  if (argc > 2) {
492  ut32 id = rz_num_math(NULL, argv[2]);
493  map = rz_io_map_resolve(core->io, id);
494  if (!map) {
495  RZ_LOG_ERROR("Cannot find any map with id %d\n", id);
496  return RZ_CMD_STATUS_ERROR;
497  }
498  } else {
499  map = rz_io_map_get(core->io, core->offset);
500  if (!map) {
501  RZ_LOG_ERROR("Cannot find any map at the current address %" PFMT64x "\n", core->offset);
502  return RZ_CMD_STATUS_ERROR;
503  }
504  }
505 
506  map->perm = perm;
507  return RZ_CMD_STATUS_OK;
508 }
RZ_API RzIOMap * rz_io_map_resolve(RzIO *io, ut32 id)
Definition: io_map.c:128

References argv, rz_core_t::io, map(), NULL, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_get(), rz_io_map_resolve(), RZ_LOG_ERROR, rz_num_math(), and rz_str_rwx().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_list_ascii_handler()

RZ_IPI RzCmdStatus rz_open_maps_list_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 276 of file cmd_open.c.

276  {
278  if (!list) {
279  return RZ_CMD_STATUS_ERROR;
280  }
281  void **it;
282  RzPVector *maps = rz_io_maps(core->io);
284  RzIOMap *map = *it;
285  char temp[32];
286  rz_strf(temp, "%d", map->fd);
287  RzListInfo *info = rz_listinfo_new(map->name, map->itv, map->itv, map->perm, temp);
288  if (!info) {
289  break;
290  }
292  }
293  RzTable *table = rz_core_table(core);
294  rz_table_visual_list(table, list, core->offset, core->blocksize,
295  rz_cons_get_size(NULL), rz_config_get_i(core->config, "scr.color"));
296  char *tablestr = rz_table_tostring(table);
297  rz_cons_printf("%s", tablestr);
298  rz_table_free(table);
300  free(tablestr);
301  return RZ_CMD_STATUS_OK;
302 }
#define rz_pvector_foreach_prev(vec, it)
Definition: rz_vector.h:338

References rz_core_t::blocksize, rz_core_t::config, free(), info(), rz_core_t::io, list(), map(), maps(), NULL, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_cons_get_size(), rz_cons_printf(), rz_core_table(), rz_io_maps(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_listinfo_free(), rz_listinfo_new(), rz_pvector_foreach_prev, rz_strf, rz_table_free(), rz_table_tostring(), and rz_table_visual_list().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_list_cur_handler()

RZ_IPI RzCmdStatus rz_open_maps_list_cur_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 637 of file cmd_open.c.

637  {
638  RzIOMap *map = rz_io_map_get(core->io, core->offset);
639  if (!map) {
640  RZ_LOG_ERROR("Cannot find any map at the current address %" PFMT64x "\n", core->offset);
641  return RZ_CMD_STATUS_ERROR;
642  }
643  rz_cmd_state_output_set_columnsf(state, "ddxxxxxss", "id", "fd", "pa", "pa_end", "va", "va_end", "perm", "name");
644  if (state->mode == RZ_OUTPUT_MODE_TABLE) {
645  state->d.t->showFancy = true;
646  }
647  open_maps_show(core, state, map, false);
648  return RZ_CMD_STATUS_OK;
649 }

References rz_core_t::io, map(), rz_core_t::offset, open_maps_show(), PFMT64x, rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_get(), RZ_LOG_ERROR, and RZ_OUTPUT_MODE_TABLE.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_list_handler()

RZ_IPI RzCmdStatus rz_open_maps_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 631 of file cmd_open.c.

631  {
632  int fd = argc > 1 ? rz_num_math(NULL, argv[1]) : -1;
633  open_maps_list(core, state, fd);
634  return RZ_CMD_STATUS_OK;
635 }
static void open_maps_list(RzCore *core, RzCmdStateOutput *state, int fd)
Definition: cmd_open.c:608

References argv, fd, NULL, open_maps_list(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_map_fd_handler()

RZ_IPI RzCmdStatus rz_open_maps_map_fd_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 471 of file cmd_open.c.

471  {
472  ut32 fd = argc > 1 ? rz_num_math(NULL, argv[1]) : rz_io_fd_get_current(core->io);
473  RzIODesc *desc = rz_io_desc_get(core->io, fd);
474  if (!desc) {
475  RZ_LOG_ERROR("Cannot find any descriptor with fd %d\n", fd);
476  return RZ_CMD_STATUS_ERROR;
477  }
479  RzIOMap *map = rz_io_map_add(core->io, fd, desc->perm, 0, 0, size);
480  if (!map) {
481  RZ_LOG_ERROR("Cannot create new map for fd %d\n", fd);
482  return RZ_CMD_STATUS_ERROR;
483  }
484  rz_io_map_set_name(map, desc->name);
485  return RZ_CMD_STATUS_OK;
486 }

References argv, desc, fd, rz_core_t::io, map(), NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_desc_get(), rz_io_desc_size(), rz_io_fd_get_current(), rz_io_map_add(), rz_io_map_set_name(), RZ_LOG_ERROR, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_map_handler()

RZ_IPI RzCmdStatus rz_open_maps_map_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 544 of file cmd_open.c.

544  {
545  int fd = (int)rz_num_math(NULL, argv[1]);
546  if (fd < 3) {
547  RZ_LOG_ERROR("Wrong fd, it must be greather than 3\n");
548  return RZ_CMD_STATUS_ERROR;
549  }
550 
551  ut64 vaddr = rz_num_math(core->num, argv[2]);
552  ut64 size = argc > 3 ? rz_num_math(core->num, argv[3]) : rz_io_fd_size(core->io, fd);
553  ut64 paddr = argc > 4 ? rz_num_math(core->num, argv[4]) : 0;
554  int rwx = argc > 5 ? rz_str_rwx(argv[5]) : 0;
555  const char *name = argc > 6 ? argv[6] : "";
556 
557  if (argc <= 5) {
558  RzIODesc *desc = rz_io_desc_get(core->io, fd);
559  if (!desc) {
560  RZ_LOG_ERROR("Could not determine any opened file with fd %d\n", fd);
561  return RZ_CMD_STATUS_ERROR;
562  }
563 
564  rwx = desc->perm;
565  }
566  RzIOMap *map = rz_io_map_add(core->io, fd, rwx, paddr, vaddr, size);
567  if (!map) {
568  RZ_LOG_ERROR("Could not create new map for fd %d at vaddr %" PFMT64x "\n", fd, vaddr);
569  return RZ_CMD_STATUS_ERROR;
570  }
572  return RZ_CMD_STATUS_OK;
573 }
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
Definition: z80asm.h:102

References argv, desc, fd, int, rz_core_t::io, map(), NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_desc_get(), rz_io_fd_size(), rz_io_map_add(), rz_io_map_set_name(), RZ_LOG_ERROR, rz_num_math(), rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_name_del_handler()

RZ_IPI RzCmdStatus rz_open_maps_name_del_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 439 of file cmd_open.c.

439  {
440  RzIOMap *map = rz_io_map_get(core->io, core->offset);
441  if (!map) {
442  RZ_LOG_ERROR("Cannot find any map at address %" PFMT64x "\n", core->offset);
443  return RZ_CMD_STATUS_ERROR;
444  }
446  return RZ_CMD_STATUS_OK;
447 }
RZ_API void rz_io_map_del_name(RzIOMap *map)
Definition: io_map.c:340

References rz_core_t::io, map(), rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_del_name(), rz_io_map_get(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_name_handler()

RZ_IPI RzCmdStatus rz_open_maps_name_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 429 of file cmd_open.c.

429  {
430  RzIOMap *map = rz_io_map_get(core->io, core->offset);
431  if (!map) {
432  RZ_LOG_ERROR("Cannot find any map at address %" PFMT64x "d\n", core->offset);
433  return RZ_CMD_STATUS_ERROR;
434  }
436  return RZ_CMD_STATUS_OK;
437 }

References argv, rz_core_t::io, map(), rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_get(), rz_io_map_set_name(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_name_id_del_handler()

RZ_IPI RzCmdStatus rz_open_maps_name_id_del_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 460 of file cmd_open.c.

460  {
461  ut32 id = rz_num_math(core->num, argv[1]);
462  RzIOMap *map = rz_io_map_resolve(core->io, id);
463  if (!map) {
464  RZ_LOG_ERROR("Cannot find any map with id %d\n", id);
465  return RZ_CMD_STATUS_ERROR;
466  }
468  return RZ_CMD_STATUS_OK;
469 }

References argv, rz_core_t::io, map(), rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_del_name(), rz_io_map_resolve(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_name_id_handler()

RZ_IPI RzCmdStatus rz_open_maps_name_id_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 449 of file cmd_open.c.

449  {
450  ut32 id = rz_num_math(core->num, argv[1]);
451  RzIOMap *map = rz_io_map_resolve(core->io, id);
452  if (!map) {
453  RZ_LOG_ERROR("Cannot find any map with id %d\n", id);
454  return RZ_CMD_STATUS_ERROR;
455  }
457  return RZ_CMD_STATUS_OK;
458 }

References argv, rz_core_t::io, map(), rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_resolve(), rz_io_map_set_name(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_prioritize_binid_handler()

RZ_IPI RzCmdStatus rz_open_maps_prioritize_binid_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 385 of file cmd_open.c.

385  {
386  ut32 id = (ut32)rz_num_math(core->num, argv[1]);
387  if (!rz_bin_file_set_cur_by_id(core->bin, id)) {
388  RZ_LOG_ERROR("Cannot prioritize bin with fd %d\n", id);
389  return RZ_CMD_STATUS_ERROR;
390  }
391  RzListIter *it;
392  RzCoreFile *file = NULL;
393  rz_list_foreach (core->files, it, file) {
394  void **binfile;
395  rz_pvector_foreach (&file->binfiles, binfile) {
396  RzBinFile *bf = *binfile;
397  if (bf->id == id) {
398  void **map;
399  rz_pvector_foreach (&file->maps, map) {
400  RzIOMap *m = *map;
401  rz_io_map_priorize(core->io, m->id);
402  }
403  }
404  }
405  }
406  return RZ_CMD_STATUS_OK;
407 }
RZ_API bool rz_bin_file_set_cur_by_id(RzBin *bin, ut32 bin_id)
Definition: bfile.c:253
RZ_API bool rz_io_map_priorize(RzIO *io, ut32 id)
Definition: io_map.c:232
Definition: gzappend.c:170
RzList * files
Definition: rz_core.h:315

References argv, rz_core_t::bin, rz_core_t::files, rz_bin_file_t::id, rz_core_t::io, regress::m, map(), NULL, rz_core_t::num, rz_bin_file_set_cur_by_id(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_priorize(), RZ_LOG_ERROR, rz_num_math(), and rz_pvector_foreach.

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_prioritize_fd_handler()

RZ_IPI RzCmdStatus rz_open_maps_prioritize_fd_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 420 of file cmd_open.c.

420  {
421  int fd = (int)rz_num_math(core->num, argv[1]);
422  if (!rz_io_map_priorize_for_fd(core->io, fd)) {
423  RZ_LOG_ERROR("Cannot prioritize any map for fd %d\n", fd);
424  return RZ_CMD_STATUS_ERROR;
425  }
426  return RZ_CMD_STATUS_OK;
427 }
RZ_API bool rz_io_map_priorize_for_fd(RzIO *io, int fd)
Definition: io_map.c:264

References argv, fd, int, rz_core_t::io, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_priorize_for_fd(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_prioritize_handler()

RZ_IPI RzCmdStatus rz_open_maps_prioritize_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 374 of file cmd_open.c.

374  {
375  ut32 id = (ut32)rz_num_math(core->num, argv[1]);
376  if (!rz_io_map_exists_for_id(core->io, id)) {
377  RZ_LOG_ERROR("Cannot find any map with mapid %d\n", id);
378  return RZ_CMD_STATUS_ERROR;
379  }
380  rz_io_map_priorize(core->io, id);
381  rz_core_block_read(core);
382  return RZ_CMD_STATUS_OK;
383 }

References argv, rz_core_t::io, rz_core_t::num, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_map_exists_for_id(), rz_io_map_priorize(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_relocate_current_handler()

RZ_IPI RzCmdStatus rz_open_maps_relocate_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 338 of file cmd_open.c.

338  {
339  if (!rz_num_is_valid_input(core->num, argv[1])) {
340  RZ_LOG_ERROR("Invalid address '%s'\n", argv[1]);
341  return RZ_CMD_STATUS_ERROR;
342  }
343  RzIOMap *map = rz_io_map_get(core->io, core->offset);
344  if (!map) {
345  RZ_LOG_ERROR("Could not find any IO map at current offset\n");
346  return RZ_CMD_STATUS_ERROR;
347  }
348  ut64 addr = rz_num_math(core->num, argv[1]);
349  if (!rz_io_map_remap(core->io, map->id, addr)) {
350  RZ_LOG_ERROR("Could not relocate map with id %d to %" PFMT64x "\n", map->id, addr);
351  return RZ_CMD_STATUS_ERROR;
352  }
353  return RZ_CMD_STATUS_OK;
354 }
RZ_API bool rz_io_map_remap(RzIO *io, ut32 id, ut64 addr)
Definition: io_map.c:54

References addr, argv, rz_core_t::io, map(), rz_core_t::num, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_get(), rz_io_map_remap(), RZ_LOG_ERROR, rz_num_is_valid_input(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_relocate_handler()

RZ_IPI RzCmdStatus rz_open_maps_relocate_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 320 of file cmd_open.c.

320  {
321  if (!rz_num_is_valid_input(NULL, argv[1])) {
322  RZ_LOG_ERROR("Invalid map id '%s'\n", argv[1]);
323  return RZ_CMD_STATUS_ERROR;
324  }
325  if (!rz_num_is_valid_input(core->num, argv[2])) {
326  RZ_LOG_ERROR("Invalid address '%s'\n", argv[2]);
327  return RZ_CMD_STATUS_ERROR;
328  }
329  ut32 map_id = (ut32)rz_num_math(NULL, argv[1]);
330  ut64 addr = rz_num_math(core->num, argv[2]);
331  if (!rz_io_map_remap(core->io, map_id, addr)) {
332  RZ_LOG_ERROR("Could not relocate map with id %d to %" PFMT64x "\n", map_id, addr);
333  return RZ_CMD_STATUS_ERROR;
334  }
335  return RZ_CMD_STATUS_OK;
336 }

References addr, argv, rz_core_t::io, NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_remap(), RZ_LOG_ERROR, rz_num_is_valid_input(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_remove_all_handler()

RZ_IPI RzCmdStatus rz_open_maps_remove_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 271 of file cmd_open.c.

271  {
272  rz_io_map_reset(core->io);
273  return RZ_CMD_STATUS_OK;
274 }
RZ_API void rz_io_map_reset(RzIO *io)
Definition: io_map.c:186

References rz_core_t::io, RZ_CMD_STATUS_OK, and rz_io_map_reset().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_remove_handler()

RZ_IPI RzCmdStatus rz_open_maps_remove_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 258 of file cmd_open.c.

258  {
259  if (!rz_num_is_valid_input(NULL, argv[1])) {
260  RZ_LOG_ERROR("Invalid map id '%s'\n", argv[1]);
261  return RZ_CMD_STATUS_ERROR;
262  }
263  ut32 map_id = rz_num_math(NULL, argv[1]);
264  if (!rz_io_map_del(core->io, map_id)) {
265  RZ_LOG_ERROR("Could not delete IO map %d\n", map_id);
266  return RZ_CMD_STATUS_ERROR;
267  }
268  return RZ_CMD_STATUS_OK;
269 }
RZ_API bool rz_io_map_del(RzIO *io, ut32 id)
Definition: io_map.c:192

References argv, rz_core_t::io, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_del(), RZ_LOG_ERROR, rz_num_is_valid_input(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_maps_resize_handler()

RZ_IPI RzCmdStatus rz_open_maps_resize_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 356 of file cmd_open.c.

356  {
357  if (!rz_num_is_valid_input(NULL, argv[1])) {
358  RZ_LOG_ERROR("Invalid map id '%s'\n", argv[1]);
359  return RZ_CMD_STATUS_ERROR;
360  }
361  if (!rz_num_is_valid_input(core->num, argv[2])) {
362  RZ_LOG_ERROR("Invalid size '%s'\n", argv[2]);
363  return RZ_CMD_STATUS_ERROR;
364  }
365  ut32 map_id = (ut32)rz_num_math(NULL, argv[1]);
366  ut64 size = rz_num_math(core->num, argv[2]);
367  if (!rz_io_map_resize(core->io, map_id, size)) {
368  RZ_LOG_ERROR("Could not resize map with id %d to %" PFMT64x "\n", map_id, size);
369  return RZ_CMD_STATUS_ERROR;
370  }
371  return RZ_CMD_STATUS_OK;
372 }
RZ_API bool rz_io_map_resize(RzIO *io, ut32 id, ut64 newsize)
Definition: io_map.c:403

References argv, rz_core_t::io, NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_map_resize(), RZ_LOG_ERROR, rz_num_is_valid_input(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_nobin_handler()

RZ_IPI RzCmdStatus rz_open_nobin_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 962 of file cmd_open.c.

962  {
963  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
964  int perms = argc > 3 ? rz_str_rwx(argv[3]) : RZ_PERM_R;
965  return open_nobin_file(core, argv[1], addr, perms);
966 }
static RzCmdStatus open_nobin_file(RzCore *core, const char *uri, ut64 addr, int perms)
Definition: cmd_open.c:946

References addr, argv, rz_core_t::num, open_nobin_file(), rz_num_math(), RZ_PERM_R, rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_nobin_write_handler()

RZ_IPI RzCmdStatus rz_open_nobin_write_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 968 of file cmd_open.c.

968  {
969  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
970  int perms = argc > 3 ? rz_str_rwx(argv[3]) : RZ_PERM_RW;
971  return open_nobin_file(core, argv[1], addr, perms);
972 }

References addr, argv, rz_core_t::num, open_nobin_file(), rz_num_math(), RZ_PERM_RW, rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_open_prioritize_handler()

RZ_IPI RzCmdStatus rz_open_prioritize_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 235 of file cmd_open.c.

235  {
236  int fd = atoi(argv[1]);
237  return prioritize_file(core, fd);
238 }
static RzCmdStatus prioritize_file(RzCore *core, int fd)
Definition: cmd_open.c:212

References argv, fd, and prioritize_file().

Referenced by rzshell_cmddescs_init().

◆ rz_open_prioritize_next_handler()

RZ_IPI RzCmdStatus rz_open_prioritize_next_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 240 of file cmd_open.c.

240  {
241  int fd = rz_io_fd_get_next(core->io, rz_io_fd_get_current(core->io));
242  return prioritize_file(core, fd);
243 }
RZ_API int rz_io_fd_get_next(RzIO *io, int fd)
Definition: io_fd.c:143

References fd, rz_core_t::io, prioritize_file(), rz_io_fd_get_current(), and rz_io_fd_get_next().

Referenced by rzshell_cmddescs_init().

◆ rz_open_prioritize_next_rotate_handler()

RZ_IPI RzCmdStatus rz_open_prioritize_next_rotate_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 250 of file cmd_open.c.

250  {
251  int fd = rz_io_fd_get_next(core->io, rz_io_fd_get_current(core->io));
252  if (fd == -1) {
253  fd = rz_io_fd_get_lowest(core->io);
254  }
256 }
RZ_API int rz_io_fd_get_lowest(RzIO *io)
Definition: io_fd.c:170

References fd, rz_core_t::io, prioritize_file(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_fd_get_current(), rz_io_fd_get_lowest(), and rz_io_fd_get_next().

Referenced by rzshell_cmddescs_init().

◆ rz_open_prioritize_prev_handler()

RZ_IPI RzCmdStatus rz_open_prioritize_prev_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 245 of file cmd_open.c.

245  {
246  int fd = rz_io_fd_get_prev(core->io, rz_io_fd_get_current(core->io));
247  return prioritize_file(core, fd);
248 }
RZ_API int rz_io_fd_get_prev(RzIO *io, int fd)
Definition: io_fd.c:152

References fd, rz_core_t::io, prioritize_file(), rz_io_fd_get_current(), and rz_io_fd_get_prev().

Referenced by rzshell_cmddescs_init().

◆ rz_open_show_current_handler()

RZ_IPI RzCmdStatus rz_open_show_current_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 841 of file cmd_open.c.

841  {
842  RzIOMap *map = rz_io_map_get(core->io, core->offset);
843  if (!map) {
844  RZ_LOG_ERROR("Could not find any map at current address %" PFMT64x ".\n", core->offset);
845  return RZ_CMD_STATUS_ERROR;
846  }
847  RzIODesc *desc = rz_io_desc_get(core->io, map->fd);
848  if (!desc) {
849  RZ_LOG_ERROR("Could not find file for map fd %d.\n", map->fd);
850  return RZ_CMD_STATUS_ERROR;
851  }
852 
853  rz_cmd_state_output_set_columnsf(state, "dbsXs", "fd", "raised", "perm", "size", "uri");
854  switch (state->mode) {
856  desc_list_cb(core->print, desc, 0);
857  break;
858  case RZ_OUTPUT_MODE_JSON:
859  desc_list_json_cb(state->d.pj, desc, 0);
860  break;
862  desc_list_table_cb(state->d.t, desc, 0);
863  break;
865  desc_list_quiet_cb(core->print, desc, 0);
866  break;
867  default:
868  break;
869  }
870  return RZ_CMD_STATUS_OK;
871 }

References desc, desc_list_cb(), desc_list_json_cb(), desc_list_quiet_cb(), desc_list_table_cb(), rz_core_t::io, map(), rz_core_t::offset, PFMT64x, rz_core_t::print, rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_desc_get(), rz_io_map_get(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, and RZ_OUTPUT_MODE_TABLE.

Referenced by rzshell_cmddescs_init().

◆ rz_open_use_handler()

RZ_IPI RzCmdStatus rz_open_use_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 188 of file cmd_open.c.

188  {
189  RzListIter *iter = NULL;
190  RzCoreFile *f;
191 
192  int fdnum = rz_num_math(NULL, argv[1]);
193  rz_list_foreach (core->files, iter, f) {
194  if (f->fd == fdnum) {
195  core->file = f;
196  rz_io_use_fd(core->io, fdnum);
197  RzBinFile *bf = rz_bin_file_find_by_fd(core->bin, fdnum);
198  if (!bf) {
199  RZ_LOG_ERROR("Could not find binfile with fd %d\n", fdnum);
200  return RZ_CMD_STATUS_ERROR;
201  }
202  rz_core_bin_raise(core, bf->id);
203  rz_core_block_read(core);
204  RZ_LOG_INFO("Switched to fd %d (%s)\n", fdnum, bf->file);
205  return RZ_CMD_STATUS_OK;
206  }
207  }
208  RZ_LOG_ERROR("Could not find any opened file with fd %d\n", fdnum);
209  return RZ_CMD_STATUS_ERROR;
210 }
#define f(i)
Definition: sha256.c:46

References argv, rz_core_t::bin, f, rz_bin_file_t::file, rz_core_t::file, rz_core_t::files, rz_bin_file_t::id, rz_core_t::io, NULL, rz_bin_file_find_by_fd(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_bin_raise(), rz_core_block_read(), rz_io_use_fd(), RZ_LOG_ERROR, RZ_LOG_INFO, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_open_write_handler()

RZ_IPI RzCmdStatus rz_open_write_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 812 of file cmd_open.c.

812  {
813  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
814  int perms = argc > 3 ? rz_str_rwx(argv[3]) : RZ_PERM_RW;
815  return bool2status(rz_core_file_open_load(core, argv[1], addr, perms, true));
816 }

References addr, argv, bool2status(), rz_core_t::num, rz_core_file_open_load(), rz_num_math(), RZ_PERM_RW, rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_binary_handler()

RZ_IPI RzCmdStatus rz_reopen_binary_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1014 of file cmd_open.c.

1014  {
1015  return bool2status(rz_core_file_reopen(core, argv[1], 0, 2));
1016 }

References argv, bool2status(), and rz_core_file_reopen().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_core_handler()

RZ_IPI RzCmdStatus rz_reopen_core_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1018 of file cmd_open.c.

1018  {
1019  if (!core->io || !core->io->desc) {
1020  RZ_LOG_ERROR("Could not find current file\n");
1021  return RZ_CMD_STATUS_ERROR;
1022  }
1023 
1024  return open_core_file(core, core->io->desc->uri);
1025 }
char * uri
Definition: rz_io.h:98

References rz_io_t::desc, rz_core_t::io, open_core_file(), RZ_CMD_STATUS_ERROR, RZ_LOG_ERROR, and rz_io_desc_t::uri.

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_debug_file_handler()

RZ_IPI RzCmdStatus rz_reopen_debug_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1048 of file cmd_open.c.

1048  {
1049  const char *uri = argv[1];
1050  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
1052  return RZ_CMD_STATUS_OK;
1053 }
RZ_API void rz_core_file_reopen_remote_debug(RzCore *core, const char *uri, ut64 addr)
Definition: cfile.c:222

References addr, argv, rz_core_t::num, RZ_CMD_STATUS_OK, rz_core_file_reopen_remote_debug(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_debug_handler()

RZ_IPI RzCmdStatus rz_reopen_debug_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1027 of file cmd_open.c.

1027  {
1028  // TODO: this is bad as we force ourselves to convert arguments to strings.
1029  // There should be an API to reopen a file in debug mode and directly
1030  // pass args to it.
1031  char **args = RZ_NEWS(char *, argc - 1);
1032  int i;
1033  for (i = 1; i < argc; i++) {
1035  args[i - 1] = rz_str_newf("\"%s\"", t);
1036  free(t);
1037  }
1038  char *args_str = rz_str_array_join((const char **)args, argc - 1, " ");
1039  for (i = 0; i < argc - 1; i++) {
1040  free(args[i]);
1041  }
1042  free(args);
1043  rz_core_file_reopen_debug(core, args_str);
1044  free(args_str);
1045  return RZ_CMD_STATUS_OK;
1046 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_core_file_reopen_debug(RzCore *core, const char *args)
Definition: cfile.c:269
RZ_API char * rz_cmd_escape_arg(const char *arg, RzCmdEscape esc)
Definition: cmd_api.c:2516
int args
Definition: mipsasm.c:18
@ RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in "....".
Definition: rz_cmd.h:82
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861

References args, argv, free(), i, rz_cmd_escape_arg(), RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG, RZ_CMD_STATUS_OK, rz_core_file_reopen_debug(), RZ_NEWS, rz_str_array_join(), and rz_str_newf().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_debug_rzrun_handler()

RZ_IPI RzCmdStatus rz_reopen_debug_rzrun_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1055 of file cmd_open.c.

1055  {
1056  char *file = rz_file_temp("rz-run");
1057  char *s = strdup(argv[1]);
1058  rz_config_set(core->config, "dbg.profile", file);
1059  rz_str_replace_char(s, ',', '\n');
1060  rz_file_dump(file, (const ut8 *)s, strlen(s), 0);
1061  rz_file_dump(file, (const ut8 *)"\n", 1, 1);
1062  free(s);
1063  free(file);
1064  rz_core_file_reopen_debug(core, "");
1065  return RZ_CMD_STATUS_OK;
1066 }
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
static RzSocket * s
Definition: rtr.c:28
RZ_API char * rz_file_temp(const char *prefix)
Definition: file.c:1048
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
Definition: file.c:838
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169

References argv, rz_core_t::config, free(), RZ_CMD_STATUS_OK, rz_config_set(), rz_core_file_reopen_debug(), rz_file_dump(), rz_file_temp(), rz_str_replace_char(), s, and strdup().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_handler()

RZ_IPI RzCmdStatus rz_reopen_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 974 of file cmd_open.c.

974  {
975  int fd;
976  if (argc > 1) {
977  fd = (int)rz_num_math(NULL, argv[1]);
978  if (fd < 0) {
979  RZ_LOG_ERROR("Invalid negative fd %d\n", fd);
980  return RZ_CMD_STATUS_ERROR;
981  }
982  } else {
983  if (!core->io || !core->io->desc) {
984  RZ_LOG_ERROR("Cannot find current file.\n");
985  return RZ_CMD_STATUS_ERROR;
986  }
987  fd = core->io->desc->fd;
988  }
989  rz_core_io_file_open(core, fd);
990  return RZ_CMD_STATUS_OK;
991 }
RZ_API void rz_core_io_file_open(RZ_NONNULL RzCore *core, int fd)
Open file use read-only Permission.
Definition: cfile.c:1601

References argv, rz_io_t::desc, fd, rz_io_desc_t::fd, int, rz_core_t::io, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_io_file_open(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_malloc_handler()

RZ_IPI RzCmdStatus rz_reopen_malloc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1068 of file cmd_open.c.

1068  {
1070  return RZ_CMD_STATUS_OK;
1071 }
RZ_API void rz_core_file_reopen_in_malloc(RzCore *core)
Definition: cmd_open.c:74

References RZ_CMD_STATUS_OK, and rz_core_file_reopen_in_malloc().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_nobin_handler()

RZ_IPI RzCmdStatus rz_reopen_nobin_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1073 of file cmd_open.c.

1073  {
1074  return bool2status(rz_core_file_reopen(core, NULL, 0, 0));
1075 }

References bool2status(), NULL, and rz_core_file_reopen().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_nobin_headers_handler()

RZ_IPI RzCmdStatus rz_reopen_nobin_headers_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1100 of file cmd_open.c.

1100  {
1101  return reopen_nobin_headers(core, 0);
1102 }
static RzCmdStatus reopen_nobin_headers(RzCore *core, int add_perms)
Definition: cmd_open.c:1081

References reopen_nobin_headers().

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_nobin_write_handler()

RZ_IPI RzCmdStatus rz_reopen_nobin_write_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1077 of file cmd_open.c.

1077  {
1078  return bool2status(rz_core_file_reopen(core, NULL, RZ_PERM_RW, 0));
1079 }

References bool2status(), NULL, rz_core_file_reopen(), and RZ_PERM_RW.

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_nobin_write_headers_handler()

RZ_IPI RzCmdStatus rz_reopen_nobin_write_headers_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1104 of file cmd_open.c.

1104  {
1105  return reopen_nobin_headers(core, RZ_PERM_RW);
1106 }

References reopen_nobin_headers(), and RZ_PERM_RW.

Referenced by rzshell_cmddescs_init().

◆ rz_reopen_write_handler()

RZ_IPI RzCmdStatus rz_reopen_write_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 993 of file cmd_open.c.

993  {
994  int fd;
995  int perms = RZ_PERM_RW;
996  if (argc > 1) {
997  fd = (int)rz_num_math(NULL, argv[1]);
998  if (fd < 0) {
999  RZ_LOG_ERROR("Invalid negative fd %d\n", fd);
1000  return RZ_CMD_STATUS_ERROR;
1001  }
1002  } else {
1003  if (!core->io || !core->io->desc) {
1004  RZ_LOG_ERROR("Cannot find current file.\n");
1005  return RZ_CMD_STATUS_ERROR;
1006  }
1007  fd = core->io->desc->fd;
1008  perms |= core->io->desc->perm;
1009  }
1010  rz_core_io_file_reopen(core, fd, perms);
1011  return RZ_CMD_STATUS_OK;
1012 }
RZ_API void rz_core_io_file_reopen(RZ_NONNULL RzCore *core, int fd, int perms)
Reopen file.
Definition: cfile.c:1650

References argv, rz_io_t::desc, fd, rz_io_desc_t::fd, int, rz_core_t::io, NULL, rz_io_desc_t::perm, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_io_file_reopen(), RZ_LOG_ERROR, rz_num_math(), and RZ_PERM_RW.

Referenced by rzshell_cmddescs_init().