* Implement support for handling av/repag and Function keys in r_cons
* Remove -u flag in r2 (was not implemented, but not needed) * Added ?v command * Check if file exists in rarun2 * Fix cmd.vprompt * Some fixes in io.undo - Two test cases to check undo and redo ops * Added 2 bugs in testsuite
This commit is contained in:
parent
8fe475a50f
commit
f7f82ecbc0
|
@ -9,7 +9,7 @@
|
|||
static struct r_core_t r;
|
||||
|
||||
static int main_help(int line) {
|
||||
printf ("Usage: radare2 [-dwnLuvV] [-p prj] [-s addr] [-b bsz] [-e k=v] [file]\n");
|
||||
printf ("Usage: radare2 [-dwnLvV] [-p prj] [-s addr] [-b bsz] [-e k=v] [file]\n");
|
||||
if (!line) printf (
|
||||
" -d use 'file' as a program to debug\n"
|
||||
" -w open file in write mode\n"
|
||||
|
@ -24,10 +24,9 @@ static int main_help(int line) {
|
|||
" -l [lib] load plugin file\n"
|
||||
//" -t load rabin2 info in thread\n"
|
||||
" -L list supported IO plugins\n"
|
||||
" -u unknown file size\n"
|
||||
" -e k=v evaluate config var\n"
|
||||
"Environment:\n"
|
||||
" R_DEBUG handle crash signal\n"
|
||||
" R_DEBUG if defined, show error messages and crash signal\n"
|
||||
" LIBR_PLUGINS path to plugins directory\n"
|
||||
" VAPIDIR path to extra vapi directory\n"
|
||||
);
|
||||
|
@ -146,9 +145,6 @@ int main(int argc, char **argv) {
|
|||
case 'L':
|
||||
list_io_plugins (r.io);
|
||||
return 0;
|
||||
case 'u':
|
||||
eprintf ("TODO\n");
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -115,6 +115,10 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
file = argv[1];
|
||||
fd = fopen (file, "r");
|
||||
if (!fd) {
|
||||
fprintf (stderr, "Cannot open %s\n", file);
|
||||
return 1;
|
||||
}
|
||||
for (;;) {
|
||||
fgets (buf, sizeof (buf)-1, fd);
|
||||
if (feof (fd)) break;
|
||||
|
|
|
@ -4,21 +4,89 @@
|
|||
#include <string.h>
|
||||
|
||||
R_API int r_cons_arrow_to_hjkl(int ch) {
|
||||
// TODO: Add support for F12
|
||||
if (ch==0x1b) {
|
||||
ch = r_cons_readchar ();
|
||||
if (ch==0x5b) {
|
||||
// TODO: must also work in interactive visual write ascii mode
|
||||
switch (ch) {
|
||||
case 0x1b:
|
||||
ch = 'q'; // XXX: must be 0x1b (R_CONS_KEY_ESC)
|
||||
break;
|
||||
case 0x4f: // function keys from f1 to f4
|
||||
ch = r_cons_readchar ();
|
||||
ch = 0xf1 + (ch&0xf);
|
||||
break;
|
||||
case 0:
|
||||
case '[': // function keys (2)
|
||||
ch = r_cons_readchar ();
|
||||
switch (ch) {
|
||||
case 0x35: ch='K'; break; // re.pag
|
||||
case 0x36: ch='J'; break; // av.pag
|
||||
case 0x41: ch='k'; break; // up
|
||||
case 0x42: ch='j'; break; // down
|
||||
case 0x43: ch='l'; break; // right
|
||||
case 0x44: ch='h'; break; // left
|
||||
case 0x3b: break;
|
||||
default: ch = 0;
|
||||
case '[':
|
||||
switch (ch) {
|
||||
case '2': ch = R_CONS_KEY_F11; break;
|
||||
case 'A': ch = R_CONS_KEY_F1; break;
|
||||
case 'B': ch = R_CONS_KEY_F2; break;
|
||||
case 'C': ch = R_CONS_KEY_F3; break;
|
||||
case 'D': ch = R_CONS_KEY_F4; break;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
ch = r_cons_readchar ();
|
||||
r_cons_readchar ();
|
||||
switch (ch) {
|
||||
case '0': ch = R_CONS_KEY_F9; break;
|
||||
case '1': ch = R_CONS_KEY_F10; break;
|
||||
case '3': ch = R_CONS_KEY_F11; break;
|
||||
case '4': ch = R_CONS_KEY_F12; break;
|
||||
}
|
||||
break;
|
||||
case '1':
|
||||
ch = r_cons_readchar ();
|
||||
switch (ch) {
|
||||
case ':': // arrow+shift
|
||||
ch = r_cons_readchar ();
|
||||
ch = r_cons_readchar ();
|
||||
switch (ch) {
|
||||
case 'A': ch = 'K'; break;
|
||||
case 'B': ch = 'J'; break;
|
||||
case 'C': ch = 'L'; break;
|
||||
case 'D': ch = 'H'; break;
|
||||
}
|
||||
break;
|
||||
/*
|
||||
case '1': ch = R_CONS_KEY_F1; break;
|
||||
case '2': ch = R_CONS_KEY_F2; break;
|
||||
case '3': ch = R_CONS_KEY_F3; break;
|
||||
case '4': ch = R_CONS_KEY_F4; break;
|
||||
*/
|
||||
case '5':
|
||||
r_cons_readchar ();
|
||||
ch = 0xf5;
|
||||
break;
|
||||
case '6':
|
||||
r_cons_readchar ();
|
||||
ch = 0xf7;
|
||||
break;
|
||||
case '7':
|
||||
r_cons_readchar ();
|
||||
ch = 0xf6;
|
||||
break;
|
||||
case '8':
|
||||
r_cons_readchar ();
|
||||
ch = 0xf7;
|
||||
break;
|
||||
case '9':
|
||||
r_cons_readchar ();
|
||||
ch = 0xf8;
|
||||
break;
|
||||
} // F9-F12 not yet supported!!
|
||||
break;
|
||||
case '5': ch='K'; break; // repag
|
||||
case '6': ch='J'; break; // avpag
|
||||
case 'A': ch='k'; break; // up
|
||||
case 'B': ch='j'; break; // down
|
||||
case 'C': ch='l'; break; // right
|
||||
case 'D': ch='h'; break; // left
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
|
|
|
@ -1080,6 +1080,10 @@ static int cmd_help(void *data, const char *input) {
|
|||
n = r_num_math (core->num, input+1);
|
||||
r_cons_printf ("%"PFMT64d" 0x%"PFMT64x"\n", n,n);
|
||||
break;
|
||||
case 'v':
|
||||
n = r_num_math (core->num, input+2);
|
||||
r_cons_printf ("0x%"PFMT64x"\n", n,n);
|
||||
break;
|
||||
case '=':
|
||||
r_num_math (core->num, input+1);
|
||||
break;
|
||||
|
@ -1177,7 +1181,8 @@ static int cmd_help(void *data, const char *input) {
|
|||
if (input[1]=='?') {
|
||||
r_cons_printf (
|
||||
"Usage: ?[?[?]] expression\n"
|
||||
" ? eip-0x804800 ; calculate result for this math expr\n"
|
||||
" ? eip-0x804800 ; show hex and dec result for this math expr\n"
|
||||
" ?v eip-0x804800 ; show hex value of math expr\n"
|
||||
" ?= eip-0x804800 ; same as above without user feedback\n"
|
||||
" ?? [cmd] ; ? == 0 run command when math matches\n"
|
||||
" ?i prompt ; prompt for number and store in $$?\n"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
|
||||
|
||||
#include "r_core.h"
|
||||
|
||||
|
|
|
@ -481,6 +481,10 @@ static void r_core_visual_refresh (RCore *core) {
|
|||
r_cons_clear00 ();
|
||||
r_print_set_cursor (core->print, curset, ocursor, cursor);
|
||||
|
||||
vi = r_config_get (core->config, "cmd.vprompt");
|
||||
if (vi) r_core_cmd (core, vi, 0);
|
||||
r_core_visual_title (core, color);
|
||||
|
||||
vi = r_config_get (core->config, "cmd.cprompt");
|
||||
if (vi && *vi) {
|
||||
r_cons_printf ("\n[cmd.cprompt] %s\n", vi);
|
||||
|
@ -488,10 +492,6 @@ static void r_core_visual_refresh (RCore *core) {
|
|||
r_cons_column (80);
|
||||
}
|
||||
|
||||
vi = r_config_get (core->config, "cmd.vprompt");
|
||||
if (vi) r_core_cmd (core, vi, 0);
|
||||
r_core_visual_title (core, color);
|
||||
|
||||
if (zoom) r_core_cmd (core, "pZ", 0);
|
||||
else r_core_cmd (core, printfmt[R_ABS (core->printidx%NPF)], 0);
|
||||
blocksize = core->num->value? core->num->value : core->blocksize;
|
||||
|
|
|
@ -80,6 +80,21 @@ typedef struct r_cons_t {
|
|||
// not needed anymoar
|
||||
//extern int (*r_cons_user_fgets)(char *buf, int len);
|
||||
|
||||
#define R_CONS_KEY_F1 0xf1
|
||||
#define R_CONS_KEY_F2 0xf2
|
||||
#define R_CONS_KEY_F3 0xf3
|
||||
#define R_CONS_KEY_F4 0xf4
|
||||
#define R_CONS_KEY_F5 0xf5
|
||||
#define R_CONS_KEY_F6 0xf6
|
||||
#define R_CONS_KEY_F7 0xf7
|
||||
#define R_CONS_KEY_F8 0xf8
|
||||
#define R_CONS_KEY_F9 0xf9
|
||||
#define R_CONS_KEY_F10 0xfa
|
||||
#define R_CONS_KEY_F11 0xfb
|
||||
#define R_CONS_KEY_F12 0xfc
|
||||
|
||||
#define R_CONS_KEY_ESC 0x1b
|
||||
|
||||
/* plain colors */
|
||||
#define Color_BLACK "\x1b[30m"
|
||||
#define Color_BGBLACK "\x1b[40m"
|
||||
|
|
|
@ -31,6 +31,8 @@ R_API ut64 r_io_sundo_last(struct r_io_t *io) {
|
|||
}
|
||||
|
||||
R_API int r_io_sundo(struct r_io_t *io) {
|
||||
if (io->undo.idx == io->undo.limit)
|
||||
r_io_sundo_push (io);
|
||||
io->undo.idx--;
|
||||
if (io->undo.idx<0)
|
||||
return io->undo.idx = 0;
|
||||
|
@ -40,11 +42,11 @@ R_API int r_io_sundo(struct r_io_t *io) {
|
|||
|
||||
R_API int r_io_sundo_redo(struct r_io_t *io) {
|
||||
if (io->undo.idx<io->undo.limit) {
|
||||
io->undo.idx += 2;
|
||||
io->undo.idx += 1;
|
||||
if (io->undo.idx>=R_IO_UNDOS) {
|
||||
io->undo.idx -= 2;
|
||||
io->undo.idx -= 1;
|
||||
return R_FALSE;
|
||||
} else io->off = io->undo.seek[io->undo.idx];
|
||||
} else io->off = io->undo.seek[io->undo.idx-1];
|
||||
r_io_sundo(io);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ R_API void r_io_sundo_push(RIO *io) {
|
|||
io->undo.idx--;
|
||||
eprintf ("undo limit reached\n");
|
||||
}
|
||||
if (io->undo.limit<io->undo.idx)
|
||||
//if (io->undo.limit<io->undo.idx)
|
||||
io->undo.limit = io->undo.idx;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
r2 test suite
|
||||
=============
|
||||
small r2 scripts to ensure everything works.
|
||||
|
||||
Test scripts are in t/
|
||||
|
||||
Bugs are in b/
|
|
@ -0,0 +1,16 @@
|
|||
DEBUG=no
|
||||
FILE=malloc://1024
|
||||
ARGS=""
|
||||
CMDS='
|
||||
s 10
|
||||
f foo
|
||||
f bar
|
||||
f cow
|
||||
f-cow
|
||||
f-bar
|
||||
f-foo
|
||||
pd 1
|
||||
'
|
||||
EXPECT="nop
|
||||
mov eax, 0x21"
|
||||
. ../tests.sh
|
|
@ -0,0 +1,8 @@
|
|||
DEBUG=no
|
||||
FILE=malloc://1024
|
||||
ARGS=""
|
||||
CMDS='
|
||||
?v 0x10+0x30
|
||||
'
|
||||
EXPECT="0x40"
|
||||
. ../tests.sh
|
|
@ -0,0 +1,30 @@
|
|||
DEBUG=no
|
||||
FILE=malloc://1024
|
||||
ARGS=""
|
||||
CMDS='
|
||||
s 0x10
|
||||
s 0x20
|
||||
s 0x30
|
||||
s 0x40
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s+
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
'
|
||||
EXPECT="0x40
|
||||
0x30
|
||||
0x40
|
||||
0x30
|
||||
0x20
|
||||
0x10
|
||||
0x0"
|
||||
. ../tests.sh
|
|
@ -0,0 +1,24 @@
|
|||
DEBUG=no
|
||||
FILE=malloc://1024
|
||||
ARGS=""
|
||||
CMDS='
|
||||
s 0x10
|
||||
s 0x20
|
||||
s 0x30
|
||||
s 0x40
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
s-
|
||||
?v $$
|
||||
'
|
||||
EXPECT="0x40
|
||||
0x30
|
||||
0x20
|
||||
0x10
|
||||
0x0"
|
||||
. ../tests.sh
|
Loading…
Reference in New Issue