leecher1337 / ntvdmx64

Run Microsoft Windows NTVDM (DOS) on 64bit Editions
780 stars 80 forks source link

32-bit processes crashing at startup (Windows 7) #202

Closed throwaway768485 closed 1 year ago

throwaway768485 commented 1 year ago

Lately I have had some 32-bit processes crashing at startup using ldntvdm.dll on Windows 7 x64.

The issue seems to lie in Hook_Inline_Func (detour.c, line 205) while patching a function in kernel32.dll (namely BasepProcessInvalidImage) :

VirtualProtectEx(hProcess, (PBYTE)src - len, len + 2, PAGE_READWRITE, &OldProt))

It turns out that the functions VirtualProtectEx and BasepProcessInvalidImage have their code located in the same memory page in the latest builds of kernel32.dll; thus the second call to VirtualProtectEx meant to restore the initial page protection triggers an exception, trying to execute no-more-executable code.

Replacing PAGE_READWRITE with PAGE_EXECUTE_READWRITE solved the issue for me.

Many thanks for your work on this great project!

leecher1337 commented 1 year ago

Thank you for reporting, analysis and fix proposal saving me the hassle of needing to reproduce it!