wargio / r2dec-js

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

Parsing fixes for riscv64: lui, loads #285

Closed strlcat closed 1 year ago

strlcat commented 1 year ago

lui decompilation is wrong:

l{d,w,h,b}[u] decompilation is wrong:

strlcat commented 1 year ago

Please note that these are quick & dirty fixes by person inexperienced with js, to make it work and be less annoying when decompilation & translation process goes.

wargio commented 1 year ago

do you have a test? you can generate it using pddi

strlcat commented 1 year ago

do you have a test? you can generate it using pddi

This generates a really long single line, potentially with sensitive data included about my project. How shall I proceed? The machine it runs on is same as reversed binary, i.e. riscv64.

strlcat commented 1 year ago

I generated one for random riscv64 binary on my system here: https://rys.strlcat.eu/pddi.json.xz

wargio commented 1 year ago

I generated one for random riscv64 binary on my system here: https://rys.strlcat.eu/pddi.json.xz

i get a 403. can you just upload it here?

strlcat commented 1 year ago

There's still problem with construct like:

lui a4, 0x80010
sw a4, 8(s0)

gives me

a4 = 0x0;
*((s0 + 0x8)) = a4;

but shall be

a4 = 0x80010000;
*((s0 + 0x8)) = a4;

(if assuming uint32_t, I don't know how typing here works, for uint64_t it shall produce 0xffffffff80010000) I don't know how to solve it right now, so notifying you.

wargio commented 1 year ago

true. the sign should extend