Handle ^C in several pd,pdr,pi,.. commands

This commit is contained in:
pancake 2014-11-01 23:54:51 +01:00
parent 1c3df12988
commit 1be4e0ea35
2 changed files with 28 additions and 8 deletions

View File

@ -772,8 +772,13 @@ static int pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt) {
core->anal->cur->reset_counter (core->anal, core->offset);
}
r_cons_break (NULL, NULL);
for (i=j=0; j<nb_opcodes; j++) {
RFlagItem *item;
if (r_cons_singleton ()->breaked) {
err = 1;
break;
}
r_asm_set_pc (core->assembler, core->offset+i);
ret = r_asm_disassemble (core->assembler, &asmop, core->block+i,
core->blocksize-i);
@ -830,6 +835,7 @@ static int pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt) {
if (nb_bytes && (nb_bytes <= i))
break;
}
r_cons_break_end ();
core->offset = old_offset;
return err;
}
@ -1241,7 +1247,7 @@ static int cmd_print(void *data, const char *input) {
break;
case 'B': { //pB
if (input[1]=='?') {
r_cons_printf("|Usage: p[bB] [len] bitstream of N bytes\n");
r_cons_printf ("|Usage: p[bB] [len] bitstream of N bytes\n");
} else {
const int size = len*8;
char *buf = malloc (size+1);
@ -1269,7 +1275,7 @@ static int cmd_print(void *data, const char *input) {
case 'd': // "pId" is the same as pDi
pdi (core, 0, l, 0);
break;
case '?':
case '?': // "pi?"
r_cons_printf("|Usage: p[iI][df] [len] print N instructions/bytes"
"(f=func) (see pi? and pdi)\n");
break;
@ -1376,8 +1382,11 @@ static int cmd_print(void *data, const char *input) {
buf = malloc (l+1);
r_core_read_at (core, core->offset, buf, l);
}
r_cons_break (NULL, NULL);
for (i=0; i<l; i++) {
r_asm_set_pc (core->assembler, core->offset+i);
if (r_cons_singleton ()->breaked)
break;
ret = r_asm_disassemble (core->assembler, &asmop,
buf+i, l-i);
if (ret<1) {
@ -1387,6 +1396,7 @@ static int cmd_print(void *data, const char *input) {
} else r_cons_printf ("0x%08"PFMT64x" %16s %s\n",
core->offset+i, asmop.buf_hex, asmop.buf_asm);
}
r_cons_break_end ();
if (buf != core->block)
free (buf);
pd_result = R_TRUE;
@ -1498,11 +1508,14 @@ static int cmd_print(void *data, const char *input) {
int j, ret;
const ut8 *buf = core->block;
if (l==0) l= len;
r_cons_break (NULL, NULL);
for (i=j=0; i<core->blocksize && j<l; i+=ret,j++ ) {
ret = r_asm_disassemble (core->assembler, &asmop, buf+i, len-i);
if (r_cons_singleton ()->breaked) break;
printf ("%d\n", ret);
if (ret<1) ret = 1;
}
r_cons_break_end ();
pd_result = 0;
}
break;
@ -1510,12 +1523,11 @@ static int cmd_print(void *data, const char *input) {
processed_cmd = R_TRUE;
if (*input == 'D'){
cmd_pDj (core, input+2);
} else
cmd_pdj (core, input+2);
r_cons_printf ("\n");
} else cmd_pdj (core, input+2);
r_cons_newline ();
pd_result = 0;
break;
case '?': //pd?
case '?': // "pd?"
processed_cmd = R_TRUE;
const char* help_msg[] = {
"Usage:", "p[dD][fil] [len] [arch] [bits] @ [addr]", " # Print Disassembly",

View File

@ -1582,6 +1582,7 @@ static void handle_print_refptr (RCore *core, RDisasmState *ds) {
R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, int l, int invbreak, int cbytes) {
int ret, idx = 0, i;
int continueoninvbreak = (len == l) && invbreak;
int dorepeat = 1;
RAnalFunction *f = NULL;
ut8 *nbuf = NULL;
RDisasmState *ds;
@ -1660,8 +1661,10 @@ toro:
for (i=idx=ret=0; idx < len && ds->lines < ds->l;
idx+=ds->oplen,i++, ds->index+=ds->oplen, ds->lines++) {
ds->at = ds->addr + idx;
if (r_cons_singleton ()->breaked)
if (r_cons_singleton ()->breaked) {
dorepeat = 0;
break;
}
r_core_seek_archbits (core, ds->at); // slow but safe
ds->hint = r_core_hint_begin (core, ds->hint, ds->at);
@ -1801,7 +1804,7 @@ toro:
#if HASRETRY
//if (!ds->cbytes && idx>=len) {// && (invbreak && !ds->lastfail)) {
if (!ds->cbytes && ds->lines<ds->l) {
if (!ds->cbytes && ds->lines<ds->l && dorepeat) {
retry:
if (len<4) len = 4;
buf = nbuf = malloc (len);
@ -1842,6 +1845,7 @@ R_API int r_core_print_disasm_instructions (RCore *core, int nb_bytes, int nb_op
RAnalFunction *f;
char *tmpopstr;
const ut64 old_offset = core->offset;
eprintf ("DISASSM\n");
if (!nb_bytes) {
nb_bytes = core->blocksize;
@ -1876,9 +1880,12 @@ R_API int r_core_print_disasm_instructions (RCore *core, int nb_bytes, int nb_op
if (ds->l == 0)
ds->l = ds->len;
r_cons_break (NULL, NULL);
for (i=j=0; i<bs && i<ds->len && j<ds->l; i+=ret, j++) {
ds->at = core->offset +i;
r_core_seek_archbits (core, ds->at);
if (r_cons_singleton ()->breaked)
break;
if (ds->hint) {
r_anal_hint_free (ds->hint);
ds->hint = NULL;
@ -1948,6 +1955,7 @@ R_API int r_core_print_disasm_instructions (RCore *core, int nb_bytes, int nb_op
ds->hint = NULL;
}
}
r_cons_break_end ();
if (ds->oldbits) {
r_config_set_i (core->config, "asm.bits", ds->oldbits);
ds->oldbits = 0;