From 3d1dddba12a826dc8e37010f035dc76604b4c9f1 Mon Sep 17 00:00:00 2001 From: aaaaaa aaaaaaa Date: Wed, 27 Dec 2017 13:47:10 +0100 Subject: [PATCH] inital commit of the tester --- hook_tests.sln | 23 +++++++++++++++++++++++ test_cases/main.cpp | 2 +- tester/abstracthook.h | 17 +++++++++++++++++ tester/main.cpp | 19 +++++++++++++++++-- tester/mhook.cpp | 28 ++++++++++++++++++++++++++++ tester/mhook.h | 11 +++++++++++ tester/tester.vcxproj | 15 ++++++++++++++- tester/tester.vcxproj.filters | 21 +++++++++++++++++++++ tester/typedefs.h | 4 ++++ 9 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 tester/abstracthook.h create mode 100644 tester/mhook.cpp create mode 100644 tester/mhook.h create mode 100644 tester/typedefs.h diff --git a/hook_tests.sln b/hook_tests.sln index 509b2ef..61b894f 100644 --- a/hook_tests.sln +++ b/hook_tests.sln @@ -6,6 +6,13 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cases", "test_cases\test_cases.vcxproj", "{8C444ABC-D25C-4B44-8F27-081B464D9AE4}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tester", "tester\tester.vcxproj", "{8182D1BA-E651-4668-9EC1-A3023AAFD5AC}" + ProjectSection(ProjectDependencies) = postProject + {8C444ABC-D25C-4B44-8F27-081B464D9AE4} = {8C444ABC-D25C-4B44-8F27-081B464D9AE4} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhook-test", "third_party\mhook\mhook-test.vcxproj", "{0E055CAF-C68B-42CB-A302-F775CA5A917F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PolyHook", "third_party\poly\PolyHook\PolyHook.vcxproj", "{64269F60-A538-4327-82EE-AB4BF4766CE9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -31,6 +38,22 @@ Global {8182D1BA-E651-4668-9EC1-A3023AAFD5AC}.Release|x64.Build.0 = Release|x64 {8182D1BA-E651-4668-9EC1-A3023AAFD5AC}.Release|x86.ActiveCfg = Release|Win32 {8182D1BA-E651-4668-9EC1-A3023AAFD5AC}.Release|x86.Build.0 = Release|Win32 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Debug|x64.ActiveCfg = Debug|x64 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Debug|x64.Build.0 = Debug|x64 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Debug|x86.ActiveCfg = Debug|Win32 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Debug|x86.Build.0 = Debug|Win32 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Release|x64.ActiveCfg = Release|x64 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Release|x64.Build.0 = Release|x64 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Release|x86.ActiveCfg = Release|Win32 + {0E055CAF-C68B-42CB-A302-F775CA5A917F}.Release|x86.Build.0 = Release|Win32 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Debug|x64.ActiveCfg = Debug|x64 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Debug|x64.Build.0 = Debug|x64 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Debug|x86.ActiveCfg = Debug|Win32 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Debug|x86.Build.0 = Debug|Win32 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Release|x64.ActiveCfg = Release|x64 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Release|x64.Build.0 = Release|x64 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Release|x86.ActiveCfg = Release|Win32 + {64269F60-A538-4327-82EE-AB4BF4766CE9}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test_cases/main.cpp b/test_cases/main.cpp index ca240a3..62e3686 100644 --- a/test_cases/main.cpp +++ b/test_cases/main.cpp @@ -7,7 +7,7 @@ static Catch::Session session; -_declspec(dllexport) void SelfTest() { +void SelfTest() { session.run(); } diff --git a/tester/abstracthook.h b/tester/abstracthook.h new file mode 100644 index 0000000..cc83062 --- /dev/null +++ b/tester/abstracthook.h @@ -0,0 +1,17 @@ +#pragma once +class AbstractHookEngine { +private: + const char* name_; +public: + AbstractHookEngine(const char* name) : name_(name) { + + } + + virtual bool hook_all() = 0; + virtual bool unhook_all() = 0; + virtual bool all_hooked() = 0; + + const char* name() { + return name_; + } +}; \ No newline at end of file diff --git a/tester/main.cpp b/tester/main.cpp index de18b47..eed9162 100644 --- a/tester/main.cpp +++ b/tester/main.cpp @@ -1,9 +1,24 @@ #include #include +#include #include "../test_cases/test_cases.h" -#pragma comment(lib, "..\\x64\\debug\\test_cases.lib") +#include "abstracthook.h" +#include "mhook.h" + +#pragma comment(lib, "..\\x64\\release\\test_cases.lib") + +extern AbstractHookEngine* g_mhook; int main(int argc, char** argv) { - SelfTest(); + AbstractHookEngine* engines[] = { + g_mhook, + }; + + for(auto&& x : engines) { + x->hook_all(); + SelfTest(); + std::cout << x->name() << ':' << x->all_hooked() << '\n'; + x->unhook_all(); + } } \ No newline at end of file diff --git a/tester/mhook.cpp b/tester/mhook.cpp new file mode 100644 index 0000000..cd59c8d --- /dev/null +++ b/tester/mhook.cpp @@ -0,0 +1,28 @@ +#include +#include +#include "../third_party/mhook/mhook-lib/mhook.h" +#include "typedefs.h" +#include "abstracthook.h" +#include "mhook.h" + +#pragma comment(lib, "..\\x64\\debug\\test_cases.lib") + +static TypeSmall trueSmall = &_small; + +AbstractHookEngine* g_mhook = new MHook(); + +static uint64_t hookSmall(void) { + return trueSmall(); +} + +bool MHook::hook_all(void) { + return Mhook_SetHook((PVOID*)&trueSmall, hookSmall); +} + +bool MHook::unhook_all() { + return Mhook_Unhook((PVOID*)&trueSmall); +} + +bool MHook::all_hooked() { + return true; +} \ No newline at end of file diff --git a/tester/mhook.h b/tester/mhook.h new file mode 100644 index 0000000..5369a59 --- /dev/null +++ b/tester/mhook.h @@ -0,0 +1,11 @@ +#pragma once +class MHook : public AbstractHookEngine { +public: + bool hook_all(); + bool unhook_all(); + bool all_hooked(); + + MHook() : AbstractHookEngine("MHook") { + + } +}; \ No newline at end of file diff --git a/tester/tester.vcxproj b/tester/tester.vcxproj index 17aceab..6332917 100644 --- a/tester/tester.vcxproj +++ b/tester/tester.vcxproj @@ -143,11 +143,24 @@ true true true - test_cases.lib;%(AdditionalDependencies) + %(AdditionalDependencies) + + + + + + + + + + + + + diff --git a/tester/tester.vcxproj.filters b/tester/tester.vcxproj.filters index 0d8d9e4..e8c7fe6 100644 --- a/tester/tester.vcxproj.filters +++ b/tester/tester.vcxproj.filters @@ -18,5 +18,26 @@ Source Files + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + + + + + + \ No newline at end of file diff --git a/tester/typedefs.h b/tester/typedefs.h new file mode 100644 index 0000000..3a33f20 --- /dev/null +++ b/tester/typedefs.h @@ -0,0 +1,4 @@ +#pragma once +#include "../test_cases/test_cases.h" + +typedef uint64_t(*TypeSmall)(void); \ No newline at end of file