9

I am planning to do some reverse engineering on an application that was written in a object oriented way. And now I'm kind of curious what a C++ class would look like in assembly. I already found out the basics about functions and their calling conventions. But classes are probably way more complex, right?

So let's say we have this class:

class Rectangle {
    int width, height;
  public:
    void set_values (int,int);
    int area() {return width*height;}
};

void Rectangle::set_values (int x, int y) {
  width = x;
  height = y;
}

and this object:

Rectangle rect;
rect.set_values (3,4);

What would/could it look like in assembly?

Forivin
  • 209
  • 2
  • 6

1 Answers1

8

As discussed in https://reverseengineering.stackexchange.com/a/5957/1562, it's compiler-dependent (different compilers will generate different machine code and data structures).

However, you may want to refer to Reversing C++, as it does a pretty good job showing how most compilers compile C++ classes.

Jason Geffner
  • 20,681
  • 1
  • 36
  • 75
  • 2
    The reversing C++ paper is invaluable. –  Nov 03 '17 at 13:20
  • In the microsoft x64 convention where RCX, RDX, R8, R9 are used are arguments, is RCX still used by c++ for the this pointer ? – Herz3h Jul 13 '21 at 18:47