Created
February 18, 2016 12:15
-
-
Save klemens-morgenstern/8b46a8d2c2e6fb3e6bb5 to your computer and use it in GitHub Desktop.
C++ stubbing via --wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//_ZN1X1fEv | |
struct stubs | |
{ | |
typedef void(stubs::*_ZN1X1fEv_t)(); | |
static _ZN1X1fEv_t _ZN1X1fEv_p; | |
template<typename T, typename ... Args> | |
static void set__ZN1X1fEv(void (T::*p)(Args...)) | |
{ | |
_ZN1X1fEv_p = reinterpret_cast<_ZN1X1fEv_t>(p); | |
} | |
static void reset__ZN1X1fEv() { _ZN1X1fEv_p = _ZN1X1fEv_t(0);} | |
void real__ZN1X1fEv() asm("__real__ZN1X1fEv"); | |
void wrap__ZN1X1fEv() asm("__wrap__ZN1X1fEv"); | |
}; | |
stubs::_ZN1X1fEv_t stubs::_ZN1X1fEv_p = 0; | |
void stubs::wrap__ZN1X1fEv() | |
{ | |
if (_ZN1X1fEv_p) | |
(this->*_ZN1X1fEv_p)(); | |
else | |
(this->real__ZN1X1fEv)(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment