diff options
author | Zeex <zeex@rocketmail.com> | 2018-09-06 23:52:15 +0600 |
---|---|---|
committer | Zeex <zeex@rocketmail.com> | 2018-09-06 23:59:35 +0600 |
commit | 6cc020b2fd950264cba0decd7d5d986c8a3fe768 (patch) | |
tree | ea8afee9b6a1ce764941cbc5b47468d72a2a490c /tests/test.cpp | |
parent | 744057d48693974f8da61efe68260b6120cc4ed2 (diff) | |
download | subhook-6cc020b2fd950264cba0decd7d5d986c8a3fe768.zip subhook-6cc020b2fd950264cba0decd7d5d986c8a3fe768.tar.gz subhook-6cc020b2fd950264cba0decd7d5d986c8a3fe768.tar.bz2 |
Rename "options" to "flags"
Diffstat (limited to 'tests/test.cpp')
-rw-r--r-- | tests/test.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test.cpp b/tests/test.cpp new file mode 100644 index 0000000..0eee1fa --- /dev/null +++ b/tests/test.cpp @@ -0,0 +1,75 @@ +#include <iostream> +#include <subhook.h> + +typedef void (*foo_func_t)(); + +#ifdef SUBHOOK_X86 + #if defined SUBHOOK_WINDOWS + #define FOO_CALL __cdecl + #elif defined SUBHOOK_UNIX + #define FOO_CALL __attribute__((cdecl)) + #endif +#else + #define FOO_CALL +#endif + +extern "C" void FOO_CALL foo(); +foo_func_t foo_tr = nullptr; + +void foo_hooked() { + std::cout << "foo_hooked() called" << std::endl;; +} + +void foo_hooked_tr() { + std::cout << "foo_hooked_tr() called" << std::endl; + foo_tr(); +} + +int main() { + std::cout << "Testing initial install" << std::endl; + + subhook::Hook foo_hook((void *)foo, + (void *)foo_hooked, + subhook::HookFlag64BitOffset); + if (!foo_hook.Install()) { + std::cout << "Install failed" << std::endl; + return EXIT_FAILURE; + } + foo(); + if (!foo_hook.Remove()) { + std::cout << "Remove failed" << std::endl; + return EXIT_FAILURE; + } + foo(); + + std::cout << "Testing re-install" << std::endl; + + if (!foo_hook.Install()) { + std::cout << "Install failed" << std::endl; + return EXIT_FAILURE; + } + foo(); + if (!foo_hook.Remove()) { + std::cout << "Remove failed" << std::endl; + return EXIT_FAILURE; + } + foo(); + + std::cout << "Testing trampoline" << std::endl; + + subhook::Hook foo_hook_tr((void *)foo, + (void *)foo_hooked_tr, + subhook::HookFlag64BitOffset); + if (!foo_hook_tr.Install()) { + std::cout << "Install failed" << std::endl; + return EXIT_FAILURE; + } + foo_tr = (foo_func_t)foo_hook_tr.GetTrampoline(); + if (foo_tr == nullptr) { + std::cout << "Failed to build trampoline" << std::endl; + return EXIT_FAILURE; + } + foo(); + + return EXIT_SUCCESS; +} |