question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deduce base class function types/names from inheriting ones

See original GitHub issue
struct Bar {
        virtual int a(int x) = 0;
        virtual int b(double x, double y) = 0;
        virtual int get() = 0;
};

struct Foo : public Bar {
        int a(int ax) override {
                x = ax;
                return x;
        }
        int b(double ax, double ay) override {
                x = ax;
                y = ay;
                return y;
        }
        virtual int get() {
                return y;
        }
        int x;
        int y;
};

int main() {
        Bar* b = new Foo;
        b->a(4);
        b->b(6, 7);
        return b->get();
}

is currently decompiled as:

void main(void)

{
  code *pcVar1;
  Foo *this;
  
  this = (Foo *)operator.new(0x10);
  Foo::Foo(this);
  pcVar1 = (code *)((this->super_Bar)._vptr)->__cxa_pure_virtual;
  (*pcVar1)(this,4,pcVar1);
  (*(code *)((this->super_Bar)._vptr)->__cxa_pure_virtual)
            (0x4018000000000000,0x401c000000000000,this);
  (*(code *)((this->super_Bar)._vptr)->__cxa_pure_virtual)(this);
  return;
}

It should be possible to improve the info in the Bar vtable struct by using the types and names from the Foo vtable struct.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jrmuizelcommented, Sep 15, 2021

I filed a similar issue for Ghidra’s class recovery script: https://github.com/NationalSecurityAgency/ghidra/issues/3417

2reactions
astrelskycommented, Jan 14, 2021

Hey @astrelsky, have you done any work on this at all? I’d be happy to have a go at this and also maybe making the ClassTypeInfo window show the vftable entries of the class being looked at.

I haven’t done so yet. You are more then welcome to give it a shot. Collecting all the abstract classes and using ClassTypeInfo::isAbstract as a filter should give you a head start.

hashCode is implemented using the typename’s hashCode but if you want to use a red black based collection I’d recommend using (a, b) -> Long.compare(a.getKey(), b.getKey()) as the comparator. getKey comes from DatabaseObject::getKey

Those are the only thoughts I’ve had yet. I started setting up nodes for the graphing but vscode kept “not responding” so I stopped working on Java stuff until it is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecoverClassesFromRTTIScript: Deduce base class function ...
The script currently only figures out which class the functions in the vftable originated in if they are inherited.
Read more >
Deduce parent class of inherited method in C++ - Stack Overflow
If I understand the problem correctly, it is possible to deduce the class a member function is defined in, using the following trait:...
Read more >
17.7 — Calling inherited functions and overriding behavior
By default, derived classes inherit all of the behaviors defined in a base class. In this lesson, we'll examine in more detail how...
Read more >
Ghidra-Cpp-Class-Analyzer - Bountysource
Ghidra C++ Class and Run Time Type Information Analyzer. Become a Bounty Hunter ... Deduce base class function types/names from inheriting ones $...
Read more >
Car class java
Write a Java program for creating one base class for student personal details ... Method references can make the language more compact and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found