#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
#include <Ntsecapi.h> //for unicode_string
typedef _LIST_ENTRY *PLIST_ENTRY;
void ShowModuleInfo(PLIST_ENTRY pEntry);
int _tmain(int argc, _TCHAR* argv[])
{
PLIST_ENTRY pFirstModule = NULL;
PLIST_ENTRY pLastModule = NULL;
PLIST_ENTRY pListEntry = NULL;
//通过fs寄存器拿到ldr链表
__asm{
pushad
mov eax, dword ptr fs:[0x30] //get peb
mov eax, dword ptr[eax + 0xc] //get ldr
lea eax, dword ptr[eax + 0x1c] //get list_entry
mov pListEntry, eax
popad
}
pFirstModule = pListEntry->Flink;
pLastModule = pFirstModule->Blink;
while (pFirstModule != pLastModule){
ShowModuleInfo(pFirstModule);
pFirstModule = pFirstModule->Flink;
}
ShowModuleInfo(pFirstModule);
getchar();
return 0;
}
void ShowModuleInfo(PLIST_ENTRY pEntry){
byte * pBase = (byte *)pEntry;
PUNICODE_STRING pUnicode = (PUNICODE_STRING)(pBase + sizeof(_LIST_ENTRY) +
sizeof(DWORD)* 3 + sizeof(UNICODE_STRING));
printf("DllBase=%p EntryPoint=%p BaseDllName = %ws\n",
*(DWORD *)(pBase + sizeof(_LIST_ENTRY)), //DllBase
*(DWORD *)(pBase + sizeof(_LIST_ENTRY) + sizeof(DWORD)), //EntryPoint
pUnicode->Buffer); //BaseDllName
}