kernel32: Moved EnumProcessModules implementation to kernel32.
This commit is contained in:
parent
4422d22cfe
commit
362a7d571e
|
@ -770,6 +770,7 @@
|
|||
@ stdcall K32EmptyWorkingSet(long)
|
||||
@ stdcall K32GetProcessImageFileNameA(long ptr long)
|
||||
@ stdcall K32GetProcessImageFileNameW(long ptr long)
|
||||
@ stdcall K32EnumProcessModules(long ptr long ptr)
|
||||
@ stdcall K32EnumProcesses(ptr long ptr)
|
||||
@ stdcall -i386 -private -register K32Thk1632Epilog() krnl386.exe16.K32Thk1632Epilog
|
||||
@ stdcall -i386 -private -register K32Thk1632Prolog() krnl386.exe16.K32Thk1632Prolog
|
||||
|
|
|
@ -3501,6 +3501,88 @@ BOOL WINAPI K32EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
HANDLE process;
|
||||
PLIST_ENTRY head, current;
|
||||
LDR_MODULE ldr_module;
|
||||
} MODULE_ITERATOR;
|
||||
|
||||
static BOOL init_module_iterator(MODULE_ITERATOR *iter, HANDLE process)
|
||||
{
|
||||
PROCESS_BASIC_INFORMATION pbi;
|
||||
PPEB_LDR_DATA ldr_data;
|
||||
NTSTATUS status;
|
||||
|
||||
/* Get address of PEB */
|
||||
status = NtQueryInformationProcess(process, ProcessBasicInformation,
|
||||
&pbi, sizeof(pbi), NULL);
|
||||
if (status != STATUS_SUCCESS)
|
||||
{
|
||||
SetLastError(RtlNtStatusToDosError(status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Read address of LdrData from PEB */
|
||||
if (!ReadProcessMemory(process, &pbi.PebBaseAddress->LdrData,
|
||||
&ldr_data, sizeof(ldr_data), NULL))
|
||||
return FALSE;
|
||||
|
||||
/* Read address of first module from LdrData */
|
||||
if (!ReadProcessMemory(process,
|
||||
&ldr_data->InLoadOrderModuleList.Flink,
|
||||
&iter->current, sizeof(iter->current), NULL))
|
||||
return FALSE;
|
||||
|
||||
iter->head = &ldr_data->InLoadOrderModuleList;
|
||||
iter->process = process;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int module_iterator_next(MODULE_ITERATOR *iter)
|
||||
{
|
||||
if (iter->current == iter->head)
|
||||
return 0;
|
||||
|
||||
if (!ReadProcessMemory(iter->process,
|
||||
CONTAINING_RECORD(iter->current, LDR_MODULE, InLoadOrderModuleList),
|
||||
&iter->ldr_module, sizeof(iter->ldr_module), NULL))
|
||||
return -1;
|
||||
|
||||
iter->current = iter->ldr_module.InLoadOrderModuleList.Flink;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* K32EnumProcessModules (KERNEL32.@)
|
||||
*
|
||||
* NOTES
|
||||
* Returned list is in load order.
|
||||
*/
|
||||
BOOL WINAPI K32EnumProcessModules(HANDLE process, HMODULE *lphModule,
|
||||
DWORD cb, DWORD *needed)
|
||||
{
|
||||
MODULE_ITERATOR iter;
|
||||
INT ret;
|
||||
|
||||
if (!init_module_iterator(&iter, process))
|
||||
return FALSE;
|
||||
|
||||
*needed = 0;
|
||||
|
||||
while ((ret = module_iterator_next(&iter)) > 0)
|
||||
{
|
||||
if (cb >= sizeof(HMODULE))
|
||||
{
|
||||
*lphModule++ = iter.ldr_module.BaseAddress;
|
||||
cb -= sizeof(HMODULE);
|
||||
}
|
||||
*needed += sizeof(HMODULE);
|
||||
}
|
||||
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ProcessIdToSessionId (KERNEL32.@)
|
||||
* This function is available on Terminal Server 4SP4 and Windows 2000
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
@ stdcall EnumDeviceDrivers(ptr long ptr)
|
||||
@ stdcall EnumPageFilesA(ptr ptr)
|
||||
@ stdcall EnumPageFilesW(ptr ptr)
|
||||
@ stdcall EnumProcessModules(long ptr long ptr)
|
||||
@ stdcall EnumProcessModules(long ptr long ptr) kernel32.K32EnumProcessModules
|
||||
@ stdcall EnumProcesses(ptr long ptr) kernel32.K32EnumProcesses
|
||||
@ stdcall GetDeviceDriverBaseNameA(ptr ptr long)
|
||||
@ stdcall GetDeviceDriverBaseNameW(ptr ptr long)
|
||||
|
|
|
@ -178,36 +178,6 @@ BOOL WINAPI EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, LPVOID context )
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* EnumProcessModules (PSAPI.@)
|
||||
*
|
||||
* NOTES
|
||||
* Returned list is in load order.
|
||||
*/
|
||||
BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule,
|
||||
DWORD cb, LPDWORD lpcbNeeded)
|
||||
{
|
||||
MODULE_ITERATOR iter;
|
||||
INT ret;
|
||||
|
||||
if (!PSAPI_ModuleIteratorInit(&iter, hProcess))
|
||||
return FALSE;
|
||||
|
||||
*lpcbNeeded = 0;
|
||||
|
||||
while ((ret = PSAPI_ModuleIteratorNext(&iter)) > 0)
|
||||
{
|
||||
if (cb >= sizeof(HMODULE))
|
||||
{
|
||||
*lphModule++ = iter.LdrModule.BaseAddress;
|
||||
cb -= sizeof(HMODULE);
|
||||
}
|
||||
*lpcbNeeded += sizeof(HMODULE);
|
||||
}
|
||||
|
||||
return (ret == 0);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* GetDeviceDriverBaseNameA (PSAPI.@)
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue