AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   hook virtual destructor (https://forums.alliedmods.net/showthread.php?t=153270)

PM 03-22-2011 07:45

Re: hook virtual destructor
 
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.


All times are GMT -4. The time now is 19:51.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.