From df5f6f66de80085249d392be5efa085e6ee056a0 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 14 Feb 2023 11:07:03 +0100 Subject: [PATCH] kernelbase: Re-implement EnumProcessModules on top of EnumProcessModulesEx. Note: this patch changes the results of EnumProcessModules for a wow64 target process called from a 64bit process. It now returns: - main module and all loaded 64bit modules (Wine multi-arch wow64 and Windows) - main module only (Wine "old" wow64). It used to return all the 32bit modules. You now must use EnumProcessModulesEx(..., LIST_MODULES_32BIT) to get that result. Signed-off-by: Eric Pouech --- dlls/kernelbase/debug.c | 66 +---------------------------------- dlls/psapi/tests/psapi_main.c | 2 -- 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/dlls/kernelbase/debug.c b/dlls/kernelbase/debug.c index ebf1ed76023..4eff7ad1cca 100644 --- a/dlls/kernelbase/debug.c +++ b/dlls/kernelbase/debug.c @@ -949,71 +949,7 @@ BOOL WINAPI /* DECLSPEC_HOTPATCH */ EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW ca BOOL WINAPI DECLSPEC_HOTPATCH EnumProcessModules( HANDLE process, HMODULE *module, DWORD count, DWORD *needed ) { - struct module_iterator iter; - DWORD size = 0; - BOOL target_wow64; - INT ret; - - if (process == GetCurrentProcess()) - { - PPEB_LDR_DATA ldr_data = NtCurrentTeb()->Peb->LdrData; - PLIST_ENTRY head = &ldr_data->InLoadOrderModuleList; - PLIST_ENTRY entry = head->Flink; - - if (count && !module) - { - SetLastError( ERROR_NOACCESS ); - return FALSE; - } - while (entry != head) - { - LDR_DATA_TABLE_ENTRY *ldr = CONTAINING_RECORD( entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks ); - if (count >= sizeof(HMODULE)) - { - *module++ = ldr->DllBase; - count -= sizeof(HMODULE); - } - size += sizeof(HMODULE); - entry = entry->Flink; - } - if (!needed) - { - SetLastError( ERROR_NOACCESS ); - return FALSE; - } - *needed = size; - return TRUE; - } - - if (!IsWow64Process( process, &target_wow64 )) return FALSE; - if (!init_module_iterator( &iter, process, is_win64 && target_wow64 )) return FALSE; - - if (count && !module) - { - SetLastError( ERROR_NOACCESS ); - return FALSE; - } - - while ((ret = module_iterator_next( &iter )) > 0) - { - if (count >= sizeof(HMODULE)) - { - if (sizeof(void *) == 8 && iter.wow64) - *module++ = (HMODULE) (DWORD_PTR)iter.ldr_module32.BaseAddress; - else - *module++ = iter.ldr_module.DllBase; - count -= sizeof(HMODULE); - } - size += sizeof(HMODULE); - } - - if (!needed) - { - SetLastError( ERROR_NOACCESS ); - return FALSE; - } - *needed = size; - return ret == 0; + return EnumProcessModulesEx( process, module, count, needed, LIST_MODULES_DEFAULT ); } diff --git a/dlls/psapi/tests/psapi_main.c b/dlls/psapi/tests/psapi_main.c index fc248d35e01..227fc52c2ad 100644 --- a/dlls/psapi/tests/psapi_main.c +++ b/dlls/psapi/tests/psapi_main.c @@ -181,7 +181,6 @@ static void test_EnumProcessModules(void) { ret = GetModuleBaseNameA(pi.hProcess, hmods[2], name, sizeof(name)); ok(ret, "got error %lu\n", GetLastError()); - todo_wine ok(strstr(CharLowerA(name), "wow64") != NULL, "third DLL in wow64 should be one of wow*.dll (%s)\n", name); } TerminateProcess(pi.hProcess, 0); @@ -207,7 +206,6 @@ static void test_EnumProcessModules(void) SetLastError(0xdeadbeef); ret = EnumProcessModules(pi.hProcess, &hMod, sizeof(HMODULE), &cbNeeded); ok(!ret, "got %ld\n", ret); - todo_wine ok(GetLastError() == ERROR_PARTIAL_COPY, "got error %lu\n", GetLastError()); TerminateProcess(pi.hProcess, 0);