Signed-off-by: Paul Gofman pgofman@codeweavers.com --- It is a very old hack and testing shows that there is no special case on Windows for entry point being inside the section without execute flag. My guess is that maybe this was introduced before 'force_exec_prot' (NtSetInformationProcess(ProcessExecuteFlags) or IMAGE_DLLCHARACTERISTICS_NX_COMPAT were properly supported.
dlls/kernel32/tests/loader.c | 18 +++++++++++------- dlls/ntdll/unix/virtual.c | 5 ----- 2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c index 4f1b11338a6..308cf1a44a0 100644 --- a/dlls/kernel32/tests/loader.c +++ b/dlls/kernel32/tests/loader.c @@ -1967,12 +1967,6 @@ static void test_section_access(void) nt_header.OptionalHeader.FileAlignment = 0x200; nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + page_size; nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER); - SetLastError(0xdeadbeef); - ret = WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL); - ok(ret, "WriteFile error %d\n", GetLastError()); - SetLastError(0xdeadbeef); - ret = WriteFile(hfile, &nt_header.OptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER), &dummy, NULL); - ok(ret, "WriteFile error %d\n", GetLastError());
section.SizeOfRawData = sizeof(section_data); section.PointerToRawData = nt_header.OptionalHeader.FileAlignment; @@ -1980,6 +1974,16 @@ static void test_section_access(void) section.Misc.VirtualSize = section.SizeOfRawData; section.Characteristics = td[i].scn_file_access; SetLastError(0xdeadbeef); + + nt_header.OptionalHeader.AddressOfEntryPoint = section.VirtualAddress; + + SetLastError(0xdeadbeef); + ret = WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL); + ok(ret, "WriteFile error %d\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = WriteFile(hfile, &nt_header.OptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER), &dummy, NULL); + ok(ret, "WriteFile error %d\n", GetLastError()); + ret = WriteFile(hfile, §ion, sizeof(section), &dummy, NULL); ok(ret, "WriteFile error %d\n", GetLastError());
@@ -1997,7 +2001,7 @@ static void test_section_access(void) CloseHandle(hfile);
SetLastError(0xdeadbeef); - hlib = LoadLibraryA(dll_name); + hlib = LoadLibraryExA(dll_name, NULL, DONT_RESOLVE_DLL_REFERENCES); ok(hlib != 0, "LoadLibrary error %d\n", GetLastError());
SetLastError(0xdeadbeef); diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 5873a3e2335..dfd61546597 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -2409,11 +2409,6 @@ static NTSTATUS map_image_into_view( struct file_view *view, const WCHAR *filena if (sec->Characteristics & IMAGE_SCN_MEM_WRITE) vprot |= VPROT_WRITECOPY; if (sec->Characteristics & IMAGE_SCN_MEM_EXECUTE) vprot |= VPROT_EXEC;
- /* Dumb game crack lets the AOEP point into a data section. Adjust. */ - if ((nt->OptionalHeader.AddressOfEntryPoint >= sec->VirtualAddress) && - (nt->OptionalHeader.AddressOfEntryPoint < sec->VirtualAddress + size)) - vprot |= VPROT_EXEC; - if (!set_vprot( view, ptr + sec->VirtualAddress, size, vprot ) && (vprot & VPROT_EXEC)) ERR( "failed to set %08x protection on %s section %.8s, noexec filesystem?\n", sec->Characteristics, debugstr_w(filename), sec->Name );