r2dec-js icon indicating copy to clipboard operation
r2dec-js copied to clipboard

r2dec generates `if-else-else` block

Open mytbk opened this issue 6 years ago • 1 comments

The following assembly code can make r2dec generate a if-else-else block:

L0:
test esi, esi
jne L2
cmp eax, 1
jne short L3
jmp short L4

L3:
cmp eax, 2
jne short L2
jmp L6

L2:
inc eax

L4:
xor eax, eax
L6:
ret
$ nasm -f elf test.asm; r2 -q -c 'aa;pdd' test.o
WARNING: Cannot initialize program headers
WARNING: Cannot initialize dynamic strings
WARNING: Cannot initialize dynamic section
Warning: run r2 with -e io.cache=true to fix relocations in disassembly
/* r2dec pseudo C output */
#include <stdint.h>
 
int32_t entry0 (void) {
    /* [01] -r-x section size 22 named .text */
    if (esi == 0) {
        if (eax == 1) {
        } else {
            if (eax == 2) {
            }
        } else {
            eax++;
        }
        eax = 0;
    }
    return eax;
}

mytbk avatar Dec 19 '18 15:12 mytbk

oh :( i'll try to fix it.

wargio avatar Dec 19 '18 17:12 wargio