rizinorg / rz-retdec

RetDec Decompiler Plugin for Rizin
GNU Lesser General Public License v3.0
28 stars 8 forks source link

[Bug] - Decompiled code not returned for function #9

Open re-fox opened 2 years ago

re-fox commented 2 years ago

An issue exists where there is inconsistent data being returned from rz-retdec (built from latest master). When running retdec independently, the function will decompile properly, however under rizin the function shows no decompiled code.

# rizin -v
rizin 0.5.0 @ linux-x86-64
commit: 9a7567962632fbc2ec612486283df10ca6dad217

When running retdec independently against this sample helloworld.zip , the function function_401030 will return the following decompiled function

// Address range: 0x401030 - 0x401082
int32_t function_401030(uint32_t a1) {
    // 0x401030
    if (a1 <= 0) {
        // 0x401074
        return 0;
    }
    int32_t v1 = 0; // 0x40104f
    int32_t result = 0; // 0x40106c
    int32_t v2; // 0x401030
    int32_t v3 = &v2; // 0x401030
    result += *(int32_t *)v3;
    v1++;
    v3 += 4;
    while (v1 != a1) {
        // 0x40105d
        result += *(int32_t *)v3;
        v1++;
        v3 += 4;
    }
    // 0x401074
    return result;
}

When opening the binary with rizin+rz-retdec, the function returns no decompiled code.

# rizin -A helloworld.exe 
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls
[x] Analyze len bytes of instructions for references
[x] Check for classes
[x] Analyze local variables and arguments
[x] Type matching analysis for all functions
[x] Applied 0 FLIRT signatures via sigdb
[x] Propagate noreturn information
[x] Use -AA or aaaa to perform additional experimental analysis.
 -- Seek at relative offsets with 's +<offset>' or 's -<offset>'
[0x004013f2]> s 0x401030

Printing the function (to show valid assembly)

[0x00401030]> pdf
            ; CALL XREF from main @ 0x401147
┌ fcn.00401030 (int32_t arg_8h, int32_t arg_ch);
│           ; var int32_t var_ch @ ebp-0xc
│           ; var int32_t var_8h @ ebp-0x8
│           ; var int32_t var_4h @ ebp-0x4
│           ; arg int32_t arg_8h @ ebp+0x8
│           ; arg int32_t arg_ch @ ebp+0xc
│           0x00401030      push  ebp
│           0x00401031      mov   ebp, esp
│           0x00401033      sub   esp, 0xc
│           0x00401036      mov   dword [var_ch], 0
│           0x0040103d      lea   eax, [arg_ch]
│           0x00401040      mov   dword [var_4h], eax
│           0x00401043      mov   dword [var_8h], 0
│       ┌─< 0x0040104a      jmp   0x401055
│       │   ; CODE XREF from fcn.00401030 @ 0x401072
│      ┌──> 0x0040104c      mov   ecx, dword [var_8h]
│      ╎│   0x0040104f      add   ecx, 1
│      ╎│   0x00401052      mov   dword [var_8h], ecx
│      ╎│   ; CODE XREF from fcn.00401030 @ 0x40104a
│      ╎└─> 0x00401055      mov   edx, dword [var_8h]
│      ╎    0x00401058      cmp   edx, dword [arg_8h]
│      ╎┌─< 0x0040105b      jge   0x401074
│      ╎│   0x0040105d      mov   eax, dword [var_4h]
│      ╎│   0x00401060      add   eax, 4
│      ╎│   0x00401063      mov   dword [var_4h], eax
│      ╎│   0x00401066      mov   ecx, dword [var_4h]
│      ╎│   0x00401069      mov   edx, dword [var_ch]
│      ╎│   0x0040106c      add   edx, dword [ecx - 4]
│      ╎│   0x0040106f      mov   dword [var_ch], edx
│      └──< 0x00401072      jmp   0x40104c
│       └─> 0x00401074      mov   dword [var_4h], 0
│           0x0040107b      mov   eax, dword [var_ch]
│           0x0040107e      mov   esp, ebp
│           0x00401080      pop   ebp
└           0x00401081      ret

Running rz-retdec

[0x00401030]> pdz
//
// This file was generated by the Retargetable Decompiler
// Website: https://retdec.com
// Copyright (c) Retargetable Decompiler <info@retdec.com>
//

#include <stdint.h>

// ------------------- Function Prototypes --------------------

void fcn_00401030(int32_t arg_ch, int32_t arg_8h);

// ------------------------ Functions -------------------------

// Address range: 0x401030 - 0x401082
void fcn_00401030(int32_t arg_ch, int32_t arg_8h) {
    // 0x401030
    return;
}

// --------------------- Meta-Information ---------------------

// Detected compiler/packer: microsoft
// Detected functions: 1

Other functions (main for example) will decompile

[0x00401030]> s main
[0x004010f0]> pdz
//
// This file was generated by the Retargetable Decompiler
// Website: https://retdec.com
// Copyright (c) Retargetable Decompiler <info@retdec.com>
//

#include <stdint.h>
#include <stdio.h>

// ------------------- Function Prototypes --------------------

void fcn_00401000(int32_t a1, int32_t a2, int32_t a3, int32_t a4, int32_t a5, int32_t a6, int32_t a7, int32_t a8);
void fcn_00401030(int32_t a1, int32_t a2);
void fcn_00401090(int32_t a1, int32_t a2, int32_t a3);
void fcn_00401170(int32_t a1, int32_t a2);
void function_4010f0(void);

// --------------------- Global Variables ---------------------

int32_t g1;

// ------------------------ Functions -------------------------

// Address range: 0x4010f0 - 0x40116f
void function_4010f0(void) {
    // 0x4010f0
    int32_t v1; // 0x4010f0
    fcn_00401090(0, 0, v1);
    fcn_00401000(1, 2, 3, 4, 5, 6, 7, 8);
    fcn_00401170((int32_t)"Sum: %d", (int32_t)&g1);
    fcn_00401030(8, 1);
    fcn_00401170((int32_t)"Variadic Sum: %d", (int32_t)&g1);
    getchar();
}

// --------------- Dynamically Linked Functions ---------------

// int32_t getchar(void);

// --------------------- Meta-Information ---------------------

// Detected compiler/packer: microsoft
// Detected functions: 1