diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index b74d32250d..1f0acf4818 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -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; } diff --git a/binr/rarun2/main.c b/binr/rarun2/main.c index 361fb752d6..b1d48f94b0 100644 --- a/binr/rarun2/main.c +++ b/binr/rarun2/main.c @@ -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; diff --git a/libr/cons/input.c b/libr/cons/input.c index addfd451e3..96a2d62911 100644 --- a/libr/cons/input.c +++ b/libr/cons/input.c @@ -4,21 +4,89 @@ #include 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; diff --git a/libr/core/cmd.c b/libr/core/cmd.c index f8d5badcfa..8eb50046f6 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -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" diff --git a/libr/core/libs.c b/libr/core/libs.c index 032773724d..b2bb9d3697 100644 --- a/libr/core/libs.c +++ b/libr/core/libs.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ +/* radare - LGPL - Copyright 2009-2011 pancake */ #include "r_core.h" diff --git a/libr/core/visual.c b/libr/core/visual.c index cfceb28343..35e5b57fb0 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -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; diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index 5ef26b4353..75a28f4c4a 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -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" diff --git a/libr/io/undo.c b/libr/io/undo.c index fd6e542134..8a68839b93 100644 --- a/libr/io/undo.c +++ b/libr/io/undo.c @@ -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.idxundo.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.limitundo.idx) + //if (io->undo.limitundo.idx) io->undo.limit = io->undo.idx; } diff --git a/test/README b/test/README new file mode 100644 index 0000000000..4de9edd795 --- /dev/null +++ b/test/README @@ -0,0 +1,7 @@ +r2 test suite +============= +small r2 scripts to ensure everything works. + +Test scripts are in t/ + +Bugs are in b/ diff --git a/test/t/crash b/test/b/crash similarity index 100% rename from test/t/crash rename to test/b/crash diff --git a/test/b/flagfail b/test/b/flagfail new file mode 100755 index 0000000000..c454908291 --- /dev/null +++ b/test/b/flagfail @@ -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 diff --git a/test/t/math b/test/t/math new file mode 100755 index 0000000000..51af75fa81 --- /dev/null +++ b/test/t/math @@ -0,0 +1,8 @@ +DEBUG=no +FILE=malloc://1024 +ARGS="" +CMDS=' +?v 0x10+0x30 +' +EXPECT="0x40" +. ../tests.sh diff --git a/test/t/redo b/test/t/redo new file mode 100755 index 0000000000..75a53d3a73 --- /dev/null +++ b/test/t/redo @@ -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 diff --git a/test/t/undo b/test/t/undo new file mode 100755 index 0000000000..ab3d2e8611 --- /dev/null +++ b/test/t/undo @@ -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