View Single Post
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 03-22-2011 , 07:45   Re: hook virtual destructor
Reply With Quote #11

I have done some disassembly, and according to
http://www.openrce.org/articles/full_view/23,
MSVC places a "scalar deleting destructor function" into the vtable instead of the destructor.
It has this prototype:
Code:
   virtual void * A::'scalar deleting destructor'(uint flags) {
      ...
   }
This means that you have to hook with
Code:
SH_DECL_MANUALHOOK1_void(TestClass_Vdtor, 0, 0, 0, unsigned int);

// ...
void VdtorHandler(unsigned int flags) {
   void *thisptr = META_IFACEPTR(void);
   // ...
   // Destructor called on thisptr
}

int main() {
	// ...
	SH_MANUALHOOK_RECONFIGURE(TestClass_Vdtor, vtblidx, 0, 0);
	SH_ADD_MANUALHOOK(TestClass_Vdtor, p, SH_STATIC(VdtorHandler), false);
}

Works for me at least, though I don't know if there are cases where it doesn't do this. You can ignore the flags parameter.

I don't know what GCC does for now, I'll look at that over the weekend

Greetings,
PM

EDIT:
1) As BAIL says, the destructor really has to be virtual!
2) I'd like to strongly suggest against superceding the original destructor call.
__________________
hello, i am pm

Last edited by PM; 03-22-2011 at 07:54.
PM is offline