Files
hook_tests/tester/abstracthook.h
aaaaaa aaaaaaa f1ec585409 use exact address for hooking
Before I tried to hook the entry in my iat, which obviously leads to various
dumb failures...
2018-01-08 18:42:35 +01:00

64 lines
1.9 KiB
C++

#pragma once
class AbstractHookEngine {
private:
const char* name_;
public:
static void* getSmall() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_small")); }
static void* getBranch() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_branch")); }
static void* getRipRelative() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_rip_relative")); }
static void* getAVX() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_AVX")); }
static void* getRDRAND() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_RDRAND")); }
static void* getLoop() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_loop")); }
static void* getTailRecursion() { return (void*)(GetProcAddress(LoadLibrary(L"test_cases.dll"), "_tail_recursion")); }
public:
/* boolean for each hook test case, which are set by the hooks */
struct {
bool small_;
bool branch;
bool rip_relative;
bool avx;
bool rdrand;
bool loop;
bool tail_recursion;
};
public:
AbstractHookEngine(const char* name) :
name_(name),
small_(false),
branch(false),
rip_relative(false),
avx(false),
rdrand(false),
loop(false),
tail_recursion(false)
{
}
virtual bool hook_all() = 0;
virtual bool unhook_all() = 0;
bool all_hooked() const {
return small_ && branch && rip_relative && avx && rdrand && loop && tail_recursion;
}
const char* name() const {
return name_;
}
friend std::ostream& operator<< (std::ostream& stream, const AbstractHookEngine& eng) {
std::cout << '|' << std::setw(10) << eng.name() << std::setw(1) << '|' <<
(eng.small_ ? 'X' : ' ') << '|' <<
(eng.branch ? 'X' : ' ') << '|' <<
(eng.rip_relative ? 'X' : ' ') << '|' <<
(eng.avx ? 'X' : ' ') << '|' <<
(eng.rdrand ? 'X' : ' ') << '|' <<
(eng.loop ? 'X' : ' ') << '|' <<
(eng.tail_recursion ? 'X' : ' ') << '|';
return stream;
}
};