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

Go to the source code of this file.

Classes

struct  seek_flag_offset_t
 

Functions

RZ_API void rz_core_seek_item_free (RzCoreSeekItem *item)
 
static void get_current_seek_state (RzCore *core, RzCoreSeekItem *elem)
 
static void set_current_seek_state (RzCore *core, RzCoreSeekItem *elem)
 
static void add_seek_history (RzCore *core)
 
static bool seek_check_save (RzCore *core, ut64 addr, bool rb, bool save)
 
RZ_API bool rz_core_seek_mark (RzCore *core)
 Mark current state (offset+cursor) as the next state to save in history. More...
 
static bool need_add2history (RzCore *core, ut64 addr)
 
static bool seek_save (RzCore *core, ut64 addr)
 
RZ_API bool rz_core_seek_save (RzCore *core)
 Save last marked position, if any, in the seek history. More...
 
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 . More...
 
RZ_API bool rz_core_seek (RzCore *core, ut64 addr, bool rb)
 Seek to addr. More...
 
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. More...
 
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. More...
 
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. More...
 
static bool seek_flag_offset (RzFlagItem *fi, void *user)
 
RZ_API bool rz_core_seek_next (RzCore *core, const char *type, bool save)
 Seek to the next type of item from current offset. More...
 
RZ_API bool rz_core_seek_prev (RzCore *core, const char *type, bool save)
 Seek to the previous type of item from current offset. More...
 
RZ_API bool rz_core_seek_align (RzCore *core, ut64 align, bool save)
 Seek to current offset aligned to align. More...
 
RZ_API bool rz_core_seek_analysis_bb (RzCore *core, ut64 addr, bool save)
 Seek to basic block that contains address addr. More...
 
RZ_API bool rz_core_seek_undo (RzCore *core)
 
RZ_API bool rz_core_seek_redo (RzCore *core)
 
static RzCoreSeekItemget_current_item (RzCore *core)
 
static RzCoreSeekItemdup_seek_history_item (RzCoreSeekItem *item, int i)
 
RZ_API RzCoreSeekItemrz_core_seek_peek (RzCore *core, int idx)
 Return a element in the undo/redo list. More...
 
RZ_API void rz_core_seek_reset (RzCore *core)
 
RZ_API void rz_core_seek_free (RzCore *core)
 
RZ_API RzListrz_core_seek_list (RzCore *core)
 Return the seek history. More...
 
RZ_IPI bool rz_core_seek_bb_instruction (RzCore *core, int index)
 

Function Documentation

◆ add_seek_history()

static void add_seek_history ( RzCore core)
static

Definition at line 22 of file seek.c.

22  {
23  RzVector *vundo = &core->seek_history.undos;
24  RzVector *vredo = &core->seek_history.redos;
25  RzCoreSeekItem *item = &core->seek_history.saved_item;
26  ut64 histsize = rz_config_get_i(core->config, "cfg.seek.histsize");
27  if (!rz_vector_empty(vundo)) {
28  RzCoreSeekItem *last = rz_vector_index_ptr(vundo, rz_vector_len(vundo) - 1);
29  if (item->offset == last->offset && item->cursor == last->cursor) {
30  return;
31  }
32  }
33  if (histsize != 0 && rz_vector_len(vundo) >= histsize) {
34  rz_vector_remove_at(vundo, 0, NULL);
35  }
36  rz_vector_push(vundo, item);
37  rz_vector_clear(vredo);
38 }
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
#define NULL
Definition: cris-opc.c:27
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88
RZ_API void rz_vector_remove_at(RzVector *vec, size_t index, void *into)
Definition: vector.c:127
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197
RZ_API void rz_vector_clear(RzVector *vec)
Definition: vector.c:68
static size_t rz_vector_len(const RzVector *vec)
Definition: rz_vector.h:82
static bool rz_vector_empty(const RzVector *vec)
Definition: rz_vector.h:74
RzCoreSeekItem saved_item
Position to save in history.
Definition: rz_core.h:294
RzVector undos
Stack of RzCoreSeekItems, allowing to "go back in time".
Definition: rz_core.h:291
RzVector redos
Stack of RzCoreSeekItems, allowing to re-do an action that was undone.
Definition: rz_core.h:292
ut64 offset
Value of core->offset at the given time in history.
Definition: rz_core.h:145
int cursor
Position of the cursor at the given time in history.
Definition: rz_core.h:146
RzCoreSeekHistory seek_history
Definition: rz_core.h:388
RzConfig * config
Definition: rz_core.h:300
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::config, rz_core_seek_undo_t::cursor, NULL, rz_core_seek_undo_t::offset, rz_core_seek_history_t::redos, rz_config_get_i(), rz_vector_clear(), rz_vector_empty(), rz_vector_index_ptr(), rz_vector_len(), rz_vector_push(), rz_vector_remove_at(), rz_core_seek_history_t::saved_item, rz_core_t::seek_history, rz_core_seek_history_t::undos, and ut64().

Referenced by seek_save().

◆ dup_seek_history_item()

static RzCoreSeekItem* dup_seek_history_item ( RzCoreSeekItem item,
int  i 
)
static

Definition at line 339 of file seek.c.

339  {
341  if (!res) {
342  return NULL;
343  }
344  res->offset = item->offset;
345  res->cursor = item->cursor;
346  res->is_current = item->is_current;
347  res->idx = i;
348  return res;
349 }
lzma_index ** i
Definition: index.h:629
#define RZ_NEW0(x)
Definition: rz_types.h:284
int idx
Position of the item relative to the current seek item (0 current seek, < 0 for undos,...
Definition: rz_core.h:148
bool is_current
True if this is the current seek value.
Definition: rz_core.h:147

References rz_core_seek_undo_t::cursor, i, rz_core_seek_undo_t::idx, rz_core_seek_undo_t::is_current, NULL, rz_core_seek_undo_t::offset, and RZ_NEW0.

Referenced by rz_core_seek_list(), and rz_core_seek_peek().

◆ get_current_item()

static RzCoreSeekItem* get_current_item ( RzCore core)
static

Definition at line 328 of file seek.c.

328  {
330  if (!res) {
331  return NULL;
332  }
333  get_current_seek_state(core, res);
334  res->is_current = true;
335  res->idx = 0;
336  return res;
337 }
static void get_current_seek_state(RzCore *core, RzCoreSeekItem *elem)
Definition: seek.c:11

References get_current_seek_state(), rz_core_seek_undo_t::idx, rz_core_seek_undo_t::is_current, NULL, and RZ_NEW0.

Referenced by rz_core_seek_list(), and rz_core_seek_peek().

◆ get_current_seek_state()

static void get_current_seek_state ( RzCore core,
RzCoreSeekItem elem 
)
static

Definition at line 11 of file seek.c.

11  {
12  elem->offset = core->offset;
13  elem->cursor = core->print->cur_enabled ? rz_print_get_cursor(core->print) : 0;
14  elem->is_current = false;
15 }
RZ_API int rz_print_get_cursor(RzPrint *p)
Definition: print.c:1571
ut64 offset
Definition: rz_core.h:301
RzPrint * print
Definition: rz_core.h:327
bool cur_enabled
Definition: rz_print.h:130

References rz_print_t::cur_enabled, rz_core_seek_undo_t::cursor, rz_core_seek_undo_t::is_current, rz_core_seek_undo_t::offset, rz_core_t::offset, rz_core_t::print, and rz_print_get_cursor().

Referenced by get_current_item(), rz_core_seek_mark(), rz_core_seek_redo(), and rz_core_seek_undo().

◆ need_add2history()

static bool need_add2history ( RzCore core,
ut64  addr 
)
static

Definition at line 67 of file seek.c.

67  {
68  RzCoreSeekHistory *hist = &core->seek_history;
69  return hist->saved_set && (addr != hist->saved_item.offset || hist->saved_item.cursor != 0);
70 }
bool saved_set
When true, the saved field is set.
Definition: rz_core.h:293
static int addr
Definition: z80asm.c:58

References addr, rz_core_seek_undo_t::cursor, rz_core_seek_undo_t::offset, rz_core_seek_history_t::saved_item, rz_core_seek_history_t::saved_set, and rz_core_t::seek_history.

Referenced by seek_save().

◆ rz_core_seek()

RZ_API bool rz_core_seek ( RzCore core,
ut64  addr,
bool  rb 
)

Seek to addr.

Parameters
coreRzCore reference
addrAddress where to move to
rbIf true read the block

Definition at line 116 of file seek.c.

116  {
117  core->offset = rz_io_seek(core->io, addr, RZ_IO_SEEK_SET);
118  if (rb) {
119  rz_core_block_read(core);
120  }
121  if (core->binat) {
122  RzBinFile *bf = rz_bin_file_at(core->bin, core->offset);
123  if (bf) {
124  core->bin->cur = bf;
125  rz_bin_select_bfid(core->bin, bf->id);
126  } else {
127  core->bin->cur = NULL;
128  }
129  }
130  return core->offset == addr;
131 }
RZ_API RzBinFile * rz_bin_file_at(RzBin *bin, ut64 at)
Definition: bin.c:1160
RZ_API bool rz_bin_select_bfid(RzBin *bin, ut32 bf_id)
Definition: bin.c:833
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API ut64 rz_io_seek(RzIO *io, ut64 offset, int whence)
Definition: io.c:632
#define RZ_IO_SEEK_SET
Definition: rz_io.h:15
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
Definition: rz_bin.h:330
RzBin * bin
Definition: rz_core.h:298
RzIO * io
Definition: rz_core.h:313
bool binat
Definition: rz_core.h:374

References addr, rz_core_t::bin, rz_core_t::binat, rz_bin_t::cur, rz_bin_file_t::id, rz_core_t::io, NULL, rz_core_t::offset, rz_bin_file_at(), rz_bin_select_bfid(), rz_core_block_read(), rz_io_seek(), and RZ_IO_SEEK_SET.

Referenced by __direction_disassembly_cb(), __disasm(), __handleComment(), __panels_process(), __print_disassembly_cb(), __print_hexdump_cb(), _cb_hit(), _CbInRangeSearchV(), backup_current_addr(), cmd_pCd(), cmd_pCD(), cmd_print_pv(), core_disassembly(), core_perform_auto_analysis(), cursor_prevrow(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_analysis_search(), do_iter_offsets(), do_iter_sections(), do_ref_search(), do_syscall_search(), fix_cursor(), foreach_pairs(), foreachOffset(), get_cgnodes(), goto_asmqjmps(), iter_dbt_commands(), list_vars(), on_fcn_delete(), on_fcn_new(), on_fcn_rename(), restore_current_addr(), rz_analysis_aefa(), rz_analysis_function_type_matching_handler(), rz_analysis_function_vars_dis_refs_handler(), rz_analysis_function_xrefs_handler(), rz_analyze_all_consecutive_functions_in_section_handler(), rz_cmd_alias(), rz_cmd_disassemble_recursively_no_function_handler(), rz_cmd_disassembly_all_methods_class_handler(), rz_cmd_disassembly_function_summary_handler(), rz_cmd_disassembly_n_instrs_as_text_json_handler(), rz_cmd_print(), rz_cmd_sizes_of_n_instructions_handler(), rz_core_agraph_print_interactive(), rz_core_analysis_esil_emulate(), rz_core_analysis_esil_init_mem(), rz_core_analysis_everything(), rz_core_analysis_types_propagation(), rz_core_bin_apply_entry(), rz_core_bin_load(), rz_core_block_size(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_lastcmd_repeat(), rz_core_cmd_subst(), rz_core_cmd_subst_i(), rz_core_debug_print_status(), rz_core_disasm_pdi(), rz_core_disasm_pdi_with_buf(), rz_core_file_reopen(), rz_core_graph_print(), rz_core_handle_backwards_disasm(), rz_core_link_stroff(), rz_core_magic(), rz_core_magic_at(), rz_core_print_disasm_instructions(), rz_core_print_disasm_instructions_with_buf(), rz_core_print_disasm_json(), rz_core_seek_and_save(), rz_core_seek_bb_instruction(), rz_core_seek_opcode_backward(), rz_core_serve(), rz_core_shift_block(), rz_core_visual(), rz_core_visual_analysis(), rz_core_visual_classes(), rz_core_visual_cmd(), rz_core_visual_debugtraces(), rz_core_visual_graph(), rz_core_visual_hudclasses(), rz_core_visual_hudstuff(), rz_core_visual_mark_seek(), rz_core_visual_title(), rz_core_visual_view_graph(), rz_core_visual_view_rop(), rz_core_yank(), rz_core_yank_string(), rz_main_rizin(), rz_seek_asz_handler(), seek_check_save(), set_current_seek_state(), variable_rename(), visual_nkey(), and visual_refresh().

◆ rz_core_seek_align()

RZ_API bool rz_core_seek_align ( RzCore core,
ut64  align,
bool  save 
)

Seek to current offset aligned to align.

Parameters
coreRzCore reference
alignValue to align the current offset
saveIf true save the current state in seek history before seeking

Definition at line 274 of file seek.c.

274  {
275  if (!align) {
276  return false;
277  }
278  int diff = core->offset % align;
279  return seek_check_save(core, core->offset - diff, true, save);
280 }
static int save
Definition: main.c:14
static bool seek_check_save(RzCore *core, ut64 addr, bool rb, bool save)
Definition: seek.c:40

References rz_core_t::offset, save, and seek_check_save().

Referenced by rz_seek_asz_handler().

◆ rz_core_seek_analysis_bb()

RZ_API bool rz_core_seek_analysis_bb ( RzCore core,
ut64  addr,
bool  save 
)

Seek to basic block that contains address addr.

Parameters
coreRzCore reference
addrAddress that needs to be in the basicblock
saveIf true save the current state in seek history before seeking

Definition at line 289 of file seek.c.

289  {
291  if (block) {
292  seek_check_save(core, block->addr, false, save);
293  return true;
294  }
295  return false;
296 }
RZ_API RzAnalysisBlock * rz_analysis_find_most_relevant_block_in(RzAnalysis *analysis, ut64 off)
Definition: block.c:997
RzAnalysis * analysis
Definition: rz_core.h:322

References addr, rz_analysis_bb_t::addr, rz_core_t::analysis, rz_analysis_find_most_relevant_block_in(), save, and seek_check_save().

Referenced by rz_seek_basicblock_handler().

◆ rz_core_seek_and_save()

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 .

If rz_core_seek_mark is used to mark a position, that position will be saved in the history, otherwise the current state is used.

Parameters
coreRzCore reference
addrAddress where to move to
rbIf true read the block

Definition at line 101 of file seek.c.

101  {
102  if (!core->seek_history.saved_set) {
103  rz_core_seek_mark(core);
104  }
105  seek_save(core, addr);
106  return rz_core_seek(core, addr, rb);
107 }
static bool seek_save(RzCore *core, ut64 addr)
Definition: seek.c:72
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(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116

References addr, rz_core_seek(), rz_core_seek_mark(), rz_core_seek_history_t::saved_set, rz_core_t::seek_history, and seek_save().

Referenced by __core_visual_gogo(), __handle_mouse_on_panel(), __handleComment(), findNextWord(), follow_ref(), goto_asmqjmps(), rz_core_analysis_bb_seek(), rz_core_visual_cmd(), rz_core_visual_comments(), rz_core_visual_offset(), rz_core_visual_seek_animation(), rz_core_visual_trackflags(), rz_seek_begin_handler(), rz_seek_end_handler(), rz_seek_function_current_handler(), rz_seek_function_handler(), rz_seek_handler(), and seek_check_save().

◆ rz_core_seek_base()

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.

Parameters
coreRzCore reference
hexNew final part of the address (in hex)
saveIf true save the current state in seek history before seeking

Definition at line 171 of file seek.c.

171  {
172  ut64 addr = rz_num_tail(core->num, core->offset, hex);
173  return seek_check_save(core, addr, true, save);
174 }
static const char hex[16]
Definition: print.c:21
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
Definition: unum.c:775
RzNum * num
Definition: rz_core.h:316

References addr, hex, rz_core_t::num, rz_core_t::offset, rz_num_tail(), save, seek_check_save(), and ut64().

Referenced by rz_core_visual_offset(), and rz_seek_base_handler().

◆ rz_core_seek_bb_instruction()

RZ_IPI bool rz_core_seek_bb_instruction ( RzCore core,
int  index 
)

Definition at line 453 of file seek.c.

453  {
455  if (!bb) {
456  RZ_LOG_ERROR("Can't find a basic block for 0x%08" PFMT64x "\n", core->offset);
457  return false;
458  }
459  // handle negative indices
460  if (index < 0) {
461  index = bb->ninstr + index;
462  }
463  if (!(index >= 0 && index < bb->ninstr)) {
464  RZ_LOG_ERROR("The current basic block has %d instructions\n", bb->ninstr);
465  return false;
466  }
467  ut64 inst_addr = rz_analysis_block_get_op_addr(bb, index);
468  return rz_core_seek(core, inst_addr, true);
469 }
RZ_API ut64 rz_analysis_block_get_op_addr(RzAnalysisBlock *block, size_t i)
Definition: block.c:1016
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define PFMT64x
Definition: rz_types.h:393

References rz_core_t::analysis, rz_analysis_bb_t::ninstr, rz_core_t::offset, PFMT64x, rz_analysis_block_get_op_addr(), rz_analysis_find_most_relevant_block_in(), rz_core_seek(), RZ_LOG_ERROR, and ut64().

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_core_cmd_subst_i(), and rz_core_visual_graph().

◆ rz_core_seek_delta()

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.

Parameters
coreRzCore reference
deltaDelta address added to the current offset
saveIf true save the current state in seek history before seeking

Definition at line 152 of file seek.c.

152  {
153  ut64 newaddr;
154  if (delta > 0 && UT64_ADD_OVFCHK(core->offset, (ut64)(delta))) {
155  newaddr = UT64_MAX;
156  } else if (delta < 0 && core->offset < (ut64)RZ_ABS(delta)) {
157  newaddr = 0;
158  } else {
159  newaddr = core->offset + delta;
160  }
161  return seek_check_save(core, newaddr, true, save);
162 }
voidpf uLong offset
Definition: ioapi.h:144
@ RZ_ABS
#define UT64_MAX
Definition: rz_types_base.h:86
#define UT64_ADD_OVFCHK(x, y)
static st64 delta
Definition: vmenus.c:2425

References delta, rz_core_t::offset, RZ_ABS, save, seek_check_save(), ut64(), UT64_ADD_OVFCHK, and UT64_MAX.

Referenced by __direction_disassembly_cb(), __fix_cursor_down(), __fix_cursor_up(), fix_cursor(), rz_core_seek_opcode_forward(), rz_core_visual_cmd(), rz_core_write_at(), rz_seek_blocksize_backward_handler(), rz_seek_blocksize_forward_handler(), and rz_seek_delta_handler().

◆ rz_core_seek_free()

RZ_API void rz_core_seek_free ( RzCore core)

Free seek history data

Definition at line 398 of file seek.c.

398  {
401 }
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61

References rz_core_seek_history_t::redos, rz_vector_fini(), rz_core_t::seek_history, and rz_core_seek_history_t::undos.

Referenced by rz_core_fini().

◆ rz_core_seek_item_free()

RZ_API void rz_core_seek_item_free ( RzCoreSeekItem item)

Definition at line 7 of file seek.c.

7  {
8  free(item);
9 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free().

Referenced by rz_core_seek_list(), rz_line_hist_offset_down(), and rz_line_hist_offset_up().

◆ rz_core_seek_list()

RZ_API RzList* rz_core_seek_list ( RzCore core)

Return the seek history.

The list is composed of some items with negative idx which are Undos items (potentially none), then there is an item with is_current=true that is the current state, followed by some items with positive idx which are Redos items.

Definition at line 411 of file seek.c.

411  {
413  if (!res) {
414  return NULL;
415  }
416 
417  RzCoreSeekItem *it;
418  int i = -rz_vector_len(&core->seek_history.undos);
419  rz_vector_foreach(&core->seek_history.undos, it) {
421  if (!dup) {
422  goto err;
423  }
424  rz_list_append(res, dup);
425  }
426 
427  RzCoreSeekItem *cur = get_current_item(core);
428  if (!cur) {
429  goto err;
430  }
431  rz_list_append(res, cur);
432 
433  i = 1;
436  if (!dup) {
437  goto err;
438  }
439  rz_list_append(res, dup);
440  }
441  return res;
442 
443 err:
444  rz_list_free(res);
445  return NULL;
446 }
static bool err
Definition: armass.c:435
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
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
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
#define rz_vector_foreach_prev(vec, it)
Definition: rz_vector.h:173
static RzCoreSeekItem * dup_seek_history_item(RzCoreSeekItem *item, int i)
Definition: seek.c:339
RZ_API void rz_core_seek_item_free(RzCoreSeekItem *item)
Definition: seek.c:7
static RzCoreSeekItem * get_current_item(RzCore *core)
Definition: seek.c:328

References dup, dup_seek_history_item(), err, get_current_item(), i, NULL, rz_core_seek_history_t::redos, rz_core_seek_item_free(), rz_list_append(), rz_list_free(), rz_list_newf(), rz_vector_foreach, rz_vector_foreach_prev, rz_vector_len(), rz_core_t::seek_history, and rz_core_seek_history_t::undos.

Referenced by rz_seek_history_list_handler().

◆ rz_core_seek_mark()

RZ_API bool rz_core_seek_mark ( RzCore core)

Mark current state (offset+cursor) as the next state to save in history.

The saving can be disabled if eval var cfg.seek.silent is set to true. The state saved here is actually saved in history once rz_core_seek_and_save is called (or other functions with the save argument set to true).

Parameters
coreRzCore reference

Definition at line 57 of file seek.c.

57  {
58  if (!rz_config_get_i(core->config, "cfg.seek.silent")) {
60  core->seek_history.saved_set = true;
61  return true;
62  }
63  core->seek_history.saved_set = false;
64  return false;
65 }

References rz_core_t::config, get_current_seek_state(), rz_config_get_i(), rz_core_seek_history_t::saved_item, rz_core_seek_history_t::saved_set, and rz_core_t::seek_history.

Referenced by rz_core_seek_and_save(), rz_core_seek_opcode_forward(), rz_seek_asz_handler(), and rz_seek_handler().

◆ rz_core_seek_next()

RZ_API bool rz_core_seek_next ( RzCore core,
const char *  type,
bool  save 
)

Seek to the next type of item from current offset.

Parameters
coreRzCore reference
typeType of next "item" to seek to (could be "opc", "fun", "hit", "flag")
saveIf true save the current state in seek history before seeking

Definition at line 203 of file seek.c.

203  {
204  RzListIter *iter;
205  ut64 next = UT64_MAX;
206  if (strstr(type, "opc")) {
207  RzAnalysisOp aop;
208  if (rz_analysis_op(core->analysis, &aop, core->offset, core->block, core->blocksize, RZ_ANALYSIS_OP_MASK_BASIC) > 0) {
209  next = core->offset + aop.size;
210  } else {
211  eprintf("Invalid opcode\n");
212  }
213  } else if (strstr(type, "fun")) {
214  RzAnalysisFunction *fcni;
215  rz_list_foreach (core->analysis->fcns, iter, fcni) {
216  if (fcni->addr < next && fcni->addr > core->offset) {
217  next = fcni->addr;
218  }
219  }
220  } else if (strstr(type, "hit")) {
221  const char *pfx = rz_config_get(core->config, "search.prefix");
222  struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = true };
223  rz_flag_foreach_prefix(core->flags, pfx, -1, seek_flag_offset, &u);
224  } else { // flags
225  struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = true };
227  }
228  if (next == UT64_MAX) {
229  return false;
230  }
231  return seek_check_save(core, next, true, save);
232 }
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
Definition: flag.c:804
RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user)
Definition: flag.c:800
int type
Definition: mipsasm.c:17
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
static bool seek_flag_offset(RzFlagItem *fi, void *user)
Definition: seek.c:182
RzList * fcns
Definition: rz_analysis.h:565
ut8 * block
Definition: rz_core.h:305
RzFlag * flags
Definition: rz_core.h:330
ut32 blocksize
Definition: rz_core.h:303
ut64 * next
Definition: seek.c:178

References rz_analysis_function_t::addr, rz_core_t::analysis, rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, eprintf, rz_analysis_t::fcns, rz_core_t::flags, seek_flag_offset_t::next, seek_flag_offset_t::offset, rz_core_t::offset, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_config_get(), rz_flag_foreach(), rz_flag_foreach_prefix(), save, seek_check_save(), seek_flag_offset(), rz_analysis_op_t::size, type, ut64(), and UT64_MAX.

Referenced by __panels_process(), rz_core_visual_cmd(), rz_core_visual_graph(), and rz_seek_next_handler().

◆ rz_core_seek_opt()

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.

Parameters
coreRzCore reference
addrAddress where to move to
rbIf true read the block
saveIf true save the current state in seek history before seeking

Definition at line 141 of file seek.c.

141  {
142  return seek_check_save(core, addr, rb, save);
143 }

References addr, save, and seek_check_save().

Referenced by loadGP(), rz_core_seek_opcode_backward(), and rz_core_seek_to_register().

◆ rz_core_seek_peek()

RZ_API RzCoreSeekItem* rz_core_seek_peek ( RzCore core,
int  idx 
)

Return a element in the undo/redo list.

The element is not removed from the list nor it is restored as the current state. Useful if you want to inspect the undo history. The object shall be freed by the caller.

Parameters
coreReference to RzCore
idxIndex of the element. 0 references the current seek, <0 are undos, >0 redos

Definition at line 361 of file seek.c.

361  {
362  if (idx == 0) {
363  return get_current_item(core);
364  } else if (idx < 0) {
365  RzVector *vundo = &core->seek_history.undos;
366  size_t i = RZ_ABS(idx) - 1;
367  size_t len = rz_vector_len(vundo);
368  if (i >= len) {
369  return NULL;
370  }
371  RzCoreSeekItem *vel = (RzCoreSeekItem *)rz_vector_index_ptr(vundo, len - i - 1);
372  return dup_seek_history_item(vel, idx);
373  } else {
374  RzVector *vredo = &core->seek_history.redos;
375  size_t i = RZ_ABS(idx) - 1;
376  size_t len = rz_vector_len(vredo);
377  if (i >= len) {
378  return NULL;
379  }
380  RzCoreSeekItem *vel = (RzCoreSeekItem *)rz_vector_index_ptr(vredo, len - i - 1);
381  return dup_seek_history_item(vel, idx);
382  }
383 }
size_t len
Definition: 6502dis.c:15
int idx
Definition: setup.py:197

References dup_seek_history_item(), get_current_item(), i, setup::idx, len, NULL, rz_core_seek_history_t::redos, RZ_ABS, rz_vector_index_ptr(), rz_vector_len(), rz_core_t::seek_history, and rz_core_seek_history_t::undos.

Referenced by rz_line_hist_offset_down(), and rz_line_hist_offset_up().

◆ rz_core_seek_prev()

RZ_API bool rz_core_seek_prev ( RzCore core,
const char *  type,
bool  save 
)

Seek to the previous type of item from current offset.

Parameters
coreRzCore reference
typeType of previous "item" to seek to (could be "opc", "fun", "hit", "flag")
saveIf true save the current state in seek history before seeking

Definition at line 241 of file seek.c.

241  {
242  RzListIter *iter;
243  ut64 next = 0;
244  if (strstr(type, "opc")) {
245  eprintf("TODO: rz_core_seek_prev (opc)\n");
246  } else if (strstr(type, "fun")) {
247  RzAnalysisFunction *fcni;
248  rz_list_foreach (core->analysis->fcns, iter, fcni) {
249  if (fcni->addr > next && fcni->addr < core->offset) {
250  next = fcni->addr;
251  }
252  }
253  } else if (strstr(type, "hit")) {
254  const char *pfx = rz_config_get(core->config, "search.prefix");
255  struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = false };
256  rz_flag_foreach_prefix(core->flags, pfx, -1, seek_flag_offset, &u);
257  } else { // flags
258  struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = false };
260  }
261  if (next == 0) {
262  return false;
263  }
264  return seek_check_save(core, next, true, save);
265 }

References rz_analysis_function_t::addr, rz_core_t::analysis, rz_core_t::config, eprintf, rz_analysis_t::fcns, rz_core_t::flags, seek_flag_offset_t::next, seek_flag_offset_t::offset, rz_core_t::offset, rz_config_get(), rz_flag_foreach(), rz_flag_foreach_prefix(), save, seek_check_save(), seek_flag_offset(), type, and ut64().

Referenced by __panels_process(), rz_core_visual_cmd(), rz_core_visual_graph(), and rz_seek_prev_handler().

◆ rz_core_seek_redo()

RZ_API bool rz_core_seek_redo ( RzCore core)

Redo the last undone entry in the seek history

Definition at line 316 of file seek.c.

316  {
317  if (rz_vector_empty(&core->seek_history.redos)) {
318  return false;
319  }
320  RzCoreSeekItem elem;
321  get_current_seek_state(core, &elem);
322  rz_vector_push(&core->seek_history.undos, &elem);
323  rz_vector_pop(&core->seek_history.redos, &elem);
324  set_current_seek_state(core, &elem);
325  return true;
326 }
RZ_API void rz_vector_pop(RzVector *vec, void *into)
Definition: vector.c:184
static void set_current_seek_state(RzCore *core, RzCoreSeekItem *elem)
Definition: seek.c:17

References get_current_seek_state(), rz_core_seek_history_t::redos, rz_vector_empty(), rz_vector_pop(), rz_vector_push(), rz_core_t::seek_history, set_current_seek_state(), and rz_core_seek_history_t::undos.

Referenced by rz_core_visual_graph(), rz_core_visual_seek_animation_redo(), and rz_seek_redo_handler().

◆ rz_core_seek_reset()

RZ_API void rz_core_seek_reset ( RzCore core)

Remove all seek history entries

Definition at line 388 of file seek.c.

388  {
393 }
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:33

References NULL, rz_core_seek_history_t::redos, rz_vector_fini(), rz_vector_init(), rz_core_t::seek_history, and rz_core_seek_history_t::undos.

Referenced by rz_core_init(), and rz_seek_undo_reset_handler().

◆ rz_core_seek_save()

RZ_API bool rz_core_seek_save ( RzCore core)

Save last marked position, if any, in the seek history.

Parameters
coreRzCore reference

Definition at line 87 of file seek.c.

87  {
88  return seek_save(core, core->offset);
89 }

References rz_core_t::offset, and seek_save().

Referenced by rz_core_seek_opcode_forward().

◆ rz_core_seek_undo()

RZ_API bool rz_core_seek_undo ( RzCore core)

Undo the last entry in the seek history

Definition at line 301 of file seek.c.

301  {
302  if (rz_vector_empty(&core->seek_history.undos)) {
303  return false;
304  }
305  RzCoreSeekItem elem;
306  get_current_seek_state(core, &elem);
307  rz_vector_push(&core->seek_history.redos, &elem);
308  rz_vector_pop(&core->seek_history.undos, &elem);
309  set_current_seek_state(core, &elem);
310  return true;
311 }

References get_current_seek_state(), rz_core_seek_history_t::redos, rz_vector_empty(), rz_vector_pop(), rz_vector_push(), rz_core_t::seek_history, set_current_seek_state(), and rz_core_seek_history_t::undos.

Referenced by rz_core_analysis_everything(), rz_core_visual_graph(), rz_core_visual_seek_animation_undo(), and rz_seek_undo_handler().

◆ seek_check_save()

static bool seek_check_save ( RzCore core,
ut64  addr,
bool  rb,
bool  save 
)
static

Definition at line 40 of file seek.c.

40  {
41  if (save) {
42  return rz_core_seek_and_save(core, addr, rb);
43  } else {
44  return rz_core_seek(core, addr, rb);
45  }
46 }
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

References addr, rz_core_seek(), rz_core_seek_and_save(), and save.

Referenced by rz_core_seek_align(), rz_core_seek_analysis_bb(), rz_core_seek_base(), rz_core_seek_delta(), rz_core_seek_next(), rz_core_seek_opt(), and rz_core_seek_prev().

◆ seek_flag_offset()

static bool seek_flag_offset ( RzFlagItem fi,
void *  user 
)
static

Definition at line 182 of file seek.c.

182  {
183  struct seek_flag_offset_t *u = (struct seek_flag_offset_t *)user;
184  if (u->is_next) {
185  if (fi->offset < *u->next && fi->offset > u->offset) {
186  *u->next = fi->offset;
187  }
188  } else {
189  if (fi->offset > *u->next && fi->offset < u->offset) {
190  *u->next = fi->offset;
191  }
192  }
193  return true;
194 }
ut64 offset
Definition: rz_flag.h:38

References seek_flag_offset_t::is_next, seek_flag_offset_t::next, seek_flag_offset_t::offset, and rz_flag_item_t::offset.

Referenced by rz_core_seek_next(), and rz_core_seek_prev().

◆ seek_save()

static bool seek_save ( RzCore core,
ut64  addr 
)
static

Definition at line 72 of file seek.c.

72  {
73  if (need_add2history(core, addr)) {
74  add_seek_history(core);
75  core->seek_history.saved_set = false;
76  return true;
77  }
78  core->seek_history.saved_set = false;
79  return false;
80 }
static bool need_add2history(RzCore *core, ut64 addr)
Definition: seek.c:67
static void add_seek_history(RzCore *core)
Definition: seek.c:22

References add_seek_history(), addr, need_add2history(), rz_core_seek_history_t::saved_set, and rz_core_t::seek_history.

Referenced by rz_core_seek_and_save(), and rz_core_seek_save().

◆ set_current_seek_state()

static void set_current_seek_state ( RzCore core,
RzCoreSeekItem elem 
)
static

Definition at line 17 of file seek.c.

17  {
18  rz_core_seek(core, elem->offset, true);
19  core->print->cur = elem->cursor;
20 }

References rz_print_t::cur, rz_core_seek_undo_t::cursor, rz_core_seek_undo_t::offset, rz_core_t::print, and rz_core_seek().

Referenced by rz_core_seek_redo(), and rz_core_seek_undo().