From 6bcd33ea5447f31ee1b9eab7300dacaf7410d8b3 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 27 Apr 2017 22:12:48 +0200 Subject: [PATCH] Include flag changes when protecting rwcseg --- DDraw/dllmain.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index 4f203a1..d2e4cfc 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -200,6 +200,22 @@ 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 ) + { + pSection->Characteristics |= IMAGE_SCN_CNT_CODE; + ntHeader->OptionalHeader.SizeOfCode += pSection->Misc.VirtualSize; + } + if ( (pSection->Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) != 0 ) + { + pSection->Characteristics &= ~(IMAGE_SCN_CNT_INITIALIZED_DATA); + ntHeader->OptionalHeader.SizeOfInitializedData -= pSection->Misc.VirtualSize; + } + if ( (pSection->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0 ) + { + pSection->Characteristics &= ~(IMAGE_SCN_CNT_UNINITIALIZED_DATA); + ntHeader->OptionalHeader.SizeOfUninitializedData -= pSection->Misc.VirtualSize; + } break; } }