2020-03-10 09:22:29 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2015-07-25 15:22:43 +00:00
|
|
|
#include <r_core.h>
|
2018-03-08 23:33:33 +00:00
|
|
|
#include <r_cons.h>
|
2015-10-14 21:50:16 +00:00
|
|
|
|
2018-12-28 18:40:54 +00:00
|
|
|
#define NPF 5
|
|
|
|
#define PIDX (R_ABS (core->printidx % NPF))
|
|
|
|
|
2020-07-22 11:37:31 +00:00
|
|
|
static void visual_refresh(RCore *core);
|
|
|
|
|
2015-09-28 00:04:08 +00:00
|
|
|
static int obs = 0;
|
2011-05-21 12:27:46 +00:00
|
|
|
static int blocksize = 0;
|
2018-12-28 18:40:54 +00:00
|
|
|
static bool autoblocksize = true;
|
2017-12-16 01:23:53 +00:00
|
|
|
static int disMode = 0;
|
2018-12-28 18:40:54 +00:00
|
|
|
static int hexMode = 0;
|
|
|
|
static int printMode = 0;
|
2017-12-18 01:44:51 +00:00
|
|
|
static bool snowMode = false;
|
|
|
|
static RList *snows = NULL;
|
2020-07-22 11:37:31 +00:00
|
|
|
static int color = 1;
|
|
|
|
static int debug = 1;
|
|
|
|
static int zoom = 0;
|
|
|
|
|
2017-12-18 01:44:51 +00:00
|
|
|
typedef struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
} Snow;
|
|
|
|
|
2017-03-24 00:23:25 +00:00
|
|
|
#define KEY_ALTQ 0xc5
|
|
|
|
|
2018-12-28 18:40:54 +00:00
|
|
|
static const char *printfmtSingle[NPF] = {
|
|
|
|
"xc", // HEXDUMP
|
|
|
|
"pd $r", // ASSEMBLY
|
|
|
|
"pxw 64@r:SP;dr=;pd $r", // DEBUGGER
|
|
|
|
"prc", // OVERVIEW
|
|
|
|
"pss", // PC// copypasteable views
|
2012-06-30 18:51:18 +00:00
|
|
|
};
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2019-01-05 10:51:46 +00:00
|
|
|
static const char *printfmtColumns[NPF] = {
|
|
|
|
"pCx", // HEXDUMP // + pCw
|
|
|
|
"pCd $r-1", // ASSEMBLY
|
|
|
|
"pCD", // DEBUGGER
|
|
|
|
"pCA", // OVERVIEW
|
|
|
|
"pCc", // PC// copypasteable views
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-28 18:40:54 +00:00
|
|
|
// to print the stack in the debugger view
|
2019-03-05 10:08:41 +00:00
|
|
|
#define PRINT_HEX_FORMATS 10
|
2018-12-29 10:17:56 +00:00
|
|
|
#define PRINT_3_FORMATS 2
|
2019-05-07 10:01:26 +00:00
|
|
|
#define PRINT_4_FORMATS 7
|
2018-12-29 10:17:56 +00:00
|
|
|
#define PRINT_5_FORMATS 8
|
2018-12-28 18:40:54 +00:00
|
|
|
|
2019-07-03 22:59:27 +00:00
|
|
|
static int currentFormat = 0;
|
|
|
|
static int current0format = 0;
|
2018-10-31 10:34:13 +00:00
|
|
|
static const char *printHexFormats[PRINT_HEX_FORMATS] = {
|
2019-03-05 10:08:41 +00:00
|
|
|
"px", "pxa", "pxr", "prx", "pxb", "pxh", "pxw", "pxq", "pxd", "pxr",
|
2018-10-31 10:34:13 +00:00
|
|
|
};
|
2018-12-28 18:40:54 +00:00
|
|
|
static int current3format = 0;
|
2018-12-29 10:17:56 +00:00
|
|
|
static const char *print3Formats[PRINT_3_FORMATS] = { // not used at all. its handled by the pd format
|
|
|
|
"pxw 64@r:SP;dr=;pd $r", // DEBUGGER
|
2019-01-05 10:51:46 +00:00
|
|
|
"pCD"
|
2018-12-28 18:40:54 +00:00
|
|
|
};
|
|
|
|
static int current4format = 0;
|
|
|
|
static const char *print4Formats[PRINT_4_FORMATS] = {
|
2019-05-07 10:01:26 +00:00
|
|
|
"prc", "prc=a", "pxAv", "pxx", "p=e $r-2", "pq 64", "pk 64"
|
2018-12-28 18:40:54 +00:00
|
|
|
};
|
|
|
|
static int current5format = 0;
|
|
|
|
static const char *print5Formats[PRINT_5_FORMATS] = {
|
2018-12-29 10:17:56 +00:00
|
|
|
"pca", "pcA", "p8", "pcc", "pss", "pcp", "pcd", "pcj"
|
2018-12-28 18:40:54 +00:00
|
|
|
};
|
2019-09-01 14:27:11 +00:00
|
|
|
|
|
|
|
R_API void r_core_visual_applyHexMode(RCore *core, int hexMode) {
|
2019-10-08 15:44:38 +00:00
|
|
|
currentFormat = R_ABS(hexMode) % PRINT_HEX_FORMATS;
|
2019-07-03 22:59:27 +00:00
|
|
|
switch (currentFormat) {
|
2019-10-08 15:44:38 +00:00
|
|
|
case 0: /* px */
|
|
|
|
case 3: /* prx */
|
|
|
|
case 6: /* pxw */
|
|
|
|
case 9: /* pxr */
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "hex.compact", "false");
|
2018-12-30 11:08:20 +00:00
|
|
|
r_config_set (core->config, "hex.comments", "true");
|
2018-12-29 10:17:56 +00:00
|
|
|
break;
|
2019-10-08 15:44:38 +00:00
|
|
|
case 1: /* pxa */
|
|
|
|
case 4: /* pxb */
|
|
|
|
case 7: /* pxq */
|
2018-12-31 00:21:03 +00:00
|
|
|
r_config_set (core->config, "hex.compact", "true");
|
2018-12-30 11:08:20 +00:00
|
|
|
r_config_set (core->config, "hex.comments", "true");
|
2018-12-29 10:17:56 +00:00
|
|
|
break;
|
2019-10-08 15:44:38 +00:00
|
|
|
case 2: /* pxr */
|
|
|
|
case 5: /* pxh */
|
|
|
|
case 8: /* pxd */
|
2018-12-31 00:21:03 +00:00
|
|
|
r_config_set (core->config, "hex.compact", "false");
|
2018-12-30 11:08:20 +00:00
|
|
|
r_config_set (core->config, "hex.comments", "false");
|
2018-12-29 10:17:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 10:08:41 +00:00
|
|
|
R_API void r_core_visual_toggle_decompiler_disasm(RCore *core, bool for_graph, bool reset) {
|
|
|
|
static RConfigHold *hold = NULL; // should be a tab-specific var
|
2019-03-04 00:24:43 +00:00
|
|
|
if (hold) {
|
|
|
|
r_config_hold_restore (hold);
|
|
|
|
r_config_hold_free (hold);
|
|
|
|
hold = NULL;
|
2019-03-05 10:08:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (reset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hold = r_config_hold_new (core->config);
|
|
|
|
r_config_hold_s (hold, "asm.hint.pos", "asm.cmt.col", "asm.offset", "asm.lines",
|
2019-06-16 20:58:48 +00:00
|
|
|
"asm.indent", "asm.bytes", "asm.comments", "asm.dwarf", "asm.usercomments", "asm.instr", NULL);
|
2019-03-05 10:08:41 +00:00
|
|
|
if (for_graph) {
|
2019-06-19 11:51:19 +00:00
|
|
|
r_config_set (core->config, "asm.hint.pos", "-2");
|
2019-03-05 10:08:41 +00:00
|
|
|
r_config_set (core->config, "asm.lines", "false");
|
|
|
|
r_config_set (core->config, "asm.indent", "false");
|
2019-03-04 00:24:43 +00:00
|
|
|
} else {
|
2019-03-05 10:08:41 +00:00
|
|
|
r_config_set (core->config, "asm.hint.pos", "0");
|
|
|
|
r_config_set (core->config, "asm.indent", "true");
|
|
|
|
r_config_set (core->config, "asm.lines", "true");
|
2019-03-04 00:24:43 +00:00
|
|
|
}
|
2019-03-05 10:08:41 +00:00
|
|
|
r_config_set (core->config, "asm.cmt.col", "0");
|
|
|
|
r_config_set (core->config, "asm.offset", "false");
|
2019-06-16 20:58:48 +00:00
|
|
|
r_config_set (core->config, "asm.dwarf", "true");
|
2019-03-05 10:08:41 +00:00
|
|
|
r_config_set (core->config, "asm.bytes", "false");
|
|
|
|
r_config_set (core->config, "asm.comments", "false");
|
|
|
|
r_config_set (core->config, "asm.usercomments", "true");
|
|
|
|
r_config_set (core->config, "asm.instr", "false");
|
2019-03-04 00:24:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-01 18:26:25 +00:00
|
|
|
static void setcursor(RCore *core, bool cur) {
|
|
|
|
int flags = core->print->flags; // wtf
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
flags |= R_PRINT_FLAGS_CURSOR;
|
|
|
|
} else {
|
|
|
|
flags &= ~(R_PRINT_FLAGS_CURSOR);
|
|
|
|
}
|
|
|
|
core->print->cur_enabled = cur;
|
|
|
|
if (core->print->cur == -1) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
}
|
|
|
|
r_print_set_flags (core->print, flags);
|
|
|
|
core->print->col = core->print->cur_enabled? 1: 0;
|
|
|
|
}
|
|
|
|
|
2019-04-19 14:46:54 +00:00
|
|
|
R_API void r_core_visual_applyDisMode(RCore *core, int disMode) {
|
2019-07-03 22:59:27 +00:00
|
|
|
currentFormat = R_ABS(disMode) % 5;
|
|
|
|
switch (currentFormat) {
|
2018-12-29 10:17:56 +00:00
|
|
|
case 0:
|
|
|
|
r_config_set (core->config, "asm.pseudo", "false");
|
|
|
|
r_config_set (core->config, "asm.bytes", "true");
|
|
|
|
r_config_set (core->config, "asm.esil", "false");
|
|
|
|
r_config_set (core->config, "emu.str", "false");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.emu", "false");
|
2018-12-29 10:17:56 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
r_config_set (core->config, "asm.pseudo", "false");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.bytes", "true");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "asm.esil", "false");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.emu", "false");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "emu.str", "true");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
r_config_set (core->config, "asm.pseudo", "true");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.bytes", "true");
|
|
|
|
r_config_set (core->config, "asm.esil", "true");
|
|
|
|
r_config_set (core->config, "emu.str", "true");
|
|
|
|
r_config_set (core->config, "asm.emu", "true");
|
2018-12-29 10:17:56 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
r_config_set (core->config, "asm.pseudo", "false");
|
|
|
|
r_config_set (core->config, "asm.bytes", "false");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.esil", "false");
|
|
|
|
r_config_set (core->config, "asm.emu", "false");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "emu.str", "true");
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.pseudo", "true");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "asm.bytes", "false");
|
2019-01-03 23:57:01 +00:00
|
|
|
r_config_set (core->config, "asm.esil", "false");
|
|
|
|
r_config_set (core->config, "asm.emu", "false");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_config_set (core->config, "emu.str", "true");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 15:44:38 +00:00
|
|
|
static void nextPrintCommand(void) {
|
2019-07-03 22:59:27 +00:00
|
|
|
current0format++;
|
|
|
|
current0format %= PRINT_HEX_FORMATS;
|
|
|
|
currentFormat = current0format;
|
2018-10-31 10:34:13 +00:00
|
|
|
}
|
2019-07-03 22:59:27 +00:00
|
|
|
|
2019-10-08 15:44:38 +00:00
|
|
|
static void prevPrintCommand(void) {
|
2019-07-03 22:59:27 +00:00
|
|
|
current0format--;
|
|
|
|
if (current0format < 0) {
|
|
|
|
current0format = 0;
|
2018-10-31 10:34:13 +00:00
|
|
|
}
|
2019-07-03 22:59:27 +00:00
|
|
|
currentFormat = current0format;
|
2018-10-31 10:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *stackPrintCommand(RCore *core) {
|
2019-07-03 22:59:27 +00:00
|
|
|
if (current0format == 0) {
|
2018-10-31 10:34:13 +00:00
|
|
|
if (r_config_get_i (core->config, "dbg.slow")) {
|
|
|
|
return "pxr";
|
|
|
|
}
|
|
|
|
if (r_config_get_i (core->config, "stack.bytes")) {
|
|
|
|
return "px";
|
|
|
|
}
|
2020-05-12 23:28:23 +00:00
|
|
|
switch (core->rasm->bits) {
|
2018-10-31 10:34:13 +00:00
|
|
|
case 64: return "pxq"; break;
|
|
|
|
case 32: return "pxw"; break;
|
|
|
|
}
|
|
|
|
return "px";
|
|
|
|
}
|
2019-07-03 22:59:27 +00:00
|
|
|
return printHexFormats[current0format % PRINT_HEX_FORMATS];
|
2018-10-31 10:34:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 09:46:23 +00:00
|
|
|
static const char *__core_visual_print_command(RCore *core) {
|
2019-02-09 11:29:48 +00:00
|
|
|
if (core->visual.tabs) {
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
|
|
|
if (tab && tab->name[0] == ':') {
|
|
|
|
return tab->name + 1;
|
|
|
|
}
|
|
|
|
}
|
2019-01-05 10:51:46 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.dumpcols")) {
|
2019-03-22 19:46:37 +00:00
|
|
|
free (core->stkcmd);
|
2020-10-30 11:30:42 +00:00
|
|
|
core->stkcmd = r_str_new (stackPrintCommand (core));
|
2019-01-05 10:51:46 +00:00
|
|
|
return printfmtColumns[PIDX];
|
|
|
|
}
|
|
|
|
return printfmtSingle[PIDX];
|
|
|
|
}
|
2016-11-20 23:19:15 +00:00
|
|
|
|
2020-07-22 11:37:31 +00:00
|
|
|
static bool __core_visual_gogo(RCore *core, int ch) {
|
2019-03-06 10:14:23 +00:00
|
|
|
RIOMap *map;
|
|
|
|
int ret = -1;
|
|
|
|
switch (ch) {
|
|
|
|
case 'g':
|
|
|
|
if (core->io->va) {
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
2020-04-07 10:43:41 +00:00
|
|
|
if (!map && !r_pvector_empty (&core->io->maps)) {
|
|
|
|
map = r_pvector_at (&core->io->maps, r_pvector_len (&core->io->maps) - 1);
|
2019-03-06 10:14:23 +00:00
|
|
|
}
|
|
|
|
if (map) {
|
2020-12-08 14:57:08 +00:00
|
|
|
r_core_seek (core, r_io_map_begin (map), true);
|
2019-03-06 10:14:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, 0, true);
|
2019-03-06 10:14:23 +00:00
|
|
|
}
|
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
return true;
|
|
|
|
case 'G':
|
|
|
|
map = r_io_map_get (core->io, core->offset);
|
2020-04-07 10:43:41 +00:00
|
|
|
if (!map && !r_pvector_empty (&core->io->maps)) {
|
|
|
|
map = r_pvector_at (&core->io->maps, 0);
|
2019-03-06 10:14:23 +00:00
|
|
|
}
|
|
|
|
if (map) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
int scr_rows;
|
|
|
|
if (!p->consbind.get_size) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void)p->consbind.get_size (&scr_rows);
|
2020-04-12 18:45:24 +00:00
|
|
|
ut64 scols = r_config_get_i (core->config, "hex.cols");
|
2020-12-08 14:57:08 +00:00
|
|
|
ret = r_core_seek (core, r_io_map_end (map) - (scr_rows - 2) * scols, true);
|
2019-03-06 10:14:23 +00:00
|
|
|
}
|
|
|
|
if (ret != -1) {
|
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-24 17:10:10 +00:00
|
|
|
static const char *help_visual[] = {
|
|
|
|
"?", "full help",
|
|
|
|
"!", "enter panels",
|
|
|
|
"a", "code analysis",
|
|
|
|
"c", "toggle cursor",
|
|
|
|
"d", "debugger / emulator",
|
|
|
|
"e", "toggle configurations",
|
|
|
|
"i", "insert / write",
|
|
|
|
"m", "moving around (seeking)",
|
|
|
|
"p", "print commands and modes",
|
|
|
|
"v", "view management",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-07-04 08:50:00 +00:00
|
|
|
static const char *help_msg_visual[] = {
|
2019-01-02 01:09:31 +00:00
|
|
|
"?", "show visual help menu",
|
|
|
|
"??", "show this help",
|
2019-03-16 09:20:20 +00:00
|
|
|
"$", "set the program counter to the current offset + cursor",
|
2020-06-25 00:55:48 +00:00
|
|
|
"&", "rotate asm.bits between 8, 16, 32 and 64 applying hints",
|
2018-07-04 08:50:00 +00:00
|
|
|
"%", "in cursor mode finds matching pair, otherwise toggle autoblocksz",
|
2020-01-27 06:43:47 +00:00
|
|
|
"^", "seek to the beginning of the function",
|
2018-07-04 08:50:00 +00:00
|
|
|
"!", "enter into the visual panels mode",
|
2018-12-29 10:17:56 +00:00
|
|
|
"TAB", "switch to the next print mode (or element in cursor mode)",
|
2018-07-04 08:50:00 +00:00
|
|
|
"_", "enter the flag/comment/functions/.. hud (same as VF_)",
|
|
|
|
"=", "set cmd.vprompt (top row)",
|
|
|
|
"|", "set cmd.cprompt (right column)",
|
|
|
|
".", "seek to program counter",
|
2019-03-04 00:24:43 +00:00
|
|
|
"#", "toggle decompiler comments in disasm (see pdd* from r2dec)",
|
2018-07-04 08:50:00 +00:00
|
|
|
"\\", "toggle visual split mode",
|
|
|
|
"\"", "toggle the column mode (uses pC..)",
|
|
|
|
"/", "in cursor mode search in current block",
|
|
|
|
"(", "toggle snow",
|
|
|
|
")", "toggle emu.str",
|
|
|
|
":cmd", "run radare command",
|
|
|
|
";[-]cmt", "add/remove comment",
|
|
|
|
"0", "seek to beginning of current function",
|
|
|
|
"[1-9]", "follow jmp/call identified by shortcut (like ;[1])",
|
|
|
|
",file", "add a link to the text file",
|
|
|
|
"/*+-[]", "change block size, [] = resize hex.cols",
|
2018-11-15 02:01:26 +00:00
|
|
|
"<,>", "seek aligned to block size (in cursor slurp or dump files)",
|
2018-07-04 08:50:00 +00:00
|
|
|
"a/A", "(a)ssemble code, visual (A)ssembler",
|
2019-03-20 01:01:17 +00:00
|
|
|
"b", "browse evals, symbols, flags, mountpoints, evals, classes, ...",
|
2018-07-04 08:50:00 +00:00
|
|
|
"B", "toggle breakpoint",
|
|
|
|
"c/C", "toggle (c)ursor and (C)olors",
|
|
|
|
"d[f?]", "define function, data, code, ..",
|
|
|
|
"D", "enter visual diff mode (set diff.from/to)",
|
|
|
|
"f/F", "set/unset or browse flags. f- to unset, F to browse, ..",
|
|
|
|
"hjkl", "move around (or HJKL) (left-down-up-right)",
|
|
|
|
"i", "insert hex or string (in hexdump) use tab to toggle",
|
|
|
|
"I", "insert hexpair block ",
|
|
|
|
"mK/'K", "mark/go to Key (any key)",
|
|
|
|
"n/N", "seek next/prev function/flag/hit (scr.nkey)",
|
2019-04-14 22:09:18 +00:00
|
|
|
"g", "go/seek to given offset (g[g/G]<enter> to seek begin/end of file)",
|
2018-07-04 08:50:00 +00:00
|
|
|
"O", "toggle asm.pseudo and asm.esil",
|
|
|
|
"p/P", "rotate print modes (hex, disasm, debug, words, buf)",
|
|
|
|
"q", "back to radare shell",
|
2019-04-16 16:42:30 +00:00
|
|
|
"r", "toggle callhints/jmphints/leahints",
|
2018-07-04 08:50:00 +00:00
|
|
|
"R", "randomize color palette (ecr)",
|
|
|
|
"sS", "step / step over",
|
2018-12-31 00:21:03 +00:00
|
|
|
"tT", "tt new tab, t[1-9] switch to nth tab, t= name tab, t- close tab",
|
2018-07-04 08:50:00 +00:00
|
|
|
"uU", "undo/redo seek",
|
|
|
|
"v", "visual function/vars code analysis menu",
|
|
|
|
"V", "(V)iew interactive ascii art graph (agfv)",
|
|
|
|
"wW", "seek cursor to next/prev word",
|
|
|
|
"xX", "show xrefs/refs of current function from/to data/code",
|
|
|
|
"yY", "copy and paste selection",
|
|
|
|
"z", "fold/unfold comments in disassembly",
|
2019-03-08 09:07:42 +00:00
|
|
|
"Z", "shift-tab rotate print modes", // ctoggle zoom mode",
|
2018-07-04 08:50:00 +00:00
|
|
|
"Enter", "follow address of jump/call",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_visual_fn[] = {
|
|
|
|
"F2", "toggle breakpoint",
|
|
|
|
"F4", "run to cursor",
|
|
|
|
"F7", "single step",
|
|
|
|
"F8", "step over",
|
|
|
|
"F9", "continue",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-08-03 12:52:46 +00:00
|
|
|
static bool splitView = false;
|
|
|
|
static ut64 splitPtr = UT64_MAX;
|
|
|
|
|
2015-05-18 22:11:04 +00:00
|
|
|
#undef USE_THREADS
|
|
|
|
#define USE_THREADS 1
|
|
|
|
|
|
|
|
#if USE_THREADS
|
2018-02-20 21:03:27 +00:00
|
|
|
|
2017-12-18 01:44:51 +00:00
|
|
|
static void printSnow(RCore *core) {
|
|
|
|
if (!snows) {
|
|
|
|
snows = r_list_newf (free);
|
|
|
|
}
|
|
|
|
int i, h, w = r_cons_get_size (&h);
|
2017-12-20 14:05:33 +00:00
|
|
|
int amount = r_num_rand (4);
|
2017-12-18 01:44:51 +00:00
|
|
|
if (amount > 0) {
|
|
|
|
for (i = 0; i < amount; i++) {
|
|
|
|
Snow *snow = R_NEW (Snow);
|
2017-12-20 14:05:33 +00:00
|
|
|
snow->x = r_num_rand (w);
|
2017-12-18 01:44:51 +00:00
|
|
|
snow->y = 0;
|
|
|
|
r_list_append (snows, snow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RListIter *iter, *iter2;
|
|
|
|
Snow *snow;
|
|
|
|
r_list_foreach_safe (snows, iter, iter2, snow) {
|
2017-12-20 14:05:33 +00:00
|
|
|
int pos = (r_num_rand (3)) - 1;
|
2017-12-18 01:44:51 +00:00
|
|
|
snow->x += pos;
|
|
|
|
snow->y++;
|
|
|
|
if (snow->x >= w) {
|
|
|
|
r_list_delete (snows, iter);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (snow->y > h) {
|
|
|
|
r_list_delete (snows, iter);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r_cons_gotoxy (snow->x, snow->y);
|
|
|
|
r_cons_printf ("*");
|
|
|
|
}
|
|
|
|
// r_cons_gotoxy (10 , 10);
|
|
|
|
r_cons_flush ();
|
|
|
|
}
|
2019-01-02 01:09:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void rotateAsmBits(RCore *core) {
|
|
|
|
RAnalHint *hint = r_anal_hint_get (core->anal, core->offset);
|
|
|
|
int bits = hint? hint->bits : r_config_get_i (core->config, "asm.bits");
|
|
|
|
int retries = 4;
|
|
|
|
while (retries > 0) {
|
|
|
|
int nb = bits == 64 ? 8:
|
|
|
|
bits == 32 ? 64:
|
|
|
|
bits == 16 ? 32:
|
|
|
|
bits == 8 ? 16: bits;
|
2020-05-12 23:28:23 +00:00
|
|
|
if ((core->rasm->cur->bits & nb) == nb) {
|
2019-01-02 01:09:31 +00:00
|
|
|
r_core_cmdf (core, "ahb %d", nb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bits = nb;
|
|
|
|
retries--;
|
|
|
|
}
|
2020-02-14 16:30:34 +00:00
|
|
|
r_anal_hint_free (hint);
|
2019-01-02 01:09:31 +00:00
|
|
|
}
|
2017-12-18 01:44:51 +00:00
|
|
|
|
2019-01-02 01:09:31 +00:00
|
|
|
static const char *rotateAsmemu(RCore *core) {
|
|
|
|
const bool isEmuStr = r_config_get_i (core->config, "emu.str");
|
|
|
|
const bool isEmu = r_config_get_i (core->config, "asm.emu");
|
|
|
|
if (isEmu) {
|
|
|
|
if (isEmuStr) {
|
|
|
|
r_config_set (core->config, "emu.str", "false");
|
2015-05-18 22:18:14 +00:00
|
|
|
} else {
|
2019-01-02 01:09:31 +00:00
|
|
|
r_config_set (core->config, "asm.emu", "false");
|
2015-05-18 22:18:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-02 01:09:31 +00:00
|
|
|
r_config_set (core->config, "emu.str", "true");
|
2015-05-18 22:18:14 +00:00
|
|
|
}
|
2019-01-02 01:09:31 +00:00
|
|
|
return "pd";
|
2015-05-18 22:11:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 11:17:44 +00:00
|
|
|
R_API void r_core_visual_showcursor(RCore *core, int x) {
|
2014-03-01 23:31:35 +00:00
|
|
|
if (core && core->vmode) {
|
2013-10-10 23:24:30 +00:00
|
|
|
r_cons_show_cursor (x);
|
2019-07-02 01:56:18 +00:00
|
|
|
r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel"));
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
}
|
2014-03-01 23:31:35 +00:00
|
|
|
r_cons_flush ();
|
2013-10-10 23:24:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 09:08:46 +00:00
|
|
|
static void printFormat(RCore *core, const int next) {
|
2019-10-08 15:44:38 +00:00
|
|
|
switch (core->printidx) {
|
|
|
|
case R_CORE_VISUAL_MODE_PX: // 0 // xc
|
2020-04-18 09:08:46 +00:00
|
|
|
hexMode += next;
|
|
|
|
r_core_visual_applyHexMode (core, hexMode);
|
2019-10-08 15:44:38 +00:00
|
|
|
printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS];
|
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_PD: // pd
|
2020-04-18 09:08:46 +00:00
|
|
|
disMode += next;
|
|
|
|
r_core_visual_applyDisMode (core, disMode);
|
2019-10-08 15:44:38 +00:00
|
|
|
printfmtSingle[1] = rotateAsmemu (core);
|
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_DB: // debugger
|
2020-04-18 09:08:46 +00:00
|
|
|
disMode += next;
|
|
|
|
r_core_visual_applyDisMode (core, disMode);
|
2019-10-08 15:44:38 +00:00
|
|
|
printfmtSingle[1] = rotateAsmemu (core);
|
2020-04-18 09:08:46 +00:00
|
|
|
current3format += next;
|
2019-10-08 15:44:38 +00:00
|
|
|
currentFormat = R_ABS (current3format) % PRINT_3_FORMATS;
|
|
|
|
printfmtSingle[2] = print3Formats[currentFormat];
|
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_OV: // overview
|
2020-04-18 09:08:46 +00:00
|
|
|
current4format += next;
|
2019-10-08 15:44:38 +00:00
|
|
|
currentFormat = R_ABS (current4format) % PRINT_4_FORMATS;
|
|
|
|
printfmtSingle[3] = print4Formats[currentFormat];
|
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_CD: // code
|
2020-04-18 09:08:46 +00:00
|
|
|
current5format += next;
|
2019-10-08 15:44:38 +00:00
|
|
|
currentFormat = R_ABS (current5format) % PRINT_5_FORMATS;
|
|
|
|
printfmtSingle[4] = print5Formats[currentFormat];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 09:08:46 +00:00
|
|
|
static inline void nextPrintFormat(RCore *core) {
|
|
|
|
printFormat (core, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void prevPrintFormat(RCore *core) {
|
|
|
|
printFormat (core, -1);
|
2019-10-08 15:44:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 11:57:39 +00:00
|
|
|
R_API int r_core_visual_hud(RCore *core) {
|
2014-08-29 22:16:46 +00:00
|
|
|
const char *c = r_config_get (core->config, "hud.path");
|
2018-05-02 13:58:14 +00:00
|
|
|
char *f = r_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"),
|
2018-04-28 08:02:55 +00:00
|
|
|
r_sys_prefix (NULL));
|
2016-04-28 12:12:11 +00:00
|
|
|
int use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
2018-04-28 08:02:55 +00:00
|
|
|
char *homehud = r_str_home (R2_HOME_HUD);
|
2012-02-12 22:45:04 +00:00
|
|
|
char *res = NULL;
|
2012-01-31 02:34:23 +00:00
|
|
|
char *p = 0;
|
2019-05-27 16:21:17 +00:00
|
|
|
r_cons_singleton ()->context->color_mode = use_color;
|
2013-02-07 08:41:05 +00:00
|
|
|
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (c && *c && r_file_exists (c)) {
|
2017-02-20 01:31:49 +00:00
|
|
|
res = r_cons_hud_file (c);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
if (!res && homehud) {
|
2017-02-20 01:31:49 +00:00
|
|
|
res = r_cons_hud_file (homehud);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
if (!res && r_file_exists (f)) {
|
2017-02-20 01:31:49 +00:00
|
|
|
res = r_cons_hud_file (f);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
if (!res) {
|
2014-08-29 22:16:46 +00:00
|
|
|
r_cons_message ("Cannot find hud file");
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2014-08-29 22:16:46 +00:00
|
|
|
|
2012-01-31 01:45:17 +00:00
|
|
|
r_cons_clear ();
|
|
|
|
if (res) {
|
2018-12-17 15:48:29 +00:00
|
|
|
p = strchr (res, ';');
|
2016-06-26 04:51:17 +00:00
|
|
|
r_cons_println (res);
|
2012-01-31 01:45:17 +00:00
|
|
|
r_cons_flush ();
|
2017-02-22 22:45:51 +00:00
|
|
|
if (p) {
|
|
|
|
r_core_cmd0 (core, p + 1);
|
|
|
|
}
|
2012-01-31 01:45:17 +00:00
|
|
|
free (res);
|
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2012-01-31 01:45:17 +00:00
|
|
|
r_cons_flush ();
|
2014-05-03 00:21:02 +00:00
|
|
|
free (homehud);
|
2018-01-16 10:13:21 +00:00
|
|
|
free (f);
|
2017-02-22 22:45:51 +00:00
|
|
|
return (int) (size_t) p;
|
2012-01-31 01:45:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 04:56:15 +00:00
|
|
|
R_API void r_core_visual_jump(RCore *core, ut8 ch) {
|
|
|
|
char chbuf[2];
|
|
|
|
ut64 off;
|
|
|
|
chbuf[0] = ch;
|
|
|
|
chbuf[1] = '\0';
|
|
|
|
off = r_core_get_asmqjmps (core, chbuf);
|
|
|
|
if (off != UT64_MAX) {
|
|
|
|
int delta = R_ABS ((st64) off - (st64) core->offset);
|
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
if (core->print->cur_enabled && delta < 100) {
|
|
|
|
core->print->cur = delta;
|
|
|
|
} else {
|
|
|
|
r_core_visual_seek_animation (core, off);
|
|
|
|
core->print->cur = 0;
|
|
|
|
}
|
|
|
|
r_core_block_read (core);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 03:55:02 +00:00
|
|
|
R_API void r_core_visual_append_help(RStrBuf *p, const char *title, const char **help) {
|
2018-07-05 09:40:59 +00:00
|
|
|
int i, max_length = 0, padding = 0;
|
2019-01-18 10:58:49 +00:00
|
|
|
RConsContext *cons_ctx = r_cons_singleton ()->context;
|
2019-05-27 16:21:17 +00:00
|
|
|
const char *pal_args_color = cons_ctx->color_mode ? cons_ctx->pal.args : "",
|
|
|
|
*pal_help_color = cons_ctx->color_mode ? cons_ctx->pal.help : "",
|
|
|
|
*pal_reset = cons_ctx->color_mode ? cons_ctx->pal.reset : "";
|
2018-07-04 08:50:00 +00:00
|
|
|
for (i = 0; help[i]; i += 2) {
|
2018-07-05 09:40:59 +00:00
|
|
|
max_length = R_MAX (max_length, strlen (help[i]));
|
2018-07-04 08:50:00 +00:00
|
|
|
}
|
2018-07-05 09:40:59 +00:00
|
|
|
r_strbuf_appendf (p, "|%s:\n", title);
|
2018-07-04 08:50:00 +00:00
|
|
|
|
|
|
|
for (i = 0; help[i]; i += 2) {
|
|
|
|
padding = max_length - (strlen (help[i]));
|
2018-07-05 09:40:59 +00:00
|
|
|
r_strbuf_appendf (p, "| %s%s%*s %s%s%s\n",
|
2018-07-04 08:50:00 +00:00
|
|
|
pal_args_color, help[i],
|
|
|
|
padding, "",
|
|
|
|
pal_help_color, help[i + 1], pal_reset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 18:26:25 +00:00
|
|
|
static int visual_help(RCore *core) {
|
2019-01-02 01:09:31 +00:00
|
|
|
int ret = 0;
|
2019-07-24 17:10:10 +00:00
|
|
|
RStrBuf *p, *q;
|
2019-01-02 01:09:31 +00:00
|
|
|
repeat:
|
|
|
|
p = r_strbuf_new (NULL);
|
2019-07-24 17:10:10 +00:00
|
|
|
q = r_strbuf_new (NULL);
|
2018-07-04 08:50:00 +00:00
|
|
|
if (!p) {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-07 01:07:10 +00:00
|
|
|
r_cons_clear00 ();
|
2019-07-24 17:10:10 +00:00
|
|
|
r_core_visual_append_help (q, "Visual Help", help_visual);
|
|
|
|
r_cons_printf ("%s", r_strbuf_get (q));
|
2019-01-02 01:09:31 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
switch (r_cons_readchar ()) {
|
|
|
|
case 'q':
|
|
|
|
r_strbuf_free (p);
|
2020-01-17 04:58:29 +00:00
|
|
|
r_strbuf_free (q);
|
2019-01-02 01:09:31 +00:00
|
|
|
return ret;
|
2019-09-01 18:26:25 +00:00
|
|
|
case '!':
|
2020-12-07 17:08:26 +00:00
|
|
|
r_core_panels_root (core, core->panels_root);
|
2019-09-01 18:26:25 +00:00
|
|
|
break;
|
2019-01-02 01:09:31 +00:00
|
|
|
case '?':
|
|
|
|
r_core_visual_append_help (p, "Visual mode help", help_msg_visual);
|
|
|
|
r_core_visual_append_help (p, "Function Keys: (See 'e key.'), defaults to", help_msg_visual_fn);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
r_strbuf_appendf (p, "Visual Views:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
|
|
|
" \\ toggle horizonal split mode\n"
|
|
|
|
" tt create a new tab (same as t+)\n"
|
|
|
|
" t= give a name to the current tab\n"
|
|
|
|
" t- close current tab\n"
|
|
|
|
" th select previous tab (same as tj)\n"
|
|
|
|
" tl select next tab (same as tk)\n"
|
|
|
|
" t[1-9] select nth tab\n"
|
|
|
|
" C -> rotate scr.color=0,1,2,3\n"
|
|
|
|
" R -> rotate color theme with ecr command which honors scr.randpal\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
r_strbuf_appendf (p, "Visual Print Modes:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
|
|
|
" pP -> change to the next/previous print mode (hex, dis, ..)\n"
|
|
|
|
" TAB -> rotate between all the configurations for the current print mode\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
r_strbuf_appendf (p, "Visual Evals:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
|
|
|
" E toggle asm.leahints\n"
|
|
|
|
" & rotate asm.bits=16,32,64\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
2019-09-01 18:26:25 +00:00
|
|
|
case 'c':
|
|
|
|
setcursor (core, !core->print->cur_enabled);
|
|
|
|
r_strbuf_free (p);
|
|
|
|
return ret;
|
2019-01-02 01:09:31 +00:00
|
|
|
case 'i':
|
|
|
|
r_strbuf_appendf (p, "Visual Insertion Help:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
|
|
|
" i -> insert bits, bytes or text depending on view\n"
|
|
|
|
" a -> assemble instruction and write the bytes in the current offset\n"
|
|
|
|
" A -> visual assembler\n"
|
|
|
|
" + -> increment value of byte\n"
|
|
|
|
" - -> decrement value of byte\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
r_strbuf_appendf (p, "Visual Debugger Help:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
2019-03-03 22:10:43 +00:00
|
|
|
" $ -> set the program counter (PC register)\n"
|
2019-01-02 01:09:31 +00:00
|
|
|
" s -> step in\n"
|
|
|
|
" S -> step over\n"
|
|
|
|
" B -> toggle breakpoint\n"
|
|
|
|
" :dc -> continue\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
r_strbuf_appendf (p, "Visual Moving Around:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
2019-04-14 22:09:18 +00:00
|
|
|
" g type flag/offset/register name to seek\n"
|
2019-01-02 01:09:31 +00:00
|
|
|
" hl seek to the next/previous byte\n"
|
|
|
|
" jk seek to the next row (core.offset += hex.cols)\n"
|
|
|
|
" JK seek one page down\n"
|
|
|
|
" ^ seek to the beginning of the current map\n"
|
|
|
|
" $ seek to the end of the current map\n"
|
|
|
|
" c toggle cursor mode (use hjkl to move and HJKL to select a range)\n"
|
|
|
|
" mK/'K mark/go to Key (any key)\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
r_strbuf_appendf (p, "Visual Analysis:\n\n");
|
|
|
|
r_strbuf_appendf (p,
|
|
|
|
" df -> define function\n"
|
|
|
|
" du -> undefine function\n"
|
|
|
|
" dc -> define as code\n"
|
2019-03-31 19:43:19 +00:00
|
|
|
" dw -> define as dword (32bit)\n"
|
|
|
|
" dw -> define as qword (64bit)\n"
|
|
|
|
" dd -> define current block or selected bytes as data\n"
|
2019-01-02 01:09:31 +00:00
|
|
|
" V -> view graph (same as press the 'space' key)\n"
|
|
|
|
);
|
|
|
|
ret = r_cons_less_str (r_strbuf_get (p), "?");
|
|
|
|
break;
|
|
|
|
}
|
2018-07-05 09:40:59 +00:00
|
|
|
r_strbuf_free (p);
|
2019-07-24 17:10:10 +00:00
|
|
|
r_strbuf_free (q);
|
2019-01-02 01:09:31 +00:00
|
|
|
goto repeat;
|
2013-11-07 01:07:10 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void prompt_read(const char *p, char *buf, int buflen) {
|
2017-01-10 00:47:15 +00:00
|
|
|
if (!buf || buflen < 1) {
|
2016-02-27 11:38:02 +00:00
|
|
|
return;
|
2017-01-10 00:47:15 +00:00
|
|
|
}
|
2016-02-27 11:38:02 +00:00
|
|
|
*buf = 0;
|
2012-08-13 02:33:01 +00:00
|
|
|
r_line_set_prompt (p);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (NULL, true);
|
2012-08-13 02:33:01 +00:00
|
|
|
r_cons_fgets (buf, buflen, 0, NULL);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (NULL, false);
|
2012-08-13 02:33:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 22:15:59 +00:00
|
|
|
static void reset_print_cur(RPrint *p) {
|
|
|
|
p->cur = 0;
|
|
|
|
p->ocur = -1;
|
|
|
|
}
|
|
|
|
|
2019-08-30 17:43:12 +00:00
|
|
|
static bool __holdMouseState(RCore *core) {
|
|
|
|
bool m = r_cons_singleton ()->mouse;
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2018-04-06 22:26:05 +00:00
|
|
|
static void backup_current_addr(RCore *core, ut64 *addr, ut64 *bsze, ut64 *newaddr) {
|
|
|
|
*addr = core->offset;
|
|
|
|
*bsze = core->blocksize;
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
if (core->print->ocur != -1) {
|
|
|
|
int newsz = core->print->cur - core->print->ocur;
|
2018-04-06 22:26:05 +00:00
|
|
|
*newaddr = core->offset + core->print->ocur;
|
2016-02-07 16:06:39 +00:00
|
|
|
r_core_block_size (core, newsz);
|
2016-12-03 11:27:32 +00:00
|
|
|
} else {
|
2018-04-06 22:26:05 +00:00
|
|
|
*newaddr = core->offset + core->print->cur;
|
2016-12-03 11:27:32 +00:00
|
|
|
}
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, *newaddr, true);
|
2014-10-01 16:57:01 +00:00
|
|
|
}
|
2018-04-06 22:26:05 +00:00
|
|
|
}
|
2018-04-06 22:15:59 +00:00
|
|
|
|
2018-04-06 22:26:05 +00:00
|
|
|
static void restore_current_addr(RCore *core, ut64 addr, ut64 bsze, ut64 newaddr) {
|
|
|
|
bool restore_seek = true;
|
2018-04-06 22:15:59 +00:00
|
|
|
if (core->offset != newaddr) {
|
|
|
|
bool cursor_moved = false;
|
|
|
|
// when new address is in the screen bounds, just move
|
|
|
|
// the cursor if enabled and restore seek
|
|
|
|
if (core->print->cur != -1 && core->print->screen_bounds > 1) {
|
|
|
|
if (core->offset >= addr &&
|
|
|
|
core->offset < core->print->screen_bounds) {
|
|
|
|
core->print->ocur = -1;
|
|
|
|
core->print->cur = core->offset - addr;
|
|
|
|
cursor_moved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cursor_moved) {
|
|
|
|
restore_seek = false;
|
2018-04-06 21:19:31 +00:00
|
|
|
reset_print_cur (core->print);
|
2014-10-01 16:57:01 +00:00
|
|
|
}
|
2018-04-06 22:15:59 +00:00
|
|
|
}
|
2018-04-06 22:26:05 +00:00
|
|
|
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2018-04-06 22:15:59 +00:00
|
|
|
if (restore_seek) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, true);
|
2014-08-05 17:49:33 +00:00
|
|
|
r_core_block_size (core, bsze);
|
|
|
|
}
|
2014-10-01 16:57:01 +00:00
|
|
|
}
|
2018-04-06 22:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_core_visual_prompt_input(RCore *core) {
|
2018-11-22 21:11:43 +00:00
|
|
|
ut64 addr, bsze, newaddr = 0LL;
|
2018-04-06 22:26:05 +00:00
|
|
|
int ret, h;
|
|
|
|
(void) r_cons_get_size (&h);
|
2019-08-30 17:43:12 +00:00
|
|
|
bool mouse_state = __holdMouseState(core);
|
2019-07-03 22:59:27 +00:00
|
|
|
r_cons_gotoxy (0, h);
|
2018-04-06 22:26:05 +00:00
|
|
|
r_cons_reset_colors ();
|
2019-07-03 22:59:27 +00:00
|
|
|
//r_cons_printf ("\nPress <enter> to return to Visual mode.\n");
|
2018-04-06 22:26:05 +00:00
|
|
|
r_cons_show_cursor (true);
|
|
|
|
core->vmode = false;
|
|
|
|
|
|
|
|
backup_current_addr (core, &addr, &bsze, &newaddr);
|
|
|
|
do {
|
|
|
|
ret = r_core_visual_prompt (core);
|
|
|
|
} while (ret);
|
|
|
|
restore_current_addr (core, addr, bsze, newaddr);
|
|
|
|
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
|
|
|
core->vmode = true;
|
2019-08-30 17:43:12 +00:00
|
|
|
r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel"));
|
2019-08-20 23:16:10 +00:00
|
|
|
r_cons_show_cursor (true);
|
2014-08-05 17:49:33 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
R_API int r_core_visual_prompt(RCore *core) {
|
2011-05-21 12:27:46 +00:00
|
|
|
char buf[1024];
|
2013-12-31 12:09:50 +00:00
|
|
|
int ret;
|
2016-12-28 11:44:26 +00:00
|
|
|
if (PIDX != 2) {
|
|
|
|
core->seltab = 0;
|
|
|
|
}
|
2011-12-04 20:02:09 +00:00
|
|
|
#if __UNIX__
|
2017-02-22 22:45:51 +00:00
|
|
|
r_line_set_prompt (Color_RESET ":> ");
|
2011-12-04 20:02:09 +00:00
|
|
|
#else
|
2011-05-21 12:27:46 +00:00
|
|
|
r_line_set_prompt (":> ");
|
2011-12-04 20:02:09 +00:00
|
|
|
#endif
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2011-05-21 12:27:46 +00:00
|
|
|
r_cons_fgets (buf, sizeof (buf), 0, NULL);
|
2014-10-01 16:57:01 +00:00
|
|
|
if (!strcmp (buf, "q")) {
|
2015-09-14 10:35:38 +00:00
|
|
|
ret = false;
|
2014-10-01 16:57:01 +00:00
|
|
|
} else if (*buf) {
|
2013-12-31 12:09:50 +00:00
|
|
|
r_line_hist_add (buf);
|
|
|
|
r_core_cmd (core, buf, 0);
|
2019-07-24 11:59:57 +00:00
|
|
|
r_cons_echo (NULL);
|
2013-12-31 12:09:50 +00:00
|
|
|
r_cons_flush ();
|
2015-09-14 10:35:38 +00:00
|
|
|
ret = true;
|
2019-10-12 21:56:16 +00:00
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
}
|
2013-12-31 12:09:50 +00:00
|
|
|
} else {
|
2015-09-14 10:35:38 +00:00
|
|
|
ret = false;
|
2015-03-05 22:33:28 +00:00
|
|
|
//r_cons_any_key (NULL);
|
2013-12-31 12:09:50 +00:00
|
|
|
r_cons_clear00 ();
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2013-12-31 12:09:50 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2011-05-21 12:27:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void visual_single_step_in(RCore *core) {
|
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
// dcu 0xaddr
|
|
|
|
r_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
core->print->cur_enabled = 0;
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "ds", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "aes", 0);
|
|
|
|
r_core_cmd (core, ".ar*", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 10:51:46 +00:00
|
|
|
static void __core_visual_step_over(RCore *core) {
|
2018-05-27 13:53:04 +00:00
|
|
|
bool io_cache = r_config_get_i (core->config, "io.cache");
|
|
|
|
r_config_set_i (core->config, "io.cache", false);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
r_core_cmd (core, "dcr", 0);
|
|
|
|
core->print->cur_enabled = 0;
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "dso", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "aeso", 0);
|
|
|
|
r_core_cmd (core, ".ar*", 0);
|
|
|
|
}
|
2018-05-27 13:53:04 +00:00
|
|
|
r_config_set_i (core->config, "io.cache", io_cache);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_breakpoint(RCore *core) {
|
|
|
|
r_core_cmd (core, "dbs $$", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_continue(RCore *core) {
|
2020-05-03 08:52:47 +00:00
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
r_core_cmd (core, "dc", 0);
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "aec;.ar*", 0);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 00:20:52 +00:00
|
|
|
static int visual_nkey(RCore *core, int ch) {
|
2011-06-05 22:16:11 +00:00
|
|
|
const char *cmd;
|
2013-10-06 13:15:23 +00:00
|
|
|
ut64 oseek = UT64_MAX;
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->ocur == -1) {
|
2013-10-06 13:15:23 +00:00
|
|
|
oseek = core->offset;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + core->print->cur, false);
|
2013-10-06 13:15:23 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 22:16:11 +00:00
|
|
|
switch (ch) {
|
|
|
|
case R_CONS_KEY_F1:
|
|
|
|
cmd = r_config_get (core->config, "key.f1");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
2019-09-01 18:26:25 +00:00
|
|
|
visual_help (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F2:
|
|
|
|
cmd = r_config_get (core->config, "key.f2");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
|
|
|
visual_breakpoint (core);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F3:
|
|
|
|
cmd = r_config_get (core->config, "key.f3");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F4:
|
|
|
|
cmd = r_config_get (core->config, "key.f4");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2015-12-16 19:35:45 +00:00
|
|
|
// dcu 0xaddr
|
2016-02-07 16:06:39 +00:00
|
|
|
r_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
core->print->cur_enabled = 0;
|
2015-12-16 19:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-01 12:59:31 +00:00
|
|
|
break;
|
2011-06-05 22:16:11 +00:00
|
|
|
case R_CONS_KEY_F5:
|
|
|
|
cmd = r_config_get (core->config, "key.f5");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2014-08-01 12:59:31 +00:00
|
|
|
break;
|
2011-06-05 22:16:11 +00:00
|
|
|
case R_CONS_KEY_F6:
|
|
|
|
cmd = r_config_get (core->config, "key.f6");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F7:
|
|
|
|
cmd = r_config_get (core->config, "key.f7");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
|
|
|
visual_single_step_in (core);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F8:
|
|
|
|
cmd = r_config_get (core->config, "key.f8");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
2019-01-05 10:51:46 +00:00
|
|
|
__core_visual_step_over (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F9:
|
|
|
|
cmd = r_config_get (core->config, "key.f9");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
} else {
|
|
|
|
visual_continue (core);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F10:
|
|
|
|
cmd = r_config_get (core->config, "key.f10");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F11:
|
|
|
|
cmd = r_config_get (core->config, "key.f11");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F12:
|
|
|
|
cmd = r_config_get (core->config, "key.f12");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmd && *cmd) {
|
|
|
|
ch = r_core_cmd0 (core, cmd);
|
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-02 01:19:31 +00:00
|
|
|
if (oseek != UT64_MAX) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, oseek, false);
|
2016-06-02 01:19:31 +00:00
|
|
|
}
|
2011-06-05 22:16:11 +00:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void setdiff(RCore *core) {
|
2012-08-13 02:33:01 +00:00
|
|
|
char from[64], to[64];
|
|
|
|
prompt_read ("diff from: ", from, sizeof (from));
|
|
|
|
r_config_set (core->config, "diff.from", from);
|
|
|
|
prompt_read ("diff to: ", to, sizeof (to));
|
|
|
|
r_config_set (core->config, "diff.to", to);
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void findPair(RCore *core) {
|
2015-02-12 23:36:05 +00:00
|
|
|
ut8 buf[256];
|
2016-02-07 16:06:39 +00:00
|
|
|
int i, len, d = core->print->cur + 1;
|
2015-02-12 23:36:05 +00:00
|
|
|
int delta = 0;
|
2015-02-13 10:06:27 +00:00
|
|
|
const ut8 *p, *q = NULL;
|
2015-02-12 23:36:05 +00:00
|
|
|
const char *keys = "{}[]()<>";
|
2016-02-07 16:06:39 +00:00
|
|
|
ut8 ch = core->block[core->print->cur];
|
2015-02-12 23:36:05 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
p = (const ut8 *) strchr (keys, ch);
|
2015-02-12 23:36:05 +00:00
|
|
|
if (p) {
|
2016-12-19 23:48:02 +00:00
|
|
|
char p_1 = 0;
|
2017-04-17 22:35:22 +00:00
|
|
|
if ((const char *) p > keys) {
|
2016-12-19 23:48:02 +00:00
|
|
|
p_1 = p[-1];
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
delta = (size_t) (p - (const ut8 *) keys);
|
|
|
|
ch = (delta % 2 && p != (const ut8 *) keys)? p_1: p[1];
|
2015-02-12 23:36:05 +00:00
|
|
|
}
|
|
|
|
len = 1;
|
|
|
|
buf[0] = ch;
|
|
|
|
|
2016-12-20 01:12:05 +00:00
|
|
|
if (p && (delta % 2)) {
|
|
|
|
for (i = d - 1; i >= 0; i--) {
|
2015-02-13 10:06:27 +00:00
|
|
|
if (core->block[i] == ch) {
|
|
|
|
q = core->block + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
q = r_mem_mem (core->block + d, core->blocksize - d,
|
|
|
|
(const ut8 *) buf, len);
|
2015-02-13 10:06:27 +00:00
|
|
|
if (!q) {
|
|
|
|
q = r_mem_mem (core->block, R_MIN (core->blocksize, d),
|
2017-02-22 22:45:51 +00:00
|
|
|
(const ut8 *) buf, len);
|
2015-02-13 10:06:27 +00:00
|
|
|
}
|
2015-02-12 23:36:05 +00:00
|
|
|
}
|
|
|
|
if (q) {
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur = (int) (size_t) (q - core->block);
|
2016-02-07 16:06:39 +00:00
|
|
|
core->print->ocur = -1;
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2015-02-12 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-13 10:06:27 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void findNextWord(RCore *core) {
|
|
|
|
int i, d = core->print->cur_enabled? core->print->cur: 0;
|
|
|
|
for (i = d + 1; i < core->blocksize; i++) {
|
2015-02-13 10:06:27 +00:00
|
|
|
switch (core->block[i]) {
|
|
|
|
case ' ':
|
|
|
|
case '.':
|
|
|
|
case '\t':
|
|
|
|
case '\n':
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
core->print->cur = i + 1;
|
|
|
|
core->print->ocur = -1;
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2015-02-13 10:06:27 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + i + 1, true);
|
2015-02-13 10:06:27 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static int isSpace(char ch) {
|
2015-02-13 10:06:27 +00:00
|
|
|
switch (ch) {
|
|
|
|
case ' ':
|
|
|
|
case '.':
|
|
|
|
case ',':
|
|
|
|
case '\t':
|
|
|
|
case '\n':
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void findPrevWord(RCore *core) {
|
|
|
|
int i = core->print->cur_enabled? core->print->cur: 0;
|
|
|
|
while (i > 1) {
|
|
|
|
if (isSpace (core->block[i])) {
|
2015-02-13 10:06:27 +00:00
|
|
|
i--;
|
2017-02-22 22:45:51 +00:00
|
|
|
} else if (isSpace (core->block[i - 1])) {
|
|
|
|
i -= 2;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2015-02-13 10:06:27 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
for (; i >= 0; i--) {
|
2015-02-13 10:06:27 +00:00
|
|
|
if (isSpace (core->block[i])) {
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
core->print->cur = i + 1;
|
|
|
|
core->print->ocur = -1;
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2015-02-13 10:06:27 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:50:39 +00:00
|
|
|
// TODO: integrate in '/' command with search.inblock ?
|
2017-02-22 22:45:51 +00:00
|
|
|
static void visual_search(RCore *core) {
|
2012-08-04 21:48:06 +00:00
|
|
|
const ut8 *p;
|
2016-02-07 16:06:39 +00:00
|
|
|
int len, d = core->print->cur;
|
2018-12-19 11:07:49 +00:00
|
|
|
char str[128], buf[sizeof (str) * 2 + 1];
|
2012-08-01 23:50:39 +00:00
|
|
|
|
|
|
|
r_line_set_prompt ("search byte/string in block: ");
|
|
|
|
r_cons_fgets (str, sizeof (str), 0, NULL);
|
2017-02-22 22:45:51 +00:00
|
|
|
len = r_hex_str2bin (str, (ut8 *) buf);
|
|
|
|
if (*str == '"') {
|
2018-12-19 11:07:49 +00:00
|
|
|
r_str_ncpy (buf, str + 1, sizeof (buf));
|
2012-08-01 23:50:39 +00:00
|
|
|
len = strlen (buf);
|
2018-12-19 11:07:49 +00:00
|
|
|
char *e = buf + len - 1;
|
|
|
|
if (e > buf && *e == '"') {
|
|
|
|
*e = 0;
|
|
|
|
len--;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else if (len < 1) {
|
2018-12-19 11:07:49 +00:00
|
|
|
r_str_ncpy (buf, str, sizeof (buf));
|
|
|
|
len = strlen (buf);
|
2012-08-01 23:50:39 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
p = r_mem_mem (core->block + d, core->blocksize - d,
|
|
|
|
(const ut8 *) buf, len);
|
2012-08-01 23:50:39 +00:00
|
|
|
if (p) {
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur = (int) (size_t) (p - core->block);
|
|
|
|
if (len > 1) {
|
|
|
|
core->print->ocur = core->print->cur + len - 1;
|
|
|
|
} else {
|
|
|
|
core->print->ocur = -1;
|
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-04-17 22:35:22 +00:00
|
|
|
eprintf ("Found in offset 0x%08"PFMT64x" + %d\n", core->offset, core->print->cur);
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2012-08-01 23:50:39 +00:00
|
|
|
} else {
|
2017-04-17 22:35:22 +00:00
|
|
|
eprintf ("Cannot find bytes.\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2012-08-01 23:50:39 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
R_API void r_core_visual_show_char(RCore *core, char ch) {
|
|
|
|
if (r_config_get_i (core->config, "scr.feedback") < 2) {
|
2014-09-28 01:27:22 +00:00
|
|
|
return;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
if (!IS_PRINTABLE (ch)) {
|
2014-09-28 01:27:22 +00:00
|
|
|
return;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2014-09-28 01:27:22 +00:00
|
|
|
r_cons_gotoxy (1, 2);
|
|
|
|
r_cons_printf (".---.\n");
|
|
|
|
r_cons_printf ("| %c |\n", ch);
|
|
|
|
r_cons_printf ("'---'\n");
|
|
|
|
r_cons_flush ();
|
2014-10-20 23:20:06 +00:00
|
|
|
r_sys_sleep (1);
|
2014-09-28 01:27:22 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
R_API void r_core_visual_seek_animation(RCore *core, ut64 addr) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.feedback") < 1) {
|
2014-09-28 01:27:22 +00:00
|
|
|
return;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
if (core->offset == addr) {
|
2013-10-19 22:25:37 +00:00
|
|
|
return;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2013-10-19 22:25:37 +00:00
|
|
|
r_cons_gotoxy (1, 2);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (addr > core->offset) {
|
2013-10-19 22:25:37 +00:00
|
|
|
r_cons_printf (".----.\n");
|
|
|
|
r_cons_printf ("| \\/ |\n");
|
|
|
|
r_cons_printf ("'----'\n");
|
|
|
|
} else {
|
|
|
|
r_cons_printf (".----.\n");
|
|
|
|
r_cons_printf ("| /\\ |\n");
|
|
|
|
r_cons_printf ("'----'\n");
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_flush ();
|
2014-10-20 23:20:06 +00:00
|
|
|
r_sys_usleep (90000);
|
2013-10-19 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
static void setprintmode(RCore *core, int n) {
|
2013-12-31 12:09:50 +00:00
|
|
|
RAsmOp op;
|
2019-10-08 15:44:38 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
if (n > 0) {
|
|
|
|
core->printidx = R_ABS ((core->printidx + 1) % NPF);
|
2013-12-02 02:53:29 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->printidx) {
|
2013-12-02 02:53:29 +00:00
|
|
|
core->printidx--;
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
core->printidx = NPF - 1;
|
|
|
|
}
|
2013-12-02 02:53:29 +00:00
|
|
|
}
|
|
|
|
switch (core->printidx) {
|
2019-10-08 15:44:38 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PD:
|
|
|
|
case R_CORE_VISUAL_MODE_DB:
|
2018-10-08 10:54:38 +00:00
|
|
|
r_asm_op_init (&op);
|
2020-05-12 23:28:23 +00:00
|
|
|
r_asm_disassemble (core->rasm, &op, core->block, R_MIN (32, core->blocksize));
|
2018-10-08 10:54:38 +00:00
|
|
|
r_asm_op_fini (&op);
|
2013-12-02 02:53:29 +00:00
|
|
|
break;
|
2019-11-27 15:06:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-12-02 02:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-01 22:33:07 +00:00
|
|
|
#define OPDELTA 32
|
2017-02-22 22:45:51 +00:00
|
|
|
static ut64 prevop_addr(RCore *core, ut64 addr) {
|
2016-02-10 23:18:09 +00:00
|
|
|
ut8 buf[OPDELTA * 2];
|
|
|
|
ut64 target, base;
|
|
|
|
RAnalBlock *bb;
|
2013-11-07 01:07:10 +00:00
|
|
|
RAnalOp op;
|
2016-02-10 23:18:09 +00:00
|
|
|
int len, ret, i;
|
2016-03-31 22:27:14 +00:00
|
|
|
int minop = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
|
|
|
|
int maxop = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE);
|
|
|
|
|
|
|
|
if (minop == maxop) {
|
2016-04-13 21:57:24 +00:00
|
|
|
if (minop == -1) {
|
|
|
|
return addr - 4;
|
|
|
|
}
|
2016-03-31 22:27:14 +00:00
|
|
|
return addr - minop;
|
|
|
|
}
|
2016-02-10 23:18:09 +00:00
|
|
|
|
|
|
|
// let's see if we can use anal info to get the previous instruction
|
|
|
|
// TODO: look in the current basicblock, then in the current function
|
|
|
|
// and search in all functions only as a last chance, to try to speed
|
|
|
|
// up the process.
|
2016-03-31 22:27:14 +00:00
|
|
|
bb = r_anal_bb_from_offset (core->anal, addr - minop);
|
2016-02-10 23:18:09 +00:00
|
|
|
if (bb) {
|
2016-03-31 22:27:14 +00:00
|
|
|
ut64 res = r_anal_bb_opaddr_at (bb, addr - minop);
|
2016-02-10 23:18:09 +00:00
|
|
|
if (res != UT64_MAX) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we anal info didn't help then fallback to the dumb solution.
|
2019-03-22 15:22:31 +00:00
|
|
|
int midflags = r_config_get_i (core->config, "asm.flags.middle");
|
2016-02-10 23:18:09 +00:00
|
|
|
target = addr;
|
2018-12-18 09:41:06 +00:00
|
|
|
base = target > OPDELTA ? target - OPDELTA : 0;
|
2018-05-21 21:06:00 +00:00
|
|
|
r_io_read_at (core->io, base, buf, sizeof (buf));
|
2016-02-10 23:18:09 +00:00
|
|
|
for (i = 0; i < sizeof (buf); i++) {
|
|
|
|
ret = r_anal_op (core->anal, &op, base + i,
|
2018-05-28 04:45:53 +00:00
|
|
|
buf + i, sizeof (buf) - i, R_ANAL_OP_MASK_BASIC);
|
2018-12-18 13:06:52 +00:00
|
|
|
if (ret) {
|
|
|
|
len = op.size;
|
|
|
|
if (len < 1) {
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
r_anal_op_fini (&op); // XXX
|
2019-03-22 15:22:31 +00:00
|
|
|
if (midflags >= R_MIDFLAGS_REALIGN) {
|
|
|
|
int skip_bytes = r_core_flag_in_middle (core, base + i, len, &midflags);
|
|
|
|
if (skip_bytes && base + i + skip_bytes < target) {
|
|
|
|
i += skip_bytes - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 13:06:52 +00:00
|
|
|
} else {
|
|
|
|
len = 1;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2018-12-12 21:03:32 +00:00
|
|
|
if (target <= base + i + len) {
|
2016-02-10 23:18:09 +00:00
|
|
|
return base + i;
|
|
|
|
}
|
|
|
|
i += len - 1;
|
2013-11-07 01:07:10 +00:00
|
|
|
}
|
2018-12-18 09:41:06 +00:00
|
|
|
return target > 4 ? target - 4 : 0;
|
2013-11-07 01:07:10 +00:00
|
|
|
}
|
2016-03-01 23:49:43 +00:00
|
|
|
|
2016-06-11 02:12:41 +00:00
|
|
|
// Returns true if we can use analysis to find the previous operation address,
|
|
|
|
// sets prev_addr to the value of the instruction numinstrs back.
|
|
|
|
// If we can't use the anal, then set prev_addr to UT64_MAX and return false;
|
2017-02-22 22:45:51 +00:00
|
|
|
R_API bool r_core_prevop_addr(RCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr) {
|
|
|
|
RAnalBlock *bb;
|
2016-06-11 02:12:41 +00:00
|
|
|
int i;
|
|
|
|
// Check that we're in a bb, otherwise this prevop stuff won't work.
|
|
|
|
bb = r_anal_bb_from_offset (core->anal, start_addr);
|
|
|
|
if (bb) {
|
|
|
|
if (r_anal_bb_opaddr_at (bb, start_addr) != UT64_MAX) {
|
|
|
|
// Do some anal looping.
|
2020-03-05 18:06:59 +00:00
|
|
|
for (i = 0; i < numinstrs; i++) {
|
2016-06-11 02:12:41 +00:00
|
|
|
*prev_addr = prevop_addr (core, start_addr);
|
|
|
|
start_addr = *prev_addr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Dang! not in a bb, return false and fallback to other methods.
|
|
|
|
*prev_addr = UT64_MAX;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:30:38 +00:00
|
|
|
// Like r_core_prevop_addr(), but also uses fallback from prevop_addr() if
|
|
|
|
// no anal info is available.
|
|
|
|
R_API ut64 r_core_prevop_addr_force(RCore *core, ut64 start_addr, int numinstrs) {
|
|
|
|
int i;
|
2020-03-05 18:06:59 +00:00
|
|
|
for (i = 0; i < numinstrs; i++) {
|
2017-12-16 16:30:38 +00:00
|
|
|
start_addr = prevop_addr (core, start_addr);
|
|
|
|
}
|
|
|
|
return start_addr;
|
|
|
|
}
|
|
|
|
|
2019-04-24 12:59:26 +00:00
|
|
|
R_API int r_line_hist_offset_up(RLine *line) {
|
2018-03-08 23:33:33 +00:00
|
|
|
RCore *core = line->user;
|
|
|
|
RIOUndo *undo = &core->io->undo;
|
2018-07-09 15:06:52 +00:00
|
|
|
if (line->offset_hist_index <= -undo->undos) {
|
2018-03-08 23:33:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-09 15:06:52 +00:00
|
|
|
line->offset_hist_index--;
|
|
|
|
ut64 off = undo->seek[undo->idx + line->offset_hist_index].off;
|
2018-03-08 23:33:33 +00:00
|
|
|
RFlagItem *f = r_flag_get_at (core->flags, off, false);
|
|
|
|
char *command;
|
|
|
|
if (f && f->offset == off && f->offset > 0) {
|
|
|
|
command = r_str_newf ("%s", f->name);
|
2018-03-19 10:51:04 +00:00
|
|
|
} else {
|
2018-03-08 23:33:33 +00:00
|
|
|
command = r_str_newf ("0x%"PFMT64x, off);
|
|
|
|
}
|
|
|
|
strncpy (line->buffer.data, command, R_LINE_BUFSIZE - 1);
|
|
|
|
line->buffer.index = line->buffer.length = strlen (line->buffer.data);
|
2018-03-19 10:51:04 +00:00
|
|
|
free (command);
|
2018-03-08 23:33:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-24 12:59:26 +00:00
|
|
|
R_API int r_line_hist_offset_down(RLine *line) {
|
2018-03-08 23:33:33 +00:00
|
|
|
RCore *core = line->user;
|
|
|
|
RIOUndo *undo = &core->io->undo;
|
2018-07-09 15:06:52 +00:00
|
|
|
if (line->offset_hist_index >= undo->redos) {
|
2018-03-08 23:33:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-09 15:06:52 +00:00
|
|
|
line->offset_hist_index++;
|
|
|
|
if (line->offset_hist_index == undo->redos) {
|
2018-03-08 23:33:33 +00:00
|
|
|
line->buffer.data[0] = '\0';
|
|
|
|
line->buffer.index = line->buffer.length = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-09 15:06:52 +00:00
|
|
|
ut64 off = undo->seek[undo->idx + line->offset_hist_index].off;
|
2018-03-08 23:33:33 +00:00
|
|
|
RFlagItem *f = r_flag_get_at (core->flags, off, false);
|
|
|
|
char *command;
|
|
|
|
if (f && f->offset == off && f->offset > 0) {
|
|
|
|
command = r_str_newf ("%s", f->name);
|
2018-03-19 10:51:04 +00:00
|
|
|
} else {
|
2018-03-08 23:33:33 +00:00
|
|
|
command = r_str_newf ("0x%"PFMT64x, off);
|
|
|
|
}
|
|
|
|
strncpy (line->buffer.data, command, R_LINE_BUFSIZE - 1);
|
|
|
|
line->buffer.index = line->buffer.length = strlen (line->buffer.data);
|
2018-03-19 10:51:04 +00:00
|
|
|
free (command);
|
2018-03-08 23:33:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-25 11:17:44 +00:00
|
|
|
R_API void r_core_visual_offset(RCore *core) {
|
2018-11-23 12:54:28 +00:00
|
|
|
ut64 addr, bsze, newaddr = 0LL;
|
2014-02-10 02:31:12 +00:00
|
|
|
char buf[256];
|
2018-04-06 22:26:05 +00:00
|
|
|
|
|
|
|
backup_current_addr (core, &addr, &bsze, &newaddr);
|
2019-04-25 14:23:19 +00:00
|
|
|
core->cons->line->prompt_type = R_LINE_PROMPT_OFFSET;
|
2019-04-24 12:59:26 +00:00
|
|
|
r_line_set_hist_callback (core->cons->line,
|
|
|
|
&r_line_hist_offset_up,
|
|
|
|
&r_line_hist_offset_down);
|
2014-02-10 02:31:12 +00:00
|
|
|
r_line_set_prompt ("[offset]> ");
|
|
|
|
strcpy (buf, "s ");
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf + 2, sizeof (buf) - 2, 0, NULL) > 0) {
|
2019-03-06 10:14:23 +00:00
|
|
|
if (!strcmp (buf + 2, "g") || !strcmp (buf + 2, "G")) {
|
|
|
|
__core_visual_gogo (core, buf[2]);
|
|
|
|
} else {
|
|
|
|
if (buf[2] == '.') {
|
|
|
|
buf[1] = '.';
|
|
|
|
}
|
|
|
|
r_core_cmd0 (core, buf);
|
|
|
|
restore_current_addr (core, addr, bsze, newaddr);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2014-02-10 02:31:12 +00:00
|
|
|
}
|
2019-04-24 12:59:26 +00:00
|
|
|
r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down);
|
2019-04-25 14:23:19 +00:00
|
|
|
core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT;
|
2014-02-10 02:31:12 +00:00
|
|
|
}
|
2013-11-07 01:07:10 +00:00
|
|
|
|
2019-05-06 14:24:31 +00:00
|
|
|
R_API int r_core_visual_prevopsz(RCore *core, ut64 addr) {
|
2016-02-10 23:18:09 +00:00
|
|
|
ut64 prev_addr = prevop_addr (core, addr);
|
2018-12-18 13:06:52 +00:00
|
|
|
return addr - prev_addr;
|
2016-02-10 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 13:57:15 +00:00
|
|
|
static void addComment(RCore *core, ut64 addr) {
|
|
|
|
char buf[1024];
|
|
|
|
r_cons_printf ("Enter comment for reference:\n");
|
|
|
|
r_core_visual_showcursor (core, true);
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (false);
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_enable_mouse (false);
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) {
|
2019-05-14 13:57:15 +00:00
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
r_core_cmdf (core, "\"CC %s\"@0x%08"PFMT64x, buf, addr);
|
|
|
|
r_core_visual_showcursor (core, false);
|
|
|
|
r_cons_set_raw (true);
|
|
|
|
}
|
|
|
|
|
2018-12-03 15:36:26 +00:00
|
|
|
static int follow_ref(RCore *core, RList *xrefs, int choice, int xref) {
|
2018-11-23 20:00:18 +00:00
|
|
|
RAnalRef *refi = r_list_get_n (xrefs, choice);
|
|
|
|
if (refi) {
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
}
|
2018-12-04 09:45:15 +00:00
|
|
|
ut64 addr = refi->addr;
|
2018-12-03 15:36:26 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset, -1);
|
|
|
|
r_core_seek (core, addr, true);
|
2018-11-23 20:00:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-25 00:55:46 +00:00
|
|
|
R_API int r_core_visual_refs(RCore *core, bool xref, bool fcnInsteadOfAddr) {
|
2019-05-14 13:57:15 +00:00
|
|
|
ut64 cur_ref_addr = UT64_MAX;
|
2014-09-22 22:40:35 +00:00
|
|
|
int ret = 0;
|
|
|
|
char ch;
|
2014-08-05 03:37:48 +00:00
|
|
|
int count = 0;
|
|
|
|
RList *xrefs = NULL;
|
|
|
|
RAnalRef *refi;
|
|
|
|
RListIter *iter;
|
2016-02-16 00:20:25 +00:00
|
|
|
int skip = 0;
|
|
|
|
int idx = 0;
|
|
|
|
char cstr[32];
|
2016-03-30 10:30:51 +00:00
|
|
|
ut64 addr = core->offset;
|
2018-11-25 00:55:46 +00:00
|
|
|
bool xrefsMode = fcnInsteadOfAddr;
|
2018-10-31 10:34:13 +00:00
|
|
|
int lastPrintMode = 3;
|
2016-03-30 10:30:51 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
addr += core->print->cur;
|
|
|
|
}
|
2016-02-16 00:20:25 +00:00
|
|
|
repeat:
|
2018-11-23 02:07:34 +00:00
|
|
|
r_list_free (xrefs);
|
2018-11-22 20:20:47 +00:00
|
|
|
if (xrefsMode) {
|
2018-11-22 21:21:06 +00:00
|
|
|
RAnalFunction *fun = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
|
2018-11-22 20:20:47 +00:00
|
|
|
if (fun) {
|
2018-12-03 15:36:26 +00:00
|
|
|
if (xref) { // function xrefs
|
2018-12-03 22:24:36 +00:00
|
|
|
xrefs = r_anal_xrefs_get (core->anal, addr);
|
|
|
|
//XXX xrefs = r_anal_fcn_get_xrefs (core->anal, fun);
|
|
|
|
// this function is buggy so we must get the xrefs of the addr
|
2018-12-03 15:36:26 +00:00
|
|
|
} else { // functon refs
|
2020-03-17 11:58:39 +00:00
|
|
|
xrefs = r_anal_function_get_refs (fun);
|
2018-11-22 20:20:47 +00:00
|
|
|
}
|
2018-11-22 02:06:36 +00:00
|
|
|
} else {
|
2018-11-22 20:20:47 +00:00
|
|
|
xrefs = NULL;
|
2018-11-22 02:06:36 +00:00
|
|
|
}
|
2017-08-16 11:47:16 +00:00
|
|
|
} else {
|
2018-12-03 15:36:26 +00:00
|
|
|
if (xref) { // address xrefs
|
2018-11-22 02:06:36 +00:00
|
|
|
xrefs = r_anal_xrefs_get (core->anal, addr);
|
2018-12-03 15:36:26 +00:00
|
|
|
} else { // address refs
|
2018-11-22 02:06:36 +00:00
|
|
|
xrefs = r_anal_refs_get (core->anal, addr);
|
|
|
|
}
|
2017-08-16 11:47:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 20:20:47 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_gotoxy (1, 1);
|
2018-12-31 02:06:05 +00:00
|
|
|
{
|
|
|
|
char *address = (core->dbg->bits & R_SYS_BITS_64)
|
|
|
|
? r_str_newf ("0x%016"PFMT64x, addr)
|
|
|
|
: r_str_newf ("0x%08"PFMT64x, addr);
|
|
|
|
r_cons_printf ("[%s%srefs]> %s # (TAB/jk/q/?) ",
|
|
|
|
xrefsMode? "fcn.": "addr.", xref ? "x": "", address);
|
|
|
|
free (address);
|
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
if (!xrefs || r_list_empty (xrefs)) {
|
|
|
|
r_list_free (xrefs);
|
|
|
|
xrefs = NULL;
|
|
|
|
r_cons_printf ("\n\n(no %srefs)\n", xref ? "x": "");
|
|
|
|
} else {
|
2018-11-24 01:52:41 +00:00
|
|
|
int h, w = r_cons_get_size (&h);
|
2016-12-26 13:05:00 +00:00
|
|
|
bool asm_bytes = r_config_get_i (core->config, "asm.bytes");
|
|
|
|
r_config_set_i (core->config, "asm.bytes", false);
|
2017-12-16 00:44:45 +00:00
|
|
|
r_core_cmd0 (core, "fd");
|
2018-11-25 01:13:28 +00:00
|
|
|
|
|
|
|
int maxcount = 9;
|
|
|
|
int rows, cols = r_cons_get_size (&rows);
|
|
|
|
count = 0;
|
|
|
|
char *dis = NULL;
|
|
|
|
rows -= 4;
|
|
|
|
idx = 0;
|
|
|
|
ut64 curat = UT64_MAX;
|
|
|
|
r_list_foreach (xrefs, iter, refi) {
|
|
|
|
if (idx - skip > maxcount) {
|
|
|
|
r_cons_printf ("...");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!iter->n && idx < skip) {
|
|
|
|
skip = idx;
|
|
|
|
}
|
|
|
|
if (idx >= skip) {
|
|
|
|
if (count > maxcount) {
|
|
|
|
strcpy (cstr, "?");
|
|
|
|
} else {
|
|
|
|
snprintf (cstr, sizeof (cstr), "%d", count);
|
2017-02-08 11:14:52 +00:00
|
|
|
}
|
2019-05-14 13:57:15 +00:00
|
|
|
if (idx == skip) {
|
|
|
|
cur_ref_addr = refi->addr;
|
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
RAnalFunction *fun = r_anal_get_fcn_in (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
char *name;
|
|
|
|
if (fun) {
|
|
|
|
name = strdup (fun->name);
|
|
|
|
} else {
|
|
|
|
RFlagItem *f = r_flag_get_at (core->flags, refi->addr, true);
|
|
|
|
if (f) {
|
2020-10-21 09:27:17 +00:00
|
|
|
name = r_str_newf ("%s + %" PFMT64d, f->name, refi->addr - f->offset);
|
2016-02-16 00:20:25 +00:00
|
|
|
} else {
|
2018-11-25 01:13:28 +00:00
|
|
|
name = strdup ("unk");
|
2016-02-16 00:20:25 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
}
|
|
|
|
if (w > 45) {
|
|
|
|
if (strlen (name) > w -45) {
|
|
|
|
name[w - 45] = 0;
|
2017-01-24 00:41:12 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
} else {
|
|
|
|
name[0] = 0;
|
|
|
|
}
|
2019-06-16 18:58:40 +00:00
|
|
|
char *cmt = r_core_cmd_strf (core, "CC.@0x%08"PFMT64x, refi->addr);
|
|
|
|
r_str_trim (cmt);
|
2019-05-14 13:57:15 +00:00
|
|
|
r_cons_printf (" %d [%s] 0x%08"PFMT64x" 0x%08"PFMT64x " %s %sref (%s) ; %s\n",
|
2018-11-25 01:13:28 +00:00
|
|
|
idx, cstr, refi->at, refi->addr,
|
|
|
|
r_anal_xrefs_type_tostring (refi->type),
|
2019-05-14 13:57:15 +00:00
|
|
|
xref ? "x":"", name, cmt);
|
|
|
|
free (cmt);
|
2018-11-25 01:13:28 +00:00
|
|
|
free (name);
|
|
|
|
if (idx == skip) {
|
|
|
|
free (dis);
|
|
|
|
curat = refi->addr;
|
2019-04-24 00:16:54 +00:00
|
|
|
char *res = r_core_cmd_strf (core, "pd 4 @ 0x%08"PFMT64x"@e:asm.flags.limit=1", refi->at);
|
2018-11-25 01:13:28 +00:00
|
|
|
// TODO: show disasm with context. not seek addr
|
|
|
|
// dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr);
|
|
|
|
dis = NULL;
|
|
|
|
res = r_str_appendf (res, "; ---------------------------\n");
|
|
|
|
switch (printMode) {
|
|
|
|
case 0:
|
|
|
|
dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dis = r_core_cmd_strf (core, "pd @ 0x%08"PFMT64x"-32", refi->addr);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dis = r_core_cmd_strf (core, "px @ 0x%08"PFMT64x, refi->addr);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
dis = r_core_cmd_strf (core, "pds @ 0x%08"PFMT64x, refi->addr);
|
|
|
|
break;
|
2018-11-24 01:52:41 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
if (dis) {
|
|
|
|
res = r_str_append (res, dis);
|
2017-02-08 11:14:52 +00:00
|
|
|
free (dis);
|
2016-02-16 00:20:25 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
dis = res;
|
2016-02-16 00:20:25 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
if (++count >= rows) {
|
|
|
|
r_cons_printf ("...");
|
|
|
|
break;
|
2018-11-23 02:07:34 +00:00
|
|
|
}
|
2017-02-08 11:14:52 +00:00
|
|
|
}
|
2018-11-25 01:13:28 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
if (dis) {
|
|
|
|
if (count < rows) {
|
|
|
|
r_cons_newline ();
|
|
|
|
}
|
|
|
|
int i = count;
|
|
|
|
for (; i < 9; i++) {
|
|
|
|
r_cons_newline ();
|
|
|
|
}
|
|
|
|
/* prepare highlight */
|
|
|
|
char *cmd = strdup (r_config_get (core->config, "scr.highlight"));
|
|
|
|
char *ats = r_str_newf ("%"PFMT64x, curat);
|
2020-02-13 19:38:52 +00:00
|
|
|
if (ats && !*cmd) {
|
2018-11-25 01:13:28 +00:00
|
|
|
(void) r_config_set (core->config, "scr.highlight", ats);
|
|
|
|
}
|
|
|
|
/* print disasm */
|
|
|
|
char *d = r_str_ansi_crop (dis, 0, 0, cols, rows - 9);
|
|
|
|
if (d) {
|
|
|
|
r_cons_printf ("%s", d);
|
|
|
|
free (d);
|
|
|
|
}
|
|
|
|
/* flush and restore highlight */
|
|
|
|
r_cons_flush ();
|
|
|
|
r_config_set (core->config, "scr.highlight", cmd);
|
|
|
|
free (ats);
|
|
|
|
free (cmd);
|
|
|
|
free (dis);
|
|
|
|
dis = NULL;
|
2014-08-05 03:37:48 +00:00
|
|
|
}
|
2016-12-26 13:05:00 +00:00
|
|
|
r_config_set_i (core->config, "asm.bytes", asm_bytes);
|
2014-08-17 18:30:28 +00:00
|
|
|
}
|
2014-08-05 03:37:48 +00:00
|
|
|
r_cons_flush ();
|
2019-07-02 01:33:57 +00:00
|
|
|
r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel"));
|
2014-08-05 03:37:48 +00:00
|
|
|
ch = r_cons_readchar ();
|
2018-08-01 20:05:24 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
2016-12-26 13:05:00 +00:00
|
|
|
if (ch == ':') {
|
|
|
|
r_core_visual_prompt_input (core);
|
2018-12-03 15:36:26 +00:00
|
|
|
goto repeat;
|
2017-12-16 00:44:45 +00:00
|
|
|
} else if (ch == '?') {
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf ("Usage: Visual Xrefs\n"
|
|
|
|
" jk - select next or previous item (use arrows)\n"
|
2018-11-23 02:07:34 +00:00
|
|
|
" JK - step 10 rows\n"
|
2017-12-16 00:44:45 +00:00
|
|
|
" pP - rotate between various print modes\n"
|
|
|
|
" : - run r2 command\n"
|
2020-02-13 19:38:52 +00:00
|
|
|
" / - highlight given word\n"
|
2017-12-16 00:44:45 +00:00
|
|
|
" ? - show this help message\n"
|
2018-12-02 23:47:16 +00:00
|
|
|
" <> - '<' for xrefs and '>' for refs\n"
|
2018-11-22 20:20:47 +00:00
|
|
|
" TAB - toggle between address and function references\n"
|
|
|
|
" xX - switch to refs or xrefs\n"
|
|
|
|
" q - quit this view\n"
|
2017-12-16 00:44:45 +00:00
|
|
|
" \\n - seek to this xref");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
goto repeat;
|
2018-11-22 20:20:47 +00:00
|
|
|
} else if (ch == 9) { // TAB
|
|
|
|
xrefsMode = !xrefsMode;
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, true);
|
2018-11-22 20:20:47 +00:00
|
|
|
goto repeat;
|
2017-12-16 00:44:45 +00:00
|
|
|
} else if (ch == 'p') {
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, true);
|
2017-12-16 00:44:45 +00:00
|
|
|
printMode++;
|
|
|
|
if (printMode > lastPrintMode) {
|
|
|
|
printMode = 0;
|
|
|
|
}
|
|
|
|
goto repeat;
|
|
|
|
} else if (ch == 'P') {
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, true);
|
2017-12-16 00:44:45 +00:00
|
|
|
printMode--;
|
2018-12-02 23:46:51 +00:00
|
|
|
if (printMode < 0) {
|
2017-12-16 00:44:45 +00:00
|
|
|
printMode = lastPrintMode;
|
|
|
|
}
|
|
|
|
goto repeat;
|
2020-02-13 19:38:52 +00:00
|
|
|
} else if (ch == '/') {
|
|
|
|
r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`");
|
|
|
|
goto repeat;
|
2018-12-03 15:36:26 +00:00
|
|
|
} else if (ch == 'x' || ch == '<') {
|
2018-11-22 20:20:47 +00:00
|
|
|
xref = true;
|
2018-12-03 22:24:36 +00:00
|
|
|
xrefsMode = !xrefsMode;
|
2018-11-22 20:20:47 +00:00
|
|
|
goto repeat;
|
2018-12-03 15:36:26 +00:00
|
|
|
} else if (ch == 'X' || ch == '>') {
|
2018-11-22 20:20:47 +00:00
|
|
|
xref = false;
|
2018-12-03 15:36:26 +00:00
|
|
|
xrefsMode = !xrefsMode;
|
2018-11-22 20:20:47 +00:00
|
|
|
goto repeat;
|
2018-11-23 02:07:34 +00:00
|
|
|
} else if (ch == 'J') {
|
|
|
|
skip += 10;
|
|
|
|
goto repeat;
|
|
|
|
} else if (ch == 'g') {
|
|
|
|
skip = 0;
|
|
|
|
goto repeat;
|
|
|
|
} else if (ch == 'G') {
|
|
|
|
skip = 9999;
|
|
|
|
goto repeat;
|
2019-05-14 13:57:15 +00:00
|
|
|
} else if (ch == ';') {
|
|
|
|
addComment (core, cur_ref_addr);
|
|
|
|
goto repeat;
|
2018-12-03 15:36:26 +00:00
|
|
|
} else if (ch == '.') {
|
|
|
|
skip = 0;
|
|
|
|
goto repeat;
|
2018-08-01 20:05:24 +00:00
|
|
|
} else if (ch == 'j') {
|
2016-02-16 00:20:25 +00:00
|
|
|
skip++;
|
|
|
|
goto repeat;
|
2018-11-23 02:07:34 +00:00
|
|
|
} else if (ch == 'K') {
|
|
|
|
skip = (skip < 10) ? 0: skip - 10;
|
|
|
|
goto repeat;
|
2018-08-01 20:05:24 +00:00
|
|
|
} else if (ch == 'k') {
|
2016-02-16 00:20:25 +00:00
|
|
|
skip--;
|
2016-08-22 16:44:52 +00:00
|
|
|
if (skip < 0) {
|
|
|
|
skip = 0;
|
|
|
|
}
|
2016-02-16 00:20:25 +00:00
|
|
|
goto repeat;
|
2018-12-02 23:47:16 +00:00
|
|
|
} else if (ch == ' ' || ch == '\n' || ch == '\r' || ch == 'l') {
|
2018-12-03 15:36:26 +00:00
|
|
|
ret = follow_ref (core, xrefs, skip, xref);
|
2017-02-22 22:45:51 +00:00
|
|
|
} else if (IS_DIGIT (ch)) {
|
2018-12-03 15:36:26 +00:00
|
|
|
ret = follow_ref (core, xrefs, ch - 0x30, xref);
|
2018-12-02 23:47:16 +00:00
|
|
|
} else if (ch != 'q' && ch != 'Q' && ch != 'h') {
|
2018-08-01 20:05:24 +00:00
|
|
|
goto repeat;
|
2014-08-05 03:37:48 +00:00
|
|
|
}
|
|
|
|
r_list_free (xrefs);
|
2020-03-30 13:14:12 +00:00
|
|
|
|
2014-08-05 03:37:48 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-15 04:55:08 +00:00
|
|
|
#if __WINDOWS__
|
2015-04-07 13:23:03 +00:00
|
|
|
void SetWindow(int Width, int Height) {
|
2015-11-18 12:03:35 +00:00
|
|
|
COORD coord;
|
|
|
|
coord.X = Width;
|
|
|
|
coord.Y = Height;
|
2015-04-07 13:23:03 +00:00
|
|
|
|
2015-11-18 12:03:35 +00:00
|
|
|
SMALL_RECT Rect;
|
|
|
|
Rect.Top = 0;
|
|
|
|
Rect.Left = 0;
|
|
|
|
Rect.Bottom = Height - 1;
|
|
|
|
Rect.Right = Width - 1;
|
2015-04-07 13:23:03 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
HANDLE Handle = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
SetConsoleScreenBufferSize (Handle, coord);
|
|
|
|
SetConsoleWindowInfo (Handle, TRUE, &Rect);
|
2015-04-07 13:23:03 +00:00
|
|
|
}
|
2015-04-07 14:25:14 +00:00
|
|
|
#endif
|
2015-04-07 13:23:03 +00:00
|
|
|
|
2015-11-18 16:02:42 +00:00
|
|
|
// unnecesarily public
|
|
|
|
char *getcommapath(RCore *core) {
|
|
|
|
char *cwd;
|
2015-11-18 12:03:35 +00:00
|
|
|
const char *dir = r_config_get (core->config, "dir.projects");
|
2016-10-17 21:58:39 +00:00
|
|
|
const char *prj = r_config_get (core->config, "prj.name");
|
2015-11-18 12:03:35 +00:00
|
|
|
if (dir && *dir && prj && *prj) {
|
2015-11-25 11:49:02 +00:00
|
|
|
char *abspath = r_file_abspath (dir);
|
2015-11-18 12:03:35 +00:00
|
|
|
/* use prjdir as base directory for comma-ent files */
|
2017-02-22 22:45:51 +00:00
|
|
|
cwd = r_str_newf ("%s"R_SYS_DIR "%s.d", abspath, prj);
|
2015-11-24 17:26:10 +00:00
|
|
|
free (abspath);
|
2015-11-18 12:03:35 +00:00
|
|
|
} else {
|
|
|
|
/* use cwd as base directory for comma-ent files */
|
2015-11-18 16:02:42 +00:00
|
|
|
cwd = r_sys_getdir ();
|
2015-11-18 12:03:35 +00:00
|
|
|
}
|
2015-11-18 16:02:42 +00:00
|
|
|
return cwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_comma(RCore *core) {
|
2019-08-30 17:43:12 +00:00
|
|
|
bool mouse_state = __holdMouseState (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
ut64 addr = core->offset + (core->print->cur_enabled? core->print->cur: 0);
|
2015-11-18 16:02:42 +00:00
|
|
|
char *comment, *cwd, *cmtfile;
|
2020-05-09 18:49:28 +00:00
|
|
|
const char *prev_cmt = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
|
|
|
comment = prev_cmt ? strdup (prev_cmt) : NULL;
|
2015-11-18 16:02:42 +00:00
|
|
|
cmtfile = r_str_between (comment, ",(", ")");
|
|
|
|
cwd = getcommapath (core);
|
2015-11-18 12:03:35 +00:00
|
|
|
if (!cmtfile) {
|
|
|
|
char *fn;
|
2015-11-18 22:32:18 +00:00
|
|
|
fn = r_cons_input ("<comment-file> ");
|
2015-11-18 12:03:35 +00:00
|
|
|
if (fn && *fn) {
|
|
|
|
cmtfile = strdup (fn);
|
|
|
|
if (!comment || !*comment) {
|
2015-11-18 16:02:42 +00:00
|
|
|
comment = r_str_newf (",(%s)", fn);
|
2015-11-18 12:03:35 +00:00
|
|
|
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment);
|
|
|
|
} else {
|
|
|
|
// append filename in current comment
|
2015-11-18 16:02:42 +00:00
|
|
|
char *nc = r_str_newf ("%s ,(%s)", comment, fn);
|
2015-11-18 12:03:35 +00:00
|
|
|
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc);
|
|
|
|
free (nc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (fn);
|
|
|
|
}
|
|
|
|
if (cmtfile) {
|
2017-02-22 22:45:51 +00:00
|
|
|
char *cwf = r_str_newf ("%s"R_SYS_DIR "%s", cwd, cmtfile);
|
2015-11-18 12:03:35 +00:00
|
|
|
char *odata = r_file_slurp (cwf, NULL);
|
2019-12-15 16:31:23 +00:00
|
|
|
if (!odata) {
|
|
|
|
eprintf ("Could not open '%s'.\n", cwf);
|
|
|
|
free (cwf);
|
|
|
|
goto beach;
|
|
|
|
}
|
2015-11-18 12:03:35 +00:00
|
|
|
char *data = r_core_editor (core, NULL, odata);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_file_dump (cwf, (const ut8 *) data, -1, 0);
|
2015-11-18 12:03:35 +00:00
|
|
|
free (data);
|
|
|
|
free (odata);
|
|
|
|
free (cwf);
|
|
|
|
} else {
|
2015-11-18 16:02:42 +00:00
|
|
|
eprintf ("No commafile found.\n");
|
2015-11-18 12:03:35 +00:00
|
|
|
}
|
2019-12-15 16:31:23 +00:00
|
|
|
beach:
|
2015-11-18 12:03:35 +00:00
|
|
|
free (comment);
|
2019-08-30 17:43:12 +00:00
|
|
|
r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel"));
|
2015-11-18 12:03:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 23:37:33 +00:00
|
|
|
static bool isDisasmPrint(int mode) {
|
2019-11-27 15:06:18 +00:00
|
|
|
return (mode == R_CORE_VISUAL_MODE_PD || mode == R_CORE_VISUAL_MODE_DB);
|
2015-12-14 23:37:33 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 23:10:48 +00:00
|
|
|
static void cursor_ocur(RCore *core, bool use_ocur) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
if (use_ocur && p->ocur == -1) {
|
|
|
|
p->ocur = p->cur;
|
|
|
|
} else if (!use_ocur) {
|
|
|
|
p->ocur = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 13:15:38 +00:00
|
|
|
static void nextOpcode(RCore *core) {
|
|
|
|
RAnalOp *aop = r_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC);
|
|
|
|
RPrint *p = core->print;
|
|
|
|
if (aop) {
|
|
|
|
p->cur += aop->size;
|
|
|
|
r_anal_op_free (aop);
|
|
|
|
} else {
|
|
|
|
p->cur += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prevOpcode(RCore *core) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
ut64 addr, oaddr = core->offset + core->print->cur;
|
|
|
|
if (r_core_prevop_addr (core, oaddr, 1, &addr)) {
|
|
|
|
const int delta = oaddr - addr;
|
|
|
|
p->cur -= delta;
|
|
|
|
} else {
|
|
|
|
p->cur -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 23:10:48 +00:00
|
|
|
static void cursor_nextrow(RCore *core, bool use_ocur) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
ut32 roff, next_roff;
|
|
|
|
int row, sz, delta;
|
|
|
|
RAsmOp op;
|
|
|
|
|
2019-07-06 13:36:09 +00:00
|
|
|
cursor_ocur (core, use_ocur);
|
2019-04-24 13:15:38 +00:00
|
|
|
if (PIDX == 1) { // DISASM
|
|
|
|
nextOpcode (core);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 02:36:34 +00:00
|
|
|
if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) {
|
2019-04-29 09:51:13 +00:00
|
|
|
p->cur += r_config_get_i (core->config, "hex.cols");
|
2017-05-29 02:36:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-03 12:52:46 +00:00
|
|
|
if (splitView) {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
if (core->seltab == 0) {
|
|
|
|
splitPtr += w;
|
|
|
|
} else {
|
|
|
|
core->offset += w;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-04-24 12:59:26 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
const int cols = core->dbg->regcols;
|
2016-11-24 22:25:49 +00:00
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
2019-04-24 12:59:26 +00:00
|
|
|
switch (core->seltab) {
|
|
|
|
case 0:
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
r_config_set_i (core->config, "stack.delta",
|
|
|
|
r_config_get_i (core->config, "stack.delta") - w);
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
p->cur += cols > 0? cols: 3;
|
|
|
|
return;
|
2019-04-24 13:15:38 +00:00
|
|
|
default:
|
|
|
|
nextOpcode (core);
|
|
|
|
return;
|
2016-11-24 22:25:49 +00:00
|
|
|
}
|
2018-05-07 08:01:25 +00:00
|
|
|
}
|
2017-05-29 09:45:13 +00:00
|
|
|
if (p->row_offsets) {
|
2016-02-10 23:10:48 +00:00
|
|
|
// FIXME: cache the current row
|
|
|
|
row = r_print_row_at_off (p, p->cur);
|
|
|
|
roff = r_print_rowoff (p, row);
|
|
|
|
if (roff == -1) {
|
|
|
|
p->cur++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next_roff = r_print_rowoff (p, row + 1);
|
2019-02-17 23:50:02 +00:00
|
|
|
if (next_roff == UT32_MAX) {
|
2016-02-10 23:10:48 +00:00
|
|
|
p->cur++;
|
|
|
|
return;
|
|
|
|
}
|
2019-02-17 23:50:02 +00:00
|
|
|
if (next_roff > core->blocksize) {
|
|
|
|
p->cur += 32; // XXX workaround to "fix" cursor nextrow far away scrolling issue
|
|
|
|
return;
|
|
|
|
}
|
2016-03-06 22:23:39 +00:00
|
|
|
if (next_roff + 32 < core->blocksize) {
|
2020-05-12 23:28:23 +00:00
|
|
|
sz = r_asm_disassemble (core->rasm, &op,
|
2017-02-22 22:45:51 +00:00
|
|
|
core->block + next_roff, 32);
|
|
|
|
if (sz < 1) {
|
|
|
|
sz = 1;
|
|
|
|
}
|
2016-03-06 22:23:39 +00:00
|
|
|
} else {
|
|
|
|
sz = 1;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
delta = p->cur - roff;
|
2018-02-22 16:46:26 +00:00
|
|
|
p->cur = next_roff + R_MIN (delta, sz - 1);
|
2016-02-10 23:10:48 +00:00
|
|
|
} else {
|
|
|
|
p->cur += R_MAX (1, p->cols);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_prevrow(RCore *core, bool use_ocur) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
ut32 roff, prev_roff;
|
2016-03-01 23:49:43 +00:00
|
|
|
int row;
|
2016-02-10 23:10:48 +00:00
|
|
|
|
2019-07-06 13:36:09 +00:00
|
|
|
cursor_ocur (core, use_ocur);
|
2019-04-24 13:15:38 +00:00
|
|
|
if (PIDX == 1) { // DISASM
|
|
|
|
prevOpcode (core);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-29 02:36:34 +00:00
|
|
|
if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) {
|
2019-04-29 09:51:13 +00:00
|
|
|
int cols = r_config_get_i (core->config, "hex.cols");
|
2017-06-28 00:21:16 +00:00
|
|
|
p->cur -= R_MAX (cols, 0);
|
2017-05-29 02:36:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-06 13:36:09 +00:00
|
|
|
|
2017-08-03 12:52:46 +00:00
|
|
|
if (splitView) {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
if (core->seltab == 0) {
|
|
|
|
splitPtr -= w;
|
|
|
|
} else {
|
|
|
|
core->offset -= w;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-04-24 13:15:38 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
switch (core->seltab) {
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
r_config_set_i (core->config, "stack.delta",
|
|
|
|
r_config_get_i (core->config, "stack.delta") + w);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
const int cols = core->dbg->regcols;
|
|
|
|
p->cur -= cols > 0? cols: 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
prevOpcode (core);
|
|
|
|
return;
|
2016-11-24 22:25:49 +00:00
|
|
|
}
|
2018-05-07 08:01:25 +00:00
|
|
|
}
|
2019-04-24 12:59:26 +00:00
|
|
|
if (p->row_offsets) {
|
2016-02-10 23:10:48 +00:00
|
|
|
int delta, prev_sz;
|
|
|
|
|
|
|
|
// FIXME: cache the current row
|
|
|
|
row = r_print_row_at_off (p, p->cur);
|
|
|
|
roff = r_print_rowoff (p, row);
|
|
|
|
if (roff == UT32_MAX) {
|
|
|
|
p->cur--;
|
|
|
|
return;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
prev_roff = row > 0? r_print_rowoff (p, row - 1): UT32_MAX;
|
2016-02-10 23:10:48 +00:00
|
|
|
delta = p->cur - roff;
|
|
|
|
if (prev_roff == UT32_MAX) {
|
2016-02-10 23:18:09 +00:00
|
|
|
ut64 prev_addr = prevop_addr (core, core->offset + roff);
|
2016-03-07 02:35:13 +00:00
|
|
|
if (prev_addr > core->offset) {
|
|
|
|
prev_roff = 0;
|
|
|
|
prev_sz = 1;
|
|
|
|
} else {
|
|
|
|
RAsmOp op;
|
|
|
|
prev_roff = 0;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, prev_addr, true);
|
2020-05-12 23:28:23 +00:00
|
|
|
prev_sz = r_asm_disassemble (core->rasm, &op,
|
2017-02-22 22:45:51 +00:00
|
|
|
core->block, 32);
|
2016-03-07 02:35:13 +00:00
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
} else {
|
|
|
|
prev_sz = roff - prev_roff;
|
|
|
|
}
|
2017-06-28 00:21:16 +00:00
|
|
|
int res = R_MIN (delta, prev_sz - 1);
|
|
|
|
ut64 cur = prev_roff + res;
|
|
|
|
if (cur == p->cur) {
|
|
|
|
if (p->cur > 0) {
|
|
|
|
p->cur--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p->cur = prev_roff + delta; //res;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
} else {
|
|
|
|
p->cur -= p->cols;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_left(RCore *core, bool use_ocur) {
|
2016-02-25 10:35:59 +00:00
|
|
|
if (PIDX == 2) {
|
|
|
|
if (core->seltab == 1) {
|
2016-03-07 02:35:13 +00:00
|
|
|
core->print->cur--;
|
2016-02-25 10:35:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
cursor_ocur (core, use_ocur);
|
|
|
|
core->print->cur--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_right(RCore *core, bool use_ocur) {
|
2016-02-25 10:35:59 +00:00
|
|
|
if (PIDX == 2) {
|
|
|
|
if (core->seltab == 1) {
|
|
|
|
core->print->cur++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
cursor_ocur (core, use_ocur);
|
|
|
|
core->print->cur++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool fix_cursor(RCore *core) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
int offscreen = (core->cons->rows - 3) * p->cols;
|
|
|
|
bool res = false;
|
|
|
|
|
2016-06-02 01:19:31 +00:00
|
|
|
if (!core->print->cur_enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-10 20:15:24 +00:00
|
|
|
if (core->print->screen_bounds > 1) {
|
|
|
|
bool off_is_visible = core->offset < core->print->screen_bounds;
|
|
|
|
bool cur_is_visible = core->offset + p->cur < core->print->screen_bounds;
|
|
|
|
bool is_close = core->offset + p->cur < core->print->screen_bounds + 32;
|
2016-02-10 23:10:48 +00:00
|
|
|
|
2016-05-18 23:45:02 +00:00
|
|
|
if ((!cur_is_visible && !is_close) || (!cur_is_visible && p->cur == 0)) {
|
2016-02-10 23:10:48 +00:00
|
|
|
// when the cursor is not visible and it's far from the
|
|
|
|
// last visible byte, just seek there.
|
2016-03-07 02:35:13 +00:00
|
|
|
r_core_seek_delta (core, p->cur);
|
2016-03-01 23:49:43 +00:00
|
|
|
reset_print_cur (p);
|
2016-02-10 23:10:48 +00:00
|
|
|
} else if ((!cur_is_visible && is_close) || !off_is_visible) {
|
|
|
|
RAsmOp op;
|
2020-05-12 23:28:23 +00:00
|
|
|
int sz = r_asm_disassemble (core->rasm,
|
2016-02-10 23:10:48 +00:00
|
|
|
&op, core->block, 32);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (sz < 1) {
|
|
|
|
sz = 1;
|
|
|
|
}
|
2016-03-07 02:35:13 +00:00
|
|
|
r_core_seek_delta (core, sz);
|
2016-02-10 23:10:48 +00:00
|
|
|
p->cur = R_MAX (p->cur - sz, 0);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (p->ocur != -1) {
|
|
|
|
p->ocur = R_MAX (p->ocur - sz, 0);
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
res |= off_is_visible;
|
|
|
|
}
|
|
|
|
} else if (core->print->cur >= offscreen) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + p->cols, true);
|
2016-02-10 23:10:48 +00:00
|
|
|
p->cur -= p->cols;
|
2017-02-22 22:45:51 +00:00
|
|
|
if (p->ocur != -1) {
|
|
|
|
p->ocur -= p->cols;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p->cur < 0) {
|
|
|
|
int sz = p->cols;
|
|
|
|
if (isDisasmPrint (core->printidx)) {
|
2019-05-06 14:24:31 +00:00
|
|
|
sz = r_core_visual_prevopsz (core, core->offset + p->cur);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (sz < 1) {
|
|
|
|
sz = 1;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
|
|
|
r_core_seek_delta (core, -sz);
|
|
|
|
p->cur += sz;
|
2017-02-22 22:45:51 +00:00
|
|
|
if (p->ocur != -1) {
|
|
|
|
p->ocur += sz;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-07-25 03:14:48 +00:00
|
|
|
static bool __ime = false;
|
|
|
|
static int __nib = -1;
|
|
|
|
|
|
|
|
static bool insert_mode_enabled(RCore *core) {
|
|
|
|
if (!__ime) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-24 00:23:25 +00:00
|
|
|
char ch = (ut8)r_cons_readchar ();
|
|
|
|
if ((ut8)ch == KEY_ALTQ) {
|
|
|
|
(void)r_cons_readchar ();
|
|
|
|
__ime = false;
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-25 03:14:48 +00:00
|
|
|
char arrows = r_cons_arrow_to_hjkl (ch);
|
|
|
|
switch (ch) {
|
|
|
|
case 127:
|
|
|
|
core->print->cur = R_MAX (0, core->print->cur - 1);
|
|
|
|
return true;
|
2019-03-05 10:08:41 +00:00
|
|
|
case 9: // tab "tab" TAB
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->col = core->print->col == 1? 2: 1;
|
2016-07-25 03:14:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ch != 'h' && arrows == 'h') {
|
|
|
|
core->print->cur = R_MAX (0, core->print->cur - 1);
|
|
|
|
return true;
|
|
|
|
} else if (ch != 'l' && arrows == 'l') {
|
|
|
|
core->print->cur = core->print->cur + 1;
|
|
|
|
return true;
|
|
|
|
} else if (ch != 'j' && arrows == 'j') {
|
|
|
|
cursor_nextrow (core, false);
|
|
|
|
return true;
|
|
|
|
} else if (ch != 'k' && arrows == 'k') {
|
|
|
|
cursor_prevrow (core, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (core->print->col == 2) {
|
|
|
|
/* ascii column */
|
|
|
|
if (IS_PRINTABLE (ch)) {
|
|
|
|
r_core_cmdf (core, "\"w %c\" @ $$+%d", ch, core->print->cur);
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur++;
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ch = arrows;
|
|
|
|
/* hex column */
|
|
|
|
switch (ch) {
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
|
|
|
case 'a':
|
|
|
|
case 'b':
|
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'e':
|
|
|
|
case 'f':
|
|
|
|
if (__nib != -1) {
|
|
|
|
r_core_cmdf (core, "wx %c%c @ $$+%d", __nib, ch, core->print->cur);
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur++;
|
2016-07-25 03:14:48 +00:00
|
|
|
__nib = -1;
|
|
|
|
} else {
|
|
|
|
r_core_cmdf (core, "wx %c. @ $$+%d", ch, core->print->cur);
|
|
|
|
__nib = ch;
|
|
|
|
}
|
|
|
|
break;
|
2016-11-24 03:44:25 +00:00
|
|
|
case 'r':
|
|
|
|
r_core_cmdf (core, "r-1 @ 0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
r_core_cmdf (core, "r+1 @ 0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
break;
|
2016-07-25 03:14:48 +00:00
|
|
|
case 'h':
|
|
|
|
core->print->cur = R_MAX (0, core->print->cur - 1);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
core->print->cur = core->print->cur + 1;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
cursor_nextrow (core, false);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
cursor_prevrow (core, false);
|
|
|
|
break;
|
2016-12-19 03:46:50 +00:00
|
|
|
case 'Q':
|
2016-07-25 03:14:48 +00:00
|
|
|
case 'q':
|
|
|
|
__ime = false;
|
|
|
|
break;
|
2016-11-24 03:44:25 +00:00
|
|
|
case '?':
|
|
|
|
r_cons_less_str ("\nVisual Insert Mode:\n\n"
|
2017-03-24 00:23:25 +00:00
|
|
|
" tab - toggle between ascii and hex columns\n"
|
|
|
|
" q (or alt-q) - quit insert mode\n"
|
2016-11-24 03:44:25 +00:00
|
|
|
"\nHex column:\n"
|
2017-03-24 00:23:25 +00:00
|
|
|
" r - remove byte in cursor\n"
|
|
|
|
" R - insert byte in cursor\n"
|
|
|
|
" [0-9a-f] - insert hexpairs in hex column\n"
|
|
|
|
" hjkl - move around\n"
|
2016-11-24 03:44:25 +00:00
|
|
|
"\nAscii column:\n"
|
2017-03-24 00:23:25 +00:00
|
|
|
" arrows - move around\n"
|
|
|
|
" alt-q - quit insert mode\n"
|
2017-02-22 22:45:51 +00:00
|
|
|
, "?");
|
2016-11-24 03:44:25 +00:00
|
|
|
break;
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-14 00:35:17 +00:00
|
|
|
R_API void r_core_visual_browse(RCore *core, const char *input) {
|
2017-10-16 20:31:29 +00:00
|
|
|
const char *browsemsg = \
|
|
|
|
"Browse stuff:\n"
|
|
|
|
"-------------\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" _ hud mode (V_)\n"
|
2019-04-28 10:47:42 +00:00
|
|
|
" 1 bit editor (vd1)\n"
|
2017-10-16 14:15:15 +00:00
|
|
|
" b blocks\n"
|
2020-04-04 08:58:08 +00:00
|
|
|
" a anal classes\n"
|
2017-10-16 14:15:15 +00:00
|
|
|
" c classes\n"
|
2018-02-21 02:10:38 +00:00
|
|
|
" C comments\n"
|
2019-03-23 13:59:15 +00:00
|
|
|
" d debug traces\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" e eval var configurations\n"
|
2019-04-29 09:44:39 +00:00
|
|
|
" E esil debugger mode\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" f flags\n"
|
|
|
|
" F functions\n"
|
2019-01-11 08:56:27 +00:00
|
|
|
" g graph\n"
|
2018-01-24 09:47:33 +00:00
|
|
|
" h history\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" i imports\n"
|
2018-08-16 09:01:53 +00:00
|
|
|
" l chat logs (previously VT)\n"
|
2017-10-16 14:15:15 +00:00
|
|
|
" m maps\n"
|
2019-03-20 01:01:17 +00:00
|
|
|
" M mountpoints\n"
|
2018-02-04 12:04:34 +00:00
|
|
|
" p pids/threads\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" q quit\n"
|
2019-03-05 10:08:41 +00:00
|
|
|
" r ROP gadgets\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" s symbols\n"
|
|
|
|
" t types\n"
|
2018-02-24 18:44:09 +00:00
|
|
|
" T themes\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" v vars\n"
|
2017-10-16 14:15:15 +00:00
|
|
|
" x xrefs\n"
|
|
|
|
" X refs\n"
|
2019-03-05 10:08:41 +00:00
|
|
|
" z browse function zignatures\n"
|
2018-06-27 22:54:50 +00:00
|
|
|
" : run command\n"
|
2017-10-16 14:15:15 +00:00
|
|
|
;
|
2017-10-16 20:31:29 +00:00
|
|
|
for (;;) {
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf ("%s\n", browsemsg);
|
|
|
|
r_cons_flush ();
|
2019-01-14 00:35:17 +00:00
|
|
|
char ch = 0;
|
|
|
|
if (input && *input) {
|
|
|
|
ch = *input;
|
|
|
|
input++;
|
|
|
|
} else {
|
|
|
|
ch = r_cons_readchar ();
|
|
|
|
}
|
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
2017-10-16 20:31:29 +00:00
|
|
|
switch (ch) {
|
2019-04-28 10:47:42 +00:00
|
|
|
case '1':
|
|
|
|
r_core_visual_bit_editor (core);
|
|
|
|
break;
|
2019-03-20 01:01:17 +00:00
|
|
|
case 'M':
|
|
|
|
if (!r_list_empty (core->fs->roots)) {
|
|
|
|
r_core_visual_mounts (core);
|
|
|
|
}
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'z': // "vbz"
|
2019-01-26 00:15:12 +00:00
|
|
|
if (r_core_visual_view_zigns (core)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'g': // "vbg"
|
2019-01-24 10:50:37 +00:00
|
|
|
if (r_core_visual_view_graph (core)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-11 08:56:27 +00:00
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'r': // "vbr"
|
2019-01-14 00:09:30 +00:00
|
|
|
r_core_visual_view_rop (core);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'f': // "vbf"
|
2017-10-16 20:31:29 +00:00
|
|
|
r_core_visual_trackflags (core);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'F': // "vbF"
|
2018-11-25 00:23:33 +00:00
|
|
|
r_core_visual_anal (core, NULL);
|
2018-06-27 22:54:50 +00:00
|
|
|
// r_core_cmd0 (core, "s $(afl~...)");
|
2018-02-21 01:17:31 +00:00
|
|
|
break;
|
2019-03-23 13:59:15 +00:00
|
|
|
case 'd': // "vbd"
|
|
|
|
r_core_visual_debugtraces (core, NULL);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'v': // "vbv"
|
2018-11-25 00:23:33 +00:00
|
|
|
r_core_visual_anal (core, "v");
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'e': // "vbe"
|
2018-08-23 13:07:21 +00:00
|
|
|
r_core_visual_config (core);
|
|
|
|
break;
|
2019-04-29 09:44:39 +00:00
|
|
|
case 'E': // "vbe"
|
|
|
|
r_core_visual_esil (core);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'c': // "vbc"
|
2017-10-16 20:31:29 +00:00
|
|
|
r_core_visual_classes (core);
|
|
|
|
break;
|
2020-04-04 08:58:08 +00:00
|
|
|
case 'a': // "vba"
|
|
|
|
r_core_visual_anal_classes (core);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'C': // "vbC"
|
2018-04-11 01:00:05 +00:00
|
|
|
r_core_visual_comments (core);
|
|
|
|
//r_core_cmd0 (core, "s $(CC~...)");
|
2018-02-21 02:10:38 +00:00
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 't': // "vbt"
|
2017-10-16 20:31:29 +00:00
|
|
|
r_core_visual_types (core);
|
|
|
|
break;
|
2019-02-04 00:41:11 +00:00
|
|
|
case 'T': // "vbT"
|
2018-02-24 18:44:09 +00:00
|
|
|
r_core_cmd0 (core, "eco $(eco~...)");
|
|
|
|
break;
|
2018-08-16 09:01:53 +00:00
|
|
|
case 'l': // previously VT
|
|
|
|
if (r_sandbox_enable (0)) {
|
|
|
|
eprintf ("sandbox not enabled\n");
|
|
|
|
} else {
|
2019-02-18 05:20:01 +00:00
|
|
|
if (r_cons_is_interactive ()) {
|
2018-08-16 09:01:53 +00:00
|
|
|
r_core_cmd0 (core, "TT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-02-04 12:04:34 +00:00
|
|
|
case 'p':
|
|
|
|
r_core_cmd0 (core, "dpt=$(dpt~[1-])");
|
|
|
|
break;
|
2017-10-16 20:31:29 +00:00
|
|
|
case 'b':
|
|
|
|
r_core_cmd0 (core, "s $(afb~...)");
|
|
|
|
break;
|
2018-01-24 09:47:33 +00:00
|
|
|
case 'i':
|
|
|
|
// XXX ii shows index first and iiq shows no offset :(
|
|
|
|
r_core_cmd0 (core, "s $(ii~...)");
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
r_core_cmd0 (core, "s $(isq~...)");
|
|
|
|
break;
|
2017-10-16 20:31:29 +00:00
|
|
|
case 'm':
|
|
|
|
r_core_cmd0 (core, "s $(dm~...)");
|
|
|
|
break;
|
|
|
|
case 'x':
|
2018-11-25 00:55:46 +00:00
|
|
|
r_core_visual_refs (core, true, true);
|
2017-10-16 20:31:29 +00:00
|
|
|
break;
|
|
|
|
case 'X':
|
2018-11-25 00:55:46 +00:00
|
|
|
r_core_visual_refs (core, false, true);
|
2017-10-16 20:31:29 +00:00
|
|
|
break;
|
2018-01-24 09:47:33 +00:00
|
|
|
case 'h': // seek history
|
2017-10-16 20:31:29 +00:00
|
|
|
r_core_cmdf (core, "s!~...");
|
|
|
|
break;
|
|
|
|
case '_':
|
|
|
|
r_core_visual_hudstuff (core);
|
|
|
|
break;
|
2018-06-27 22:54:50 +00:00
|
|
|
case ':':
|
|
|
|
r_core_visual_prompt_input (core);
|
|
|
|
break;
|
2018-05-28 21:44:51 +00:00
|
|
|
case 127: // backspace
|
2017-10-16 20:31:29 +00:00
|
|
|
case 'q':
|
|
|
|
return;
|
|
|
|
}
|
2017-10-16 14:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 10:08:41 +00:00
|
|
|
#include "visual_tabs.inc"
|
2017-12-16 01:23:53 +00:00
|
|
|
|
2018-12-15 11:30:15 +00:00
|
|
|
static bool isNumber(RCore *core, int ch) {
|
2018-11-15 02:00:19 +00:00
|
|
|
if (ch > '0' && ch <= '9') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
return ch == '0';
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char numbuf[32] = {0};
|
|
|
|
static int numbuf_i = 0;
|
|
|
|
|
|
|
|
static void numbuf_append(int ch) {
|
|
|
|
if (numbuf_i >= sizeof (numbuf) - 1) {
|
|
|
|
numbuf_i = 0;
|
|
|
|
}
|
|
|
|
numbuf[numbuf_i++] = ch;
|
|
|
|
numbuf[numbuf_i] = 0;
|
|
|
|
}
|
|
|
|
|
2020-06-14 14:08:32 +00:00
|
|
|
static int numbuf_pull(void) {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = 1;
|
|
|
|
if (numbuf_i) {
|
|
|
|
numbuf[numbuf_i] = 0;
|
|
|
|
distance = atoi (numbuf);
|
|
|
|
if (!distance) {
|
|
|
|
distance = 1;
|
|
|
|
}
|
|
|
|
numbuf_i = 0;
|
|
|
|
}
|
|
|
|
return distance;
|
|
|
|
}
|
|
|
|
|
2019-01-25 22:59:52 +00:00
|
|
|
static bool canWrite(RCore *core, ut64 addr) {
|
|
|
|
if (r_config_get_i (core->config, "io.cache")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
RIOMap *map = r_io_map_get (core->io, addr);
|
|
|
|
return (map && (map->perm & R_PERM_W));
|
|
|
|
}
|
|
|
|
|
2019-03-18 01:51:12 +00:00
|
|
|
static bool toggle_bb(RCore *core, ut64 addr) {
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
if (fcn) {
|
|
|
|
RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, addr);
|
|
|
|
if (bb) {
|
|
|
|
bb->folded = !bb->folded;
|
|
|
|
} else {
|
|
|
|
r_warn_if_reached ();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:15:47 +00:00
|
|
|
static int process_get_click(RCore *core, int ch) {
|
|
|
|
int x, y;
|
|
|
|
if (r_cons_get_click (&x, &y)) {
|
|
|
|
if (y == 1) {
|
|
|
|
if (x < 13) {
|
|
|
|
ch = '_';
|
|
|
|
} else if (x < 20) {
|
|
|
|
ch = 'p';
|
|
|
|
} else if (x < 24) {
|
|
|
|
ch = 9;
|
|
|
|
}
|
|
|
|
} else if (y == 2) {
|
|
|
|
if (x < 2) {
|
|
|
|
visual_closetab (core);
|
|
|
|
} else if (x < 5) {
|
|
|
|
visual_newtab (core);
|
|
|
|
} else {
|
|
|
|
visual_nexttab (core);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ch = 0; //'c';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:54:33 +00:00
|
|
|
R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
2019-03-18 01:51:12 +00:00
|
|
|
ut8 och = arg[0];
|
2011-02-24 15:50:29 +00:00
|
|
|
RAsmOp op;
|
2014-01-29 23:55:34 +00:00
|
|
|
ut64 offset = core->offset;
|
2011-03-01 23:02:50 +00:00
|
|
|
char buf[4096];
|
2015-06-12 00:19:58 +00:00
|
|
|
const char *key_s;
|
2019-03-06 10:14:23 +00:00
|
|
|
int i, cols = core->print->cols;
|
2015-02-10 23:13:04 +00:00
|
|
|
int wheelspeed;
|
2019-12-08 11:49:58 +00:00
|
|
|
int ch = och;
|
2017-03-24 00:23:25 +00:00
|
|
|
if ((ut8)ch == KEY_ALTQ) {
|
2017-08-26 01:49:54 +00:00
|
|
|
r_cons_readchar ();
|
2017-03-24 00:23:25 +00:00
|
|
|
ch = 'q';
|
|
|
|
}
|
2010-06-17 15:55:39 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
2012-09-28 00:20:52 +00:00
|
|
|
ch = visual_nkey (core, ch);
|
2016-12-09 14:29:15 +00:00
|
|
|
if (ch < 2) {
|
2020-12-20 14:15:47 +00:00
|
|
|
ch = process_get_click (core, ch);
|
|
|
|
if (!ch) {
|
2019-07-02 01:33:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-12-09 14:29:15 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (r_cons_singleton ()->mouse_event) {
|
2018-02-22 16:59:08 +00:00
|
|
|
wheelspeed = r_config_get_i (core->config, "scr.wheel.speed");
|
2015-02-10 23:13:04 +00:00
|
|
|
} else {
|
|
|
|
wheelspeed = 1;
|
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
|
2019-03-29 14:37:52 +00:00
|
|
|
if (ch == 'l' && och == 6) {
|
|
|
|
ch = 'J';
|
|
|
|
} else if (ch == 'h' && och == 2) {
|
|
|
|
ch = 'K';
|
|
|
|
}
|
|
|
|
|
2010-06-17 15:55:39 +00:00
|
|
|
// do we need hotkeys for data references? not only calls?
|
2016-05-11 02:25:16 +00:00
|
|
|
// '0' is handled to seek at the beginning of the function
|
2018-11-15 02:00:19 +00:00
|
|
|
// unless the cursor is set, then, the 0 is captured here
|
|
|
|
if (isNumber (core, ch)) {
|
|
|
|
// only in disasm and debug prints..
|
|
|
|
if (isDisasmPrint (core->printidx)) {
|
2019-04-16 08:09:43 +00:00
|
|
|
if (r_config_get_i (core->config, "asm.hints") && (r_config_get_i (core->config, "asm.hint.jmp")
|
2019-08-28 04:54:46 +00:00
|
|
|
|| r_config_get_i (core->config, "asm.hint.lea") || r_config_get_i (core->config, "asm.hint.emu")
|
|
|
|
|| r_config_get_i (core->config, "asm.hint.call"))) {
|
2018-12-15 11:30:15 +00:00
|
|
|
r_core_visual_jump (core, ch);
|
|
|
|
} else {
|
|
|
|
numbuf_append (ch);
|
|
|
|
}
|
2018-11-15 02:00:19 +00:00
|
|
|
} else {
|
|
|
|
numbuf_append (ch);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
switch (ch) {
|
2019-03-15 04:55:08 +00:00
|
|
|
#if __WINDOWS__
|
2017-02-22 22:45:51 +00:00
|
|
|
case 0xf5:
|
2018-11-15 02:00:19 +00:00
|
|
|
SetWindow (81, 25);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 0xcf5:
|
2018-11-15 02:00:19 +00:00
|
|
|
SetWindow (81, 40);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2015-04-07 14:25:14 +00:00
|
|
|
#endif
|
2017-02-22 22:45:51 +00:00
|
|
|
case 0x0d: // "enter" "\\n" "newline"
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
r_cons_set_click (core->cons->cpos.x, core->cons->cpos.y);
|
|
|
|
char buf[10];
|
|
|
|
int ch = process_get_click (core, 0);
|
|
|
|
buf[0] = ch;
|
|
|
|
buf[1] = 0;
|
|
|
|
r_core_visual_cmd(core, buf);
|
|
|
|
} else {
|
2015-02-10 23:13:04 +00:00
|
|
|
RAnalOp *op;
|
2014-09-03 21:55:09 +00:00
|
|
|
int wheel = r_config_get_i (core->config, "scr.wheel");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (wheel) {
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_enable_mouse (true);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2015-02-10 23:13:04 +00:00
|
|
|
do {
|
2018-06-07 18:32:00 +00:00
|
|
|
op = r_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC);
|
2015-02-10 23:13:04 +00:00
|
|
|
if (op) {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (op->type == R_ANAL_OP_TYPE_JMP ||
|
|
|
|
op->type == R_ANAL_OP_TYPE_CJMP ||
|
|
|
|
op->type == R_ANAL_OP_TYPE_CALL ||
|
|
|
|
op->type == R_ANAL_OP_TYPE_CCALL) {
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2017-02-22 22:45:51 +00:00
|
|
|
int delta = R_ABS ((st64) op->jump - (st64) offset);
|
|
|
|
if (op->jump < core->offset || op->jump >= core->print->screen_bounds) {
|
2016-06-01 10:16:00 +00:00
|
|
|
r_io_sundo_push (core->io, offset, r_print_get_cursor (core->print));
|
2014-09-23 11:32:51 +00:00
|
|
|
r_core_visual_seek_animation (core, op->jump);
|
2016-02-07 16:06:39 +00:00
|
|
|
core->print->cur = 0;
|
2014-09-23 11:32:51 +00:00
|
|
|
} else {
|
2016-06-01 10:16:00 +00:00
|
|
|
r_io_sundo_push (core->io, offset, r_print_get_cursor (core->print));
|
2016-02-07 16:06:39 +00:00
|
|
|
core->print->cur = delta;
|
2014-09-23 11:32:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-06-01 10:16:00 +00:00
|
|
|
r_io_sundo_push (core->io, offset, 0);
|
2015-02-10 23:13:04 +00:00
|
|
|
r_core_visual_seek_animation (core, op->jump);
|
2014-09-23 11:32:51 +00:00
|
|
|
}
|
2014-02-07 13:54:31 +00:00
|
|
|
}
|
2015-02-10 23:13:04 +00:00
|
|
|
}
|
|
|
|
r_anal_op_free (op);
|
2017-02-22 22:45:51 +00:00
|
|
|
} while (--wheelspeed > 0);
|
2014-02-07 13:54:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-04-18 15:12:50 +00:00
|
|
|
case 'o': // tab TAB
|
2019-10-23 12:09:14 +00:00
|
|
|
nextPrintFormat (core);
|
2019-04-18 15:12:50 +00:00
|
|
|
break;
|
2019-01-03 23:57:01 +00:00
|
|
|
case 'O': // tab TAB
|
2018-12-28 18:40:54 +00:00
|
|
|
case 9: // tab TAB
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, true);
|
2018-12-28 18:40:54 +00:00
|
|
|
if (splitView) {
|
|
|
|
// this split view is kind of useless imho, we should kill it or merge it into tabs
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur = 0;
|
2017-08-03 12:52:46 +00:00
|
|
|
core->curtab = 0;
|
2017-02-22 22:45:51 +00:00
|
|
|
core->seltab++;
|
2017-08-03 12:52:46 +00:00
|
|
|
if (core->seltab > 1) {
|
2017-02-22 22:45:51 +00:00
|
|
|
core->seltab = 0;
|
|
|
|
}
|
2016-02-25 09:28:54 +00:00
|
|
|
} else {
|
2018-12-28 18:40:54 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
core->curtab = 0;
|
|
|
|
if (core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
core->seltab++;
|
|
|
|
if (core->seltab > 2) {
|
|
|
|
core->seltab = 0;
|
|
|
|
}
|
2017-08-03 12:52:46 +00:00
|
|
|
} else {
|
2018-12-28 18:40:54 +00:00
|
|
|
core->seltab = 0;
|
|
|
|
ut64 f = r_config_get_i (core->config, "diff.from");
|
|
|
|
ut64 t = r_config_get_i (core->config, "diff.to");
|
|
|
|
if (f == t && f == 0) {
|
|
|
|
core->print->col = core->print->col == 1? 2: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-10-23 12:09:14 +00:00
|
|
|
prevPrintFormat (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2016-02-25 09:28:54 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2017-10-20 00:21:19 +00:00
|
|
|
case '&':
|
2017-11-09 11:21:03 +00:00
|
|
|
rotateAsmBits (core);
|
2017-10-20 00:21:19 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'a':
|
2017-02-03 12:09:34 +00:00
|
|
|
{
|
2018-12-29 10:17:56 +00:00
|
|
|
{
|
|
|
|
ut64 addr = core->offset;
|
|
|
|
if (PIDX == 2) {
|
|
|
|
if (core->seltab == 0) {
|
|
|
|
addr = r_debug_reg_get (core->dbg, "SP");
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 22:59:52 +00:00
|
|
|
if (!canWrite (core, addr)) {
|
2019-07-02 01:51:07 +00:00
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_cons_any_key (NULL);
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-07 16:06:39 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_printf ("Enter assembler opcodes separated with ';':\n");
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (false);
|
2019-06-30 19:39:31 +00:00
|
|
|
strcpy (buf, "\"wa ");
|
2017-02-22 22:45:51 +00:00
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_enable_mouse (false);
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) {
|
2017-02-22 22:45:51 +00:00
|
|
|
buf[0] = '\0';
|
2016-02-07 16:06:39 +00:00
|
|
|
}
|
2019-06-30 19:39:31 +00:00
|
|
|
strcat (buf, "\"");
|
2017-02-22 22:45:51 +00:00
|
|
|
int wheel = r_config_get_i (core->config, "scr.wheel");
|
|
|
|
if (wheel) {
|
|
|
|
r_cons_enable_mouse (true);
|
|
|
|
}
|
|
|
|
if (*buf) {
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
int t = core->offset + core->print->cur;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, t, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
r_core_cmd (core, buf, true);
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
int t = core->offset - core->print->cur;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, t, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_set_raw (true);
|
2017-02-03 12:09:34 +00:00
|
|
|
}
|
2013-08-21 22:08:08 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '=':
|
2014-10-06 00:36:22 +00:00
|
|
|
{ // TODO: edit
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
const char *buf = NULL;
|
|
|
|
#define I core->cons
|
|
|
|
const char *cmd = r_config_get (core->config, "cmd.vprompt");
|
|
|
|
r_line_set_prompt ("cmd.vprompt> ");
|
|
|
|
I->line->contents = strdup (cmd);
|
|
|
|
buf = r_line_readline ();
|
|
|
|
I->line->contents = NULL;
|
2017-03-15 11:12:01 +00:00
|
|
|
(void)r_config_set (core->config, "cmd.vprompt", buf);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2014-10-06 00:36:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '|':
|
2014-10-06 00:36:22 +00:00
|
|
|
{ // TODO: edit
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
const char *buf = NULL;
|
|
|
|
#define I core->cons
|
|
|
|
const char *cmd = r_config_get (core->config, "cmd.cprompt");
|
|
|
|
r_line_set_prompt ("cmd.cprompt> ");
|
|
|
|
I->line->contents = strdup (cmd);
|
|
|
|
buf = r_line_readline ();
|
2017-09-15 14:59:51 +00:00
|
|
|
if (buf && !strcmp (buf, "|")) {
|
2017-06-27 22:24:26 +00:00
|
|
|
R_FREE (I->line->contents);
|
|
|
|
core->print->cur_enabled = true;
|
|
|
|
core->print->cur = 0;
|
|
|
|
(void)r_config_set (core->config, "cmd.cprompt", "p=e $r-2");
|
|
|
|
} else {
|
|
|
|
R_FREE (I->line->contents);
|
2020-12-08 14:57:08 +00:00
|
|
|
(void)r_config_set (core->config, "cmd.cprompt", r_str_get (buf));
|
2017-06-27 22:24:26 +00:00
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2014-10-06 00:36:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '!':
|
2020-12-07 17:08:26 +00:00
|
|
|
r_core_panels_root (core, core->panels_root);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2019-03-06 10:14:23 +00:00
|
|
|
case 'g':
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
|
|
|
r_core_visual_offset (core);
|
|
|
|
r_core_visual_showcursor (core, false);
|
2019-03-17 11:14:37 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
__core_visual_gogo (core, 'G');
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'A':
|
2016-02-07 16:06:39 +00:00
|
|
|
{
|
2019-07-02 01:33:57 +00:00
|
|
|
const int oce = core->print->cur_enabled;
|
|
|
|
const int oco = core->print->ocur;
|
|
|
|
const int occ = core->print->cur;
|
2018-07-17 21:53:44 +00:00
|
|
|
ut64 off = oce? core->offset + core->print->cur: core->offset;
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur_enabled = 0;
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
r_core_visual_asm (core, off);
|
2018-07-17 21:53:44 +00:00
|
|
|
core->print->cur_enabled = oce;
|
|
|
|
core->print->cur = occ;
|
|
|
|
core->print->ocur = oco;
|
2019-07-02 01:33:57 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.wheel")) {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_enable_mouse (true);
|
|
|
|
}
|
2017-01-11 22:51:20 +00:00
|
|
|
}
|
2014-09-27 01:48:54 +00:00
|
|
|
break;
|
2017-08-03 12:52:46 +00:00
|
|
|
case '\\':
|
|
|
|
if (splitPtr == UT64_MAX) {
|
|
|
|
splitPtr = core->offset;
|
|
|
|
}
|
|
|
|
splitView = !splitView;
|
|
|
|
setcursor (core, splitView);
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'c':
|
|
|
|
setcursor (core, !core->print->cur_enabled);
|
|
|
|
break;
|
2019-03-03 22:10:43 +00:00
|
|
|
case '$':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
r_core_cmdf (core, "dr PC=$$+%d", core->print->cur);
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, "dr PC=$$");
|
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '@':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
char buf[128];
|
|
|
|
prompt_read ("cursor at:", buf, sizeof (buf));
|
|
|
|
core->print->cur = (st64) r_num_math (core->num, buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C':
|
2018-03-02 16:58:44 +00:00
|
|
|
if (++color > 2) {
|
|
|
|
color = 0;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_config_set_i (core->config, "scr.color", color);
|
|
|
|
break;
|
2019-08-30 17:43:12 +00:00
|
|
|
case 'd': {
|
|
|
|
bool mouse_state = __holdMouseState (core);
|
2019-04-29 09:44:39 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
|
|
|
int distance = numbuf_pull ();
|
|
|
|
r_core_visual_define (core, arg + 1, distance - 1);
|
|
|
|
r_core_visual_showcursor (core, false);
|
2019-08-30 17:43:12 +00:00
|
|
|
r_cons_enable_mouse (mouse_state && r_config_get_i(core->config, "scr.wheel"));
|
|
|
|
}
|
2017-06-09 17:12:20 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'D':
|
|
|
|
setdiff (core);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2012-09-28 00:20:52 +00:00
|
|
|
{
|
2019-08-30 17:43:12 +00:00
|
|
|
bool mouse_state = __holdMouseState (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
int range, min, max;
|
|
|
|
char name[256], *n;
|
|
|
|
r_line_set_prompt ("flag name: ");
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (r_cons_fgets (name, sizeof (name), 0, NULL) >= 0 && *name) {
|
2019-06-16 18:58:40 +00:00
|
|
|
n = name;
|
|
|
|
r_str_trim (n);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->ocur != -1) {
|
|
|
|
min = R_MIN (core->print->cur, core->print->ocur);
|
|
|
|
max = R_MAX (core->print->cur, core->print->ocur);
|
|
|
|
} else {
|
|
|
|
min = max = core->print->cur;
|
|
|
|
}
|
|
|
|
range = max - min + 1;
|
|
|
|
if (!strcmp (n, "-")) {
|
|
|
|
r_flag_unset_off (core->flags, core->offset + core->print->cur);
|
|
|
|
} else if (*n == '.') {
|
|
|
|
if (n[1] == '-') {
|
|
|
|
//unset
|
|
|
|
r_core_cmdf (core, "f.-%s@0x%"PFMT64x, n + 1, core->offset + min);
|
|
|
|
} else {
|
|
|
|
r_core_cmdf (core, "f.%s@0x%"PFMT64x, n + 1, core->offset + min);
|
|
|
|
}
|
|
|
|
} else if (*n == '-') {
|
|
|
|
if (*n) {
|
|
|
|
r_flag_unset_name (core->flags, n + 1);
|
|
|
|
}
|
2013-10-15 01:56:01 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (range < 1) {
|
|
|
|
range = 1;
|
|
|
|
}
|
|
|
|
if (*n) {
|
|
|
|
r_flag_set (core->flags, n,
|
|
|
|
core->offset + min, range);
|
|
|
|
}
|
2013-10-15 01:56:01 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2019-08-30 17:43:12 +00:00
|
|
|
r_cons_enable_mouse (mouse_state && r_config_get_i(core->config, "scr.wheel"));
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
visual_comma (core);
|
|
|
|
break;
|
2018-08-16 09:01:53 +00:00
|
|
|
case 't':
|
2018-12-31 00:21:03 +00:00
|
|
|
{
|
2019-02-09 11:29:48 +00:00
|
|
|
r_cons_gotoxy (0, 0);
|
2019-01-02 01:09:31 +00:00
|
|
|
if (core->visual.tabs) {
|
2019-02-09 11:29:48 +00:00
|
|
|
r_cons_printf ("[tnp:=+-] ");
|
2019-01-02 01:09:31 +00:00
|
|
|
} else {
|
|
|
|
r_cons_printf ("[t] ");
|
|
|
|
}
|
2018-12-31 00:21:03 +00:00
|
|
|
r_cons_flush();
|
|
|
|
int ch = r_cons_readchar ();
|
|
|
|
if (isdigit (ch)) {
|
|
|
|
visual_nthtab (core, ch - '0' - 1);
|
|
|
|
}
|
|
|
|
switch (ch) {
|
2019-01-02 01:09:31 +00:00
|
|
|
case 'h':
|
|
|
|
case 'k':
|
2018-12-31 00:21:03 +00:00
|
|
|
case 'p':
|
|
|
|
visual_prevtab (core);
|
|
|
|
break;
|
2019-01-02 01:09:31 +00:00
|
|
|
case 9: // t-TAB
|
|
|
|
case 'l':
|
|
|
|
case 'j':
|
2018-12-31 00:21:03 +00:00
|
|
|
case 'n':
|
|
|
|
visual_nexttab (core);
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
visual_tabname (core);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
visual_closetab (core);
|
|
|
|
break;
|
2019-02-09 11:29:48 +00:00
|
|
|
case ':':
|
|
|
|
{
|
|
|
|
RCoreVisualTab *tab = visual_newtab (core);
|
|
|
|
if (tab) {
|
|
|
|
tab->name[0] = ':';
|
2020-02-29 19:47:10 +00:00
|
|
|
r_cons_fgets (tab->name + 1, sizeof (tab->name) - 1, 0, NULL);
|
2019-02-09 11:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-01-02 01:09:31 +00:00
|
|
|
case '+':
|
2018-12-31 00:21:03 +00:00
|
|
|
case 't':
|
2019-01-02 01:09:31 +00:00
|
|
|
case 'a':
|
2018-12-31 00:21:03 +00:00
|
|
|
visual_newtab (core);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 09:01:53 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'T':
|
2018-08-16 09:01:53 +00:00
|
|
|
visual_closetab (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
r_core_seek_next (core, r_config_get (core->config, "scr.nkey"));
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
r_core_seek_previous (core, r_config_get (core->config, "scr.nkey"));
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
2018-12-29 10:17:56 +00:00
|
|
|
{
|
|
|
|
ut64 oaddr = core->offset;
|
|
|
|
int delta = (core->print->ocur != -1)? R_MIN (core->print->cur, core->print->ocur): core->print->cur;
|
|
|
|
ut64 addr = core->offset + delta;
|
2017-02-22 22:45:51 +00:00
|
|
|
if (PIDX == 0) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (strstr (printfmtSingle[0], "pxb")) {
|
|
|
|
r_core_visual_define (core, "1", 1);
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->ocur == -1) {
|
|
|
|
__ime = true;
|
|
|
|
core->print->cur_enabled = true;
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
} else if (PIDX == 2) {
|
|
|
|
if (core->seltab == 0) {
|
|
|
|
addr = r_debug_reg_get (core->dbg, "SP") + delta;
|
|
|
|
} else if (core->seltab == 1) {
|
|
|
|
char buf[128];
|
|
|
|
prompt_read ("new-reg-value> ", buf, sizeof (buf));
|
|
|
|
if (*buf) {
|
|
|
|
const char *creg = core->dbg->creg;
|
|
|
|
if (creg) {
|
|
|
|
r_core_cmdf (core, "dr %s = %s\n", creg, buf);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
return true;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2019-01-25 22:59:52 +00:00
|
|
|
if (!canWrite (core, addr)) {
|
2019-07-02 01:51:07 +00:00
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n");
|
2019-01-25 22:59:52 +00:00
|
|
|
r_cons_any_key (NULL);
|
|
|
|
return true;
|
2016-02-25 10:35:59 +00:00
|
|
|
}
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
if (ch == 'I') {
|
2014-01-29 23:55:34 +00:00
|
|
|
strcpy (buf, "wow ");
|
2017-02-22 22:45:51 +00:00
|
|
|
r_line_set_prompt ("insert hexpair block: ");
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) {
|
2017-02-22 22:45:51 +00:00
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
char *p = strdup (buf);
|
|
|
|
int cur = core->print->cur;
|
|
|
|
if (cur >= core->blocksize) {
|
|
|
|
cur = core->print->cur - 1;
|
|
|
|
}
|
|
|
|
snprintf (buf, sizeof (buf), "%s @ $$0!%i", p,
|
2018-12-04 13:19:30 +00:00
|
|
|
core->blocksize - cur);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
free (p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (core->print->col == 2) {
|
|
|
|
strcpy (buf, "\"w ");
|
|
|
|
r_line_set_prompt ("insert string: ");
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf + 3, sizeof (buf) - 3, 0, NULL) < 0) {
|
2017-02-22 22:45:51 +00:00
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
|
|
|
strcat (buf, "\"");
|
2014-01-29 23:55:34 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_line_set_prompt ("insert hex: ");
|
|
|
|
if (core->print->ocur != -1) {
|
|
|
|
int bs = R_ABS (core->print->cur - core->print->ocur) + 1;
|
|
|
|
core->blocksize = bs;
|
|
|
|
strcpy (buf, "wow ");
|
|
|
|
} else {
|
|
|
|
strcpy (buf, "wx ");
|
|
|
|
}
|
|
|
|
if (r_cons_fgets (buf + strlen (buf), sizeof (buf) - strlen (buf), 0, NULL) < 0) {
|
|
|
|
buf[0] = '\0';
|
|
|
|
}
|
2014-01-29 23:55:34 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, false);
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_cmd (core, buf, 1);
|
|
|
|
if (core->print->cur_enabled) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, true);
|
2015-08-30 22:55:41 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_set_raw (1);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, oaddr, true);
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
if (r_config_get_i (core->config, "scr.randpal")) {
|
|
|
|
r_core_cmd0 (core, "ecr");
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, "ecn");
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
r_core_visual_config (core);
|
|
|
|
break;
|
2017-12-30 03:11:49 +00:00
|
|
|
case '^':
|
|
|
|
{
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
|
|
|
if (fcn) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, fcn->addr, false);
|
2019-03-17 11:14:37 +00:00
|
|
|
} else {
|
|
|
|
__core_visual_gogo (core, 'g');
|
2017-12-30 03:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'E':
|
|
|
|
r_core_visual_colors (core);
|
|
|
|
break;
|
|
|
|
case 'x':
|
2018-11-25 00:55:46 +00:00
|
|
|
r_core_visual_refs (core, true, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'X':
|
2018-11-25 00:55:46 +00:00
|
|
|
r_core_visual_refs (core, false, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
2018-04-11 01:00:05 +00:00
|
|
|
// TODO: toggle shortcut hotkeys
|
2019-04-16 16:42:30 +00:00
|
|
|
if (r_config_get_i (core->config, "asm.hint.call")) {
|
2019-04-16 08:09:43 +00:00
|
|
|
r_core_cmd0 (core, "e!asm.hint.call");
|
2019-08-28 04:54:46 +00:00
|
|
|
r_core_cmd0 (core, "e asm.hint.jmp=true");
|
2019-04-16 16:42:30 +00:00
|
|
|
} else if (r_config_get_i (core->config, "asm.hint.jmp")) {
|
|
|
|
r_core_cmd0 (core, "e!asm.hint.jmp");
|
2019-08-28 04:54:46 +00:00
|
|
|
r_core_cmd0 (core, "e asm.hint.emu=true");
|
|
|
|
} else if (r_config_get_i (core->config, "asm.hint.emu")) {
|
|
|
|
r_core_cmd0 (core, "e!asm.hint.emu");
|
|
|
|
r_core_cmd0 (core, "e asm.hint.lea=true");
|
2019-04-16 08:09:43 +00:00
|
|
|
} else if (r_config_get_i (core->config, "asm.hint.lea")) {
|
|
|
|
r_core_cmd0 (core, "e!asm.hint.lea");
|
2019-08-28 04:54:46 +00:00
|
|
|
r_core_cmd0 (core, "e asm.hint.call=true");
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, "e asm.hint.call=true");
|
2019-04-16 08:09:43 +00:00
|
|
|
}
|
2018-04-11 01:00:05 +00:00
|
|
|
visual_refresh (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case 'V':
|
|
|
|
if (r_config_get_i (core->config, "graph.web")) {
|
|
|
|
r_core_cmd0 (core, "agv $$");
|
|
|
|
} else {
|
|
|
|
RAnalFunction *fun = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
int ocolor = r_config_get_i (core->config, "scr.color");
|
|
|
|
if (!fun) {
|
|
|
|
r_cons_message ("Not in a function. Type 'df' to define it here");
|
|
|
|
break;
|
|
|
|
} else if (r_list_empty (fun->bbs)) {
|
|
|
|
r_cons_message ("No basic blocks in this function. You may want to use 'afb+'.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
reset_print_cur (core->print);
|
2017-11-24 22:19:26 +00:00
|
|
|
eprintf ("\rRendering graph...");
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_visual_graph (core, NULL, NULL, true);
|
|
|
|
r_config_set_i (core->config, "scr.color", ocolor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v':
|
2018-11-25 00:23:33 +00:00
|
|
|
r_core_visual_anal (core, NULL);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'l':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
core->cons->cpos.x += ch == 'h'? -1: 1;
|
|
|
|
if (core->cons->cpos.x < 1) {
|
|
|
|
core->cons->cpos.x = 0;
|
|
|
|
}
|
|
|
|
int h, w = r_cons_get_size (&h);
|
|
|
|
if (core->cons->cpos.x >= w) {
|
|
|
|
core->cons->cpos.x = w;
|
|
|
|
}
|
|
|
|
} else {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
if (ch == 'h') {
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_left (core, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_right (core, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ch == 'h') {
|
|
|
|
distance = -distance;
|
|
|
|
}
|
|
|
|
r_core_seek_delta (core, distance);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
2018-11-15 02:00:19 +00:00
|
|
|
case 'H':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
int distance = 8; // numbuf_pull ();
|
|
|
|
core->cons->cpos.x += (ch == 'h' || ch == 'H')? -distance: distance;
|
|
|
|
if (core->cons->cpos.x < 1) {
|
|
|
|
core->cons->cpos.x = 0;
|
|
|
|
}
|
|
|
|
int h, w = r_cons_get_size (&h);
|
|
|
|
if (core->cons->cpos.x >= w) {
|
|
|
|
core->cons->cpos.x = w;
|
|
|
|
}
|
|
|
|
} else {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
if (ch == 'H') {
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_left (core, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_right (core, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ch == 'H') {
|
|
|
|
distance = -distance;
|
|
|
|
}
|
|
|
|
r_core_seek_delta (core, distance * 2);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'j':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
core->cons->cpos.y++;
|
|
|
|
int h;
|
|
|
|
(void)r_cons_get_size (&h);
|
|
|
|
if (core->cons->cpos.y >= h) {
|
|
|
|
core->cons->cpos.y = h;
|
|
|
|
}
|
|
|
|
} else if (core->print->cur_enabled) {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_nextrow (core, false);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
2018-02-22 16:59:08 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.wheel.nkey")) {
|
2018-12-15 11:30:15 +00:00
|
|
|
int i, distance = numbuf_pull ();
|
|
|
|
if (distance < 1) {
|
|
|
|
distance = 1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
r_core_cmd0 (core, "sn");
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
int times = R_MAX (1, wheelspeed);
|
2017-10-19 05:16:40 +00:00
|
|
|
// Check if we have a data annotation.
|
2020-05-09 18:49:28 +00:00
|
|
|
ut64 amisize;
|
|
|
|
RAnalMetaItem *ami = r_meta_get_at (core->anal, core->offset, R_META_TYPE_DATA, &amisize);
|
2018-01-07 01:23:48 +00:00
|
|
|
if (!ami) {
|
2020-05-09 18:49:28 +00:00
|
|
|
ami = r_meta_get_at (core->anal, core->offset, R_META_TYPE_STRING, &amisize);
|
2018-01-07 01:23:48 +00:00
|
|
|
}
|
2017-10-19 05:16:40 +00:00
|
|
|
if (ami) {
|
2020-05-09 18:49:28 +00:00
|
|
|
r_core_seek_delta (core, amisize);
|
2017-10-19 05:16:40 +00:00
|
|
|
} else {
|
2018-12-15 11:30:15 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
if (distance > 1) {
|
|
|
|
times = distance;
|
|
|
|
}
|
2017-10-19 05:16:40 +00:00
|
|
|
while (times--) {
|
|
|
|
if (isDisasmPrint (core->printidx)) {
|
2018-07-29 19:06:58 +00:00
|
|
|
r_core_visual_disasm_down (core, &op, &cols);
|
2019-03-31 16:22:07 +00:00
|
|
|
} else if (!strcmp (__core_visual_print_command (core),
|
|
|
|
"prc")) {
|
2019-04-29 09:51:13 +00:00
|
|
|
cols = r_config_get_i (core->config, "hex.cols");
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + cols, true);
|
2016-02-21 00:56:50 +00:00
|
|
|
}
|
2015-12-14 09:19:07 +00:00
|
|
|
}
|
2015-02-10 23:13:04 +00:00
|
|
|
}
|
2011-02-15 15:19:18 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'J':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
int distance = 4;// numbuf_pull ();
|
|
|
|
core->cons->cpos.y += distance;
|
|
|
|
int h;
|
|
|
|
(void)r_cons_get_size (&h);
|
|
|
|
if (core->cons->cpos.y >= h) {
|
|
|
|
core->cons->cpos.y = h;
|
|
|
|
}
|
|
|
|
} else if (core->print->cur_enabled) {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_nextrow (core, true);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
if (core->print->screen_bounds > 1 && core->print->screen_bounds >= core->offset) {
|
2018-11-19 13:44:54 +00:00
|
|
|
ut64 addr = UT64_MAX;
|
|
|
|
if (isDisasmPrint (core->printidx)) {
|
|
|
|
if (core->print->screen_bounds == core->offset) {
|
|
|
|
ut64 addr = core->print->screen_bounds;
|
2020-05-12 23:28:23 +00:00
|
|
|
addr += r_asm_disassemble (core->rasm, &op, core->block, 32);
|
2018-11-19 13:44:54 +00:00
|
|
|
}
|
2018-11-20 10:04:39 +00:00
|
|
|
if (addr == core->offset || addr == UT64_MAX) {
|
|
|
|
addr = core->offset + 48;
|
2018-11-19 13:44:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-11-20 00:13:54 +00:00
|
|
|
int h;
|
2018-11-19 13:44:54 +00:00
|
|
|
int hexCols = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (hexCols < 1) {
|
|
|
|
hexCols = 16;
|
|
|
|
}
|
2018-11-20 00:13:54 +00:00
|
|
|
(void)r_cons_get_size (&h);
|
2018-11-19 13:44:54 +00:00
|
|
|
int delta = hexCols * (h / 4);
|
|
|
|
addr = core->offset + delta;
|
2016-11-04 00:30:35 +00:00
|
|
|
}
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + obs, true);
|
2016-03-04 12:42:55 +00:00
|
|
|
}
|
2014-09-22 11:45:36 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
core->cons->cpos.y--;
|
|
|
|
if (core->cons->cpos.y < 1) {
|
|
|
|
core->cons->cpos.y = 0;
|
|
|
|
}
|
|
|
|
} else if (core->print->cur_enabled) {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_prevrow (core, false);
|
|
|
|
}
|
2016-02-21 00:56:50 +00:00
|
|
|
} else {
|
2018-02-22 16:59:08 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.wheel.nkey")) {
|
2018-12-15 11:30:15 +00:00
|
|
|
int i, distance = numbuf_pull ();
|
|
|
|
if (distance < 1) {
|
|
|
|
distance = 1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
r_core_cmd0 (core, "sp");
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
int times = wheelspeed;
|
|
|
|
if (times < 1) {
|
|
|
|
times = 1;
|
|
|
|
}
|
2018-12-15 11:30:15 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
if (distance > 1) {
|
|
|
|
times = distance;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
while (times--) {
|
|
|
|
if (isDisasmPrint (core->printidx)) {
|
2018-07-29 19:06:58 +00:00
|
|
|
r_core_visual_disasm_up (core, &cols);
|
2019-03-31 16:22:07 +00:00
|
|
|
} else if (!strcmp (__core_visual_print_command (core), "prc")) {
|
2019-04-29 09:51:13 +00:00
|
|
|
cols = r_config_get_i (core->config, "hex.cols");
|
2015-12-14 09:19:07 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_seek_delta (core, -cols);
|
2015-12-14 09:19:07 +00:00
|
|
|
}
|
2015-12-18 18:53:54 +00:00
|
|
|
}
|
2011-02-15 11:31:32 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'K':
|
2020-12-20 14:15:47 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.cursor")) {
|
|
|
|
int distance = 4;// numbuf_pull ();
|
|
|
|
core->cons->cpos.y -= distance;
|
|
|
|
if (core->cons->cpos.y < 1) {
|
|
|
|
core->cons->cpos.y = 0;
|
|
|
|
}
|
|
|
|
} else if (core->print->cur_enabled) {
|
2018-11-15 02:00:19 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
for (i = 0; i < distance; i++) {
|
|
|
|
cursor_prevrow (core, true);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
if (core->print->screen_bounds > 1 && core->print->screen_bounds > core->offset) {
|
|
|
|
int delta = (core->print->screen_bounds - core->offset);
|
2017-08-22 07:42:16 +00:00
|
|
|
if (core->offset >= delta) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset - delta, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, 0, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2016-11-04 00:30:35 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
ut64 at = (core->offset > obs)? core->offset - obs: 0;
|
|
|
|
if (core->offset > obs) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, at, true);
|
2016-11-04 00:30:35 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, 0, true);
|
2016-11-04 00:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '[':
|
2017-06-09 13:58:49 +00:00
|
|
|
// comments column
|
|
|
|
if (core->print->cur_enabled &&
|
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_PD ||
|
2018-12-28 18:40:54 +00:00
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab == 2))) {
|
2018-02-22 16:59:08 +00:00
|
|
|
int cmtcol = r_config_get_i (core->config, "asm.cmt.col");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (cmtcol > 2) {
|
2018-02-22 16:59:08 +00:00
|
|
|
r_config_set_i (core->config, "asm.cmt.col", cmtcol - 2);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2017-05-29 02:36:34 +00:00
|
|
|
}
|
2017-06-09 13:58:49 +00:00
|
|
|
// hex column
|
2018-12-28 18:40:54 +00:00
|
|
|
if ((core->printidx != R_CORE_VISUAL_MODE_PD && core->printidx != R_CORE_VISUAL_MODE_DB) ||
|
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab != 2)) {
|
2017-02-22 22:45:51 +00:00
|
|
|
int scrcols = r_config_get_i (core->config, "hex.cols");
|
2018-12-16 09:04:58 +00:00
|
|
|
if (scrcols > 1) {
|
|
|
|
r_config_set_i (core->config, "hex.cols", scrcols - 1);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2014-09-22 11:45:36 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case ']':
|
2017-06-09 13:58:49 +00:00
|
|
|
// comments column
|
|
|
|
if (core->print->cur_enabled &&
|
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_PD ||
|
2018-12-28 18:40:54 +00:00
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab == 2))) {
|
2018-02-22 16:59:08 +00:00
|
|
|
int cmtcol = r_config_get_i (core->config, "asm.cmt.col");
|
|
|
|
r_config_set_i (core->config, "asm.cmt.col", cmtcol + 2);
|
2017-05-29 02:36:34 +00:00
|
|
|
}
|
2017-06-09 13:58:49 +00:00
|
|
|
// hex column
|
2018-12-28 18:40:54 +00:00
|
|
|
if ((core->printidx != R_CORE_VISUAL_MODE_PD && core->printidx != R_CORE_VISUAL_MODE_DB) ||
|
|
|
|
(core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab != 2)) {
|
2017-02-22 22:45:51 +00:00
|
|
|
int scrcols = r_config_get_i (core->config, "hex.cols");
|
2018-12-16 09:04:58 +00:00
|
|
|
r_config_set_i (core->config, "hex.cols", scrcols + 1);
|
2016-11-22 22:30:46 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2013-02-25 08:36:07 +00:00
|
|
|
#if 0
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'I':
|
|
|
|
r_core_cmd (core, "dsp", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
break;
|
2013-02-25 08:36:07 +00:00
|
|
|
#endif
|
2017-02-22 22:45:51 +00:00
|
|
|
case 's':
|
|
|
|
key_s = r_config_get (core->config, "key.s");
|
|
|
|
if (key_s && *key_s) {
|
|
|
|
r_core_cmd0 (core, key_s);
|
2014-02-10 02:31:12 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
visual_single_step_in (core);
|
2014-02-10 02:31:12 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
key_s = r_config_get (core->config, "key.S");
|
|
|
|
if (key_s && *key_s) {
|
|
|
|
r_core_cmd0 (core, key_s);
|
|
|
|
} else {
|
2019-01-05 10:51:46 +00:00
|
|
|
__core_visual_step_over (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '"':
|
2019-01-05 10:51:46 +00:00
|
|
|
r_config_toggle (core->config, "scr.dumpcols");
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, true);
|
2018-12-28 18:40:54 +00:00
|
|
|
if (core->printidx == R_CORE_VISUAL_MODE_DB && core->print->cur_enabled) {
|
2018-10-31 10:34:13 +00:00
|
|
|
nextPrintCommand ();
|
|
|
|
} else {
|
|
|
|
setprintmode (core, 1);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
2018-12-28 18:40:54 +00:00
|
|
|
if (core->printidx == R_CORE_VISUAL_MODE_DB && core->print->cur_enabled) {
|
2018-10-31 10:34:13 +00:00
|
|
|
prevPrintCommand ();
|
|
|
|
} else {
|
|
|
|
setprintmode (core, -1);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
findPair (core);
|
|
|
|
} else {
|
|
|
|
/* do nothing? */
|
|
|
|
autoblocksize = !autoblocksize;
|
|
|
|
if (autoblocksize) {
|
|
|
|
obs = core->blocksize;
|
2015-06-12 00:19:58 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_block_size (core, obs);
|
2015-06-12 00:19:58 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_clear ();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
findNextWord (core);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
findPrevWord (core);
|
|
|
|
//r_core_cmd0 (core, "=H");
|
|
|
|
break;
|
|
|
|
case 'm':
|
2019-05-11 08:09:17 +00:00
|
|
|
{
|
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
r_cons_printf (R_CONS_CLEAR_LINE"Set shortcut key for 0x%"PFMT64x"\n", core->offset);
|
|
|
|
r_cons_flush ();
|
|
|
|
int ch = r_cons_readchar ();
|
|
|
|
r_core_visual_mark (core, ch);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
{
|
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
if (r_core_visual_mark_dump (core)) {
|
|
|
|
r_cons_printf (R_CONS_CLEAR_LINE"Remove a shortcut key from the list\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
int ch = r_cons_readchar ();
|
|
|
|
r_core_visual_mark_del (core, ch);
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case '\'':
|
2019-05-11 08:09:17 +00:00
|
|
|
{
|
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
if (r_core_visual_mark_dump (core)) {
|
|
|
|
r_cons_flush ();
|
|
|
|
int ch = r_cons_readchar ();
|
|
|
|
r_core_visual_mark_seek (core, ch);
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if (core->print->ocur == -1) {
|
|
|
|
r_core_yank (core, core->offset + core->print->cur, 1);
|
2015-06-12 00:19:58 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_yank (core, core->offset + ((core->print->ocur < core->print->cur) ?
|
|
|
|
core->print->ocur: core->print->cur), R_ABS (core->print->cur - core->print->ocur) + 1);
|
2015-06-12 00:19:58 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'Y':
|
|
|
|
if (!core->yank_buf) {
|
|
|
|
r_cons_strcat ("Cannot paste, clipboard is empty.\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
r_cons_clear00 ();
|
|
|
|
} else {
|
|
|
|
r_core_yank_paste (core, core->offset + core->print->cur, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '0':
|
2016-05-11 02:25:16 +00:00
|
|
|
{
|
2017-02-22 22:45:51 +00:00
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
if (fcn) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, fcn->addr, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2016-05-11 02:25:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '-':
|
|
|
|
if (core->print->cur_enabled) {
|
2019-04-08 23:22:19 +00:00
|
|
|
if (core->seltab < 2 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
if (core->seltab) {
|
|
|
|
const char *creg = core->dbg->creg;
|
|
|
|
if (creg) {
|
|
|
|
r_core_cmdf (core, "dr %s = %s-1\n", creg, creg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
|
|
|
r_config_get_i (core->config, "stack.size") - w);
|
|
|
|
}
|
2016-11-24 22:25:49 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->ocur == -1) {
|
|
|
|
sprintf (buf, "wos 01 @ $$+%i!1",core->print->cur);
|
|
|
|
} else {
|
|
|
|
sprintf (buf, "wos 01 @ $$+%i!%i", core->print->cur < core->print->ocur
|
2016-11-24 22:25:49 +00:00
|
|
|
? core->print->cur
|
|
|
|
: core->print->ocur,
|
|
|
|
R_ABS (core->print->ocur - core->print->cur) + 1);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!autoblocksize) {
|
|
|
|
r_core_block_size (core, core->blocksize - 1);
|
2016-11-24 22:25:49 +00:00
|
|
|
}
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
if (core->print->cur_enabled) {
|
2019-04-08 23:22:19 +00:00
|
|
|
if (core->seltab < 2 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
if (core->seltab) {
|
|
|
|
const char *creg = core->dbg->creg;
|
|
|
|
if (creg) {
|
|
|
|
r_core_cmdf (core, "dr %s = %s+1\n", creg, creg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
|
|
|
r_config_get_i (core->config, "stack.size") + w);
|
|
|
|
}
|
2016-11-24 22:25:49 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->ocur == -1) {
|
|
|
|
sprintf (buf, "woa 01 @ $$+%i!1", core->print->cur);
|
|
|
|
} else {
|
|
|
|
sprintf (buf, "woa 01 @ $$+%i!%i", core->print->cur < core->print->ocur
|
2016-11-24 22:25:49 +00:00
|
|
|
? core->print->cur
|
|
|
|
: core->print->ocur,
|
|
|
|
R_ABS (core->print->ocur - core->print->cur) + 1);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!autoblocksize) {
|
|
|
|
r_core_block_size (core, core->blocksize + 1);
|
2016-11-24 22:25:49 +00:00
|
|
|
}
|
2016-05-17 11:12:06 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2019-08-30 17:43:12 +00:00
|
|
|
case '/': {
|
|
|
|
bool mouse_state = __holdMouseState (core);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2019-04-08 23:45:09 +00:00
|
|
|
if (core->seltab < 2 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
if (core->seltab) {
|
|
|
|
const char *creg = core->dbg->creg;
|
|
|
|
if (creg) {
|
2020-05-12 23:28:23 +00:00
|
|
|
int delta = core->rasm->bits / 8;
|
2019-04-08 23:45:09 +00:00
|
|
|
r_core_cmdf (core, "dr %s = %s-%d\n", creg, creg, delta);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
|
|
|
r_config_get_i (core->config, "stack.size") - w);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
visual_search (core);
|
|
|
|
}
|
2014-09-28 02:01:31 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (autoblocksize) {
|
2018-08-10 13:24:24 +00:00
|
|
|
r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`");
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
r_core_block_size (core, core->blocksize - cols);
|
|
|
|
}
|
2014-09-28 02:01:31 +00:00
|
|
|
}
|
2019-08-30 17:43:12 +00:00
|
|
|
r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel"));
|
|
|
|
} break;
|
2017-12-18 01:44:51 +00:00
|
|
|
case '(':
|
|
|
|
snowMode = !snowMode;
|
|
|
|
if (!snowMode) {
|
|
|
|
r_list_free (snows);
|
|
|
|
snows = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2019-02-12 01:24:47 +00:00
|
|
|
case ')':
|
|
|
|
rotateAsmemu (core);
|
|
|
|
break;
|
2018-06-06 15:08:31 +00:00
|
|
|
case '#':
|
2019-03-04 00:45:12 +00:00
|
|
|
if (core->printidx == 1) {
|
2019-03-05 10:08:41 +00:00
|
|
|
r_core_visual_toggle_decompiler_disasm (core, false, false);
|
2019-03-04 00:45:12 +00:00
|
|
|
} else {
|
|
|
|
// do nothing for now :?, px vs pxa?
|
|
|
|
}
|
2018-06-06 15:08:31 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '*':
|
|
|
|
if (core->print->cur_enabled) {
|
2019-04-08 23:45:09 +00:00
|
|
|
if (core->seltab < 2 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
if (core->seltab) {
|
|
|
|
const char *creg = core->dbg->creg;
|
|
|
|
if (creg) {
|
2020-05-12 23:28:23 +00:00
|
|
|
int delta = core->rasm->bits / 8;
|
2019-04-08 23:45:09 +00:00
|
|
|
r_core_cmdf (core, "dr %s = %s+%d\n", creg, creg, delta);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
|
|
|
r_config_get_i (core->config, "stack.size") + w);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else if (!autoblocksize) {
|
|
|
|
r_core_block_size (core, core->blocksize + cols);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if (core->print->cur_enabled) {
|
2018-11-15 02:01:26 +00:00
|
|
|
if (core->print->ocur == -1) {
|
|
|
|
eprintf ("No range selected. Use HJKL.\n");
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
break;
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
char buf[128];
|
2018-11-15 02:01:26 +00:00
|
|
|
// TODO autocomplete filenames
|
|
|
|
prompt_read ("dump to file: ", buf, sizeof (buf));
|
|
|
|
if (buf[0]) {
|
|
|
|
ut64 from = core->offset + core->print->ocur;
|
|
|
|
ut64 size = R_ABS (core->print->cur - core->print->ocur) + 1;
|
|
|
|
r_core_dump (core, buf, from, size, false);
|
|
|
|
}
|
2014-02-20 01:11:04 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + core->blocksize, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
2014-02-20 01:11:04 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2017-03-24 10:34:40 +00:00
|
|
|
case '<': // "V<"
|
2016-02-07 16:06:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2017-02-22 22:45:51 +00:00
|
|
|
char buf[128];
|
2018-11-15 02:01:26 +00:00
|
|
|
// TODO autocomplete filenames
|
|
|
|
prompt_read ("load from file: ", buf, sizeof (buf));
|
|
|
|
if (buf[0]) {
|
2020-03-15 22:34:38 +00:00
|
|
|
size_t sz;
|
2018-11-15 02:01:26 +00:00
|
|
|
char *data = r_file_slurp (buf, &sz);
|
|
|
|
if (data) {
|
|
|
|
int cur;
|
|
|
|
if (core->print->ocur != -1) {
|
|
|
|
cur = R_MIN (core->print->cur, core->print->ocur);
|
|
|
|
} else {
|
|
|
|
cur = core->print->cur;
|
|
|
|
}
|
|
|
|
ut64 from = core->offset + cur;
|
|
|
|
ut64 size = R_ABS (core->print->cur - core->print->ocur) + 1;
|
2020-03-15 22:34:38 +00:00
|
|
|
ut64 s = R_MIN (size, (ut64)sz);
|
2018-11-15 02:01:26 +00:00
|
|
|
r_io_write_at (core->io, from, (const ut8*)data, s);
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset - core->blocksize, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
2011-05-21 12:27:46 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2017-03-24 10:34:40 +00:00
|
|
|
case '.': // "V."
|
2017-02-22 22:45:51 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
r_config_set_i (core->config, "stack.delta", 0);
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->offset + core->print->cur, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->cur = 0;
|
2015-12-22 22:09:23 +00:00
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
ut64 addr = r_debug_reg_get (core->dbg, "PC");
|
2017-03-24 00:06:41 +00:00
|
|
|
if (addr && addr != UT64_MAX) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_cmdf (core, "ar `arn PC`=0x%"PFMT64x, addr);
|
|
|
|
} else {
|
2017-03-24 00:06:41 +00:00
|
|
|
ut64 entry = r_num_get (core->num, "entry0");
|
|
|
|
if (!entry || entry == UT64_MAX) {
|
2019-01-13 02:07:51 +00:00
|
|
|
RBinObject *o = r_bin_cur_object (core->bin);
|
|
|
|
RBinSection *s = o? r_bin_get_section_at (o, addr, core->io->va): NULL;
|
2017-03-24 00:06:41 +00:00
|
|
|
if (s) {
|
|
|
|
entry = s->vaddr;
|
|
|
|
} else {
|
2020-04-07 10:43:41 +00:00
|
|
|
RIOMap *map = r_pvector_pop (&core->io->maps);
|
2017-03-24 00:06:41 +00:00
|
|
|
if (map) {
|
2020-12-08 14:57:08 +00:00
|
|
|
entry = r_io_map_begin (map);
|
2017-03-24 00:06:41 +00:00
|
|
|
} else {
|
|
|
|
entry = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
}
|
2020-04-07 10:43:41 +00:00
|
|
|
r_pvector_push_front (&core->io->maps, map);
|
2017-03-24 00:06:41 +00:00
|
|
|
}
|
2017-03-24 00:28:24 +00:00
|
|
|
}
|
2017-03-24 10:34:40 +00:00
|
|
|
if (entry != UT64_MAX) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, entry, true);
|
2017-03-24 00:06:41 +00:00
|
|
|
}
|
2015-12-22 22:09:23 +00:00
|
|
|
}
|
2011-05-21 12:27:46 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case 'n': r_core_seek_delta (core, core->blocksize); break;
|
|
|
|
case 'N': r_core_seek_delta (core, 0 - (int) core->blocksize); break;
|
|
|
|
#endif
|
|
|
|
case ':':
|
|
|
|
r_core_visual_prompt_input (core);
|
|
|
|
break;
|
|
|
|
case '_':
|
|
|
|
r_core_visual_hudstuff (core);
|
|
|
|
break;
|
|
|
|
case ';':
|
2018-05-18 08:35:33 +00:00
|
|
|
r_cons_enable_mouse (false);
|
2017-04-12 01:11:17 +00:00
|
|
|
r_cons_gotoxy (0, 0);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_printf ("Enter a comment: ('-' to remove, '!' to use $EDITOR)\n");
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (false);
|
|
|
|
r_line_set_prompt ("comment: ");
|
|
|
|
strcpy (buf, "\"CC ");
|
|
|
|
i = strlen (buf);
|
2020-02-29 19:47:10 +00:00
|
|
|
if (r_cons_fgets (buf + i, sizeof (buf) - i, 0, NULL) > 0) {
|
2017-02-22 22:45:51 +00:00
|
|
|
ut64 addr, orig;
|
|
|
|
addr = orig = core->offset;
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
addr += core->print->cur;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, addr, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_cmdf (core, "s 0x%"PFMT64x, addr);
|
|
|
|
}
|
|
|
|
if (!strcmp (buf + i, "-")) {
|
|
|
|
strcpy (buf, "CC-");
|
|
|
|
} else {
|
|
|
|
switch (buf[i]) {
|
|
|
|
case '-':
|
|
|
|
memcpy (buf, "\"CC-\x00", 5);
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
memcpy (buf, "\"CC!\x00", 5);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
memcpy (buf, "\"CC ", 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strcat (buf, "\"");
|
|
|
|
}
|
|
|
|
if (buf[3] == ' ') {
|
|
|
|
// have to escape any quotes.
|
|
|
|
int j, len = strlen (buf);
|
|
|
|
char *duped = strdup (buf);
|
2020-03-05 18:06:59 +00:00
|
|
|
for (i = 4, j = 4; i < len; i++, j++) {
|
2017-02-22 22:45:51 +00:00
|
|
|
char c = duped[i];
|
|
|
|
if (c == '"' && i != (len - 1)) {
|
|
|
|
buf[j] = '\\';
|
2018-12-29 10:17:56 +00:00
|
|
|
j++;
|
2017-02-22 22:45:51 +00:00
|
|
|
buf[j] = '"';
|
|
|
|
} else {
|
|
|
|
buf[j] = c;
|
|
|
|
}
|
2016-04-08 01:25:32 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
free (duped);
|
|
|
|
}
|
|
|
|
r_core_cmd (core, buf, 1);
|
|
|
|
if (core->print->cur_enabled) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, orig, true);
|
2016-04-08 01:25:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_set_raw (true);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
2019-01-14 00:35:17 +00:00
|
|
|
r_core_visual_browse (core, arg + 1);
|
2017-10-16 14:15:15 +00:00
|
|
|
break;
|
|
|
|
case 'B':
|
2017-07-02 21:39:30 +00:00
|
|
|
{
|
2017-02-22 22:45:51 +00:00
|
|
|
ut64 addr = core->print->cur_enabled? core->offset + core->print->cur: core->offset;
|
2017-07-02 21:39:30 +00:00
|
|
|
r_core_cmdf (core, "dbs 0x%08"PFMT64x, addr);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2017-07-02 21:37:13 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'u':
|
2011-12-04 20:09:16 +00:00
|
|
|
{
|
2017-02-22 22:45:51 +00:00
|
|
|
RIOUndos *undo = r_io_sundo (core->io, core->offset);
|
|
|
|
if (undo) {
|
|
|
|
r_core_visual_seek_animation (core, undo->off);
|
|
|
|
core->print->cur = undo->cursor;
|
|
|
|
} else {
|
|
|
|
eprintf ("Cannot undo\n");
|
|
|
|
}
|
2011-12-04 20:09:16 +00:00
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'U':
|
2011-12-05 07:27:16 +00:00
|
|
|
{
|
2017-02-22 22:45:51 +00:00
|
|
|
RIOUndos *undo = r_io_sundo_redo (core->io);
|
|
|
|
if (undo) {
|
|
|
|
r_core_visual_seek_animation (core, undo->off);
|
|
|
|
reset_print_cur (core->print);
|
|
|
|
}
|
2015-11-13 16:47:15 +00:00
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'z':
|
2015-12-14 09:19:07 +00:00
|
|
|
{
|
2017-02-22 22:45:51 +00:00
|
|
|
RAnalFunction *fcn;
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
fcn = r_anal_get_fcn_in (core->anal,
|
|
|
|
core->offset + core->print->cur, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
} else {
|
|
|
|
fcn = r_anal_get_fcn_in (core->anal,
|
|
|
|
core->offset, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
}
|
|
|
|
if (fcn) {
|
|
|
|
fcn->folded = !fcn->folded;
|
|
|
|
} else {
|
2018-02-22 16:59:08 +00:00
|
|
|
r_config_toggle (core->config, "asm.cmt.fold");
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2011-02-23 02:01:26 +00:00
|
|
|
}
|
2011-02-16 23:58:54 +00:00
|
|
|
break;
|
2018-12-29 10:17:56 +00:00
|
|
|
case 'Z': // shift-tab SHIFT-TAB
|
2019-03-18 01:51:12 +00:00
|
|
|
if (och == 27) { // shift-tab
|
|
|
|
if (core->print->cur_enabled && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
core->seltab--;
|
|
|
|
if (core->seltab < 0) {
|
|
|
|
core->seltab = 2;
|
|
|
|
}
|
|
|
|
} else {
|
2019-11-07 09:46:23 +00:00
|
|
|
prevPrintFormat (core);
|
2019-03-18 01:51:12 +00:00
|
|
|
}
|
|
|
|
} else { // "Z"
|
|
|
|
ut64 addr = core->print->cur_enabled? core->offset + core->print->cur: core->offset;
|
|
|
|
toggle_bb (core, addr);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
2019-09-01 18:26:25 +00:00
|
|
|
if (visual_help (core) == '?') {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_visual_hud (core);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1b:
|
|
|
|
case 'q':
|
|
|
|
case 'Q':
|
|
|
|
setcursor (core, false);
|
|
|
|
return false;
|
2016-11-24 03:44:25 +00:00
|
|
|
}
|
2018-11-15 02:00:19 +00:00
|
|
|
numbuf_i = 0;
|
2009-02-09 00:54:09 +00:00
|
|
|
}
|
2016-08-15 18:56:23 +00:00
|
|
|
r_core_block_read (core);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2009-02-09 00:54:09 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
R_API void r_core_visual_title(RCore *core, int color) {
|
2018-02-22 11:45:54 +00:00
|
|
|
bool showDelta = r_config_get_i (core->config, "scr.slow");
|
2014-10-22 22:07:30 +00:00
|
|
|
static ut64 oldpc = 0;
|
2019-01-18 10:58:49 +00:00
|
|
|
const char *BEGIN = core->cons->context->pal.prompt;
|
2011-02-09 23:21:05 +00:00
|
|
|
const char *filename;
|
2018-07-08 23:13:03 +00:00
|
|
|
char pos[512], bar[512], pcs[32];
|
2016-12-03 11:27:32 +00:00
|
|
|
if (!oldpc) {
|
|
|
|
oldpc = r_debug_reg_get (core->dbg, "PC");
|
|
|
|
}
|
2011-01-23 16:48:31 +00:00
|
|
|
/* automatic block size */
|
2015-03-22 15:49:29 +00:00
|
|
|
int pc, hexcols = r_config_get_i (core->config, "hex.cols");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (autoblocksize) {
|
|
|
|
switch (core->printidx) {
|
2018-12-28 18:40:54 +00:00
|
|
|
#if 0
|
2018-05-04 22:58:13 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PXR: // prc
|
2017-06-09 13:58:49 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PRC: // prc
|
2017-12-18 23:17:43 +00:00
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 3.5));
|
2017-05-29 02:36:34 +00:00
|
|
|
break;
|
2017-06-09 13:58:49 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PXa: // pxa
|
|
|
|
case R_CORE_VISUAL_MODE_PW: // XXX pw
|
2017-12-18 23:17:43 +00:00
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols));
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2017-06-09 13:58:49 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PC: // XXX pc
|
2017-12-18 23:17:43 +00:00
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 4));
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2018-12-28 18:40:54 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PXA: // pxA
|
|
|
|
r_core_block_size (core, hexcols * core->cons->rows * 8);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case R_CORE_VISUAL_MODE_PX: // x
|
2019-11-07 09:46:23 +00:00
|
|
|
if (currentFormat == 3 || currentFormat == 9 || currentFormat == 5) { // prx
|
2019-05-13 13:12:44 +00:00
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 4));
|
2019-11-07 09:46:23 +00:00
|
|
|
} else if ((R_ABS (hexMode) % 3) == 0) { // prx
|
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols));
|
2019-05-13 13:12:44 +00:00
|
|
|
} else {
|
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 2));
|
|
|
|
}
|
|
|
|
break;
|
2018-12-28 18:40:54 +00:00
|
|
|
case R_CORE_VISUAL_MODE_OV:
|
|
|
|
case R_CORE_VISUAL_MODE_CD:
|
2019-04-29 09:51:13 +00:00
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 2));
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
2017-06-09 13:58:49 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PD: // pd
|
2018-12-28 18:40:54 +00:00
|
|
|
case R_CORE_VISUAL_MODE_DB: // pd+dbg
|
2017-02-22 22:45:51 +00:00
|
|
|
{
|
|
|
|
int bsize = core->cons->rows * 5;
|
|
|
|
|
|
|
|
if (core->print->screen_bounds > 1) {
|
|
|
|
// estimate new blocksize with the size of the last
|
|
|
|
// printed instructions
|
|
|
|
int new_sz = core->print->screen_bounds - core->offset + 32;
|
2018-12-19 21:57:00 +00:00
|
|
|
new_sz = R_MIN (new_sz, 16 * 1024);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (new_sz > bsize) {
|
|
|
|
bsize = new_sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_core_block_size (core, bsize);
|
|
|
|
break;
|
|
|
|
}
|
2016-02-12 23:46:33 +00:00
|
|
|
}
|
2011-01-23 16:48:31 +00:00
|
|
|
}
|
2019-04-11 04:48:22 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.scrollbar") == 2) {
|
2016-10-06 00:40:26 +00:00
|
|
|
r_core_cmd (core, "fz:", 0);
|
|
|
|
}
|
2014-10-22 22:07:30 +00:00
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
2015-10-31 01:20:25 +00:00
|
|
|
ut64 curpc = r_debug_reg_get (core->dbg, "PC");
|
2015-10-15 15:28:34 +00:00
|
|
|
if (curpc && curpc != UT64_MAX && curpc != oldpc) {
|
2014-10-22 22:07:30 +00:00
|
|
|
// check dbg.follow here
|
2017-02-22 22:45:51 +00:00
|
|
|
int follow = (int) (st64) r_config_get_i (core->config, "dbg.follow");
|
2016-06-02 01:19:31 +00:00
|
|
|
if (follow > 0) {
|
2017-02-22 22:45:51 +00:00
|
|
|
if ((curpc < core->offset) || (curpc > (core->offset + follow))) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, curpc, true);
|
2016-06-02 01:19:31 +00:00
|
|
|
}
|
|
|
|
} else if (follow < 0) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, curpc + follow, true);
|
2014-10-22 22:07:30 +00:00
|
|
|
}
|
|
|
|
oldpc = curpc;
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 03:55:31 +00:00
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
RIODesc *desc = map
|
|
|
|
? r_io_desc_get (core->io, map->fd)
|
|
|
|
: core->file? r_io_desc_get (core->io, core->file->fd): NULL;
|
2018-02-23 17:27:03 +00:00
|
|
|
filename = desc? desc->name: "";
|
2020-07-02 03:55:31 +00:00
|
|
|
|
2011-11-22 00:42:16 +00:00
|
|
|
{ /* get flag with delta */
|
2016-02-07 16:06:39 +00:00
|
|
|
ut64 addr = core->offset + (core->print->cur_enabled? core->print->cur: 0);
|
2016-11-23 11:30:43 +00:00
|
|
|
/* TODO: we need a helper into r_flags to do that */
|
|
|
|
RFlagItem *f = NULL;
|
2019-02-23 00:31:06 +00:00
|
|
|
if (r_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS)) {
|
|
|
|
f = r_flag_get_at (core->flags, addr, showDelta);
|
|
|
|
r_flag_space_pop (core->flags);
|
2016-11-23 11:30:43 +00:00
|
|
|
}
|
|
|
|
if (!f) {
|
2018-02-22 11:45:54 +00:00
|
|
|
f = r_flag_get_at (core->flags, addr, showDelta);
|
2016-11-23 11:30:43 +00:00
|
|
|
}
|
2011-11-22 00:42:16 +00:00
|
|
|
if (f) {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (f->offset == addr || !f->offset) {
|
2012-11-14 02:25:32 +00:00
|
|
|
snprintf (pos, sizeof (pos), "@ %s", f->name);
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
snprintf (pos, sizeof (pos), "@ %s+%d # 0x%"PFMT64x,
|
|
|
|
f->name, (int) (addr - f->offset), addr);
|
|
|
|
}
|
2016-11-23 11:30:43 +00:00
|
|
|
} else {
|
2017-01-11 22:56:36 +00:00
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0);
|
|
|
|
if (fcn) {
|
|
|
|
int delta = addr - fcn->addr;
|
|
|
|
if (delta > 0) {
|
|
|
|
snprintf (pos, sizeof (pos), "@ %s+%d", fcn->name, delta);
|
|
|
|
} else if (delta < 0) {
|
|
|
|
snprintf (pos, sizeof (pos), "@ %s%d", fcn->name, delta);
|
|
|
|
} else {
|
|
|
|
snprintf (pos, sizeof (pos), "@ %s", fcn->name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pos[0] = 0;
|
|
|
|
}
|
2016-11-23 11:30:43 +00:00
|
|
|
}
|
2011-11-22 00:42:16 +00:00
|
|
|
}
|
2011-02-09 23:21:05 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->cur < 0) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
}
|
2013-02-27 00:40:26 +00:00
|
|
|
|
2017-02-22 22:45:51 +00:00
|
|
|
if (color) {
|
|
|
|
r_cons_strcat (BEGIN);
|
|
|
|
}
|
2017-05-03 00:54:31 +00:00
|
|
|
const char *cmd_visual = r_config_get (core->config, "cmd.visual");
|
|
|
|
if (cmd_visual && *cmd_visual) {
|
2020-07-02 03:55:31 +00:00
|
|
|
r_str_ncpy (bar, cmd_visual, sizeof (bar) - 1);
|
2017-05-03 01:05:01 +00:00
|
|
|
bar[10] = '.'; // chop cmdfmt
|
|
|
|
bar[11] = '.'; // chop cmdfmt
|
|
|
|
bar[12] = 0; // chop cmdfmt
|
2017-05-03 00:54:31 +00:00
|
|
|
} else {
|
2019-01-05 10:51:46 +00:00
|
|
|
const char *cmd = __core_visual_print_command (core);
|
2018-12-28 18:40:54 +00:00
|
|
|
if (cmd) {
|
2020-07-02 03:55:31 +00:00
|
|
|
r_str_ncpy (bar, cmd, sizeof (bar) - 1);
|
2018-12-28 18:40:54 +00:00
|
|
|
bar[10] = '.'; // chop cmdfmt
|
|
|
|
bar[11] = '.'; // chop cmdfmt
|
|
|
|
bar[12] = 0; // chop cmdfmt
|
|
|
|
}
|
2017-05-03 00:54:31 +00:00
|
|
|
}
|
2015-02-06 18:24:26 +00:00
|
|
|
{
|
|
|
|
ut64 sz = r_io_size (core->io);
|
2019-01-13 02:07:51 +00:00
|
|
|
ut64 pa = core->offset;
|
2017-08-22 07:42:16 +00:00
|
|
|
{
|
2019-01-13 02:07:51 +00:00
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
|
|
|
if (map) {
|
|
|
|
pa = map->delta;
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
}
|
2015-02-06 18:24:26 +00:00
|
|
|
if (sz == UT64_MAX) {
|
|
|
|
pcs[0] = 0;
|
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (!sz || pa > sz) {
|
2015-02-06 18:24:26 +00:00
|
|
|
pc = 0;
|
|
|
|
} else {
|
2017-02-22 22:45:51 +00:00
|
|
|
pc = (pa * 100) / sz;
|
2015-02-06 18:24:26 +00:00
|
|
|
}
|
|
|
|
sprintf (pcs, "%d%% ", pc);
|
|
|
|
}
|
|
|
|
}
|
2018-07-08 23:13:03 +00:00
|
|
|
{
|
|
|
|
char *title;
|
2018-12-31 02:06:05 +00:00
|
|
|
char *address = (core->print->wide_offsets && core->dbg->bits & R_SYS_BITS_64)
|
|
|
|
? r_str_newf ("0x%016"PFMT64x, core->offset)
|
|
|
|
: r_str_newf ("0x%08"PFMT64x, core->offset);
|
2018-07-08 23:13:03 +00:00
|
|
|
if (__ime) {
|
2018-12-31 02:06:05 +00:00
|
|
|
title = r_str_newf ("[%s + %d> * INSERT MODE *\n",
|
|
|
|
address, core->print->cur);
|
2016-07-25 03:14:48 +00:00
|
|
|
} else {
|
2018-12-29 10:17:56 +00:00
|
|
|
char pm[32] = "[XADVC]";
|
|
|
|
int i;
|
|
|
|
for(i=0;i<6;i++) {
|
|
|
|
if (core->printidx == i) {
|
|
|
|
pm[i + 1] = toupper(pm[i + 1]);
|
|
|
|
} else {
|
|
|
|
pm[i + 1] = tolower(pm[i + 1]);
|
|
|
|
}
|
|
|
|
}
|
2018-07-08 23:13:03 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2018-11-15 02:08:44 +00:00
|
|
|
if (core->print->ocur == -1) {
|
2019-07-03 22:59:27 +00:00
|
|
|
title = r_str_newf ("[%s *0x%08"PFMT64x" %s%d ($$+0x%x)]> %s %s\n",
|
2018-12-31 02:06:05 +00:00
|
|
|
address, core->offset + core->print->cur,
|
2019-07-03 22:59:27 +00:00
|
|
|
pm, currentFormat, core->print->cur,
|
2018-11-15 02:08:44 +00:00
|
|
|
bar, pos);
|
|
|
|
} else {
|
2019-07-03 22:59:27 +00:00
|
|
|
title = r_str_newf ("[%s 0x%08"PFMT64x" %s%d [0x%x..0x%x] %d]> %s %s\n",
|
2018-12-31 02:06:05 +00:00
|
|
|
address, core->offset + core->print->cur,
|
2019-07-03 22:59:27 +00:00
|
|
|
pm, currentFormat, core->print->ocur, core->print->cur,
|
2018-12-31 02:06:05 +00:00
|
|
|
R_ABS (core->print->cur - core->print->ocur) + 1,
|
2018-11-15 02:08:44 +00:00
|
|
|
bar, pos);
|
|
|
|
}
|
2018-07-08 23:13:03 +00:00
|
|
|
} else {
|
2019-07-03 22:59:27 +00:00
|
|
|
title = r_str_newf ("[%s %s%d %s%d %s]> %s %s\n",
|
|
|
|
address, pm, currentFormat, pcs, core->blocksize, filename, bar, pos);
|
2018-07-08 23:13:03 +00:00
|
|
|
}
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2019-03-05 10:08:41 +00:00
|
|
|
const int tabsCount = __core_visual_tab_count (core);
|
2018-08-16 09:01:53 +00:00
|
|
|
if (tabsCount > 0) {
|
2019-01-18 10:58:49 +00:00
|
|
|
const char *kolor = core->cons->context->pal.prompt;
|
2019-03-05 10:08:41 +00:00
|
|
|
char *tabstring = __core_visual_tab_string (core, kolor);
|
2018-12-31 12:56:47 +00:00
|
|
|
if (tabstring) {
|
2018-12-31 10:27:46 +00:00
|
|
|
title = r_str_append (title, tabstring);
|
|
|
|
free (tabstring);
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
#if 0
|
|
|
|
// TODO: add an option to show this tab mode instead?
|
2018-08-16 09:01:53 +00:00
|
|
|
const int curTab = core->visual.tab;
|
|
|
|
r_cons_printf ("[");
|
|
|
|
int i;
|
2018-10-01 17:57:33 +00:00
|
|
|
for (i = 0; i < tabsCount; i++) {
|
2018-12-29 10:17:56 +00:00
|
|
|
if (i == curTab) {
|
|
|
|
r_cons_printf ("%d", curTab + 1);
|
2018-08-16 09:01:53 +00:00
|
|
|
} else {
|
|
|
|
r_cons_printf (".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_cons_printf ("]");
|
2019-03-05 10:08:41 +00:00
|
|
|
r_cons_printf ("[tab:%d/%d]", core->visual.tab, tabsCount);
|
2018-12-29 10:17:56 +00:00
|
|
|
#endif
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
2018-07-08 23:13:03 +00:00
|
|
|
r_cons_print (title);
|
|
|
|
free (title);
|
2018-12-31 10:27:46 +00:00
|
|
|
free (address);
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
|
|
|
if (color) {
|
|
|
|
r_cons_strcat (Color_RESET);
|
|
|
|
}
|
2009-02-09 11:42:54 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 20:15:24 +00:00
|
|
|
static int visual_responsive(RCore *core) {
|
2015-11-23 16:09:46 +00:00
|
|
|
int h, w = r_cons_get_size (&h);
|
2014-09-11 02:18:23 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.responsive")) {
|
2017-02-22 22:45:51 +00:00
|
|
|
if (w < 110) {
|
2018-02-22 16:59:08 +00:00
|
|
|
r_config_set_i (core->config, "asm.cmt.right", 0);
|
2014-11-06 10:11:51 +00:00
|
|
|
} else {
|
2018-02-22 16:59:08 +00:00
|
|
|
r_config_set_i (core->config, "asm.cmt.right", 1);
|
2014-11-06 10:11:51 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (w < 68) {
|
2019-03-20 06:32:49 +00:00
|
|
|
r_config_set_i (core->config, "hex.cols", (int)(w / 5.2));
|
2014-09-11 02:18:23 +00:00
|
|
|
} else {
|
|
|
|
r_config_set_i (core->config, "hex.cols", 16);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (w < 25) {
|
2014-09-11 02:18:23 +00:00
|
|
|
r_config_set_i (core->config, "asm.offset", 0);
|
|
|
|
} else {
|
|
|
|
r_config_set_i (core->config, "asm.offset", 1);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (w > 80) {
|
2018-05-18 08:29:00 +00:00
|
|
|
r_config_set_i (core->config, "asm.lines.width", 14);
|
2019-03-20 06:32:49 +00:00
|
|
|
r_config_set_i (core->config, "asm.lines.width", w - (int)(w / 1.2));
|
|
|
|
r_config_set_i (core->config, "asm.cmt.col", w - (int)(w / 2.5));
|
2014-09-11 02:18:23 +00:00
|
|
|
} else {
|
2018-05-18 08:29:00 +00:00
|
|
|
r_config_set_i (core->config, "asm.lines.width", 7);
|
2014-09-11 02:18:23 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (w < 70) {
|
2018-05-18 08:29:00 +00:00
|
|
|
r_config_set_i (core->config, "asm.lines.width", 1);
|
2014-09-11 02:18:23 +00:00
|
|
|
r_config_set_i (core->config, "asm.bytes", 0);
|
|
|
|
} else {
|
|
|
|
r_config_set_i (core->config, "asm.bytes", 1);
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 16:09:46 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2019-03-29 15:10:59 +00:00
|
|
|
// TODO: use colors
|
2019-04-03 00:29:10 +00:00
|
|
|
// TODO: find better name
|
|
|
|
R_API void r_core_print_scrollbar(RCore *core) {
|
2018-11-12 23:22:22 +00:00
|
|
|
int i, h, w = r_cons_get_size (&h);
|
|
|
|
|
2019-04-11 04:48:22 +00:00
|
|
|
int scrollbar = r_config_get_i (core->config, "scr.scrollbar");
|
|
|
|
if (scrollbar == 2) {
|
|
|
|
// already handled by r_core_cmd("zf:") in visual.c
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scrollbar > 2) {
|
2019-04-11 02:48:14 +00:00
|
|
|
r_core_print_scrollbar_bottom (core);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-12 23:22:22 +00:00
|
|
|
if (w < 10 || h < 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ut64 from = 0;
|
|
|
|
ut64 to = UT64_MAX;
|
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
from = r_num_math (core->num, "$D");
|
|
|
|
to = r_num_math (core->num, "$D+$DD");
|
|
|
|
} else if (r_config_get_i (core->config, "io.va")) {
|
|
|
|
from = r_num_math (core->num, "$S");
|
|
|
|
to = r_num_math (core->num, "$S+$SS");
|
|
|
|
} else {
|
|
|
|
to = r_num_math (core->num, "$s");
|
|
|
|
}
|
|
|
|
char *s = r_str_newf ("[0x%08"PFMT64x"]", from);
|
2019-03-29 15:10:59 +00:00
|
|
|
r_cons_gotoxy (w - strlen (s) + 1, 2);
|
2018-11-12 23:22:22 +00:00
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
|
|
|
|
ut64 block = (to - from) / h;
|
2019-03-29 15:10:59 +00:00
|
|
|
|
|
|
|
RList *words = r_flag_zone_barlist (core->flags, from, block, h);
|
|
|
|
|
2018-11-12 23:22:22 +00:00
|
|
|
bool hadMatch = false;
|
|
|
|
for (i = 0; i < h ; i++) {
|
2019-03-29 15:10:59 +00:00
|
|
|
const char *word = r_list_pop_head (words);
|
|
|
|
if (word && *word) {
|
|
|
|
r_cons_gotoxy (w - strlen (word) - 1, i + 3);
|
|
|
|
r_cons_printf ("%s>", word);
|
|
|
|
}
|
|
|
|
r_cons_gotoxy (w, i + 3);
|
2018-11-12 23:22:22 +00:00
|
|
|
if (hadMatch) {
|
|
|
|
r_cons_printf ("|");
|
|
|
|
} else {
|
|
|
|
ut64 cur = from + (block * i);
|
|
|
|
ut64 nex = from + (block * (i + 1));
|
|
|
|
if (R_BETWEEN (cur, core->offset, nex)) {
|
|
|
|
r_cons_printf (Color_INVERT"|"Color_RESET);
|
|
|
|
hadMatch = true;
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("|");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = r_str_newf ("[0x%08"PFMT64x"]", to);
|
2019-03-09 16:36:59 +00:00
|
|
|
if (s) {
|
|
|
|
r_cons_gotoxy (w - strlen (s) + 1, h + 1);
|
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
}
|
2019-03-29 15:10:59 +00:00
|
|
|
r_list_free (words);
|
2018-11-12 23:22:22 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
}
|
|
|
|
|
2019-04-11 02:48:14 +00:00
|
|
|
R_API void r_core_print_scrollbar_bottom(RCore *core) {
|
|
|
|
int i, h, w = r_cons_get_size (&h);
|
|
|
|
|
|
|
|
if (w < 10 || h < 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ut64 from = 0;
|
|
|
|
ut64 to = UT64_MAX;
|
|
|
|
if (r_config_get_i (core->config, "cfg.debug")) {
|
|
|
|
from = r_num_math (core->num, "$D");
|
|
|
|
to = r_num_math (core->num, "$D+$DD");
|
|
|
|
} else if (r_config_get_i (core->config, "io.va")) {
|
|
|
|
from = r_num_math (core->num, "$S");
|
|
|
|
to = r_num_math (core->num, "$S+$SS");
|
|
|
|
} else {
|
|
|
|
to = r_num_math (core->num, "$s");
|
|
|
|
}
|
|
|
|
char *s = r_str_newf ("[0x%08"PFMT64x"]", from);
|
|
|
|
int slen = strlen (s) + 1;
|
|
|
|
r_cons_gotoxy (0, h + 1);
|
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
|
|
|
|
int linew = (w - (slen * 2)) + 1;
|
|
|
|
ut64 block = (to - from) / linew;
|
|
|
|
|
|
|
|
RList *words = r_flag_zone_barlist (core->flags, from, block, h);
|
|
|
|
|
|
|
|
bool hadMatch = false;
|
|
|
|
for (i = 0; i < linew + 1; i++) {
|
|
|
|
r_cons_gotoxy (i + slen, h + 1);
|
|
|
|
if (hadMatch) {
|
|
|
|
r_cons_strcat ("-");
|
|
|
|
} else {
|
|
|
|
ut64 cur = from + (block * i);
|
|
|
|
ut64 nex = from + (block * (i + 2));
|
|
|
|
if (R_BETWEEN (cur, core->offset, nex)) {
|
|
|
|
r_cons_strcat (Color_INVERT"-"Color_RESET);
|
|
|
|
hadMatch = true;
|
|
|
|
} else {
|
|
|
|
r_cons_strcat ("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < linew; i++) {
|
|
|
|
const char *word = r_list_pop_head (words);
|
|
|
|
if (word && *word) {
|
|
|
|
ut64 cur = from + (block * i);
|
|
|
|
ut64 nex = from + (block * (i + strlen (word) + 1));
|
|
|
|
r_cons_gotoxy (i + slen - 1, h);
|
|
|
|
if (R_BETWEEN (cur, core->offset, nex)) {
|
|
|
|
r_cons_printf (Color_INVERT"{%s}"Color_RESET, word);
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("{%s}", word);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = r_str_newf ("[0x%08"PFMT64x"]", to);
|
|
|
|
if (s) {
|
|
|
|
r_cons_gotoxy (linew + slen + 1, h + 1);
|
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
}
|
|
|
|
r_list_free (words);
|
|
|
|
r_cons_flush ();
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:15:47 +00:00
|
|
|
static void show_cursor(RCore *core) {
|
|
|
|
const bool keyCursor = r_config_get_i (core->config, "scr.cursor");
|
|
|
|
if (keyCursor) {
|
|
|
|
r_cons_gotoxy (core->cons->cpos.x, core->cons->cpos.y);
|
|
|
|
r_cons_show_cursor (1);
|
|
|
|
//r_cons_invert (1, 1);
|
|
|
|
//r_cons_print ("#");
|
|
|
|
r_cons_flush ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-10 20:15:24 +00:00
|
|
|
static void visual_refresh(RCore *core) {
|
2017-06-27 22:24:26 +00:00
|
|
|
static ut64 oseek = UT64_MAX;
|
2018-11-23 00:15:05 +00:00
|
|
|
const char *vi, *vcmd, *cmd_str;
|
2017-02-22 22:45:51 +00:00
|
|
|
if (!core) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-07 16:06:39 +00:00
|
|
|
r_print_set_cursor (core->print, core->print->cur_enabled, core->print->ocur, core->print->cur);
|
2015-11-23 16:09:46 +00:00
|
|
|
core->cons->blankline = true;
|
|
|
|
|
2017-06-27 22:24:26 +00:00
|
|
|
int w = visual_responsive (core);
|
2014-09-11 02:18:23 +00:00
|
|
|
|
2012-06-30 18:51:18 +00:00
|
|
|
if (autoblocksize) {
|
|
|
|
r_cons_gotoxy (0, 0);
|
2014-09-17 08:36:38 +00:00
|
|
|
} else {
|
|
|
|
r_cons_clear ();
|
|
|
|
}
|
2015-11-23 16:09:46 +00:00
|
|
|
r_cons_flush ();
|
2012-11-14 02:25:32 +00:00
|
|
|
r_cons_print_clear ();
|
2011-06-05 18:36:22 +00:00
|
|
|
|
2018-11-23 00:15:05 +00:00
|
|
|
int hex_cols = r_config_get_i (core->config, "hex.cols");
|
|
|
|
int split_w = 12 + 4 + hex_cols + (hex_cols * 3);
|
2017-06-28 00:21:16 +00:00
|
|
|
bool ce = core->print->cur_enabled;
|
2018-11-23 00:15:05 +00:00
|
|
|
|
|
|
|
vi = r_config_get (core->config, "cmd.cprompt");
|
|
|
|
bool vsplit = (vi && *vi);
|
|
|
|
|
|
|
|
if (vsplit) {
|
2012-12-07 14:44:36 +00:00
|
|
|
// XXX: slow
|
2015-09-14 10:35:38 +00:00
|
|
|
core->cons->blankline = false;
|
2014-10-06 00:36:22 +00:00
|
|
|
{
|
2018-11-23 00:15:05 +00:00
|
|
|
int hex_cols = r_config_get_i (core->config, "hex.cols");
|
|
|
|
int split_w = 12 + 4 + hex_cols + (hex_cols * 3);
|
|
|
|
if (split_w > w) {
|
2014-10-06 00:36:22 +00:00
|
|
|
// do not show column contents
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("[cmd.cprompt=%s]\n", vi);
|
2017-06-27 22:24:26 +00:00
|
|
|
if (oseek != UT64_MAX) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, oseek, true);
|
2017-06-27 22:24:26 +00:00
|
|
|
}
|
2014-10-06 00:36:22 +00:00
|
|
|
r_core_cmd0 (core, vi);
|
2018-11-23 00:15:05 +00:00
|
|
|
r_cons_column (split_w);
|
2017-06-27 22:24:26 +00:00
|
|
|
if (!strncmp (vi, "p=", 2) && core->print->cur_enabled) {
|
|
|
|
oseek = core->offset;
|
2017-06-28 00:21:16 +00:00
|
|
|
core->print->cur_enabled = false;
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, core->num->value, true);
|
2017-06-27 22:24:26 +00:00
|
|
|
} else {
|
|
|
|
oseek = UT64_MAX;
|
|
|
|
}
|
2014-10-06 00:36:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r_cons_gotoxy (0, 0);
|
2011-05-21 13:45:43 +00:00
|
|
|
}
|
2019-01-11 08:56:27 +00:00
|
|
|
vi = r_config_get (core->config, "cmd.vprompt");
|
|
|
|
if (vi && *vi) {
|
|
|
|
r_core_cmd0 (core, vi);
|
|
|
|
#if 0
|
|
|
|
char *output = r_core_cmd_str (core, vi);
|
|
|
|
r_cons_strcat_at (output, 10, 5, 20, 20);
|
|
|
|
free (output);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
r_core_visual_title (core, color);
|
2013-02-27 00:40:26 +00:00
|
|
|
vcmd = r_config_get (core->config, "cmd.visual");
|
|
|
|
if (vcmd && *vcmd) {
|
2016-02-09 23:26:24 +00:00
|
|
|
// disable screen bounds when it's a user-defined command
|
|
|
|
// because it can cause some issues
|
2016-05-10 20:15:24 +00:00
|
|
|
core->print->screen_bounds = 0;
|
2018-11-23 00:15:05 +00:00
|
|
|
cmd_str = vcmd;
|
2013-02-27 00:40:26 +00:00
|
|
|
} else {
|
2017-08-03 12:52:46 +00:00
|
|
|
if (splitView) {
|
|
|
|
static char debugstr[512];
|
2018-10-31 10:34:13 +00:00
|
|
|
const char *pxw = NULL;
|
2017-08-03 12:52:46 +00:00
|
|
|
int h = r_num_get (core->num, "$r");
|
|
|
|
int size = (h * 16) / 2;
|
|
|
|
switch (core->printidx) {
|
|
|
|
case 1:
|
|
|
|
size = (h - 2) / 2;
|
|
|
|
pxw = "pd";
|
|
|
|
break;
|
|
|
|
default:
|
2018-10-31 10:34:13 +00:00
|
|
|
pxw = stackPrintCommand (core);
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
2017-08-03 12:52:46 +00:00
|
|
|
}
|
|
|
|
snprintf (debugstr, sizeof (debugstr),
|
2017-10-16 14:38:33 +00:00
|
|
|
"?0;%s %d @ %"PFMT64d";cl;"
|
2017-08-03 12:52:46 +00:00
|
|
|
"?1;%s %d @ %"PFMT64d";",
|
|
|
|
pxw, size, splitPtr,
|
|
|
|
pxw, size, core->offset);
|
|
|
|
core->print->screen_bounds = 1LL;
|
2018-11-23 00:15:05 +00:00
|
|
|
cmd_str = debugstr;
|
2017-08-03 12:52:46 +00:00
|
|
|
} else {
|
|
|
|
core->print->screen_bounds = 1LL;
|
2019-01-05 10:51:46 +00:00
|
|
|
cmd_str = (zoom ? "pz" : __core_visual_print_command (core));
|
2018-11-23 00:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cmd_str && *cmd_str) {
|
|
|
|
if (vsplit) {
|
2019-11-07 09:46:23 +00:00
|
|
|
char *cmd_result = r_core_cmd_str (core, cmd_str);
|
2018-11-23 00:15:05 +00:00
|
|
|
cmd_result = r_str_ansi_crop (cmd_result, 0, 0, split_w, -1);
|
|
|
|
r_cons_strcat (cmd_result);
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, cmd_str);
|
2017-08-03 12:52:46 +00:00
|
|
|
}
|
2013-02-27 00:40:26 +00:00
|
|
|
}
|
2017-06-27 22:24:26 +00:00
|
|
|
core->print->cur_enabled = ce;
|
|
|
|
#if 0
|
2016-05-10 20:15:24 +00:00
|
|
|
if (core->print->screen_bounds != 1LL) {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_cons_printf ("[0x%08"PFMT64x "..0x%08"PFMT64x "]\n",
|
2016-05-10 20:15:24 +00:00
|
|
|
core->offset, core->print->screen_bounds);
|
2014-09-22 11:45:36 +00:00
|
|
|
}
|
2017-06-27 22:24:26 +00:00
|
|
|
#endif
|
2017-02-22 22:45:51 +00:00
|
|
|
blocksize = core->num->value? core->num->value: core->blocksize;
|
2012-11-14 02:25:32 +00:00
|
|
|
|
2012-11-30 15:12:54 +00:00
|
|
|
/* this is why there's flickering */
|
2016-02-10 23:10:48 +00:00
|
|
|
if (core->print->vflush) {
|
|
|
|
r_cons_visual_flush ();
|
|
|
|
} else {
|
|
|
|
r_cons_reset ();
|
|
|
|
}
|
2019-01-11 08:56:27 +00:00
|
|
|
if (core->scr_gadgets) {
|
|
|
|
r_core_cmd0 (core, "pg");
|
|
|
|
r_cons_flush ();
|
|
|
|
}
|
2018-11-12 23:22:22 +00:00
|
|
|
core->cons->blankline = false;
|
2015-09-14 10:35:38 +00:00
|
|
|
core->cons->blankline = true;
|
2016-02-25 09:28:54 +00:00
|
|
|
core->curtab = 0; // which command are we focusing
|
|
|
|
//core->seltab = 0; // user selected tab
|
2017-12-18 01:44:51 +00:00
|
|
|
|
|
|
|
if (snowMode) {
|
|
|
|
printSnow (core);
|
|
|
|
}
|
2018-11-12 23:22:22 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.scrollbar")) {
|
2019-04-03 00:29:10 +00:00
|
|
|
r_core_print_scrollbar (core);
|
2018-11-12 23:22:22 +00:00
|
|
|
}
|
2020-12-20 14:15:47 +00:00
|
|
|
show_cursor (core);
|
2011-01-23 12:12:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:26:38 +00:00
|
|
|
static void visual_refresh_oneshot(RCore *core) {
|
2019-11-26 07:52:17 +00:00
|
|
|
r_core_task_enqueue_oneshot (&core->tasks, (RCoreTaskOneShot) visual_refresh, core);
|
2018-07-09 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 19:06:58 +00:00
|
|
|
R_API void r_core_visual_disasm_up(RCore *core, int *cols) {
|
|
|
|
RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
if (f && f->folded) {
|
|
|
|
*cols = core->offset - f->addr; // + f->size;
|
|
|
|
if (*cols < 1) {
|
|
|
|
*cols = 4;
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-06 14:24:31 +00:00
|
|
|
*cols = r_core_visual_prevopsz (core, core->offset);
|
2018-07-29 19:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_core_visual_disasm_down(RCore *core, RAsmOp *op, int *cols) {
|
2019-01-12 10:43:27 +00:00
|
|
|
int midflags = r_config_get_i (core->config, "asm.flags.middle");
|
2018-11-22 14:48:11 +00:00
|
|
|
const bool midbb = r_config_get_i (core->config, "asm.bb.middle");
|
2018-07-29 19:06:58 +00:00
|
|
|
RAnalFunction *f = NULL;
|
|
|
|
f = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
|
|
|
op->size = 1;
|
|
|
|
if (f && f->folded) {
|
2020-01-15 09:58:30 +00:00
|
|
|
*cols = core->offset - r_anal_function_max_addr (f);
|
2018-07-29 19:06:58 +00:00
|
|
|
} else {
|
2020-05-12 23:28:23 +00:00
|
|
|
r_asm_set_pc (core->rasm, core->offset);
|
|
|
|
*cols = r_asm_disassemble (core->rasm,
|
2018-07-29 19:06:58 +00:00
|
|
|
op, core->block, 32);
|
2019-01-12 10:43:27 +00:00
|
|
|
if (midflags || midbb) {
|
|
|
|
int skip_bytes_flag = 0, skip_bytes_bb = 0;
|
2019-03-21 23:41:51 +00:00
|
|
|
if (midflags >= R_MIDFLAGS_REALIGN) {
|
2019-01-12 10:43:27 +00:00
|
|
|
skip_bytes_flag = r_core_flag_in_middle (core, core->offset, *cols, &midflags);
|
|
|
|
}
|
2018-11-22 14:48:11 +00:00
|
|
|
if (midbb) {
|
|
|
|
skip_bytes_bb = r_core_bb_starts_in_middle (core, core->offset, *cols);
|
|
|
|
}
|
2019-03-21 23:41:51 +00:00
|
|
|
if (skip_bytes_flag) {
|
2019-01-12 10:43:27 +00:00
|
|
|
*cols = skip_bytes_flag;
|
|
|
|
}
|
2018-11-22 14:48:11 +00:00
|
|
|
if (skip_bytes_bb && skip_bytes_bb < *cols) {
|
|
|
|
*cols = skip_bytes_bb;
|
|
|
|
}
|
|
|
|
}
|
2018-07-29 19:06:58 +00:00
|
|
|
}
|
|
|
|
if (*cols < 1) {
|
|
|
|
*cols = op->size > 1 ? op->size : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 11:54:11 +00:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
|
|
|
static bool is_mintty(RCons *cons) {
|
|
|
|
return cons->term_xterm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_stdin(void) {
|
|
|
|
while (r_cons_readchar_timeout (1) != -1) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static bool is_mintty(RCons *cons) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_stdin(void) {
|
|
|
|
tcflush (STDIN_FILENO, TCIFLUSH);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_visual(RCore *core, const char *input) {
|
2019-01-11 08:56:27 +00:00
|
|
|
const char *teefile;
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 scrseek;
|
2019-07-02 01:33:57 +00:00
|
|
|
int flags, ch;
|
2016-02-10 23:10:48 +00:00
|
|
|
bool skip;
|
2017-02-22 22:45:51 +00:00
|
|
|
char arg[2] = {
|
|
|
|
input[0], 0
|
|
|
|
};
|
2009-02-09 00:54:09 +00:00
|
|
|
|
2017-08-03 12:52:46 +00:00
|
|
|
splitPtr = UT64_MAX;
|
|
|
|
|
2016-06-02 01:19:31 +00:00
|
|
|
if (r_cons_get_size (&ch) < 1 || ch < 1) {
|
2014-09-24 01:17:43 +00:00
|
|
|
eprintf ("Cannot create Visual context. Use scr.fix_{columns|rows}\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-26 23:12:58 +00:00
|
|
|
obs = core->blocksize;
|
2015-09-14 10:35:38 +00:00
|
|
|
//r_cons_set_cup (true);
|
2011-01-23 12:12:16 +00:00
|
|
|
|
2015-09-14 10:35:38 +00:00
|
|
|
core->vmode = false;
|
2016-10-17 11:11:46 +00:00
|
|
|
/* honor vim */
|
|
|
|
if (!strncmp (input, "im", 2)) {
|
|
|
|
char *cmd = r_str_newf ("!v%s", input);
|
|
|
|
int ret = r_core_cmd0 (core, cmd);
|
|
|
|
free (cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-03-01 23:02:50 +00:00
|
|
|
while (*input) {
|
2017-02-05 23:54:33 +00:00
|
|
|
int len = *input == 'd'? 2: 1;
|
|
|
|
if (!r_core_visual_cmd (core, input)) {
|
2009-02-09 00:54:09 +00:00
|
|
|
return 0;
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
input += len;
|
2009-02-09 00:54:09 +00:00
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
core->vmode = true;
|
2009-02-09 00:54:09 +00:00
|
|
|
|
2011-02-27 23:03:26 +00:00
|
|
|
// disable tee in cons
|
|
|
|
teefile = r_cons_singleton ()->teefile;
|
|
|
|
r_cons_singleton ()->teefile = "";
|
|
|
|
|
2017-08-03 12:52:46 +00:00
|
|
|
static char debugstr[512];
|
2014-09-24 01:17:43 +00:00
|
|
|
core->print->flags |= R_PRINT_FLAGS_ADDRMOD;
|
2009-02-09 00:54:09 +00:00
|
|
|
do {
|
2016-07-25 03:14:48 +00:00
|
|
|
dodo:
|
2018-10-19 11:42:38 +00:00
|
|
|
r_core_visual_tab_update (core);
|
2016-03-01 23:49:43 +00:00
|
|
|
// update the cursor when it's not visible anymore
|
|
|
|
skip = fix_cursor (core);
|
2018-10-19 11:42:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
|
|
|
r_cons_set_raw (1);
|
2017-08-03 12:52:46 +00:00
|
|
|
const int ref = r_config_get_i (core->config, "dbg.slow");
|
2019-01-05 10:51:46 +00:00
|
|
|
#if 1
|
|
|
|
// This is why multiple debug views dont work
|
|
|
|
if (core->printidx == R_CORE_VISUAL_MODE_DB) {
|
2014-09-27 01:48:54 +00:00
|
|
|
const int pxa = r_config_get_i (core->config, "stack.anotated"); // stack.anotated
|
2018-10-31 10:34:13 +00:00
|
|
|
const char *reg = r_config_get (core->config, "stack.reg");
|
2014-10-03 18:05:33 +00:00
|
|
|
const int size = r_config_get_i (core->config, "stack.size");
|
|
|
|
const int delta = r_config_get_i (core->config, "stack.delta");
|
2016-06-02 01:19:31 +00:00
|
|
|
const char *cmdvhex = r_config_get (core->config, "cmd.stack");
|
|
|
|
|
2014-09-27 01:48:54 +00:00
|
|
|
if (cmdvhex && *cmdvhex) {
|
2016-02-25 09:28:54 +00:00
|
|
|
snprintf (debugstr, sizeof (debugstr),
|
2018-10-31 10:34:13 +00:00
|
|
|
"?0;f tmp;ssr %s;%s;?1;%s;?1;"
|
|
|
|
"ss tmp;f-tmp;pd $r", reg, cmdvhex,
|
2016-01-02 08:07:46 +00:00
|
|
|
ref? "drr": "dr=");
|
2017-02-22 22:45:51 +00:00
|
|
|
debugstr[sizeof (debugstr) - 1] = 0;
|
2014-09-27 01:48:54 +00:00
|
|
|
} else {
|
2018-10-31 10:34:13 +00:00
|
|
|
const char *pxw = stackPrintCommand (core);
|
2016-11-24 22:25:49 +00:00
|
|
|
const char sign = (delta < 0)? '+': '-';
|
2017-02-22 22:45:51 +00:00
|
|
|
const int absdelta = R_ABS (delta);
|
2015-11-23 15:31:31 +00:00
|
|
|
snprintf (debugstr, sizeof (debugstr),
|
2018-10-31 10:34:13 +00:00
|
|
|
"diq;?0;f tmp;ssr %s;%s %d@$$%c%d;"
|
2017-03-19 01:34:53 +00:00
|
|
|
"?1;%s;"
|
2018-02-22 05:21:41 +00:00
|
|
|
"?1;ss tmp;f-tmp;afal;pd $r",
|
2018-10-31 10:34:13 +00:00
|
|
|
reg, pxa? "pxa": pxw, size, sign, absdelta,
|
2016-01-02 08:07:46 +00:00
|
|
|
ref? "drr": "dr=");
|
2014-09-27 01:48:54 +00:00
|
|
|
}
|
2019-01-05 10:51:46 +00:00
|
|
|
printfmtSingle[2] = debugstr;
|
2014-09-27 01:48:54 +00:00
|
|
|
}
|
2019-01-05 10:51:46 +00:00
|
|
|
#endif
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2019-07-02 01:33:57 +00:00
|
|
|
r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel"));
|
2018-07-09 19:26:38 +00:00
|
|
|
core->cons->event_resize = NULL; // avoid running old event with new data
|
2014-08-03 23:29:53 +00:00
|
|
|
core->cons->event_data = core;
|
2018-07-09 19:26:38 +00:00
|
|
|
core->cons->event_resize = (RConsEvent) visual_refresh_oneshot;
|
2013-08-26 23:12:58 +00:00
|
|
|
flags = core->print->flags;
|
2013-08-21 22:08:08 +00:00
|
|
|
color = r_config_get_i (core->config, "scr.color");
|
2016-12-18 16:14:30 +00:00
|
|
|
if (color) {
|
|
|
|
flags |= R_PRINT_FLAGS_COLOR;
|
|
|
|
}
|
2013-08-21 22:08:08 +00:00
|
|
|
debug = r_config_get_i (core->config, "cfg.debug");
|
2015-08-28 16:29:31 +00:00
|
|
|
flags |= R_PRINT_FLAGS_ADDRMOD | R_PRINT_FLAGS_HEADER;
|
2018-12-24 00:18:12 +00:00
|
|
|
r_print_set_flags (core->print, flags);
|
2012-07-22 08:00:35 +00:00
|
|
|
scrseek = r_num_math (core->num,
|
2010-05-19 22:59:42 +00:00
|
|
|
r_config_get (core->config, "scr.seek"));
|
2016-02-10 23:10:48 +00:00
|
|
|
if (scrseek != 0LL) {
|
2020-04-17 10:53:35 +00:00
|
|
|
r_core_seek (core, scrseek, true);
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
|
|
|
if (debug) {
|
2010-05-19 22:59:42 +00:00
|
|
|
r_core_cmd (core, ".dr*", 0);
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
2019-01-11 08:56:27 +00:00
|
|
|
#if 0
|
2010-05-19 22:59:42 +00:00
|
|
|
cmdprompt = r_config_get (core->config, "cmd.vprompt");
|
2016-02-10 23:10:48 +00:00
|
|
|
if (cmdprompt && *cmdprompt) {
|
2010-02-28 22:57:55 +00:00
|
|
|
r_core_cmd (core, cmdprompt, 0);
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
2019-01-11 08:56:27 +00:00
|
|
|
#endif
|
2016-02-10 23:10:48 +00:00
|
|
|
core->print->vflush = !skip;
|
2016-05-10 20:15:24 +00:00
|
|
|
visual_refresh (core);
|
2016-07-25 03:14:48 +00:00
|
|
|
if (insert_mode_enabled (core)) {
|
|
|
|
goto dodo;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
if (!skip) {
|
2017-12-18 01:44:51 +00:00
|
|
|
if (snowMode) {
|
|
|
|
ch = r_cons_readchar_timeout (300);
|
|
|
|
if (ch == -1) {
|
|
|
|
skip = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ch = r_cons_readchar ();
|
|
|
|
}
|
2020-06-05 11:54:11 +00:00
|
|
|
if (I->vtmode == 2 && !is_mintty (core->cons)) {
|
|
|
|
// Prevent runaway scrolling
|
|
|
|
if (IS_PRINTABLE (ch) || ch == '\t' || ch == '\n') {
|
|
|
|
flush_stdin ();
|
|
|
|
} else if (ch == 0x1b) {
|
|
|
|
char chrs[2];
|
|
|
|
int chrs_read = 1;
|
|
|
|
chrs[0] = r_cons_readchar ();
|
|
|
|
if (chrs[0] == '[') {
|
|
|
|
chrs[1] = r_cons_readchar ();
|
|
|
|
chrs_read++;
|
|
|
|
if (chrs[1] >= 'A' && chrs[1] <= 'D') { // arrow keys
|
|
|
|
flush_stdin ();
|
2019-01-13 09:02:24 +00:00
|
|
|
#ifndef __WINDOWS__
|
2020-06-05 11:54:11 +00:00
|
|
|
// Following seems to fix an issue where scrolling slows
|
|
|
|
// down to a crawl for some terminals after some time
|
|
|
|
// mashing the up and down arrow keys
|
|
|
|
r_cons_set_raw (false);
|
|
|
|
r_cons_set_raw (true);
|
|
|
|
#endif
|
|
|
|
}
|
2019-01-25 14:51:05 +00:00
|
|
|
}
|
2020-06-05 11:54:11 +00:00
|
|
|
(void)r_cons_readpush (chrs, chrs_read);
|
2019-01-25 14:51:05 +00:00
|
|
|
}
|
2019-01-13 10:25:48 +00:00
|
|
|
}
|
2017-08-26 01:49:54 +00:00
|
|
|
if (r_cons_is_breaked()) {
|
|
|
|
break;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
r_core_visual_show_char (core, ch);
|
2017-02-22 22:45:51 +00:00
|
|
|
if (ch == -1 || ch == 4) {
|
|
|
|
break; // error or eof
|
|
|
|
}
|
2017-02-05 23:54:33 +00:00
|
|
|
arg[0] = ch;
|
|
|
|
arg[1] = 0;
|
2016-02-10 23:10:48 +00:00
|
|
|
}
|
2019-07-01 17:07:11 +00:00
|
|
|
} while (skip || (*arg && r_core_visual_cmd (core, arg)));
|
2010-02-28 22:57:55 +00:00
|
|
|
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_enable_mouse (false);
|
2016-06-02 01:19:31 +00:00
|
|
|
if (color) {
|
2019-03-05 10:08:41 +00:00
|
|
|
r_cons_strcat (Color_RESET);
|
2016-06-02 01:19:31 +00:00
|
|
|
}
|
2013-08-26 01:17:29 +00:00
|
|
|
r_config_set_i (core->config, "scr.color", color);
|
2015-09-14 10:35:38 +00:00
|
|
|
core->print->cur_enabled = false;
|
2016-06-02 01:19:31 +00:00
|
|
|
if (autoblocksize) {
|
2011-02-02 23:57:29 +00:00
|
|
|
r_core_block_size (core, obs);
|
2016-06-02 01:19:31 +00:00
|
|
|
}
|
2011-02-27 23:03:26 +00:00
|
|
|
r_cons_singleton ()->teefile = teefile;
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_set_cup (false);
|
2014-09-17 08:36:38 +00:00
|
|
|
r_cons_clear00 ();
|
2015-09-14 10:35:38 +00:00
|
|
|
core->vmode = false;
|
2013-04-04 23:53:21 +00:00
|
|
|
core->cons->event_resize = NULL;
|
|
|
|
core->cons->event_data = NULL;
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2009-02-05 21:08:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-09 06:07:17 +00:00
|
|
|
|
2020-03-05 17:07:03 +00:00
|
|
|
R_API RListInfo *r_listinfo_new(const char *name, RInterval pitv, RInterval vitv, int perm, const char *extra) {
|
2019-06-10 11:47:04 +00:00
|
|
|
RListInfo *info = R_NEW (RListInfo);
|
2020-03-05 17:07:03 +00:00
|
|
|
if (info) {
|
2020-04-19 17:06:47 +00:00
|
|
|
info->name = name ? strdup (name) : NULL;
|
2020-03-05 17:07:03 +00:00
|
|
|
info->pitv = pitv;
|
|
|
|
info->vitv = vitv;
|
|
|
|
info->perm = perm;
|
2020-04-19 17:06:47 +00:00
|
|
|
info->extra = extra ? strdup (extra) : NULL;
|
2019-06-10 11:47:04 +00:00
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_listinfo_free (RListInfo *info) {
|
|
|
|
if (!info) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-05 17:07:03 +00:00
|
|
|
free (info->name);
|
|
|
|
free (info->extra);
|
2020-04-18 09:08:46 +00:00
|
|
|
free (info);
|
2019-06-10 11:47:04 +00:00
|
|
|
}
|