2012-09-19 12:08:44 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2012 - pancake */
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#include "r_core.h"
|
|
|
|
|
2011-12-02 13:32:04 +00:00
|
|
|
#define NPF 5
|
2011-05-21 12:27:46 +00:00
|
|
|
static int blocksize = 0;
|
2012-06-30 18:51:18 +00:00
|
|
|
static const char *printfmt[] = {
|
2012-08-23 10:46:55 +00:00
|
|
|
"x", "pd",
|
2012-09-28 00:20:52 +00:00
|
|
|
"f tmp;sr sp;pxw 64;dr=;s-;s tmp;f-tmp;pd",
|
|
|
|
"pxw", "pc"
|
2012-06-30 18:51:18 +00:00
|
|
|
};
|
2011-02-02 23:57:29 +00:00
|
|
|
static int autoblocksize = 1;
|
|
|
|
static int obs = 0;
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2010-10-07 22:48:07 +00:00
|
|
|
// XXX: use core->print->cur_enabled instead of curset/cursor/ocursor
|
2010-07-16 09:28:16 +00:00
|
|
|
static int curset = 0, cursor = 0, ocursor=-1;
|
2009-02-09 11:42:54 +00:00
|
|
|
static int color = 1;
|
2009-04-17 11:42:45 +00:00
|
|
|
static int debug = 1;
|
2009-02-09 11:42:54 +00:00
|
|
|
static int flags = R_PRINT_FLAGS_ADDRMOD;
|
2011-02-16 23:58:54 +00:00
|
|
|
static int zoom = 0;
|
2009-02-09 00:54:09 +00:00
|
|
|
|
2009-02-18 00:43:57 +00:00
|
|
|
static int marks_init = 0;
|
2010-05-19 22:59:42 +00:00
|
|
|
static ut64 marks[UT8_MAX+1];
|
2009-02-18 00:43:57 +00:00
|
|
|
|
2012-01-31 02:34:23 +00:00
|
|
|
static int r_core_visual_hud(RCore *core) {
|
2012-02-12 22:45:04 +00:00
|
|
|
char *res = NULL;
|
2012-01-31 02:34:23 +00:00
|
|
|
char *p = 0;
|
2012-01-31 01:45:17 +00:00
|
|
|
r_cons_show_cursor (R_TRUE);
|
|
|
|
char *homehud = r_str_home("/.radare2/hud");
|
|
|
|
if (homehud)
|
|
|
|
res = r_cons_hud_file (homehud);
|
2012-02-27 02:07:32 +00:00
|
|
|
if (!res) {
|
|
|
|
const char *f = R2_LIBDIR"/radare2/"R2_VERSION"/hud/main";
|
2012-09-06 06:59:13 +00:00
|
|
|
if (r_file_exists (f))
|
2012-02-27 02:07:32 +00:00
|
|
|
res = r_cons_hud_file (f);
|
|
|
|
else r_cons_message ("Cannot find hud file");
|
|
|
|
}
|
2012-01-31 01:45:17 +00:00
|
|
|
r_cons_clear ();
|
|
|
|
if (res) {
|
2012-01-31 02:34:23 +00:00
|
|
|
p = strchr (res, '\t');
|
2012-01-31 01:45:17 +00:00
|
|
|
core->printidx = 1;
|
|
|
|
r_cons_printf ("%s\n", res);
|
|
|
|
r_cons_flush ();
|
2012-01-31 02:34:23 +00:00
|
|
|
if (p) r_core_cmd0 (core, p+1);
|
2012-01-31 01:45:17 +00:00
|
|
|
free (res);
|
|
|
|
}
|
|
|
|
r_cons_show_cursor (R_FALSE);
|
|
|
|
r_cons_flush ();
|
2012-01-31 02:34:23 +00:00
|
|
|
return (int)(size_t)p;
|
2012-01-31 01:45:17 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
static void r_core_visual_mark_seek(RCore *core, ut8 ch) {
|
|
|
|
if (!marks_init) {
|
|
|
|
int i;
|
|
|
|
for (i=0;i<UT8_MAX;i++)
|
|
|
|
marks[i] = 0;
|
|
|
|
marks_init = 1;
|
|
|
|
}
|
|
|
|
if (marks[ch])
|
|
|
|
r_core_seek (core, marks[ch], 1);
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
static void r_core_visual_mark(RCore *core, ut8 ch) {
|
2010-01-31 01:30:59 +00:00
|
|
|
if (!marks_init) {
|
2009-02-18 00:43:57 +00:00
|
|
|
int i;
|
2010-08-16 11:59:48 +00:00
|
|
|
for (i=0;i<UT8_MAX;i++)
|
2009-02-18 00:43:57 +00:00
|
|
|
marks[i] = 0;
|
|
|
|
marks_init = 1;
|
|
|
|
}
|
2010-01-12 01:12:18 +00:00
|
|
|
marks[ch] = core->offset;
|
2009-02-18 00:43:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 02:33:01 +00:00
|
|
|
static void prompt_read (const char *p, char *buf, int buflen) {
|
|
|
|
r_line_set_prompt (p);
|
|
|
|
r_cons_show_cursor (R_TRUE);
|
|
|
|
r_cons_fgets (buf, buflen, 0, NULL);
|
|
|
|
r_cons_show_cursor (R_FALSE);
|
|
|
|
}
|
|
|
|
|
2011-06-04 01:23:12 +00:00
|
|
|
R_API void r_core_visual_prompt (RCore *core) {
|
2011-05-21 12:27:46 +00:00
|
|
|
char buf[1024];
|
|
|
|
ut64 oseek = core->offset;
|
2011-12-04 20:02:09 +00:00
|
|
|
#if __UNIX__
|
|
|
|
r_line_set_prompt (Color_RESET":> ");
|
|
|
|
#else
|
2011-05-21 12:27:46 +00:00
|
|
|
r_line_set_prompt (":> ");
|
2011-12-04 20:02:09 +00:00
|
|
|
#endif
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_TRUE);
|
2011-05-21 12:27:46 +00:00
|
|
|
r_cons_fgets (buf, sizeof (buf), 0, NULL);
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
r_cons_any_key ();
|
2011-12-02 01:13:49 +00:00
|
|
|
r_cons_clear00 ();
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_FALSE);
|
2011-05-21 12:27:46 +00:00
|
|
|
if (curset) r_core_seek (core, oseek, 1);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
switch (ch) {
|
|
|
|
case R_CONS_KEY_F1:
|
|
|
|
cmd = r_config_get (core->config, "key.f1");
|
2012-07-22 08:00:35 +00:00
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
2011-06-05 22:16:11 +00:00
|
|
|
ch = '?';
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F2:
|
|
|
|
cmd = r_config_get (core->config, "key.f2");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F3:
|
|
|
|
cmd = r_config_get (core->config, "key.f3");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F4:
|
|
|
|
cmd = r_config_get (core->config, "key.f4");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
case R_CONS_KEY_F5:
|
|
|
|
cmd = r_config_get (core->config, "key.f5");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
case R_CONS_KEY_F6:
|
|
|
|
cmd = r_config_get (core->config, "key.f6");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F7:
|
|
|
|
cmd = r_config_get (core->config, "key.f7");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
ch = 's';
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F8:
|
|
|
|
cmd = r_config_get (core->config, "key.f8");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F9:
|
|
|
|
cmd = r_config_get (core->config, "key.f9");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
r_core_cmd0 (core, "dc");
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F10:
|
|
|
|
cmd = r_config_get (core->config, "key.f10");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F11:
|
|
|
|
cmd = r_config_get (core->config, "key.f11");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F12:
|
|
|
|
cmd = r_config_get (core->config, "key.f12");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2012-08-13 02:33:01 +00:00
|
|
|
static void setcursor (RCore *core, int cur) {
|
2012-06-14 08:01:16 +00:00
|
|
|
curset = cur;
|
2012-07-22 08:00:35 +00:00
|
|
|
if (curset) flags|=R_PRINT_FLAGS_CURSOR;
|
2012-06-14 08:01:16 +00:00
|
|
|
else flags &= ~(flags&R_PRINT_FLAGS_CURSOR);
|
|
|
|
r_print_set_flags (core->print, flags);
|
|
|
|
core->print->col = curset? 1: 0;
|
|
|
|
}
|
|
|
|
|
2012-08-13 02:33:01 +00:00
|
|
|
static void setdiff (RCore *core) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:50:39 +00:00
|
|
|
// TODO: integrate in '/' command with search.inblock ?
|
|
|
|
static void visual_search (RCore *core) {
|
2012-08-04 21:48:06 +00:00
|
|
|
const ut8 *p;
|
|
|
|
int len, d = cursor;
|
2012-08-01 23:50:39 +00:00
|
|
|
char str[128], buf[258];
|
|
|
|
|
|
|
|
r_line_set_prompt ("search byte/string in block: ");
|
|
|
|
r_cons_fgets (str, sizeof (str), 0, NULL);
|
2012-08-04 21:48:06 +00:00
|
|
|
len = r_hex_str2bin (str, (ut8*)buf);
|
2012-08-01 23:50:39 +00:00
|
|
|
if (*str=='"') {
|
|
|
|
char *e = strncpy (buf, str+1, sizeof (buf)-1);
|
|
|
|
if (e) { --e; if (*e=='"') *e=0; }
|
|
|
|
len = strlen (buf);
|
|
|
|
} else
|
|
|
|
if (len<1) {
|
|
|
|
strncpy (buf, str, sizeof (buf)-1);
|
|
|
|
len = strlen (str);
|
|
|
|
}
|
2012-08-04 21:48:06 +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) {
|
|
|
|
cursor = (int)(size_t)(p-core->block);
|
|
|
|
if (len>1) {
|
|
|
|
ocursor = cursor+len-1;
|
|
|
|
} else ocursor = -1;
|
|
|
|
r_cons_show_cursor (R_TRUE);
|
|
|
|
eprintf ("FOUND IN %d\n", cursor);
|
|
|
|
r_cons_any_key ();
|
|
|
|
} else {
|
|
|
|
eprintf ("Cannot find bytes\n");
|
|
|
|
r_cons_any_key ();
|
|
|
|
r_cons_clear00 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_visual_cmd(RCore *core, int ch) {
|
2011-02-24 15:50:29 +00:00
|
|
|
RAsmOp op;
|
2011-03-01 23:02:50 +00:00
|
|
|
char buf[4096];
|
2011-05-21 12:27:46 +00:00
|
|
|
int i, cols = core->print->cols;
|
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);
|
2011-06-05 22:16:11 +00:00
|
|
|
if (ch<2) return 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?
|
2012-07-16 09:39:43 +00:00
|
|
|
if (ch>='0'&& ch<='9') {
|
2011-12-04 20:09:16 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset);
|
2011-03-03 15:52:51 +00:00
|
|
|
r_core_seek (core, core->asmqjmps[ch-'0'], 1);
|
2010-05-19 22:59:42 +00:00
|
|
|
} else
|
|
|
|
switch (ch) {
|
2012-08-13 02:33:01 +00:00
|
|
|
case 9: // tab
|
|
|
|
{ // XXX: unify diff mode detection
|
|
|
|
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 {
|
|
|
|
ut64 delta = core->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);
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 01:41:21 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'c':
|
2010-07-15 22:02:33 +00:00
|
|
|
// XXX dupped flag imho
|
2012-06-14 08:01:16 +00:00
|
|
|
setcursor (core, curset ^ 1);
|
2010-05-19 22:59:42 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
r_core_visual_define (core);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2012-08-13 02:33:01 +00:00
|
|
|
case 'D':
|
|
|
|
setdiff (core);
|
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'C':
|
2009-02-09 11:42:54 +00:00
|
|
|
color ^= 1;
|
2010-05-19 22:59:42 +00:00
|
|
|
if (color) flags |= R_PRINT_FLAGS_COLOR;
|
2010-07-15 22:02:33 +00:00
|
|
|
else flags &= ~(flags&R_PRINT_FLAGS_COLOR);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_config_set_i (core->config, "scr.color", color);
|
|
|
|
r_print_set_flags (core->print, flags);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2011-03-01 23:02:50 +00:00
|
|
|
case 'f':
|
2012-09-28 00:20:52 +00:00
|
|
|
{
|
|
|
|
char name[256], *n;
|
|
|
|
r_line_set_prompt ("flag name: ");
|
|
|
|
if (r_cons_fgets (name, sizeof (name), 0, NULL) >=0 && *name) {
|
|
|
|
int range = curset? (R_ABS (cursor-ocursor)+1): 1;
|
|
|
|
if (range<1) range=1;
|
|
|
|
n = r_str_chop (name);
|
|
|
|
if (*n) r_flag_set (core->flags, n, core->offset + cursor, range, 1);
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 23:02:50 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2012-09-28 00:20:52 +00:00
|
|
|
r_flag_unset_i (core->flags, core->offset + cursor, NULL);
|
|
|
|
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"));
|
2011-03-01 23:02:50 +00:00
|
|
|
break;
|
2009-04-07 00:26:41 +00:00
|
|
|
case 'a':
|
2012-07-06 00:17:44 +00:00
|
|
|
if (core->file && !(core->file->rwx & 2)) {
|
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
|
|
|
r_cons_any_key ();
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
2010-04-14 22:29:42 +00:00
|
|
|
r_cons_printf ("Enter assembler opcodes separated with ';':\n");
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_TRUE);
|
2010-04-14 22:29:42 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (R_FALSE);
|
2010-02-02 10:09:52 +00:00
|
|
|
strcpy (buf, "wa ");
|
2011-03-05 18:09:38 +00:00
|
|
|
r_line_set_prompt (":> ");
|
2010-02-02 10:09:52 +00:00
|
|
|
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
2011-06-04 01:14:04 +00:00
|
|
|
if (*buf) {
|
2010-04-14 22:29:42 +00:00
|
|
|
if (curset) r_core_seek (core, core->offset + cursor, 0);
|
|
|
|
r_core_cmd (core, buf, R_TRUE);
|
|
|
|
if (curset) r_core_seek (core, core->offset - cursor, 1);
|
2009-04-07 11:28:22 +00:00
|
|
|
}
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_FALSE);
|
2010-04-14 22:29:42 +00:00
|
|
|
r_cons_set_raw (R_TRUE);
|
2009-04-07 00:26:41 +00:00
|
|
|
break;
|
2012-06-07 01:41:21 +00:00
|
|
|
case 'i':
|
2012-07-06 00:17:44 +00:00
|
|
|
if (core->file && !(core->file->rwx & 2)) {
|
|
|
|
r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag\n");
|
|
|
|
r_cons_any_key ();
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_TRUE);
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (0);
|
2012-11-07 03:25:42 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
strcpy (buf, "wow ");
|
|
|
|
r_line_set_prompt ("insert string: ");
|
|
|
|
if (r_cons_fgets (buf+4, sizeof (buf)-3, 0, NULL) <0)
|
|
|
|
buf[0]='\0';
|
|
|
|
} else
|
2012-06-07 01:41:21 +00:00
|
|
|
if (core->print->col==2) {
|
|
|
|
strcpy (buf, "w ");
|
|
|
|
r_line_set_prompt ("insert string: ");
|
|
|
|
if (r_cons_fgets (buf+2, sizeof (buf)-3, 0, NULL) <0)
|
|
|
|
buf[0]='\0';
|
|
|
|
} else {
|
|
|
|
strcpy (buf, "wx ");
|
|
|
|
r_line_set_prompt ("insert hex: ");
|
|
|
|
if (r_cons_fgets (buf+3, sizeof (buf)-4, 0, NULL) <0)
|
|
|
|
buf[0]='\0';
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
if (*buf) {
|
2012-11-07 03:25:42 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
char *p = strdup (buf);
|
|
|
|
int cur = core->print->cur;
|
|
|
|
if (cur>=core->blocksize)
|
|
|
|
cur = core->print->cur-1;
|
|
|
|
sprintf (buf, "%s @ $$+%i:%i", p, cursor<ocursor?
|
|
|
|
cursor:ocursor, R_ABS (ocursor-cursor)+1);
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
free (p);
|
|
|
|
} else {
|
|
|
|
if (curset) r_core_seek (core, core->offset + cursor, 0);
|
|
|
|
r_core_cmd (core, buf, 1);
|
|
|
|
if (curset) r_core_seek (core, core->offset - cursor, 1);
|
|
|
|
}
|
2009-04-07 11:28:22 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_set_raw (1);
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_FALSE);
|
2009-04-07 00:26:41 +00:00
|
|
|
break;
|
2009-04-02 01:23:45 +00:00
|
|
|
case 'e':
|
2010-05-19 22:59:42 +00:00
|
|
|
r_core_visual_config (core);
|
2009-04-02 01:23:45 +00:00
|
|
|
break;
|
2011-07-11 20:52:05 +00:00
|
|
|
case 'M':
|
|
|
|
r_core_visual_mounts (core);
|
|
|
|
break;
|
2009-04-02 00:44:24 +00:00
|
|
|
case 't':
|
2010-05-19 22:59:42 +00:00
|
|
|
r_core_visual_trackflags (core);
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
2011-11-24 22:50:15 +00:00
|
|
|
case 'x':
|
|
|
|
{
|
|
|
|
int count = 0;
|
2012-07-12 00:47:04 +00:00
|
|
|
RList *xrefs = NULL;
|
2011-11-24 22:50:15 +00:00
|
|
|
RAnalRef *refi;
|
|
|
|
RListIter *iter;
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fun;
|
2011-11-24 22:50:15 +00:00
|
|
|
|
|
|
|
if ((xrefs = r_anal_xref_get (core->anal, core->offset))) {
|
|
|
|
r_cons_printf ("XREFS:\n");
|
|
|
|
if (r_list_empty (xrefs)) {
|
|
|
|
r_cons_printf ("\tNo XREF found at 0x%"PFMT64x"\n", core->offset);
|
|
|
|
r_cons_any_key ();
|
2011-12-02 01:13:49 +00:00
|
|
|
r_cons_clear00 ();
|
2011-11-24 22:50:15 +00:00
|
|
|
} else {
|
|
|
|
r_list_foreach (xrefs, iter, refi) {
|
|
|
|
fun = r_anal_fcn_find (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
r_cons_printf ("\t[%i] %s XREF 0x%08"PFMT64x" (%s)\n", count,
|
|
|
|
refi->type==R_ANAL_REF_TYPE_CODE?"CODE (JMP)":
|
|
|
|
refi->type==R_ANAL_REF_TYPE_CALL?"CODE (CALL)":"DATA", refi->addr,
|
|
|
|
fun?fun->name:"unk");
|
|
|
|
if (++count > 9) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else xrefs = NULL;
|
|
|
|
r_cons_flush ();
|
|
|
|
ch = r_cons_readchar ();
|
|
|
|
if (ch >= '0' && ch <= '9') {
|
|
|
|
refi = r_list_get_n (xrefs, ch-0x30);
|
|
|
|
if (refi) {
|
|
|
|
sprintf (buf, "s 0x%"PFMT64x, refi->addr);
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xrefs)
|
|
|
|
r_list_free (xrefs);
|
|
|
|
}
|
|
|
|
break;
|
2011-11-23 01:29:09 +00:00
|
|
|
case 'T':
|
|
|
|
r_core_visual_comments (core);
|
|
|
|
break;
|
2012-08-14 01:21:31 +00:00
|
|
|
case 'V':
|
|
|
|
r_core_cmd0 (core, "agv $$");
|
|
|
|
break;
|
2010-08-22 17:07:03 +00:00
|
|
|
case 'v':
|
|
|
|
r_core_visual_anal (core);
|
|
|
|
break;
|
2009-03-20 21:05:12 +00:00
|
|
|
case 'g':
|
2011-06-26 21:41:34 +00:00
|
|
|
if (core->io->va) {
|
|
|
|
ut64 offset = r_io_section_get_vaddr (core->io, 0);
|
2011-07-04 16:54:41 +00:00
|
|
|
if (offset == -1)
|
|
|
|
offset = 0;
|
2011-06-26 21:41:34 +00:00
|
|
|
r_core_seek (core, offset, 1);
|
2012-06-30 18:51:18 +00:00
|
|
|
} else r_core_seek (core, 0, 1);
|
2011-12-04 20:09:16 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset);
|
2009-03-20 21:05:12 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
2011-09-04 00:34:54 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-06-26 21:41:34 +00:00
|
|
|
if (core->io->va) {
|
2011-09-04 00:34:54 +00:00
|
|
|
ut64 offset = r_io_section_get_vaddr (core->io, 0);
|
|
|
|
if (offset == UT64_MAX) {
|
2012-06-30 18:51:18 +00:00
|
|
|
offset = core->file->size - core->blocksize;
|
2011-09-04 00:34:54 +00:00
|
|
|
ret = r_core_seek (core, offset, 1);
|
|
|
|
} else {
|
|
|
|
offset += core->file->size - core->blocksize;
|
|
|
|
ret = r_core_seek (core, offset, 1);
|
|
|
|
}
|
2012-06-30 18:51:18 +00:00
|
|
|
} else {
|
|
|
|
ret = r_core_seek (core,
|
|
|
|
core->file->size-core->blocksize, 1);
|
|
|
|
}
|
2011-10-25 18:30:05 +00:00
|
|
|
if (ret != -1)
|
2011-12-04 20:09:16 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset);
|
2011-09-04 00:34:54 +00:00
|
|
|
}
|
2009-03-20 21:05:12 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'h':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
|
|
|
cursor--;
|
|
|
|
ocursor=-1;
|
2011-02-04 23:20:28 +00:00
|
|
|
if (cursor<0) {
|
2012-09-23 19:42:10 +00:00
|
|
|
r_core_seek_delta (core, -cols);
|
2011-02-04 23:20:28 +00:00
|
|
|
cursor ++;
|
|
|
|
}
|
2012-06-14 00:18:15 +00:00
|
|
|
} else r_core_seek_delta (core, -1);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'H':
|
|
|
|
if (curset) {
|
|
|
|
if (ocursor==-1) ocursor=cursor;
|
|
|
|
cursor--;
|
|
|
|
if (cursor<0) {
|
|
|
|
r_core_seek (core, core->offset-cols, 1);
|
|
|
|
cursor += cols;
|
|
|
|
ocursor += cols;
|
|
|
|
}
|
2012-06-14 00:18:15 +00:00
|
|
|
} else r_core_seek_delta (core, -2);
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'l':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
|
|
|
cursor++;
|
|
|
|
ocursor=-1;
|
2011-02-04 23:20:28 +00:00
|
|
|
{
|
|
|
|
int offscreen = (core->cons->rows-3)*cols;
|
|
|
|
if (cursor>=offscreen) {
|
|
|
|
r_core_seek (core, core->offset+cols, 1);
|
|
|
|
cursor-=cols;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 00:18:15 +00:00
|
|
|
} else r_core_seek_delta (core, 1);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'L':
|
|
|
|
if (curset) {
|
|
|
|
if (ocursor==-1) ocursor=cursor;
|
|
|
|
cursor++;
|
|
|
|
{
|
|
|
|
int offscreen = (core->cons->rows-3)*cols;
|
|
|
|
if (cursor>=offscreen) {
|
|
|
|
r_core_seek (core, core->offset+cols, 1);
|
|
|
|
cursor-=cols;
|
|
|
|
ocursor-=cols;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 00:18:15 +00:00
|
|
|
} else r_core_seek_delta (core, 2);
|
2010-05-19 00:39:01 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'j':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (core->printidx == 1 || core->printidx == 2)
|
2012-06-10 21:58:34 +00:00
|
|
|
cols = r_asm_disassemble (core->assembler,
|
|
|
|
&op, core->block+cursor, 32);
|
2010-10-17 21:03:54 +00:00
|
|
|
cursor += cols;
|
|
|
|
ocursor = -1;
|
2011-02-04 23:20:28 +00:00
|
|
|
{
|
|
|
|
int offscreen = (core->cons->rows-3)*cols;
|
|
|
|
if (cursor>=offscreen) {
|
2012-09-27 17:35:19 +00:00
|
|
|
//ut64 x = core->offset + cols;
|
2011-02-04 23:20:28 +00:00
|
|
|
r_core_seek (core, core->offset+cols, 1);
|
|
|
|
cursor-=cols;
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 00:12:02 +00:00
|
|
|
} else {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (core->printidx == 1 || core->printidx == 2) {
|
2011-01-27 00:12:02 +00:00
|
|
|
cols = core->inc;
|
2011-02-15 15:19:18 +00:00
|
|
|
core->asmsteps[core->curasmstep].offset = core->offset+cols;
|
|
|
|
core->asmsteps[core->curasmstep].cols = cols;
|
|
|
|
if (core->curasmstep < R_CORE_ASMSTEPS-1)
|
|
|
|
core->curasmstep++;
|
|
|
|
else core->curasmstep = 0;
|
|
|
|
}
|
2011-01-27 00:12:02 +00:00
|
|
|
r_core_seek (core, core->offset+cols, 1);
|
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'J':
|
|
|
|
if (curset) {
|
|
|
|
if (ocursor==-1) ocursor = cursor;
|
|
|
|
cursor += cols;
|
|
|
|
{
|
|
|
|
int offscreen = (core->cons->rows-3)*cols;
|
|
|
|
if (cursor>=offscreen) {
|
|
|
|
r_core_seek (core, core->offset+cols, 1);
|
|
|
|
cursor-=cols;
|
|
|
|
ocursor-=cols;
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 13:11:34 +00:00
|
|
|
} else r_core_seek (core, core->offset+obs, 1);
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'k':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (core->printidx == 1 || core->printidx == 2)
|
2012-07-16 09:39:43 +00:00
|
|
|
cols = 4;
|
2010-10-17 21:03:54 +00:00
|
|
|
cursor -= cols;
|
2011-02-04 23:36:51 +00:00
|
|
|
ocursor = -1;
|
|
|
|
if (cursor<0) {
|
|
|
|
if (core->offset>=cols)
|
|
|
|
r_core_seek (core, core->offset-cols, 1);
|
2011-02-04 23:20:28 +00:00
|
|
|
cursor += cols;
|
|
|
|
}
|
2011-01-27 00:12:02 +00:00
|
|
|
} else {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (core->printidx == 1 || core->printidx == 2) {
|
2011-02-15 15:19:18 +00:00
|
|
|
int i;
|
|
|
|
cols = core->inc;
|
|
|
|
for (i = 0; i < R_CORE_ASMSTEPS; i++)
|
|
|
|
if (core->offset == core->asmsteps[i].offset)
|
|
|
|
cols = core->asmsteps[i].cols;
|
2011-02-15 11:31:32 +00:00
|
|
|
}
|
2011-02-15 15:19:18 +00:00
|
|
|
if (core->offset >= cols)
|
|
|
|
r_core_seek (core, core->offset-cols, 1);
|
|
|
|
else r_core_seek (core, 0, 1);
|
2011-01-27 00:12:02 +00:00
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'K':
|
|
|
|
if (curset) {
|
|
|
|
if (ocursor==-1) ocursor=cursor;
|
|
|
|
cursor -= cols;
|
2011-02-04 23:36:51 +00:00
|
|
|
if (cursor<0) {
|
|
|
|
if (core->offset>=cols) {
|
|
|
|
r_core_seek (core, core->offset-cols, 1);
|
|
|
|
ocursor += cols;
|
|
|
|
cursor += cols;
|
|
|
|
} else {
|
|
|
|
r_core_seek (core, 0, 1);
|
|
|
|
cursor = 0;
|
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
}
|
2011-03-02 13:11:34 +00:00
|
|
|
} else {
|
|
|
|
ut64 at = (core->offset>obs)?core->offset-obs:0;
|
|
|
|
r_core_seek (core, at, 1);
|
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
|
|
|
case '[':
|
|
|
|
{
|
|
|
|
int scrcols = r_config_get_i (core->config, "scr.cols");
|
|
|
|
if (scrcols>2)
|
|
|
|
r_config_set_i (core->config, "scr.cols", scrcols-2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
{
|
|
|
|
int scrcols = r_config_get_i (core->config, "scr.cols");
|
2012-07-16 09:39:43 +00:00
|
|
|
r_config_set_i (core->config, "scr.cols", scrcols+2);
|
2011-02-04 23:20:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-11-25 03:32:32 +00:00
|
|
|
case 'I':
|
|
|
|
r_core_cmd (core, "dsp", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
break;
|
2009-02-18 00:43:57 +00:00
|
|
|
case 's':
|
2012-05-30 09:14:41 +00:00
|
|
|
if (curset) {
|
|
|
|
// dcu 0xaddr
|
|
|
|
char xxx[128];
|
|
|
|
snprintf (xxx, sizeof (xxx), "dcu 0x%08"PFMT64x, core->offset + cursor);
|
|
|
|
r_core_cmd (core, xxx, 0);
|
|
|
|
curset = 0;
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "ds", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
}
|
2009-02-18 00:43:57 +00:00
|
|
|
break;
|
2010-05-24 15:51:51 +00:00
|
|
|
case 'S':
|
2012-05-30 09:14:41 +00:00
|
|
|
if (curset) {
|
|
|
|
r_core_cmd (core, "dcr", 0);
|
|
|
|
curset = 0;
|
|
|
|
} else {
|
|
|
|
r_core_cmd (core, "dso", 0);
|
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
}
|
2010-05-24 15:51:51 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'p':
|
2011-12-02 13:41:17 +00:00
|
|
|
core->printidx = R_ABS ((core->printidx+1)%NPF);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
2011-12-02 13:41:17 +00:00
|
|
|
if (core->printidx)
|
|
|
|
core->printidx--;
|
|
|
|
else core->printidx = NPF-1;
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-02-18 00:43:57 +00:00
|
|
|
case 'm':
|
2011-09-04 00:34:54 +00:00
|
|
|
r_core_visual_mark (core, r_cons_readchar ());
|
2009-02-18 00:43:57 +00:00
|
|
|
break;
|
|
|
|
case '\'':
|
2011-09-04 00:34:54 +00:00
|
|
|
r_core_visual_mark_seek (core, r_cons_readchar ());
|
2009-02-18 00:43:57 +00:00
|
|
|
break;
|
2010-08-12 13:52:07 +00:00
|
|
|
case 'y':
|
|
|
|
if (ocursor==-1) r_core_yank (core, core->offset+cursor, 1);
|
2011-10-25 18:30:05 +00:00
|
|
|
else r_core_yank (core, core->offset+((ocursor<cursor)?
|
|
|
|
ocursor:cursor), R_ABS (cursor-ocursor)+1);
|
2010-08-12 13:52:07 +00:00
|
|
|
break;
|
|
|
|
case 'Y':
|
2012-09-19 12:08:44 +00:00
|
|
|
if (!core->yank_buf) {
|
2010-10-19 11:17:25 +00:00
|
|
|
r_cons_strcat ("Can't paste, clipboard is empty.\n");
|
2010-08-12 13:52:07 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key ();
|
2011-12-02 01:13:49 +00:00
|
|
|
r_cons_clear00 ();
|
2010-10-19 11:17:25 +00:00
|
|
|
} else r_core_yank_paste (core, core->offset+cursor, 0);
|
2010-08-12 13:52:07 +00:00
|
|
|
break;
|
2010-06-17 15:55:39 +00:00
|
|
|
case '-':
|
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
int cur = core->print->cur;
|
|
|
|
if (cur>=core->blocksize)
|
|
|
|
cur = core->print->cur-1;
|
2010-08-12 13:52:07 +00:00
|
|
|
if (ocursor==-1) sprintf (buf, "wos 01 @ $$+%i:1",cursor);
|
2011-10-25 18:30:05 +00:00
|
|
|
else sprintf (buf, "wos 01 @ $$+%i:%i", cursor<ocursor?
|
|
|
|
cursor:ocursor, R_ABS (ocursor-cursor)+1);
|
2010-08-12 13:52:07 +00:00
|
|
|
r_core_cmd (core, buf, 0);
|
2011-11-29 02:46:46 +00:00
|
|
|
} else {
|
2011-12-05 14:21:13 +00:00
|
|
|
if (!autoblocksize)
|
|
|
|
r_core_block_size (core, core->blocksize-1);
|
2011-11-29 02:46:46 +00:00
|
|
|
}
|
2010-06-17 15:55:39 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case '+':
|
2010-06-17 15:55:39 +00:00
|
|
|
if (core->print->cur_enabled) {
|
|
|
|
int cur = core->print->cur;
|
|
|
|
if (cur>=core->blocksize)
|
|
|
|
cur = core->print->cur-1;
|
2011-01-26 20:54:39 +00:00
|
|
|
if (ocursor==-1) sprintf (buf, "woa 01 @ $$+%i:1", cursor);
|
2011-10-25 18:30:05 +00:00
|
|
|
else sprintf (buf, "woa 01 @ $$+%i:%i",
|
|
|
|
cursor<ocursor? cursor: ocursor, R_ABS (ocursor-cursor)+1);
|
2010-08-12 13:52:07 +00:00
|
|
|
r_core_cmd (core, buf, 0);
|
2011-11-29 02:46:46 +00:00
|
|
|
} else {
|
2011-12-05 14:21:13 +00:00
|
|
|
if (!autoblocksize)
|
|
|
|
r_core_block_size (core, core->blocksize+1);
|
2011-11-29 02:46:46 +00:00
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case '/':
|
2012-08-01 23:50:39 +00:00
|
|
|
if (curset) {
|
|
|
|
visual_search (core);
|
|
|
|
} else {
|
|
|
|
if (!autoblocksize)
|
|
|
|
r_core_block_size (core, core->blocksize-cols);
|
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case '*':
|
2011-12-05 14:21:13 +00:00
|
|
|
if (!autoblocksize)
|
|
|
|
r_core_block_size (core, core->blocksize+cols);
|
2009-03-12 12:30:32 +00:00
|
|
|
break;
|
|
|
|
case '>':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_seek_align (core, core->blocksize, 1);
|
2011-12-04 20:09:16 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset);
|
2009-03-12 12:30:32 +00:00
|
|
|
break;
|
|
|
|
case '<':
|
2011-03-02 13:11:34 +00:00
|
|
|
r_core_seek_align (core, core->blocksize, -1);
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_seek_align (core, core->blocksize, -1);
|
2011-12-04 20:09:16 +00:00
|
|
|
r_io_sundo_push (core->io, core->offset);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-04-18 21:49:17 +00:00
|
|
|
case '.':
|
2012-07-16 09:39:43 +00:00
|
|
|
r_core_cmd (core, "sr pc", 0);
|
2009-04-18 21:49:17 +00:00
|
|
|
break;
|
2012-09-28 00:20:52 +00:00
|
|
|
#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
|
2011-05-21 12:27:46 +00:00
|
|
|
case ':':
|
2011-06-04 01:23:12 +00:00
|
|
|
r_core_visual_prompt (core);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2012-01-31 01:45:17 +00:00
|
|
|
case '_':
|
2012-02-01 01:22:43 +00:00
|
|
|
if (r_config_get_i (core->config, "hud.once"))
|
|
|
|
r_core_visual_hud (core);
|
|
|
|
else while (r_core_visual_hud (core));
|
2012-01-31 01:45:17 +00:00
|
|
|
break;
|
2009-04-06 22:53:25 +00:00
|
|
|
case ';':
|
2011-05-21 12:27:46 +00:00
|
|
|
r_cons_printf ("Enter a comment: ('-' to remove, '!' to use $EDITOR)\n");
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_TRUE);
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_flush ();
|
2011-03-05 18:09:38 +00:00
|
|
|
r_cons_set_raw (R_FALSE);
|
2011-09-12 01:01:07 +00:00
|
|
|
strcpy (buf, "CC ");
|
2011-03-05 18:09:38 +00:00
|
|
|
r_line_set_prompt ("comment: ");
|
2011-05-21 12:27:46 +00:00
|
|
|
i = strlen (buf);
|
|
|
|
if (r_cons_fgets (buf+i, sizeof (buf)-i-1, 0, NULL) >1) {
|
|
|
|
ut64 orig = core->offset;
|
|
|
|
ut64 addr = core->offset;
|
|
|
|
if (curset) {
|
|
|
|
addr += cursor;
|
|
|
|
r_core_seek (core, addr, 0);
|
|
|
|
}
|
|
|
|
switch (buf[i]) {
|
|
|
|
case '-':
|
|
|
|
strcpy (buf, "CC-");
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
strcpy (buf, "CC!");
|
|
|
|
break;
|
|
|
|
}
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_cmd (core, buf, 1);
|
2011-05-21 12:27:46 +00:00
|
|
|
if (curset) r_core_seek (core, orig, 1);
|
2009-04-07 11:28:22 +00:00
|
|
|
}
|
2011-03-05 18:09:38 +00:00
|
|
|
r_cons_set_raw (R_TRUE);
|
2011-12-02 00:58:34 +00:00
|
|
|
r_cons_show_cursor (R_FALSE);
|
2009-04-06 22:53:25 +00:00
|
|
|
break;
|
2012-09-28 00:20:52 +00:00
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
ut64 addr = curset? core->offset + cursor : core->offset;
|
|
|
|
RBreakpointItem *bp = r_bp_get (core->dbg->bp, addr);
|
|
|
|
if (bp) {
|
|
|
|
r_bp_del (core->dbg->bp, addr);
|
|
|
|
} else {
|
|
|
|
r_bp_add_sw (core->dbg->bp, addr, 1, R_BP_PROT_EXEC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-02-02 23:57:29 +00:00
|
|
|
case 'B':
|
2011-05-21 12:27:46 +00:00
|
|
|
autoblocksize = !autoblocksize;
|
2011-02-02 23:57:29 +00:00
|
|
|
if (autoblocksize)
|
|
|
|
obs = core->blocksize;
|
|
|
|
else r_core_block_size (core, obs);
|
2011-11-29 02:46:46 +00:00
|
|
|
r_cons_clear ();
|
2011-02-02 23:57:29 +00:00
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'u':
|
2011-12-04 20:09:16 +00:00
|
|
|
{
|
2011-12-05 07:27:16 +00:00
|
|
|
ut64 off = r_io_sundo (core->io, core->offset);
|
2011-12-04 20:09:16 +00:00
|
|
|
if (off != UT64_MAX)
|
|
|
|
r_core_seek (core, off, 1);
|
|
|
|
else eprintf ("Cannot undo\n");
|
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
|
|
|
case 'U':
|
2011-12-05 07:27:16 +00:00
|
|
|
{
|
|
|
|
ut64 off = r_io_sundo_redo (core->io);
|
|
|
|
if (off != UT64_MAX)
|
|
|
|
r_core_seek (core, off, 1);
|
|
|
|
}
|
2011-02-04 23:20:28 +00:00
|
|
|
break;
|
2011-02-16 23:58:54 +00:00
|
|
|
case 'z':
|
2011-02-23 02:01:26 +00:00
|
|
|
if (zoom && cursor) {
|
|
|
|
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)*cursor, 1);
|
|
|
|
}
|
2011-02-16 23:58:54 +00:00
|
|
|
zoom = !zoom;
|
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case '?':
|
2012-02-01 01:22:43 +00:00
|
|
|
r_cons_clear00 ();
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_printf (
|
2012-02-01 01:22:43 +00:00
|
|
|
"Visual mode help:\n"
|
|
|
|
" >||< seek aligned to block size\n"
|
2012-09-28 00:20:52 +00:00
|
|
|
" hjkl move around (or HJKL)\n"
|
2012-02-01 01:22:43 +00:00
|
|
|
" pP rotate print modes\n"
|
|
|
|
" /*+-[] change block size, [] = resize scr.cols\n"
|
|
|
|
" cC toggle cursor and colors\n"
|
|
|
|
" gG go seek to begin and end of file (0-$s)\n"
|
|
|
|
" d[f?] define function, data, code, ..\n"
|
2012-08-13 02:33:01 +00:00
|
|
|
" D enter visual diff mode (set diff.from/to)\n"
|
2012-02-01 01:22:43 +00:00
|
|
|
" x show xrefs to seek between them\n"
|
|
|
|
" sS step / step over\n"
|
2012-09-28 00:20:52 +00:00
|
|
|
//" n/N seek next/previous block\n"
|
2012-11-07 03:25:42 +00:00
|
|
|
" i/a insert hex (i) or assemble code (a)\n"
|
2012-02-01 01:22:43 +00:00
|
|
|
" e edit eval configuration variables\n"
|
|
|
|
" t track flags (browse symbols, functions..)\n"
|
|
|
|
" T browse anal info and comments\n"
|
|
|
|
" v visual code analysis menu\n"
|
2012-08-14 01:21:31 +00:00
|
|
|
" V view graph using cmd.graph (agv?)\n"
|
2012-11-07 03:25:42 +00:00
|
|
|
" M walk the mounted filesystems\n"
|
2012-09-28 00:20:52 +00:00
|
|
|
" f/F set/unset flag\n"
|
|
|
|
" n/N seek next/prev function/flag/hit (scr.nkey)\n"
|
|
|
|
" b/B toggle breakpoint / automatic block size\n"
|
2012-02-01 01:22:43 +00:00
|
|
|
" uU undo/redo seek\n"
|
|
|
|
" yY copy and paste selection\n"
|
|
|
|
" mK/'K mark/go to Key (any key)\n"
|
|
|
|
" M show mount points\n"
|
2012-11-07 03:25:42 +00:00
|
|
|
" _ enter the hud\n"
|
2012-08-01 23:50:39 +00:00
|
|
|
" / in cursor mode search in current block\n"
|
2012-02-01 01:22:43 +00:00
|
|
|
" :cmd run radare command\n"
|
|
|
|
" ;[-]cmt add/remove comment\n"
|
|
|
|
" . seek to program counter\n"
|
|
|
|
" z toggle zoom mode\n"
|
|
|
|
" q back to radare shell\n");
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key ();
|
2011-12-02 01:13:49 +00:00
|
|
|
r_cons_clear00 ();
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2012-02-01 01:22:43 +00:00
|
|
|
case 0x1b:
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'q':
|
2009-02-09 11:42:54 +00:00
|
|
|
case 'Q':
|
2012-06-14 08:01:16 +00:00
|
|
|
setcursor (core, 0);
|
2010-07-15 22:02:33 +00:00
|
|
|
return R_FALSE;
|
2009-02-09 00:54:09 +00:00
|
|
|
}
|
2010-07-15 22:02:33 +00:00
|
|
|
return R_TRUE;
|
2009-02-09 00:54:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 09:52:04 +00:00
|
|
|
#define PIDX (R_ABS(core->printidx%NPF))
|
2011-06-04 01:23:12 +00:00
|
|
|
R_API void r_core_visual_title (RCore *core, int color) {
|
2011-02-09 23:21:05 +00:00
|
|
|
const char *filename;
|
2011-12-02 13:32:04 +00:00
|
|
|
char pos[512], foo[512], bar[512];
|
2011-01-23 16:48:31 +00:00
|
|
|
/* automatic block size */
|
2011-02-02 23:57:29 +00:00
|
|
|
if (autoblocksize)
|
2011-06-04 01:14:04 +00:00
|
|
|
switch (core->printidx) {
|
2011-01-23 16:48:31 +00:00
|
|
|
case 0:
|
2011-02-04 23:20:28 +00:00
|
|
|
{
|
|
|
|
int scrcols = r_config_get_i (core->config, "scr.cols");
|
|
|
|
r_core_block_size (core, core->cons->rows * scrcols);
|
|
|
|
}
|
2011-01-23 16:48:31 +00:00
|
|
|
break;
|
2012-02-09 00:38:16 +00:00
|
|
|
case 3: // XXX pw
|
|
|
|
{
|
|
|
|
int scrcols = r_config_get_i (core->config, "scr.cols");
|
|
|
|
r_core_block_size (core, core->cons->rows * scrcols);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: // XXX pc
|
|
|
|
r_core_block_size (core, core->cons->rows * 5);
|
|
|
|
break;
|
2011-01-23 16:48:31 +00:00
|
|
|
case 1: // pd
|
|
|
|
case 2: // pd+dbg
|
2012-08-31 09:45:06 +00:00
|
|
|
r_core_block_size (core, core->cons->rows *5); // this is hacky
|
2011-01-23 16:48:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-21 12:27:46 +00:00
|
|
|
if (core->file && core->file->filename)
|
2011-02-09 23:21:05 +00:00
|
|
|
filename = core->file->filename;
|
2011-05-21 12:27:46 +00:00
|
|
|
else filename = "";
|
2011-11-22 00:42:16 +00:00
|
|
|
{ /* get flag with delta */
|
|
|
|
RFlagItem *f = r_flag_get_at (core->flags, core->offset);
|
|
|
|
if (f) {
|
|
|
|
if (f->offset == core->offset) snprintf (pos, sizeof (pos), "@ %s", f->name);
|
2012-02-01 10:49:46 +00:00
|
|
|
else snprintf (pos, sizeof (pos), "@ %s+%d (0x%"PFMT64x")",
|
|
|
|
f->name, (int)(core->offset-f->offset), f->offset);
|
2011-11-22 00:42:16 +00:00
|
|
|
} else pos[0] = 0;
|
|
|
|
}
|
2011-02-09 23:21:05 +00:00
|
|
|
|
2010-07-16 09:28:16 +00:00
|
|
|
if (cursor<0) cursor = 0;
|
|
|
|
if (color) r_cons_strcat (Color_YELLOW);
|
2012-07-16 09:39:43 +00:00
|
|
|
strncpy (bar, printfmt[PIDX], sizeof (bar)-1);
|
2012-02-01 10:49:46 +00:00
|
|
|
bar[sizeof (bar)-1] = 0; // '\0'-terminate bar
|
2011-12-02 13:32:04 +00:00
|
|
|
bar[10] = '.'; // chop cmdfmt
|
|
|
|
bar[11] = '.'; // chop cmdfmt
|
|
|
|
bar[12] = 0; // chop cmdfmt
|
2011-12-05 23:27:57 +00:00
|
|
|
if (curset)
|
2012-07-12 00:47:04 +00:00
|
|
|
snprintf (foo, sizeof (foo), "[0x%08"PFMT64x" %d %s(0x%x:%d=%d)]> %s\n", core->offset,
|
2011-12-05 23:27:57 +00:00
|
|
|
core->blocksize, filename, cursor, ocursor,
|
2011-12-02 13:32:04 +00:00
|
|
|
ocursor==-1?1:R_ABS (cursor-ocursor)+1, bar);
|
|
|
|
else
|
2011-12-02 13:41:17 +00:00
|
|
|
snprintf (foo, sizeof (foo), "[0x%08"PFMT64x" %d %s]> %s %s\n",
|
|
|
|
core->offset, core->blocksize, filename, bar, pos);
|
2011-12-02 13:32:04 +00:00
|
|
|
r_cons_printf (foo);
|
2010-07-16 09:28:16 +00:00
|
|
|
if (color) r_cons_strcat (Color_RESET);
|
2009-02-09 11:42:54 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 12:12:16 +00:00
|
|
|
static void r_core_visual_refresh (RCore *core) {
|
2011-02-23 19:53:56 +00:00
|
|
|
const char *vi;
|
2012-02-15 10:11:25 +00:00
|
|
|
if (!core) return;
|
2011-01-23 12:12:16 +00:00
|
|
|
r_cons_get_size (NULL);
|
|
|
|
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
2011-11-24 23:22:44 +00:00
|
|
|
|
2012-06-30 18:51:18 +00:00
|
|
|
if (autoblocksize) {
|
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
r_cons_flush ();
|
|
|
|
} else r_cons_clear ();
|
2011-05-21 13:45:43 +00:00
|
|
|
|
2011-06-05 18:36:22 +00:00
|
|
|
vi = r_config_get (core->config, "cmd.vprompt");
|
|
|
|
if (vi) r_core_cmd (core, vi, 0);
|
|
|
|
r_core_visual_title (core, color);
|
|
|
|
|
2011-05-21 13:45:43 +00:00
|
|
|
vi = r_config_get (core->config, "cmd.cprompt");
|
|
|
|
if (vi && *vi) {
|
|
|
|
r_cons_printf ("\n[cmd.cprompt] %s\n", vi);
|
|
|
|
r_core_cmd (core, vi, 0);
|
|
|
|
r_cons_column (80);
|
|
|
|
}
|
2012-09-28 00:20:52 +00:00
|
|
|
if (zoom) r_core_cmd (core, "pz", 0);
|
2012-07-16 09:39:43 +00:00
|
|
|
else r_core_cmd (core, printfmt[PIDX], 0);
|
2011-05-21 12:27:46 +00:00
|
|
|
blocksize = core->num->value? core->num->value : core->blocksize;
|
2011-01-23 12:12:16 +00:00
|
|
|
r_cons_visual_flush ();
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_visual(RCore *core, const char *input) {
|
2011-02-27 23:03:26 +00:00
|
|
|
const char *cmdprompt, *teefile;
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 scrseek;
|
2011-02-02 23:57:29 +00:00
|
|
|
int ch;
|
|
|
|
obs = core->blocksize;
|
2009-02-09 00:54:09 +00:00
|
|
|
|
2012-09-19 12:08:44 +00:00
|
|
|
core->vmode = R_TRUE;
|
2012-06-26 14:20:30 +00:00
|
|
|
core->cons->data = core;
|
|
|
|
core->cons->event_resize = (RConsEvent)r_core_visual_refresh;
|
2012-02-16 01:40:50 +00:00
|
|
|
//r_cons_set_cup (R_TRUE);
|
2011-01-23 12:12:16 +00:00
|
|
|
|
2011-03-01 23:02:50 +00:00
|
|
|
while (*input) {
|
2012-07-16 09:39:43 +00:00
|
|
|
if (!r_core_visual_cmd (core, input[0]))
|
2009-02-09 00:54:09 +00:00
|
|
|
return 0;
|
2011-01-23 12:12:16 +00:00
|
|
|
input++;
|
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 = "";
|
|
|
|
|
2010-05-19 22:59:42 +00:00
|
|
|
color = r_config_get_i (core->config, "scr.color");
|
|
|
|
debug = r_config_get_i (core->config, "cfg.debug");
|
2010-07-15 22:02:33 +00:00
|
|
|
flags = R_PRINT_FLAGS_ADDRMOD | R_PRINT_FLAGS_HEADER;
|
|
|
|
if (color) flags |= R_PRINT_FLAGS_COLOR;
|
2009-02-09 00:54:09 +00:00
|
|
|
do {
|
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"));
|
2011-01-23 12:12:16 +00:00
|
|
|
if (scrseek != 0LL)
|
2009-04-07 11:28:22 +00:00
|
|
|
r_core_seek (core, scrseek, 1);
|
2010-02-28 22:57:55 +00:00
|
|
|
if (debug)
|
2010-05-19 22:59:42 +00:00
|
|
|
r_core_cmd (core, ".dr*", 0);
|
|
|
|
cmdprompt = r_config_get (core->config, "cmd.vprompt");
|
2010-02-28 22:57:55 +00:00
|
|
|
if (cmdprompt && *cmdprompt)
|
|
|
|
r_core_cmd (core, cmdprompt, 0);
|
2011-01-23 12:12:16 +00:00
|
|
|
r_core_visual_refresh (core);
|
2010-02-28 22:57:55 +00:00
|
|
|
ch = r_cons_readchar ();
|
|
|
|
} while (r_core_visual_cmd (core, ch));
|
|
|
|
|
|
|
|
if (color)
|
|
|
|
r_cons_printf (Color_RESET);
|
2010-06-20 23:58:45 +00:00
|
|
|
core->print->cur_enabled = R_FALSE;
|
2011-02-02 23:57:29 +00:00
|
|
|
if (autoblocksize)
|
|
|
|
r_core_block_size (core, obs);
|
2011-02-27 23:03:26 +00:00
|
|
|
r_cons_singleton ()->teefile = teefile;
|
2012-02-16 01:40:50 +00:00
|
|
|
r_cons_clear00 ();
|
2011-05-15 23:47:01 +00:00
|
|
|
r_cons_set_cup (R_FALSE);
|
2012-09-19 12:08:44 +00:00
|
|
|
core->vmode = R_FALSE;
|
2009-02-05 21:08:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|