Cannot decompile passing structs (especially stack-allocated ones) into functions
- Dominant language
- C++
- Stars
- 8.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
```c
#include
const char alphabet[]="abcdefjhijklmopqrtuvwxyz\n"; // not decompiled at all!
struct bar{
int a;
char b;
float c;
double d;
};
struct baz{
char b;
int a;
double d;
float c;
const char * e;
};
struct foo{
struct bar a;
struct baz b;
};
void func(struct foo a){
printf(a.b.e);
}
int main(){
struct foo a;
a.b.e=alphabet;
func(a);
return 0;
}
```
The best-possible conditions (clang compiler (it seems llvm-based retdec has difficulties with gcc-generated machine code), 64-bit, `-O0`, `-ggdb`, `--backend-aggressive-opts` in retdec call).
```c
#include
#include
typedef int64_t int128_t;
void func(int64_t a);
void func(int64_t a) {
int64_t v1 = 0x401120; // 0x401130
int64_t v2 = 0x4010f0; // 0x401130
int64_t v3 = 0; // 0x401130
char v4 = 0; // bp+404030, 0x401130
int32_t v5; // 0x401130
// 0x401130
char * format; // 0x401130
printf(format);
}
int main() {
int64_t v1; // 0x401150
int64_t v2; // 0x401150
int64_t v3; // 0x401150
char v4; // bp+404030, 0x401150
// 0x401150
int64_t v5; // 0x401150
int128_t v6 = __asm_movups((int128_t)v5); // 0x40117b
int128_t v7; // 0x401150
int128_t v8 = __asm_movups(v7); // 0x40117f
__asm_movups_1(v7, __asm_movups(v7));
__asm_movups_1(v7, v8);
__asm_movups_1(0, v6);
func(v5);
int32_t v9; // 0x401150
return (int32_t)&v9 ^ (int32_t)&v9;
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling the supplied C reproducer with clang at -O0 and -ggdb, then run RetDec with --backend-aggressive-opts and compare the decompilation of func and main. The issue is done when the stack-allocated structs passed to functions and the alphabet data are recovered as meaningful C rather than unrelated scalar and intrinsic variables.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers, reverse-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100