Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Platform:Windows/PEB and TEB

From ReverseEngineering.wiki
Topic page of Platform:Windows.

The Thread Environment Block (TEB) and Process Environment Block (PEB): how user-mode code finds them (fs:[0x18]/fs:[0x30] on x86, gs:[0x30]/gs:[0x60] on x64) and the fields programs actually read.

Finding the blocks

  • x86: fs:[0x18] is the TEB's own address (NT_TIB.Self), fs:[0x30] is the PEB pointer (TEB.ProcessEnvironmentBlock), fs:[0x00] the SEH chain head, fs:[0x04]/fs:[0x08] stack base/limit.
  • x64: gs:[0x30] is Self, gs:[0x60] the PEB, gs:[0x08]/gs:[0x10] stack base/limit. NtCurrentTeb() is just that one read.
  • ARM64 Windows: register x18 holds the TEB pointer.
  • A 32-bit process under WOW64 reads the 32-bit TEB through fs:; offsets are the x86 ones.
  • Typical shapes in disassembly: mov eax, fs:[30h], mov rax, gs:[60h], then [eax+0Ch] / [rax+18h] (Ldr) to walk modules, [+2] BeingDebugged, [+8]/[+10h] image base.
  • Thread-local storage: TEB.ThreadLocalStoragePointer (x86 fs:[0x2C], x64 gs:[0x58]) points to the array indexed by the image's _tls_index; the first 64 TlsAlloc slots are in TEB.TlsSlots (0xE10 x86, 0x1480 x64).

PEB fields programs read

See the struct facts for the full offsets: BeingDebugged (byte at +2, set while a user-mode debugger is attached), ImageBaseAddress, Ldr, ProcessParameters, ProcessHeap, NumberOfProcessors, NtGlobalFlag, OSMajorVersion/OSMinorVersion/OSBuildNumber, SessionId.

RTL_USER_PROCESS_PARAMETERS

PEB.ProcessParameters points to command line (CommandLine, UTF-16 UNICODE_STRING), ImagePathName, CurrentDirectory, DllPath, Environment (a block of NUL-separated UTF-16 NAME=value strings ended by an empty string), the standard handles, window title and startup flags. Until normalized (Flags & 1, RTL_USER_PROC_PARAMS_NORMALIZED) the string buffers hold offsets from the block start, not pointers; the loader normalizes it before the process runs.

Related

Platform:Windows, Platform:Windows/Loader module lists, Platform:Windows/KUSER_SHARED_DATA.

Code & repositories

  • https://github.com/winsiderss/phnt @ 53fbbdc5b5d2b08761db1c7b26bfa8c820924356 · license: MIT
    phnt (MIT): Native API headers of System Informer; PEB, TEB, loader, RTL_USER_PROCESS_PARAMETERS, KUSER_SHARED_DATA with offset static_asserts.
    Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-03-26

Evidence & references

phnt ntpebteb.h, ntrtl.h (MIT), see the linked repository and the struct facts.