-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpeb_teb.h
394 lines (384 loc) · 13.4 KB
/
peb_teb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#define PASTE2(x,y) x##y
#define PASTE(x,y) PASTE2(x,y)
#ifdef EXPLICIT_32BIT
#define STRUCT(x) PASTE(x,32)
#define PTR(x) ULONG
#elif defined(EXPLICIT_64BIT)
#define STRUCT(x) PASTE(x,64)
#define PTR(x) ULONG64
#else
#define STRUCT(x) x
#define PTR(x) x
#endif
#if (defined(_WIN64) && !defined(EXPLICIT_32BIT)) || defined(EXPLICIT_64BIT)
#define GDI_HANDLE_BUFFER_SIZE 60
#else
#define GDI_HANDLE_BUFFER_SIZE 34
#endif
#if defined(_NTDDK_INCLUDED_) || defined(_NTIFS_)
#define PPEB PPEB_RENAMED
#endif
typedef struct STRUCT(_PEB)
{
BOOLEAN InheritedAddressSpace;
BOOLEAN ReadImageFileExecOptions;
BOOLEAN BeingDebugged;
#if (NTDDI_VERSION >= NTDDI_WS03)
union
{
BOOLEAN BitField;
struct
{
BOOLEAN ImageUsesLargePages:1;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
BOOLEAN IsProtectedProcess:1;
BOOLEAN IsLegacyProcess:1;
BOOLEAN IsImageDynamicallyRelocated:1;
BOOLEAN SkipPatchingUser32Forwarders:1;
BOOLEAN SpareBits:3;
#else
BOOLEAN SpareBits:7;
#endif
};
};
#else
BOOLEAN SpareBool;
#endif
PTR(HANDLE) Mutant;
PTR(PVOID) ImageBaseAddress;
PTR(PPEB_LDR_DATA) Ldr;
PTR(struct _RTL_USER_PROCESS_PARAMETERS*) ProcessParameters;
PTR(PVOID) SubSystemData;
PTR(PVOID) ProcessHeap;
PTR(struct _RTL_CRITICAL_SECTION*) FastPebLock;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(PVOID) AltThunkSListPtr;
PTR(PVOID) IFEOKey;
union
{
ULONG CrossProcessFlags;
struct
{
ULONG ProcessInJob:1;
ULONG ProcessInitializing:1;
ULONG ProcessUsingVEH:1;
ULONG ProcessUsingVCH:1;
ULONG ReservedBits0:28;
};
};
union
{
PTR(PVOID) KernelCallbackTable;
PTR(PVOID) UserSharedInfoPtr;
};
#elif (NTDDI_VERSION >= NTDDI_WS03)
PTR(PVOID) AltThunkSListPtr;
PTR(PVOID) SparePtr2;
ULONG EnvironmentUpdateCount;
PTR(PVOID) KernelCallbackTable;
#else
PTR(PPEBLOCKROUTINE) FastPebLockRoutine;
PTR(PPEBLOCKROUTINE) FastPebUnlockRoutine;
ULONG EnvironmentUpdateCount;
PTR(PVOID) KernelCallbackTable;
#endif
ULONG SystemReserved[1];
ULONG SpareUlong; // AtlThunkSListPtr32
PTR(PPEB_FREE_BLOCK) FreeList;
ULONG TlsExpansionCounter;
PTR(PVOID) TlsBitmap;
ULONG TlsBitmapBits[2];
PTR(PVOID) ReadOnlySharedMemoryBase;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(PVOID) HotpatchInformation;
#else
PTR(PVOID) ReadOnlySharedMemoryHeap;
#endif
PTR(PVOID*) ReadOnlyStaticServerData;
PTR(PVOID) AnsiCodePageData;
PTR(PVOID) OemCodePageData;
PTR(PVOID) UnicodeCaseTableData;
ULONG NumberOfProcessors;
ULONG NtGlobalFlag;
LARGE_INTEGER CriticalSectionTimeout;
PTR(ULONG_PTR) HeapSegmentReserve;
PTR(ULONG_PTR) HeapSegmentCommit;
PTR(ULONG_PTR) HeapDeCommitTotalFreeThreshold;
PTR(ULONG_PTR) HeapDeCommitFreeBlockThreshold;
ULONG NumberOfHeaps;
ULONG MaximumNumberOfHeaps;
PTR(PVOID*) ProcessHeaps;
PTR(PVOID) GdiSharedHandleTable;
PTR(PVOID) ProcessStarterHelper;
ULONG GdiDCAttributeList;
PTR(struct _RTL_CRITICAL_SECTION*) LoaderLock;
ULONG OSMajorVersion;
ULONG OSMinorVersion;
USHORT OSBuildNumber;
USHORT OSCSDVersion;
ULONG OSPlatformId;
ULONG ImageSubsystem;
ULONG ImageSubsystemMajorVersion;
ULONG ImageSubsystemMinorVersion;
PTR(ULONG_PTR) ImageProcessAffinityMask;
ULONG GdiHandleBuffer[GDI_HANDLE_BUFFER_SIZE];
PTR(PPOST_PROCESS_INIT_ROUTINE) PostProcessInitRoutine;
PTR(PVOID) TlsExpansionBitmap;
ULONG TlsExpansionBitmapBits[32];
ULONG SessionId;
#if (NTDDI_VERSION >= NTDDI_WINXP)
ULARGE_INTEGER AppCompatFlags;
ULARGE_INTEGER AppCompatFlagsUser;
PTR(PVOID) pShimData;
PTR(PVOID) AppCompatInfo;
STRUCT(UNICODE_STRING) CSDVersion;
PTR(struct _ACTIVATION_CONTEXT_DATA*) ActivationContextData;
PTR(struct _ASSEMBLY_STORAGE_MAP*) ProcessAssemblyStorageMap;
PTR(struct _ACTIVATION_CONTEXT_DATA*) SystemDefaultActivationContextData;
PTR(struct _ASSEMBLY_STORAGE_MAP*) SystemAssemblyStorageMap;
PTR(ULONG_PTR) MinimumStackCommit;
#endif
#if (NTDDI_VERSION >= NTDDI_WS03)
PTR(PVOID*) FlsCallback;
STRUCT(LIST_ENTRY) FlsListHead;
PTR(PVOID) FlsBitmap;
ULONG FlsBitmapBits[4]; // [FLS_MAXIMUM_AVAILABLE/(sizeof(ULONG)*8)];
ULONG FlsHighIndex;
#endif
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(PVOID) WerRegistrationData;
PTR(PVOID) WerShipAssertPtr;
#endif
} STRUCT(PEB), *STRUCT(PPEB);
#undef PPEB
#if defined(_WIN64) && !defined(EXPLICIT_32BIT)
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Mutant) == 0x08);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Ldr) == 0x18);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FastPebLock) == 0x038);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), TlsExpansionCounter) == 0x070);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), NtGlobalFlag) == 0x0BC);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), GdiSharedHandleTable) == 0x0F8);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), LoaderLock) == 0x110);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageSubsystem) == 0x128);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageProcessAffinityMask) == 0x138);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), PostProcessInitRoutine) == 0x230);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), SessionId) == 0x2C0);
#if (NTDDI_VERSION >= NTDDI_WS03)
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FlsHighIndex) == 0x350);
#endif
#else
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Mutant) == 0x04);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Ldr) == 0x0C);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FastPebLock) == 0x01C);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), TlsExpansionCounter) == 0x03C);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), NtGlobalFlag) == 0x068);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), GdiSharedHandleTable) == 0x094);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), LoaderLock) == 0x0A0);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageSubsystem) == 0x0B4);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageProcessAffinityMask) == 0x0C0);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), PostProcessInitRoutine) == 0x14C);
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), SessionId) == 0x1D4);
#if (NTDDI_VERSION >= NTDDI_WS03)
C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FlsHighIndex) == 0x22C);
#endif
#endif
#define GDI_BATCH_BUFFER_SIZE 0x136
//
// GDI Batch Descriptor
//
typedef struct STRUCT(_GDI_TEB_BATCH)
{
ULONG Offset;
PTR(HANDLE) HDC;
ULONG Buffer[GDI_BATCH_BUFFER_SIZE];
} STRUCT(GDI_TEB_BATCH), *STRUCT(PGDI_TEB_BATCH);
//
// Thread Environment Block (TEB)
//
typedef struct STRUCT(_TEB)
{
STRUCT(NT_TIB) NtTib;
PTR(PVOID) EnvironmentPointer;
STRUCT(CLIENT_ID) ClientId;
PTR(PVOID) ActiveRpcHandle;
PTR(PVOID) ThreadLocalStoragePointer;
PTR(STRUCT(PPEB)) ProcessEnvironmentBlock;
ULONG LastErrorValue;
ULONG CountOfOwnedCriticalSections;
PTR(PVOID) CsrClientThread;
PTR(PVOID) Win32ThreadInfo;
ULONG User32Reserved[26];
ULONG UserReserved[5];
PTR(PVOID) WOW32Reserved;
LCID CurrentLocale;
ULONG FpSoftwareStatusRegister;
PTR(PVOID) SystemReserved1[54];
LONG ExceptionCode;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(struct _ACTIVATION_CONTEXT_STACK*) ActivationContextStackPointer;
UCHAR SpareBytes1[0x30 - 3 * sizeof(PTR(PVOID))];
ULONG TxFsContext;
#elif (NTDDI_VERSION >= NTDDI_WS03)
PTR(struct _ACTIVATION_CONTEXT_STACK*) ActivationContextStackPointer;
UCHAR SpareBytes1[0x34 - 3 * sizeof(PTR(PVOID))];
#else
ACTIVATION_CONTEXT_STACK ActivationContextStack;
UCHAR SpareBytes1[24];
#endif
STRUCT(GDI_TEB_BATCH) GdiTebBatch;
STRUCT(CLIENT_ID) RealClientId;
PTR(PVOID) GdiCachedProcessHandle;
ULONG GdiClientPID;
ULONG GdiClientTID;
PTR(PVOID) GdiThreadLocalInfo;
PTR(SIZE_T) Win32ClientInfo[62];
PTR(PVOID) glDispatchTable[233];
PTR(SIZE_T) glReserved1[29];
PTR(PVOID) glReserved2;
PTR(PVOID) glSectionInfo;
PTR(PVOID) glSection;
PTR(PVOID) glTable;
PTR(PVOID) glCurrentRC;
PTR(PVOID) glContext;
NTSTATUS LastStatusValue;
STRUCT(UNICODE_STRING) StaticUnicodeString;
WCHAR StaticUnicodeBuffer[261];
PTR(PVOID) DeallocationStack;
PTR(PVOID) TlsSlots[64];
STRUCT(LIST_ENTRY) TlsLinks;
PTR(PVOID) Vdm;
PTR(PVOID) ReservedForNtRpc;
PTR(PVOID) DbgSsReserved[2];
#if (NTDDI_VERSION >= NTDDI_WS03)
ULONG HardErrorMode;
#else
ULONG HardErrorsAreDisabled;
#endif
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(PVOID) Instrumentation[13 - sizeof(GUID)/sizeof(PTR(PVOID))];
GUID ActivityId;
PTR(PVOID) SubProcessTag;
PTR(PVOID) EtwLocalData;
PTR(PVOID) EtwTraceData;
#elif (NTDDI_VERSION >= NTDDI_WS03)
PTR(PVOID) Instrumentation[14];
PTR(PVOID) SubProcessTag;
PTR(PVOID) EtwLocalData;
#else
PTR(PVOID) Instrumentation[16];
#endif
PTR(PVOID) WinSockData;
ULONG GdiBatchCount;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
BOOLEAN SpareBool0;
BOOLEAN SpareBool1;
BOOLEAN SpareBool2;
#else
BOOLEAN InDbgPrint;
BOOLEAN FreeStackOnTermination;
BOOLEAN HasFiberData;
#endif
UCHAR IdealProcessor;
#if (NTDDI_VERSION >= NTDDI_WS03)
ULONG GuaranteedStackBytes;
#else
ULONG Spare3;
#endif
PTR(PVOID) ReservedForPerf;
PTR(PVOID) ReservedForOle;
ULONG WaitingOnLoaderLock;
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PTR(PVOID) SavedPriorityState;
PTR(ULONG_PTR) SoftPatchPtr1;
PTR(ULONG_PTR) ThreadPoolData;
#elif (NTDDI_VERSION >= NTDDI_WS03)
PTR(ULONG_PTR) SparePointer1;
PTR(ULONG_PTR) SoftPatchPtr1;
PTR(ULONG_PTR) SoftPatchPtr2;
#else
Wx86ThreadState Wx86Thread;
#endif
PTR(PVOID*) TlsExpansionSlots;
#if defined(_WIN64) && !defined(EXPLICIT_32BIT)
PTR(PVOID) DeallocationBStore;
PTR(PVOID) BStoreLimit;
#endif
ULONG ImpersonationLocale;
ULONG IsImpersonating;
PTR(PVOID) NlsCache;
PTR(PVOID) pShimData;
ULONG HeapVirtualAffinity;
PTR(HANDLE) CurrentTransactionHandle;
PTR(PTEB_ACTIVE_FRAME) ActiveFrame;
#if (NTDDI_VERSION >= NTDDI_WS03)
PVOID FlsData;
#endif
#if (NTDDI_VERSION >= NTDDI_LONGHORN)
PVOID PreferredLangauges;
PVOID UserPrefLanguages;
PVOID MergedPrefLanguages;
ULONG MuiImpersonation;
union
{
struct
{
USHORT SpareCrossTebFlags:16;
};
USHORT CrossTebFlags;
};
union
{
struct
{
USHORT DbgSafeThunkCall:1;
USHORT DbgInDebugPrint:1;
USHORT DbgHasFiberData:1;
USHORT DbgSkipThreadAttach:1;
USHORT DbgWerInShipAssertCode:1;
USHORT DbgIssuedInitialBp:1;
USHORT DbgClonedThread:1;
USHORT SpareSameTebBits:9;
};
USHORT SameTebFlags;
};
PTR(PVOID) TxnScopeEntercallback;
PTR(PVOID) TxnScopeExitCAllback;
PTR(PVOID) TxnScopeContext;
ULONG LockCount;
ULONG ProcessRundown;
ULONG64 LastSwitchTime;
ULONG64 TotalSwitchOutTime;
LARGE_INTEGER WaitReasonBitMap;
#else
BOOLEAN SafeThunkCall;
BOOLEAN BooleanSpare[3];
#endif
} STRUCT(TEB), *STRUCT(PTEB);
#if defined(_WIN64) && !defined(EXPLICIT_32BIT)
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), EnvironmentPointer) == 0x038);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ExceptionCode) == 0x2C0);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiTebBatch) == 0x2F0);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), LastStatusValue) == 0x1250);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), Vdm) == 0x1690);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), HardErrorMode) == 0x16B0);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiBatchCount) == 0x1740);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), IdealProcessor) == 0x1747);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), WaitingOnLoaderLock) == 0x1760);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), TlsExpansionSlots) == 0x1780);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), WaitingOnLoaderLock) == 0x1760);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ActiveFrame) == 0x17C0);
#else
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), EnvironmentPointer) == 0x01C);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ExceptionCode) == 0x1A4);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiTebBatch) == 0x1D4);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), LastStatusValue) == 0xBF4);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), Vdm) == 0xF18);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiBatchCount) == 0xF70);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), TlsExpansionSlots) == 0xF94);
C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ActiveFrame) == 0xFB0);
#endif
#undef PTR
#undef STRUCT
#undef PASTE
#undef PASTE2
#undef GDI_HANDLE_BUFFER_SIZE