6

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?

  • even for simple C code, the assembly output depends on compiler and compiler options. To see how the output is in various compilers, use GCC Godbolt compiler explorer – phuclv Oct 8 '15 at 16:55
5

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.

  • The reversing C++ paper is invaluable. – Jacob Persi Nov 3 '17 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.