2010-02-28 22:57:55 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2010 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
|
2009-02-09 00:54:09 +00:00
|
|
|
static int printidx = 0;
|
2010-05-24 17:38:13 +00:00
|
|
|
const char *printfmt[] = { "x", "pd", "f tmp&&sr sp&&x 64&&dr=&&s-&&s tmp&&f-tmp&&pd", "p8", "pc", "ps" };
|
2009-02-09 11:42:54 +00:00
|
|
|
|
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;
|
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
|
|
|
|
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-05-19 22:59:42 +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
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
static void r_core_visual_mark_seek(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-05-19 22:59:42 +00:00
|
|
|
for(i=0;i<UT8_MAX;i++)
|
2009-02-18 00:43:57 +00:00
|
|
|
marks[i] = 0;
|
|
|
|
marks_init = 1;
|
|
|
|
}
|
|
|
|
if (marks[ch])
|
2009-04-07 11:28:22 +00:00
|
|
|
r_core_seek(core, marks[ch], 1);
|
2009-02-18 00:43:57 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_visual_trackflags(RCore *core) {
|
2009-04-02 00:44:24 +00:00
|
|
|
char cmd[1024];
|
|
|
|
struct list_head *pos;
|
|
|
|
#define MAX_FORMAT 2
|
|
|
|
int format = 0;
|
|
|
|
const char *ptr;
|
|
|
|
const char *fs = NULL;
|
|
|
|
char *fs2 = NULL;
|
|
|
|
int option = 0;
|
|
|
|
int _option = 0;
|
|
|
|
int delta = 7;
|
|
|
|
int menu = 0;
|
|
|
|
int i,j, ch;
|
|
|
|
int hit;
|
|
|
|
|
2010-02-28 22:57:55 +00:00
|
|
|
for (;;) {
|
|
|
|
r_cons_gotoxy (0,0);
|
|
|
|
r_cons_clear ();
|
2009-04-02 00:44:24 +00:00
|
|
|
/* Execute visual prompt */
|
2010-05-19 22:59:42 +00:00
|
|
|
ptr = r_config_get (core->config, "cmd.vprompt");
|
2010-02-28 22:57:55 +00:00
|
|
|
if (ptr&&ptr[0])
|
|
|
|
r_core_cmd (core, ptr, 0);
|
2009-04-02 00:44:24 +00:00
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
if (menu) {
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_printf ("\n Flags in flagspace '%s'. Press '?' for help.\n\n",
|
2010-05-19 22:59:42 +00:00
|
|
|
(core->flags->space_idx==-1)?"*":core->flags->space[core->flags->space_idx]);
|
2009-04-02 00:44:24 +00:00
|
|
|
hit = 0;
|
|
|
|
i = j = 0;
|
2010-05-19 22:59:42 +00:00
|
|
|
list_for_each_prev (pos, &core->flags->flags) {
|
|
|
|
RFlagItem *flag = (RFlagItem*) list_entry(pos, RFlagItem, list);
|
2009-04-02 00:44:24 +00:00
|
|
|
/* filter per flag spaces */
|
2010-05-19 22:59:42 +00:00
|
|
|
if ((core->flags->space_idx != -1) &&
|
|
|
|
(flag->space != core->flags->space_idx))
|
2009-04-02 00:44:24 +00:00
|
|
|
continue;
|
|
|
|
if (option==i) {
|
|
|
|
fs2 = flag->name;
|
|
|
|
hit = 1;
|
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
if ((i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
2010-04-14 11:02:23 +00:00
|
|
|
r_cons_printf (" %c %03d 0x%08"PFMT64x" %4"PFMT64d" %s\n",
|
2009-04-02 00:44:24 +00:00
|
|
|
(option==i)?'>':' ',
|
|
|
|
i, flag->offset, flag->size, flag->name);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (!hit && i>0) {
|
|
|
|
option = i-1;
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_printf ("\n Selected: %s\n\n", fs2);
|
2009-04-02 00:44:24 +00:00
|
|
|
|
2010-02-28 22:57:55 +00:00
|
|
|
switch (format) {
|
2010-04-09 11:24:40 +00:00
|
|
|
case 0: sprintf (cmd, "px @ %s", fs2); printidx = 0; break;
|
|
|
|
case 1: sprintf (cmd, "pd 12 @ %s", fs2); printidx = 1; break;
|
|
|
|
case 2: sprintf (cmd, "ps @ %s", fs2); printidx = 5; break;
|
2009-04-02 00:44:24 +00:00
|
|
|
default: format = 0; continue;
|
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
if (*cmd) r_core_cmd (core, cmd, 0);
|
2010-03-08 11:45:22 +00:00
|
|
|
} else {
|
|
|
|
r_cons_printf ("\n Flag spaces:\n\n");
|
|
|
|
hit = 0;
|
|
|
|
for (j=i=0;i<R_FLAG_SPACES_MAX;i++) {
|
2010-05-19 22:59:42 +00:00
|
|
|
if (core->flags->space[i]) {
|
2010-03-08 11:45:22 +00:00
|
|
|
if (option==i) {
|
2010-05-19 22:59:42 +00:00
|
|
|
fs = core->flags->space[i];
|
2010-03-08 11:45:22 +00:00
|
|
|
hit = 1;
|
|
|
|
}
|
2010-05-19 22:59:42 +00:00
|
|
|
if ((i >=option-delta) && ((i<option+delta)|| \
|
|
|
|
((option<delta)&&(i<(delta<<1))))) {
|
2010-03-08 11:45:22 +00:00
|
|
|
r_cons_printf(" %c %02d %c %s\n",
|
2010-05-19 22:59:42 +00:00
|
|
|
(option==i)?'>':' ', j,
|
|
|
|
(i==core->flags->space_idx)?'*':' ',
|
|
|
|
core->flags->space[i]);
|
2010-03-08 11:45:22 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
{
|
|
|
|
if (option == j) {
|
|
|
|
fs = "*";
|
|
|
|
hit = 1;
|
|
|
|
}
|
|
|
|
r_cons_printf (" %c %02d %c %s\n",
|
|
|
|
(option==j)?'>':' ', j,
|
2010-05-19 22:59:42 +00:00
|
|
|
(i==core->flags->space_idx)?'*':' ',
|
2010-04-09 11:24:40 +00:00
|
|
|
"*");
|
|
|
|
}
|
2010-03-08 11:45:22 +00:00
|
|
|
if (!hit && j>0) {
|
|
|
|
option = j-1;
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-02 00:44:24 +00:00
|
|
|
}
|
2010-01-30 13:02:53 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
ch = r_cons_readchar ();
|
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
2010-04-09 11:24:40 +00:00
|
|
|
switch (ch) {
|
2009-04-02 00:44:24 +00:00
|
|
|
case 'J':
|
|
|
|
option+=10;
|
|
|
|
break;
|
2010-04-09 09:32:17 +00:00
|
|
|
case 'o':
|
2010-05-19 22:59:42 +00:00
|
|
|
r_flag_sort (core->flags, 0);
|
2010-04-09 09:32:17 +00:00
|
|
|
break;
|
|
|
|
case 'n':
|
2010-05-19 22:59:42 +00:00
|
|
|
r_flag_sort (core->flags, 1);
|
2010-04-09 09:32:17 +00:00
|
|
|
break;
|
2009-04-02 00:44:24 +00:00
|
|
|
case 'j':
|
|
|
|
option++;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
if (--option<0)
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
option-=10;
|
|
|
|
if (option<0)
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'b': // back
|
|
|
|
menu = 0;
|
|
|
|
option = _option;
|
|
|
|
break;
|
|
|
|
case 'a':
|
2010-02-28 22:57:55 +00:00
|
|
|
switch (menu) {
|
2009-04-02 00:44:24 +00:00
|
|
|
case 0: // new flag space
|
|
|
|
break;
|
|
|
|
case 1: // new flag
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2010-05-19 22:59:42 +00:00
|
|
|
r_flag_unset (core->flags, fs2);
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
/* TODO: prompt for addr, size, name */
|
2010-07-12 19:37:40 +00:00
|
|
|
eprintf ("TODO\n");
|
2010-07-24 10:44:19 +00:00
|
|
|
r_sys_sleep (1);
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
2009-04-02 10:23:32 +00:00
|
|
|
if (menu<=0) return R_TRUE; menu--;
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
|
|
|
case '*':
|
2010-06-17 15:55:39 +00:00
|
|
|
r_core_block_size (core, core->blocksize+16);
|
|
|
|
break;
|
2009-04-02 00:44:24 +00:00
|
|
|
case '+':
|
2010-02-28 22:57:55 +00:00
|
|
|
r_core_block_size (core, core->blocksize+1);
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
|
|
|
case '/':
|
2010-06-17 15:55:39 +00:00
|
|
|
r_core_block_size (core, core->blocksize-16);
|
|
|
|
break;
|
2009-04-02 00:44:24 +00:00
|
|
|
case '-':
|
2010-02-28 22:57:55 +00:00
|
|
|
r_core_block_size (core, core->blocksize-1);
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
2010-07-12 19:37:40 +00:00
|
|
|
case 'r':
|
|
|
|
if (menu == 1) {
|
|
|
|
int len;
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
// TODO: use r_flag_rename or wtf?..fr doesnt uses this..
|
|
|
|
snprintf (cmd, sizeof (cmd), "fr %s ", fs2);
|
|
|
|
len = strlen (cmd);
|
|
|
|
eprintf ("Rename flag '%s' as:\n", fs2);
|
|
|
|
if (r_cons_fgets (cmd+len, sizeof (cmd)-len-1, 0, NULL) <0)
|
|
|
|
cmd[0]='\0';
|
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-02 00:44:24 +00:00
|
|
|
case 'P':
|
|
|
|
if (--format<0)
|
|
|
|
format = MAX_FORMAT;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
format++;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
if (menu == 1) {
|
2010-04-09 11:24:40 +00:00
|
|
|
sprintf (cmd, "s %s", fs2);
|
|
|
|
r_core_cmd (core, cmd, 0);
|
2009-04-02 10:23:32 +00:00
|
|
|
return R_TRUE;
|
2009-04-02 00:44:24 +00:00
|
|
|
}
|
2010-05-19 22:59:42 +00:00
|
|
|
r_flag_space_set (core->flags, fs);
|
2009-04-02 00:44:24 +00:00
|
|
|
menu = 1;
|
|
|
|
_option = option;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case '?':
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
|
|
|
"\nVt: Visual Track help:\n\n"
|
|
|
|
" q - quit menu\n"
|
|
|
|
" j/k - down/up keys\n"
|
|
|
|
" h/b - go back\n"
|
|
|
|
" l/' ' - accept current selection\n"
|
|
|
|
" a/d/e - add/delete/edit flag\n"
|
|
|
|
" +/- - increase/decrease block size\n"
|
2010-04-08 13:48:53 +00:00
|
|
|
" o - sort flags by offset\n"
|
2010-07-12 19:37:40 +00:00
|
|
|
" r - rename flag\n"
|
2010-04-08 13:48:53 +00:00
|
|
|
" n - sort flags by name\n"
|
2010-02-28 22:57:55 +00:00
|
|
|
" p/P - rotate print format\n"
|
|
|
|
" : - enter command\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key ();
|
2009-04-02 00:44:24 +00:00
|
|
|
break;
|
|
|
|
case ':':
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_set_raw (0);
|
2009-04-02 00:44:24 +00:00
|
|
|
cmd[0]='\0';
|
2010-05-19 22:59:42 +00:00
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) <0)
|
2009-04-02 00:44:24 +00:00
|
|
|
cmd[0]='\0';
|
|
|
|
//line[strlen(line)-1]='\0';
|
2010-02-28 22:57:55 +00:00
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
r_cons_set_raw (1);
|
2009-04-02 00:44:24 +00:00
|
|
|
if (cmd[0])
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_any_key ();
|
2009-04-02 00:44:24 +00:00
|
|
|
//cons_gotoxy(0,0);
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_clear ();
|
2009-04-02 00:44:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
static void config_visual_hit_i(RCore *core, const char *name, int delta) {
|
2009-04-02 01:23:45 +00:00
|
|
|
struct r_config_node_t *node;
|
2010-05-19 22:59:42 +00:00
|
|
|
node = r_config_node_get (core->config, name);
|
2009-04-02 10:23:32 +00:00
|
|
|
if (node && ((node->flags & CN_INT) || (node->flags & CN_OFFT)))
|
2010-05-19 22:59:42 +00:00
|
|
|
r_config_set_i(core->config, name, r_config_get_i(core->config, name)+delta);
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Visually activate the config variable */
|
2010-03-08 11:45:22 +00:00
|
|
|
static void config_visual_hit(RCore *core, const char *name) {
|
2009-04-02 01:23:45 +00:00
|
|
|
char buf[1024];
|
2010-03-08 11:45:22 +00:00
|
|
|
RConfigNode *node;
|
2009-04-02 01:23:45 +00:00
|
|
|
|
2010-05-19 22:59:42 +00:00
|
|
|
if (!(node = r_config_node_get(core->config, name)))
|
2010-03-08 11:45:22 +00:00
|
|
|
return;
|
|
|
|
if (node->flags & CN_BOOL) {
|
|
|
|
/* TOGGLE */
|
|
|
|
node->i_value = !node->i_value;
|
|
|
|
node->value = r_str_dup(node->value, node->i_value?"true":"false");
|
|
|
|
} else {
|
|
|
|
// FGETS AND SO
|
|
|
|
r_cons_printf("New value (old=%s): ", node->value);
|
|
|
|
r_cons_flush();
|
|
|
|
r_cons_set_raw(0);
|
|
|
|
r_cons_fgets(buf, 1023, 0, 0);
|
|
|
|
r_cons_set_raw(1);
|
|
|
|
node->value = r_str_dup(node->value, buf);
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API void r_core_visual_config(RCore *core) {
|
2009-04-02 01:23:45 +00:00
|
|
|
char cmd[1024];
|
|
|
|
struct list_head *pos;
|
|
|
|
#define MAX_FORMAT 2
|
|
|
|
const char *ptr;
|
|
|
|
char *fs = NULL;
|
|
|
|
char *fs2 = NULL;
|
|
|
|
int option = 0;
|
|
|
|
int _option = 0;
|
|
|
|
int delta = 9;
|
|
|
|
int menu = 0;
|
|
|
|
int i,j, ch;
|
|
|
|
int hit;
|
|
|
|
int show;
|
|
|
|
char old[1024];
|
|
|
|
old[0]='\0';
|
|
|
|
|
2010-02-28 22:57:55 +00:00
|
|
|
for (;;) {
|
2010-04-09 11:24:40 +00:00
|
|
|
r_cons_gotoxy (0,0);
|
|
|
|
r_cons_clear ();
|
2009-04-02 01:23:45 +00:00
|
|
|
|
|
|
|
/* Execute visual prompt */
|
2010-05-19 22:59:42 +00:00
|
|
|
ptr = r_config_get (core->config, "cmd.vprompt");
|
2009-04-02 01:23:45 +00:00
|
|
|
if (ptr&&ptr[0]) {
|
|
|
|
// int tmp = last_print_format;
|
2010-04-09 11:24:40 +00:00
|
|
|
r_core_cmd (core, ptr, 0);
|
2009-04-02 01:23:45 +00:00
|
|
|
// last_print_format = tmp;
|
|
|
|
}
|
|
|
|
|
2010-04-09 11:24:40 +00:00
|
|
|
if (fs&&!memcmp (fs, "asm.", 4))
|
|
|
|
r_core_cmd (core, "pd 5", 0);
|
2009-04-02 01:23:45 +00:00
|
|
|
|
2010-04-09 11:24:40 +00:00
|
|
|
switch (menu) {
|
|
|
|
case 0: // flag space
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_printf ("\n Eval spaces:\n\n");
|
2010-04-09 11:24:40 +00:00
|
|
|
hit = 0;
|
|
|
|
j = i = 0;
|
2010-05-19 22:59:42 +00:00
|
|
|
list_for_each(pos, &(core->config->nodes)) {
|
2010-04-09 11:24:40 +00:00
|
|
|
struct r_config_node_t *bt = list_entry(pos, struct r_config_node_t, list);
|
|
|
|
if (option==i) {
|
|
|
|
fs = bt->name;
|
|
|
|
hit = 1;
|
|
|
|
}
|
|
|
|
if (old[0]=='\0') {
|
2010-06-25 09:22:14 +00:00
|
|
|
r_str_ccpy (old, bt->name, '.');
|
2010-04-09 11:24:40 +00:00
|
|
|
show = 1;
|
|
|
|
} else if (r_str_ccmp(old, bt->name, '.')) {
|
2010-06-25 09:22:14 +00:00
|
|
|
r_str_ccpy (old, bt->name, '.');
|
2010-04-09 11:24:40 +00:00
|
|
|
show = 1;
|
2010-06-25 09:22:14 +00:00
|
|
|
} else show = 0;
|
2009-04-02 01:23:45 +00:00
|
|
|
|
2010-04-09 11:24:40 +00:00
|
|
|
if (show) {
|
|
|
|
if( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
|
|
|
r_cons_printf(" %c %s\n", (option==i)?'>':' ', old);
|
|
|
|
j++;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
i++;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
}
|
|
|
|
if (!hit && j>0) {
|
|
|
|
option = j-1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r_cons_printf("\n Sel:%s \n\n", fs);
|
|
|
|
break;
|
|
|
|
case 1: // flag selection
|
|
|
|
r_cons_printf("\n Eval variables: (%s)\n\n", fs);
|
|
|
|
hit = 0;
|
|
|
|
j = i = 0;
|
|
|
|
// TODO: cut -d '.' -f 1 | sort | uniq !!!
|
2010-05-19 22:59:42 +00:00
|
|
|
list_for_each (pos, &(core->config->nodes)) {
|
|
|
|
RConfigNode *bt = list_entry(pos, RConfigNode, list);
|
2010-04-09 11:24:40 +00:00
|
|
|
if (option==i) {
|
|
|
|
fs2 = bt->name;
|
|
|
|
hit = 1;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
if (!r_str_ccmp(bt->name, fs, '.')) {
|
|
|
|
if( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
|
|
|
// TODO: Better align
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_printf (" %c %s = %s\n", (option==i)?'>':' ', bt->name, bt->value);
|
2010-04-09 11:24:40 +00:00
|
|
|
j++;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
i++;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
2010-04-09 11:24:40 +00:00
|
|
|
}
|
|
|
|
if (!hit && j>0) {
|
|
|
|
option = i-1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fs2 != NULL)
|
|
|
|
r_cons_printf("\n Selected: %s\n\n", fs2);
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
|
|
|
r_cons_flush();
|
|
|
|
ch = r_cons_readchar();
|
2010-01-30 13:02:53 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl(ch); // get ESC+char, return 'hjkl' char
|
2009-04-03 11:11:17 +00:00
|
|
|
|
2009-04-02 01:23:45 +00:00
|
|
|
switch(ch) {
|
2009-04-03 11:11:17 +00:00
|
|
|
case 'j':
|
|
|
|
option++;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
if (--option<0)
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'b': // back
|
|
|
|
menu = 0;
|
|
|
|
option = _option;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
if (menu<=0) return; menu--;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
case '+':
|
|
|
|
if (fs2 != NULL)
|
2010-03-07 23:18:58 +00:00
|
|
|
config_visual_hit_i (core, fs2, +1);
|
2009-04-03 11:11:17 +00:00
|
|
|
continue;
|
|
|
|
case '/':
|
|
|
|
case '-':
|
|
|
|
if (fs2 != NULL)
|
2010-03-07 23:18:58 +00:00
|
|
|
config_visual_hit_i (core, fs2, -1);
|
2009-04-03 11:11:17 +00:00
|
|
|
continue;
|
|
|
|
case 'l':
|
|
|
|
case 'e': // edit value
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n': // never happens
|
|
|
|
if (menu == 1) {
|
2009-04-02 01:23:45 +00:00
|
|
|
if (fs2 != NULL)
|
2010-05-19 22:59:42 +00:00
|
|
|
config_visual_hit (core, fs2);
|
2009-04-03 11:11:17 +00:00
|
|
|
} else {
|
2010-05-19 22:59:42 +00:00
|
|
|
r_flag_space_set (core->flags, fs);
|
2009-04-03 11:11:17 +00:00
|
|
|
menu = 1;
|
|
|
|
_option = option;
|
|
|
|
option = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
r_cons_clear00();
|
|
|
|
r_cons_printf("\nVe: Visual Eval help:\n\n");
|
|
|
|
r_cons_printf(" q - quit menu\n");
|
|
|
|
r_cons_printf(" j/k - down/up keys\n");
|
|
|
|
r_cons_printf(" h/b - go back\n");
|
|
|
|
r_cons_printf(" e/' ' - edit/toggle current variable\n");
|
|
|
|
r_cons_printf(" +/- - increase/decrease numeric value\n");
|
|
|
|
r_cons_printf(" : - enter command\n");
|
|
|
|
r_cons_flush();
|
|
|
|
r_cons_any_key();
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
r_cons_set_raw(0);
|
2009-04-02 01:23:45 +00:00
|
|
|
#if HAVE_LIB_READLINE
|
2009-04-03 11:11:17 +00:00
|
|
|
char *ptr = readline(VISUAL_PROMPT);
|
|
|
|
if (ptr) {
|
2010-07-12 19:37:40 +00:00
|
|
|
strncpy(cmd, ptr, sizeof (cmd));
|
2009-04-03 11:11:17 +00:00
|
|
|
r_core_cmd(core, cmd, 1);
|
|
|
|
free(ptr);
|
|
|
|
}
|
2009-04-02 01:23:45 +00:00
|
|
|
#else
|
2009-04-03 11:11:17 +00:00
|
|
|
cmd[0]='\0';
|
|
|
|
//dl_prompt = ":> ";
|
2010-05-19 22:59:42 +00:00
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) <0)
|
2009-04-02 01:23:45 +00:00
|
|
|
cmd[0]='\0';
|
2009-04-03 11:11:17 +00:00
|
|
|
//line[strlen(line)-1]='\0';
|
2010-05-19 22:59:42 +00:00
|
|
|
r_core_cmd (core, cmd, 1);
|
2009-04-02 01:23:45 +00:00
|
|
|
#endif
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_set_raw (1);
|
2009-04-03 11:11:17 +00:00
|
|
|
if (cmd[0])
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_any_key ();
|
2009-04-03 11:11:17 +00:00
|
|
|
//r_cons_gotoxy(0,0);
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_clear00 ();
|
2009-04-03 11:11:17 +00:00
|
|
|
continue;
|
2009-04-02 01:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 22:59:42 +00:00
|
|
|
R_API void r_core_visual_define (RCore *core) {
|
|
|
|
int ch;
|
2010-06-20 23:58:45 +00:00
|
|
|
ut64 off = core->offset;
|
|
|
|
if (core->print->cur_enabled)
|
|
|
|
off += core->print->cur;
|
|
|
|
r_cons_printf ("Define current block as:\n"
|
2010-06-21 09:55:48 +00:00
|
|
|
" d - set as data\n"
|
|
|
|
" c - set as code\n"
|
|
|
|
" s - set string\n"
|
2010-06-20 23:58:45 +00:00
|
|
|
" f - analyze function\n"
|
2010-06-21 09:55:48 +00:00
|
|
|
" u - undefine metadata here\n"
|
2010-06-20 23:58:45 +00:00
|
|
|
" q - quit/cancel operation\n"
|
|
|
|
"TODO: add support for data, string, code ..\n");
|
2010-05-19 22:59:42 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
|
2010-07-15 22:02:33 +00:00
|
|
|
// get ESC+char, return 'hjkl' char
|
|
|
|
ch = r_cons_arrow_to_hjkl (r_cons_readchar ());
|
2010-05-19 22:59:42 +00:00
|
|
|
|
2010-07-15 22:02:33 +00:00
|
|
|
switch (ch) {
|
2010-06-21 09:55:48 +00:00
|
|
|
case 's':
|
|
|
|
// detect type of string
|
|
|
|
// find EOS
|
|
|
|
// capture string value
|
2010-06-30 00:44:24 +00:00
|
|
|
r_meta_add (core->meta, R_META_STRING, off, off+core->blocksize, "");
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
|
|
|
case 'd': // TODO: check
|
2010-06-30 00:44:24 +00:00
|
|
|
r_meta_add (core->meta, R_META_DATA, off, off+core->blocksize, "");
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
|
|
|
case 'c': // TODO: check
|
2010-06-30 00:44:24 +00:00
|
|
|
r_meta_add (core->meta, R_META_CODE, off, off+core->blocksize, "");
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
2010-06-20 23:58:45 +00:00
|
|
|
case 'u':
|
|
|
|
r_meta_del (core->meta, R_META_ANY, off, 1, "");
|
|
|
|
r_flag_unset_i (core->flags, off);
|
|
|
|
break;
|
2010-05-19 22:59:42 +00:00
|
|
|
case 'f':
|
|
|
|
r_core_cmd (core, "af", 0);
|
|
|
|
r_core_cmd (core, "ab", 0);
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2009-02-09 00:54:09 +00:00
|
|
|
char buf[1024];
|
2010-06-17 15:55:39 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
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') {
|
2010-06-20 22:48:06 +00:00
|
|
|
if (core->reflines2) {
|
2010-05-19 22:59:42 +00:00
|
|
|
struct list_head *pos;
|
|
|
|
int n = ch-'0';
|
2010-06-20 22:48:06 +00:00
|
|
|
list_for_each (pos, &core->reflines2->list) {
|
2010-05-19 22:59:42 +00:00
|
|
|
RAnalRefline *r = list_entry (pos, RAnalRefline, list);
|
|
|
|
if (!--n) {
|
|
|
|
r_core_seek (core, r->to, 1);
|
|
|
|
r_io_sundo_push (core->io);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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;
|
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 ");
|
|
|
|
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0) buf[0]='\0';
|
2009-04-07 11:28:22 +00:00
|
|
|
if (buf[0]) {
|
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';
|
2009-04-07 11:28:22 +00:00
|
|
|
if (buf[0]) {
|
2010-01-12 01:12:18 +00:00
|
|
|
if (curset) r_core_seek(core, core->offset + cursor, 0);
|
2009-04-07 00:26:41 +00:00
|
|
|
r_core_cmd(core, buf, 1);
|
2010-01-12 01:12:18 +00:00
|
|
|
if (curset) r_core_seek(core, core->offset - cursor, 1);
|
2009-04-07 11:28:22 +00:00
|
|
|
}
|
2009-04-07 00:26:41 +00:00
|
|
|
r_cons_set_raw(1);
|
|
|
|
break;
|
2009-02-09 11:42:54 +00:00
|
|
|
/* select */
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'H':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (ocursor==-1) ocursor=cursor;
|
2009-02-09 11:42:54 +00:00
|
|
|
cursor--;
|
2010-02-02 10:09:52 +00:00
|
|
|
} else r_core_cmd (core, "s-2", 0);
|
2009-02-09 00:54:09 +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;
|
2009-02-09 11:42:54 +00:00
|
|
|
case 'J':
|
|
|
|
if (curset) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (ocursor==-1) ocursor = cursor;
|
2010-06-17 15:55:39 +00:00
|
|
|
cursor += 16;
|
2010-02-02 10:09:52 +00:00
|
|
|
} else r_core_cmd (core, "s++", 0);
|
2009-02-09 11:42:54 +00:00
|
|
|
break;
|
2009-03-20 21:05:12 +00:00
|
|
|
case 'g':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_core_cmd (core, "s 0", 0);
|
2009-03-20 21:05:12 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
2010-02-02 10:09:52 +00:00
|
|
|
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 11:42:54 +00:00
|
|
|
case 'K':
|
|
|
|
if (curset) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (ocursor==-1) ocursor=cursor;
|
|
|
|
cursor -= 16;
|
|
|
|
} else r_core_cmd (core, "s--", 0);
|
2009-02-09 11:42:54 +00:00
|
|
|
break;
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'L':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (ocursor==-1) ocursor=cursor;
|
2009-02-09 11:42:54 +00:00
|
|
|
cursor++;
|
2010-02-02 10:09:52 +00:00
|
|
|
} else r_core_cmd (core, "s+2", 0);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-02-09 11:42:54 +00:00
|
|
|
/* move */
|
2009-02-09 00:54:09 +00:00
|
|
|
case 'h':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
|
|
|
cursor--;
|
|
|
|
ocursor=-1;
|
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;
|
|
|
|
case 'l':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
|
|
|
cursor++;
|
|
|
|
ocursor=-1;
|
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;
|
2010-05-19 00:39:01 +00:00
|
|
|
case 'u':
|
2010-05-19 22:59:42 +00:00
|
|
|
if (r_io_sundo (core->io))
|
2010-07-12 23:00:36 +00:00
|
|
|
r_core_seek (core, core->io->off, 1);
|
2010-05-19 00:39:01 +00:00
|
|
|
break;
|
|
|
|
case 'U':
|
2010-05-19 22:59:42 +00:00
|
|
|
if (r_io_sundo_redo (core->io))
|
2010-07-12 23:00:36 +00:00
|
|
|
r_core_seek (core, core->io->off, 1);
|
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) {
|
|
|
|
cursor+=16;
|
|
|
|
ocursor=-1;
|
2010-05-19 22:59:42 +00:00
|
|
|
} else {
|
|
|
|
if (printidx==1)
|
|
|
|
r_core_cmd (core, "s+ 8", 0);
|
|
|
|
else r_core_cmd (core, "s+ 16", 0);
|
|
|
|
}
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
2009-02-09 11:42:54 +00:00
|
|
|
if (curset) {
|
|
|
|
cursor-=16;
|
|
|
|
ocursor=-1;
|
2010-07-15 22:02:33 +00:00
|
|
|
} else r_core_cmd (core, (printidx==1)?"s- 8":"s- 16", 0);
|
2009-02-09 00:54:09 +00:00
|
|
|
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':
|
|
|
|
printidx++;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
printidx--;
|
|
|
|
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':
|
|
|
|
if (core->yank) r_core_yank_paste (core, core->offset+cursor, 0);
|
|
|
|
else {
|
|
|
|
r_cons_printf ("Can't paste, clipboard is empty.\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key ();
|
|
|
|
}
|
|
|
|
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;
|
2010-08-12 13:52:07 +00:00
|
|
|
if (ocursor==-1) sprintf (buf, "woa 01 @ $$+%i:1",cursor);
|
|
|
|
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-02-03 13:34:00 +00:00
|
|
|
r_core_block_size (core, core->blocksize-16);
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
|
|
|
case '*':
|
2010-02-03 13:34:00 +00:00
|
|
|
r_core_block_size (core, core->blocksize+16);
|
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 '<':
|
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;
|
2009-02-09 00:54:09 +00:00
|
|
|
case ':':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_fgets (buf, 1023, 0, NULL);
|
|
|
|
r_core_cmd (core, buf, 0);
|
2010-08-06 15:19:09 +00:00
|
|
|
r_cons_any_key ();
|
2009-02-09 00:54:09 +00:00
|
|
|
break;
|
2009-04-06 22:53:25 +00:00
|
|
|
case ';':
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_printf ("Enter a comment: (prefix it with '-' to remove)\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
strcpy (buf, "CC ");
|
|
|
|
if (r_cons_fgets (buf+3, 1000, 0, NULL) <0)
|
2009-04-06 22:53:25 +00:00
|
|
|
buf[0]='\0';
|
2009-04-07 11:28:22 +00:00
|
|
|
if (buf[0]) {
|
2010-02-02 10:09:52 +00:00
|
|
|
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
|
|
|
}
|
2010-02-02 10:09:52 +00:00
|
|
|
r_cons_set_raw (1);
|
2009-04-06 22:53:25 +00:00
|
|
|
break;
|
2010-06-25 09:22:14 +00:00
|
|
|
case 'x':
|
|
|
|
r_core_cmdf (core, "./a 0x%08llx @ entry0", core->offset);
|
|
|
|
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"
|
2009-04-06 22:53:25 +00:00
|
|
|
" >||< - seek aligned to block size\n"
|
|
|
|
" hjkl - move around\n"
|
|
|
|
" HJKL - move around faster\n"
|
2010-05-24 17:38:13 +00:00
|
|
|
" pP - rotate print modes\n"
|
2009-04-06 22:53:25 +00:00
|
|
|
" /*+- - change block size\n"
|
2010-02-02 10:09:52 +00:00
|
|
|
" cC - toggle cursor and colors\n"
|
2010-05-24 17:38:13 +00:00
|
|
|
" d[f?] - define function, data, code, ..\n"
|
2010-06-25 09:22:14 +00:00
|
|
|
" x - find xrefs for current offset\n"
|
2010-05-24 17:38:13 +00:00
|
|
|
" sS - step / step over\n"
|
2010-05-19 00:39:01 +00:00
|
|
|
" uU - undo/redo seek\n"
|
2010-08-12 13:52:07 +00:00
|
|
|
" yY - copy and paste selection\n"
|
2010-05-19 00:39:01 +00:00
|
|
|
" mK/'K - mark/go to Key (any key)\n"
|
2009-04-06 22:53:25 +00:00
|
|
|
" :cmd - run radare command\n"
|
|
|
|
" ;[-]cmt - add/remove comment\n"
|
2010-05-24 17:38:13 +00:00
|
|
|
" . - seek to program counter\n"
|
2009-04-06 22:53:25 +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..
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API void r_core_visual_prompt(RCore *core, int color) {
|
2010-07-16 09:28:16 +00:00
|
|
|
if (cursor<0) cursor = 0;
|
|
|
|
if (color) r_cons_strcat (Color_YELLOW);
|
|
|
|
if (curset) r_cons_printf ("[0x%08"PFMT64x"(%d:%d=%d)]> %s\n", core->offset,
|
|
|
|
cursor, ocursor, ocursor==-1?1:R_ABS (cursor-ocursor)+1, printfmt[R_ABS (printidx%NPF)]);
|
2010-05-24 17:38:13 +00:00
|
|
|
else r_cons_printf ("[0x%08"PFMT64x"]> %s\n", core->offset, printfmt[R_ABS (printidx%NPF)]);
|
2010-07-16 09:28:16 +00:00
|
|
|
if (color) r_cons_strcat (Color_RESET);
|
2009-02-09 11:42:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_visual(RCore *core, const char *input) {
|
2009-03-27 00:16:27 +00:00
|
|
|
const char *cmdprompt;
|
|
|
|
const char *vi;
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 scrseek;
|
2009-02-09 00:54:09 +00:00
|
|
|
int ch;
|
|
|
|
|
2010-06-20 23:58:45 +00:00
|
|
|
core->print->cur_enabled = R_FALSE;
|
2010-05-19 22:59:42 +00:00
|
|
|
vi = r_config_get (core->config, "cmd.vprompt");
|
2010-03-08 11:45:22 +00:00
|
|
|
if (vi) r_core_cmd (core, vi, 0);
|
2009-03-12 02:03:18 +00:00
|
|
|
|
2010-02-02 10:09:52 +00:00
|
|
|
while (input[0]) {
|
|
|
|
if (!r_core_visual_cmd (core, input[0])) {
|
|
|
|
r_cons_clear00 ();
|
2010-04-14 20:55:28 +00:00
|
|
|
r_core_cmd (core, printfmt[R_ABS (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 ();
|
2009-02-09 00:54:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
input = input + 1;
|
|
|
|
}
|
|
|
|
|
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"));
|
2009-03-27 00:16:27 +00:00
|
|
|
if (scrseek != 0LL) {
|
2009-04-07 11:28:22 +00:00
|
|
|
r_core_seek (core, scrseek, 1);
|
2009-03-27 00:16:27 +00:00
|
|
|
// TODO: read?
|
|
|
|
}
|
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);
|
|
|
|
r_cons_clear00 ();
|
2010-05-19 22:59:42 +00:00
|
|
|
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
2010-02-28 22:57:55 +00:00
|
|
|
r_core_visual_prompt (core, color);
|
2010-04-14 20:55:28 +00:00
|
|
|
r_core_cmd (core, printfmt[R_ABS (printidx%NPF)], 0);
|
2010-02-28 22:57:55 +00:00
|
|
|
r_cons_visual_flush ();
|
|
|
|
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;
|
2009-02-18 00:43:57 +00:00
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|