#ifndef ELFSPY_FAKE_H #define ELFSPY_FAKE_H #include "elfspy/Lambda.h" #include #include #include namespace spy { /** * @namespace spy * @class Fake * This replaces an existing function with another function, so that all calls * to the program are made to the other function. * The constructor installs the new function in place of the function, the * destructor uninstalls it */ template class Fake { public: Fake(H& hook, ReturnType (*func)(ArgTypes...)); ~Fake(); private: H& hook_; ReturnType (*func_)(ArgTypes...); }; template Fake:: Fake(H& hook, ReturnType (*func)(ArgTypes...)) :hook_(hook) { func_ = hook_.patch(func); } /* template Fake::~Fake() { std::cout << "Fake" << std::endl; hook_.patch(func_); } template Fake* new_fake(H& hook, ReturnType (*patch)(ArgTypes...)) { std::cout << "hola" << std::endl; auto instance = new Fake(hook, patch); fake_list.push_back (instance); return instance; } */ } // namespace elfspy #endif