Browse Source

add backwards mhook tests

master
aaaaaa aaaaaaa 7 years ago
parent
commit
605d03c0f5
4 changed files with 40 additions and 10 deletions
  1. +3
    -0
      tester/abstracthook.h
  2. +24
    -5
      tester/mhook.cpp
  3. +8
    -4
      tester/mhook.h
  4. +5
    -1
      tester/typedefs.h

+ 3
- 0
tester/abstracthook.h View File



bool avx; bool avx;
bool rdrand; bool rdrand;

bool loop;
bool tail_recursion;
}; };
public: public:
AbstractHookEngine(const char* name) : name_(name) { AbstractHookEngine(const char* name) : name_(name) {

+ 24
- 5
tester/mhook.cpp View File

static TypeRip_relative trueRip_Relative = &_rip_relative; static TypeRip_relative trueRip_Relative = &_rip_relative;
static TypeAVX trueAVX = &_AVX; static TypeAVX trueAVX = &_AVX;
static TypeRDRAND trueRDRAND = &_RDRAND; static TypeRDRAND trueRDRAND = &_RDRAND;
static TypeLoop trueLoop = &_loop;
static TypeTailRecursion trueTailRecursion = &_tail_recursion;


AbstractHookEngine* g_mhook = new MHook(); AbstractHookEngine* g_mhook = new MHook();


return trueRip_Relative(); return trueRip_Relative();
} }


void MHook_Hooks::_AVX(float num, void* res) {
void MHook_Hooks::hookAVX(float num, void* res) {
g_mhook->avx = true; g_mhook->avx = true;


return trueAVX(num, res); return trueAVX(num, res);
} }


uint32_t MHook_Hooks::_RDRAND(void) {
uint32_t MHook_Hooks::hookRDRAND(void) {
g_mhook->rdrand = true; g_mhook->rdrand = true;


return trueRDRAND(); return trueRDRAND();
} }


uint32_t MHook_Hooks::hookLoop(uint32_t num, uint32_t cnt) {
g_mhook->loop = true;

return trueLoop(num, cnt);
}

uint32_t MHook_Hooks::hookTail_recursion(uint32_t x) {
g_mhook->tail_recursion = true;

return trueTailRecursion(x);
}

bool MHook::hook_all(void) { bool MHook::hook_all(void) {
bool ret = Mhook_SetHook((PVOID*)&trueSmall, &MHook_Hooks::hookSmall); bool ret = Mhook_SetHook((PVOID*)&trueSmall, &MHook_Hooks::hookSmall);
ret |= Mhook_SetHook((PVOID*)&trueBranch, &MHook_Hooks::hookBranch); ret |= Mhook_SetHook((PVOID*)&trueBranch, &MHook_Hooks::hookBranch);
ret |= Mhook_SetHook((PVOID*)&trueRip_Relative, &MHook_Hooks::hookRip_relative); ret |= Mhook_SetHook((PVOID*)&trueRip_Relative, &MHook_Hooks::hookRip_relative);


ret |= Mhook_SetHook((PVOID*)&trueAVX, &MHook_Hooks::_AVX);
ret |= Mhook_SetHook((PVOID*)&trueRDRAND, &MHook_Hooks::_RDRAND);
ret |= Mhook_SetHook((PVOID*)&trueAVX, &MHook_Hooks::hookAVX);
ret |= Mhook_SetHook((PVOID*)&trueRDRAND, &MHook_Hooks::hookRDRAND);

ret |= Mhook_SetHook((PVOID*)&trueLoop, &MHook_Hooks::hookLoop);
ret |= Mhook_SetHook((PVOID*)&trueTailRecursion, &MHook_Hooks::hookTail_recursion);


return ret; return ret;
} }
return Mhook_Unhook((PVOID*)&trueSmall) && return Mhook_Unhook((PVOID*)&trueSmall) &&
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*)&trueTailRecursion);
} }

+ 8
- 4
tester/mhook.h View File

uint64_t hookSmall(void); uint64_t hookSmall(void);
uint64_t hookBranch(uint64_t); uint64_t hookBranch(uint64_t);
uint64_t hookRip_relative(void); uint64_t hookRip_relative(void);
void _AVX(float num, void* res);
uint32_t _RDRAND(void);
void hookAVX(float num, void* res);
uint32_t hookRDRAND(void);
uint32_t hookLoop(uint32_t num, uint32_t cnt);
uint32_t hookTail_recursion(uint32_t x);
}; };


class MHook : public AbstractHookEngine { class MHook : public AbstractHookEngine {
friend uint64_t MHook_Hooks::hookBranch(uint64_t); friend uint64_t MHook_Hooks::hookBranch(uint64_t);
friend uint64_t MHook_Hooks::hookRip_relative(void); friend uint64_t MHook_Hooks::hookRip_relative(void);
friend void MHook_Hooks::_AVX(float num, void* res);
friend uint32_t MHook_Hooks::_RDRAND(void);
friend void MHook_Hooks::hookAVX(float num, void* res);
friend uint32_t MHook_Hooks::hookRDRAND(void);
friend uint32_t MHook_Hooks::hookLoop(uint32_t num, uint32_t cnt);
friend uint32_t MHook_Hooks::hookTail_recursion(uint32_t x);
}; };

+ 5
- 1
tester/typedefs.h View File



typedef void (*TypeAVX)(float num, void* res); typedef void (*TypeAVX)(float num, void* res);


typedef uint32_t (*TypeRDRAND)(void);
typedef uint32_t (*TypeRDRAND)(void);

typedef uint32_t (*TypeLoop)(uint32_t num, uint32_t cnt);

typedef uint32_t (*TypeTailRecursion)(uint32_t x);

Loading…
Cancel
Save