// Take a snapshot of all modules in the specified process.
hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
if (hModuleSnap == INVALID_HANDLE_VALUE)
return (FALSE);
// Fill the size of the structure before using it.
me32.dwSize = sizeof(MODULEENTRY32);
// Walk the module list of the process, and find the module of
// interest. Then copy the information to the buffer pointed
// to by lpMe32 so that it can be returned to the caller.
if (Module32First(hModuleSnap, &me32))
{
do
{
if (me32.th32ModuleID == dwModuleID)
{
CopyMemory (lpMe32, &me32, cbMe32);
bFound = TRUE;
}
}
while (!bFound && Module32Next(hModuleSnap, &me32));
bRet = bFound; // if this sets bRet to FALSE, dwModuleID
// no longer exists in specified process
}
else
bRet = FALSE; // could not walk module list
我还是要补充:
关于Win32的PE格式,有一个叫Matt Pietrek人是专家,这人在94年就开始提出了分析PE格式的文章,叫:"Peering Inside the PE: A Tour of the Win32 Portable Executable File Format".
2002年,有写了篇新的,其中包括.net和64位下的PE文件格式,叫:"An In-Depth Look into the Win32 Portable Executable File Format"。
这两篇文章在MSDN中都有,各位可以去查看,而且Matt 还给出了程序原码,很有价值。原码可以在这下载:
http://download.microsoft.com/download/msdnmagazine/code/Feb02/WXP/EN-US/PE.exe
我稍微看了以下,比VC6提供的dumpbin.exe工具强.