Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include "detours.h"
- #pragma comment(lib, "detours")
- #pragma comment(lib, "winmm")
- static int TickCount;
- static long long PerformanceCount, PerformanceFrequency;
- BOOL DetourFunction(BOOL fStatus, LPVOID* lppvFunction, LPVOID lpvRedirection)
- {
- if (DetourTransactionBegin() != NO_ERROR)
- return FALSE;
- if (DetourUpdateThread(GetCurrentThread()) == NO_ERROR)
- if ((fStatus ? DetourAttach : DetourDetach)(lppvFunction, lpvRedirection) == NO_ERROR)
- if (DetourTransactionCommit() == NO_ERROR)
- return TRUE;
- DetourTransactionAbort();
- return FALSE;
- }
- VOID SetTick()
- {
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
- const int SleepTime = 1;
- float Acceleration = 0.01;
- while (true)
- {
- timeBeginPeriod(1);
- Sleep(SleepTime);
- timeEndPeriod(1);
- TickCount += (int)(SleepTime * Acceleration);
- PerformanceCount += (long long)((SleepTime * PerformanceFrequency / 1000) * Acceleration);
- }
- }
- VOID Exploit()
- {
- typedef DWORD(WINAPI *GetTickCount)();
- static GetTickCount _GetTickCount = reinterpret_cast<GetTickCount>(GetProcAddress(GetModuleHandle(TEXT("KERNELBASE.dll")), "GetTickCount"));
- static decltype(&QueryPerformanceCounter) _QueryPerformanceCounter = QueryPerformanceCounter;
- static decltype(&timeGetTime) _timeGetTime = timeGetTime;
- decltype(&QueryPerformanceCounter) QueryPerformanceCounter__Hook = [](
- LARGE_INTEGER *lpPerformanceCount) -> BOOL
- {
- lpPerformanceCount->QuadPart = PerformanceCount;
- return TRUE;
- };
- decltype(&timeGetTime) timeGetTime__Hook = [](
- ) -> DWORD { return TickCount; };
- GetTickCount GetTickCount__Hook = [](
- ) -> DWORD { return TickCount; };
- LARGE_INTEGER Ref;
- TickCount = _GetTickCount();
- QueryPerformanceFrequency(&Ref);
- PerformanceFrequency = Ref.QuadPart;
- QueryPerformanceCounter(&Ref);
- PerformanceCount = Ref.QuadPart;
- CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&SetTick, NULL, NULL, NULL);
- DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_QueryPerformanceCounter), QueryPerformanceCounter__Hook);
- DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_timeGetTime), timeGetTime__Hook);
- DetourFunction(TRUE, reinterpret_cast<LPVOID*>(&_GetTickCount), GetTickCount__Hook);
- }
- BOOL WINAPI OnAttachProcess( __in HINSTANCE hInstance )
- {
- Exploit();
- return TRUE;
- }
- BOOL WINAPI DllMain(
- __in HINSTANCE hInstance,
- __in DWORD fdwReason,
- __reserved LPVOID lpvReserved )
- {
- UNREFERENCED_PARAMETER( lpvReserved );
- switch ( fdwReason )
- {
- case DLL_PROCESS_ATTACH:
- {
- DisableThreadLibraryCalls( hInstance );
- OnAttachProcess( hInstance );
- return TRUE;
- }
- case DLL_PROCESS_DETACH: { }
- }
- return TRUE;
- }
Add Comment
Please, Sign In to add comment