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

Format:PE (Portable Executable)/Load config directory

From ReverseEngineering.wiki

Data directory 10 of a PE file: IMAGE_LOAD_CONFIG_DIRECTORY, a versioned structure (its first dword is its own size) holding the security cookie, the SafeSEH handler table, the Control Flow Guard function table and flags, and later mitigations (XFG, EH continuation, hot patching, dynamic relocations).

Layout

The directory (index 10) starts with u32 Size, which says how many bytes the producing linker wrote; fields beyond Size do not exist, so a parser must read only Size bytes. The structure grew with each Windows release, so Size differs between linkers. Pointers are VAs, not RVAs (they are relocated, and are 8 bytes in PE32+).

PE32+ offsets (from Wine winnt.h and pefile): 0x00 Size, 0x04 TimeDateStamp, 0x08 MajorVersion, 0x0A MinorVersion, 0x0C GlobalFlagsClear, 0x10 GlobalFlagsSet, 0x14 CriticalSectionDefaultTimeout, 0x18 DeCommitFreeBlockThreshold (8), 0x20 DeCommitTotalFreeThreshold, 0x28 LockPrefixTable, 0x30 MaximumAllocationSize, 0x38 VirtualMemoryThreshold, 0x40 ProcessAffinityMask, 0x48 ProcessHeapFlags (4), 0x4C CSDVersion (2), 0x4E DependentLoadFlags (2), 0x50 EditList, 0x58 SecurityCookie, 0x60 SEHandlerTable, 0x68 SEHandlerCount, 0x70 GuardCFCheckFunctionPointer, 0x78 GuardCFDispatchFunctionPointer, 0x80 GuardCFFunctionTable, 0x88 GuardCFFunctionCount, 0x90 GuardFlags (4), 0x94 CodeIntegrity (12 bytes: Flags u16, Catalog u16, CatalogOffset u32, Reserved u32), 0xA0 GuardAddressTakenIatEntryTable, 0xA8 ...Count, 0xB0 GuardLongJumpTargetTable, 0xB8 ...Count, 0xC0 DynamicValueRelocTable, 0xC8 CHPEMetadataPointer, 0xD0 GuardRFFailureRoutine, 0xD8 GuardRFFailureRoutineFunctionPointer, 0xE0 DynamicValueRelocTableOffset (4), 0xE4 DynamicValueRelocTableSection (2), 0xE8 GuardRFVerifyStackPointerFunctionPointer, 0xF0 HotPatchTableOffset (4), 0xF8 EnclaveConfigurationPointer, 0x100 VolatileMetadataPointer, 0x108 GuardEHContinuationTable, 0x110 ...Count, 0x118-0x128 the three GuardXFG pointers, 0x130 CastGuardOsDeterminedFailureMode, 0x138 GuardMemcpyFunctionPointer; total 0x140.

PE32: the same order with 4-byte pointers and the two 8-byte thresholds, ProcessAffinityMask and the pointer fields shrunk; ProcessHeapFlags is at 0x2C and ProcessAffinityMask at 0x30, SecurityCookie at 0x3C, SEHandlerTable 0x40, GuardCFFunctionTable 0x50, GuardFlags 0x58, total 0xC0. Use pefile's __IMAGE_LOAD_CONFIG_DIRECTORY_format__ (lines 2737-2793) for the exact 32-bit sequence.

Fields worth knowing

  • SecurityCookie: VA of the /GS cookie (__security_cookie). Finding it names the stack-protector variable in the CRT startup code (__security_init_cookie) and the check __security_check_cookie.
  • SEHandlerTable / SEHandlerCount (x86 only): VA of a sorted array of RVAs of the exception handlers that are legal for SafeSEH. An x86 image without the table but with the flag IMAGE_DLLCHARACTERISTICS_NO_SEH has no handlers at all.
  • GuardCFFunctionTable / Count: sorted array of RVAs of all valid indirect-call targets (Control Flow Guard). Each entry is a 4-byte RVA followed by GuardFlags >> 28 extra bytes (the stride, from IMAGE_GUARD_CF_FUNCTION_TABLE_SIZE_MASK 0xF0000000); the extra bytes carry per-target flags (for example a suppressed export). LIEF parses the stride this way (LoadConfiguration.cpp lines 558-600). The check and dispatch pointers hold the address of the slot that the loader fills with ntdll!LdrpValidateUserCallTarget / LdrpDispatchUserCallTarget; instrumented calls look like call [__guard_check_icall_fptr].
  • GuardFlags (IMAGE_GUARD_*): 0x100 CF_INSTRUMENTED, 0x200 CFW_INSTRUMENTED, 0x400 CF_FUNCTION_TABLE_PRESENT, 0x800 SECURITY_COOKIE_UNUSED, 0x1000 PROTECT_DELAYLOAD_IAT, 0x2000 DELAYLOAD_IAT_IN_ITS_OWN_SECTION, 0x4000 CF_EXPORT_SUPPRESSION_INFO_PRESENT, 0x8000 CF_ENABLE_EXPORT_SUPPRESSION, 0x10000 CF_LONGJUMP_TABLE_PRESENT, 0x20000 RF_INSTRUMENTED, 0x40000 RF_ENABLE, 0x80000 RF_STRICT, 0x100000 RETPOLINE_PRESENT, 0x400000 EH_CONTINUATION_TABLE_PRESENT, 0x800000 XFG_ENABLED, 0x1000000 CASTGUARD_PRESENT, 0x2000000 MEMCPY_PRESENT, top nibble 0xF0000000 the table stride. CFG is also advertised by DllCharacteristics 0x4000 (GUARD_CF).
  • GuardAddressTakenIatEntryTable, GuardLongJumpTargetTable, GuardEHContinuationTable (CET): further sorted RVA tables with the same stride rule.
  • DynamicValueRelocTable: a table (IMAGE_DYNAMIC_RELOCATION_TABLE: Version, Size, then records of Symbol and BaseRelocSize) for retpoline and import-control-transfer patching, and the ARM64X relocations of hybrid images (symbol values 1-6: GUARD_RF_PROLOGUE, GUARD_RF_EPILOGUE, GUARD_IMPORT_CONTROL_TRANSFER, GUARD_INDIR_CONTROL_TRANSFER, GUARD_SWITCHTABLE_BRANCH, ARM64X; Wine winnt.h lines 4223-4280).
  • CHPEMetadataPointer: on ARM64EC and x86-on-ARM images, points to the compiled hybrid PE metadata (code ranges split into native and emulated).

For reversers

CFG-aware tools use GuardCFFunctionTable as a free list of function starts: on a stripped x64 binary built with /guard:cf it names most functions, including those only reached indirectly (virtual functions, callbacks). Combine it with the exception directory (see Format:PE (Portable Executable)/Exception directory), which lists every non-leaf function.

Code & repositories

  • pefile structure formats (pefile.py lines 2737-2870), LIEF LoadConfiguration.hpp (IMAGE_GUARD enum lines 51-106) and LoadConfiguration.cpp, Wine include/winnt.h (IMAGE_LOAD_CONFIG_DIRECTORY64 lines 4111-4161).

Evidence & references

  • Microsoft, "PE Format", section "The Load Configuration Structure".
  • The 32-bit offsets above are computed from the field order and sizes in pefile; Unverified against a 32-bit binary in this wiki (test: parse any x86 file with pefile and print DIRECTORY_ENTRY_LOAD_CONFIG.struct.get_field_absolute_offset('GuardFlags')).