Cromon

Untitled

Aug 15th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include "HookTemplate.h"
  2.  
  3. stdext::Hook < int (__thiscall*)(int) >* fooHook;
  4.  
  5. class Foo
  6. {
  7.     int mValue;
  8. public:
  9.     Foo(int value) : mValue(value) {
  10.  
  11.     }
  12.  
  13.     int foo(int arg) {
  14.         return arg * mValue;
  15.     }
  16. };
  17.  
  18. class Bar
  19. {
  20. public:
  21.     int hookFoo(int arg) {
  22.         int retOrig = fooHook->callOrig(this, arg);
  23.         retOrig *= 2;
  24.  
  25.         return retOrig;
  26.     }
  27. };
  28.  
  29. int main() {
  30.     void* origFoo = stdext::__detail::HookImpl::union_cast<void*>(&Foo::foo);
  31.  
  32.     fooHook = new stdext::Hook < int (__thiscall*) (int) >(origFoo, &Bar::hookFoo);
  33.     fooHook->enable();
  34.  
  35.     Foo* foo = new Foo(5);
  36.     foo->foo(2);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment