#ifndef ELFSPY_FAKE_H #define ELFSPY_FAKE_H #include "elfspy/Lambda.h" #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 */ class FakeI { }; extern std::vector> fake_list; template class Fake : FakeI { public: Fake(H& hook, ReturnType (*func)(ArgTypes...)); ~Fake(); private: H& hook_; ReturnType (*func_)(ArgTypes...); }; template inline Fake:: Fake(H& hook, ReturnType (*func)(ArgTypes...)) :hook_(hook) { func_ = hook_.patch(func); } template inline Fake::~Fake() { hook_.patch(func_); } template inline auto new_fake(H& hook, ReturnType (*patch)(ArgTypes...)) -> Fake* { auto instance = std::make_shared>(hook, patch); fake_list.push_back (instance); return instance; } } // namespace elfspy #endif