2011-01-23 12:12:16 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#include "r_core.h"
|
|
|
|
|
2009-02-18 00:43:57 +00:00
|
|
|
#define NPF 6
|
2011-05-21 12:27:46 +00:00
|
|
|
static int blocksize = 0;
|
2011-06-03 16:54:12 +00:00
|
|
|
static const char *printfmt[] = { "x", "pd", "f tmp;sr sp;x 64;dr=;s-;s tmp;f-tmp;pd", "p8", "pc", "ps" };
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_fgets (buf, sizeof (buf), 0, NULL);
|
|
|
|
r_core_cmd (core, buf, 0);
|
|
|
|
r_cons_any_key ();
|
|
|
|
if (curset) r_core_seek (core, oseek, 1);
|
|
|
|
}
|
|
|
|
|
2010-05-19 22:59:42 +00:00
|
|
|
|
2011-06-05 22:16:11 +00:00
|
|
|
static int visual_fkey(RCore *core, int ch) {
|
|
|
|
const char *cmd;
|
|
|
|
switch (ch) {
|
|
|
|
case R_CONS_KEY_F1:
|
|
|
|
cmd = r_config_get (core->config, "key.f1");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
ch = '?';
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F2:
|
|
|
|
cmd = r_config_get (core->config, "key.f2");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
// TODO: toggle breakpoint
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F3:
|
|
|
|
cmd = r_config_get (core->config, "key.f3");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
// TODO: F3
|
|
|
|
break;
|
|
|
|
case R_CONS_KEY_F4:
|
|
|
|
cmd = r_config_get (core->config, "key.f4");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
// TODO: F4
|
|
|
|
case R_CONS_KEY_F5:
|
|
|
|
cmd = r_config_get (core->config, "key.f5");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
// TODO: F5
|
|
|
|
case R_CONS_KEY_F6:
|
|
|
|
cmd = r_config_get (core->config, "key.f6");
|
|
|
|
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
|
|
|
|
// TODO: F6
|
|
|
|
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);
|
|
|
|
// TODO: F8
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-02-09 00:54:09 +00:00
|
|
|
/* TODO: use r_cmd here in core->vcmd..optimize over 255 table */
|
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);
|
2011-06-05 22:16:11 +00:00
|
|
|
ch = visual_fkey (core, ch);
|
|
|
|
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?
|
2010-05-19 22:59:42 +00:00
|
|
|
if (ch>='0'&&ch<='9') {
|
2011-03-03 15:52:51 +00:00
|
|
|
r_core_seek (core, core->asmqjmps[ch-'0'], 1);
|
|
|
|
r_io_sundo_push (core->io);
|
2010-05-19 22:59:42 +00:00
|
|
|
} else
|
|
|
|
switch (ch) {
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'c':
|
2010-07-15 22:02:33 +00:00
|
|
|
// XXX dupped flag imho
|
2009-02-09 11:42:54 +00:00
|
|
|
curset ^= 1;
|
2010-07-15 22:02:33 +00:00
|
|
|
if (curset) flags|=R_PRINT_FLAGS_CURSOR;
|
|
|
|
else flags &= ~(flags&R_PRINT_FLAGS_CURSOR);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_print_set_flags (core->print, flags);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
r_core_visual_define (core);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
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':
|
2011-05-21 12:27:46 +00:00
|
|
|
r_core_seek_next (core, r_config_get (core->config, "scr.fkey"));
|
2011-03-01 23:02:50 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2011-05-21 12:27:46 +00:00
|
|
|
r_core_seek_previous (core, r_config_get (core->config, "scr.fkey"));
|
2011-03-01 23:02:50 +00:00
|
|
|
break;
|
2009-04-07 00:26:41 +00:00
|
|
|
case 'a':
|
2010-04-14 22:29:42 +00:00
|
|
|
r_cons_printf ("Enter assembler opcodes separated with ';':\n");
|
|
|
|
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
|
|
|
}
|
2010-04-14 22:29:42 +00:00
|
|
|
r_cons_set_raw (R_TRUE);
|
2009-04-07 00:26:41 +00:00
|
|
|
break;
|
2009-04-07 11:28:22 +00:00
|
|
|
case 'w':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_printf ("Enter hexpair string to write:\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
strcpy (buf, "wx ");
|
|
|
|
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
2011-06-04 01:14:04 +00:00
|
|
|
if (*buf) {
|
|
|
|
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);
|
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;
|
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;
|
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);
|
|
|
|
} else
|
|
|
|
r_core_cmd (core, "s 0", 0);
|
2011-07-04 16:54:41 +00:00
|
|
|
r_io_sundo_push (core->io);
|
2009-03-20 21:05:12 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
2011-06-26 21:41:34 +00:00
|
|
|
if (core->io->va) {
|
|
|
|
ut64 offset = r_io_section_get_vaddr (core->io, core->file->size-core->blocksize);
|
|
|
|
r_core_seek (core, offset, 1);
|
|
|
|
} else
|
|
|
|
r_core_seek (core, core->file->size-core->blocksize, 1);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_io_sundo_push (core->io);
|
2009-03-20 21:05:12 +00:00
|
|
|
//r_core_cmd(core, "s 0", 0);
|
|
|
|
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) {
|
|
|
|
r_core_seek (core, core->offset-cols, 1);
|
|
|
|
cursor ++;
|
|
|
|
}
|
2010-02-02 10:09:52 +00:00
|
|
|
} else r_core_cmd (core, "s-1", 0);
|
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;
|
|
|
|
}
|
|
|
|
} else r_core_cmd (core, "s-2", 0);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-02-02 10:09:52 +00:00
|
|
|
} else r_core_cmd (core, "s+1", 0);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else r_core_cmd (core, "s+2", 0);
|
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)
|
2011-05-21 12:27:46 +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) {
|
|
|
|
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)
|
2011-05-21 12:27:46 +00:00
|
|
|
cols = 4; //r_asm_disassemble (core->assembler, &op, core->block, 32);
|
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");
|
|
|
|
//if (scrcols<32)
|
|
|
|
r_config_set_i (core->config, "scr.cols", scrcols+2);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-18 00:43:57 +00:00
|
|
|
case 's':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_cmd (core, "ds", 0);
|
2010-08-06 15:19:09 +00:00
|
|
|
r_core_cmd (core, ".dr*", 0);
|
2009-04-06 22:53:25 +00:00
|
|
|
//r_core_cmd(core, "s eip", 0);
|
2009-02-18 00:43:57 +00:00
|
|
|
break;
|
2010-05-24 15:51:51 +00:00
|
|
|
case 'S':
|
|
|
|
r_core_cmd (core, "dso", 0);
|
2010-08-06 15:19:09 +00:00
|
|
|
r_core_cmd (core, ".dr*", 0);
|
2010-05-24 15:51:51 +00:00
|
|
|
//r_core_cmd(core, "s eip", 0);
|
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'p':
|
2011-06-04 01:14:04 +00:00
|
|
|
core->printidx = (core->printidx+1)%NPF;
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
2011-06-04 01:14:04 +00:00
|
|
|
core->printidx = (core->printidx-1)%NPF;
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-02-18 00:43:57 +00:00
|
|
|
case 'm':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_visual_mark (core, r_cons_readchar());
|
2009-02-18 00:43:57 +00:00
|
|
|
break;
|
|
|
|
case '\'':
|
2010-02-02 10:09:52 +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);
|
|
|
|
else r_core_yank (core, core->offset+((ocursor<cursor)?ocursor:cursor), R_ABS (cursor-ocursor)+1);
|
|
|
|
break;
|
|
|
|
case 'Y':
|
2010-10-19 11:17:25 +00:00
|
|
|
if (!core->yank) {
|
|
|
|
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 ();
|
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);
|
|
|
|
else sprintf (buf, "wos 01 @ $$+%i:%i", cursor<ocursor?cursor:ocursor, R_ABS (ocursor-cursor)+1);
|
|
|
|
r_core_cmd (core, buf, 0);
|
2010-06-17 15:55:39 +00:00
|
|
|
} else r_core_block_size (core, core->blocksize-1);
|
|
|
|
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);
|
2010-08-12 13:52:07 +00:00
|
|
|
else sprintf (buf, "woa 01 @ $$+%i:%i", cursor<ocursor?cursor:ocursor, R_ABS (ocursor-cursor)+1);
|
|
|
|
r_core_cmd (core, buf, 0);
|
2010-06-27 22:43:07 +00:00
|
|
|
} else r_core_block_size (core, core->blocksize+1);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case '/':
|
2010-10-17 21:03:54 +00:00
|
|
|
r_core_block_size (core, core->blocksize-cols);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case '*':
|
2010-10-17 21:03:54 +00:00
|
|
|
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);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_io_sundo_push (core->io);
|
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);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_io_sundo_push (core->io);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-04-18 21:49:17 +00:00
|
|
|
case '.':
|
2010-04-06 12:23:12 +00:00
|
|
|
r_core_cmd (core, "sr pc", 0); // XXX
|
2009-04-18 21:49:17 +00:00
|
|
|
break;
|
2011-05-21 12:27:46 +00:00
|
|
|
case 'n':
|
|
|
|
r_core_seek (core, core->offset + (core->num->value/4), 1);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
r_core_seek (core, core->offset - (core->num->value/4), 1);
|
|
|
|
break;
|
|
|
|
case ':':
|
2011-06-04 01:23:12 +00:00
|
|
|
r_core_visual_prompt (core);
|
2009-02-09 00:54:09 +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");
|
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);
|
2010-08-26 02:19:12 +00:00
|
|
|
strcpy (buf, "CC 0 ");
|
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);
|
2009-04-06 22:53:25 +00:00
|
|
|
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);
|
|
|
|
break;
|
2011-02-04 23:20:28 +00:00
|
|
|
case 'u':
|
|
|
|
if (r_io_sundo (core->io))
|
|
|
|
r_core_seek (core, core->io->off, 1);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
if (r_io_sundo_redo (core->io))
|
|
|
|
r_core_seek (core, core->io->off, 1);
|
|
|
|
break;
|
2010-06-25 09:22:14 +00:00
|
|
|
case 'x':
|
|
|
|
r_core_cmdf (core, "./a 0x%08llx @ entry0", core->offset);
|
|
|
|
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 '?':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
2009-02-09 00:54:09 +00:00
|
|
|
"\nVisual mode help:\n\n"
|
2011-01-23 12:12:16 +00:00
|
|
|
" >||< - seek aligned to block size\n"
|
|
|
|
" hjkl - move around\n"
|
|
|
|
" HJKL - move around faster\n"
|
|
|
|
" pP - rotate print modes\n"
|
2011-03-23 18:19:23 +00:00
|
|
|
" /*+-[] - change block size, [] = resize scr.cols\n"
|
2011-01-23 12:12:16 +00:00
|
|
|
" cC - toggle cursor and colors\n"
|
2011-06-26 01:01:32 +00:00
|
|
|
" gG - go seek to begin and end of file (0-$s)\n"
|
2011-01-23 12:12:16 +00:00
|
|
|
" d[f?] - define function, data, code, ..\n"
|
|
|
|
" x - find xrefs for current offset\n"
|
|
|
|
" sS - step / step over\n"
|
2011-05-21 12:27:46 +00:00
|
|
|
" e - edit eval configuration variables\n"
|
|
|
|
" t - track flags (browse symbols, functions..)\n"
|
|
|
|
" v - visual code analysis menu\n"
|
2011-03-01 23:02:50 +00:00
|
|
|
" fF - seek next/prev function/flag/hit (scr.fkey)\n"
|
2011-02-02 23:57:29 +00:00
|
|
|
" B - toggle automatic block size\n"
|
2011-01-23 12:12:16 +00:00
|
|
|
" uU - undo/redo seek\n"
|
|
|
|
" yY - copy and paste selection\n"
|
|
|
|
" mK/'K - mark/go to Key (any key)\n"
|
|
|
|
" :cmd - run radare command\n"
|
|
|
|
" ;[-]cmt - add/remove comment\n"
|
|
|
|
" . - seek to program counter\n"
|
2011-02-16 23:58:54 +00:00
|
|
|
" z - toggle zoom mode\n"
|
2011-01-23 12:12:16 +00:00
|
|
|
" q - back to radare shell\n");
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key ();
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
2009-02-09 11:42:54 +00:00
|
|
|
case 'Q':
|
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
|
|
|
}
|
|
|
|
|
2010-04-14 20:55:28 +00:00
|
|
|
// TODO: simplify R_ABS(printidx%NPF) into a macro, or just control negative values..
|
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-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;
|
|
|
|
case 1: // pd
|
|
|
|
case 2: // pd+dbg
|
2011-01-26 23:45:16 +00:00
|
|
|
r_core_block_size (core, core->cons->rows * 15);
|
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-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);
|
2011-01-23 16:48:31 +00:00
|
|
|
if (curset) r_cons_printf ("[0x%08"PFMT64x" %d %s(%d:%d=%d)]> %s\n", core->offset,
|
|
|
|
core->blocksize, core->file->filename, cursor, ocursor,
|
2011-06-04 01:14:04 +00:00
|
|
|
ocursor==-1?1:R_ABS (cursor-ocursor)+1, printfmt[R_ABS (core->printidx%NPF)]);
|
2011-01-23 16:48:31 +00:00
|
|
|
else r_cons_printf ("[0x%08"PFMT64x" %d %s]> %s\n", core->offset, core->blocksize,
|
2011-06-04 01:14:04 +00:00
|
|
|
filename, printfmt[R_ABS (core->printidx%NPF)]);
|
|
|
|
//r_cons_printf (" %d %d %d\n", core->printidx, core->cons->rows, core->blocksize);
|
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;
|
2011-01-23 12:12:16 +00:00
|
|
|
r_cons_get_size (NULL);
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
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);
|
|
|
|
}
|
|
|
|
|
2011-05-21 12:27:46 +00:00
|
|
|
if (zoom) r_core_cmd (core, "pZ", 0);
|
2011-06-04 01:14:04 +00:00
|
|
|
else r_core_cmd (core, printfmt[R_ABS (core->printidx%NPF)], 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
|
|
|
|
2011-05-21 12:27:46 +00:00
|
|
|
core->visual = R_TRUE;
|
2011-01-23 12:12:16 +00:00
|
|
|
r_cons_singleton ()->data = core;
|
|
|
|
r_cons_singleton ()->event_resize = (RConsEvent)r_core_visual_refresh;
|
2011-05-15 23:47:01 +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) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (!r_core_visual_cmd (core, input[0])) {
|
|
|
|
r_cons_clear00 ();
|
2011-06-04 01:14:04 +00:00
|
|
|
r_core_cmd (core, printfmt[R_ABS (core->printidx%NPF)], 0);
|
2010-03-08 11:45:22 +00:00
|
|
|
r_cons_visual_flush ();
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_any_key ();
|
2011-05-15 23:47:01 +00:00
|
|
|
r_cons_set_cup (R_FALSE);
|
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 {
|
2010-05-19 22:59:42 +00:00
|
|
|
scrseek = r_num_math (core->num,
|
|
|
|
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;
|
2011-05-15 23:47:01 +00:00
|
|
|
r_cons_set_cup (R_FALSE);
|
2011-05-21 12:27:46 +00:00
|
|
|
core->visual = R_FALSE;
|
2009-02-05 21:08:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|