* Honor ^C in macros (r_cmd depends on r_cons now)

* Add ?vi to show integer decimal values
* Various fixes for macro scripting
* Fix pw and pq hexdumps
This commit is contained in:
pancake 2012-06-12 02:51:34 +02:00
parent fcac2336c9
commit 3fbcab2d66
6 changed files with 58 additions and 42 deletions

2
TODO
View File

@ -7,6 +7,8 @@
====[[ 0.9.1 ]]====
* Source debugging or gtfo
* Fix ?-
* Register diff colorization is broken
* bar for cursor?
* p= show entropy of current block

View File

@ -1,6 +1,6 @@
NAME=r_cmd
OBJ=cmd.o plugin.o macro.o
DEPS=r_util r_lib
DEPS=r_util r_lib r_cons
include ../config.mk

View File

@ -2,6 +2,7 @@
// TODO: use RList !!
#include <stdio.h>
#include <r_cons.h>
#include "r_cmd.h"
#include "r_util.h"
@ -251,16 +252,17 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in
/* goto */
for (i=0;i<*labels_n;i++) {
// eprintf("---| chk '%s'\n", labels[i].name);
if (!strcmp (ptr+1, labels[i].name))
if (!strcmp (ptr+1, labels[i].name)) {
return labels[i].ptr;
}
}
return NULL;
} else
/* conditional goto */
if (ptr[0]=='?' && ptr[1]=='!' && ptr[2] != '?') {
if (mac->num && mac->num->value != 0) {
char *label = ptr + 3;
for(; *label==' '||*label=='.'; label++);
for (; *label==' '||*label=='.'; label++);
// eprintf("===> GOTO %s\n", label);
/* goto label ptr+3 */
for (i=0;i<*labels_n;i++) {
@ -277,7 +279,7 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in
for (;label[0]==' '||label[0]=='.'; label++);
// eprintf("===> GOTO %s\n", label);
/* goto label ptr+3 */
for (i=0;i<*labels_n;i++) {
for (i=0; i<*labels_n; i++) {
if (!strcmp (label, labels[i].name))
return labels[i].ptr;
}
@ -306,6 +308,7 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in
/* TODO: add support for spaced arguments */
R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
RCons *cons;
char *args;
int nargs = 0;
char *str, *ptr, *ptr2;
@ -342,6 +345,8 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
return 0;
}
cons = r_cons_singleton ();
r_cons_break (NULL, NULL);
list_for_each_prev (pos, &mac->macros) {
RCmdMacroItem *m = list_entry (pos, RCmdMacroItem, list);
@ -359,7 +364,13 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
mac->brk = 0;
do {
if (end) *end='\0';
if (end) *end = '\0';
if (cons->breaked) {
eprintf ("Interrupted at (%s)\n", ptr);
if (end) *end = '\n';
return R_FALSE;
}
r_cons_flush ();
/* Label handling */
ptr2 = r_cmd_macro_label_process (mac, &(labels[0]), &labels_n, ptr);
@ -367,17 +378,17 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
eprintf ("Oops. invalid label name\n");
break;
} else
if (ptr != ptr2 && end) {
*end='\n';
if (ptr != ptr2) { // && end) {
ptr = ptr2;
end = strchr(ptr, '\n');
if (end) *end ='\n';
end = strchr (ptr, '\n');
continue;
}
/* Command execution */
if (*ptr) {
r_cmd_macro_cmd_args (mac, ptr, args, nargs);
}
}
if (end) {
*end = '\n';
ptr = end + 1;

View File

@ -194,7 +194,9 @@ static int cmd_interpret(void *data, const char *input) {
break;
default:
ptr = str = r_core_cmd_str (core, input);
r_cons_break (NULL, NULL);
for (;;) {
if (r_cons_singleton()->breaked) break;
eol = strchr (ptr, '\n');
if (eol) *eol = '\0';
if (*ptr)
@ -202,6 +204,7 @@ static int cmd_interpret(void *data, const char *input) {
if (!eol) break;
ptr = eol+1;
}
r_cons_break_end ();
free (str);
break;
}
@ -720,7 +723,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
core->cmd->macro.counter=0;
while (!feof (fd)) {
buf[0] = '\0';
if (fgets (buf, 1024, fd) == NULL)
if (fgets (buf, sizeof (buf), fd) == NULL)
break;
addr = r_num_math (core->num, buf);
eprintf ("0x%08"PFMT64x": %s\n", addr, cmd);

View File

@ -96,7 +96,9 @@ static int cmd_help(void *data, const char *input) {
break;
case 'v':
n = (input[1] != '\0') ? r_num_math (core->num, input+2) : 0;
r_cons_printf ("0x%"PFMT64x"\n", n);
if (input[1] == 'i' || input[1]=='d')
r_cons_printf ("%"PFMT64d"\n", n);
else r_cons_printf ("0x%"PFMT64x"\n", n);
core->num->value = n;
break;
case '=':
@ -270,6 +272,7 @@ static int cmd_help(void *data, const char *input) {
"Usage: ?[?[?]] expression\n"
" ? eip-0x804800 ; show hex and dec result for this math expr\n"
" ?v eip-0x804800 ; show hex value of math expr\n"
" ?vi rsp-rbp ; show decimal value of math expr\n"
" ?V ; show library version of r_core\n"
" ?= eip-0x804800 ; same as above without user feedback\n"
" ?? [cmd] ; ? == 0 run command when math matches\n"

View File

@ -6,25 +6,24 @@
R_API RPrint *r_print_new() {
RPrint *p = R_NEW (RPrint);
if (p) {
strcpy (p->datefmt, "%d:%m:%Y %H:%M:%S %z");
p->user = NULL;
r_io_bind_init (p->iob);
p->printf = printf;
p->interrupt = 0;
p->bigendian = 0;
p->col = 0;
p->width = 78;
p->cols = 16;
p->cur_enabled = R_FALSE;
p->cur = p->ocur = -1;
p->addrmod = 4;
p->flags = \
R_PRINT_FLAGS_COLOR |
R_PRINT_FLAGS_HEADER |
R_PRINT_FLAGS_ADDRMOD;
p->zoom = R_NEW0 (RPrintZoom);
}
if (!p) return NULL;
strcpy (p->datefmt, "%d:%m:%Y %H:%M:%S %z");
p->user = NULL;
r_io_bind_init (p->iob);
p->printf = printf;
p->interrupt = 0;
p->bigendian = 0;
p->col = 0;
p->width = 78;
p->cols = 16;
p->cur_enabled = R_FALSE;
p->cur = p->ocur = -1;
p->addrmod = 4;
p->flags = \
R_PRINT_FLAGS_COLOR |
R_PRINT_FLAGS_HEADER |
R_PRINT_FLAGS_ADDRMOD;
p->zoom = R_NEW0 (RPrintZoom);
return p;
}
@ -222,7 +221,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
}
inc = p->cols;
if (base==64) inc = p->cols/1.2;
//if (base==64) inc = p->cols/1.2;
if (base<32)
if (p->flags & R_PRINT_FLAGS_HEADER) {
@ -248,8 +247,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
p->interrupt = 0;
for (i=0; !p->interrupt && i<len; i+=inc) {
r_print_addr (p, addr+(i*step));
p->printf ((p->col==1)? "|":" ");
r_print_addr (p, addr+j); //(i*step));
p->printf ((p->col==1)? "|": " ");
for (j=i; j<i+inc; j++) {
if (j>=len) {
//p->printf (j%2?" ":" ");
@ -260,19 +259,17 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
ut32 n;
memcpy (&n, buf+j, sizeof (n));
p->printf ("0x%08x ", n);
j+=3;
j += 3;
} else
if (base==64) {
ut64 n;
ut32 a, b;
/* Prevent reading outside of buf. Necessary as inc is not
* a multiple of 4 for base == 64. */
size_t l = sizeof (n);
if (j + l > len)
l = len - j;
memset (&n, 0, sizeof (n));
memcpy (&n, buf+j, l);
j+=4;
p->printf ("0x%08x %08x", n<<32, n&0xffffff);
// size_t l = sizeof (n); if (j + l > len) l = len - j;
memcpy (&a, buf+j, 4);
memcpy (&b, buf+j+4, 4);
j += 7;
p->printf ("0x%08x%08x ", b, a); //n<<32, n&0xffffff);
} else {
r_print_byte (p, fmt, j, buf[j]);
if (j%2) {