avast / avast/retdec

Detection of superClasses for multiple inheritance

Open
#617 1 comment 0 reactions 0 assignees View on GitHub
C-bin2llvmir P-output
Dominant language
C++
Stars
8.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Looking through the json output, it appears that the superclasses are not being detected from instances of __vmi_class_type_info.

This can be recreated with the following diamond inheritance example:

```
class A {
public:
virtual void a_foo() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }

int a_data;
};

class B : virtual public A {
public:
virtual void b_foo() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }

int b_data;
};

class C : virtual public A {
public:
virtual void c_foo() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }

int c_data;
};

class D : public B, public C {
public:
virtual void d_foo() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }

int d_data;
};
```

It yields the following json output:
```
"classes" :
[
{
"constructors" :
[
"_ZN1AC2Ev"
],
"demangledName" : "A",
"destructors" : [],
"methods" : [],
"name" : "1A",
"superClasses" : [],
"virtualMethods" :
[
"_ZN1A5a_fooEv"
],
"virtualTables" :
[
"vtable_6b98"
]
},
{
"constructors" :
[
"_ZN1BC1Ev"
],
"demangledName" : "B",
"destructors" : [],
"methods" : [],
"name" : "1B",
"superClasses" :
[
"1A"
],
"virtualMethods" :
[
"_ZN1B5b_fooEv"
],
"virtualTables" :
[
"vtable_6830",
"vtable_6a80",
"vtable_6b50"
]
},
{
"constructors" :
[
"_ZN1CC1Ev"
],
"demangledName" : "C",
"destructors" : [],
"methods" : [],
"name" : "1C",
"superClasses" :
[
"1A"
],
"virtualMethods" :
[
"_ZN1C5c_fooEv"
],
"virtualTables" :
[
"vtable_6870",
"vtable_6ac0",
"vtable_6b00"
]
},
{
"constructors" :
[
"_ZN1DC1Ev"
],
"demangledName" : "D",
"destructors" : [],
"methods" : [],
"name" : "1D",
"superClasses" : [],
"virtualMethods" :
[
"_ZN1B5b_fooEv",
"_ZN1D5d_fooEv"
],
"virtualTables" :
[
"vtable_69e0"
]
}
]
```

The super class for __si_class_type_info appears to be functional.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the missing superclass metadata with the diamond-inheritance example in the issue, then trace handling of __vmi_class_type_info while generating the JSON classes output. Done means the D entry lists B and C in superClasses, while the existing __si_class_type_info behavior remains functional; add or run a regression check for this output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
reverse-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.