Fixes for pd, pdn and pD, Fix Vppj issue

This commit is contained in:
pancake 2013-12-02 03:53:29 +01:00
parent b8dbf7e07d
commit 4e368ae2b3
3 changed files with 54 additions and 26 deletions

View File

@ -1029,14 +1029,15 @@ static int cmd_print(void *data, const char *input) {
processed_cmd = R_TRUE; processed_cmd = R_TRUE;
eprintf ("Usage: pd[f|i|l] [len] [arch] [bits] @ [addr]\n" eprintf ("Usage: pd[f|i|l] [len] [arch] [bits] @ [addr]\n"
//TODO: eprintf (" pdr : disassemble resume\n"); //TODO: eprintf (" pdr : disassemble resume\n");
" pda : disassemble all possible opcodes (byte per byte)\n" " pda disassemble all possible opcodes (byte per byte)\n"
" pdj : disassemble to json\n" " pdj disassemble to json\n"
" pdb : disassemble basic block\n" " pdb disassemble basic block\n"
" pdr : recursive disassemble across the function graph\n" " pdr recursive disassemble across the function graph\n"
" pdf : disassemble function\n" " pdf disassemble function\n"
" pdi : like 'pi', with offset and bytes\n" " pdi like 'pi', with offset and bytes\n"
" pdl : show instruction sizes\n" " pdn disassemble N bytes (like pdi)\n"
" pds : disassemble with back sweep (greedy disassembly backwards)\n"); " pdl show instruction sizes\n"
" pds disassemble with back sweep (greedy disassembly backwards)\n");
pd_result = 0; pd_result = 0;
} }
if (!processed_cmd) { if (!processed_cmd) {
@ -1046,7 +1047,6 @@ static int cmd_print(void *data, const char *input) {
ut8 *block = malloc (core->blocksize); ut8 *block = malloc (core->blocksize);
if (block && bw_disassemble) { if (block && bw_disassemble) {
l = -l; l = -l;
if (block) { if (block) {
if (*input == 'D'){ if (*input == 'D'){
@ -1076,22 +1076,30 @@ static int cmd_print(void *data, const char *input) {
ut64 idx = 0; ut64 idx = 0;
RAsmOp asmop; RAsmOp asmop;
// XXX: issue with small blocks
for (i=0; i < use_blocksize; i++ ) { for (i=0; i < use_blocksize; i++ ) {
ut64 addr = core->offset + idx; ut64 addr = core->offset + i;
r_core_read_at (core, addr, r_core_read_at (core, addr,
block, core->blocksize); block, core->blocksize);
if (*input == 'D') { if (*input == 'D') {
core->num->value = r_core_print_disasm (core->print, // l must be smaller than blocksize
core, addr, block, core->blocksize, l, 0, 1); if (l>=core->blocksize) {
idx++; eprintf ("Invalid length\n");
r_cons_printf ("------\n"); } else {
core->num->value = r_core_print_disasm (core->print,
core, addr, block, l, l, 0, 1);
}
break;
} else { } else {
/*
ut32 disasm_len = r_asm_disassemble (core->assembler, &asmop, block, ut32 disasm_len = r_asm_disassemble (core->assembler, &asmop, block,
core->blocksize); core->blocksize);
if (disasm_len == 0) disasm_len++; if (disasm_len == 0) disasm_len++;
*/
core->num->value = r_core_print_disasm (core->print, core->num->value = r_core_print_disasm (core->print,
core, addr, block, disasm_len, l, 0, 1); core, addr, block, l, l, 0, 0);
idx += disasm_len; i += core->num->value-1; //disasm_len;
break;
} }
} }
} }

View File

@ -206,7 +206,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
int tries = 3; int tries = 3;
opstr = NULL; opstr = NULL;
memset(str, 0, sizeof(str)); memset (str, 0, sizeof (str));
//r_cons_printf ("len =%d l=%d ib=%d limit=%d\n", len, l, invbreak, p->limit); //r_cons_printf ("len =%d l=%d ib=%d limit=%d\n", len, l, invbreak, p->limit);
// TODO: import values from debugger is possible // TODO: import values from debugger is possible
@ -373,8 +373,9 @@ toro:
r_core_seek_archbits (core, at); // slow but safe r_core_seek_archbits (core, at); // slow but safe
hint = r_core_hint_begin (core, hint, at); hint = r_core_hint_begin (core, hint, at);
if (cbytes && idx>=l) if (!cbytes && idx>=l) {
break; break;
}
r_asm_set_pc (core->assembler, at); r_asm_set_pc (core->assembler, at);
if (show_lines) { if (show_lines) {
line = r_anal_reflines_str (core, at, linesopts); line = r_anal_reflines_str (core, at, linesopts);
@ -540,7 +541,7 @@ toro:
// core->assembler->pc + ret, l, len); // core->assembler->pc + ret, l, len);
#if HASRETRY #if HASRETRY
//eprintf ("~~~~~~LEN~~~~ %d %d %d\n", l, len, lines); //eprintf ("~~~~~~LEN~~~~ %d %d %d\n", l, len, lines);
if (!cbytes && tries>0) { //1||l < len) { if (!cbytes && tries>0) { //1||l < len)
//eprintf ("~~~~~~~~~~~~~ %d %d\n", idx, core->blocksize); //eprintf ("~~~~~~~~~~~~~ %d %d\n", idx, core->blocksize);
addr = core->assembler->pc; addr = core->assembler->pc;
tries--; tries--;
@ -1288,9 +1289,7 @@ toro:
goto toro; goto toro;
} }
} }
//if (invbreak && lines<l) {
if (lines<l) { if (lines<l) {
//eprintf ("RETR %d\n", );
addr += idx; addr += idx;
if (r_core_read_at (core, addr, buf, len) != len) { if (r_core_read_at (core, addr, buf, len) != len) {
//tries = -1; //tries = -1;
@ -1308,7 +1307,7 @@ toro:
r_anal_op_fini (&analop); r_anal_op_fini (&analop);
if (hint) r_anal_hint_free (hint); if (hint) r_anal_hint_free (hint);
free (osl); free (osl);
return idx-lastfail; return idx; //-lastfail;
} }
R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int len) { R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int len) {

View File

@ -291,6 +291,27 @@ R_API void r_core_visual_seek_animation (RCore *core, ut64 addr) {
r_core_seek (core, addr, 1); r_core_seek (core, addr, 1);
} }
static void setprintmode (RCore *core, int n) {
RAnalOp op;
if (n>0) {
core->printidx = R_ABS ((core->printidx+1)%NPF);
} else {
if (core->printidx)
core->printidx--;
else core->printidx = NPF-1;
}
switch (core->printidx) {
case 0:
core->inc = 16;
break;
case 1:
case 2:
core->inc = r_asm_disassemble (core->assembler,
&op, core->block, 32);
break;
}
}
#define OPDELTA 32 #define OPDELTA 32
static int prevopsz (RCore *core, ut64 addr) { static int prevopsz (RCore *core, ut64 addr) {
ut64 target = addr; ut64 target = addr;
@ -629,6 +650,8 @@ r_cons_gotoxy (1,1);
} else { } else {
if (core->printidx == 1 || core->printidx == 2) { if (core->printidx == 1 || core->printidx == 2) {
cols = core->inc; cols = core->inc;
//cols = r_asm_disassemble (core->assembler,
// &op, core->block+cursor, 32);
core->asmsteps[core->curasmstep].offset = core->offset+cols; core->asmsteps[core->curasmstep].offset = core->offset+cols;
core->asmsteps[core->curasmstep].cols = cols; core->asmsteps[core->curasmstep].cols = cols;
if (core->curasmstep < R_CORE_ASMSTEPS-1) if (core->curasmstep < R_CORE_ASMSTEPS-1)
@ -738,12 +761,10 @@ r_cons_gotoxy (1,1);
} }
break; break;
case 'p': case 'p':
core->printidx = R_ABS ((core->printidx+1)%NPF); setprintmode (core, 1);
break; break;
case 'P': case 'P':
if (core->printidx) setprintmode (core, -1);
core->printidx--;
else core->printidx = NPF-1;
break; break;
case 'm': case 'm':
r_core_visual_mark (core, r_cons_readchar ()); r_core_visual_mark (core, r_cons_readchar ());