dimanche 3 juillet 2016

c++ class disassembly


I have the following code:

class Base {
public:
int x,y;
Base() { x=10; y=20; }
virtual void myfunction() { }
};

int main() {
Base *b = new Base();
return 0;
}

The disassembly gives me something like:

push 0Ch                ; size of Base
call j_<some giberrish> ; IDA gives the comment "operator new(uint)"
add esp, 4              ; function epilogue
mov [ebp+var_E0], eax

A few lines later you have the constructor being called.

mov ecx, [ebp+var_E0]
call j_Base__Base
mov [ebp+var_F4], eax
  • At first I had thought that var_E0 would contain the pointer to the instance, but now I'm pretty sure that var_F4 does as it contains the return value of the constructor.
  • In that case, what does var_E0 contain at all? Why is it moved into ecx before the constructor is called?

Aucun commentaire:

Enregistrer un commentaire