有誰知道LDR_MODULE.LoadCount在Windows 8上的位置?Windows 8上的DLL LoadCount 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上執行相同操作的任何想法?
如果您認爲閱讀DLL負載計數是您的解決方案,那麼您遇到的問題是什麼? – 2013-03-17 19:29:42
哦,我只是想檢查一個DLL在一個進程中加載了多少次..我在做注入,我希望能夠調用LdrUnloadDll來卸載DLL的高計數。 – Brandon 2013-03-17 19:39:29
嗯,釋放一個你沒有加載的DLL並不是最好的工程設計。 – 2013-03-17 22:37:09