You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5KB

  1. #include <Windows.h>
  2. #include <cstdint>
  3. #include "../third_party/mhook/mhook-lib/mhook.h"
  4. #include "typedefs.h"
  5. #include "abstracthook.h"
  6. #include "mhook.h"
  7. #pragma comment(lib, "..\\x64\\debug\\test_cases.lib")
  8. static TypeSmall trueSmall = &_small;
  9. static TypeBranch trueBranch = &_branch;
  10. static TypeRip_relative trueRip_Relative = &_rip_relative;
  11. static TypeAVX trueAVX = &_AVX;
  12. static TypeRDRAND trueRDRAND = &_RDRAND;
  13. AbstractHookEngine* g_mhook = new MHook();
  14. uint64_t MHook_Hooks::hookSmall(void) {
  15. g_mhook->small_ = true;
  16. return trueSmall();
  17. }
  18. uint64_t MHook_Hooks::hookBranch(uint64_t x) {
  19. g_mhook->branch = true;
  20. return trueBranch(x);
  21. }
  22. uint64_t MHook_Hooks::hookRip_relative(void) {
  23. g_mhook->rip_relative = true;
  24. return trueRip_Relative();
  25. }
  26. void MHook_Hooks::_AVX(float num, void* res) {
  27. g_mhook->avx = true;
  28. return trueAVX(num, res);
  29. }
  30. uint32_t MHook_Hooks::_RDRAND(void) {
  31. g_mhook->rdrand = true;
  32. return trueRDRAND();
  33. }
  34. bool MHook::hook_all(void) {
  35. bool ret = Mhook_SetHook((PVOID*)&trueSmall, &MHook_Hooks::hookSmall);
  36. ret |= Mhook_SetHook((PVOID*)&trueBranch, &MHook_Hooks::hookBranch);
  37. ret |= Mhook_SetHook((PVOID*)&trueRip_Relative, &MHook_Hooks::hookRip_relative);
  38. ret |= Mhook_SetHook((PVOID*)&trueAVX, &MHook_Hooks::_AVX);
  39. ret |= Mhook_SetHook((PVOID*)&trueRDRAND, &MHook_Hooks::_RDRAND);
  40. return ret;
  41. }
  42. bool MHook::unhook_all() {
  43. return Mhook_Unhook((PVOID*)&trueSmall) &&
  44. Mhook_Unhook((PVOID*)&trueBranch) &&
  45. Mhook_Unhook((PVOID*)&trueAVX) &&
  46. Mhook_Unhook((PVOID*)&trueRDRAND);
  47. }