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;
eprintf ("Usage: pd[f|i|l] [len] [arch] [bits] @ [addr]\n"
//TODO: eprintf (" pdr : disassemble resume\n");
" pda : disassemble all possible opcodes (byte per byte)\n"
" pdj : disassemble to json\n"
" pdb : disassemble basic block\n"
" pdr : recursive disassemble across the function graph\n"
" pdf : disassemble function\n"
" pdi : like 'pi', with offset and bytes\n"
" pdl : show instruction sizes\n"
" pds : disassemble with back sweep (greedy disassembly backwards)\n");
" pda disassemble all possible opcodes (byte per byte)\n"
" pdj disassemble to json\n"
" pdb disassemble basic block\n"
" pdr recursive disassemble across the function graph\n"
" pdf disassemble function\n"
" pdi like 'pi', with offset and bytes\n"
" pdn disassemble N bytes (like pdi)\n"
" pdl show instruction sizes\n"
" pds disassemble with back sweep (greedy disassembly backwards)\n");
pd_result = 0;
}
if (!processed_cmd) {
@ -1046,7 +1047,6 @@ static int cmd_print(void *data, const char *input) {
ut8 *block = malloc (core->blocksize);
if (block && bw_disassemble) {
l = -l;
if (block) {
if (*input == 'D'){
@ -1076,22 +1076,30 @@ static int cmd_print(void *data, const char *input) {
ut64 idx = 0;
RAsmOp asmop;
// XXX: issue with small blocks
for (i=0; i < use_blocksize; i++ ) {
ut64 addr = core->offset + idx;
ut64 addr = core->offset + i;
r_core_read_at (core, addr,
block, core->blocksize);
if (*input == 'D') {
core->num->value = r_core_print_disasm (core->print,
core, addr, block, core->blocksize, l, 0, 1);
idx++;
r_cons_printf ("------\n");
// l must be smaller than blocksize
if (l>=core->blocksize) {
eprintf ("Invalid length\n");
} else {
core->num->value = r_core_print_disasm (core->print,
core, addr, block, l, l, 0, 1);
}
break;
} else {
/*
ut32 disasm_len = r_asm_disassemble (core->assembler, &asmop, block,
core->blocksize);
if (disasm_len == 0) disasm_len++;
*/
core->num->value = r_core_print_disasm (core->print,
core, addr, block, disasm_len, l, 0, 1);
idx += disasm_len;
core, addr, block, l, l, 0, 0);
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;
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);
// TODO: import values from debugger is possible
@ -373,8 +373,9 @@ toro:
r_core_seek_archbits (core, at); // slow but safe
hint = r_core_hint_begin (core, hint, at);
if (cbytes && idx>=l)
if (!cbytes && idx>=l) {
break;
}
r_asm_set_pc (core->assembler, at);
if (show_lines) {
line = r_anal_reflines_str (core, at, linesopts);
@ -540,7 +541,7 @@ toro:
// core->assembler->pc + ret, l, len);
#if HASRETRY
//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);
addr = core->assembler->pc;
tries--;
@ -1288,9 +1289,7 @@ toro:
goto toro;
}
}
//if (invbreak && lines<l) {
if (lines<l) {
//eprintf ("RETR %d\n", );
addr += idx;
if (r_core_read_at (core, addr, buf, len) != len) {
//tries = -1;
@ -1308,7 +1307,7 @@ toro:
r_anal_op_fini (&analop);
if (hint) r_anal_hint_free (hint);
free (osl);
return idx-lastfail;
return idx; //-lastfail;
}
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);
}
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
static int prevopsz (RCore *core, ut64 addr) {
ut64 target = addr;
@ -629,6 +650,8 @@ r_cons_gotoxy (1,1);
} else {
if (core->printidx == 1 || core->printidx == 2) {
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].cols = cols;
if (core->curasmstep < R_CORE_ASMSTEPS-1)
@ -738,12 +761,10 @@ r_cons_gotoxy (1,1);
}
break;
case 'p':
core->printidx = R_ABS ((core->printidx+1)%NPF);
setprintmode (core, 1);
break;
case 'P':
if (core->printidx)
core->printidx--;
else core->printidx = NPF-1;
setprintmode (core, -1);
break;
case 'm':
r_core_visual_mark (core, r_cons_readchar ());