Skip to content

Commit

Permalink
Fix 'invalid' instructions in disassembly (reported by xvilka)
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 13, 2012
1 parent 674c732 commit 23bd67c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions binr/radare2/radare2.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ int main(int argc, char **argv) {
break;
case 'm': mapaddr = r_num_math (r.num, optarg); break;
case 'q':
r_config_set (r.config, "scr.interactive", "false");
r_config_set (r.config, "scr.prompt", "false");
quiet = R_TRUE;
break;
Expand Down
34 changes: 28 additions & 6 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
char *refline = NULL;
RAsmOp asmop;
RAnalOp analop = {0};
int tries = 0;
RFlagItem *flag;
RMetaItem *mi;
ut64 dest = UT64_MAX;
Expand Down Expand Up @@ -245,14 +246,24 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
}
}
// TODO : line analysis must respect data types! shouldnt be interpreted as code
ret = r_asm_disassemble (core->assembler, &asmop, buf+idx, len-idx+5);
ret = r_asm_disassemble (core->assembler, &asmop, buf+idx, len-idx);
if (ret<1) { // XXX: move to r_asm_disassemble ()
ret = 1;
//eprintf ("** invalid opcode at 0x%08"PFMT64x" **\n",
// core->assembler->pc + ret);
lastfail = 1;
strcpy (asmop.buf_asm, "invalid");
sprintf (asmop.buf_hex, "%02x", buf[idx]);
r_cons_printf ("%d %d\n", lines, l);
// HACK protection against 'invalid' false positives
if ((lines+10)<l) {// && (idx+5)<len) {
tries++;
goto retry;
} else {
break;
}
retryback:
ret = 1; // dummy
//if (invbreak) break;
} else {
lastfail = 0;
Expand Down Expand Up @@ -585,7 +596,7 @@ else
r_parse_varsub (core->parser, f,
opstr, strsub, sizeof (strsub));
free (opstr);
opstr = strsub;
opstr = strdup (strsub);
}
}
r_cons_strcat (opstr);
Expand Down Expand Up @@ -715,14 +726,25 @@ else
}

}
if (nbuf == buf)
if (nbuf == buf) {
free (buf);
buf = NULL;
}
if (idx>=len) {// && (invbreak && !lastfail)) {
retry:
if (len<4) len = 4;
buf = nbuf = malloc (len);
if (tries>1) {
addr += 1;
if (r_core_read_at (core, addr, buf, len) != len)
goto retryback;
goto toro;
}
if (invbreak && lines<l) {
if (len<4) len = 4;
buf = nbuf = malloc (len);
addr += idx;
r_core_read_at (core, addr, buf, len);
if (r_core_read_at (core, addr, buf, len) != len) {
tries = -1;
}
goto toro;
}
}
Expand Down

0 comments on commit 23bd67c

Please sign in to comment.