Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cases", "test_cases\test_cases.vcxproj", "{8C444ABC-D25C-4B44-8F27-081B464D9AE4}" | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cases", "test_cases\test_cases.vcxproj", "{8C444ABC-D25C-4B44-8F27-081B464D9AE4}" | ||||
EndProject | EndProject | ||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tester", "tester\tester.vcxproj", "{8182D1BA-E651-4668-9EC1-A3023AAFD5AC}" | 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 | EndProject | ||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
{8182D1BA-E651-4668-9EC1-A3023AAFD5AC}.Release|x64.Build.0 = Release|x64 | {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.ActiveCfg = Release|Win32 | ||||
{8182D1BA-E651-4668-9EC1-A3023AAFD5AC}.Release|x86.Build.0 = 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 | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE |
static Catch::Session session; | static Catch::Session session; | ||||
_declspec(dllexport) void SelfTest() { | |||||
void SelfTest() { | |||||
session.run(); | session.run(); | ||||
} | } | ||||
#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_; | |||||
} | |||||
}; |
#include <Windows.h> | #include <Windows.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <iostream> | |||||
#include "../test_cases/test_cases.h" | #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) { | 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(); | |||||
} | |||||
} | } |
#include <Windows.h> | |||||
#include <cstdint> | |||||
#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; | |||||
} |
#pragma once | |||||
class MHook : public AbstractHookEngine { | |||||
public: | |||||
bool hook_all(); | |||||
bool unhook_all(); | |||||
bool all_hooked(); | |||||
MHook() : AbstractHookEngine("MHook") { | |||||
} | |||||
}; |
<EnableCOMDATFolding>true</EnableCOMDATFolding> | <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||
<OptimizeReferences>true</OptimizeReferences> | <OptimizeReferences>true</OptimizeReferences> | ||||
<GenerateDebugInformation>true</GenerateDebugInformation> | <GenerateDebugInformation>true</GenerateDebugInformation> | ||||
<AdditionalDependencies>test_cases.lib;%(AdditionalDependencies)</AdditionalDependencies> | |||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | |||||
</Link> | </Link> | ||||
</ItemDefinitionGroup> | </ItemDefinitionGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ClCompile Include="main.cpp" /> | <ClCompile Include="main.cpp" /> | ||||
<ClCompile Include="mhook.cpp" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ClInclude Include="abstracthook.h" /> | |||||
<ClInclude Include="mhook.h" /> | |||||
<ClInclude Include="typedefs.h" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<Object Include="..\x64\Debug\cpu.obj" /> | |||||
<Object Include="..\x64\Debug\disasm.obj" /> | |||||
<Object Include="..\x64\Debug\disasm_x86.obj" /> | |||||
<Object Include="..\x64\Debug\mhook.obj" /> | |||||
<Object Include="..\x64\Debug\misc.obj" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||
<ImportGroup Label="ExtensionTargets"> | <ImportGroup Label="ExtensionTargets"> |
<ClCompile Include="main.cpp"> | <ClCompile Include="main.cpp"> | ||||
<Filter>Source Files</Filter> | <Filter>Source Files</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="mhook.cpp"> | |||||
<Filter>Source Files</Filter> | |||||
</ClCompile> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ClInclude Include="typedefs.h"> | |||||
<Filter>Header Files</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="mhook.h"> | |||||
<Filter>Header Files</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="abstracthook.h"> | |||||
<Filter>Header Files</Filter> | |||||
</ClInclude> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<Object Include="..\x64\Debug\mhook.obj" /> | |||||
<Object Include="..\x64\Debug\disasm.obj" /> | |||||
<Object Include="..\x64\Debug\disasm_x86.obj" /> | |||||
<Object Include="..\x64\Debug\misc.obj" /> | |||||
<Object Include="..\x64\Debug\cpu.obj" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
#pragma once | |||||
#include "../test_cases/test_cases.h" | |||||
typedef uint64_t(*TypeSmall)(void); |