From a17495fdbcfab1555e0a3da39a93837712ff12fc Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 17 May 2017 00:36:09 +0200 Subject: [PATCH] fix ddraw unprotecting --- DDraw/dllmain.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index 0ef18f8..01298d0 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -200,21 +200,23 @@ void PatchIAT() DWORD dwProtect; VirtualProtect((LPVOID)((ptrdiff_t)hInstance + pSection->VirtualAddress), pSection->Misc.VirtualSize, PAGE_EXECUTE_READ, &dwProtect); - if ( (pSection->Characteristics & IMAGE_SCN_CNT_CODE) == 0 ) + DWORD Characteristics = pSection->Characteristics; + if ( (Characteristics & IMAGE_SCN_CNT_CODE) == 0 ) { - pSection->Characteristics |= IMAGE_SCN_CNT_CODE; - ntHeader->OptionalHeader.SizeOfCode += pSection->Misc.VirtualSize; + Characteristics |= IMAGE_SCN_CNT_CODE; + Memory::VP::Patch( &ntHeader->OptionalHeader.SizeOfCode, ntHeader->OptionalHeader.SizeOfCode + pSection->Misc.VirtualSize ); } - if ( (pSection->Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) != 0 ) + if ( (Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) != 0 ) { - pSection->Characteristics &= ~(IMAGE_SCN_CNT_INITIALIZED_DATA); - ntHeader->OptionalHeader.SizeOfInitializedData -= pSection->Misc.VirtualSize; + Characteristics &= ~(IMAGE_SCN_CNT_INITIALIZED_DATA); + Memory::VP::Patch( &ntHeader->OptionalHeader.SizeOfInitializedData, ntHeader->OptionalHeader.SizeOfInitializedData - pSection->Misc.VirtualSize ); } - if ( (pSection->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0 ) + if ( (Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0 ) { - pSection->Characteristics &= ~(IMAGE_SCN_CNT_UNINITIALIZED_DATA); - ntHeader->OptionalHeader.SizeOfUninitializedData -= pSection->Misc.VirtualSize; + Characteristics &= ~(IMAGE_SCN_CNT_UNINITIALIZED_DATA); + Memory::VP::Patch( &ntHeader->OptionalHeader.SizeOfUninitializedData, ntHeader->OptionalHeader.SizeOfUninitializedData - pSection->Misc.VirtualSize ); } + Memory::VP::Patch( &pSection->Characteristics, Characteristics ); break; } }