Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Hooking & wrapping of virtual class methods in C++ (gcc/clang/intel ABI only)
- //
- // (C) 2016 by Bueddl <sebastian.buettner@powerserverplus.net>
- //
- #include "hook.hpp"
- #include <iostream>
- class SomeClass
- {
- public:
- virtual ~SomeClass() = default;
- virtual int test_fn(int param)
- {
- std::cout << "Original SomeClass::test_fn()" << std::endl
- << " this = " << this << std::endl
- << " param = " << param << std::endl
- << " -> " << (param * 7) << std::endl;
- return param * 7;
- }
- };
- void some_class_dtor(SomeClass const *_this)
- {
- // Get some stuff done before
- std::cout << "Pre call to SomeClass::~SomeClass()" << std::endl
- << " this = " << _this << std::endl;
- // Get and call orig
- Hook<SomeClass>::call_once<1>(_this);
- // Get some stuff done after
- std::cout << "Post call to SomeClass::~SomeClass()" << std::endl;
- }
- int main()
- {
- // Create object instance
- SomeClass *some_object = new SomeClass;
- // Hook
- Hook<SomeClass>::install<1>(some_object, some_class_dtor);
- // Delete object instance
- delete some_object;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement