Shrooms

Untitled

Mar 21st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "detours.h"
  3. #pragma comment(lib, "detours")
  4. #pragma comment(lib, "winmm")
  5.  
  6. static int TickCount;
  7. static long long PerformanceCount, PerformanceFrequency;
  8.  
  9. BOOL DetourFunction(BOOL fStatus, LPVOID* lppvFunction, LPVOID lpvRedirection)
  10. {
  11. if (DetourTransactionBegin() != NO_ERROR)
  12. return FALSE;
  13.  
  14. if (DetourUpdateThread(GetCurrentThread()) == NO_ERROR)
  15. if ((fStatus ? DetourAttach : DetourDetach)(lppvFunction, lpvRedirection) == NO_ERROR)
  16. if (DetourTransactionCommit() == NO_ERROR)
  17. return TRUE;
  18.  
  19. DetourTransactionAbort();
  20. return FALSE;
  21. }
  22.  
  23. VOID SetTick()
  24. {
  25. SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  26. const int SleepTime = 1;
  27. float Acceleration = 0.01;
  28.  
  29. while (true)
  30. {
  31. timeBeginPeriod(1);
  32. Sleep(SleepTime);
  33. timeEndPeriod(1);
  34.  
  35. TickCount += (int)(SleepTime * Acceleration);
  36. PerformanceCount += (long long)((SleepTime * PerformanceFrequency / 1000) * Acceleration);
  37. }
  38. }
  39.  
  40. VOID Exploit()
  41. {
  42. typedef DWORD(WINAPI *GetTickCount)();
  43. static GetTickCount _GetTickCount = reinterpret_cast<GetTickCount>(GetProcAddress(GetModuleHandle(TEXT("KERNELBASE.dll")), "GetTickCount"));
  44. static decltype(&QueryPerformanceCounter) _QueryPerformanceCounter = QueryPerformanceCounter;
  45. static decltype(&timeGetTime) _timeGetTime = timeGetTime;
  46.  
  47. decltype(&QueryPerformanceCounter) QueryPerformanceCounter__Hook = [](
  48. LARGE_INTEGER *lpPerformanceCount) -> BOOL
  49. {
  50. lpPerformanceCount->QuadPart = PerformanceCount;
  51. return TRUE;
  52. };
  53.  
  54. decltype(&timeGetTime) timeGetTime__Hook = [](
  55. ) -> DWORD { return TickCount; };
  56.  
  57. GetTickCount GetTickCount__Hook = [](
  58. ) -> DWORD { return TickCount; };
  59.  
  60. LARGE_INTEGER Ref;
  61. TickCount = _GetTickCount();
  62. QueryPerformanceFrequency(&Ref);
  63. PerformanceFrequency = Ref.QuadPart;
  64.  
  65. QueryPerformanceCounter(&Ref);
  66. PerformanceCount = Ref.QuadPart;
  67.  
  68. CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&SetTick, NULL, NULL, NULL);
  69.  
  70. DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_QueryPerformanceCounter), QueryPerformanceCounter__Hook);
  71. DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_timeGetTime), timeGetTime__Hook);
  72. DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_GetTickCount), GetTickCount__Hook);
  73. }
  74.  
  75. BOOL WINAPI OnAttachProcess( __in HINSTANCE hInstance )
  76. {
  77. Exploit();
  78.  
  79. return TRUE;
  80. }
  81.  
  82. BOOL WINAPI DllMain(
  83. __in HINSTANCE hInstance,
  84. __in DWORD fdwReason,
  85. __reserved LPVOID lpvReserved )
  86. {
  87. UNREFERENCED_PARAMETER( lpvReserved );
  88.  
  89. switch ( fdwReason )
  90. {
  91. case DLL_PROCESS_ATTACH:
  92. {
  93. DisableThreadLibraryCalls( hInstance );
  94.  
  95. OnAttachProcess( hInstance );
  96.  
  97. return TRUE;
  98. }
  99. case DLL_PROCESS_DETACH: { }
  100. }
  101.  
  102. return TRUE;
  103. }
Add Comment
Please, Sign In to add comment