Raised This Month: $130 Target: $400

hook virtual destructor

Post New Thread Reply   
Thread Tools Display Modes
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
MSVC places a "scalar deleting destructor function" into the vtable instead of the destructor.
It has this prototype:
   virtual void * A::'scalar deleting destructor'(uint flags) {
This means that you have to hook with
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


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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 09:44.

Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode