wargio / r2dec-js

radare2 plugin - converts asm to pseudo-C code.
514 stars 50 forks source link

[6502] Indirect Addressing incorrect #196

Open thestr4ng3r opened 4 years ago

thestr4ng3r commented 4 years ago

Example:

[0x00000000]> wx a142b1428113913760
[0x00000000]> af
[0x00000000]> pdf
┌ 9: fcn.0 (int8_t arg_100h, int8_t arg_101h);
│           0x00000000      a142           lda (0x42,x)
│           0x00000002      b142           lda (0x42),y
│           0x00000004      8113           sta (0x13,x)
│           0x00000006      9137           sta (0x37),y
└           0x00000008      60             rts

Expected:

/* r2dec pseudo code output */
/* malloc://512 @ 0x0 */
#include <stdint.h>

void fcn_0 () {
    acc = *(*(0x42 + x));
    acc = *((*0x42) + y);
    *(*(0x13 + x)) = acc;
    *((*0x37) + y) = acc;
    return;
}

Actual:

/* r2dec pseudo code output */
/* malloc://512 @ 0x0 */
#include <stdint.h>

void fcn_0 () {
    do {
label_0:
        acc = *(0x42);
        acc += x;
    } while (1);
    acc = *((0x42 + y));
    goto label_0;
    *(0x13) = acc;
    acc += x;
    goto label_0;
    *((0x37 + y)) = acc;
    goto label_0;
    return;
    goto label_0;
}

The gotos and the do/while seem wrong too.

pddi: 6502_pddi.json.gz

wargio commented 4 years ago

it's r2 giving me those jumps. the bug must be in r2