Implement visual entropy browser with V|| and then hl keys to move

This commit is contained in:
pancake 2017-06-28 00:24:26 +02:00
parent 716ade94bf
commit 721304a3ed
5 changed files with 51 additions and 11 deletions

View File

@ -2260,17 +2260,17 @@ static void cmd_print_bars(RCore *core, const char *input) {
if (input[0]) {
char *spc = strchr (input, ' ');
if (spc) {
nblocks = r_num_get (core->num, spc + 1);
nblocks = r_num_math (core->num, spc + 1);
if (nblocks < 1) {
nblocks = core->blocksize;
return;
}
spc = strchr (spc + 1, ' ');
if (spc) {
totalsize = r_num_get (core->num, spc + 1);
totalsize = r_num_math (core->num, spc + 1);
spc = strchr (spc + 1, ' ');
if (spc) {
skipblocks = r_num_get (core->num, spc + 1);
skipblocks = r_num_math (core->num, spc + 1);
}
}
}
@ -2583,10 +2583,19 @@ static void cmd_print_bars(RCore *core, const char *input) {
case 'q':
for (i = 0; i < nblocks; i++) {
ut64 off = core->offset + (blocksize * i);
if (core->print->cur_enabled) {
if (i == core->print->cur) {
r_cons_printf ("> ");
core->num->value = off;
} else {
r_cons_printf (" ");
}
}
r_cons_printf ("0x%08"PFMT64x " %d %d\n", off, i, ptr[i]);
}
break;
default:
core->print->num = core->num;
r_print_fill (core->print, ptr, nblocks, core->offset, blocksize);
break;
}

View File

@ -1577,6 +1577,7 @@ R_API bool r_core_init(RCore *core) {
core->http_up = false;
core->print = r_print_new ();
core->print->user = core;
core->print->num = core->num;
core->print->get_enumname = getenumname;
core->print->get_bitfield = getbitfield;
core->print->offname = r_core_print_offname;

View File

@ -1622,9 +1622,16 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
r_line_set_prompt ("cmd.cprompt> ");
I->line->contents = strdup (cmd);
buf = r_line_readline ();
// if (r_cons_fgets (buf, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0';
I->line->contents = NULL;
(void)r_config_set (core->config, "cmd.cprompt", buf);
if (!strcmp (buf, "|")) {
R_FREE (I->line->contents);
core->print->cur_enabled = true;
core->print->cur = 0;
(void)r_config_set (core->config, "cmd.cprompt", "p=e $r-2");
} else {
// if (r_cons_fgets (buf, sizeof (buf)-4, 0, NULL) <0) buf[0]='\0';
R_FREE (I->line->contents);
(void)r_config_set (core->config, "cmd.cprompt", buf);
}
}
break;
case '!':
@ -2647,7 +2654,7 @@ static int visual_responsive(RCore *core) {
}
static void visual_refresh(RCore *core) {
int w;
static ut64 oseek = UT64_MAX;
const char *vi, *vcmd;
if (!core) {
return;
@ -2655,7 +2662,7 @@ static void visual_refresh(RCore *core) {
r_print_set_cursor (core->print, core->print->cur_enabled, core->print->ocur, core->print->cur);
core->cons->blankline = true;
w = visual_responsive (core);
int w = visual_responsive (core);
if (autoblocksize) {
r_cons_gotoxy (0, 0);
@ -2678,9 +2685,18 @@ static void visual_refresh(RCore *core) {
// do not show column contents
} else {
r_cons_printf ("[cmd.cprompt=%s]\n", vi);
if (oseek != UT64_MAX) {
r_core_seek (core, oseek, 1);
}
r_core_cmd0 (core, vi);
r_cons_column (nw);
r_cons_flush ();
if (!strncmp (vi, "p=", 2) && core->print->cur_enabled) {
oseek = core->offset;
r_core_seek (core, core->num->value, 1);
} else {
oseek = UT64_MAX;
}
}
}
r_cons_gotoxy (0, 0);
@ -2696,6 +2712,8 @@ static void visual_refresh(RCore *core) {
}
r_core_visual_title (core, color);
}
bool ce = core->print->cur_enabled;
core->print->cur_enabled = false;
vcmd = r_config_get (core->config, "cmd.visual");
if (vcmd && *vcmd) {
@ -2707,10 +2725,13 @@ static void visual_refresh(RCore *core) {
core->print->screen_bounds = 1LL;
r_core_cmd0 (core, zoom? "pz": printfmt[PIDX]);
}
core->print->cur_enabled = ce;
#if 0
if (core->print->screen_bounds != 1LL) {
r_cons_printf ("[0x%08"PFMT64x "..0x%08"PFMT64x "]\n",
core->offset, core->print->screen_bounds);
}
#endif
blocksize = core->num->value? core->num->value: core->blocksize;
/* this is why there's flickering */

View File

@ -1,4 +1,4 @@
/* radare - Copyright 2008-2016 - LGPL -- pancake */
/* radare - Copyright 2008-2017 - LGPL -- pancake */
#include <r_types.h>
#include <r_util.h>
@ -26,13 +26,12 @@ R_API RSyscall* r_syscall_new() {
R_API void r_syscall_free(RSyscall *s) {
sdb_free (s->db);
free (s->os);
memset (s, 0, sizeof (RSyscall));
free (s);
}
/* return fastcall register argument 'idx' for a syscall with 'num' args */
R_API const char *r_syscall_reg(RSyscall *s, int idx, int num) {
if (num < 0 || num >= R_SYSCALL_ARGS || idx<0 || idx>=R_SYSCALL_ARGS) {
if (num < 0 || num >= R_SYSCALL_ARGS || idx < 0 || idx >= R_SYSCALL_ARGS) {
return NULL;
}
return s->regs[num].arg[idx];

View File

@ -1333,6 +1333,16 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
ut8 next = (i + 1 < size)? arr[i + 1]: 0;
int base = 0;
if (addr != UT64_MAX && step > 0) {
if (p->cur_enabled) {
if (i == p->cur) {
p->cb_printf ("> ");
if (p->num) {
p->num->value = addr + (i * step);
}
} else {
p->cb_printf (" ");
}
}
p->cb_printf ("0x%08" PFMT64x " ", addr + (i * step));
p->cb_printf ("%02x %04x |", i, arr[i]);
} else {