Rizin
unix-like reverse engineering framework and cli tools
cmd_resize.c File Reference
#include <string.h>
#include <rz_core.h>

Go to the source code of this file.

Functions

static int rebase_helper (RzCore *core, ut64 oldbase, ut64 newbase)
 
RZ_IPI RzCmdStatus rz_rebase_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus resize_helper (RzCore *core, st64 delta)
 
RZ_IPI RzCmdStatus rz_resize_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_resize_remove_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_resize_insert_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_resize_human_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ rebase_helper()

static int rebase_helper ( RzCore core,
ut64  oldbase,
ut64  newbase 
)
static

Definition at line 7 of file cmd_resize.c.

7  {
8  rz_debug_bp_rebase(core->dbg, oldbase, newbase);
9  rz_bin_set_baddr(core->bin, newbase);
10  rz_flag_move(core->flags, oldbase, newbase);
12  // TODO: rz_analysis_move :??
13  // TODO: differentiate analysis by map ranges (associated with files or memory maps)
14  return 0;
15 }
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API void rz_bin_set_baddr(RzBin *bin, ut64 baddr)
Definition: bin.c:549
RZ_API bool rz_core_bin_apply_all_info(RzCore *r, RzBinFile *binfile)
Definition: cbin.c:311
RZ_API bool rz_flag_move(RzFlag *f, ut64 at, ut64 to)
Definition: flag.c:741
RZ_API void rz_debug_bp_rebase(RzDebug *dbg, ut64 old_base, ut64 new_base)
Definition: debug.c:1737
RzBin * bin
Definition: rz_core.h:298
RzDebug * dbg
Definition: rz_core.h:329
RzFlag * flags
Definition: rz_core.h:330

References rz_core_t::bin, rz_core_t::dbg, rz_core_t::flags, rz_bin_cur(), rz_bin_set_baddr(), rz_core_bin_apply_all_info(), rz_debug_bp_rebase(), and rz_flag_move().

Referenced by rz_rebase_handler().

◆ resize_helper()

static RzCmdStatus resize_helper ( RzCore core,
st64  delta 
)
static

Definition at line 24 of file cmd_resize.c.

24  {
25  if (!core->file) {
26  return RZ_CMD_STATUS_ERROR;
27  }
28  ut64 oldsize = (core->file) ? rz_io_fd_size(core->io, core->file->fd) : 0;
29  if (oldsize == -1) {
30  return RZ_CMD_STATUS_ERROR;
31  }
33  return RZ_CMD_STATUS_OK;
34 }
RZ_API bool rz_core_file_resize_delta(RzCore *core, st64 delta)
Definition: cfile.c:522
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RzIO * io
Definition: rz_core.h:313
RzCoreFile * file
Definition: rz_core.h:314
static st64 delta
Definition: vmenus.c:2425
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References delta, rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_file_resize_delta(), rz_io_fd_size(), and ut64().

Referenced by rz_resize_insert_handler(), and rz_resize_remove_handler().

◆ rz_rebase_handler()

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

Definition at line 17 of file cmd_resize.c.

17  {
18  ut64 oldbase = rz_num_math(core->num, argv[1]);
19  // old base = addr
20  // new base = core->offset
21  return rebase_helper(core, oldbase, core->offset);
22 }
static int rebase_helper(RzCore *core, ut64 oldbase, ut64 newbase)
Definition: cmd_resize.c:7
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
ut64 offset
Definition: rz_core.h:301
RzNum * num
Definition: rz_core.h:316

References argv, rz_core_t::num, rz_core_t::offset, rebase_helper(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_resize_handler()

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

Definition at line 36 of file cmd_resize.c.

36  {
37  if (!core->file) {
38  return RZ_CMD_STATUS_ERROR;
39  }
40  ut64 oldsize = (core->file) ? rz_io_fd_size(core->io, core->file->fd) : 0;
41  if (oldsize == -1) {
42  return RZ_CMD_STATUS_ERROR;
43  }
44  if (argc > 1) {
45  ut64 newsize = rz_num_math(core->num, argv[1]);
46  if (newsize == 0) {
47  RZ_LOG_ERROR("Invalid new file size");
48  return RZ_CMD_STATUS_ERROR;
49  }
50  rz_core_file_resize(core, newsize);
51  } else {
52  switch (state->mode) {
53  case RZ_OUTPUT_MODE_JSON: {
54  PJ *pj = state->d.pj;
55  pj_o(pj);
56  pj_kn(pj, "size", oldsize);
57  pj_end(pj);
58  break;
59  }
61  rz_cons_printf("%" PFMT64d "\n", oldsize);
62  break;
63  default:
65  break;
66  }
67  }
68  return RZ_CMD_STATUS_OK;
69 }
RZ_API bool rz_core_file_resize(RzCore *core, ut64 newsize)
Definition: cfile.c:518
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
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_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
#define PFMT64d
Definition: rz_types.h:394
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
Definition: rz_pj.h:12
Definition: dis.h:43

References argv, rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, rz_core_t::num, PFMT64d, pj_end(), pj_kn(), pj_o(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_file_resize(), rz_io_fd_size(), RZ_LOG_ERROR, rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_resize_human_handler()

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

Definition at line 81 of file cmd_resize.c.

81  {
82  if (!core->file) {
83  return RZ_CMD_STATUS_ERROR;
84  }
85  ut64 oldsize = (core->file) ? rz_io_fd_size(core->io, core->file->fd) : 0;
86  if (oldsize == -1) {
87  return RZ_CMD_STATUS_ERROR;
88  }
89  char humansz[8];
90  rz_num_units(humansz, sizeof(humansz), oldsize);
91  rz_cons_println(humansz);
92  return RZ_CMD_STATUS_OK;
93 }
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API char * rz_num_units(char *buf, size_t len, ut64 number)
Definition: unum.c:108

References rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), rz_io_fd_size(), rz_num_units(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_resize_insert_handler()

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

Definition at line 76 of file cmd_resize.c.

76  {
77  st64 delta = (st64)rz_num_math(core->num, argv[1]);
78  return resize_helper(core, delta);
79 }
static RzCmdStatus resize_helper(RzCore *core, st64 delta)
Definition: cmd_resize.c:24
#define st64
Definition: rz_types_base.h:10

References argv, delta, rz_core_t::num, resize_helper(), rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_resize_remove_handler()

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

Definition at line 71 of file cmd_resize.c.

71  {
72  st64 delta = (st64)rz_num_math(core->num, argv[1]);
73  return resize_helper(core, -delta);
74 }

References argv, delta, rz_core_t::num, resize_helper(), rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().