Exemple #1
0
BOOL APIENTRY DllMain( HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
	)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hDll = hModule;
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)CopyCreateFileW, Bio_CreateFileW);
		DetourAttach(&(PVOID&)CopyMoveFileW, Bio_MoveFileW);
		DetourAttach(&(PVOID&)CopyDeleteFileW, Bio_DeleteFileW);
		DetourAttach(&(PVOID&)CopyRemoveDirectoryW, Bio_RemoveDirectoryW);
		DetourAttach(&(PVOID&)CopyMessageBoxW, Bio_MessageBoxW);
		DetourTransactionCommit();
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)CopyCreateFileW, Bio_CreateFileW);
		DetourDetach(&(PVOID&)CopyMoveFileW, Bio_MoveFileW);
		DetourDetach(&(PVOID&)CopyDeleteFileW, Bio_DeleteFileW);
		DetourDetach(&(PVOID&)CopyRemoveDirectoryW, Bio_RemoveDirectoryW);
		DetourDetach(&(PVOID&)CopyMessageBoxW, Bio_MessageBoxW);
		DetourTransactionCommit();
		break;
	}
	return TRUE;
}
Exemple #2
0
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved) {
	if (DetourIsHelperProcess()) {
		return TRUE;
	}
	
	char buffer[100];
	if (dwReason == DLL_PROCESS_ATTACH) {
		OutputDebugString("Hooking");	
		DetourRestoreAfterWith();

		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());		
		oldDirectInput8Create = (HRESULT(WINAPI *)(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID * ppvOut, LPUNKNOWN punkOuter))DetourFindFunction("dinput8.dll", "DirectInput8Create");
		sprintf_s(buffer, 100, "DirectInput8Create at %x", oldDirectInput8Create);
		OutputDebugString(buffer);
		if(oldDirectInput8Create == NULL)
			OutputDebugString("Failed to find function");
		int error = DetourAttach(&(PVOID&)oldDirectInput8Create, myDirectInput8Create);
		if(error != NO_ERROR)
			OutputDebugString("Failed to detour");
		error = DetourTransactionCommit();
		if(error != NO_ERROR)
			OutputDebugString("Failed to commit");
	}
	else if (dwReason == DLL_PROCESS_DETACH) {
		OutputDebugString("Unhooking");
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)oldDirectInput8Create, myDirectInput8Create);
		DetourDetach(&(PVOID&)oldCreateDevice, myCreateDevice);
		DetourDetach(&(PVOID&)oldGetDeviceState, myGetDeviceState);
		DetourTransactionCommit();
	}
	return TRUE;
}
static VOID UnModifyFunction()
{
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourDetach(&(PVOID&)TrueExtTextOutW, SUIExtTextOutW);
	DetourDetach(&(PVOID&)TrueTextOutW, SUITextOutW);
	DetourTransactionCommit();
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
    LONG error;
    (void)hinst;
    (void)reserved;

    if (DetourIsHelperProcess()) {
        return TRUE;
    }

    if (dwReason == DLL_PROCESS_ATTACH) {
        DetourRestoreAfterWith();

        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Starting.\n");
        Verify("SleepEx", (PVOID)SleepEx);
        printf("\n");
        fflush(stdout);

        // NB: DllMain can't call LoadLibrary, so we hook the app entry point.
        TrueEntryPoint = (int (WINAPI *)(VOID))DetourGetEntryPoint(NULL);
        RawEntryPoint = TrueEntryPoint;

        Verify("EntryPoint", RawEntryPoint);

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID&)TrueEntryPoint, TimedEntryPoint);
        error = DetourTransactionCommit();

        Verify("EntryPoint after attach", RawEntryPoint);
        Verify("EntryPoint trampoline", TrueEntryPoint);

        if (error == NO_ERROR) {
            printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
                   " Detoured EntryPoint().\n");
        }
        else {
            printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
                   " Error detouring EntryPoint(): %d\n", error);
        }
    }
    else if (dwReason == DLL_PROCESS_DETACH) {
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        if (TrueSleepEx != NULL) {
            DetourDetach(&(PVOID&)TrueSleepEx, (PVOID)TimedSleepEx);
        }
        DetourDetach(&(PVOID&)TrueEntryPoint, TimedEntryPoint);
        error = DetourTransactionCommit();

        printf("dslept" DETOURS_STRINGIFY(DETOURS_BITS) ".dll: "
               " Removed Sleep() detours (%d), slept %d ticks.\n", error, dwSlept);

        fflush(stdout);
    }
    return TRUE;
}
bool Hooks::DetachHooks() {
    LONG error = 0;
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    error |= DetourDetach((void**)&Hooks::orgConnection_t_Send, Hooks::Connection_t_SendHook);
    error |= DetourDetach((void**)&Hooks::orgDataBlockToMessage, Hooks::DataBlockToMessageHook);
    error |= DetourTransactionCommit();
    return error == 0;
}
void DehookMemory()
{
	//DetourDetach((void**)&OLD_0042C840, TEST_0042C840);
	//DetourDetach((void**)&OLD_0042C870, TEST_0042C870);
	//DetourDetach((void**)&OLD_00BE70B0, TEST_00BE70B0);
	DetourDetach((void**)HookHeap::_Allocate_GetPtr(), (void*)GetFnAddr(&HookHeap::Allocate));
	DetourDetach((void**)UnkHeapStruct1::_Unknown00436740_GetPtr(), (void*)GetFnAddr(&UnkHeapStruct1::TEST_00436740));
	DetourDetach((void**)UnkRCManager::_WaitForRun_GetPtr(), (void*)GetFnAddr(&UnkRCManager::WaitForRun));
	DetourDetach((void**)hkSkyrimMemoryAllocator::_blockAlloc_GetPtr(), (void*)GetFnAddr(&hkSkyrimMemoryAllocator::blockAllocGuard));
	DetourDetach((void**)hkSkyrimMemoryAllocator::_blockFree_GetPtr(), (void*)GetFnAddr(&hkSkyrimMemoryAllocator::blockFreeGuard));
}
Exemple #7
0
void Hooker::Unhook()
{
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());

	DetourDetach(&(PVOID&)Real_TextOutA,Fake_TextOutA);
	DetourDetach(&(PVOID&)Real_TextOutW,Fake_TextOutW);
	DetourDetach(&(PVOID&)Real_ExtTextOutA,Fake_ExtTextOutA);
	DetourDetach(&(PVOID&)Real_ExtTextOutW,Fake_ExtTextOutW);

    DetourTransactionCommit();
}
bool CComManager::Finalize()
{
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());

	DetourDetach(&(PVOID&)NativeRegCreateKeyA, DetourRegCreateKeyA);
	DetourDetach(&(PVOID&)NativeRegCreateKeyW, DetourRegCreateKeyW);
	//DetourDetach(&(PVOID&)NativeCoCreateInstance, DetourCoCreateInstance);
	DetourDetach(&(PVOID&)NativeCoGetClassObject, DetourCoGetClassObject);

	ULONG error = DetourTransactionCommit();
	return error == NO_ERROR;
}
Exemple #9
0
void endDetour() {
	//if(Settings::get().getSkipIntro()) {
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		//DetourDetach(&(PVOID&)TrueSleepEx, DetouredSleepEx);
		//DetourDetach(&(PVOID&)TrueTimeGetTime, DetouredTimeGetTime);
		if(Settings::get().getSkipIntro()) DetourDetach(&(PVOID&)TrueQueryPerformanceCounter, DetouredQueryPerformanceCounter);
		//DetourDetach(&(PVOID&)TrueD3DXCreateTexture, DetouredD3DXCreateTexture);
		DetourDetach(&(PVOID&)TrueD3DXCreateTextureFromFileInMemory, DetouredD3DXCreateTextureFromFileInMemory);
		DetourDetach(&(PVOID&)TrueD3DXCreateTextureFromFileInMemoryEx, DetouredD3DXCreateTextureFromFileInMemoryEx);
		DetourDetach(&(PVOID&)oDirect3DCreate9, hkDirect3DCreate9);
		//DetourDetach(&(PVOID&)TrueD3DXCompileShader, DetouredD3DXCompileShader);
		DetourTransactionCommit();
	//}
}
Exemple #10
0
void PatchTitanium::Unregister() {
	Log::Get().Write(Log::Status, "Unregistering patch Titanium");
#ifdef EQC_ENABLE_COMMANDS
	DetourDetach(&(PVOID&)TitaniumPlayer__CommandHandler, TitaniumPlayerCommandHandlerHook);
#endif

	DetourDetach(&(PVOID&)TitaniumGame__RegisterZone, TitaniumGameRegisterZoneHook);
	DetourDetach(&(PVOID&)TitaniumGame__RegisterModel, TitaniumGameRegisterModelHook);
	DetourDetach(&(PVOID&)TitaniumGame__OnMsgRecv, TitaniumGameOnMsgRecvHook);

	SafeWriteBuffer(Titanium_aGame__TradeStackCheck1, &TitaniumTradeUndo1[0], 39);
	SafeWriteBuffer(Titanium_aGame__TradeStackCheck2, &TitaniumTradeUndo2[0], 6);

	DetourDetach(&(PVOID&)TitaniumGame__DisplayLoadingMessage, TitaniumGameDisplayLoadingMessageHook);
}
Exemple #11
0
void PatchSoD::Unregister() {
	Log::Get().Write(Log::Status, "Unregistering patch SoD");
#ifdef EQC_ENABLE_COMMANDS
	DetourDetach(&(PVOID&)SoDPlayer__CommandHandler, SoDPlayerCommandHandlerHook);
#endif

	DetourDetach(&(PVOID&)SoDGame__RegisterZone, SoDGameRegisterZoneHook);
	DetourDetach(&(PVOID&)SoDGame__RegisterModel, SoDGameRegisterModelHook);
	DetourDetach(&(PVOID&)SoDGame__OnMsgRecv, SoDGameOnMsgRecvHook);

	SafeWriteBuffer(SoD_aGame__TradeStackCheck1, &SoDTradeUndo1[0], 48);
	SafeWriteBuffer(SoD_aGame__TradeStackCheck2, &SoDTradeUndo2[0], 9);

	DetourDetach(&(PVOID&)SoDGame__DisplayLoadingMessage, SoDGameDisplayLoadingMessageHook);
}
Exemple #12
0
HRESULT UnApplyVistaPatch(void)
{
	HMODULE hDetours = ::LoadLibrary(L"detoured.dll");

	if(!hDetours) return E_NOTIMPL;

  DetourTransactionBegin();
  DetourUpdateThread(GetCurrentThread());
  DetourDetach(&(PVOID&)g_fnGetModuleFileNameW, MyGetModuleFileNameW);
  DetourDetach(&(PVOID&)g_fnSizeofResource,     MySizeofResource);
  DetourDetach(&(PVOID&)g_fnLoadResource,		MyLoadResource);
  DetourDetach(&(PVOID&)g_fnFindResource,		MyFindResource);
  DetourTransactionCommit();

  return S_OK;
}
Exemple #13
0
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD dwReason, PVOID)
{
    switch (dwReason)
    {
    case DLL_PROCESS_ATTACH:
        {
            _Module.Init(NULL, hDllHandle);

            HMODULE hKernel32 = GetModuleHandle(_T("kernel32.dll"));
            RawLoadLibraryW = reinterpret_cast<FNLoadLibraryW>(GetProcAddress(hKernel32,
                "LoadLibraryW"));
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(reinterpret_cast<PVOID *>(&RawLoadLibraryW), HookLoadLibraryW);
            DetourTransactionCommit();

            Globals::Init();
            break;
        }
    case DLL_PROCESS_DETACH:
        {
            Globals::Uninit();

            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourDetach(reinterpret_cast<PVOID *>(&RawLoadLibraryW), HookLoadLibraryW);
            DetourTransactionCommit();

            _Module.Term();
            break;
        }
    }
    return TRUE;
}
Exemple #14
0
BOOL APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
    switch(Reason)
    {
    case DLL_PROCESS_ATTACH:
        /* Detour interesting function */
        DisableThreadLibraryCalls(hDLL);
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach(&(PVOID&)detFunc, MyDetourFunction); // actual detour fn_a -> fn_b
        if(DetourTransactionCommit() == NO_ERROR)
            OutputDebugString("function detoured successfully");

        break;


    case DLL_PROCESS_DETACH:
        /* De-Detour interesting function */
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourDetach(&(PVOID&)detFunc, MyDetourFunction); // removing the detour
        if(DetourTransactionCommit() == NO_ERROR)
            OutputDebugString("function detour removed");

        break;


    case DLL_THREAD_ATTACH:
        break;
    case DLL_THREAD_DETACH:
        break;
    }
    return TRUE;
}
Exemple #15
0
void Ndr_removeHooks ()
{
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourDetach((PVOID *)&_NdrAsyncServerCall, NdrAsyncServerCallHook);
	DetourTransactionCommit();
}
Exemple #16
0
VOID DetDetach(PVOID *ppvReal, PVOID pvMine, PCHAR psz)
{
	LONG l = DetourDetach(ppvReal, pvMine);
	if (l != 0) {
		(void)psz;
	}
}
PVOID DetourHook::unhook(){
	PVOID detoured = target;
	DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)target, replacer);
    DetourTransactionCommit();
	return replacer;
}
Exemple #18
0
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
    LONG error;
    (void)hinst;
    (void)reserved;

    if (DetourIsHelperProcess()) {
        return TRUE;
    }

    if (dwReason == DLL_PROCESS_ATTACH) {
		// open log
		SyelogOpen("readcl", SYELOG_FACILITY_APPLICATION);

		TouchHelloCpp("d:\\Hello.cpp");

		// detour it
        DetourRestoreAfterWith();

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)Real_CreateFileW, Mine_CreateFileW);
		DetourAttach(&(PVOID&)Real_ReadFile, Mine_ReadFile);
		DetourAttach(&(PVOID&)Real_CloseHandle, Mine_CloseHandle);
        error = DetourTransactionCommit();

		if (error == NO_ERROR) {
			Syelog(SYELOG_SEVERITY_INFORMATION, "Detoured ok: %d\n", error);
		} else {
			Syelog(SYELOG_SEVERITY_INFORMATION, "Error detouring: %d\n", error);
        }
    }
    else if (dwReason == DLL_PROCESS_DETACH) {
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)Real_CreateFileW, Mine_CreateFileW);
		DetourDetach(&(PVOID&)Real_ReadFile, Mine_ReadFile);
		DetourDetach(&(PVOID&)Real_CloseHandle, Mine_CloseHandle);
        error = DetourTransactionCommit();

		Syelog(SYELOG_SEVERITY_INFORMATION, "Removed detour: %d\n", error);

		SyelogClose(FALSE);
    }
    return TRUE;
}
Exemple #19
0
//卸载Hook  
BOOL APIENTRY DropHook()  
{  
	DetourTransactionBegin();  
	DetourUpdateThread(GetCurrentThread());  
	DetourDetach(&g_pOldMessageBoxA, ZwNewMessageBoxA);  
	LONG ret=DetourTransactionCommit();  
	return ret==NO_ERROR;  
}  
Exemple #20
0
VOID DetDetach(PVOID *ppbReal, PVOID pbMine, PCHAR psz)
{
    LONG l = DetourDetach(ppbReal, pbMine);
    if (l != 0) {
        Syelog(SYELOG_SEVERITY_NOTICE,
               "Detach failed: `%s': error %d\n", DetRealName(psz), l);
    }
}
Exemple #21
0
void DirectX8Shutdown() {
	if (g_fpDirect3DCreate8 != NULL) {
		DetourDetach(&(PVOID&)g_fpDirect3DCreate8, Direct3DCreate8Detour);
	}
	
	g_fpDirect3DCreate8 = NULL;
	g_fpCreateDevice8 = NULL;
	g_fpPresent8 = NULL;
}
Exemple #22
0
//------------------------------------------------------------------------------------------
//	Function name:	UnhookAPI
//	Description:	Unhooking the real functions and our intercepted ones, upon exit.
//------------------------------------------------------------------------------------------
void UnhookAPI()
{
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourDetach(&(PVOID&)Real_Direct3DCreate9, Mine_Direct3DCreate9);
	//DetourDetach(&(PVOID&)Real_CreateWindowExA,Mine_CreateWindowExA) ;
	//DetourAttach(&(PVOID&)Real_CreateWindowExW,Mine_CreateWindowExW) ;
	DetourTransactionCommit();
}
 BOOL CProcessMgrImpl::HookFuncEnd( PVOID *ppPointer, PVOID pDetour )
 {
     DetourRestoreAfterWith();
     DetourTransactionBegin();
     DetourUpdateThread( GetCurrentThread() );
     DetourDetach( ppPointer, pDetour );
     DWORD dwErr = DetourTransactionCommit();
     return ( dwErr == NO_ERROR );
 }
Exemple #24
0
BOOL CDOMPlugin::UnPatch()
{
	DetourTransactionBegin();
	DetourUpdateThread(GetCurrentThread());
	DetourDetach(&(PVOID&)StubShell->PatchAt, (PVOID)StubShell->ShellCode);

	DetourTransactionCommit();
	return TRUE;
}
void CSimpleDetour::Detach()
{
	if ( !m_bAttached )
		return;

	DetourTransactionBegin();
	DetourUpdateThread( GetCurrentThread() );
	DetourDetach( m_fnOld, m_fnReplacement );
	DetourTransactionCommit();
}
void FileFilter_Unload()
{
	if(sigcheckfileext_Sig.sig_addr)
	{
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
			DetourDetach(&(PVOID&)checkext_trampoline, (PVOID)(&(PVOID&)checkext_hook));
		DetourTransactionCommit();
	}
}
Exemple #27
0
int main(int argc, char **argv)
{
    HRESULT hr;

    (void)argc;
    (void)argv;

    LPSTREAM pStream = NULL;
    ULARGE_INTEGER ul;
    LARGE_INTEGER li;

    CoInitialize(NULL);

    hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);

    RealIStreamWrite = pStream->lpVtbl->Write;

    ul.QuadPart = 512;
    hr = pStream->lpVtbl->SetSize(pStream, ul);
    li.QuadPart = 0;
    hr = pStream->lpVtbl->Seek(pStream, li, STREAM_SEEK_SET, NULL);

    printf("commem: Calling Write w/o before attach.\n");

    li.QuadPart = 0;
    hr = pStream->lpVtbl->Write(pStream, &ul, sizeof(ul), NULL);

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)RealIStreamWrite, MineIStreamWrite);
    DetourTransactionCommit();

    printf("commem: Calling Write w/o after attach.\n");

    li.QuadPart = 1;
    hr = pStream->lpVtbl->Write(pStream, &li, sizeof(li), NULL);

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)RealIStreamWrite, MineIStreamWrite);
    DetourTransactionCommit();

    printf("commem: Calling Write w/o after detach.\n");

    li.QuadPart = 2;
    hr = pStream->lpVtbl->Write(pStream, &li, sizeof(li), NULL);

    hr = pStream->lpVtbl->Release(pStream);
    pStream = NULL;

    CoUninitialize();

    return 0;
}
Exemple #28
0
INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
	switch(Reason)
	{
	case DLL_PROCESS_ATTACH:
		{
		s_hDll = hDLL;

		// Calculate addresses of the functions to detour
		baseAddress = GetModuleHandle(NULL);
		regFunc = (pRegFunc)((DWORD)baseAddress + regFuncOffset);
		regFunc2 = (pRegFunc2)((DWORD)baseAddress + regFunc2Offset);
		printInitial = (pprintInitial)((DWORD)baseAddress + printInitialOffset);
		printNumbers = (pprintNumbers)((DWORD)baseAddress + printNumbersOffset);

		DisableThreadLibraryCalls(hDLL);
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)regFunc, d_regFunc);
		DetourAttach(&(PVOID&)regFunc2, d_regFunc2);
		DetourAttach(&(PVOID&)printInitial, d_printInitial);
		DetourAttach(&(PVOID&)printNumbers, d_printNumbers);
		DetourTransactionCommit();
		}
		break;
	case DLL_PROCESS_DETACH:
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)regFunc, d_regFunc);
		DetourDetach(&(PVOID&)regFunc2, d_regFunc2);
		DetourDetach(&(PVOID&)printInitial, d_printInitial);
		DetourDetach(&(PVOID&)printNumbers, d_printNumbers);
		DetourTransactionCommit();
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
		break;
	}
	return TRUE;
}
Exemple #29
0
BOOL EnableSpeedControl(BOOL bEnable)
{
	static BOOL bEnabled = FALSE;
	if ((bEnable && bEnabled) || (!bEnable && !bEnabled))
		return FALSE;

	BOOL bSuccessed;
	if (bEnable)
	{
		InitializeCriticalSection(&g_csGetTickCount);
		InitializeCriticalSection(&g_csQueryPerformanceCounter);
		InitializeCriticalSection(&g_csTimeGetTime);
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());

		*(PVOID *)&Real_GetTickCount = DetourCodeFromPointer((PVOID)GetTickCount, NULL);
 		DetourAttach(&(PVOID&)Real_GetTickCount, Mine_GetTickCount);
		DetourAttach(&(PVOID&)Real_QueryPerformanceCounter, Mine_QueryPerformanceCounter);
		DetourAttach(&(PVOID&)Real_timeGetTime, Mine_timeGetTime);

		bSuccessed = DetourTransactionCommit() == 0;
		bEnabled = TRUE;
	}
	else
	{
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());

		DetourDetach(&(PVOID&)Real_GetTickCount, Mine_GetTickCount);
		DetourDetach(&(PVOID&)Real_QueryPerformanceCounter, Mine_QueryPerformanceCounter);
		DetourDetach(&(PVOID&)Real_timeGetTime, Mine_timeGetTime);

		bSuccessed = DetourTransactionCommit() == 0;
		DeleteCriticalSection(&g_csGetTickCount);
		DeleteCriticalSection(&g_csQueryPerformanceCounter);
		DeleteCriticalSection(&g_csTimeGetTime);
		bEnabled = FALSE;
	}
	return bSuccessed;
}
// =============================================================================
// DllMain
// =============================================================================
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
	if (DetourIsHelperProcess()) {
		return TRUE;
	}

	if (dwReason == DLL_PROCESS_ATTACH) {

		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourAttach(&(PVOID&)pWSAStartup, MyWSAStartup);
		DetourAttach(&(PVOID&)pSocket, MySocket);
		DetourAttach(&(PVOID&)pConnect, MyConnect);
		DetourAttach(&(PVOID&)pSend, MySend);
		DetourAttach(&(PVOID&)pClosesocket, MyClosesocket);
		DetourAttach(&(PVOID&)pWSACleanup, MyWSACleanup);
		DetourTransactionCommit();
	}
	else if (dwReason == DLL_PROCESS_DETACH) {
		DetourTransactionBegin();
		DetourUpdateThread(GetCurrentThread());
		DetourDetach(&(PVOID&)pWSAStartup, MyWSAStartup);
		DetourDetach(&(PVOID&)pSocket, MySocket);
		DetourDetach(&(PVOID&)pConnect, MyConnect);
		DetourDetach(&(PVOID&)pSend, MySend);
		DetourDetach(&(PVOID&)pClosesocket, MyClosesocket);
		DetourDetach(&(PVOID&)pWSACleanup, MyWSACleanup);
		DetourTransactionCommit();
	}
	return TRUE;
}