2019-01-03 23:57:01 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2019 - 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))
|
|
|
|
|
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;
|
2016-05-10 20:15:24 +00:00
|
|
|
static void visual_refresh(RCore *core);
|
2017-06-09 17:12:20 +00:00
|
|
|
|
2017-12-18 01:44:51 +00:00
|
|
|
static bool snowMode = false;
|
|
|
|
static RList *snows = NULL;
|
|
|
|
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
|
2018-12-29 10:17:56 +00:00
|
|
|
#define PRINT_HEX_FORMATS 9
|
|
|
|
#define PRINT_3_FORMATS 2
|
|
|
|
#define PRINT_4_FORMATS 6
|
|
|
|
#define PRINT_5_FORMATS 8
|
2018-12-28 18:40:54 +00:00
|
|
|
|
|
|
|
static int currentHexFormat = 0;
|
2018-10-31 10:34:13 +00:00
|
|
|
static const char *printHexFormats[PRINT_HEX_FORMATS] = {
|
2018-12-29 10:17:56 +00:00
|
|
|
"px", "pxa", "pxr", "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] = {
|
2018-12-29 10:17:56 +00:00
|
|
|
"prc", "pCA", "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
|
|
|
};
|
2018-12-29 10:17:56 +00:00
|
|
|
static void applyHexMode(RCore *core, int hexMode) {
|
2019-01-02 01:09:31 +00:00
|
|
|
switch (R_ABS(hexMode) % 3) {
|
2018-12-29 10:17:56 +00:00
|
|
|
case 0:
|
|
|
|
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;
|
|
|
|
case 1:
|
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;
|
|
|
|
case 2:
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void applyDisMode(RCore *core, int disMode) {
|
|
|
|
switch (disMode % 5) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 10:34:13 +00:00
|
|
|
static void nextPrintCommand() {
|
|
|
|
currentHexFormat++;
|
|
|
|
currentHexFormat %= PRINT_HEX_FORMATS;
|
|
|
|
}
|
|
|
|
static void prevPrintCommand() {
|
|
|
|
currentHexFormat--;
|
|
|
|
if (currentHexFormat < 0) {
|
|
|
|
currentHexFormat = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *stackPrintCommand(RCore *core) {
|
|
|
|
if (currentHexFormat == 0) {
|
|
|
|
if (r_config_get_i (core->config, "dbg.slow")) {
|
|
|
|
return "pxr";
|
|
|
|
}
|
|
|
|
if (r_config_get_i (core->config, "stack.bytes")) {
|
|
|
|
return "px";
|
|
|
|
}
|
|
|
|
switch (core->assembler->bits) {
|
|
|
|
case 64: return "pxq"; break;
|
|
|
|
case 32: return "pxw"; break;
|
|
|
|
}
|
|
|
|
return "px";
|
|
|
|
}
|
|
|
|
return printHexFormats[currentHexFormat % PRINT_HEX_FORMATS];
|
|
|
|
}
|
|
|
|
|
2019-01-05 10:51:46 +00:00
|
|
|
static const char *__core_visual_print_command (RCore *core) {
|
|
|
|
if (r_config_get_i (core->config, "scr.dumpcols")) {
|
|
|
|
return printfmtColumns[PIDX];
|
|
|
|
}
|
|
|
|
return printfmtSingle[PIDX];
|
|
|
|
}
|
2016-11-20 23:19:15 +00:00
|
|
|
|
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",
|
|
|
|
"???", "show the user-friendly hud",
|
2018-07-04 08:50:00 +00:00
|
|
|
"%", "in cursor mode finds matching pair, otherwise toggle autoblocksz",
|
|
|
|
"^", "seek to the begining of the function",
|
|
|
|
"!", "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",
|
|
|
|
"#", "toggle bytes in disasm view",
|
|
|
|
"\\", "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",
|
2018-08-23 12:46:54 +00:00
|
|
|
"b", "browse evals, symbols, flags, configurations, 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, ..",
|
|
|
|
"gG", "go seek to begin and end of file (0-$s)",
|
|
|
|
"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)",
|
|
|
|
"M", "walk the mounted filesystems",
|
|
|
|
"n/N", "seek next/prev function/flag/hit (scr.nkey)",
|
|
|
|
"o", "go/seek to given offset",
|
|
|
|
"O", "toggle asm.pseudo and asm.esil",
|
|
|
|
"p/P", "rotate print modes (hex, disasm, debug, words, buf)",
|
|
|
|
"q", "back to radare shell",
|
|
|
|
"r", "toggle jmphints/leahints",
|
|
|
|
"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",
|
|
|
|
"Z", "toggle zoom mode",
|
|
|
|
"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);
|
|
|
|
// const char *arch = r_config_get_i (core->config, "asm.arch");
|
|
|
|
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;
|
|
|
|
if ((core->assembler->cur->bits & nb) == nb) {
|
|
|
|
r_core_cmdf (core, "ahb %d", nb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bits = nb;
|
|
|
|
retries--;
|
|
|
|
}
|
|
|
|
}
|
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);
|
2018-05-18 08:35:33 +00:00
|
|
|
if (!x) {
|
2014-09-03 21:13:41 +00:00
|
|
|
// TODO: cache this
|
|
|
|
int wheel = r_config_get_i (core->config, "scr.wheel");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (wheel) {
|
|
|
|
r_cons_enable_mouse (true);
|
|
|
|
} else {
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
}
|
2014-09-03 21:13:41 +00:00
|
|
|
} else {
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_enable_mouse (false);
|
2014-09-03 21:13:41 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-02-09 11:42:54 +00:00
|
|
|
static int color = 1;
|
2009-04-17 11:42:45 +00:00
|
|
|
static int debug = 1;
|
2011-02-16 23:58:54 +00:00
|
|
|
static int zoom = 0;
|
2009-02-18 00:43:57 +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-01-18 10:58:49 +00:00
|
|
|
r_cons_singleton ()->context->color = 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;
|
|
|
|
const char *pal_args_color = cons_ctx->color ? cons_ctx->pal.args : "",
|
|
|
|
*pal_help_color = cons_ctx->color ? cons_ctx->pal.help : "",
|
|
|
|
*pal_reset = cons_ctx->color ? 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 11:54:19 +00:00
|
|
|
static int visual_help() {
|
2019-01-02 01:09:31 +00:00
|
|
|
int ret = 0;
|
|
|
|
RStrBuf *p;
|
|
|
|
repeat:
|
|
|
|
p = 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-01-02 01:09:31 +00:00
|
|
|
r_cons_printf ("Visual Help:\n\n"
|
|
|
|
" (?) full help\n"
|
|
|
|
" (a) code analysis\n"
|
|
|
|
" (d) debugger / emulator\n"
|
|
|
|
" (e) toggle configurations\n"
|
|
|
|
" (i) insert / write\n"
|
|
|
|
" (m) moving around (seeking)\n"
|
|
|
|
" (p) print commands and modes\n"
|
|
|
|
" (v) view management\n"
|
|
|
|
);
|
|
|
|
r_cons_flush ();
|
|
|
|
switch (r_cons_readchar ()) {
|
|
|
|
case 'q':
|
|
|
|
r_strbuf_free (p);
|
|
|
|
return ret;
|
|
|
|
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;
|
|
|
|
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,
|
|
|
|
" 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,
|
|
|
|
" o type flag/offset/register name to seek\n"
|
|
|
|
" 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"
|
|
|
|
" 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-01-02 01:09:31 +00:00
|
|
|
goto repeat;
|
2018-07-04 08:50:00 +00:00
|
|
|
return ret;
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2018-04-06 22:26:05 +00:00
|
|
|
r_core_seek (core, *newaddr, 1);
|
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) {
|
2014-08-05 17:49:33 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
|
|
|
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);
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
r_cons_gotoxy (0, h - 2);
|
|
|
|
r_cons_reset_colors ();
|
|
|
|
r_cons_printf ("\nPress <enter> to return to Visual mode.\n");
|
|
|
|
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;
|
2017-02-23 18:46:01 +00:00
|
|
|
r_cons_enable_mouse (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);
|
|
|
|
r_cons_flush ();
|
2015-09-14 10:35:38 +00:00
|
|
|
ret = true;
|
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) {
|
|
|
|
r_core_cmd (core, "dc", 0);
|
|
|
|
}
|
|
|
|
|
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;
|
2016-02-07 16:06:39 +00:00
|
|
|
r_core_seek (core, core->offset + core->print->cur, 0);
|
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 {
|
|
|
|
visual_help ();
|
|
|
|
}
|
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) {
|
2013-10-06 13:15:23 +00:00
|
|
|
r_core_seek (core, oseek, 0);
|
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 setcursor(RCore *core, bool cur) {
|
2013-08-26 23:12:58 +00:00
|
|
|
int flags = core->print->flags; // wtf
|
2017-02-22 22:45:51 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
flags |= R_PRINT_FLAGS_CURSOR;
|
|
|
|
} else {
|
|
|
|
flags &= ~(R_PRINT_FLAGS_CURSOR);
|
|
|
|
}
|
2013-10-10 23:24:30 +00:00
|
|
|
core->print->cur_enabled = cur;
|
2016-05-17 11:12:06 +00:00
|
|
|
if (core->print->cur == -1) {
|
|
|
|
core->print->cur = 0;
|
|
|
|
}
|
2012-06-14 08:01:16 +00:00
|
|
|
r_print_set_flags (core->print, flags);
|
2017-02-22 22:45:51 +00:00
|
|
|
core->print->col = core->print->cur_enabled? 1: 0;
|
2012-06-14 08:01:16 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
r_core_seek (core, core->offset + i + 1, 1);
|
|
|
|
}
|
|
|
|
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
|
|
|
} else {
|
|
|
|
// r_core_seek (core, core->offset + i + 1, 1);
|
|
|
|
}
|
|
|
|
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) {
|
2015-11-19 11:23:10 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
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;
|
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) {
|
|
|
|
case 0:
|
|
|
|
core->inc = 16;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2018-10-08 10:54:38 +00:00
|
|
|
r_asm_op_init (&op);
|
|
|
|
core->inc = r_asm_disassemble (core->assembler, &op, core->block, R_MIN (32, core->blocksize));
|
|
|
|
r_asm_op_fini (&op);
|
2013-12-02 02:53:29 +00:00
|
|
|
break;
|
2015-03-21 02:06:31 +00:00
|
|
|
case 5: // "pxA"
|
|
|
|
core->inc = 256;
|
|
|
|
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.
|
|
|
|
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
|
|
|
|
} 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.
|
|
|
|
for (i = 0; i < numinstrs; ++i) {
|
|
|
|
*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;
|
|
|
|
for (i = 0; i < numinstrs; ++i) {
|
|
|
|
start_addr = prevop_addr (core, start_addr);
|
|
|
|
}
|
|
|
|
return start_addr;
|
|
|
|
}
|
|
|
|
|
2018-03-08 23:33:33 +00:00
|
|
|
R_API int offset_history_up(RLine *line) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int offset_history_down(RLine *line) {
|
|
|
|
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);
|
2018-03-08 23:33:33 +00:00
|
|
|
core->cons->line->offset_prompt = true;
|
|
|
|
r_line_set_hist_callback (core->cons->line, &offset_history_up, &offset_history_down);
|
2014-02-10 02:31:12 +00:00
|
|
|
r_line_set_prompt ("[offset]> ");
|
|
|
|
strcpy (buf, "s ");
|
2017-02-22 22:45:51 +00:00
|
|
|
if (r_cons_fgets (buf + 2, sizeof (buf) - 3, 0, NULL) > 0) {
|
|
|
|
if (buf[2] == '.') {
|
|
|
|
buf[1] = '.';
|
|
|
|
}
|
2014-02-10 02:31:12 +00:00
|
|
|
r_core_cmd0 (core, buf);
|
2018-04-06 22:26:05 +00:00
|
|
|
restore_current_addr (core, addr, bsze, newaddr);
|
2014-02-10 02:31:12 +00:00
|
|
|
}
|
2018-07-09 15:48:48 +00:00
|
|
|
r_line_set_hist_callback (core->cons->line, &cmd_history_up, &cmd_history_down);
|
|
|
|
core->cons->line->offset_prompt = false;
|
2014-02-10 02:31:12 +00:00
|
|
|
}
|
2013-11-07 01:07:10 +00:00
|
|
|
|
2016-02-10 23:18:09 +00:00
|
|
|
static int prevopsz(RCore *core, ut64 addr) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2014-09-22 22:40:35 +00:00
|
|
|
int ret = 0;
|
|
|
|
#if FCN_OLD
|
|
|
|
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
|
2018-11-22 20:20:47 +00:00
|
|
|
xrefs = r_anal_fcn_get_refs (core->anal, fun);
|
|
|
|
}
|
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
|
|
|
}
|
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) {
|
|
|
|
name = r_str_newf ("%s + %d", 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;
|
|
|
|
}
|
|
|
|
r_cons_printf (" %d [%s] 0x%08"PFMT64x" 0x%08"PFMT64x " %s %sref (%s)\n",
|
|
|
|
idx, cstr, refi->at, refi->addr,
|
|
|
|
r_anal_xrefs_type_tostring (refi->type),
|
|
|
|
xref ? "x":"", name);
|
|
|
|
free (name);
|
|
|
|
if (idx == skip) {
|
|
|
|
free (dis);
|
|
|
|
curat = refi->addr;
|
|
|
|
char *res = r_core_cmd_strf (core, "pd 4 @ 0x%08"PFMT64x"@e:asm.maxflags=1", refi->at);
|
|
|
|
// 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);
|
|
|
|
if (ats) {
|
|
|
|
(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 ();
|
2018-11-25 01:20:36 +00:00
|
|
|
int wheel = r_config_get_i (core->config, "scr.wheel");
|
|
|
|
if (wheel > 0) {
|
|
|
|
r_cons_enable_mouse (true);
|
|
|
|
}
|
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"
|
|
|
|
" ? - 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;
|
|
|
|
goto repeat;
|
2017-12-16 00:44:45 +00:00
|
|
|
} else if (ch == 'p') {
|
|
|
|
printMode++;
|
|
|
|
if (printMode > lastPrintMode) {
|
|
|
|
printMode = 0;
|
|
|
|
}
|
|
|
|
goto repeat;
|
|
|
|
} else if (ch == 'P') {
|
|
|
|
printMode--;
|
2018-12-02 23:46:51 +00:00
|
|
|
if (printMode < 0) {
|
2017-12-16 00:44:45 +00:00
|
|
|
printMode = lastPrintMode;
|
|
|
|
}
|
|
|
|
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;
|
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);
|
2014-09-22 22:40:35 +00:00
|
|
|
#else
|
|
|
|
eprintf ("TODO: sdbize xrefs here\n");
|
|
|
|
#endif
|
2014-08-05 03:37:48 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:25:14 +00:00
|
|
|
#if __WINDOWS__ && !__CYGWIN__
|
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) {
|
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;
|
|
|
|
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
|
|
|
cmtfile = r_str_between (comment, ",(", ")");
|
|
|
|
cwd = getcommapath (core);
|
2015-11-18 12:03:35 +00:00
|
|
|
if (!cmtfile) {
|
|
|
|
char *fn;
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2015-11-18 22:32:18 +00:00
|
|
|
fn = r_cons_input ("<comment-file> ");
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
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);
|
|
|
|
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
|
|
|
}
|
|
|
|
free (comment);
|
|
|
|
}
|
|
|
|
|
2015-12-14 23:37:33 +00:00
|
|
|
static bool isDisasmPrint(int mode) {
|
|
|
|
return (mode == 1 || mode == 2);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_nextrow(RCore *core, bool use_ocur) {
|
|
|
|
RPrint *p = core->print;
|
|
|
|
ut32 roff, next_roff;
|
|
|
|
int row, sz, delta;
|
|
|
|
RAsmOp op;
|
|
|
|
|
|
|
|
cursor_ocur (core, use_ocur);
|
2017-05-29 02:36:34 +00:00
|
|
|
if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) {
|
|
|
|
//int cols = r_config_get_i (core->config, "hex.cols") * 3.5;
|
|
|
|
int cols = r_config_get_i (core->config, "hex.cols") + r_config_get_i (core->config, "hex.pcols");
|
|
|
|
cols /= 2;
|
2017-05-29 09:45:13 +00:00
|
|
|
p->cur += cols > 0? cols: 0;
|
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;
|
|
|
|
}
|
2018-12-28 18:40:54 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB && core->seltab == 0) {
|
2016-11-24 22:25:49 +00:00
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
r_config_set_i (core->config, "stack.delta",
|
2017-02-22 22:45:51 +00:00
|
|
|
r_config_get_i (core->config, "stack.delta") - w);
|
2016-11-24 22:25:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-28 18:40:54 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB && core->seltab == 1) {
|
2018-05-07 08:01:25 +00:00
|
|
|
const int cols = core->dbg->regcols;
|
|
|
|
p->cur += cols > 0? cols: 3;
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
if (next_roff == -1) {
|
|
|
|
p->cur++;
|
|
|
|
return;
|
|
|
|
}
|
2016-03-06 22:23:39 +00:00
|
|
|
if (next_roff + 32 < core->blocksize) {
|
|
|
|
sz = r_asm_disassemble (core->assembler, &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
|
|
|
|
2017-05-29 02:36:34 +00:00
|
|
|
if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) {
|
|
|
|
int cols = r_config_get_i (core->config, "hex.cols") + r_config_get_i (core->config, "hex.pcols");
|
|
|
|
cols /= 2;
|
2017-06-28 00:21:16 +00:00
|
|
|
p->cur -= R_MAX (cols, 0);
|
2017-05-29 02:36:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
cursor_ocur (core, use_ocur);
|
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;
|
|
|
|
}
|
2018-12-28 18:40:54 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB && core->seltab == 0) {
|
2016-11-24 22:25:49 +00:00
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
if (w < 1) {
|
|
|
|
w = 16;
|
|
|
|
}
|
|
|
|
r_config_set_i (core->config, "stack.delta",
|
2017-02-22 22:45:51 +00:00
|
|
|
r_config_get_i (core->config, "stack.delta") + w);
|
2016-11-24 22:25:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-28 18:40:54 +00:00
|
|
|
if (PIDX == R_CORE_VISUAL_MODE_DB && core->seltab == 1) {
|
2018-05-07 08:01:25 +00:00
|
|
|
const int cols = core->dbg->regcols;
|
|
|
|
p->cur -= cols > 0? cols: 4;
|
|
|
|
return;
|
|
|
|
}
|
2016-02-10 23:10:48 +00:00
|
|
|
if (p->row_offsets != NULL) {
|
|
|
|
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;
|
|
|
|
r_core_seek (core, prev_addr, 1);
|
|
|
|
prev_sz = r_asm_disassemble (core->assembler, &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;
|
|
|
|
int sz = r_asm_disassemble (core->assembler,
|
|
|
|
&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) {
|
|
|
|
r_core_seek (core, core->offset + p->cols, 1);
|
|
|
|
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)) {
|
|
|
|
sz = 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;
|
2017-08-03 12:52:46 +00:00
|
|
|
case 9: // 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"
|
2017-10-16 14:15:15 +00:00
|
|
|
" b blocks\n"
|
|
|
|
" c classes\n"
|
2018-02-21 02:10:38 +00:00
|
|
|
" C comments\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" e eval var configurations\n"
|
|
|
|
" 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"
|
2018-02-04 12:04:34 +00:00
|
|
|
" p pids/threads\n"
|
2018-02-21 01:17:31 +00:00
|
|
|
" q quit\n"
|
2019-01-14 00:09:30 +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"
|
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-01-11 08:56:27 +00:00
|
|
|
case 'g':
|
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-01-14 00:09:30 +00:00
|
|
|
case 'r':
|
|
|
|
r_core_visual_view_rop (core);
|
|
|
|
break;
|
2017-10-16 20:31:29 +00:00
|
|
|
case 'f':
|
|
|
|
r_core_visual_trackflags (core);
|
|
|
|
break;
|
2018-02-21 01:17:31 +00:00
|
|
|
case 'F':
|
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;
|
2018-11-25 00:23:33 +00:00
|
|
|
case 'v':
|
|
|
|
r_core_visual_anal (core, "v");
|
|
|
|
break;
|
2018-08-23 13:07:21 +00:00
|
|
|
case 'e':
|
|
|
|
r_core_visual_config (core);
|
|
|
|
break;
|
2017-10-16 20:31:29 +00:00
|
|
|
case 'c':
|
|
|
|
r_core_visual_classes (core);
|
|
|
|
break;
|
2018-02-21 02:10:38 +00:00
|
|
|
case 'C':
|
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;
|
2017-10-16 20:31:29 +00:00
|
|
|
case 't':
|
|
|
|
r_core_visual_types (core);
|
|
|
|
break;
|
2018-02-24 18:44:09 +00:00
|
|
|
case 'T':
|
|
|
|
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 {
|
|
|
|
if (r_config_get_i (core->config, "scr.interactive")) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:01:53 +00:00
|
|
|
static void r_core_visual_tab_free (RCoreVisualTab *tab) {
|
|
|
|
free (tab);
|
|
|
|
}
|
|
|
|
|
2018-12-29 10:17:56 +00:00
|
|
|
static char *visual_tabstring(RCore *core, const char *kolor) {
|
|
|
|
int hex_cols = r_config_get_i (core->config, "hex.cols");
|
|
|
|
int scr_color = r_config_get_i (core->config, "scr.color");
|
|
|
|
if (hex_cols < 4) {
|
|
|
|
return strdup ("");
|
|
|
|
}
|
|
|
|
int i=0;
|
|
|
|
char *str = NULL;
|
|
|
|
int tabs = r_list_length (core->visual.tabs);
|
|
|
|
if (scr_color > 0) {
|
|
|
|
// TODO: use theme
|
|
|
|
if (tabs > 0) {
|
2019-01-02 01:09:31 +00:00
|
|
|
str = r_str_appendf (str, "%s___", kolor);
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < tabs;i++) {
|
|
|
|
const char *name = NULL;
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, i);
|
|
|
|
if (tab && *tab->name) {
|
|
|
|
name = tab->name;
|
|
|
|
}
|
2018-12-31 00:21:03 +00:00
|
|
|
if (i == core->visual.tab) {
|
|
|
|
str = r_str_appendf (str, Color_WHITE"_/ %s \\_%s", name? name: "t=", kolor);
|
2018-12-29 10:17:56 +00:00
|
|
|
} else {
|
2018-12-31 00:21:03 +00:00
|
|
|
str = r_str_appendf (str, "_%s(%d)_", name?name: "", i+ 1);
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tabs > 0) {
|
|
|
|
str = r_str_append (str, "___");
|
|
|
|
}
|
|
|
|
for (i = 0;i < tabs; i++) {
|
|
|
|
const char *name = NULL;
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, i);
|
|
|
|
if (tab && *tab->name) {
|
|
|
|
name = tab->name;
|
|
|
|
}
|
|
|
|
if (i==core->visual.tab) {
|
|
|
|
str = r_str_appendf (str, "_/ %d:%s \\_", i + 1, name? name: "'=");
|
|
|
|
} else {
|
2019-01-02 01:09:31 +00:00
|
|
|
str = r_str_appendf (str, "_(t%d%s%s)__", i + 1, name?":":"", name?name: "");
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-02 01:09:31 +00:00
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
int n = 79 - r_str_ansi_len (str);
|
|
|
|
if (n > 0) {
|
|
|
|
str = r_str_append (str, r_str_pad ('_', n));
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
2019-01-02 01:09:31 +00:00
|
|
|
str = r_str_append (str, "\n"Color_RESET);
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
return str;
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_tabset(RCore *core, RCoreVisualTab *tab) {
|
|
|
|
r_return_if_fail (core && tab);
|
|
|
|
|
|
|
|
r_core_seek (core, tab->offset, 1);
|
|
|
|
core->printidx = tab->printidx;
|
|
|
|
core->print->cur_enabled = tab->cur_enabled;
|
|
|
|
core->print->cur = tab->cur;
|
|
|
|
core->print->ocur = tab->ocur;
|
2018-12-29 10:17:56 +00:00
|
|
|
disMode = tab->disMode;
|
|
|
|
hexMode = tab->hexMode;
|
|
|
|
printMode = tab->printMode;
|
|
|
|
current3format = tab->current3format;
|
|
|
|
current4format = tab->current4format;
|
|
|
|
current5format = tab->current5format;
|
|
|
|
applyDisMode (core, disMode);
|
|
|
|
applyHexMode (core, hexMode);
|
|
|
|
r_config_set_i (core->config, "hex.cols", tab->cols);
|
2019-01-05 10:51:46 +00:00
|
|
|
r_config_set_i (core->config, "scr.dumpcols", tab->dumpCols);
|
2019-01-02 01:09:31 +00:00
|
|
|
printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS];
|
|
|
|
printfmtSingle[2] = print3Formats[R_ABS(current3format) % PRINT_3_FORMATS];
|
|
|
|
printfmtSingle[3] = print4Formats[R_ABS(current4format) % PRINT_4_FORMATS];
|
|
|
|
printfmtSingle[4] = print5Formats[R_ABS(current5format) % PRINT_5_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_tabget(RCore *core, RCoreVisualTab *tab) {
|
|
|
|
r_return_if_fail (core && tab);
|
|
|
|
|
2018-08-16 09:01:53 +00:00
|
|
|
tab->offset = core->offset;
|
|
|
|
tab->printidx = core->printidx;
|
2018-12-28 18:40:54 +00:00
|
|
|
tab->cur_enabled = core->print->cur_enabled;
|
|
|
|
tab->cur = core->print->cur;
|
|
|
|
tab->ocur = core->print->ocur;
|
2018-12-29 10:17:56 +00:00
|
|
|
tab->cols = r_config_get_i (core->config, "hex.cols");
|
2019-01-05 10:51:46 +00:00
|
|
|
tab->dumpCols = r_config_get_i (core->config, "scr.dumpcols");
|
2018-12-29 10:17:56 +00:00
|
|
|
tab->disMode = disMode;
|
|
|
|
tab->hexMode = hexMode;
|
|
|
|
tab->printMode = printMode;
|
|
|
|
tab->current3format = current3format;
|
|
|
|
tab->current4format = current4format;
|
|
|
|
tab->current5format = current5format;
|
|
|
|
// tab->cols = core->print->cols;
|
|
|
|
}
|
|
|
|
|
|
|
|
static RCoreVisualTab *r_core_visual_tab_new(RCore *core) {
|
|
|
|
RCoreVisualTab *tab = R_NEW0 (RCoreVisualTab);
|
|
|
|
if (tab) {
|
|
|
|
visual_tabget (core, tab);
|
|
|
|
}
|
|
|
|
return tab;
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void r_core_visual_tab_update(RCore *core) {
|
2018-12-28 18:40:54 +00:00
|
|
|
if (!core->visual.tabs) {
|
2018-08-16 09:01:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-28 18:40:54 +00:00
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
2018-12-29 10:17:56 +00:00
|
|
|
if (tab) {
|
2018-12-28 18:40:54 +00:00
|
|
|
visual_tabget (core, tab);
|
|
|
|
}
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_newtab (RCore *core) {
|
|
|
|
if (!core->visual.tabs) {
|
2018-12-29 10:17:56 +00:00
|
|
|
core->visual.tabs = r_list_newf ((RListFree)r_core_visual_tab_free);
|
2018-08-17 14:43:11 +00:00
|
|
|
if (!core->visual.tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
core->visual.tab = -1;
|
2018-08-17 14:43:11 +00:00
|
|
|
visual_newtab (core);
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
core->visual.tab++;
|
2018-08-16 09:01:53 +00:00
|
|
|
RCoreVisualTab *tab = r_core_visual_tab_new (core);
|
2018-12-28 18:40:54 +00:00
|
|
|
// r_list_prepend (core->visual.tabs, tab);
|
|
|
|
r_list_append (core->visual.tabs, tab);
|
2018-12-29 10:17:56 +00:00
|
|
|
visual_tabset (core, tab);
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 18:40:54 +00:00
|
|
|
static void visual_nthtab (RCore *core, int n) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (!core->visual.tabs || n < 0 || n >= r_list_length (core->visual.tabs)) {
|
2018-12-29 10:17:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
core->visual.tab = n;
|
2018-12-28 18:40:54 +00:00
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
|
|
|
if (tab) {
|
|
|
|
visual_tabset (core, tab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 10:17:56 +00:00
|
|
|
static void visual_tabname (RCore *core) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (!core->visual.tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
char name[32]={0};
|
|
|
|
prompt_read ("tab name: ", name, sizeof (name));
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
|
|
|
if (tab) {
|
|
|
|
strcpy (tab->name, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:01:53 +00:00
|
|
|
static void visual_nexttab (RCore *core) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (!core->visual.tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
if (core->visual.tab >= r_list_length (core->visual.tabs) - 1) {
|
|
|
|
core->visual.tab = -1;
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
|
|
|
core->visual.tab++;
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
2018-08-16 09:01:53 +00:00
|
|
|
if (tab) {
|
2018-12-28 18:40:54 +00:00
|
|
|
visual_tabset (core, tab);
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_prevtab (RCore *core) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (!core->visual.tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
if (core->visual.tab < 1) {
|
|
|
|
core->visual.tab = r_list_length (core->visual.tabs) - 1;
|
2018-12-28 18:40:54 +00:00
|
|
|
} else {
|
2018-08-16 09:01:53 +00:00
|
|
|
core->visual.tab--;
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
2018-12-28 18:40:54 +00:00
|
|
|
if (tab) {
|
|
|
|
visual_tabset (core, tab);
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void visual_closetab (RCore *core) {
|
2019-01-02 01:09:31 +00:00
|
|
|
if (!core->visual.tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
|
|
|
if (tab) {
|
|
|
|
r_list_delete_data (core->visual.tabs, tab);
|
|
|
|
const int tabsCount = r_list_length (core->visual.tabs);
|
|
|
|
if (tabsCount > 0) {
|
|
|
|
if (core->visual.tab > 0) {
|
|
|
|
core->visual.tab--;
|
|
|
|
}
|
|
|
|
RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab);
|
|
|
|
if (tab) {
|
|
|
|
visual_tabset(core, tab);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_list_free (core->visual.tabs);
|
|
|
|
core->visual.tabs = NULL;
|
2018-08-16 09:01:53 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int numbuf_pull() {
|
|
|
|
int distance = 1;
|
|
|
|
if (numbuf_i) {
|
|
|
|
numbuf[numbuf_i] = 0;
|
|
|
|
distance = atoi (numbuf);
|
|
|
|
if (!distance) {
|
|
|
|
distance = 1;
|
|
|
|
}
|
|
|
|
numbuf_i = 0;
|
|
|
|
}
|
|
|
|
return distance;
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:54:33 +00:00
|
|
|
R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
2017-06-30 15:40:07 +00:00
|
|
|
ut8 ch = 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;
|
2018-12-29 10:17:56 +00:00
|
|
|
int i, ret, cols = core->print->cols;
|
2015-02-10 23:13:04 +00:00
|
|
|
int wheelspeed;
|
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) {
|
|
|
|
return 1;
|
|
|
|
}
|
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
|
|
|
|
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)) {
|
2018-12-15 11:30:15 +00:00
|
|
|
if (r_config_get_i (core->config, "asm.hints") && (r_config_get_i (core->config, "asm.hint.jmp") || r_config_get_i (core->config, "asm.hint.lea"))) {
|
|
|
|
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) {
|
2015-04-07 14:25:14 +00:00
|
|
|
#if __WINDOWS__ && !__CYGWIN__
|
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"
|
2014-02-07 13:54:31 +00:00
|
|
|
{
|
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-01-03 23:57:01 +00:00
|
|
|
case 'O': // tab TAB
|
2018-12-28 18:40:54 +00:00
|
|
|
case 9: // tab TAB
|
|
|
|
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 {
|
2018-08-16 09:01:53 +00:00
|
|
|
#if 0
|
2018-12-28 18:40:54 +00:00
|
|
|
// XXX WTF
|
|
|
|
ut64 delta = offset - f;
|
|
|
|
r_core_seek (core, t + delta, 1);
|
|
|
|
r_config_set_i (core->config, "diff.from", t);
|
|
|
|
r_config_set_i (core->config, "diff.to", f);
|
2018-08-16 09:01:53 +00:00
|
|
|
#endif
|
2018-12-28 18:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-01-03 23:57:01 +00:00
|
|
|
switch (core->printidx) {
|
2018-12-28 18:40:54 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PX: // 0 // xc
|
2019-01-02 01:09:31 +00:00
|
|
|
hexMode++;
|
|
|
|
applyHexMode (core, hexMode);
|
|
|
|
printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_PD: // pd
|
2018-12-29 10:17:56 +00:00
|
|
|
applyDisMode (core, ++disMode);
|
2018-12-30 11:08:20 +00:00
|
|
|
printfmtSingle[1] = rotateAsmemu (core);
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_DB: // debugger
|
2018-12-29 10:17:56 +00:00
|
|
|
applyDisMode (core, ++disMode);
|
2018-12-30 11:08:20 +00:00
|
|
|
printfmtSingle[1] = rotateAsmemu (core);
|
2019-01-02 01:09:31 +00:00
|
|
|
current3format = current3format + 1;
|
|
|
|
printfmtSingle[2] = print3Formats[R_ABS(current3format) % PRINT_3_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_OV: // overview
|
2019-01-02 01:09:31 +00:00
|
|
|
current4format = current4format + 1;
|
|
|
|
printfmtSingle[3] = print4Formats[R_ABS(current4format) % PRINT_4_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_CD: // code
|
2019-01-02 01:09:31 +00:00
|
|
|
current5format = current5format + 1;
|
|
|
|
printfmtSingle[4] = print5Formats[R_ABS(current5format) % PRINT_5_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
2017-08-03 12:52:46 +00:00
|
|
|
}
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RIOMap *map = r_io_map_get (core->io, addr);
|
|
|
|
if (!map || !(map->perm & R_PERM_W)) {
|
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
|
|
|
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);
|
|
|
|
strcpy (buf, "wa ");
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_enable_mouse (false);
|
|
|
|
if (r_cons_fgets (buf + 3, 1000, 0, NULL) < 0) {
|
|
|
|
buf[0] = '\0';
|
2016-02-07 16:06:39 +00:00
|
|
|
}
|
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;
|
|
|
|
r_core_seek (core, t, 0);
|
|
|
|
}
|
|
|
|
r_core_cmd (core, buf, true);
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
int t = core->offset - core->print->cur;
|
|
|
|
r_core_seek (core, t, 1);
|
|
|
|
}
|
|
|
|
}
|
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 ();
|
2014-10-06 00:36:22 +00:00
|
|
|
// if (r_cons_fgets (buf, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0';
|
2017-02-22 22:45:51 +00:00
|
|
|
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 {
|
|
|
|
// if (r_cons_fgets (buf, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0';
|
|
|
|
R_FREE (I->line->contents);
|
2017-09-18 13:46:55 +00:00
|
|
|
(void)r_config_set (core->config, "cmd.cprompt", buf? 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 '!':
|
2018-04-07 14:51:25 +00:00
|
|
|
r_core_visual_panels (core, NULL);
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
2017-02-03 12:09:34 +00:00
|
|
|
{
|
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);
|
2017-02-03 12:09:34 +00:00
|
|
|
}
|
2014-02-10 02:31:12 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'A':
|
2016-02-07 16:06:39 +00:00
|
|
|
{
|
2018-07-17 21:53:44 +00:00
|
|
|
int oce = core->print->cur_enabled;
|
|
|
|
int oco = core->print->ocur;
|
|
|
|
int occ = core->print->cur;
|
|
|
|
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;
|
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);
|
|
|
|
}
|
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;
|
|
|
|
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;
|
|
|
|
case 'd':
|
2017-06-09 17:12:20 +00:00
|
|
|
if (r_config_get_i (core->config, "asm.esil")) {
|
2017-06-09 19:35:38 +00:00
|
|
|
r_core_visual_esil (core);
|
2017-06-09 17:12:20 +00:00
|
|
|
} else {
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, true);
|
2018-12-15 11:30:15 +00:00
|
|
|
int distance = numbuf_pull ();
|
|
|
|
r_core_visual_define (core, arg + 1, distance - 1);
|
2018-07-25 11:17:44 +00:00
|
|
|
r_core_visual_showcursor (core, false);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
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
|
|
|
{
|
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) {
|
2018-01-08 02:22:26 +00:00
|
|
|
n = r_str_trim (name);
|
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
|
|
|
}
|
|
|
|
}
|
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-01-02 01:09:31 +00:00
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
if (core->visual.tabs) {
|
|
|
|
r_cons_printf ("[tnp=+-] ");
|
|
|
|
} 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-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
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
{
|
|
|
|
RIOMap *map = r_io_map_get (core->io, addr);
|
|
|
|
if (!map || !(map->perm & R_PERM_W)) {
|
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
|
|
|
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: ");
|
|
|
|
if (r_cons_fgets (buf + 4, sizeof (buf) - 5, 0, NULL) < 0) {
|
|
|
|
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: ");
|
|
|
|
if (r_cons_fgets (buf + 3, sizeof (buf) - 4, 0, NULL) < 0) {
|
|
|
|
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) {
|
2018-12-29 10:17:56 +00:00
|
|
|
r_core_seek (core, addr, 0);
|
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) {
|
2018-12-29 10:17:56 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
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);
|
2018-12-29 10:17:56 +00:00
|
|
|
r_core_seek (core, oaddr, 1);
|
|
|
|
}
|
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) {
|
|
|
|
r_core_seek (core, fcn->addr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case 'E':
|
|
|
|
r_core_visual_colors (core);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
if (!r_list_empty (core->fs->roots)) {
|
|
|
|
r_core_visual_mounts (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
|
2018-12-15 10:37:19 +00:00
|
|
|
r_core_cmd0 (core, "e!asm.hint.jmp");
|
|
|
|
r_core_cmd0 (core, "e!asm.hint.lea");
|
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 'g':
|
2015-06-12 19:47:08 +00:00
|
|
|
if (core->io->va) {
|
2019-01-05 11:05:09 +00:00
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
2019-01-07 07:57:27 +00:00
|
|
|
if (!map) {
|
|
|
|
SdbListIter *i = ls_tail (core->io->maps);
|
|
|
|
map = ls_iter_get (i);
|
|
|
|
}
|
2019-01-05 11:05:09 +00:00
|
|
|
if (map) {
|
|
|
|
r_core_seek (core, r_itv_begin (map->itv), 1);
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
r_core_seek (core, 0, 1);
|
|
|
|
}
|
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
break;
|
|
|
|
case 'G':
|
2018-12-04 13:19:30 +00:00
|
|
|
ret = -1;
|
2018-12-29 10:17:56 +00:00
|
|
|
{
|
|
|
|
RIOMap *map = r_io_map_get (core->io, core->offset);
|
2019-01-07 07:57:27 +00:00
|
|
|
if (!map) {
|
|
|
|
SdbListIter *i = ls_head (core->io->maps);
|
|
|
|
map = ls_iter_get (i);
|
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
if (map) {
|
2019-01-05 09:13:59 +00:00
|
|
|
RPrint *p = core->print;
|
|
|
|
int scr_rows;
|
|
|
|
if (!p->consbind.get_size) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void)p->consbind.get_size (&scr_rows);
|
2018-12-29 10:17:56 +00:00
|
|
|
int scols = r_config_get_i (core->config, "hex.cols");
|
2019-01-05 09:13:59 +00:00
|
|
|
ret = r_core_seek (core, r_itv_end (map->itv) - (scr_rows - 2) * scols, 1);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2011-09-04 00:34:54 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
if (ret != -1) {
|
|
|
|
r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'l':
|
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':
|
|
|
|
{
|
|
|
|
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':
|
|
|
|
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.
|
|
|
|
RAnalMetaItem *ami = r_meta_find (core->anal,
|
|
|
|
core->offset, R_META_TYPE_DATA,
|
|
|
|
R_META_WHERE_HERE);
|
2018-01-07 01:23:48 +00:00
|
|
|
if (!ami) {
|
|
|
|
ami = r_meta_find (core->anal,
|
|
|
|
core->offset, R_META_TYPE_STRING,
|
|
|
|
R_META_WHERE_HERE);
|
|
|
|
}
|
2017-10-19 05:16:40 +00:00
|
|
|
if (ami) {
|
|
|
|
r_core_seek_delta (core, ami->size);
|
|
|
|
} 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);
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2017-10-19 05:16:40 +00:00
|
|
|
r_core_seek (core, core->offset + cols, 1);
|
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':
|
|
|
|
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;
|
|
|
|
addr += r_asm_disassemble (core->assembler, &op, core->block, 32);
|
|
|
|
}
|
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
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
|
|
|
} else {
|
|
|
|
r_core_seek (core, core->offset + obs, 1);
|
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':
|
|
|
|
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);
|
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':
|
|
|
|
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) {
|
|
|
|
r_core_seek (core, core->offset - delta, 1);
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
2017-08-22 07:42:16 +00:00
|
|
|
r_core_seek (core, 0, 1);
|
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) {
|
|
|
|
r_core_seek (core, at, 1);
|
2016-11-04 00:30:35 +00:00
|
|
|
} else {
|
|
|
|
r_core_seek (core, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
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':
|
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':
|
|
|
|
r_core_visual_mark (core, r_cons_readchar ());
|
|
|
|
break;
|
|
|
|
case '\'':
|
2019-01-02 01:09:31 +00:00
|
|
|
r_core_visual_mark_seek (core, r_cons_readchar ());
|
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) {
|
|
|
|
r_core_seek (core, fcn->addr, 1);
|
|
|
|
}
|
2016-05-11 02:25:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '-':
|
|
|
|
if (core->print->cur_enabled) {
|
2018-12-28 18:40:54 +00:00
|
|
|
if (core->seltab == 0 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
2017-02-22 22:45:51 +00:00
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
2016-11-24 22:25:49 +00:00
|
|
|
r_config_get_i (core->config, "stack.size") - w);
|
|
|
|
|
|
|
|
} 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) {
|
2018-12-28 18:40:54 +00:00
|
|
|
if (core->seltab == 0 && core->printidx == R_CORE_VISUAL_MODE_DB) {
|
2017-02-22 22:45:51 +00:00
|
|
|
int w = r_config_get_i (core->config, "hex.cols");
|
|
|
|
r_config_set_i (core->config, "stack.size",
|
2016-11-24 22:25:49 +00:00
|
|
|
r_config_get_i (core->config, "stack.size") + w);
|
|
|
|
} 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;
|
|
|
|
case '/':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
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
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
2017-12-18 01:44:51 +00:00
|
|
|
case '(':
|
2018-12-28 18:40:54 +00:00
|
|
|
case ')':
|
2017-12-18 01:44:51 +00:00
|
|
|
snowMode = !snowMode;
|
|
|
|
if (!snowMode) {
|
|
|
|
r_list_free (snows);
|
|
|
|
snows = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2018-06-06 15:08:31 +00:00
|
|
|
case '#':
|
|
|
|
r_config_toggle (core->config, "asm.bytes");
|
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
case '*':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
r_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + core->print->cur);
|
|
|
|
} 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 {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_seek_align (core, core->blocksize, 1);
|
|
|
|
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]) {
|
|
|
|
int sz;
|
|
|
|
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;
|
|
|
|
ut64 s = R_MIN (size, sz);
|
|
|
|
r_io_write_at (core->io, from, (const ut8*)data, s);
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
} else {
|
|
|
|
r_core_seek_align (core, core->blocksize, -1);
|
|
|
|
r_core_seek_align (core, core->blocksize, -1);
|
|
|
|
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);
|
|
|
|
r_core_seek (core, core->offset + core->print->cur, 1);
|
|
|
|
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) {
|
2017-02-22 22:45:51 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
|
|
|
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 {
|
2017-05-03 15:19:49 +00:00
|
|
|
RIOMap *map = ls_pop (core->io->maps);
|
2017-03-24 00:06:41 +00:00
|
|
|
if (map) {
|
2017-09-01 06:41:03 +00:00
|
|
|
entry = map->itv.addr;
|
2017-03-24 00:06:41 +00:00
|
|
|
} else {
|
|
|
|
entry = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
}
|
2017-05-03 15:19:49 +00:00
|
|
|
ls_prepend (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) {
|
2017-03-24 00:06:41 +00:00
|
|
|
r_core_seek (core, entry, 1);
|
|
|
|
}
|
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);
|
|
|
|
if (r_cons_fgets (buf + i, sizeof (buf) - i - 1, 0, NULL) > 0) {
|
|
|
|
ut64 addr, orig;
|
|
|
|
addr = orig = core->offset;
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
addr += core->print->cur;
|
|
|
|
r_core_seek (core, addr, 0);
|
|
|
|
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);
|
|
|
|
for (i = 4, j = 4; i < len; ++i,++j) {
|
|
|
|
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) {
|
|
|
|
r_core_seek (core, orig, 1);
|
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
|
|
|
|
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 {
|
2018-12-28 18:40:54 +00:00
|
|
|
#if 0
|
2018-12-29 10:17:56 +00:00
|
|
|
// we need to improve visual zoom, not deleted because we need more brainstorming here
|
|
|
|
if (zoom && core->print->cur) {
|
|
|
|
ut64 from = r_config_get_i (core->config, "zoom.from");
|
|
|
|
ut64 to = r_config_get_i (core->config, "zoom.to");
|
|
|
|
r_core_seek (core, from + ((to - from) / core->blocksize) * core->print->cur, 1);
|
|
|
|
}
|
|
|
|
zoom = !zoom;
|
2018-12-28 18:40:54 +00:00
|
|
|
#endif
|
2018-12-29 10:17:56 +00:00
|
|
|
switch (core->printidx) {
|
2018-12-28 18:40:54 +00:00
|
|
|
case R_CORE_VISUAL_MODE_PX: // 0 // xc
|
2018-12-29 10:17:56 +00:00
|
|
|
applyHexMode (core, --hexMode);
|
2019-01-02 01:09:31 +00:00
|
|
|
printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_PD: // pd
|
|
|
|
printfmtSingle[1] = rotateAsmemu (core);
|
2018-12-29 10:17:56 +00:00
|
|
|
applyDisMode (core, --disMode);
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_DB: // debugger
|
2018-12-29 10:17:56 +00:00
|
|
|
//printfmtSingle[1] = rotateAsmemu (core);
|
2019-01-02 01:09:31 +00:00
|
|
|
current3format = current3format - 1;
|
|
|
|
printfmtSingle[2] = print3Formats[R_ABS(current3format) % PRINT_3_FORMATS];
|
2018-12-29 10:17:56 +00:00
|
|
|
applyDisMode (core, --disMode);
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_OV: // overview
|
2019-01-02 01:09:31 +00:00
|
|
|
current4format = current4format-1;
|
|
|
|
printfmtSingle[3] = print4Formats[R_ABS(current4format)% PRINT_4_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
|
|
|
case R_CORE_VISUAL_MODE_CD: // code
|
2019-01-02 01:09:31 +00:00
|
|
|
current5format = current5format-1;
|
|
|
|
printfmtSingle[4] = print5Formats[R_ABS(current5format) % PRINT_5_FORMATS];
|
2018-12-28 18:40:54 +00:00
|
|
|
break;
|
2017-02-22 22:45:51 +00:00
|
|
|
}
|
2018-12-29 10:17:56 +00:00
|
|
|
}
|
2017-02-22 22:45:51 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
if (visual_help () == '?') {
|
|
|
|
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
|
|
|
|
case R_CORE_VISUAL_MODE_OV:
|
|
|
|
case R_CORE_VISUAL_MODE_CD:
|
|
|
|
r_core_block_size (core, (int)(core->cons->rows * hexcols * 3.5));
|
|
|
|
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
|
|
|
}
|
2016-10-06 00:40:26 +00:00
|
|
|
if (r_config_get_i (core->config, "scr.zoneflags")) {
|
|
|
|
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))) {
|
2014-10-22 22:07:30 +00:00
|
|
|
r_core_seek (core, curpc, 1);
|
2016-06-02 01:19:31 +00:00
|
|
|
}
|
|
|
|
} else if (follow < 0) {
|
|
|
|
r_core_seek (core, curpc + follow, 1);
|
2014-10-22 22:07:30 +00:00
|
|
|
}
|
|
|
|
oldpc = curpc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 09:34:04 +00:00
|
|
|
RIODesc *desc = core->file? r_io_desc_get (core->io, core->file->fd): NULL;
|
2018-02-23 17:27:03 +00:00
|
|
|
filename = desc? desc->name: "";
|
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
|
|
|
#if 1
|
|
|
|
/* TODO: we need a helper into r_flags to do that */
|
|
|
|
bool oss = core->flags->space_strict;
|
|
|
|
int osi = core->flags->space_idx;
|
|
|
|
RFlagItem *f = NULL;
|
|
|
|
core->flags->space_strict = true;
|
|
|
|
core->anal->flb.set_fs (core->flags, "symbols");
|
|
|
|
if (core->flags->space_idx != -1) {
|
2018-02-22 11:45:54 +00:00
|
|
|
f = core->anal->flb.get_at (core->flags, addr, showDelta);
|
2016-11-23 11:30:43 +00:00
|
|
|
}
|
|
|
|
core->flags->space_strict = oss;
|
|
|
|
core->flags->space_idx = osi;
|
|
|
|
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
|
|
|
}
|
|
|
|
#else
|
2016-12-01 09:48:00 +00:00
|
|
|
RFlagItem *f = r_flag_get_at (core->flags, addr, false);
|
2016-11-23 11:30:43 +00:00
|
|
|
#endif
|
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) {
|
2017-05-03 01:05:01 +00:00
|
|
|
strncpy (bar, cmd_visual, sizeof (bar) - 1);
|
|
|
|
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) {
|
|
|
|
strncpy (bar, cmd, sizeof (bar) - 1);
|
|
|
|
bar[sizeof (bar) - 1] = 0; // '\0'-terminate bar
|
|
|
|
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) {
|
2018-12-31 02:06:05 +00:00
|
|
|
title = r_str_newf ("[%s *0x%08"PFMT64x" %s ($$+0x%x)]> %s %s\n",
|
|
|
|
address, core->offset + core->print->cur,
|
2018-12-29 10:17:56 +00:00
|
|
|
pm, core->print->cur,
|
2018-11-15 02:08:44 +00:00
|
|
|
bar, pos);
|
|
|
|
} else {
|
2018-12-31 02:06:05 +00:00
|
|
|
title = r_str_newf ("[%s 0x%08"PFMT64x" %s [0x%x..0x%x] %d]> %s %s\n",
|
|
|
|
address, core->offset + core->print->cur,
|
|
|
|
pm, core->print->ocur, core->print->cur,
|
|
|
|
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 {
|
2018-12-31 02:06:05 +00:00
|
|
|
title = r_str_newf ("[%s %s %s%d %s]> %s %s\n",
|
|
|
|
address, pm, pcs, core->blocksize, filename, bar, pos);
|
2018-07-08 23:13:03 +00:00
|
|
|
}
|
2016-07-25 03:14:48 +00:00
|
|
|
}
|
2018-10-01 17:57:33 +00:00
|
|
|
const int tabsCount = core->visual.tabs? r_list_length (core->visual.tabs): 0;
|
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;
|
2018-12-29 10:17:56 +00:00
|
|
|
char *tabstring = visual_tabstring (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 ("]");
|
2018-12-29 10:17:56 +00:00
|
|
|
r_cons_printf ("[tab:%d/%d]", core->visual.tab, tabsCount);
|
|
|
|
#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) {
|
|
|
|
r_config_set_i (core->config, "hex.cols", 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);
|
|
|
|
r_config_set_i (core->config, "asm.lines.width", w - (w / 1.2));
|
2018-02-22 16:59:08 +00:00
|
|
|
r_config_set_i (core->config, "asm.cmt.col", w - (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;
|
|
|
|
}
|
|
|
|
|
2018-11-12 23:22:22 +00:00
|
|
|
static void scrollbar(RCore *core) {
|
|
|
|
int i, h, w = r_cons_get_size (&h);
|
|
|
|
|
|
|
|
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);
|
|
|
|
r_cons_gotoxy (w - strlen (s) + 1, 1);
|
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
|
|
|
|
ut64 block = (to - from) / h;
|
|
|
|
bool hadMatch = false;
|
|
|
|
for (i = 0; i < h ; i++) {
|
|
|
|
// TODO: show short comment introduced by user in there
|
|
|
|
// TODO: use colors
|
|
|
|
r_cons_gotoxy (w, i + 2);
|
|
|
|
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);
|
|
|
|
r_cons_gotoxy (w - strlen (s) + 1, h + 1);
|
|
|
|
r_cons_strcat (s);
|
|
|
|
free (s);
|
|
|
|
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) {
|
|
|
|
r_core_seek (core, oseek, 1);
|
|
|
|
}
|
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;
|
2017-06-27 22:24:26 +00:00
|
|
|
r_core_seek (core, core->num->value, 1);
|
|
|
|
} 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) {
|
|
|
|
char *cmd_result;
|
|
|
|
cmd_result = r_core_cmd_str (core, cmd_str);
|
|
|
|
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")) {
|
|
|
|
scrollbar (core);
|
|
|
|
}
|
2011-01-23 12:12:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:26:38 +00:00
|
|
|
static void visual_refresh_oneshot(RCore *core) {
|
|
|
|
r_core_task_enqueue_oneshot (core, (RCoreTaskOneShot) visual_refresh, core);
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
*cols = prevopsz (core, core->offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
*cols = core->offset - f->addr + r_anal_fcn_size (f);
|
|
|
|
} else {
|
|
|
|
r_asm_set_pc (core->assembler, core->offset);
|
|
|
|
*cols = r_asm_disassemble (core->assembler,
|
|
|
|
op, core->block, 32);
|
2019-01-12 10:43:27 +00:00
|
|
|
if (midflags || midbb) {
|
|
|
|
int skip_bytes_flag = 0, skip_bytes_bb = 0;
|
|
|
|
if (midflags) {
|
|
|
|
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-01-12 10:43:27 +00:00
|
|
|
if (skip_bytes_flag && midflags >= R_MIDFLAGS_REALIGN) {
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2014-09-04 09:06:11 +00:00
|
|
|
int wheel, 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");
|
2016-02-10 23:10:48 +00:00
|
|
|
|
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
|
2014-09-04 09:06:11 +00:00
|
|
|
wheel = r_config_get_i (core->config, "scr.wheel");
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2016-12-18 16:14:30 +00:00
|
|
|
if (wheel) {
|
|
|
|
r_cons_enable_mouse (true);
|
|
|
|
}
|
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) {
|
2009-04-07 11:28:22 +00:00
|
|
|
r_core_seek (core, scrseek, 1);
|
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 ();
|
|
|
|
}
|
2019-01-13 09:02:24 +00:00
|
|
|
#ifndef __WINDOWS__
|
2019-01-13 11:47:59 +00:00
|
|
|
if (IS_PRINTABLE (ch) || ch == '\t' || ch == '\n') {
|
2019-01-13 10:25:48 +00:00
|
|
|
tcflush (STDIN_FILENO, TCIFLUSH);
|
|
|
|
}
|
2019-01-13 09:02:24 +00:00
|
|
|
#endif
|
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
|
|
|
}
|
2017-02-05 23:54:33 +00:00
|
|
|
} while (skip || 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) {
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_printf (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;
|
|
|
|
}
|