Total Articles 180
[CPP] - ECX register is used for object pointer.
class Base
{
public:
Base()
{
foo(); mov ecx,dword ptr [this] // ecx <- object pointer
call Base::foo (4111A9h) // direct call
}
virtual void foo() {
}
};
[Pascal] - EAX register is used for object pointer.
Base = class
public constructor Create; destructor Destroy; override; procedure foo; virtual; end; constructor Base.Create; begin foo; mov eax,esi // eax <- object pointer mov edx,[eax] // edx <- virtual method pointer table call dword ptr [edx] // indirect call(first virtual method pointer) end;
In constructor code in C++, even if a function is declared as virtual, the function is called in direct mode(not indirect mode) because virtual table of that object is not set yet. So does in destructor codes.
[Download]
[C++]
When new is called : malloc > constructor codes called > virtual function table setting.
When delete is called : destructor codes called > free.
[Pascal]
When Create is called : GetMem > virtual function table setting > constructor codes called.
When Destroy is called : destuctor codes called > FreeMem.