Browse Source

disable crashing hooks

master
aaaaaa aaaaaaa 6 years ago
parent
commit
d27893167c
3 changed files with 5 additions and 43 deletions
  1. +2
    -40
      tester/main.cpp
  2. +1
    -1
      tester/mhook.cpp
  3. +2
    -2
      tester/polyhook.cpp

+ 2
- 40
tester/main.cpp View File



#include "abstracthook.h" #include "abstracthook.h"



//#pragma comment(lib, "..\\x64\\debug\\test_cases.lib")

extern AbstractHookEngine* g_mhook, extern AbstractHookEngine* g_mhook,
*g_PolyHook, *g_PolyHook,
*g_MinHook; *g_MinHook;


#if 0
typedef BOOL(__stdcall* tBitBlt)(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop);
tBitBlt oBitBlt;

//Just an int that gets incremented to verify handler got called for unit tests

int BitBltHookVerifier = 0;
BOOL __stdcall hkBitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
{
BitBltHookVerifier += 1337;
return oBitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
}

void test()
{
std::shared_ptr<PLH::Detour> Detour_Ex(new PLH::Detour);
//REQUIRE(Detour_Ex->GetType() == PLH::HookType::Detour);

assert(BitBltHookVerifier == 0);
Detour_Ex->SetupHook((uint8_t*)GetProcAddress(LoadLibrary(L"Gdi32.dll"), "BitBlt"), (BYTE*)&hkBitBlt);
assert(Detour_Ex->Hook());
oBitBlt = Detour_Ex->GetOriginal<tBitBlt>();
BitBlt(NULL, 0, 0, 0, 0, NULL, 0, 0, 0);
assert(BitBltHookVerifier == 1337);
Detour_Ex->UnHook();
BitBlt(NULL, 0, 0, 0, 0, NULL, 0, 0, 0);
assert(BitBltHookVerifier == 1337);

std::cout << (Detour_Ex->GetLastError().GetSeverity() != PLH::RuntimeError::Severity::UnRecoverable) << '\n';
std::cout << (Detour_Ex->GetLastError().GetSeverity() != PLH::RuntimeError::Severity::Critical) << '\n';
}
#endif

int main(int argc, char** argv) { int main(int argc, char** argv) {
AbstractHookEngine* engines[] = { AbstractHookEngine* engines[] = {
g_mhook,
g_PolyHook, g_PolyHook,
g_MinHook
g_MinHook,
g_mhook,
}; };


SelfTest(); SelfTest();

+ 1
- 1
tester/mhook.cpp View File

Mhook_Unhook((PVOID*)&trueBranch) && Mhook_Unhook((PVOID*)&trueBranch) &&
Mhook_Unhook((PVOID*)&trueAVX) && Mhook_Unhook((PVOID*)&trueAVX) &&
Mhook_Unhook((PVOID*)&trueRDRAND) && Mhook_Unhook((PVOID*)&trueRDRAND) &&
//Mhook_Unhook((PVOID*)&trueLoop) &&
Mhook_Unhook((PVOID*)&trueLoop) &&
Mhook_Unhook((PVOID*)&trueTailRecursion); Mhook_Unhook((PVOID*)&trueTailRecursion);
} }

+ 2
- 2
tester/polyhook.cpp View File

ret |= hook<decltype(&_AVX)>(detAVX, getAVX(), trueAVX, &PolyHook_Hooks::hookAVX); ret |= hook<decltype(&_AVX)>(detAVX, getAVX(), trueAVX, &PolyHook_Hooks::hookAVX);
ret |= hook<decltype(&_RDRAND)>(detRDRAND, getRDRAND(), trueRDRAND, &PolyHook_Hooks::hookRDRAND); ret |= hook<decltype(&_RDRAND)>(detRDRAND, getRDRAND(), trueRDRAND, &PolyHook_Hooks::hookRDRAND);


ret |= hook<decltype(&_loop)>(detLoop, getLoop(), trueLoop, &PolyHook_Hooks::hookLoop);
ret |= hook<decltype(&_tail_recursion)>(detTailRecursion, getTailRecursion(), trueTailRecursion, &PolyHook_Hooks::hookTail_recursion);
//ret |= hook<decltype(&_loop)>(detLoop, getLoop(), trueLoop, &PolyHook_Hooks::hookLoop);
//ret |= hook<decltype(&_tail_recursion)>(detTailRecursion, getTailRecursion(), trueTailRecursion, &PolyHook_Hooks::hookTail_recursion);


return ret; return ret;
} }

Loading…
Cancel
Save