假設PEB在1000h。
的PEB的第一構件在此處列出,連同它們的地址在存儲器
typedef struct _PEB {
/* 1000h + 000h = 1000h */ BYTE Reserved1[2];
/* 1000h + 002h = 1002h */ BYTE BeingDebugged;
/* 1000h + 003h = 1003h */ BYTE Reserved2[1];
/* 1000h + 004h = 1004h */ PVOID Reserved3[2];
/* 1000h + 00ch = 100ch */ PPEB_LDR_DATA Ldr;
...
} PEB, *PPEB;
的Ldr
構件是指針,假設它指向2000H, 即該PEB_LDR_DATA
位於在2000h。
來自MSDN
現在,PEB_LDR_DATA
具有這種結構(許多成員的官方文檔中省略)
typedef struct _PEB_LDR_DATA {
/* 2000h + 000h = 2000h */ BYTE Reserved1[8];
/* 2000h + 008h = 2008h */ PVOID Reserved2[3];
/* 2000h + 014h = 2014h */ LIST_ENTRY InMemoryOrderModuleList;
} PEB_LDR_DATA, *PPEB_LDR_DATA;
正如你可以看到成員InMemoryOrderModuleList
不是指針是結構,因此,所有的LIST_ENTRY
的成員被嵌入到PEB_LDR_DATA
結構中。
這意味着在InMemoryOrderModuleList
的地址中有LIST_ENTRY
的第一個成員,該成員是Flink
,它位於2014h。
Here the expanded structure
typedef struct _PEB_LDR_DATA {
/* 2000h + 000h = 2000h */ BYTE Reserved1[8];
/* 2000h + 008h = 2008h */ PVOID Reserved2[3];
/* 2000h + 014h = 2014h */ LIST_ENTRY InMemoryOrderModuleList;
/* 2000h + 014h = 2014h */ LIST_ENTRY* InMemoryOrderModuleList.Flink
/* 2000h + 018h = 2018h */ LIST_ENTRY* InMemoryOrderModuleList.Blink
} PEB_LDR_DATA, *PPEB_LDR_DATA;
注意,現在Flink
和Blink
成員指針。
現在假設InMemoryOrderModuleList.Flink
指向3000h。
在3000h有LIST_ENTRY
結構,這是第一個條目。
假設這個結構Flink
成員指向4000h,這是第二個條目。
假設這最後的結構Flink
成員指向5000h,這是第三項。
現在除了PEB_LDR_DATA
的列表頭之外,每個LIST_ENTRY
實際上都是LDR_DATA_TABLE_ENTRY
,這是可能的,因爲後者與前者具有兼容的存儲器佈局。
所以你到達了感興趣的條目,你可以訪問LDR_DATA_TABLE_ENTRY
結構的成員。
由於第三項是在5000小時和LDR_DATA_TABLE_ENTRY
具有這種佈局
typedef struct _LDR_DATA_TABLE_ENTRY {
/* 5000h + 000h = 5000h */ PVOID Reserved1[2];
/* 5000h + 008h = 5008h */ LIST_ENTRY InMemoryOrderLinks;
/* 5000h + 010h = 5010h */ PVOID Reserved2[2];
/* 5000h + 018h = 5018h */ PVOID DllBase;
...
} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
的情況

查看你的彙編代碼的醜陋MS畫圖圖片
xor ebx, ebx //An useless instruction
mov ebx, fs:[ 0x30 ] //get a pointer to the PEB
;EBX is now 1000h
mov ebx, [ ebx + 0x0C ] //get PEB->Ldr
;This read from 100ch and EBX gets 2000h
mov ebx, [ ebx + 0x14 ] //get PEB->Ldr.InMemoryOrderModuleList.Flink(1st entry)
;This read from 2014h and EBX gets 3000h
mov ebx, [ ebx ] //get the next entry(2nd entry)
;This read from 3000h and EBX gets 4000h
mov ebx, [ ebx ] //get the next entry(3rd entry)
;This read from 4000h and EBX gets 5000h
mov ebx, [ ebx + 0x10 ] //get the 3rd entries base address(kernel32.dll)
;This read from 5010h, it seems that this DOES NOT read the correct member!
;Should be at offset 18h