From 30c26ec1043abb602cf55f65dea161a10f02c76c Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 3 Dec 2018 16:36:26 +0100 Subject: [PATCH] Some more improvements for the visual xrefs (fix undo seek and more) --- libr/core/core.c | 8 ++++---- libr/core/visual.c | 35 ++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libr/core/core.c b/libr/core/core.c index 392ca13d02..bd8e26740d 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -2710,12 +2710,12 @@ R_API int r_core_block_size(RCore *core, int bsize) { } R_API int r_core_seek_align(RCore *core, ut64 align, int times) { - int diff, inc = (times >= 0)? 1: -1; + int inc = (times >= 0)? 1: -1; ut64 seek = core->offset; if (!align) { return false; } - diff = core->offset%align; + int diff = core->offset % align; if (!times) { diff = -diff; } else if (diff) { @@ -2730,12 +2730,12 @@ R_API int r_core_seek_align(RCore *core, ut64 align, int times) { } while ((times*inc) > 0) { times -= inc; - diff += align*inc; + diff += (align * inc); } if (diff < 0 && -diff > seek) { seek = diff = 0; } - return r_core_seek (core, seek+diff, 1); + return r_core_seek (core, seek + diff, 1); } R_API char *r_core_op_str(RCore *core, ut64 addr) { diff --git a/libr/core/visual.c b/libr/core/visual.c index a83407f39d..9e619c2b9e 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -1028,14 +1028,15 @@ static int prevopsz(RCore *core, ut64 addr) { return addr - prev_addr; } -static int follow_ref(RCore *core, RList *xrefs, int choice) { +static int follow_ref(RCore *core, RList *xrefs, int choice, int xref) { RAnalRef *refi = r_list_get_n (xrefs, choice); if (refi) { if (core->print->cur_enabled) { core->print->cur = 0; } - r_io_sundo_push (core->io, refi->addr, r_print_get_cursor (core->print)); - r_core_seek (core, refi->addr, 1); + r_io_sundo_push (core->io, core->offset, -1); + ut64 addr = xref? refi->at: refi->addr; + r_core_seek (core, addr, true); return 1; } return 0; @@ -1064,18 +1065,18 @@ repeat: if (xrefsMode) { RAnalFunction *fun = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fun) { - if (xref) { + if (xref) { // function xrefs xrefs = r_anal_fcn_get_xrefs (core->anal, fun); - } else { + } else { // functon refs xrefs = r_anal_fcn_get_refs (core->anal, fun); } } else { xrefs = NULL; } } else { - if (xref) { + if (xref) { // address xrefs xrefs = r_anal_xrefs_get (core->anal, addr); - } else { + } else { // address refs xrefs = r_anal_refs_get (core->anal, addr); } } @@ -1214,6 +1215,7 @@ repeat: ch = r_cons_arrow_to_hjkl (ch); if (ch == ':') { r_core_visual_prompt_input (core); + goto repeat; } else if (ch == '?') { r_cons_clear00 (); r_cons_printf ("Usage: Visual Xrefs\n" @@ -1230,12 +1232,6 @@ repeat: r_cons_flush (); r_cons_any_key (NULL); goto repeat; - } else if (ch == '<') { - xrefsMode = false; - goto repeat; - } else if (ch == '>') { - xrefsMode = true; - goto repeat; } else if (ch == 9) { // TAB xrefsMode = !xrefsMode; goto repeat; @@ -1251,11 +1247,13 @@ repeat: printMode = lastPrintMode; } goto repeat; - } else if (ch == 'x') { + } else if (ch == 'x' || ch == '<') { + xrefsMode = !xrefsMode; xref = true; goto repeat; - } else if (ch == 'X') { + } else if (ch == 'X' || ch == '>') { xref = false; + xrefsMode = !xrefsMode; goto repeat; } else if (ch == 'J') { skip += 10; @@ -1266,6 +1264,9 @@ repeat: } else if (ch == 'G') { skip = 9999; goto repeat; + } else if (ch == '.') { + skip = 0; + goto repeat; } else if (ch == 'j') { skip++; goto repeat; @@ -1279,9 +1280,9 @@ repeat: } goto repeat; } else if (ch == ' ' || ch == '\n' || ch == '\r' || ch == 'l') { - ret = follow_ref (core, xrefs, skip); + ret = follow_ref (core, xrefs, skip, xref); } else if (IS_DIGIT (ch)) { - ret = follow_ref (core, xrefs, ch - 0x30); + ret = follow_ref (core, xrefs, ch - 0x30, xref); } else if (ch != 'q' && ch != 'Q' && ch != 'h') { goto repeat; }