Before I tried to hook the entry in my iat, which obviously leads to various dumb failures...
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#include <cstdint>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <Windows.h>
|
|
#include <memory>
|
|
#include "../test_cases/test_cases.h"
|
|
|
|
#include "abstracthook.h"
|
|
|
|
|
|
//#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,
|
|
g_PolyHook,
|
|
g_MinHook
|
|
};
|
|
|
|
SelfTest();
|
|
|
|
for(auto&& x : engines) {
|
|
if (!x->hook_all()) {
|
|
std::cerr << x->name() << " can't hook\n";
|
|
x->unhook_all();
|
|
continue;
|
|
}
|
|
|
|
SelfTest();
|
|
x->unhook_all();
|
|
}
|
|
|
|
std::cout << "+----------+-+-+-+-+-+-+-+" << std::endl <<
|
|
'|' << std::setw(10) << "Name" << std::setw(1) << "|S|B|R|A|?|L|T|" << std::endl <<
|
|
"+----------+-+-+-+-+-+-+-+" << std::endl;
|
|
for (auto&& x : engines) {
|
|
std::cout << *x << std::endl;
|
|
}
|
|
std::cout << "+----------+-+-+-+-+-+-+-+" << std::endl;
|
|
} |