Rizin
unix-like reverse engineering framework and cli tools
cmd_seek.c File Reference
#include "rz_types.h"
#include "rz_config.h"
#include "rz_cons.h"
#include "rz_core.h"
#include "rz_debug.h"
#include "rz_io.h"

Go to the source code of this file.

Functions

static void printPadded (RzCore *core, int pad)
 
RZ_IPI bool rz_core_seek_to_register (RzCore *core, const char *regname, bool is_silent)
 
RZ_IPI int rz_core_seek_opcode_backward (RzCore *core, int numinstr, bool silent)
 
RZ_IPI int rz_core_seek_opcode_forward (RzCore *core, int n, bool silent)
 
RZ_IPI int rz_core_seek_opcode (RzCore *core, int n, bool silent)
 
static void cmd_seek_opcode (RzCore *core, const char *input, bool silent)
 
RZ_IPI int rz_seek_search (void *data, const char *input)
 
static RzCmdStatus bool2cmdstatus (bool res)
 
RZ_IPI RzCmdStatus rz_seek_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_delta_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_padded_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_base_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_blocksize_backward_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_blocksize_forward_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_redo_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_undo_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_undo_reset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_history_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_seek_asz_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_basicblock_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_function_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_function_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_begin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_end_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_next_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_prev_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_opcode_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_seek_register_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ bool2cmdstatus()

◆ cmd_seek_opcode()

static void cmd_seek_opcode ( RzCore core,
const char *  input,
bool  silent 
)
static

Definition at line 94 of file cmd_seek.c.

94  {
95  if (input[0] == '?') {
96  eprintf("Usage: so [-][n]\n");
97  return;
98  }
99  if (!strcmp(input, "-")) {
100  input = "-1";
101  }
102  int n = rz_num_math(core->num, input);
103  if (n == 0) {
104  n = 1;
105  }
106  rz_core_seek_opcode(core, n, silent);
107 }
RZ_IPI int rz_core_seek_opcode(RzCore *core, int n, bool silent)
Definition: cmd_seek.c:86
int n
Definition: mipsasm.c:19
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RzNum * num
Definition: rz_core.h:316
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References eprintf, input(), n, rz_core_t::num, rz_core_seek_opcode(), rz_num_math(), and test-lz4-list::silent.

Referenced by rz_seek_opcode_handler().

◆ printPadded()

static void printPadded ( RzCore core,
int  pad 
)
static

Definition at line 11 of file cmd_seek.c.

11  {
12  if (pad < 1) {
13  pad = 8;
14  }
15  char *fmt = rz_str_newf("0x%%0%d" PFMT64x, pad);
16  char *off = rz_str_newf(fmt, core->offset);
17  rz_cons_printf("%s\n", off);
18  free(off);
19  free(fmt);
20 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int off
Definition: pal.c:13
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64x
Definition: rz_types.h:393
ut64 offset
Definition: rz_core.h:301

References free(), off, rz_core_t::offset, pad(), PFMT64x, rz_cons_printf(), and rz_str_newf().

Referenced by rz_seek_padded_handler().

◆ rz_core_seek_opcode()

RZ_IPI int rz_core_seek_opcode ( RzCore core,
int  n,
bool  silent 
)

Definition at line 86 of file cmd_seek.c.

86  {
87  int val = (n < 0)
90  core->num->value = val;
91  return val;
92 }
ut16 val
Definition: armass64_const.h:6
RZ_IPI int rz_core_seek_opcode_backward(RzCore *core, int numinstr, bool silent)
Definition: cmd_seek.c:27
RZ_IPI int rz_core_seek_opcode_forward(RzCore *core, int n, bool silent)
Definition: cmd_seek.c:65
ut64 value
Definition: rz_num.h:63

References n, rz_core_t::num, rz_core_seek_opcode_backward(), rz_core_seek_opcode_forward(), test-lz4-list::silent, val, and rz_num_t::value.

Referenced by cmd_seek_opcode(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), graphNodeMove(), rz_core_cmd_lastcmd_repeat(), rz_core_cmd_subst_i(), and rz_core_visual_graph().

◆ rz_core_seek_opcode_backward()

RZ_IPI int rz_core_seek_opcode_backward ( RzCore core,
int  numinstr,
bool  silent 
)

Definition at line 27 of file cmd_seek.c.

27  {
28  int i, val = 0;
29  // N previous instructions
30  ut64 addr = core->offset;
31  int ret = 0;
32  if (rz_core_prevop_addr(core, core->offset, numinstr, &addr)) {
33  ret = core->offset - addr;
34  } else {
35 #if 0
36  // core_asm_bwdis_len is really buggy and we should remove it. seems like prevop_addr
37  // works as expected, because is the one used from visual
38  ret = rz_core_asm_bwdis_len (core, &instr_len, &addr, numinstr);
39 #endif
40  addr = core->offset;
41  const int mininstrsize = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE);
42  for (i = 0; i < numinstr; i++) {
43  ut64 prev_addr = rz_core_prevop_addr_force(core, addr, 1);
44  if (prev_addr == UT64_MAX) {
45  prev_addr = addr - mininstrsize;
46  }
47  if (prev_addr == UT64_MAX || prev_addr >= core->offset) {
48  break;
49  }
50  RzAsmOp op = { 0 };
51  rz_core_seek(core, prev_addr, true);
52  rz_asm_disassemble(core->rasm, &op, core->block, 32);
53  if (op.size < mininstrsize) {
54  op.size = mininstrsize;
55  }
56  val += op.size;
57  addr = prev_addr;
58  }
59  }
60  rz_core_seek_opt(core, addr, true, !silent);
61  val += ret;
62  return val;
63 }
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
lzma_index ** i
Definition: index.h:629
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
RZ_API ut32 rz_core_asm_bwdis_len(RzCore *core, int *instr_len, ut64 *start_addr, ut32 nb)
Definition: casm.c:890
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API bool rz_core_seek_opt(RzCore *core, ut64 addr, bool rb, bool save)
Seek to addr and optionally save the current offset in seek history.
Definition: seek.c:141
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
RzAsm * rasm
Definition: rz_core.h:323
RzAnalysis * analysis
Definition: rz_core.h:322
ut8 * block
Definition: rz_core.h:305
Definition: dis.c:32
RZ_API bool rz_core_prevop_addr(RzCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr)
Definition: visual.c:1173
RZ_API ut64 rz_core_prevop_addr_force(RzCore *core, ut64 start_addr, int numinstrs)
Definition: visual.c:1195
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, rz_core_t::analysis, rz_core_t::block, i, rz_core_t::offset, rz_core_t::rasm, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE, rz_asm_disassemble(), rz_core_asm_bwdis_len(), rz_core_prevop_addr(), rz_core_prevop_addr_force(), rz_core_seek(), rz_core_seek_opt(), test-lz4-list::silent, ut64(), UT64_MAX, and val.

Referenced by rz_core_seek_opcode().

◆ rz_core_seek_opcode_forward()

RZ_IPI int rz_core_seek_opcode_forward ( RzCore core,
int  n,
bool  silent 
)

Definition at line 65 of file cmd_seek.c.

65  {
66  // N forward instructions
67  int i, ret, val = 0;
68  if (!silent) {
69  rz_core_seek_mark(core);
70  }
71  for (val = i = 0; i < n; i++) {
73  ret = rz_analysis_op(core->analysis, &op, core->offset, core->block,
75  if (ret < 1) {
76  ret = 1;
77  }
78  rz_core_seek_delta(core, ret, false);
80  val += ret;
81  }
82  rz_core_seek_save(core);
83  return val;
84 }
ut8 op
Definition: 6502dis.c:13
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
RZ_API bool rz_core_seek_delta(RzCore *core, st64 delta, bool save)
Seek relative to current offset and optionally save the current offset in seek history.
Definition: seek.c:152
RZ_API bool rz_core_seek_mark(RzCore *core)
Mark current state (offset+cursor) as the next state to save in history.
Definition: seek.c:57
RZ_API bool rz_core_seek_save(RzCore *core)
Save last marked position, if any, in the seek history.
Definition: seek.c:87
ut32 blocksize
Definition: rz_core.h:303

References rz_core_t::analysis, rz_core_t::block, rz_core_t::blocksize, i, n, rz_core_t::offset, op, rz_analysis_op(), rz_analysis_op_fini(), RZ_ANALYSIS_OP_MASK_BASIC, rz_core_seek_delta(), rz_core_seek_mark(), rz_core_seek_save(), test-lz4-list::silent, and val.

Referenced by rz_core_seek_opcode().

◆ rz_core_seek_to_register()

RZ_IPI bool rz_core_seek_to_register ( RzCore core,
const char *  regname,
bool  is_silent 
)

Definition at line 22 of file cmd_seek.c.

22  {
24  return rz_core_seek_opt(core, off, true, !is_silent);
25 }
RZ_API ut64 rz_core_reg_getv_by_role_or_name(RzCore *core, const char *name)
rz_reg_getv_by_role_or_name() on rz_core_reg_default()
Definition: creg.c:24
static char * regname(int reg)
Definition: dis.c:71

References off, regname(), rz_core_reg_getv_by_role_or_name(), rz_core_seek_opt(), and ut64().

Referenced by agraph_refresh(), rz_core_cmd_lastcmd_repeat(), rz_core_dbg_follow_seek_register(), rz_core_esil_step(), rz_core_file_reopen(), rz_core_file_reopen_debug(), rz_core_file_reopen_remote_debug(), rz_core_setup_debugger(), rz_core_visual_graph(), and rz_seek_register_handler().

◆ rz_seek_asz_handler()

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

Definition at line 287 of file cmd_seek.c.

287  {
288  ut64 align = rz_num_math(NULL, argv[1]);
289  ut64 addr = core->offset;
290  rz_core_seek_mark(core);
291  if (argc > 2) {
292  addr = rz_num_math(core->num, argv[2]);
293  rz_core_seek(core, addr, false);
294  }
295  return bool2cmdstatus(rz_core_seek_align(core, align, true));
296 }
static RzCmdStatus bool2cmdstatus(bool res)
Definition: cmd_seek.c:153
#define NULL
Definition: cris-opc.c:27
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API bool rz_core_seek_align(RzCore *core, ut64 align, bool save)
Seek to current offset aligned to align.
Definition: seek.c:274

References addr, argv, bool2cmdstatus(), NULL, rz_core_t::num, rz_core_t::offset, rz_core_seek(), rz_core_seek_align(), rz_core_seek_mark(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_base_handler()

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

Definition at line 194 of file cmd_seek.c.

194  {
195  return bool2cmdstatus(rz_core_seek_base(core, argv[1], true));
196 }
RZ_API int rz_core_seek_base(RzCore *core, const char *hex, bool save)
Seek to a new address composed of current offset with last hex digits replaced with those of hex.
Definition: seek.c:171

References argv, bool2cmdstatus(), and rz_core_seek_base().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_basicblock_handler()

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

Definition at line 298 of file cmd_seek.c.

298  {
299  return bool2cmdstatus(rz_core_seek_analysis_bb(core, core->offset, true));
300 }
RZ_API bool rz_core_seek_analysis_bb(RzCore *core, ut64 addr, bool save)
Seek to basic block that contains address addr.
Definition: seek.c:289

References bool2cmdstatus(), rz_core_t::offset, and rz_core_seek_analysis_bb().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_begin_handler()

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

Definition at line 329 of file cmd_seek.c.

329  {
330  RzIOMap *map = rz_io_map_get(core->io, core->offset);
331  ut64 addr = map ? map->itv.addr : 0;
332  return bool2cmdstatus(rz_core_seek_and_save(core, addr, true));
333 }
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 bool rz_core_seek_and_save(RzCore *core, ut64 addr, bool rb)
Save currently marked state in seek history and seek to addr .
Definition: seek.c:101
RzIO * io
Definition: rz_core.h:313

References addr, bool2cmdstatus(), rz_core_t::io, map(), rz_core_t::offset, rz_core_seek_and_save(), rz_io_map_get(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_blocksize_backward_handler()

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

Definition at line 198 of file cmd_seek.c.

198  {
199  int n = 1;
200  if (argc == 2) {
201  n = rz_num_math(core->num, argv[1]);
202  }
203  int delta = -core->blocksize / n;
204  return bool2cmdstatus(rz_core_seek_delta(core, delta, true));
205 }
static st64 delta
Definition: vmenus.c:2425

References argv, rz_core_t::blocksize, bool2cmdstatus(), delta, n, rz_core_t::num, rz_core_seek_delta(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_blocksize_forward_handler()

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

Definition at line 207 of file cmd_seek.c.

207  {
208  int n = 1;
209  if (argc == 2) {
210  n = rz_num_math(core->num, argv[1]);
211  }
212  int delta = core->blocksize / n;
213  return bool2cmdstatus(rz_core_seek_delta(core, delta, true));
214 }

References argv, rz_core_t::blocksize, bool2cmdstatus(), delta, n, rz_core_t::num, rz_core_seek_delta(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_delta_handler()

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

Definition at line 183 of file cmd_seek.c.

183  {
184  st64 delta = strtoll(argv[1], NULL, 0);
185  return bool2cmdstatus(rz_core_seek_delta(core, delta, true));
186 }
#define st64
Definition: rz_types_base.h:10

References argv, bool2cmdstatus(), delta, NULL, rz_core_seek_delta(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_seek_end_handler()

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

Definition at line 335 of file cmd_seek.c.

335  {
336  RzIOMap *map = rz_io_map_get(core->io, core->offset);
337  // XXX: this +2 is a hack. must fix gap between sections
338  ut64 addr = map ? map->itv.addr + map->itv.size + 2 : rz_io_fd_size(core->io, core->file->fd);
339  return bool2cmdstatus(rz_core_seek_and_save(core, addr, true));
340 }
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RzCoreFile * file
Definition: rz_core.h:314

References addr, bool2cmdstatus(), rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, map(), rz_core_t::offset, rz_core_seek_and_save(), rz_io_fd_size(), rz_io_map_get(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_function_current_handler()

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

Definition at line 321 of file cmd_seek.c.

321  {
323  if (!fcn) {
324  return RZ_CMD_STATUS_ERROR;
325  }
326  return bool2cmdstatus(rz_core_seek_and_save(core, fcn->addr, true));
327 }
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687

References rz_analysis_function_t::addr, rz_core_t::analysis, bool2cmdstatus(), rz_core_t::offset, rz_analysis_get_fcn_in(), RZ_CMD_STATUS_ERROR, and rz_core_seek_and_save().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_function_handler()

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

Definition at line 302 of file cmd_seek.c.

302  {
303  RzAnalysisFunction *fcn = NULL;
304  ut64 addr;
305  if (argc == 1) {
306  fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
307  if (!fcn) {
308  return RZ_CMD_STATUS_ERROR;
309  }
311  } else {
313  if (!fcn) {
314  return RZ_CMD_STATUS_ERROR;
315  }
316  addr = fcn->addr;
317  }
318  return bool2cmdstatus(rz_core_seek_and_save(core, addr, true));
319 }
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API RzAnalysisFunction * rz_analysis_get_function_byname(RzAnalysis *a, const char *name)
Definition: fcn.c:1729

References addr, rz_analysis_function_t::addr, rz_core_t::analysis, argv, bool2cmdstatus(), NULL, rz_core_t::offset, rz_analysis_function_max_addr(), rz_analysis_get_fcn_in(), rz_analysis_get_function_byname(), RZ_CMD_STATUS_ERROR, rz_core_seek_and_save(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_handler()

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

Definition at line 157 of file cmd_seek.c.

157  {
158  if (argc == 1) {
159  rz_cons_printf("0x%" PFMT64x "\n", core->offset);
160  return RZ_CMD_STATUS_OK;
161  }
162 
163  rz_core_seek_mark(core);
164 
165  // NOTE: hack to make it work with local function labels
166  char *ptr;
167  if ((ptr = strstr(argv[1], "+.")) != NULL) {
168  char *dup = strdup(argv[1]);
169  dup[ptr - argv[1]] = '\x00';
170  core->offset = rz_num_math(core->num, dup);
171  ;
172  free(dup);
173  }
174 
175  ut64 addr = rz_num_math(core->num, argv[1]);
176  if (core->num->nc.errors) {
177  RZ_LOG_ERROR("Cannot seek to unknown address '%s'\n", core->num->nc.calc_buf);
178  return RZ_CMD_STATUS_ERROR;
179  }
180  return bool2cmdstatus(rz_core_seek_and_save(core, addr, true));
181 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode dup
Definition: sflib.h:68
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")
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
const char * calc_buf
Definition: rz_num.h:54
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67

References addr, argv, bool2cmdstatus(), rz_num_calc_t::calc_buf, dup, rz_num_calc_t::errors, free(), rz_num_t::nc, NULL, rz_core_t::num, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_seek_and_save(), rz_core_seek_mark(), RZ_LOG_ERROR, rz_num_math(), strdup(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_history_list_handler()

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

Definition at line 229 of file cmd_seek.c.

229  {
230  RzList *list = rz_core_seek_list(core);
231  RzListIter *iter;
232  RzCoreSeekItem *undo;
233  PJ *pj = state->d.pj;
235  bool current_met = false;
236  rz_list_foreach (list, iter, undo) {
237  RzFlagItem *f = rz_flag_get_at(core->flags, undo->offset, true);
238  const char *comment;
239  char *name = NULL;
240  if (f) {
241  if (f->offset != undo->offset) {
242  name = rz_str_newf("%s+%" PFMT64d, f->name, undo->offset - f->offset);
243  } else {
244  name = strdup(f->name);
245  }
246  }
247  current_met |= undo->is_current;
248  switch (state->mode) {
249  case RZ_OUTPUT_MODE_JSON:
250  pj_o(pj);
251  pj_kn(pj, "offset", undo->offset);
252  pj_kn(pj, "cursor", undo->cursor);
253  if (name) {
254  pj_ks(pj, "name", name);
255  }
256  pj_kb(pj, "current", undo->is_current);
257  pj_end(pj);
258  break;
260  comment = "";
261  if (undo->is_current) {
262  comment = " # current seek";
263  } else if (current_met) {
264  comment = " # redo";
265  }
266  rz_cons_printf("0x%" PFMT64x " %s%s\n", undo->offset, name ? name : "", comment);
267  break;
269  if (undo->is_current) {
270  rz_cons_printf("# Current seek @ 0x%" PFMT64x "\n", undo->offset);
271  } else if (current_met) {
272  rz_cons_printf("f redo_%d @ 0x%" PFMT64x "\n", RZ_ABS(undo->idx - 1), undo->offset);
273  } else {
274  rz_cons_printf("f undo_%d @ 0x%" PFMT64x "\n", RZ_ABS(undo->idx + 1), undo->offset);
275  }
276  break;
277  default:
279  break;
280  }
281  free(name);
282  }
284  return RZ_CMD_STATUS_OK;
285 }
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
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
static void list(RzEgg *egg)
Definition: rz-gg.c:52
@ RZ_ABS
#define rz_warn_if_reached()
Definition: rz_assert.h:29
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
#define PFMT64d
Definition: rz_types.h:394
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
RZ_API RzList * rz_core_seek_list(RzCore *core)
Return the seek history.
Definition: seek.c:411
#define f(i)
Definition: sha256.c:46
Definition: z80asm.h:102
Definition: rz_pj.h:12
int idx
Position of the item relative to the current seek item (0 current seek, < 0 for undos,...
Definition: rz_core.h:148
ut64 offset
Value of core->offset at the given time in history.
Definition: rz_core.h:145
bool is_current
True if this is the current seek value.
Definition: rz_core.h:147
int cursor
Position of the cursor at the given time in history.
Definition: rz_core.h:146
RzFlag * flags
Definition: rz_core.h:330
Definition: dis.h:43

References rz_core_seek_undo_t::cursor, f, rz_core_t::flags, free(), rz_core_seek_undo_t::idx, rz_core_seek_undo_t::is_current, list(), NULL, rz_core_seek_undo_t::offset, PFMT64d, PFMT64x, pj_end(), pj_kb(), pj_kn(), pj_ks(), pj_o(), RZ_ABS, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_seek_list(), rz_flag_get_at(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_str_newf(), rz_warn_if_reached, and strdup().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_next_handler()

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

Definition at line 342 of file cmd_seek.c.

342  {
343  const char *nkey;
344  if (argc == 1) {
345  nkey = rz_config_get(core->config, "scr.nkey");
346  } else {
347  nkey = argv[1];
348  }
349  return bool2cmdstatus(rz_core_seek_next(core, nkey, true));
350 }
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API bool rz_core_seek_next(RzCore *core, const char *type, bool save)
Seek to the next type of item from current offset.
Definition: seek.c:203
RzConfig * config
Definition: rz_core.h:300

References argv, bool2cmdstatus(), rz_core_t::config, rz_config_get(), and rz_core_seek_next().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_opcode_handler()

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

Definition at line 362 of file cmd_seek.c.

362  {
363  cmd_seek_opcode(core, argc > 1 ? argv[1] : "", false);
364  return RZ_CMD_STATUS_OK;
365 }
static void cmd_seek_opcode(RzCore *core, const char *input, bool silent)
Definition: cmd_seek.c:94

References argv, cmd_seek_opcode(), and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_seek_padded_handler()

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

Definition at line 188 of file cmd_seek.c.

188  {
189  int n = argc > 1 ? atoi(argv[1]) : 0;
190  printPadded(core, n);
191  return RZ_CMD_STATUS_OK;
192 }
static void printPadded(RzCore *core, int pad)
Definition: cmd_seek.c:11

References argv, n, printPadded(), and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_seek_prev_handler()

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

Definition at line 352 of file cmd_seek.c.

352  {
353  const char *nkey;
354  if (argc == 1) {
355  nkey = rz_config_get(core->config, "scr.nkey");
356  } else {
357  nkey = argv[1];
358  }
359  return bool2cmdstatus(rz_core_seek_prev(core, nkey, true));
360 }
RZ_API bool rz_core_seek_prev(RzCore *core, const char *type, bool save)
Seek to the previous type of item from current offset.
Definition: seek.c:241

References argv, bool2cmdstatus(), rz_core_t::config, rz_config_get(), and rz_core_seek_prev().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_redo_handler()

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

Definition at line 216 of file cmd_seek.c.

216  {
217  return bool2cmdstatus(rz_core_seek_redo(core));
218 }
RZ_API bool rz_core_seek_redo(RzCore *core)
Definition: seek.c:316

References bool2cmdstatus(), and rz_core_seek_redo().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_register_handler()

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

Definition at line 367 of file cmd_seek.c.

367  {
368  return bool2cmdstatus(rz_core_seek_to_register(core, argv[1], false));
369 }
RZ_IPI bool rz_core_seek_to_register(RzCore *core, const char *regname, bool is_silent)
Definition: cmd_seek.c:22

References argv, bool2cmdstatus(), and rz_core_seek_to_register().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_search()

RZ_IPI int rz_seek_search ( void *  data,
const char *  input 
)

Definition at line 109 of file cmd_seek.c.

109  {
110  RzCore *core = (RzCore *)data;
111  const char *pfx = rz_config_get(core->config, "search.prefix");
112  const ut64 saved_from = rz_config_get_i(core->config, "search.from");
113  const ut64 saved_maxhits = rz_config_get_i(core->config, "search.maxhits");
114  int kwidx = core->search->n_kws; // (int)rz_config_get_i (core->config, "search.kwidx")-1;
115  if (kwidx < 0) {
116  kwidx = 0;
117  }
118  switch (input[0]) {
119  case ' ':
120  case 'v':
121  case 'V':
122  case 'w':
123  case 'W':
124  case 'z':
125  case 'm':
126  case 'c':
127  case 'A':
128  case 'e':
129  case 'E':
130  case 'i':
131  case 'R':
132  case 'r':
133  case '/':
134  case 'x':
135  rz_config_set_i(core->config, "search.from", core->offset + 1);
136  rz_config_set_i(core->config, "search.maxhits", 1);
137  rz_core_cmdf(core, "sd 1@e:cfg.seek.silent=true; /%s; sd -1@e:cfg.seek.silent=true; s %s%d_0; f- %s%d_0",
138  input, pfx, kwidx, pfx, kwidx);
139  rz_config_set_i(core->config, "search.from", saved_from);
140  rz_config_set_i(core->config, "search.maxhits", saved_maxhits);
141  break;
142  case '?':
143  eprintf("Usage: s/.. arg.\n");
144  rz_cons_printf("/?\n");
145  break;
146  default:
147  eprintf("unknown search method\n");
148  break;
149  }
150  return 0;
151 }
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RzSearch * search
Definition: rz_core.h:331

References rz_core_t::config, eprintf, input(), rz_search_t::n_kws, rz_core_t::offset, rz_config_get(), rz_config_get_i(), rz_config_set_i(), rz_cons_printf(), rz_core_cmdf(), rz_core_t::search, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_undo_handler()

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

Definition at line 220 of file cmd_seek.c.

220  {
221  return bool2cmdstatus(rz_core_seek_undo(core));
222 }
RZ_API bool rz_core_seek_undo(RzCore *core)
Definition: seek.c:301

References bool2cmdstatus(), and rz_core_seek_undo().

Referenced by rzshell_cmddescs_init().

◆ rz_seek_undo_reset_handler()

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

Definition at line 224 of file cmd_seek.c.

224  {
225  rz_core_seek_reset(core);
226  return RZ_CMD_STATUS_OK;
227 }
RZ_API void rz_core_seek_reset(RzCore *core)
Definition: seek.c:388

References RZ_CMD_STATUS_OK, and rz_core_seek_reset().

Referenced by rzshell_cmddescs_init().