有谁知道 LDR_MODULE.LoadCount 在 Windows 8 上的位置?
下面的代码总是为引用计数打印 6:S 我用 RemoteDLLTool 检查,基地址和所有其他信息都是正确的。但是,LoadCount 是错误的,因为它始终为 6。我读到如果它是 6,则意味着 DLL 是动态加载的,如果是 -1,它是静态的。
还有一种方法可以只迭代链表而不必不断地 ReadProcessMemory?
我需要以某种方式计算引用计数。基本上,Windows 7 上的以下代码将告诉我加载 DLL 的次数。也就是对 DLL 的引用计数。
#include <winternl.h>
typedef struct _LDR_MODULE
{
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
PVOID BaseAddress;
PVOID EntryPoint;
ULONG SizeOfImage;
UNICODE_STRING FullDllName;
UNICODE_STRING BaseDllName;
ULONG Flags;
SHORT LoadCount;
SHORT TlsIndex;
LIST_ENTRY HashTableEntry;
ULONG TimeDateStamp;
} LDR_MODULE, *PLDR_MODULE;
int GetModuleLoadCount()
{
DWORD dwBytesRead = 0;
PROCESS_BASIC_INFORMATION PBI = {0};
HANDLE ProcessHandle = GetCurrentProcess();
if (NT_SUCCESS(NtQueryInformationProcess(ProcessHandle, ProcessBasicInformation, &PBI, sizeof(PBI), &dwBytesRead)))
{
PEB_LDR_DATA LdrData;
LDR_MODULE LdrModule;
PPEB_LDR_DATA pLdrData = nullptr;
PLDR_MODULE pLdrModule = nullptr;
char* LdrDataOffset = reinterpret_cast<char*>(PBI.PebBaseAddress) + offsetof(PEB, Ldr);
ReadProcessMemory(ProcessHandle, LdrDataOffset, &pLdrData, sizeof(pLdrData), &dwBytesRead);
ReadProcessMemory(ProcessHandle, pLdrData, &LdrData, sizeof(LdrData), &dwBytesRead);
LIST_ENTRY* Head = LdrData.InMemoryOrderModuleList.Flink;
LIST_ENTRY* Next = Head;
do
{
LDR_DATA_TABLE_ENTRY LdrEntry;
LDR_DATA_TABLE_ENTRY* Base = CONTAINING_RECORD(Head, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
if (ReadProcessMemory(ProcessHandle, Base, &LdrEntry, sizeof(LdrEntry), &dwBytesRead))
{
char* pLdrModuleOffset = reinterpret_cast<char*>(Head) - sizeof(LIST_ENTRY);
ReadProcessMemory(ProcessHandle, pLdrModuleOffset, &pLdrModule, sizeof(pLdrModule), &dwBytesRead);
ReadProcessMemory(ProcessHandle, pLdrModule, &LdrModule, sizeof(LdrModule), &dwBytesRead);
if (LdrEntry.DllBase)
{
std::cout<<"BaseAddress: "<< LdrModule.BaseAddress<<std::endl;
std::cout<<"Reference Count: "<< LdrModule.LoadCount<<std::endl;
}
Head = LdrEntry.InMemoryOrderLinks.Flink;
}
}
while (Head != Next);
}
CloseHandle(ProcessHandle);
return 0;
}
有关如何在 Windows 8 上执行相同操作的任何想法?