2016-04-27 22:15:12 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
2012-01-31 01:45:17 +00:00
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
#include "r_core.h"
|
|
|
|
|
2015-10-14 21:50:16 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-09-23 22:43:31 +00:00
|
|
|
#define MAX_FORMAT 3
|
2012-09-28 00:20:52 +00:00
|
|
|
|
2016-02-13 19:37:18 +00:00
|
|
|
enum {
|
|
|
|
R_BYTE_DATA = 1,
|
|
|
|
R_WORD_DATA = 2,
|
|
|
|
R_DWORD_DATA = 4,
|
|
|
|
R_QWORD_DATA = 8
|
|
|
|
};
|
|
|
|
|
2015-09-14 14:22:57 +00:00
|
|
|
typedef struct {
|
|
|
|
RCore *core;
|
|
|
|
int t_idx;
|
|
|
|
int t_ctr;
|
|
|
|
const char *type;
|
|
|
|
char *curname;
|
|
|
|
char *curfmt;
|
|
|
|
const char *optword;
|
|
|
|
} RCoreVisualTypes;
|
|
|
|
|
2015-03-17 00:29:28 +00:00
|
|
|
// TODO: move this helper into r_cons
|
|
|
|
static char *prompt(const char *str, const char *txt) {
|
|
|
|
char cmd[1024];
|
|
|
|
char *res = NULL;
|
2015-03-21 00:27:54 +00:00
|
|
|
char *oprompt = strdup (r_cons_singleton()->line->prompt);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2015-03-17 00:29:28 +00:00
|
|
|
if (txt && *txt) {
|
|
|
|
free (r_cons_singleton ()->line->contents);
|
|
|
|
r_cons_singleton ()->line->contents = strdup (txt);
|
|
|
|
} else {
|
|
|
|
free (r_cons_singleton ()->line->contents);
|
|
|
|
r_cons_singleton ()->line->contents = NULL;
|
|
|
|
}
|
|
|
|
*cmd = '\0';
|
|
|
|
r_line_set_prompt (str);
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) < 0) {
|
2015-03-17 00:29:28 +00:00
|
|
|
*cmd = '\0';
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
//line[strlen(line)-1]='\0';
|
2016-08-23 01:02:23 +00:00
|
|
|
if (*cmd) {
|
2015-03-17 00:29:28 +00:00
|
|
|
res = strdup (cmd);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
r_line_set_prompt (oprompt);
|
2015-03-21 00:27:54 +00:00
|
|
|
free (oprompt);
|
2015-03-17 00:29:28 +00:00
|
|
|
free (r_cons_singleton ()->line->contents);
|
|
|
|
r_cons_singleton ()->line->contents = NULL;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *getformat (RCoreVisualTypes *vt, const char *k) {
|
|
|
|
return sdb_get (vt->core->anal->sdb_types,
|
|
|
|
sdb_fmt (0, "type.%s", k), 0);
|
|
|
|
}
|
2016-09-22 10:19:21 +00:00
|
|
|
static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype) {
|
2016-09-27 16:35:49 +00:00
|
|
|
char *tmp, *spacer = NULL;
|
2016-09-22 10:19:21 +00:00
|
|
|
char *source = (char*)buf_asm;
|
|
|
|
bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
|
|
|
const char *color_num = core->cons->pal.num;
|
|
|
|
const char *color_reg = core->cons->pal.reg;
|
|
|
|
|
|
|
|
if (!use_color) {
|
|
|
|
return strdup (source);
|
|
|
|
}
|
|
|
|
// workaround dummy colorizer in case of paired commands (tms320 & friends)
|
|
|
|
spacer = strstr (source, "||");
|
|
|
|
if (spacer) {
|
|
|
|
char *scol1, *s1 = r_str_ndup (source, spacer - source);
|
|
|
|
char *scol2, *s2 = strdup (spacer + 2);
|
|
|
|
scol1 = r_print_colorize_opcode (s1, color_reg, color_num);
|
|
|
|
free (s1);
|
|
|
|
scol2 = r_print_colorize_opcode (s2, color_reg, color_num);
|
|
|
|
free (s2);
|
|
|
|
if (!scol1) {
|
|
|
|
scol1 = strdup ("");
|
|
|
|
}
|
|
|
|
if (!scol2) {
|
|
|
|
scol2 = strdup ("");
|
|
|
|
}
|
|
|
|
source = malloc (strlen(scol1) + strlen(scol2) + 2 + 1); // reuse source variable
|
|
|
|
sprintf (source, "%s||%s", scol1, scol2);
|
|
|
|
free (scol1);
|
|
|
|
free (scol2);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
char *res = strdup("");
|
|
|
|
res = r_str_concat (res, r_print_color_op_type (core->print, optype));
|
2016-09-27 16:35:49 +00:00
|
|
|
tmp = r_print_colorize_opcode (source, color_reg, color_num);
|
|
|
|
res = r_str_concat (res, tmp);
|
|
|
|
free (tmp);
|
2016-09-22 10:19:21 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rotate_nibble (const ut8 b, int dir) {
|
|
|
|
if (dir > 0) {
|
|
|
|
bool high = b >> 7;
|
|
|
|
return (b << 1) | high;
|
|
|
|
}
|
|
|
|
bool lower = b & 1;
|
|
|
|
return (b >> 1) | (lower << 7);
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
|
2016-07-05 03:25:29 +00:00
|
|
|
static bool edit_bits (RCore *core) {
|
|
|
|
const int nbits = sizeof (ut64) * 8;
|
2016-09-22 10:19:21 +00:00
|
|
|
bool colorBits = false;
|
|
|
|
int analopType;
|
2016-07-05 03:25:29 +00:00
|
|
|
int i, j, x = 0;
|
|
|
|
RAsmOp asmop;
|
2016-09-22 10:19:21 +00:00
|
|
|
RAnalOp analop;
|
2016-07-05 03:25:29 +00:00
|
|
|
ut8 buf[sizeof (ut64)];
|
|
|
|
|
|
|
|
if (core->blocksize < sizeof (ut64)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memcpy (buf, core->block, sizeof (ut64));
|
|
|
|
for (;;) {
|
|
|
|
r_cons_clear00 ();
|
2016-09-22 10:19:21 +00:00
|
|
|
bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
|
|
|
(void) r_asm_disassemble (core->assembler, &asmop, buf, sizeof (ut64));
|
|
|
|
analop.type = -1;
|
|
|
|
(void)r_anal_op (core->anal, &analop, core->offset, buf, sizeof (ut64));
|
|
|
|
analopType = analop.type & R_ANAL_OP_TYPE_MASK;
|
2016-07-05 03:25:29 +00:00
|
|
|
r_cons_printf ("r2's bit editor:\n\n");
|
2016-09-22 10:19:21 +00:00
|
|
|
{
|
|
|
|
char *res = r_print_hexpair (core->print, asmop.buf_hex, -1);
|
|
|
|
r_cons_printf ("hex: %s\n"Color_RESET, res);
|
|
|
|
free (res);
|
|
|
|
}
|
2016-07-05 03:25:29 +00:00
|
|
|
r_cons_printf ("len: %d\n", asmop.size);
|
2016-09-22 10:19:21 +00:00
|
|
|
{
|
|
|
|
char *op = colorize_asm_string (core, asmop.buf_asm, analopType);
|
|
|
|
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
|
|
|
free (op);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
r_cons_printf (Color_RESET"esl: %s\n"Color_RESET, r_strbuf_get (&analop.esil));
|
|
|
|
}
|
|
|
|
r_anal_op_fini (&analop);
|
2016-07-05 03:25:29 +00:00
|
|
|
r_cons_printf ("chr:");
|
|
|
|
for (i = 0; i < 8; i++) {
|
2016-09-22 10:19:21 +00:00
|
|
|
const ut8 *byte = buf + i;
|
|
|
|
char ch = IS_PRINTABLE (*byte)? *byte: '?';
|
|
|
|
if (use_color) {
|
|
|
|
r_cons_printf (" %5s'%s%c"Color_RESET"'", " ", core->cons->pal.btext, ch);
|
|
|
|
} else {
|
|
|
|
r_cons_printf (" %5s'%c'", " ", ch);
|
|
|
|
}
|
2016-07-05 03:25:29 +00:00
|
|
|
}
|
|
|
|
r_cons_printf ("\ndec:");
|
|
|
|
for (i = 0; i < 8; i++) {
|
2016-09-22 10:19:21 +00:00
|
|
|
const ut8 *byte = buf + i;
|
2016-07-05 03:25:29 +00:00
|
|
|
r_cons_printf (" %8d", *byte);
|
|
|
|
}
|
|
|
|
r_cons_printf ("\nhex:");
|
|
|
|
for (i = 0; i < 8; i++) {
|
2016-09-22 10:19:21 +00:00
|
|
|
const ut8 *byte = buf + i;
|
2016-07-05 03:25:29 +00:00
|
|
|
r_cons_printf (" 0x%02x", *byte);
|
|
|
|
}
|
|
|
|
r_cons_printf ("\nbit: ");
|
2016-09-22 10:19:21 +00:00
|
|
|
if (use_color) {
|
|
|
|
r_cons_print (core->cons->pal.b0x7f);
|
|
|
|
colorBits = true;
|
|
|
|
}
|
2016-07-05 03:25:29 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
ut8 *byte = buf + i;
|
2016-09-22 10:19:21 +00:00
|
|
|
if (colorBits && i >= asmop.size) {
|
|
|
|
r_cons_print (Color_RESET);
|
|
|
|
colorBits = false;
|
|
|
|
}
|
2016-07-05 03:25:29 +00:00
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
bool bit = R_BIT_CHK (byte, 7 - j);
|
|
|
|
r_cons_printf ("%d", bit? 1: 0);
|
|
|
|
}
|
|
|
|
r_cons_print (" ");
|
|
|
|
}
|
|
|
|
r_cons_newline ();
|
|
|
|
char str_pos[128];
|
|
|
|
memset (str_pos, '-', nbits + 7);
|
|
|
|
str_pos[x + (x/8)] = '^';
|
|
|
|
str_pos[nbits + 7] = 0;
|
|
|
|
str_pos[8] = ' ';
|
|
|
|
str_pos[17] = ' ';
|
|
|
|
str_pos[26] = ' ';
|
|
|
|
str_pos[35] = ' ';
|
|
|
|
str_pos[44] = ' ';
|
|
|
|
str_pos[53] = ' ';
|
|
|
|
str_pos[62] = ' ';
|
|
|
|
r_cons_printf ("pos: %s\n", str_pos);
|
|
|
|
r_cons_newline ();
|
|
|
|
r_cons_visual_flush ();
|
|
|
|
|
|
|
|
int ch = r_cons_readchar ();
|
|
|
|
if (ch == -1 || ch == 4) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
|
|
|
case 'q':
|
|
|
|
return false;
|
|
|
|
case 'j':
|
|
|
|
case 'k':
|
|
|
|
case ' ':
|
|
|
|
//togglebit();
|
|
|
|
{
|
|
|
|
const int nbyte = x / 8;
|
|
|
|
const int nbit = 7 - (x - (nbyte * 8));
|
|
|
|
ut8 *byte = buf + nbyte;
|
2016-08-23 01:02:23 +00:00
|
|
|
bool bit = R_BIT_CHK (byte, nbit);
|
2016-07-05 03:25:29 +00:00
|
|
|
if (bit) {
|
2016-08-23 01:02:23 +00:00
|
|
|
R_BIT_UNSET (byte, nbit);
|
2016-07-05 03:25:29 +00:00
|
|
|
} else {
|
2016-08-23 01:02:23 +00:00
|
|
|
R_BIT_SET (byte, nbit);
|
2016-07-05 03:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-09-22 10:19:21 +00:00
|
|
|
case '>':
|
|
|
|
buf[x/8] = rotate_nibble (buf [(x / 8)], -1);
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
buf[x/8] = rotate_nibble (buf [(x / 8)], 1);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
{
|
|
|
|
r_line_set_prompt ("> ");
|
|
|
|
const char *line = r_line_readline ();
|
|
|
|
ut64 num = r_num_math (core->num, line);
|
|
|
|
if (num || (!num && *line == '0')) {
|
|
|
|
buf[x/8] = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
if (r_config_get_i (core->config, "scr.randpal")) {
|
|
|
|
r_core_cmd0 (core, "ecr");
|
|
|
|
} else {
|
|
|
|
r_core_cmd0 (core, "ecn");
|
|
|
|
}
|
|
|
|
break;
|
2016-07-05 10:31:25 +00:00
|
|
|
case '+':
|
|
|
|
buf[(x/8)]++;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
buf[(x/8)]--;
|
|
|
|
break;
|
2016-07-05 03:25:29 +00:00
|
|
|
case 'h':
|
|
|
|
x = R_MAX (x - 1, 0);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
x = R_MIN (x + 1, nbits - 1);
|
|
|
|
break;
|
2016-09-22 10:19:21 +00:00
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
|
|
|
"Vd1?: Visual Bit Editor Help:\n\n"
|
|
|
|
" q - quit the bit editor\n"
|
|
|
|
" R - randomize color palette\n"
|
|
|
|
" j/k - toggle bit value (same as space key)\n"
|
|
|
|
" h/l - select next/previous bit\n"
|
|
|
|
" +/- - increment or decrement byte value\n"
|
|
|
|
" </> - rotate left/right byte value\n"
|
|
|
|
" i - insert numeric value of byte\n"
|
|
|
|
" : - enter command\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
break;
|
2016-07-05 03:25:29 +00:00
|
|
|
case ':': // TODO: move this into a separate helper function
|
|
|
|
{
|
|
|
|
char cmd[1024];
|
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
cmd[0]='\0';
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) < 0) {
|
|
|
|
cmd[0] = '\0';
|
|
|
|
}
|
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
r_cons_set_raw (1);
|
|
|
|
r_cons_show_cursor (false);
|
|
|
|
if (cmd[0]) {
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
}
|
|
|
|
r_cons_clear ();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-17 00:29:28 +00:00
|
|
|
// belongs to r_core_visual_types
|
|
|
|
static int sdbforcb (void *p, const char *k, const char *v) {
|
2015-03-18 03:15:00 +00:00
|
|
|
const char *pre = " ";
|
2015-03-17 00:29:28 +00:00
|
|
|
RCoreVisualTypes *vt = (RCoreVisualTypes*)p;
|
2016-09-22 10:19:21 +00:00
|
|
|
bool use_color = vt->core->print->flags & R_PRINT_FLAGS_COLOR;
|
2015-03-18 03:15:00 +00:00
|
|
|
if (vt->optword) {
|
|
|
|
if (!strcmp (vt->type, "struct")) {
|
|
|
|
char *s = r_str_newf ("struct.%s.", vt->optword);
|
|
|
|
/* enum */
|
|
|
|
if (!strncmp (s, k, strlen (s))) {
|
|
|
|
if (vt->t_idx == vt->t_ctr) {
|
|
|
|
free (vt->curname);
|
|
|
|
vt->curname = strdup (k);
|
|
|
|
free (vt->curfmt);
|
|
|
|
vt->curfmt = strdup (v);
|
|
|
|
pre = ">";
|
|
|
|
}
|
2016-04-01 16:15:35 +00:00
|
|
|
if (use_color && *pre=='>')
|
|
|
|
r_cons_printf (Color_YELLOW" %s %s %s\n"
|
|
|
|
Color_RESET, pre, k+strlen (s), v);
|
|
|
|
else
|
|
|
|
r_cons_printf (" %s %s %s\n",
|
|
|
|
pre, k+strlen (s), v);
|
2015-03-18 03:15:00 +00:00
|
|
|
vt->t_ctr ++;
|
|
|
|
}
|
|
|
|
free (s);
|
|
|
|
} else {
|
|
|
|
char *s = r_str_newf ("%s.", vt->optword);
|
|
|
|
/* enum */
|
|
|
|
if (!strncmp (s, k, strlen (s))) {
|
|
|
|
if (!strstr (k, ".0x")) {
|
|
|
|
if (vt->t_idx == vt->t_ctr) {
|
|
|
|
free (vt->curname);
|
|
|
|
vt->curname = strdup (v);
|
|
|
|
free (vt->curfmt);
|
|
|
|
vt->curfmt = strdup (v);
|
|
|
|
pre = ">";
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (use_color && *pre=='>') {
|
|
|
|
r_cons_printf (Color_YELLOW" %s %s %s\n"
|
|
|
|
Color_RESET, pre, k, v);
|
|
|
|
} else {
|
2016-04-01 16:15:35 +00:00
|
|
|
r_cons_printf (" %s %s %s\n",
|
|
|
|
pre, k, v);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-18 03:15:00 +00:00
|
|
|
vt->t_ctr ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (s);
|
|
|
|
}
|
|
|
|
} else if (!strcmp (v, vt->type)) {
|
2015-03-17 00:29:28 +00:00
|
|
|
if (!strcmp (vt->type, "type")) {
|
|
|
|
char *fmt = getformat (vt, k);
|
|
|
|
if (vt->t_idx == vt->t_ctr) {
|
|
|
|
free (vt->curname);
|
|
|
|
vt->curname = strdup (k);
|
|
|
|
free (vt->curfmt);
|
|
|
|
vt->curfmt = strdup (fmt);
|
|
|
|
pre = ">";
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (use_color && *pre=='>') {
|
2016-04-01 16:15:35 +00:00
|
|
|
r_cons_printf (Color_YELLOW" %s pf %3s %s\n"
|
|
|
|
Color_RESET,pre, fmt, k);
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
2016-04-01 16:15:35 +00:00
|
|
|
r_cons_printf (" %s pf %3s %s\n",
|
|
|
|
pre, fmt, k);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
free (fmt);
|
|
|
|
} else {
|
2015-03-18 03:15:00 +00:00
|
|
|
if (vt->t_idx == vt->t_ctr) {
|
|
|
|
free (vt->curname);
|
|
|
|
vt->curname = strdup (k);
|
|
|
|
free (vt->curfmt);
|
|
|
|
vt->curfmt = strdup (v);
|
|
|
|
pre = ">";
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (use_color && *pre == '>') {
|
2016-04-01 16:15:35 +00:00
|
|
|
r_cons_printf (Color_YELLOW" %s %s\n"Color_RESET,
|
|
|
|
(vt->t_idx == vt->t_ctr)?
|
|
|
|
">":" ", k);
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
2016-04-01 16:15:35 +00:00
|
|
|
r_cons_printf (" %s %s\n",
|
|
|
|
(vt->t_idx == vt->t_ctr)?
|
|
|
|
">":" ", k);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
}
|
|
|
|
vt->t_ctr ++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_core_visual_types(RCore *core) {
|
2015-10-23 14:55:38 +00:00
|
|
|
RCoreVisualTypes vt = {core, 0, 0};
|
2015-03-21 01:04:49 +00:00
|
|
|
int i, j, ch;
|
2015-03-17 00:29:28 +00:00
|
|
|
int _option = 0;
|
|
|
|
int option = 0;
|
|
|
|
char *txt;
|
|
|
|
char cmd[1024];
|
|
|
|
int menu = 0;
|
|
|
|
int h_opt = 0;
|
2015-03-18 03:15:00 +00:00
|
|
|
char *optword = NULL;
|
2015-03-17 00:29:28 +00:00
|
|
|
const char *opts[] = {
|
|
|
|
"type",
|
|
|
|
"enum",
|
|
|
|
"struct",
|
|
|
|
"func",
|
2016-04-01 16:15:35 +00:00
|
|
|
"union",
|
2015-03-17 00:29:28 +00:00
|
|
|
NULL
|
|
|
|
};
|
2016-08-23 01:02:23 +00:00
|
|
|
bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
|
|
|
for (j = i = 0; i < R_FLAG_SPACES_MAX; i++) {
|
|
|
|
if (core->flags->spaces[i]) {
|
2015-03-17 00:29:28 +00:00
|
|
|
j = 1;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j == 0) {
|
|
|
|
menu = 1;
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
for (;;) {
|
|
|
|
r_cons_clear00 ();
|
2016-08-23 01:02:23 +00:00
|
|
|
for (i = 0; opts[i]; i++) {
|
|
|
|
const char *fmt = use_color
|
|
|
|
? (h_opt == i)
|
|
|
|
? Color_BGREEN"[%s] "Color_RESET
|
|
|
|
: Color_GREEN" %s "Color_RESET
|
|
|
|
: (h_opt == i)
|
|
|
|
? "[%s] "
|
|
|
|
: " %s ";
|
2015-03-17 00:29:28 +00:00
|
|
|
r_cons_printf (fmt, opts[i]);
|
|
|
|
}
|
|
|
|
r_cons_newline ();
|
2015-03-18 03:15:00 +00:00
|
|
|
if (optword) {
|
|
|
|
r_cons_printf (">> %s\n", optword);
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
vt.t_idx = option;
|
|
|
|
vt.t_ctr = 0;
|
|
|
|
vt.type = opts[h_opt];
|
2015-03-18 03:15:00 +00:00
|
|
|
vt.optword = optword;
|
2015-03-17 00:29:28 +00:00
|
|
|
sdb_foreach (core->anal->sdb_types, sdbforcb, &vt);
|
|
|
|
|
|
|
|
r_cons_visual_flush ();
|
|
|
|
ch = r_cons_readchar ();
|
2016-08-23 01:02:23 +00:00
|
|
|
if (ch == -1 || ch == 4) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
|
|
|
case 'h':
|
|
|
|
h_opt--;
|
|
|
|
if (h_opt<0)
|
|
|
|
h_opt = 0;
|
2015-03-18 03:15:00 +00:00
|
|
|
option = 0;
|
|
|
|
R_FREE (optword);
|
2015-03-17 00:29:28 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
h_opt++;
|
2015-03-18 03:15:00 +00:00
|
|
|
option = 0;
|
2015-03-17 00:29:28 +00:00
|
|
|
if (!opts[h_opt])
|
|
|
|
h_opt--;
|
2015-03-18 03:15:00 +00:00
|
|
|
R_FREE (optword);
|
2015-03-17 00:29:28 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
{
|
|
|
|
char *file = prompt ("Filename: ", NULL);
|
|
|
|
if (file) {
|
|
|
|
r_core_cmdf (core, "\"to %s\"", file);
|
|
|
|
free (file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-04-01 16:15:35 +00:00
|
|
|
case 'j':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (++option >= vt.t_ctr) {
|
|
|
|
option = vt.t_ctr - 1;
|
|
|
|
}
|
2016-04-01 16:15:35 +00:00
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
option += 10;
|
2016-08-23 01:02:23 +00:00
|
|
|
if (option >= vt.t_ctr) {
|
2016-04-01 16:15:35 +00:00
|
|
|
option = vt.t_ctr-1;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
if (--option < 0) {
|
|
|
|
option = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
option -= 10;
|
|
|
|
if (option < 0) {
|
|
|
|
option = 0;
|
|
|
|
}
|
2016-04-01 16:15:35 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
2016-08-23 01:02:23 +00:00
|
|
|
r_core_cmdf (core, "tl %s", vt.curname);
|
|
|
|
break;
|
2015-03-23 15:18:35 +00:00
|
|
|
case -1: // EOF
|
2015-03-17 00:29:28 +00:00
|
|
|
case 'q':
|
2016-01-13 14:59:31 +00:00
|
|
|
if (optword) {
|
|
|
|
R_FREE (optword);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (menu <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-05 22:33:11 +00:00
|
|
|
menu--;
|
2015-03-17 00:29:28 +00:00
|
|
|
option = _option;
|
|
|
|
if (menu==0) {
|
|
|
|
// if no flagspaces, just quit
|
2016-08-23 01:02:23 +00:00
|
|
|
for (j = i = 0; i < R_FLAG_SPACES_MAX; i++) {
|
|
|
|
if (core->flags->spaces[i]) {
|
2015-03-17 00:29:28 +00:00
|
|
|
j = 1;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!j) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
{
|
|
|
|
txt = prompt ("add C type: ", NULL);
|
|
|
|
if (txt) {
|
|
|
|
r_core_cmdf (core, "\"td %s\"", txt);
|
|
|
|
free (txt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2016-04-01 16:15:35 +00:00
|
|
|
r_core_cmdf (core, "t- %s", vt.curname);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
r_core_cmd0 (core, "to -");
|
2015-03-17 00:29:28 +00:00
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
case 'e':
|
2015-03-18 03:15:00 +00:00
|
|
|
if (optword) {
|
|
|
|
/* TODO: edit field */
|
|
|
|
} else {
|
|
|
|
switch (h_opt) {
|
|
|
|
case 0: // type
|
|
|
|
/* TODO: do something with this data */
|
|
|
|
prompt ("name: ", vt.curname);
|
|
|
|
prompt ("pf: ", vt.curfmt);
|
|
|
|
break;
|
|
|
|
case 1: // enum
|
|
|
|
case 2: // struct
|
|
|
|
free (optword);
|
|
|
|
optword = strdup (vt.curname);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
|
|
|
"Vt?: Visual Types Help:\n\n"
|
|
|
|
" q - quit menu\n"
|
|
|
|
" j/k - down/up keys\n"
|
|
|
|
" h/l - left-right\n"
|
|
|
|
" a - add new type (C syntax)\n"
|
2016-04-01 16:15:35 +00:00
|
|
|
" b - bind type to current offset\n"
|
2015-03-17 00:29:28 +00:00
|
|
|
" d - delete current type\n"
|
|
|
|
" e - edit current type\n"
|
|
|
|
" o - open .h include file\n"
|
2016-04-01 16:15:35 +00:00
|
|
|
" - - Open cfg.editor to load types\n"
|
2015-03-17 00:29:28 +00:00
|
|
|
" : - enter command\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
break;
|
|
|
|
case ':':
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2015-03-17 00:29:28 +00:00
|
|
|
r_cons_set_raw (0);
|
|
|
|
cmd[0]='\0';
|
|
|
|
r_line_set_prompt (":> ");
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) < 0) {
|
2015-03-17 00:29:28 +00:00
|
|
|
cmd[0]='\0';
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2016-07-05 03:25:29 +00:00
|
|
|
if (cmd[0]) {
|
2015-03-17 00:29:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2016-07-05 03:25:29 +00:00
|
|
|
}
|
2015-03-17 00:29:28 +00:00
|
|
|
r_cons_clear ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2015-03-17 00:29:28 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 12:01:07 +00:00
|
|
|
static int cmtcb(void *usr, const char *k, const char *v) {
|
|
|
|
if (!strncmp (k, "meta.C.", 7)) {
|
|
|
|
RList *list = (RList*)usr;
|
|
|
|
char *msg, *comma = strchr (v, ',');
|
|
|
|
if (comma) {
|
2016-08-14 23:02:05 +00:00
|
|
|
comma = strchr (comma + 1, ',');
|
2015-10-08 12:01:07 +00:00
|
|
|
if (comma) {
|
2016-08-14 23:02:05 +00:00
|
|
|
msg = (char *)sdb_decode (comma + 1, NULL);
|
2015-10-08 12:01:07 +00:00
|
|
|
if (msg) {
|
|
|
|
msg = r_str_replace (msg, "\n", "", true);
|
|
|
|
r_list_append (list, r_str_newf ("%s %s", k+7, msg));
|
|
|
|
free (msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_core_visual_hudstuff(RCore *core) {
|
|
|
|
RListIter *iter;
|
|
|
|
RFlagItem *flag;
|
|
|
|
ut64 addr;
|
|
|
|
char *res;
|
|
|
|
RList *list = r_list_new ();
|
2016-08-23 01:02:23 +00:00
|
|
|
if (!list) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-08 12:01:07 +00:00
|
|
|
list->free = free;
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
r_list_append (list, r_str_newf ("0x%08"PFMT64x" %s",
|
|
|
|
flag->offset, flag->name));
|
|
|
|
}
|
|
|
|
sdb_foreach (core->anal->sdb_meta, cmtcb, list);
|
2016-04-24 16:53:36 +00:00
|
|
|
res = r_cons_hud (list, NULL, r_config_get_i (core->config, "scr.color"));
|
2015-10-08 12:01:07 +00:00
|
|
|
if (res) {
|
|
|
|
char *p = strchr (res, ' ');
|
2016-08-23 01:02:23 +00:00
|
|
|
if (p) {
|
|
|
|
*p = 0;
|
|
|
|
}
|
2015-10-08 12:01:07 +00:00
|
|
|
addr = r_num_get (NULL, res);
|
|
|
|
r_core_seek (core, addr, true);
|
|
|
|
free (res);
|
|
|
|
}
|
|
|
|
r_list_free (list);
|
|
|
|
return res? true: false;
|
|
|
|
}
|
|
|
|
|
2015-10-23 14:55:38 +00:00
|
|
|
static bool r_core_visual_config_hud(RCore *core) {
|
|
|
|
RListIter *iter;
|
|
|
|
RConfigNode *bt;
|
|
|
|
RList *list = r_list_new ();
|
2016-05-24 20:22:15 +00:00
|
|
|
if (!list) return false;
|
2015-10-23 14:55:38 +00:00
|
|
|
char *res;
|
|
|
|
list->free = free;
|
|
|
|
r_list_foreach (core->config->nodes, iter, bt) {
|
2016-06-15 19:42:03 +00:00
|
|
|
r_list_append (list, r_str_newf ("%s %s", bt->name, bt->value));
|
2015-10-23 14:55:38 +00:00
|
|
|
}
|
2016-04-24 16:53:36 +00:00
|
|
|
res = r_cons_hud (list, NULL, r_config_get_i (core->config, "scr.color"));
|
2015-10-23 14:55:38 +00:00
|
|
|
if (res) {
|
|
|
|
const char *oldvalue = NULL;
|
|
|
|
char cmd[512];
|
|
|
|
char *p = strchr (res, ' ');
|
|
|
|
if (p) *p = 0;
|
|
|
|
oldvalue = r_config_get (core->config, res);
|
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
cmd[0] = '\0';
|
|
|
|
eprintf ("set new value for %s (old=%s)\n", res, oldvalue);
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd) - 1, 0, NULL) < 0)
|
|
|
|
cmd[0]='\0';
|
|
|
|
r_config_set (core->config, res, cmd);
|
|
|
|
r_cons_set_raw (1);
|
|
|
|
r_cons_show_cursor (false);
|
|
|
|
}
|
|
|
|
r_list_free (list);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-12 14:11:19 +00:00
|
|
|
// TODO: skip N first elements
|
|
|
|
// TODO: show only N elements of the list
|
|
|
|
// TODO: wrap index when out of boundaries
|
|
|
|
// TODO: Add support to show class fields too
|
2016-04-27 23:24:49 +00:00
|
|
|
static void *show_class(RCore *core, int mode, int idx, RBinClass *_c, const char *grep) {
|
|
|
|
bool show_color = r_config_get_i (core->config, "scr.color");
|
2015-10-12 14:11:19 +00:00
|
|
|
RListIter *iter;
|
|
|
|
RBinClass *c, *cur = NULL;
|
|
|
|
RBinSymbol *m, *mur = NULL;
|
|
|
|
RList *list;
|
|
|
|
int i = 0;
|
2016-04-27 22:15:12 +00:00
|
|
|
int skip = idx - 10;
|
2015-10-12 14:11:19 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case 'c':
|
2016-04-27 23:24:49 +00:00
|
|
|
r_cons_printf ("Classes:\n\n");
|
2015-10-12 14:11:19 +00:00
|
|
|
list = r_bin_get_classes (core->bin);
|
|
|
|
r_list_foreach (list, iter, c) {
|
2016-04-27 23:24:49 +00:00
|
|
|
if (grep) {
|
|
|
|
if (!r_str_casestr (c->name, grep)) {
|
2016-04-27 22:15:12 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-27 23:24:49 +00:00
|
|
|
} else {
|
|
|
|
if (idx > 10) {
|
|
|
|
skip--;
|
|
|
|
if (skip > 0) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 22:15:12 +00:00
|
|
|
}
|
2016-04-27 23:24:49 +00:00
|
|
|
if (show_color) {
|
|
|
|
if (i == idx) {
|
|
|
|
const char *clr = Color_BLUE;
|
|
|
|
r_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08"
|
|
|
|
PFMT64x Color_YELLOW " %s\n" Color_RESET,
|
|
|
|
i, clr, c->addr, c->name);
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s\n",
|
|
|
|
i, core->cons->pal.offset, c->addr, c->name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("%s %02d 0x%08"PFMT64x" %s\n",
|
|
|
|
(i==idx)?">>":"- ", i, c->addr, c->name);
|
|
|
|
}
|
|
|
|
if (i++ == idx) {
|
2015-10-12 14:11:19 +00:00
|
|
|
cur = c;
|
2016-04-27 23:24:49 +00:00
|
|
|
}
|
2015-10-12 14:11:19 +00:00
|
|
|
}
|
|
|
|
return cur;
|
|
|
|
case 'f':
|
|
|
|
// show fields
|
2016-04-27 23:24:49 +00:00
|
|
|
r_cons_printf ("Fields:\n\n");
|
2015-10-12 14:11:19 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
// show methods
|
2016-08-23 01:02:23 +00:00
|
|
|
if (!_c) {
|
|
|
|
eprintf ("No class defined\n");
|
|
|
|
return mur;
|
|
|
|
}
|
|
|
|
r_cons_printf ("MethodsFor: %s\n\n", _c->name);
|
|
|
|
r_list_foreach (_c->methods, iter, m) {
|
|
|
|
if (grep) {
|
|
|
|
if (!r_str_casestr (m->name, grep)) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (idx > 10) {
|
|
|
|
skip--;
|
|
|
|
if (skip > 0) {
|
2016-04-27 23:24:49 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
if (show_color) {
|
|
|
|
if (i == idx) {
|
|
|
|
const char *clr = Color_BLUE;
|
|
|
|
r_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08"
|
|
|
|
PFMT64x Color_YELLOW " %s\n" Color_RESET,
|
|
|
|
i, clr, m->vaddr, m->name);
|
2016-04-27 23:24:49 +00:00
|
|
|
} else {
|
2016-08-23 01:02:23 +00:00
|
|
|
r_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s\n",
|
|
|
|
i, core->cons->pal.offset, m->vaddr, m->name);
|
2016-04-27 23:24:49 +00:00
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
|
|
|
r_cons_printf ("%s %02d 0x%08"PFMT64x" %s\n",
|
|
|
|
(i==idx)? ">>": "- ", i, m->vaddr, m->name);
|
|
|
|
}
|
|
|
|
if (i++ == idx) {
|
|
|
|
mur = m;
|
2015-10-12 14:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mur;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_core_visual_classes(RCore *core) {
|
|
|
|
int ch, option = 0;
|
|
|
|
char cmd[1024];
|
|
|
|
int mode = 'c';
|
|
|
|
RBinClass *cur = NULL;
|
|
|
|
RBinSymbol *mur = NULL;
|
|
|
|
void *ptr;
|
2016-04-27 22:15:12 +00:00
|
|
|
int oldcur = 0;
|
2016-04-27 23:24:49 +00:00
|
|
|
char *grep = NULL;
|
|
|
|
bool grepmode = false;
|
2015-10-12 14:11:19 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2016-04-27 23:24:49 +00:00
|
|
|
int cols;
|
2015-10-12 14:11:19 +00:00
|
|
|
r_cons_clear00 ();
|
2016-04-27 23:24:49 +00:00
|
|
|
if (grepmode) {
|
|
|
|
r_cons_printf ("Grep: %s\n", grep? grep: "");
|
|
|
|
}
|
|
|
|
ptr = show_class (core, mode, option, cur, grep);
|
2015-10-12 14:11:19 +00:00
|
|
|
switch (mode) {
|
|
|
|
case 'm':
|
|
|
|
mur = (RBinSymbol*)ptr;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cur = (RBinClass*)ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-27 23:24:49 +00:00
|
|
|
/* update terminal size */
|
|
|
|
(void) r_cons_get_size (&cols);
|
2015-10-12 14:11:19 +00:00
|
|
|
r_cons_visual_flush ();
|
|
|
|
ch = r_cons_readchar ();
|
2016-04-27 22:15:12 +00:00
|
|
|
if (ch==-1 || ch==4) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-27 23:24:49 +00:00
|
|
|
|
|
|
|
if (grepmode) {
|
|
|
|
switch (ch) {
|
|
|
|
case 127:
|
|
|
|
if (grep) {
|
|
|
|
int len = strlen (grep);
|
|
|
|
if (len < 1) {
|
|
|
|
grepmode = false;
|
|
|
|
} else {
|
|
|
|
grep[len - 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
R_FREE (grep);
|
|
|
|
grepmode = false;
|
|
|
|
break;
|
|
|
|
default:
|
2016-08-23 01:02:23 +00:00
|
|
|
grep = grep
|
|
|
|
? r_str_concatf (grep, "%c", ch)
|
|
|
|
: r_str_newf ("%c", ch);
|
2016-04-27 23:24:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-10-12 14:11:19 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
|
|
|
case 'C':
|
|
|
|
r_config_toggle (core->config, "scr.color");
|
|
|
|
break;
|
|
|
|
case 'J': option += 10; break;
|
|
|
|
case 'j': option++; break;
|
2016-04-27 22:15:12 +00:00
|
|
|
case 'k': if (--option < 0) option = 0; break;
|
|
|
|
case 'K': option -= 10; if (option<0) option = 0; break;
|
2016-04-27 23:24:49 +00:00
|
|
|
case 'g':
|
|
|
|
{
|
|
|
|
char *num = prompt ("Index:", NULL);
|
|
|
|
option = atoi (num);
|
|
|
|
free (num);
|
|
|
|
}
|
|
|
|
break;
|
2016-04-28 01:17:16 +00:00
|
|
|
case 'p':
|
|
|
|
if (mode == 'm' && mur) {
|
|
|
|
r_core_seek (core, mur->vaddr, true);
|
|
|
|
r_core_cmd0 (core, "af;pdf~..");
|
|
|
|
}
|
|
|
|
break;
|
2015-10-12 14:11:19 +00:00
|
|
|
case 'h':
|
2016-04-27 23:24:49 +00:00
|
|
|
case 127: // backspace
|
2015-10-12 14:11:19 +00:00
|
|
|
case 'b': // back
|
|
|
|
case 'q':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (mode == 'c') {
|
2015-10-12 14:11:19 +00:00
|
|
|
return true;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-10-12 14:11:19 +00:00
|
|
|
mode = 'c';
|
2016-04-27 22:15:12 +00:00
|
|
|
option = oldcur;
|
2015-10-12 14:11:19 +00:00
|
|
|
break;
|
|
|
|
case '/':
|
2016-04-27 23:24:49 +00:00
|
|
|
grepmode = true;
|
2015-10-12 14:11:19 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
if (mur && mode == 'm') {
|
|
|
|
r_core_seek (core, mur->vaddr, true);
|
|
|
|
return true;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
if (cur) {
|
|
|
|
oldcur = option;
|
|
|
|
option = 0;
|
|
|
|
mode = 'm';
|
2015-10-12 14:11:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
|
|
|
"\nVF: Visual Classes help:\n\n"
|
|
|
|
" q - quit menu\n"
|
|
|
|
" j/k - down/up keys\n"
|
|
|
|
" h/b - go back\n"
|
2016-04-27 23:24:49 +00:00
|
|
|
" / - grep mode\n"
|
2015-10-12 14:11:19 +00:00
|
|
|
" C - toggle colors\n"
|
|
|
|
" l/' ' - accept current selection\n"
|
2016-04-28 01:17:16 +00:00
|
|
|
" p - preview method disasm with less\n"
|
2015-10-12 14:11:19 +00:00
|
|
|
" : - enter command\n");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_cons_set_raw (0);
|
2016-08-23 01:02:23 +00:00
|
|
|
cmd[0] = '\0';
|
2015-10-12 14:11:19 +00:00
|
|
|
r_line_set_prompt (":> ");
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) < 0) {
|
2015-10-12 14:11:19 +00:00
|
|
|
cmd[0]='\0';
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-10-12 14:11:19 +00:00
|
|
|
//line[strlen(line)-1]='\0';
|
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
r_cons_set_raw (1);
|
|
|
|
r_cons_show_cursor (false);
|
2016-08-23 01:02:23 +00:00
|
|
|
if (cmd[0]) {
|
2015-10-12 14:11:19 +00:00
|
|
|
r_cons_any_key (NULL);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2015-10-12 14:11:19 +00:00
|
|
|
//cons_gotoxy(0,0);
|
|
|
|
r_cons_clear ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
R_API int r_core_visual_trackflags(RCore *core) {
|
2013-09-23 22:43:31 +00:00
|
|
|
const char *fs = NULL, *fs2 = NULL;
|
|
|
|
int hit, i, j, ch;
|
2011-06-04 01:14:04 +00:00
|
|
|
RListIter *iter;
|
|
|
|
RFlagItem *flag;
|
|
|
|
int _option = 0;
|
2013-09-23 22:43:31 +00:00
|
|
|
int option = 0;
|
|
|
|
char cmd[1024];
|
|
|
|
int format = 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
int delta = 7;
|
|
|
|
int menu = 0;
|
|
|
|
|
2013-09-23 22:43:31 +00:00
|
|
|
for (j=i=0; i<R_FLAG_SPACES_MAX; i++)
|
2013-09-21 15:50:09 +00:00
|
|
|
if (core->flags->spaces[i])
|
|
|
|
j = 1;
|
|
|
|
if (j==0) menu = 1;
|
2011-06-04 01:14:04 +00:00
|
|
|
for (;;) {
|
2014-09-12 17:25:42 +00:00
|
|
|
r_cons_clear00 ();
|
2011-06-04 01:14:04 +00:00
|
|
|
|
|
|
|
if (menu) {
|
2015-07-13 21:04:34 +00:00
|
|
|
r_cons_printf ("Flags in flagspace '%s'. Press '?' for help.\n\n",
|
2011-06-04 01:14:04 +00:00
|
|
|
(core->flags->space_idx==-1)?"*":core->flags->spaces[core->flags->space_idx]);
|
|
|
|
hit = 0;
|
|
|
|
i = j = 0;
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
/* filter per flag spaces */
|
2012-07-22 08:00:35 +00:00
|
|
|
if ((core->flags->space_idx != -1) &&
|
2016-08-23 01:02:23 +00:00
|
|
|
(flag->space != core->flags->space_idx)) {
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
if (option == i) {
|
2011-06-04 01:14:04 +00:00
|
|
|
fs2 = flag->name;
|
|
|
|
hit = 1;
|
|
|
|
}
|
|
|
|
if ((i>=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
|
|
|
r_cons_printf (" %c %03d 0x%08"PFMT64x" %4"PFMT64d" %s\n",
|
|
|
|
(option==i)?'>':' ',
|
|
|
|
i, flag->offset, flag->size, flag->name);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (!hit && i > 0) {
|
|
|
|
option = i - 1;
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-21 15:50:09 +00:00
|
|
|
if (fs2) {
|
2015-03-24 02:23:56 +00:00
|
|
|
int cols, rows = r_cons_get_size (&cols);
|
|
|
|
//int rows = 20;
|
|
|
|
rows -= 12;
|
2013-09-21 15:50:09 +00:00
|
|
|
r_cons_printf ("\n Selected: %s\n\n", fs2);
|
2013-09-23 22:43:31 +00:00
|
|
|
// Honor MAX_FORMATS here
|
2013-09-21 15:50:09 +00:00
|
|
|
switch (format) {
|
2015-03-24 02:23:56 +00:00
|
|
|
case 0: snprintf (cmd, sizeof (cmd), "px %d @ %s!64", rows*16, fs2); core->printidx = 0; break;
|
|
|
|
case 1: snprintf (cmd, sizeof (cmd), "pd %d @ %s!64", rows, fs2); core->printidx = 1; break;
|
2013-09-23 22:43:31 +00:00
|
|
|
case 2: snprintf (cmd, sizeof (cmd), "ps @ %s!64", fs2); core->printidx = 5; break;
|
|
|
|
case 3: strcpy (cmd, "f="); break;
|
2013-09-21 15:50:09 +00:00
|
|
|
default: format = 0; continue;
|
|
|
|
}
|
|
|
|
if (*cmd) r_core_cmd (core, cmd, 0);
|
2013-09-23 22:43:31 +00:00
|
|
|
} else r_cons_printf ("(no flags)\n");
|
2011-06-04 01:14:04 +00:00
|
|
|
} else {
|
2015-07-13 21:04:34 +00:00
|
|
|
r_cons_printf ("Flag spaces:\n\n");
|
2011-06-04 01:14:04 +00:00
|
|
|
hit = 0;
|
|
|
|
for (j=i=0;i<R_FLAG_SPACES_MAX;i++) {
|
|
|
|
if (core->flags->spaces[i]) {
|
2016-08-23 01:02:23 +00:00
|
|
|
if (option == i) {
|
2011-06-04 01:14:04 +00:00
|
|
|
fs = core->flags->spaces[i];
|
|
|
|
hit = 1;
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if ((i >= option - delta) && ((i < option + delta)|| \
|
|
|
|
((option < delta) && (i < (delta << 1))))) {
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_printf(" %c %02d %c %s\n",
|
2012-07-22 08:00:35 +00:00
|
|
|
(option==i)?'>':' ', j,
|
2011-06-04 01:14:04 +00:00
|
|
|
(i==core->flags->space_idx)?'*':' ',
|
|
|
|
core->flags->spaces[i]);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-27 00:40:26 +00:00
|
|
|
if (core->flags->spaces[9]) {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (option == j) {
|
|
|
|
fs = "*";
|
|
|
|
hit = 1;
|
|
|
|
}
|
|
|
|
r_cons_printf (" %c %02d %c %s\n",
|
2012-07-22 08:00:35 +00:00
|
|
|
(option==j)?'>':' ', j,
|
2011-06-04 01:14:04 +00:00
|
|
|
(i==core->flags->space_idx)?'*':' ',
|
|
|
|
"*");
|
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (!hit && j > 0) {
|
|
|
|
option = j - 1;
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 03:28:34 +00:00
|
|
|
r_cons_visual_flush ();
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_readchar ();
|
2016-08-23 01:02:23 +00:00
|
|
|
if (ch == -1 || ch == 4) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
2015-03-24 02:23:56 +00:00
|
|
|
case 'C':
|
2015-09-17 18:20:51 +00:00
|
|
|
r_config_toggle (core->config, "scr.color");
|
2015-03-24 02:23:56 +00:00
|
|
|
break;
|
2015-10-08 12:01:07 +00:00
|
|
|
case '_':
|
|
|
|
if (r_core_visual_hudstuff (core))
|
|
|
|
return true;
|
|
|
|
break;
|
2013-09-23 22:43:31 +00:00
|
|
|
case 'J': option += 10; break;
|
|
|
|
case 'o': r_flag_sort (core->flags, 0); break;
|
|
|
|
case 'n': r_flag_sort (core->flags, 1); break;
|
|
|
|
case 'j': option++; break;
|
|
|
|
case 'k': if (--option<0) option = 0; break;
|
|
|
|
case 'K': option-=10; if (option<0) option = 0; break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 'h':
|
|
|
|
case 'b': // back
|
2013-04-02 20:36:07 +00:00
|
|
|
case 'q':
|
2016-06-05 22:33:11 +00:00
|
|
|
if (menu <= 0) return true;
|
|
|
|
menu--;
|
2011-06-04 01:14:04 +00:00
|
|
|
option = _option;
|
2016-08-23 01:02:23 +00:00
|
|
|
if (menu == 0) {
|
2013-09-21 15:50:09 +00:00
|
|
|
// if no flagspaces, just quit
|
2016-08-23 01:02:23 +00:00
|
|
|
for (j=i=0;i<R_FLAG_SPACES_MAX;i++) {
|
|
|
|
if (core->flags->spaces[i]) {
|
2013-09-21 15:50:09 +00:00
|
|
|
j = 1;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!j) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-21 15:50:09 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
switch (menu) {
|
|
|
|
case 0: // new flag space
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_line_set_prompt ("add flagspace: ");
|
|
|
|
strcpy (cmd, "fs ");
|
|
|
|
if (r_cons_fgets (cmd+3, sizeof (cmd)-4, 0, NULL) > 0) {
|
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // new flag
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_line_set_prompt ("add flag: ");
|
|
|
|
strcpy (cmd, "f ");
|
|
|
|
if (r_cons_fgets (cmd+2, sizeof (cmd)-3, 0, NULL) > 0) {
|
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2016-02-20 14:25:27 +00:00
|
|
|
r_flag_unset_name (core->flags, fs2);
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
/* TODO: prompt for addr, size, name */
|
|
|
|
eprintf ("TODO\n");
|
|
|
|
r_sys_sleep (1);
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
r_core_block_size (core, core->blocksize+16);
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
r_core_block_size (core, core->blocksize-16);
|
|
|
|
break;
|
2013-09-21 15:50:09 +00:00
|
|
|
case '+':
|
|
|
|
if (menu==1)
|
|
|
|
r_core_cmdf (core, "f %s=%s+1", fs2, fs2);
|
|
|
|
else r_core_block_size (core, core->blocksize+1);
|
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case '-':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (menu == 1) {
|
2013-09-21 15:50:09 +00:00
|
|
|
r_core_cmdf (core, "f %s=%s-1", fs2, fs2);
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
|
|
|
r_core_block_size (core, core->blocksize-1);
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
2014-10-21 23:01:38 +00:00
|
|
|
case 'r': // "Vtr"
|
2011-06-04 01:14:04 +00:00
|
|
|
if (menu == 1) {
|
|
|
|
int len;
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
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);
|
|
|
|
r_line_set_prompt (":> ");
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_cons_fgets (cmd + len, sizeof (cmd) - len - 1, 0, NULL) < 0) {
|
|
|
|
cmd[0] = '\0';
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-02-27 02:35:00 +00:00
|
|
|
case 'R':
|
|
|
|
if (menu == 1) {
|
|
|
|
char line[1024];
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2012-02-27 02:35:00 +00:00
|
|
|
r_cons_set_raw (0);
|
|
|
|
eprintf ("Rename function '%s' as:\n", fs2);
|
|
|
|
r_line_set_prompt (":> ");
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_cons_fgets (line, sizeof (line), 0, NULL) < 0) {
|
2012-02-27 02:35:00 +00:00
|
|
|
cmd[0]='\0';
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2012-02-27 02:35:00 +00:00
|
|
|
snprintf (cmd, sizeof (cmd), "afr %s %s", line, fs2);
|
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2012-02-27 02:35:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-09-23 22:43:31 +00:00
|
|
|
case 'P': if (--format<0) format = MAX_FORMAT; break;
|
|
|
|
// = (format<=0)? MAX_FORMAT: format-1; break;
|
|
|
|
case 'p': format++; break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 'l':
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
if (menu == 1) {
|
|
|
|
sprintf (cmd, "s %s", fs2);
|
|
|
|
r_core_cmd (core, cmd, 0);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
r_flag_space_set (core->flags, fs);
|
|
|
|
menu = 1;
|
|
|
|
_option = option;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
2015-03-17 00:29:28 +00:00
|
|
|
"\nVF: Visual Flags help:\n\n"
|
2011-06-04 01:14:04 +00:00
|
|
|
" q - quit menu\n"
|
2015-10-14 01:01:33 +00:00
|
|
|
" j/k - line down/up keys\n"
|
|
|
|
" J/K - page down/up keys\n"
|
2011-06-04 01:14:04 +00:00
|
|
|
" h/b - go back\n"
|
2015-03-24 02:23:56 +00:00
|
|
|
" C - toggle colors\n"
|
2011-06-04 01:14:04 +00:00
|
|
|
" l/' ' - accept current selection\n"
|
|
|
|
" a/d/e - add/delete/edit flag\n"
|
|
|
|
" +/- - increase/decrease block size\n"
|
|
|
|
" o - sort flags by offset\n"
|
2012-02-27 02:35:00 +00:00
|
|
|
" r/R - rename flag / Rename function\n"
|
2011-06-04 01:14:04 +00:00
|
|
|
" n - sort flags by name\n"
|
|
|
|
" p/P - rotate print format\n"
|
2015-10-08 12:01:07 +00:00
|
|
|
" _ - hud for flags and comments\n"
|
2011-06-04 01:14:04 +00:00
|
|
|
" : - enter command\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case ':':
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_set_raw (0);
|
|
|
|
cmd[0]='\0';
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) <0)
|
|
|
|
cmd[0]='\0';
|
|
|
|
//line[strlen(line)-1]='\0';
|
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
if (cmd[0])
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-06-04 01:14:04 +00:00
|
|
|
//cons_gotoxy(0,0);
|
|
|
|
r_cons_clear ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
|
2011-11-23 01:29:09 +00:00
|
|
|
R_API int r_core_visual_comments (RCore *core) {
|
2015-09-14 14:22:57 +00:00
|
|
|
#undef DB
|
|
|
|
#define DB core->anal->sdb_meta
|
|
|
|
const char *val, *comma = NULL;
|
|
|
|
char *list = sdb_get (DB, "meta.C", 0);
|
|
|
|
char *str, *next, *cur = list;
|
|
|
|
char key[128], cmd[512], *p = NULL;
|
|
|
|
int i, ch, option = 0, delta = 7;
|
|
|
|
int format = 0, found = 0;
|
|
|
|
ut64 addr, from = 0, size = 0;
|
2011-11-23 01:29:09 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2014-09-12 17:25:42 +00:00
|
|
|
r_cons_clear00 ();
|
2013-09-23 22:43:31 +00:00
|
|
|
r_cons_strcat ("Comments:\n");
|
2015-08-28 18:58:21 +00:00
|
|
|
i = 0;
|
2011-11-24 08:50:40 +00:00
|
|
|
found = 0;
|
2015-09-14 14:22:57 +00:00
|
|
|
if (list) {
|
|
|
|
for (i=0; ;i++) {
|
|
|
|
cur = sdb_anext (cur, &next);
|
|
|
|
addr = sdb_atoi (cur);
|
|
|
|
snprintf (key, sizeof (key)-1, "meta.C.0x%08"PFMT64x, addr);
|
|
|
|
val = sdb_const_get (DB, key, 0);
|
|
|
|
if (val)
|
|
|
|
comma = strchr (val, ',');
|
|
|
|
if (comma) {
|
|
|
|
str = (char *)sdb_decode (comma+1, 0);
|
|
|
|
if ((i>=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
|
|
|
r_str_sanitize (str);
|
|
|
|
if (option==i) {
|
|
|
|
found = 1;
|
|
|
|
from = addr;
|
|
|
|
size = 1; // XXX: remove this thing size for comments is useless d->size;
|
|
|
|
free (p);
|
|
|
|
p = str;
|
|
|
|
r_cons_printf (" > %s\n", str);
|
|
|
|
} else {
|
|
|
|
r_cons_printf (" %s\n", str);
|
|
|
|
free (str);
|
2014-03-12 01:44:49 +00:00
|
|
|
}
|
2015-09-14 14:22:57 +00:00
|
|
|
} else free (str);
|
2011-11-23 01:29:09 +00:00
|
|
|
}
|
2015-09-14 14:22:57 +00:00
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
cur = next;
|
|
|
|
}
|
|
|
|
}
|
2014-05-03 00:11:05 +00:00
|
|
|
|
2011-11-24 08:50:40 +00:00
|
|
|
if (!found) {
|
2016-08-23 01:02:23 +00:00
|
|
|
if (--option < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2011-11-24 08:50:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-16 01:24:47 +00:00
|
|
|
r_cons_newline ();
|
2011-11-23 01:29:09 +00:00
|
|
|
|
|
|
|
switch (format) {
|
2012-06-26 13:21:48 +00:00
|
|
|
case 0: sprintf (cmd, "px @ 0x%"PFMT64x":64", from); core->printidx = 0; break;
|
|
|
|
case 1: sprintf (cmd, "pd 12 @ 0x%"PFMT64x":64", from); core->printidx = 1; break;
|
|
|
|
case 2: sprintf (cmd, "ps @ 0x%"PFMT64x":64", from); core->printidx = 5; break;
|
|
|
|
default: format = 0; continue;
|
2011-11-23 01:29:09 +00:00
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
if (*cmd) {
|
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
}
|
2013-04-01 03:28:34 +00:00
|
|
|
r_cons_visual_flush ();
|
2011-11-23 01:29:09 +00:00
|
|
|
ch = r_cons_readchar ();
|
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
//TODO
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
//TODO
|
|
|
|
break;
|
|
|
|
case 'd':
|
2015-02-17 23:28:53 +00:00
|
|
|
if (p)
|
|
|
|
r_meta_del (core->anal, R_META_TYPE_ANY, from, size, p);
|
2011-11-23 01:29:09 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
if (--format<0)
|
|
|
|
format = MAX_FORMAT;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
format++;
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
option += 10;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
option++;
|
|
|
|
break;
|
|
|
|
case 'k':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (--option < 0) {
|
2011-11-23 01:29:09 +00:00
|
|
|
option = 0;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2011-11-23 01:29:09 +00:00
|
|
|
break;
|
|
|
|
case 'K':
|
2016-08-23 01:02:23 +00:00
|
|
|
option -= 10;
|
|
|
|
if (option < 0) {
|
2011-11-23 01:29:09 +00:00
|
|
|
option = 0;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2011-11-23 01:29:09 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
2016-08-23 01:02:23 +00:00
|
|
|
r_core_cmdf (core, "s 0x%"PFMT64x, from);
|
|
|
|
R_FREE (p);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2011-11-23 01:29:09 +00:00
|
|
|
case 'q':
|
2016-08-23 01:02:23 +00:00
|
|
|
R_FREE (p);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2011-11-24 08:50:40 +00:00
|
|
|
case '?':
|
2011-11-23 01:29:09 +00:00
|
|
|
case 'h':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf (
|
|
|
|
"\nVT: Visual Comments/Anal 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 comment/anal symbol\n"
|
|
|
|
" p/P - rotate print format\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-11-23 01:29:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p) {
|
2016-08-23 01:02:23 +00:00
|
|
|
R_FREE (p);
|
2011-11-23 01:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2011-11-23 01:29:09 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
static void config_visual_hit_i(RCore *core, const char *name, int delta) {
|
|
|
|
struct r_config_node_t *node;
|
|
|
|
node = r_config_node_get (core->config, name);
|
2016-08-23 01:02:23 +00:00
|
|
|
if (node && ((node->flags & CN_INT) || (node->flags & CN_OFFT))) {
|
2011-06-04 01:14:04 +00:00
|
|
|
r_config_set_i(core->config, name, r_config_get_i(core->config, name)+delta);
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Visually activate the config variable */
|
|
|
|
static void config_visual_hit(RCore *core, const char *name, int editor) {
|
|
|
|
char buf[1024];
|
|
|
|
RConfigNode *node;
|
|
|
|
|
|
|
|
if (!(node = r_config_node_get (core->config, name)))
|
|
|
|
return;
|
|
|
|
if (node->flags & CN_BOOL) {
|
2013-04-01 03:28:34 +00:00
|
|
|
r_config_set_i (core->config, name, node->i_value? 0:1);
|
2011-06-04 01:14:04 +00:00
|
|
|
} else {
|
2013-04-01 03:28:34 +00:00
|
|
|
// XXX: must use config_set () to run callbacks!
|
2011-06-04 01:14:04 +00:00
|
|
|
if (editor) {
|
2014-12-19 02:17:28 +00:00
|
|
|
char * buf = r_core_editor (core, NULL, node->value);
|
2011-06-04 01:14:04 +00:00
|
|
|
node->value = r_str_dup (node->value, buf);
|
|
|
|
free (buf);
|
|
|
|
} else {
|
|
|
|
// FGETS AND SO
|
|
|
|
r_cons_printf ("New value (old=%s): \n", node->value);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_cons_set_raw (0);
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_fgets (buf, sizeof (buf)-1, 0, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2013-04-01 03:28:34 +00:00
|
|
|
r_config_set (core->config, name, buf);
|
|
|
|
//node->value = r_str_dup (node->value, buf);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_core_visual_config(RCore *core) {
|
2015-03-21 01:04:49 +00:00
|
|
|
char *fs = NULL, *fs2 = NULL, *desc = NULL;
|
2013-09-23 22:43:31 +00:00
|
|
|
int i, j, ch, hit, show;
|
|
|
|
int option, _option = 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
RListIter *iter;
|
|
|
|
RConfigNode *bt;
|
2013-09-23 22:43:31 +00:00
|
|
|
char old[1024];
|
2011-06-04 01:14:04 +00:00
|
|
|
int delta = 9;
|
|
|
|
int menu = 0;
|
|
|
|
old[0]='\0';
|
|
|
|
|
2012-06-26 13:21:48 +00:00
|
|
|
option = 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
for (;;) {
|
2014-09-12 17:25:42 +00:00
|
|
|
r_cons_clear00 ();
|
2015-04-14 01:07:57 +00:00
|
|
|
r_cons_get_size (&delta);
|
|
|
|
delta /= 4;
|
2011-06-04 01:14:04 +00:00
|
|
|
|
|
|
|
switch (menu) {
|
|
|
|
case 0: // flag space
|
2015-07-13 21:04:34 +00:00
|
|
|
r_cons_printf ("[EvalSpace]\n\n");
|
2013-04-02 20:36:07 +00:00
|
|
|
hit = j = i = 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach (core->config->nodes, iter, bt) {
|
|
|
|
if (option==i) {
|
|
|
|
fs = bt->name;
|
|
|
|
}
|
|
|
|
if (old[0]=='\0') {
|
|
|
|
r_str_ccpy (old, bt->name, '.');
|
|
|
|
show = 1;
|
|
|
|
} else if (r_str_ccmp (old, bt->name, '.')) {
|
|
|
|
r_str_ccpy (old, bt->name, '.');
|
|
|
|
show = 1;
|
|
|
|
} else show = 0;
|
|
|
|
|
|
|
|
if (show) {
|
2013-04-02 20:36:07 +00:00
|
|
|
if (option == i) hit = 1;
|
|
|
|
if ( (i >=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_printf(" %c %s\n", (option==i)?'>':' ', old);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hit && j>0) {
|
2013-04-02 20:36:07 +00:00
|
|
|
option--;
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r_cons_printf ("\n Sel:%s \n\n", fs);
|
|
|
|
break;
|
|
|
|
case 1: // flag selection
|
2015-07-13 21:04:34 +00:00
|
|
|
r_cons_printf ("[EvalSpace < Variables: %s]\n\n", fs);
|
2011-06-04 01:14:04 +00:00
|
|
|
hit = 0;
|
|
|
|
j = i = 0;
|
|
|
|
// TODO: cut -d '.' -f 1 | sort | uniq !!!
|
|
|
|
r_list_foreach (core->config->nodes, iter, bt) {
|
|
|
|
if (!r_str_ccmp (bt->name, fs, '.')) {
|
2014-09-12 17:25:42 +00:00
|
|
|
if (option==i) {
|
|
|
|
fs2 = bt->name;
|
2014-09-12 17:25:42 +00:00
|
|
|
desc = bt->desc;
|
2014-09-12 17:25:42 +00:00
|
|
|
hit = 1;
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
if ( (i>=option-delta) && ((i<option+delta)||((option<delta)&&(i<(delta<<1))))) {
|
|
|
|
// TODO: Better align
|
|
|
|
r_cons_printf (" %c %s = %s\n", (option==i)?'>':' ', bt->name, bt->value);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hit && j>0) {
|
|
|
|
option = i-1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fs2 != NULL)
|
2014-09-12 17:25:42 +00:00
|
|
|
// TODO: Break long lines.
|
|
|
|
r_cons_printf ("\n Selected: %s (%s)\n\n",
|
|
|
|
fs2, desc);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 15:11:29 +00:00
|
|
|
if (fs && !strncmp (fs, "asm.", 4)) {
|
2016-01-10 23:40:14 +00:00
|
|
|
r_core_cmd (core, "pd $r", 0);
|
2016-05-20 15:11:29 +00:00
|
|
|
}
|
2013-04-01 03:28:34 +00:00
|
|
|
r_cons_visual_flush ();
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_readchar ();
|
2016-01-10 23:40:14 +00:00
|
|
|
if (ch==4 || ch==-1)
|
2014-02-08 11:09:12 +00:00
|
|
|
return;
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
|
|
|
|
switch (ch) {
|
2013-09-23 22:43:31 +00:00
|
|
|
case 'j': option++; break;
|
|
|
|
case 'k': option = (option<=0)? 0: option-1; break;
|
2015-07-09 00:16:25 +00:00
|
|
|
case 'J': option+=4; break;
|
|
|
|
case 'K': option = (option<=3)? 0: option-4; break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 'h':
|
|
|
|
case 'b': // back
|
|
|
|
menu = 0;
|
|
|
|
option = _option;
|
|
|
|
break;
|
2015-10-23 14:55:38 +00:00
|
|
|
case '_':
|
|
|
|
r_core_visual_config_hud (core);
|
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 'q':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (menu <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-05 22:33:11 +00:00
|
|
|
menu--;
|
2015-07-14 23:39:00 +00:00
|
|
|
option = _option;
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
2016-09-15 10:40:29 +00:00
|
|
|
case '$':
|
|
|
|
r_core_cmd0 (core, "?$");
|
|
|
|
r_cons_any_key (NULL);
|
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case '*':
|
|
|
|
case '+':
|
2016-08-23 01:02:23 +00:00
|
|
|
fs2 ? config_visual_hit_i (core, fs2, +1) : 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
case '/':
|
|
|
|
case '-':
|
2016-08-23 01:02:23 +00:00
|
|
|
fs2 ? config_visual_hit_i (core, fs2, -1) : 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
case 'l':
|
|
|
|
case 'E': // edit value
|
|
|
|
case 'e': // edit value
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n': // never happens
|
|
|
|
if (menu == 1) {
|
2016-08-23 01:02:23 +00:00
|
|
|
fs2 ? config_visual_hit (core, fs2, (ch=='E')) : 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
} else {
|
|
|
|
menu = 1;
|
|
|
|
_option = option;
|
|
|
|
option = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
2013-09-23 22:43:31 +00:00
|
|
|
r_cons_printf ("\nVe: Visual Eval help:\n\n"
|
|
|
|
" q - quit menu\n"
|
|
|
|
" j/k - down/up keys\n"
|
|
|
|
" h/b - go back\n"
|
2016-09-15 10:40:29 +00:00
|
|
|
" $ - same as ?$ - show values of vars\n"
|
2013-09-23 22:43:31 +00:00
|
|
|
" e/' ' - edit/toggle current variable\n"
|
|
|
|
" E - edit variable with 'cfg.editor' (vi?)\n"
|
2014-09-12 17:25:42 +00:00
|
|
|
" +/- - increase/decrease numeric value (* and /, too)\n"
|
2013-09-23 22:43:31 +00:00
|
|
|
" : - enter command\n");
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case ':':
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_set_raw(0);
|
2015-03-17 00:29:28 +00:00
|
|
|
{
|
|
|
|
char *cmd = prompt (":> ", NULL);
|
|
|
|
r_core_cmd (core, cmd, 1);
|
|
|
|
free (cmd);
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2015-03-21 00:27:54 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 10:40:29 +00:00
|
|
|
R_API void r_core_visual_mounts(RCore *core) {
|
2015-02-05 05:29:59 +00:00
|
|
|
RList *list = NULL;
|
2015-02-05 09:30:46 +00:00
|
|
|
RFSRoot *fsroot = NULL;
|
2011-07-11 20:52:05 +00:00
|
|
|
RListIter *iter;
|
|
|
|
RFSFile *file;
|
2011-07-13 16:55:16 +00:00
|
|
|
RFSPartition *part;
|
2011-07-12 15:26:56 +00:00
|
|
|
int i, ch, option, mode, partition, dir, delta = 7;
|
|
|
|
char *str, path[4096], buf[1024], *root = NULL;
|
2011-07-11 20:52:05 +00:00
|
|
|
const char *n, *p;
|
|
|
|
|
|
|
|
dir = partition = option = mode = 0;
|
|
|
|
for (;;) {
|
|
|
|
/* Clear */
|
2014-09-12 17:25:42 +00:00
|
|
|
r_cons_clear00 ();
|
2011-07-11 20:52:05 +00:00
|
|
|
|
|
|
|
/* Show */
|
|
|
|
if (mode == 0) {
|
2015-02-17 16:01:00 +00:00
|
|
|
if (list) {
|
2015-02-07 23:30:25 +00:00
|
|
|
r_list_free (list);
|
|
|
|
list = NULL;
|
2015-02-05 05:29:59 +00:00
|
|
|
}
|
2014-11-03 03:05:19 +00:00
|
|
|
r_cons_printf ("Press '/' to navigate the root filesystem.\nPartitions:\n\n");
|
2011-07-11 20:52:05 +00:00
|
|
|
n = r_fs_partition_type_get (partition);
|
|
|
|
list = r_fs_partitions (core->fs, n, 0);
|
|
|
|
i = 0;
|
|
|
|
if (list) {
|
|
|
|
r_list_foreach (list, iter, part) {
|
2011-07-12 15:26:56 +00:00
|
|
|
if ((option-delta <= i) && (i <= option+delta)) {
|
2011-07-13 16:55:16 +00:00
|
|
|
if (option == i)
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf (" > ");
|
2011-07-13 16:55:16 +00:00
|
|
|
else r_cons_printf (" ");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n",
|
|
|
|
part->number, part->type,
|
|
|
|
part->start, part->start+part->length);
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
i++;
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
|
|
|
r_list_free (list);
|
2015-02-16 23:34:51 +00:00
|
|
|
list = NULL;
|
2011-07-11 20:52:05 +00:00
|
|
|
} else r_cons_printf ("Cannot read partition\n");
|
|
|
|
} else if (mode == 1) {
|
|
|
|
r_cons_printf ("Types:\n\n");
|
|
|
|
for(i=0;;i++) {
|
|
|
|
n = r_fs_partition_type_get (i);
|
|
|
|
if (!n) break;
|
|
|
|
r_cons_printf ("%s%s\n", (i==partition)?" > ":" ", n);
|
|
|
|
}
|
2013-04-24 15:13:52 +00:00
|
|
|
} else if (mode == 3) {
|
|
|
|
i = 0;
|
|
|
|
r_cons_printf ("Mountpoints:\n\n");
|
|
|
|
r_list_foreach (core->fs->roots, iter, fsroot) {
|
2015-02-05 09:30:46 +00:00
|
|
|
if (fsroot && (option-delta <= i) && (i <= option+delta)) {
|
2013-04-24 15:13:52 +00:00
|
|
|
r_cons_printf ("%s %s\n", (option == i)?" > ":" ",
|
|
|
|
fsroot->path);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2011-07-11 20:52:05 +00:00
|
|
|
} else {
|
|
|
|
if (root) {
|
|
|
|
list = r_fs_dir (core->fs, path);
|
|
|
|
if (list) {
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf ("%s:\n\n", path);
|
2011-07-11 20:52:05 +00:00
|
|
|
i = 0;
|
|
|
|
r_list_foreach (list, iter, file) {
|
2011-07-12 15:26:56 +00:00
|
|
|
if ((dir-delta <= i) && (i <= dir+delta)) {
|
|
|
|
r_cons_printf ("%s%c %s\n", (dir == i)?" > ":" ",
|
|
|
|
file->type, file->name);
|
|
|
|
}
|
|
|
|
i++;
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf ("\n");
|
2011-07-11 20:52:05 +00:00
|
|
|
r_list_free (list);
|
2015-02-16 23:34:51 +00:00
|
|
|
list = NULL;
|
2011-07-11 20:52:05 +00:00
|
|
|
} else r_cons_printf ("Cannot open '%s' directory\n", root);
|
|
|
|
} else r_cons_printf ("Root undefined\n");
|
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
if (mode==2) {
|
|
|
|
r_str_chop_path (path);
|
|
|
|
str = path + strlen (path);
|
2011-09-18 18:41:36 +00:00
|
|
|
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
2011-07-12 15:26:56 +00:00
|
|
|
list = r_fs_dir (core->fs, path);
|
|
|
|
file = r_list_get_n (list, dir);
|
2011-07-13 16:55:16 +00:00
|
|
|
if (file && file->type != 'd')
|
2013-07-01 14:29:47 +00:00
|
|
|
r_core_cmdf (core, "px @ 0x%"PFMT64x"!64", file->off);
|
2015-01-29 11:16:37 +00:00
|
|
|
r_list_free (list);
|
2015-02-16 23:34:51 +00:00
|
|
|
list = NULL;
|
2011-07-12 15:26:56 +00:00
|
|
|
*str='\0';
|
|
|
|
}
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
|
|
|
|
/* Ask for option */
|
|
|
|
ch = r_cons_readchar ();
|
2015-01-30 21:50:48 +00:00
|
|
|
if (ch==-1||ch==4){
|
|
|
|
free (root);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-11 20:52:05 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
|
|
|
switch (ch) {
|
2014-11-03 03:05:19 +00:00
|
|
|
case '/':
|
2015-04-18 23:38:41 +00:00
|
|
|
if (root) R_FREE (root);
|
2014-11-03 03:05:19 +00:00
|
|
|
root = strdup ("/");
|
|
|
|
strncpy (path, root, sizeof (path)-1);
|
2015-02-03 14:53:21 +00:00
|
|
|
R_FREE (root);
|
2014-11-03 03:05:19 +00:00
|
|
|
mode = 2;
|
|
|
|
break;
|
2011-07-12 15:26:56 +00:00
|
|
|
case 'l':
|
2011-07-11 20:52:05 +00:00
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
if (mode == 0) {
|
|
|
|
n = r_fs_partition_type_get (partition);
|
|
|
|
list = r_fs_partitions (core->fs, n, 0);
|
|
|
|
if (!list) {
|
|
|
|
r_cons_printf ("Unknown partition\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
part = r_list_get_n (list, option);
|
|
|
|
if (!part) {
|
|
|
|
r_cons_printf ("Unknown partition\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = r_fs_partition_type (n, part->type);
|
|
|
|
if (p) {
|
|
|
|
if (r_fs_mount (core->fs, p, "/root", part->start)) {
|
2015-01-30 21:50:48 +00:00
|
|
|
free (root);
|
2011-07-11 20:52:05 +00:00
|
|
|
root = strdup ("/root");
|
2011-09-18 18:41:36 +00:00
|
|
|
strncpy (path, root, sizeof (path)-1);
|
2011-07-11 20:52:05 +00:00
|
|
|
mode = 2;
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("Cannot mount partition\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("Unknown partition type\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
2015-01-29 11:16:37 +00:00
|
|
|
r_list_free (list);
|
2015-02-16 23:34:51 +00:00
|
|
|
list = NULL;
|
2011-07-11 20:52:05 +00:00
|
|
|
} else if (mode == 2){
|
|
|
|
r_str_chop_path (path);
|
2011-09-18 18:41:36 +00:00
|
|
|
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
2011-07-11 20:52:05 +00:00
|
|
|
list = r_fs_dir (core->fs, path);
|
|
|
|
file = r_list_get_n (list, dir);
|
|
|
|
if (file) {
|
|
|
|
if (file->type == 'd') {
|
2011-09-18 18:41:36 +00:00
|
|
|
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_str_chop_path (path);
|
2016-02-16 01:08:09 +00:00
|
|
|
if (root && strncmp (root, path, strlen (root)-1))
|
2011-09-18 18:41:36 +00:00
|
|
|
strncpy (path, root, sizeof (path)-1);
|
2011-07-12 15:26:56 +00:00
|
|
|
} else {
|
|
|
|
r_core_cmdf (core, "s 0x%"PFMT64x, file->off);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_fs_umount (core->fs, root);
|
2014-05-03 00:11:05 +00:00
|
|
|
free (root);
|
2011-07-11 20:52:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_cons_printf ("Unknown file\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
2013-04-24 15:13:52 +00:00
|
|
|
|
|
|
|
} else if (mode == 3) {
|
|
|
|
fsroot = r_list_get_n (core->fs->roots, option);
|
2014-02-26 17:45:59 +00:00
|
|
|
if (fsroot) {
|
|
|
|
root = strdup (fsroot->path);
|
|
|
|
strncpy (path, root, sizeof (path)-1);
|
|
|
|
}
|
2013-04-24 15:13:52 +00:00
|
|
|
mode = 2;
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
dir = partition = option = 0;
|
2011-07-11 20:52:05 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
2013-04-24 15:13:52 +00:00
|
|
|
if (mode == 0 || mode == 3) {
|
2011-07-11 20:52:05 +00:00
|
|
|
if (option > 0)
|
|
|
|
option--;
|
|
|
|
} else if (mode == 1) {
|
|
|
|
if (partition > 0)
|
|
|
|
partition--;
|
|
|
|
} else {
|
|
|
|
if (dir>0)
|
|
|
|
dir--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
if (mode == 0) {
|
|
|
|
n = r_fs_partition_type_get (partition);
|
|
|
|
list = r_fs_partitions (core->fs, n, 0);
|
|
|
|
if (option < r_list_length (list)-1)
|
|
|
|
option++;
|
|
|
|
} else if (mode == 1) {
|
|
|
|
if (partition < r_fs_partition_get_size ()-1)
|
|
|
|
partition++;
|
2013-04-24 15:13:52 +00:00
|
|
|
} else if (mode == 3) {
|
|
|
|
if (option < r_list_length (core->fs->roots)-1)
|
|
|
|
option++;
|
2011-07-11 20:52:05 +00:00
|
|
|
} else {
|
2011-07-12 15:26:56 +00:00
|
|
|
list = r_fs_dir (core->fs, path);
|
|
|
|
if (dir < r_list_length (list)-1)
|
|
|
|
dir++;
|
2011-07-11 20:52:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
mode = 1;
|
|
|
|
break;
|
2011-07-12 15:26:56 +00:00
|
|
|
case 'h':
|
|
|
|
if (mode == 2) {
|
2014-02-26 17:45:59 +00:00
|
|
|
if (!root) {
|
|
|
|
mode = 0;
|
2014-09-26 13:40:17 +00:00
|
|
|
} else
|
2011-07-12 15:26:56 +00:00
|
|
|
if (strcmp (path, root)) {
|
|
|
|
strcat (path, "/..");
|
|
|
|
r_str_chop_path (path);
|
|
|
|
} else {
|
|
|
|
r_fs_umount (core->fs, root);
|
|
|
|
mode = 0;
|
|
|
|
}
|
2013-09-23 22:43:31 +00:00
|
|
|
} else if (mode == 1) {
|
2011-07-12 15:26:56 +00:00
|
|
|
mode = 0;
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
if (mode == 2 && root) {
|
2011-07-11 20:52:05 +00:00
|
|
|
r_fs_umount (core->fs, root);
|
2011-07-12 15:26:56 +00:00
|
|
|
mode = 0;
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
2011-07-12 15:26:56 +00:00
|
|
|
return;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2011-07-12 15:26:56 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
2015-02-05 09:30:46 +00:00
|
|
|
if (mode == 2) {
|
2011-07-12 15:26:56 +00:00
|
|
|
r_str_chop_path (path);
|
|
|
|
str = path + strlen (path);
|
2011-09-18 18:41:36 +00:00
|
|
|
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
2011-07-12 15:26:56 +00:00
|
|
|
list = r_fs_dir (core->fs, path);
|
|
|
|
file = r_list_get_n (list, dir);
|
2015-02-05 09:30:46 +00:00
|
|
|
if (file && root) {
|
2011-09-18 18:41:36 +00:00
|
|
|
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
2011-07-12 15:26:56 +00:00
|
|
|
r_str_chop_path (path);
|
2015-09-14 14:22:57 +00:00
|
|
|
if (strncmp (root, path, strlen (root)-1))
|
2011-09-18 18:41:36 +00:00
|
|
|
strncpy (path, root, sizeof (path)-1);
|
2011-07-12 15:26:56 +00:00
|
|
|
file = r_fs_open (core->fs, path);
|
|
|
|
if (file) {
|
|
|
|
r_fs_read (core->fs, file, 0, file->size);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_set_raw (0);
|
|
|
|
r_line_set_prompt ("Dump path (ej: /tmp/file): ");
|
|
|
|
r_cons_fgets (buf, sizeof (buf)-1, 0, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2015-04-03 02:04:46 +00:00
|
|
|
r_file_dump (buf, file->data, file->size, 0);
|
2011-07-12 15:26:56 +00:00
|
|
|
r_fs_close (core->fs, file);
|
|
|
|
r_cons_printf ("Done\n");
|
2013-09-23 22:43:31 +00:00
|
|
|
} else r_cons_printf ("Cannot dump file\n");
|
|
|
|
} else r_cons_printf ("Cannot dump file\n");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-12 15:26:56 +00:00
|
|
|
*str='\0';
|
|
|
|
}
|
2011-07-11 20:52:05 +00:00
|
|
|
break;
|
2013-04-24 15:13:52 +00:00
|
|
|
case 'm':
|
|
|
|
mode = 3;
|
|
|
|
option = 0;
|
|
|
|
break;
|
2011-07-11 20:52:05 +00:00
|
|
|
case '?':
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf ("\nVM: Visual Mount points help:\n\n");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf (" q - go back or quit menu\n");
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_printf (" j/k - down/up keys\n");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf (" h/l - forward/go keys\n");
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_printf (" t - choose partition type\n");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf (" g - dump file\n");
|
2013-04-24 15:13:52 +00:00
|
|
|
r_cons_printf (" m - show mountpoints\n");
|
2011-07-12 15:26:56 +00:00
|
|
|
r_cons_printf (" : - enter command\n");
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_printf (" ? - show this help\n");
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
break;
|
|
|
|
case ':':
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_cons_set_raw (0);
|
|
|
|
r_line_set_prompt (":> ");
|
|
|
|
r_cons_fgets (buf, sizeof (buf)-1, 0, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2011-07-11 20:52:05 +00:00
|
|
|
r_core_cmd (core, buf, 1);
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-07-11 20:52:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 13:57:45 +00:00
|
|
|
#if 0
|
2012-07-22 08:00:35 +00:00
|
|
|
static void var_index_show(RAnal *anal, RAnalFunction *fcn, ut64 addr, int idx) {
|
2011-06-04 01:14:04 +00:00
|
|
|
int i = 0;
|
|
|
|
RAnalVar *v;
|
|
|
|
RAnalVarAccess *x;
|
|
|
|
RListIter *iter, *iter2;
|
2014-10-23 07:15:55 +00:00
|
|
|
int window ;
|
|
|
|
|
|
|
|
// Adjust the windows size automaticaly
|
|
|
|
(void)r_cons_get_size (&window);
|
|
|
|
window-=5; // Size of printed things
|
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
int wdelta = (idx>5)?idx-5:0;
|
2013-09-23 22:43:31 +00:00
|
|
|
if (!fcn) return;
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach(fcn->vars, iter, v) {
|
|
|
|
if (addr == 0 || (addr >= v->addr && addr <= v->eaddr)) {
|
|
|
|
if (i>=wdelta) {
|
2013-09-23 22:43:31 +00:00
|
|
|
if (i>window+wdelta) {
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_printf("...\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (idx == i) r_cons_printf (" * ");
|
|
|
|
else r_cons_printf (" ");
|
2013-09-01 23:19:43 +00:00
|
|
|
#if 0
|
|
|
|
if (v->type->type == R_ANAL_TYPE_ARRAY) {
|
|
|
|
eprintf ("TODO: support for arrays\n");
|
2012-07-22 08:00:35 +00:00
|
|
|
r_cons_printf ("0x%08llx - 0x%08llx scope=%s type=%s name=%s delta=%d array=%d\n",
|
|
|
|
v->addr, v->eaddr, r_anal_var_scope_to_str (anal, v->scope),
|
2012-08-29 12:46:19 +00:00
|
|
|
r_anal_type_to_str (anal, v->type, ""),
|
|
|
|
v->name, v->delta, v->type->custom.a->count);
|
2014-05-03 00:11:05 +00:00
|
|
|
} else
|
2013-09-01 23:19:43 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
char *s = r_anal_type_to_str (anal, v->type);
|
|
|
|
if (!s) s = strdup ("<unk>");
|
2014-04-04 01:42:22 +00:00
|
|
|
r_cons_printf ("0x%08llx - 0x%08llx scope=%d type=%s name=%s delta=%d\n",
|
|
|
|
v->addr, v->eaddr, v->scope, s, v->name, v->delta);
|
2013-09-01 23:19:43 +00:00
|
|
|
free (s);
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach (v->accesses, iter2, x) {
|
|
|
|
r_cons_printf (" 0x%08llx %s\n", x->addr, x->set?"set":"get");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 13:57:45 +00:00
|
|
|
#endif
|
2011-06-04 01:14:04 +00:00
|
|
|
|
|
|
|
// helper
|
|
|
|
static void function_rename(RCore *core, ut64 addr, const char *name) {
|
|
|
|
RListIter *iter;
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fcn;
|
2011-06-04 01:14:04 +00:00
|
|
|
|
|
|
|
r_list_foreach (core->anal->fcns, iter, fcn) {
|
|
|
|
if (fcn->addr == addr) {
|
2016-02-20 14:25:27 +00:00
|
|
|
r_flag_unset_name (core->flags, fcn->name);
|
2011-06-04 01:14:04 +00:00
|
|
|
free (fcn->name);
|
|
|
|
fcn->name = strdup (name);
|
2016-05-15 12:37:22 +00:00
|
|
|
r_flag_set (core->flags, name, addr, r_anal_fcn_size (fcn));
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 07:15:55 +00:00
|
|
|
// In visual mode, display function list
|
2011-06-04 01:14:04 +00:00
|
|
|
static ut64 var_functions_show(RCore *core, int idx, int show) {
|
2016-08-17 23:27:24 +00:00
|
|
|
int wdelta = (idx > 5)? idx - 5: 0;
|
2011-06-04 01:14:04 +00:00
|
|
|
ut64 seek = core->offset;
|
|
|
|
ut64 addr = core->offset;
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fcn;
|
2016-08-17 23:27:24 +00:00
|
|
|
int window, i = 0;
|
|
|
|
RListIter *iter;
|
2011-06-04 01:14:04 +00:00
|
|
|
|
2014-10-23 07:15:55 +00:00
|
|
|
// Adjust the windows size automaticaly
|
|
|
|
(void)r_cons_get_size (&window);
|
2016-08-17 23:27:24 +00:00
|
|
|
window -= 8; // Size of printed things
|
2014-10-23 07:15:55 +00:00
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach (core->anal->fcns, iter, fcn) {
|
2016-08-17 23:27:24 +00:00
|
|
|
if (i >= wdelta) {
|
2011-06-04 01:14:04 +00:00
|
|
|
if (i> window+wdelta) {
|
2016-01-13 05:23:49 +00:00
|
|
|
r_cons_printf ("...\n");
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
2016-08-17 23:27:24 +00:00
|
|
|
}
|
|
|
|
if (idx == i) {
|
2011-06-04 01:14:04 +00:00
|
|
|
addr = fcn->addr;
|
2016-08-17 23:27:24 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
if (show)
|
2016-08-17 23:27:24 +00:00
|
|
|
r_cons_printf ("%c%c 0x%08"PFMT64x" %4d %s\n",
|
2011-06-04 01:14:04 +00:00
|
|
|
(seek == fcn->addr)?'>':' ',
|
|
|
|
(idx==i)?'*':' ',
|
2016-08-17 23:27:24 +00:00
|
|
|
fcn->addr, r_anal_fcn_realsize (fcn), fcn->name);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-01-13 05:35:14 +00:00
|
|
|
// In visual mode, display the variables.
|
2016-01-13 14:59:31 +00:00
|
|
|
static ut64 var_variables_show(RCore* core, int idx, int show) {
|
2016-01-13 05:23:49 +00:00
|
|
|
int i = 0;
|
2016-01-13 14:59:31 +00:00
|
|
|
const ut64 addr = var_functions_show (core, idx, 0);
|
2016-08-17 23:27:24 +00:00
|
|
|
RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
|
2016-01-13 05:23:49 +00:00
|
|
|
int window;
|
|
|
|
int wdelta = (idx > 5) ? idx - 5 : 0;
|
|
|
|
RListIter *iter;
|
2016-01-13 05:35:14 +00:00
|
|
|
// arguments.
|
|
|
|
RList* list2 = r_anal_var_list (core->anal, fcn, 'v');
|
|
|
|
// variables.
|
|
|
|
RList* list = r_anal_var_list (core->anal, fcn, 'a');
|
|
|
|
r_list_join (list, list2);
|
2016-01-13 05:23:49 +00:00
|
|
|
RAnalVar* var;
|
|
|
|
// Adjust the window size automatically.
|
|
|
|
(void)r_cons_get_size (&window);
|
|
|
|
window -= 8; // Size of printed things.
|
|
|
|
|
2016-01-13 05:35:14 +00:00
|
|
|
// A new line so this looks reasonable.
|
2016-08-17 23:27:24 +00:00
|
|
|
r_cons_newline ();
|
2016-01-13 05:35:14 +00:00
|
|
|
|
2016-01-13 05:23:49 +00:00
|
|
|
r_list_foreach (list, iter, var) {
|
|
|
|
if (i >= wdelta) {
|
|
|
|
if (i > window + wdelta) {
|
|
|
|
r_cons_printf ("...\n");
|
|
|
|
break;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
|
|
|
if (show) {
|
2016-01-13 05:23:49 +00:00
|
|
|
r_cons_printf ("%s %s %s @ %s%s0x%x\n",
|
|
|
|
var->kind=='v'?"var":"arg",
|
|
|
|
var->type, var->name,
|
|
|
|
core->anal->reg->name[R_REG_NAME_BP],
|
|
|
|
(var->kind=='v')?"-":"+",
|
|
|
|
var->delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2016-01-13 05:35:14 +00:00
|
|
|
r_list_free (list);
|
|
|
|
r_list_free (list2);
|
2016-01-13 05:23:49 +00:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2012-06-26 13:21:48 +00:00
|
|
|
static int level = 0;
|
|
|
|
static ut64 addr = 0;
|
|
|
|
static int option = 0;
|
2016-08-17 23:27:24 +00:00
|
|
|
static int printMode = 0;
|
2016-08-18 00:13:34 +00:00
|
|
|
#define lastPrintMode 5
|
2012-06-26 13:21:48 +00:00
|
|
|
|
2016-05-20 15:11:29 +00:00
|
|
|
static void r_core_visual_anal_refresh_column (RCore *core, int colpos) {
|
|
|
|
const ut64 addr = (level != 0 && level != 1)
|
|
|
|
? core->offset
|
|
|
|
: var_functions_show (core, option, 0);
|
2016-09-20 09:34:08 +00:00
|
|
|
// RAnalFunction* fcn = r_anal_get_fcn_in(core->anal, addr, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
int h, w = r_cons_get_size (&h);
|
|
|
|
// int sz = (fcn)? R_MIN (r_anal_fcn_size (fcn), h * 15) : 16; // max instr is 15 bytes.
|
2016-05-20 15:11:29 +00:00
|
|
|
|
2016-08-17 23:27:24 +00:00
|
|
|
const char *cmd, *printCmds[lastPrintMode] = {
|
|
|
|
"pdf", "afi", "pds", "pdc", "pdr"
|
|
|
|
};
|
|
|
|
if (printMode > 0 && printMode < lastPrintMode) {
|
|
|
|
cmd = printCmds[printMode];
|
|
|
|
} else {
|
|
|
|
cmd = printCmds[printMode = 0];
|
|
|
|
}
|
|
|
|
char *cmdf = r_str_newf ("%s @ 0x%"PFMT64x, cmd, addr);
|
|
|
|
if (!cmdf) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-20 15:11:29 +00:00
|
|
|
char *output = r_core_cmd_str (core, cmdf);
|
|
|
|
if (output) {
|
2016-05-31 09:50:12 +00:00
|
|
|
// 'h - 2' because we have two new lines in r_cons_printf
|
|
|
|
char *out = r_str_ansi_crop (output, 0, 0, w - colpos, h - 2);
|
2016-08-17 23:27:24 +00:00
|
|
|
r_cons_printf ("Visual code review (%s)\n%s\n", cmd, out);
|
2016-05-20 15:11:29 +00:00
|
|
|
free (out);
|
|
|
|
R_FREE (output);
|
2015-12-18 20:53:51 +00:00
|
|
|
}
|
2016-05-20 15:11:29 +00:00
|
|
|
free (cmdf);
|
2013-09-23 22:43:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 11:45:36 +00:00
|
|
|
static ut64 r_core_visual_anal_refresh (RCore *core) {
|
2013-03-01 11:20:18 +00:00
|
|
|
ut64 addr;
|
2012-06-26 13:21:48 +00:00
|
|
|
char old[1024];
|
2013-09-23 22:43:31 +00:00
|
|
|
int cols = r_cons_get_size (NULL);
|
2016-08-17 22:29:11 +00:00
|
|
|
if (!core) {
|
|
|
|
return 0LL;
|
|
|
|
}
|
|
|
|
old[0] = '\0';
|
2013-03-01 11:20:18 +00:00
|
|
|
addr = core->offset;
|
2012-06-26 13:21:48 +00:00
|
|
|
cols -= 50;
|
2016-08-17 22:29:11 +00:00
|
|
|
if (cols > 60) {
|
|
|
|
cols = 60;
|
|
|
|
}
|
2014-08-23 00:27:31 +00:00
|
|
|
|
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_flush ();
|
2016-05-20 15:11:29 +00:00
|
|
|
r_core_visual_anal_refresh_column (core, cols);
|
|
|
|
if (cols > 30) {
|
2013-09-01 23:19:43 +00:00
|
|
|
r_cons_column (cols);
|
2012-06-26 13:21:48 +00:00
|
|
|
}
|
|
|
|
switch (level) {
|
2014-10-23 07:15:55 +00:00
|
|
|
// Show functions list help in visual mode
|
2012-06-26 13:21:48 +00:00
|
|
|
case 0:
|
|
|
|
r_cons_printf ("-[ functions ]---------------- \n"
|
2013-09-01 23:19:43 +00:00
|
|
|
"(a) add (x)xrefs (q)quit \n"
|
2016-09-15 11:00:27 +00:00
|
|
|
"(r) rename (c)calls (g)go \n"
|
2013-09-01 23:19:43 +00:00
|
|
|
"(d) delete (v)variables (?)help \n");
|
2012-06-26 13:21:48 +00:00
|
|
|
addr = var_functions_show (core, option, 1);
|
|
|
|
break;
|
|
|
|
case 1:
|
2013-09-01 23:19:43 +00:00
|
|
|
r_cons_printf (
|
|
|
|
"-[ variables ]----- 0x%08"PFMT64x"\n"
|
|
|
|
"(a) add (x)xrefs \n"
|
2016-09-15 11:00:27 +00:00
|
|
|
"(r) rename (g)go \n"
|
2013-09-01 23:19:43 +00:00
|
|
|
"(d) delete (q)quit \n", addr);
|
2016-01-13 14:59:31 +00:00
|
|
|
addr = var_variables_show (core, option, 1);
|
2016-01-13 05:23:49 +00:00
|
|
|
// var_index_show (core->anal, fcn, addr, option);
|
2012-06-26 13:21:48 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-08-23 00:27:31 +00:00
|
|
|
r_cons_printf ("Press 'q' to quit call refs\n");
|
2012-06-26 13:21:48 +00:00
|
|
|
r_cons_printf ("-[ calls ]----------------------- 0x%08"PFMT64x" (TODO)\n", addr);
|
2014-08-23 00:27:31 +00:00
|
|
|
// TODO: filter only the callrefs. but we cant grep here
|
|
|
|
sprintf(old, "afi @ 0x%08"PFMT64x, addr);
|
|
|
|
r_core_cmd0 (core, old);
|
2012-06-26 13:21:48 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-08-23 00:27:31 +00:00
|
|
|
r_cons_printf ("Press 'q' to view call refs\n");
|
2012-06-26 13:21:48 +00:00
|
|
|
r_cons_printf ("-[ xrefs ]----------------------- 0x%08"PFMT64x"\n", addr);
|
2014-08-23 00:27:31 +00:00
|
|
|
//sprintf (old, "axl~0x%08"PFMT64x, addr);
|
|
|
|
r_core_cmd0 (core, "pd 1");
|
|
|
|
//r_core_cmd0 (core, old);
|
2012-06-26 13:21:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
r_cons_flush ();
|
2014-09-22 11:45:36 +00:00
|
|
|
return addr;
|
2012-06-26 13:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Like emenu but for real */
|
|
|
|
R_API void r_core_visual_anal(RCore *core) {
|
|
|
|
char old[218];
|
2013-09-23 22:43:31 +00:00
|
|
|
int ch, _option = 0;
|
2015-12-20 18:12:16 +00:00
|
|
|
int nfcns = r_list_length (core->anal->fcns);
|
2013-09-23 22:43:31 +00:00
|
|
|
RConsEvent olde = core->cons->event_resize;
|
|
|
|
core->cons->event_resize = (RConsEvent) r_core_visual_anal_refresh;
|
2012-06-26 13:21:48 +00:00
|
|
|
level = 0;
|
|
|
|
addr = core->offset;
|
|
|
|
|
2014-08-23 00:27:31 +00:00
|
|
|
int asmbytes = r_config_get_i (core->config, "asm.bytes");
|
|
|
|
r_config_set_i (core->config, "asm.bytes", 0);
|
2012-06-26 13:21:48 +00:00
|
|
|
for (;;) {
|
2014-09-22 11:45:36 +00:00
|
|
|
addr = r_core_visual_anal_refresh (core);
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_readchar ();
|
2016-08-17 22:29:11 +00:00
|
|
|
if (ch == 4 || ch == -1) {
|
|
|
|
if (level == 0) {
|
2014-02-08 11:09:12 +00:00
|
|
|
goto beach;
|
2016-08-17 22:29:11 +00:00
|
|
|
}
|
2014-02-08 11:09:12 +00:00
|
|
|
level--;
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
|
|
|
|
switch (ch) {
|
2013-09-01 23:19:43 +00:00
|
|
|
case '?':
|
|
|
|
r_cons_clear ();
|
|
|
|
r_cons_printf (
|
|
|
|
"Usage: Vv [\n"
|
|
|
|
"Actions supported:\n"
|
|
|
|
" functions: Add, Modify, Delete, Xrefs Calls Vars\n"
|
|
|
|
" variables: Add, Modify, Delete\n"
|
|
|
|
"Moving:\n"
|
|
|
|
" j,k select next/prev item\n"
|
2016-08-17 22:29:11 +00:00
|
|
|
" J,K scroll next/prev page\n"
|
2013-09-01 23:19:43 +00:00
|
|
|
" h,q go back, quit\n"
|
2016-08-17 23:27:24 +00:00
|
|
|
" p,P switch next/prev print mode\n"
|
2013-09-01 23:19:43 +00:00
|
|
|
" l,ret enter, function\n"
|
|
|
|
);
|
|
|
|
r_cons_flush ();
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2013-09-01 23:19:43 +00:00
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case ':':
|
2011-06-04 01:23:12 +00:00
|
|
|
r_core_visual_prompt (core);
|
2016-05-20 15:20:06 +00:00
|
|
|
r_cons_any_key (NULL);
|
2011-06-04 01:14:04 +00:00
|
|
|
continue;
|
|
|
|
case 'a':
|
|
|
|
switch (level) {
|
|
|
|
case 0:
|
2014-02-08 11:09:12 +00:00
|
|
|
eprintf ("TODO: Add new function manually\n");
|
2011-06-04 01:14:04 +00:00
|
|
|
/*
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_cons_set_raw (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_line_set_prompt ("Address: ");
|
|
|
|
if (!r_cons_fgets (old, sizeof (old), 0, NULL)) break;
|
|
|
|
old[strlen (old)-1] = 0;
|
|
|
|
if (!*old) break;
|
|
|
|
addr = r_num_math (core->num, old);
|
|
|
|
r_line_set_prompt ("Size: ");
|
|
|
|
if (!r_cons_fgets (old, sizeof (old), 0, NULL)) break;
|
|
|
|
old[strlen (old)-1] = 0;
|
|
|
|
if (!*old) break;
|
|
|
|
size = r_num_math (core->num, old);
|
|
|
|
r_line_set_prompt ("Name: ");
|
|
|
|
if (!r_cons_fgets (old, sizeof (old), 0, NULL)) break;
|
|
|
|
old[strlen (old)-1] = 0;
|
|
|
|
r_flag_set (core->flags, old, addr, 0, 0);
|
|
|
|
//XXX sprintf(cmd, "CF %lld @ 0x%08llx", size, addr);
|
|
|
|
// XXX r_core_cmd0(core, cmd);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_set_raw (true);
|
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-15 11:00:27 +00:00
|
|
|
case 'r':
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_cons_set_raw (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
r_line_set_prompt ("New name: ");
|
|
|
|
if (!r_cons_fgets (old, sizeof (old), 0, NULL)) break;
|
|
|
|
//old[strlen (old)-1] = 0;
|
|
|
|
function_rename (core, addr, old);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_set_raw (true);
|
|
|
|
r_cons_show_cursor (false);
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
2016-08-17 23:27:24 +00:00
|
|
|
case 'p':
|
|
|
|
printMode ++;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
if (printMode == 0) {
|
|
|
|
printMode = lastPrintMode;
|
|
|
|
} else {
|
|
|
|
printMode --;
|
|
|
|
}
|
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 'd':
|
|
|
|
switch (level) {
|
|
|
|
case 0:
|
|
|
|
eprintf ("TODO\n");
|
|
|
|
//data_del(addr, DATA_FUN, 0);
|
|
|
|
// XXX correcly remove all the data contained inside the size of the function
|
|
|
|
//flag_remove_at(addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-23 22:43:31 +00:00
|
|
|
case 'x': level = 3; break;
|
|
|
|
case 'c': level = 2; break;
|
|
|
|
case 'v': level = 1; break;
|
2015-12-20 18:12:16 +00:00
|
|
|
case 'j':
|
|
|
|
option++;
|
|
|
|
if (option >= nfcns) --option;
|
|
|
|
break;
|
2016-08-17 22:29:11 +00:00
|
|
|
case 'k':
|
|
|
|
option = (option<=0)? 0: option-1;
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
{
|
|
|
|
int rows = 0;
|
|
|
|
r_cons_get_size (&rows);
|
|
|
|
option += (rows - 5);
|
|
|
|
if (option >= nfcns) {
|
|
|
|
option = nfcns - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
{
|
|
|
|
int rows = 0;
|
|
|
|
r_cons_get_size (&rows);
|
|
|
|
option -= (rows - 5);
|
|
|
|
if (option < 0) {
|
|
|
|
option = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-05-03 00:11:05 +00:00
|
|
|
case 'g':
|
2011-06-04 01:14:04 +00:00
|
|
|
r_core_seek (core, addr, SEEK_SET);
|
2012-06-26 13:21:48 +00:00
|
|
|
goto beach;
|
2011-06-04 01:14:04 +00:00
|
|
|
case ' ':
|
|
|
|
case 'l':
|
|
|
|
level = 1;
|
|
|
|
_option = option;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'b': // back
|
|
|
|
level = 0;
|
|
|
|
option = _option;
|
|
|
|
break;
|
|
|
|
case 'q':
|
2016-08-23 01:02:23 +00:00
|
|
|
if (level == 0) {
|
2012-06-26 13:21:48 +00:00
|
|
|
goto beach;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2013-09-23 22:43:31 +00:00
|
|
|
level--;
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 13:21:48 +00:00
|
|
|
beach:
|
|
|
|
core->cons->event_resize = olde;
|
|
|
|
level = 0;
|
2014-08-23 00:27:31 +00:00
|
|
|
r_config_set_i (core->config, "asm.bytes", asmbytes);
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_core_seek_next(RCore *core, const char *type) {
|
|
|
|
RListIter *iter;
|
|
|
|
ut64 next = UT64_MAX;
|
|
|
|
if (strstr (type, "opc")) {
|
|
|
|
RAnalOp aop;
|
2016-08-23 01:02:23 +00:00
|
|
|
if (r_anal_op (core->anal, &aop, core->offset, core->block, core->blocksize)) {
|
2013-12-06 04:18:57 +00:00
|
|
|
next = core->offset + aop.size;
|
2016-08-23 01:02:23 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Invalid opcode\n");
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
} else
|
|
|
|
if (strstr (type, "fun")) {
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fcni;
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach (core->anal->fcns, iter, fcni) {
|
2016-08-23 01:02:23 +00:00
|
|
|
if (fcni->addr < next && fcni->addr > core->offset) {
|
2011-06-04 01:14:04 +00:00
|
|
|
next = fcni->addr;
|
2016-08-23 01:02:23 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (strstr (type, "hit")) {
|
|
|
|
const char *pfx = r_config_get (core->config, "search.prefix");
|
|
|
|
RFlagItem *flag;
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
2015-09-14 14:22:57 +00:00
|
|
|
if (!strncmp (flag->name, pfx, strlen (pfx)))
|
2011-06-04 01:14:04 +00:00
|
|
|
if (flag->offset < next && flag->offset > core->offset)
|
|
|
|
next = flag->offset;
|
|
|
|
}
|
|
|
|
} else { // flags
|
|
|
|
RFlagItem *flag;
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
if (flag->offset < next && flag->offset > core->offset)
|
|
|
|
next = flag->offset;
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 14:22:57 +00:00
|
|
|
if (next != UT64_MAX)
|
2011-06-04 01:14:04 +00:00
|
|
|
r_core_seek (core, next, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_core_seek_previous (RCore *core, const char *type) {
|
|
|
|
RListIter *iter;
|
|
|
|
ut64 next = 0;
|
|
|
|
if (strstr (type, "opc")) {
|
|
|
|
eprintf ("TODO: r_core_seek_previous (opc)\n");
|
|
|
|
} else
|
|
|
|
if (strstr (type, "fun")) {
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fcni;
|
2011-06-04 01:14:04 +00:00
|
|
|
r_list_foreach (core->anal->fcns, iter, fcni) {
|
|
|
|
if (fcni->addr > next && fcni->addr < core->offset)
|
|
|
|
next = fcni->addr;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (strstr (type, "hit")) {
|
|
|
|
RFlagItem *flag;
|
|
|
|
const char *pfx = r_config_get (core->config, "search.prefix");
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
2015-09-14 14:22:57 +00:00
|
|
|
if (!strncmp (flag->name, pfx, strlen (pfx)))
|
2011-06-04 01:14:04 +00:00
|
|
|
if (flag->offset > next && flag->offset< core->offset)
|
|
|
|
next = flag->offset;
|
|
|
|
}
|
|
|
|
} else { // flags
|
|
|
|
RFlagItem *flag;
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
if (flag->offset > next && flag->offset < core->offset)
|
|
|
|
next = flag->offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (next!=0)
|
|
|
|
r_core_seek (core, next, 1);
|
|
|
|
}
|
|
|
|
|
2016-02-13 19:37:18 +00:00
|
|
|
//define the data at offset according to the type (byte, word...) n times
|
|
|
|
static void define_data_ntimes (RCore *core, ut64 off, int times, int type) {
|
|
|
|
int i = 0;
|
|
|
|
r_meta_cleanup (core->anal, off, off + core->blocksize);
|
2016-08-07 23:00:47 +00:00
|
|
|
if (times < 0) {
|
2016-02-13 19:37:18 +00:00
|
|
|
times = 1;
|
2016-08-07 23:00:47 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < times; i++, off += type) {
|
2016-02-13 19:37:18 +00:00
|
|
|
r_meta_add (core->anal, R_META_TYPE_DATA, off, off + type, "");
|
2016-08-07 23:00:47 +00:00
|
|
|
}
|
2016-02-13 19:37:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 22:08:06 +00:00
|
|
|
static bool isDisasmPrint(int mode) {
|
|
|
|
return (mode == 1 || mode == 2);
|
|
|
|
}
|
|
|
|
|
2011-06-04 01:14:04 +00:00
|
|
|
R_API void r_core_visual_define (RCore *core) {
|
2011-06-09 00:12:46 +00:00
|
|
|
int plen = core->blocksize;
|
2013-06-28 09:58:30 +00:00
|
|
|
ut64 off = core->offset;
|
2016-08-23 01:02:23 +00:00
|
|
|
int i, h = 0, n, ch, ntotal = 0;
|
2013-06-28 09:58:30 +00:00
|
|
|
ut8 *p = core->block;
|
2016-02-11 10:11:45 +00:00
|
|
|
int rep = -1;
|
2013-06-28 09:58:30 +00:00
|
|
|
char *name;
|
2015-09-27 23:00:06 +00:00
|
|
|
int delta = 0;
|
2011-06-09 00:12:46 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2014-03-02 00:49:19 +00:00
|
|
|
int cur = core->print->cur;
|
|
|
|
if (core->print->ocur != -1) {
|
|
|
|
plen = R_ABS (core->print->cur- core->print->ocur)+1;
|
2016-07-05 03:25:29 +00:00
|
|
|
if (core->print->ocur<cur) {
|
2014-03-02 00:49:19 +00:00
|
|
|
cur = core->print->ocur;
|
2016-07-05 03:25:29 +00:00
|
|
|
}
|
2014-03-02 00:49:19 +00:00
|
|
|
}
|
2013-06-28 09:58:30 +00:00
|
|
|
off += cur;
|
|
|
|
p += cur;
|
2011-06-09 00:12:46 +00:00
|
|
|
}
|
2016-08-23 01:02:23 +00:00
|
|
|
(void) r_cons_get_size (&h);
|
|
|
|
h -= 19;
|
|
|
|
if (h < 0) {
|
|
|
|
h = 0;
|
|
|
|
r_cons_clear00 ();
|
|
|
|
} else {
|
|
|
|
r_cons_gotoxy (0, h);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
|
|
|
const char *lines[] = { ""
|
|
|
|
,"[Vd]- Define current block as:"
|
|
|
|
," $ define flag size"
|
2016-07-05 03:25:29 +00:00
|
|
|
," 1 edit bits"
|
2014-09-07 23:33:50 +00:00
|
|
|
," b set as byte"
|
|
|
|
," B set as short word (2 bytes)"
|
|
|
|
," c set as code"
|
|
|
|
," C define flag color (fc)"
|
|
|
|
," d set as data"
|
|
|
|
," e end of function"
|
|
|
|
," f analyze function"
|
|
|
|
," F format"
|
2016-08-26 18:02:02 +00:00
|
|
|
," i immediate base (b(in), o(ct), d(ec), h(ex), s(tr))"
|
2014-11-15 01:07:08 +00:00
|
|
|
," j merge down (join this and next functions)"
|
|
|
|
," k merge up (join this and previous function)"
|
2014-09-27 01:48:54 +00:00
|
|
|
," h highlight word"
|
2015-02-17 10:47:24 +00:00
|
|
|
," m manpage for current call"
|
2016-02-16 22:08:06 +00:00
|
|
|
," n rename flag used at cursor"
|
2014-09-07 23:33:50 +00:00
|
|
|
," r rename function"
|
2015-02-09 02:21:47 +00:00
|
|
|
," R find references /r"
|
2014-09-07 23:33:50 +00:00
|
|
|
," s set string"
|
|
|
|
," S set strings in current block"
|
|
|
|
," u undefine metadata here"
|
2016-02-16 00:21:36 +00:00
|
|
|
," x find xrefs to current address (./r)"
|
2014-09-07 23:33:50 +00:00
|
|
|
," w set as 32bit word"
|
|
|
|
," W set as 64bit word"
|
2016-05-01 12:47:44 +00:00
|
|
|
," q quit menu"
|
2016-10-06 00:40:26 +00:00
|
|
|
," z zone flag"
|
2014-09-07 23:33:50 +00:00
|
|
|
, NULL};
|
2016-08-23 01:02:23 +00:00
|
|
|
for (i = 0; lines[i]; i++) {
|
|
|
|
r_cons_fill_line ();
|
|
|
|
r_cons_printf ("\r%s\n", lines[i]);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
// get ESC+char, return 'hjkl' char
|
2016-02-11 10:11:45 +00:00
|
|
|
repeat:
|
2011-06-04 01:14:04 +00:00
|
|
|
ch = r_cons_arrow_to_hjkl (r_cons_readchar ());
|
|
|
|
|
|
|
|
switch (ch) {
|
2014-09-03 08:25:29 +00:00
|
|
|
case 'F':
|
|
|
|
{
|
|
|
|
char cmd[128];
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2014-09-03 08:25:29 +00:00
|
|
|
r_core_cmd0 (core, "pf?");
|
|
|
|
r_cons_flush ();
|
|
|
|
r_line_set_prompt ("format: ");
|
|
|
|
strcpy (cmd, "Cf 0 ");
|
2015-01-14 01:53:34 +00:00
|
|
|
if (r_cons_fgets (cmd+5, sizeof (cmd)-6, 0, NULL) > 0) {
|
2014-09-03 08:25:29 +00:00
|
|
|
r_core_cmd (core, cmd, 0);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2014-09-03 08:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-07-05 03:25:29 +00:00
|
|
|
case '1':
|
|
|
|
edit_bits (core);
|
|
|
|
break;
|
2016-02-16 00:21:36 +00:00
|
|
|
case 'x':
|
|
|
|
r_core_cmd0 (core, "./r");
|
|
|
|
break;
|
2014-09-03 08:25:29 +00:00
|
|
|
case 'B':
|
2016-02-13 19:37:18 +00:00
|
|
|
define_data_ntimes (core, off, rep, R_WORD_DATA);
|
2014-09-03 08:25:29 +00:00
|
|
|
break;
|
2015-09-27 23:00:06 +00:00
|
|
|
case 'i':
|
|
|
|
{
|
|
|
|
char str[128];
|
|
|
|
r_cons_show_cursor (true);
|
|
|
|
r_line_set_prompt ("immbase: ");
|
|
|
|
if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) {
|
2016-08-26 18:02:02 +00:00
|
|
|
r_core_cmdf (core, "ahi %s @ 0x%"PFMT64x, str, off);
|
2015-09-27 23:00:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-09-03 08:25:29 +00:00
|
|
|
case 'b':
|
2016-02-13 19:37:18 +00:00
|
|
|
define_data_ntimes (core, off, rep, R_BYTE_DATA);
|
2014-09-03 08:25:29 +00:00
|
|
|
break;
|
2015-02-17 10:47:24 +00:00
|
|
|
case 'm':
|
|
|
|
{
|
|
|
|
char *man = NULL;
|
|
|
|
/* check for manpage */
|
|
|
|
RAnalOp *op = r_core_anal_op (core, off);
|
|
|
|
if (op) {
|
|
|
|
if (op->jump != UT64_MAX) {
|
|
|
|
RFlagItem *item = r_flag_get_i (core->flags, op->jump);
|
|
|
|
if (item) {
|
|
|
|
const char *ptr = r_str_lchr (item->name, '.');
|
|
|
|
if (ptr)
|
|
|
|
man = strdup (ptr+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_anal_op_free (op);
|
|
|
|
}
|
|
|
|
if (man) {
|
|
|
|
char *p = strstr (man, "INODE");
|
|
|
|
if (p) *p = 0;
|
|
|
|
r_cons_clear();
|
|
|
|
r_cons_flush();
|
|
|
|
r_sys_cmdf ("man %s", man);
|
|
|
|
free (man);
|
|
|
|
}
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2015-02-17 10:47:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-02-16 22:08:06 +00:00
|
|
|
case 'n':
|
|
|
|
{
|
|
|
|
RAnalOp op;
|
|
|
|
char *q = NULL;
|
|
|
|
ut64 tgt_addr = UT64_MAX;
|
2016-08-07 23:00:47 +00:00
|
|
|
if (!isDisasmPrint (core->printidx)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// TODO: get the aligned instruction even if the cursor is in the middle of it.
|
2016-02-16 22:08:06 +00:00
|
|
|
r_anal_op (core->anal, &op, off,
|
|
|
|
core->block + off - core->offset, 32);
|
|
|
|
|
|
|
|
tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr;
|
|
|
|
if (op.var) {
|
2016-08-07 23:00:47 +00:00
|
|
|
// q = r_str_newf ("?i Rename variable %s to;afvn %s `?y`", op.var->name, op.var->name);
|
|
|
|
#if 1
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
|
|
|
if (fcn) {
|
2016-08-08 22:17:42 +00:00
|
|
|
RAnalVar *bar = r_anal_var_get_byname (core->anal, fcn, op.var->name);
|
2016-08-07 23:00:47 +00:00
|
|
|
if (!bar) {
|
2016-08-08 22:17:42 +00:00
|
|
|
bar = r_anal_var_get_byname (core->anal, fcn, op.var->name);
|
2016-08-07 23:00:47 +00:00
|
|
|
if (!bar) {
|
2016-08-08 22:17:42 +00:00
|
|
|
bar = r_anal_var_get_byname (core->anal, fcn, op.var->name);
|
2016-08-07 23:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bar) {
|
|
|
|
char *newname = r_cons_input (sdb_fmt (0, "New variable name for '%s': ", bar->name));
|
|
|
|
if (newname) {
|
|
|
|
if (*newname) {
|
|
|
|
r_anal_var_rename (core->anal, fcn->addr, bar->scope,
|
|
|
|
bar->kind, bar->name, newname);
|
|
|
|
}
|
|
|
|
free (newname);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("Cannot find variable\n");
|
|
|
|
r_sys_sleep (1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("Cannot find function\n");
|
|
|
|
r_sys_sleep (1);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-16 22:08:06 +00:00
|
|
|
} else if (tgt_addr != UT64_MAX) {
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, tgt_addr, R_ANAL_FCN_TYPE_NULL);
|
|
|
|
RFlagItem *f = r_flag_get_i (core->flags, tgt_addr);
|
|
|
|
if (fcn) {
|
|
|
|
q = r_str_newf ("?i Rename function %s to;afn `?y` 0x%"PFMT64x,
|
|
|
|
fcn->name, tgt_addr);
|
|
|
|
} else if (f) {
|
|
|
|
q = r_str_newf ("?i Rename flag %s to;fr %s `?y`",
|
|
|
|
f->name, f->name);
|
|
|
|
} else {
|
|
|
|
q = r_str_newf ("?i Create flag at 0x%"PFMT64x" named;f `?y` @ 0x%"PFMT64x,
|
|
|
|
tgt_addr, tgt_addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q) {
|
|
|
|
r_core_cmd0 (core, q);
|
|
|
|
free (q);
|
|
|
|
}
|
|
|
|
r_anal_op_fini (&op);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-07 23:33:50 +00:00
|
|
|
case 'C':
|
|
|
|
{
|
|
|
|
RFlagItem *item = r_flag_get_i (core->flags, off);
|
|
|
|
if (item) {
|
|
|
|
char cmd[128];
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2014-09-07 23:33:50 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_line_set_prompt ("color: ");
|
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) > 0) {
|
|
|
|
r_flag_color (core->flags, item, cmd);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("Sorry. No flag here\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
{
|
|
|
|
RFlagItem *item = r_flag_get_i (core->flags, off);
|
|
|
|
if (item) {
|
|
|
|
char cmd[128];
|
|
|
|
r_cons_printf ("Current flag size is: %d\n", item->size);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (true);
|
2014-09-07 23:33:50 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
r_line_set_prompt ("new size: ");
|
|
|
|
if (r_cons_fgets (cmd, sizeof (cmd)-1, 0, NULL) > 0) {
|
|
|
|
item->size = r_num_math (core->num, cmd);
|
|
|
|
r_cons_set_raw (1);
|
2015-09-14 10:35:38 +00:00
|
|
|
r_cons_show_cursor (false);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("Sorry. No flag here\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2014-09-07 23:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-09-03 08:25:29 +00:00
|
|
|
case 'w':
|
2016-02-13 19:37:18 +00:00
|
|
|
define_data_ntimes (core, off, rep, R_DWORD_DATA);
|
2014-09-03 08:25:29 +00:00
|
|
|
break;
|
|
|
|
case 'W':
|
2016-02-13 19:37:18 +00:00
|
|
|
define_data_ntimes (core, off, rep, R_QWORD_DATA);
|
2014-09-03 08:25:29 +00:00
|
|
|
break;
|
2014-08-30 01:13:11 +00:00
|
|
|
case 'e':
|
|
|
|
// set function size
|
|
|
|
{
|
2014-09-26 13:40:17 +00:00
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
2014-08-30 01:28:09 +00:00
|
|
|
if (!fcn) {
|
2014-09-26 13:40:17 +00:00
|
|
|
fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
2014-08-30 01:28:09 +00:00
|
|
|
}
|
2014-08-30 01:13:11 +00:00
|
|
|
if (fcn) {
|
|
|
|
RAnalOp op;
|
|
|
|
ut64 size;
|
2015-09-27 23:00:06 +00:00
|
|
|
if (r_anal_op (core->anal, &op, off, core->block+delta,
|
2014-08-30 01:13:11 +00:00
|
|
|
core->blocksize-delta)) {
|
2015-09-27 23:00:06 +00:00
|
|
|
size = off - fcn->addr + op.size;
|
2014-09-02 00:41:40 +00:00
|
|
|
r_anal_fcn_resize (fcn, size);
|
2014-08-30 01:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-11-15 01:07:08 +00:00
|
|
|
case 'j':
|
2015-09-27 23:00:06 +00:00
|
|
|
r_core_cmdf (core, "afm $$+$F @0x%08"PFMT64x, off);
|
2014-11-15 01:07:08 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
eprintf ("TODO: merge up\n");
|
2015-03-05 22:33:28 +00:00
|
|
|
r_cons_any_key (NULL);
|
2014-11-15 01:07:08 +00:00
|
|
|
break;
|
2014-10-21 23:01:38 +00:00
|
|
|
case 'h': // "Vdh"
|
2015-09-27 23:00:06 +00:00
|
|
|
r_core_cmdf (core, "?i highlight;e scr.highlight=`?y` @ 0x%08"PFMT64x, off);
|
2014-09-27 01:48:54 +00:00
|
|
|
break;
|
2014-10-21 23:01:38 +00:00
|
|
|
case 'r': // "Vdr"
|
2015-09-27 23:00:06 +00:00
|
|
|
r_core_cmdf (core, "?i new function name;afn `?y` @ 0x%08"PFMT64x, off);
|
2012-10-25 23:33:57 +00:00
|
|
|
break;
|
2016-10-06 00:40:26 +00:00
|
|
|
case 'z': // "Vdz"
|
|
|
|
r_core_cmdf (core, "?i zone name;fz `?y` @ 0x%08"PFMT64x, off);
|
|
|
|
break;
|
2015-02-09 02:21:47 +00:00
|
|
|
case 'R': // "VdR"
|
2015-09-27 23:00:06 +00:00
|
|
|
eprintf ("Finding references to 0x%08"PFMT64x" ...\n", off);
|
|
|
|
r_core_cmdf (core, "./r 0x%08"PFMT64x" @ $S", off);
|
2015-02-09 02:21:47 +00:00
|
|
|
break;
|
2011-06-09 00:29:24 +00:00
|
|
|
case 'S':
|
|
|
|
do {
|
2013-02-11 09:51:45 +00:00
|
|
|
n = r_str_nlen ((const char*)p+ntotal, plen-ntotal)+1;
|
2014-11-08 23:59:32 +00:00
|
|
|
if (n<2) break;
|
|
|
|
if (p[ntotal + n - 1])
|
|
|
|
break; // Not a \0 terminated string
|
2011-06-09 00:29:24 +00:00
|
|
|
name = malloc (n+10);
|
2011-09-18 18:41:36 +00:00
|
|
|
strcpy (name, "str.");
|
2014-11-08 23:59:32 +00:00
|
|
|
memcpy (name+4, (const char *)p+ntotal, n);
|
|
|
|
name[4+n] = '\0';
|
|
|
|
r_meta_add (core->anal, R_META_TYPE_STRING,
|
|
|
|
off+ntotal, off+n+ntotal, (const char *)name+4);
|
2014-11-15 01:07:08 +00:00
|
|
|
r_name_filter (name, n+10);
|
2016-02-20 14:38:46 +00:00
|
|
|
r_flag_set (core->flags, name, off+ntotal, n);
|
2011-06-09 00:29:24 +00:00
|
|
|
free (name);
|
2014-11-15 01:07:08 +00:00
|
|
|
ntotal += n;
|
2014-11-08 23:59:32 +00:00
|
|
|
} while (ntotal<plen);
|
2011-06-09 00:29:24 +00:00
|
|
|
break;
|
2011-06-04 01:14:04 +00:00
|
|
|
case 's':
|
2014-11-08 20:58:48 +00:00
|
|
|
{
|
|
|
|
int i;
|
2013-02-11 03:08:21 +00:00
|
|
|
// TODO: r_core_cmd0 (core, "Cz");
|
2014-11-08 20:58:48 +00:00
|
|
|
if (core->print->ocur != -1)
|
|
|
|
n = plen;
|
2014-11-15 01:07:08 +00:00
|
|
|
else n = r_str_nlen ((const char*)p, plen)+1;
|
2013-02-11 09:51:45 +00:00
|
|
|
name = malloc (n+10);
|
|
|
|
strcpy (name, "str.");
|
2014-11-08 20:58:48 +00:00
|
|
|
memcpy (name+4, (const char *)p, n);
|
|
|
|
name[4+n] = '\0';
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
if (!name[4+i])
|
|
|
|
name[4+i]='_';
|
2014-11-08 21:04:21 +00:00
|
|
|
r_meta_add (core->anal, R_META_TYPE_STRING, off, off+n, (const char *)name+4);
|
2014-11-15 01:07:08 +00:00
|
|
|
r_name_filter (name, n+10);
|
2016-02-20 14:38:46 +00:00
|
|
|
r_flag_set (core->flags, name, off, n);
|
2013-02-11 09:51:45 +00:00
|
|
|
free (name);
|
2014-11-08 20:58:48 +00:00
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'd': // TODO: check
|
2014-01-23 02:28:25 +00:00
|
|
|
r_meta_cleanup (core->anal, off, off+plen);
|
|
|
|
r_meta_add (core->anal, R_META_TYPE_DATA, off, off+plen, "");
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
2012-07-22 08:00:35 +00:00
|
|
|
case 'c': // TODO: check
|
2014-01-23 02:28:25 +00:00
|
|
|
r_meta_cleanup (core->anal, off, off+plen);
|
|
|
|
r_meta_add (core->anal, R_META_TYPE_CODE, off, off+plen, "");
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
2014-09-22 13:00:41 +00:00
|
|
|
r_core_anal_undefine (core, off);
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2014-09-22 13:00:41 +00:00
|
|
|
{
|
2016-09-16 09:31:30 +00:00
|
|
|
int funsize = 0;
|
2014-09-26 16:10:33 +00:00
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
2016-09-16 09:31:30 +00:00
|
|
|
if (fcn) {
|
2014-09-22 13:00:41 +00:00
|
|
|
r_anal_fcn_resize (fcn, core->offset - fcn->addr);
|
2016-09-16 09:31:30 +00:00
|
|
|
}
|
2016-05-08 10:21:11 +00:00
|
|
|
//int depth = r_config_get_i (core->config, "anal.depth");
|
2013-07-19 01:35:45 +00:00
|
|
|
if (core->print->cur_enabled) {
|
2014-03-02 00:49:19 +00:00
|
|
|
if (core->print->ocur != -1) {
|
2016-09-16 09:31:30 +00:00
|
|
|
funsize = 1 + R_ABS (core->print->cur - core->print->ocur);
|
2014-03-02 00:49:19 +00:00
|
|
|
}
|
2016-05-08 10:21:11 +00:00
|
|
|
//depth = 0;
|
2013-07-19 01:35:45 +00:00
|
|
|
}
|
2014-03-02 00:49:19 +00:00
|
|
|
r_cons_break (NULL, NULL);
|
2016-09-16 09:31:30 +00:00
|
|
|
r_core_cmdf (core, "af @ 0x%08" PFMT64x, off); // required for thumb autodetection
|
|
|
|
//r_core_anal_fcn (core, off, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth);
|
2013-07-19 01:35:45 +00:00
|
|
|
r_cons_break_end ();
|
|
|
|
if (funsize) {
|
2014-09-26 13:40:17 +00:00
|
|
|
RAnalFunction *f = r_anal_get_fcn_in (core->anal, off, -1);
|
2016-05-15 12:37:22 +00:00
|
|
|
r_anal_fcn_set_size (f, funsize);
|
2013-07-19 01:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
default:
|
2016-02-11 10:11:45 +00:00
|
|
|
if (ch >= '0' && ch <= '9') {
|
2016-08-23 01:02:23 +00:00
|
|
|
if (rep < 0) {
|
|
|
|
rep = 0;
|
|
|
|
}
|
2016-02-11 10:11:45 +00:00
|
|
|
rep = rep * 10 + atoi ((char *)&ch);
|
|
|
|
goto repeat;
|
|
|
|
}
|
2011-06-04 01:14:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-17 01:51:53 +00:00
|
|
|
|
|
|
|
R_API void r_core_visual_colors(RCore *core) {
|
|
|
|
char color[32], cstr[32];
|
|
|
|
const char *k, *kol;
|
2013-07-17 20:12:14 +00:00
|
|
|
int ch, opt = 0, oopt = -1;
|
2013-07-17 01:51:53 +00:00
|
|
|
ut8 r, g, b;
|
|
|
|
|
|
|
|
r = g = b = 0;
|
|
|
|
kol = r_cons_pal_get_color (opt);
|
2013-07-17 20:12:14 +00:00
|
|
|
r_cons_rgb_parse (kol, &r, &g, &b, NULL);
|
2013-07-17 01:51:53 +00:00
|
|
|
for (;;) {
|
|
|
|
r_cons_clear ();
|
|
|
|
k = r_cons_pal_get_i (opt);
|
|
|
|
if (!k) {
|
|
|
|
opt = 0;
|
|
|
|
k = r_cons_pal_get_i (opt);
|
|
|
|
}
|
|
|
|
r_cons_gotoxy (0, 0);
|
|
|
|
r_cons_rgb_str (cstr, r, g, b, 0);
|
2013-07-17 17:34:27 +00:00
|
|
|
r&=0xf;
|
|
|
|
g&=0xf;
|
|
|
|
b&=0xf;
|
2013-07-17 01:51:53 +00:00
|
|
|
sprintf (color, "rgb:%x%x%x", r, g, b);
|
|
|
|
//r_cons_printf ("COLOR%s(%sXXX)"Color_RESET"\n", kol, kol?kol+1:"");
|
|
|
|
r_cons_printf ("# Colorscheme %d - Use '.' and ':' to randomize palette\n"
|
|
|
|
"# Press 'rRgGbB', 'jk' or 'q'\nec %s %s # %d (%s)\n",
|
|
|
|
opt, k, color, atoi (cstr+7), cstr+1);
|
|
|
|
r_core_cmdf (core, "ec %s %s", k, color);
|
|
|
|
r_core_cmd0 (core, "pd 25");
|
|
|
|
r_cons_flush ();
|
|
|
|
ch = r_cons_readchar ();
|
|
|
|
ch = r_cons_arrow_to_hjkl (ch);
|
|
|
|
switch (ch) {
|
|
|
|
#define CASE_RGB(x,X,y) \
|
|
|
|
case x:y--;if(y>0x7f)y=0;break;\
|
|
|
|
case X:y++;if(y>15)y=15;break;
|
|
|
|
CASE_RGB ('R','r',r);
|
|
|
|
CASE_RGB ('G','g',g);
|
|
|
|
CASE_RGB ('B','b',b);
|
2013-07-17 20:12:14 +00:00
|
|
|
case 'q': return;
|
2013-07-17 17:34:27 +00:00
|
|
|
case 'k': opt--; break;
|
|
|
|
case 'j': opt++; break;
|
2013-07-17 01:51:53 +00:00
|
|
|
case 'K': opt=0; break;
|
|
|
|
case 'J': opt=0; break; // XXX must go to end
|
2013-07-17 20:12:14 +00:00
|
|
|
case ':': r_cons_pal_random (); break;
|
2013-07-17 01:51:53 +00:00
|
|
|
case '.':
|
|
|
|
r = r_num_rand (0xf);
|
|
|
|
g = r_num_rand (0xf);
|
|
|
|
b = r_num_rand (0xf);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-17 20:12:14 +00:00
|
|
|
if (opt != oopt) {
|
|
|
|
kol = r_cons_pal_get_color (opt);
|
|
|
|
r_cons_rgb_parse (kol, &r, &g, &b, NULL);
|
|
|
|
oopt = opt;
|
|
|
|
}
|
2013-07-17 01:51:53 +00:00
|
|
|
}
|
|
|
|
}
|