use exact address for hooking

Before I tried to hook the entry in my iat, which obviously leads to various
dumb failures...
This commit is contained in:
2018-01-08 18:42:35 +01:00
parent bce85be82e
commit f1ec585409
6 changed files with 72 additions and 27 deletions

View File

@@ -1,17 +1,54 @@
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <memory>
#include "../test_cases/test_cases.h"
#include "abstracthook.h"
#include "mhook.h"
#pragma comment(lib, "..\\x64\\debug\\test_cases.lib")
//#pragma comment(lib, "..\\x64\\debug\\test_cases.lib")
extern AbstractHookEngine* g_mhook,
*g_PolyHook,
*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) {
AbstractHookEngine* engines[] = {
g_mhook,