avast / avast/retdec

Missing information about functions from virtual tables

Open
#202 1 comment 1 reaction 0 assignees View on GitHub
bug C-bin2llvmir P-output T-lang-c++
Dominant language
C++
Stars
8.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

When decompiling the [attached binary](https://github.com/avast-tl/retdec/files/1705849/classes.zip) (the archive includes the original C++ source code), the generated C file does not contain information about functions from virtual tables.

## Input

```
$ retdec-decompiler.sh classes.exe
```

## Output

The generated C source code (`classes.c`) contains the following code:
```c
struct vtable_4096b8_type g2 = {
.e0 = function_407548
};
struct vtable_4096c8_type g3 = {
.e0 = function_407580
};
struct vtable_4096d8_type g4 = {
.e0 = function_4075d0
};
struct vtable_4096e8_type g5 = {
.e0 = function_407620
};
```
However, there is no information about the referenced functions (e.g. `function_407548`). When I looked into the generated LLVM IR (`classes.c.backend.ll`), there are only declarations of these functions, without bodies.

## Expected output

Since the referenced functions are not from the standard library, their body should be included into the generated C source code. The functions correspond to the following virtual member functions from the original C++ source code:
```cpp
class A {
virtual int foo() { return 1; }
};
class B: public A {
virtual int foo() { return 2; }
};
class C: public A {
virtual int foo() { return 3; }
};
class D: public B, public C {
virtual int foo() { return 4; }
};
```

## Configuration

* Commit: 1db0cb6379bd59a4c885b04eac8bf51a6d0f400f (current `master`)
* 64b Arch Linux, GCC 7.2.1, Debug build of RetDec

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with classes.exe from the attached classes.zip using retdec-decompiler.sh, then compare classes.c with classes.c.backend.ll. Trace why the virtual-table functions have declarations but no bodies, and verify completion by confirming the generated C includes the bodies for the referenced non-library functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.