Format:PE (Portable Executable)/Resource directory
Data directory 2 of a PE file: a three-level tree (type, name or id, language) of IMAGE_RESOURCE_DIRECTORY tables with RT_* types such as icons, dialogs, strings, manifests and the RT_VERSION VS_VERSIONINFO block.
Tree layout
The resource section (.rsrc) starts with a tree. Level 1 is the resource type, level 2 the name or id, level 3 the language (LANGID, for example 0x0409 en-US, 0 neutral); the leaves are data entries. Every offset in the tree is relative to the start of the resource directory, except the final RVA in the data entry.
IMAGE_RESOURCE_DIRECTORY(16 bytes):u32 Characteristics, u32 TimeDateStamp, u16 MajorVersion, u16 MinorVersion, u16 NumberOfNamedEntries, u16 NumberOfIdEntries. Followed by that many 8-byte entries: the named ones first (sorted), then the id ones (sorted).IMAGE_RESOURCE_DIRECTORY_ENTRY(8 bytes):u32 Name,u32 OffsetToData. If the top bit of Name is set, the low 31 bits are the offset of au16 length+ UTF-16 string (no NUL); otherwise Name is the integer id. If the top bit of OffsetToData is set, the low 31 bits are the offset of a subdirectory; otherwise it is the offset of a data entry.IMAGE_RESOURCE_DATA_ENTRY(16 bytes):u32 OffsetToData(an RVA, not a tree offset),u32 Size,u32 CodePage,u32 Reserved.
(pefile.py lines 2576-2597 and 4938-4943 apply exactly these masks, 0x7FFFFFFF and 0x80000000.)
Resource types
1 RT_CURSOR, 2 RT_BITMAP, 3 RT_ICON, 4 RT_MENU, 5 RT_DIALOG, 6 RT_STRING, 7 RT_FONTDIR, 8 RT_FONT, 9 RT_ACCELERATOR, 10 RT_RCDATA, 11 RT_MESSAGETABLE, 12 RT_GROUP_CURSOR, 14 RT_GROUP_ICON, 16 RT_VERSION, 17 RT_DLGINCLUDE, 19 RT_PLUGPLAY, 20 RT_VXD, 21 RT_ANICURSOR, 22 RT_ANIICON, 23 RT_HTML, 24 RT_MANIFEST. There is no 13 or 15 (reserved). Custom types use a string name or an id above 255 (for example installers and frameworks that store payloads as RCDATA or under a named type).
Notes for the common types:
- RT_STRING: strings come in blocks of 16; block id N holds string ids (N-1)16 .. N16-1; each string is a
u16length in characters and the UTF-16 text without NUL (a length of 0 means unused). - RT_GROUP_ICON / RT_ICON: the group is the
.icodirectory with the file offset replaced by the id of an RT_ICON resource; the RT_ICON data is the image part of the.icoentry (a DIB without the file header, or a PNG for large icons). Unverified in this wiki's tests for the 14-byte GRPICONDIRENTRY layout. - RT_MANIFEST (24): the application manifest XML (UTF-8), usually id 1 (executables) or 2 (DLLs) with language 0; carries
requestedExecutionLevel,supportedOSGUIDs, DPI awareness and side-by-side dependencies. - RT_RCDATA: raw data defined by the program; Delphi and C++Builder store their forms there (
PACKAGEINFO,DVCLAL, andTPF0form streams).
Layouts of the UI types: Format:Windows dialog template resource (RT_DIALOG), Format:Windows menu resource (RT_MENU), Format:Windows accelerator table resource (RT_ACCELERATOR); frameworks that consume them: Technique:Identifying Windows GUI frameworks.
VS_VERSIONINFO (RT_VERSION)
RT_VERSION id 1 (language usually 0x0409 or neutral) holds the file's version information. It is a tree of nodes, each u16 wLength (total node size including children), u16 wValueLength, u16 wType (1 text, 0 binary), the key as NUL-terminated UTF-16, padding to a 4-byte boundary (relative to the resource start), the value, padding again, then the child nodes.
- Root: key
VS_VERSION_INFO, value a 52-byteVS_FIXEDFILEINFO(wValueLength 52, wType 0):u32 dwSignature0xFEEF04BD,dwStrucVersion0x00010000,dwFileVersionMS/LS(major<<16|minor, build<<16|revision),dwProductVersionMS/LS,dwFileFlagsMask,dwFileFlags(0x01 DEBUG, 0x02 PRERELEASE, 0x04 PATCHED, 0x08 PRIVATEBUILD, 0x10 INFOINFERRED, 0x20 SPECIALBUILD),dwFileOS(for example 0x00040004 VOS_NT_WINDOWS32),dwFileType(1 VFT_APP, 2 VFT_DLL, 3 VFT_DRV, 4 VFT_FONT, 5 VFT_VXD, 7 VFT_STATIC_LIB),dwFileSubtype,dwFileDateMS/LS. - Child
StringFileInfo(wType 1, no value) with oneStringTableper language, key = 8 hex digitsLLLLCCCC(language id, code page;040904B0is en-US with code page 1200 = UTF-16,040904E4is code page 1252). EachStringnode has the field name as key (CompanyName,FileDescription,FileVersion,InternalName,LegalCopyright,OriginalFilename,ProductName,ProductVersion,Comments,LegalTrademarks,PrivateBuild,SpecialBuild) and the UTF-16 text as value; wValueLength counts characters here (including the NUL). - Child
VarFileInfowith oneVarnode, keyTranslation, value an array of dwords (language id in the low word, code page in the high word) listing the string tables present.
The fixed-info version numbers and the FileVersion string are independent and often disagree; OriginalFilename is useful to detect a renamed binary. pefile exposes this as VS_FIXEDFILEINFO, FileInfo, and FileInfo[..].StringTable[..].entries.
Code & repositories
- pefile resource and version parsing (pefile.py
parse_resources_directory,parse_version_information, lines 4611-4945 and 4960-5370). - Wine
include/verrsrc.h(VS_FFI_SIGNATURE, VS_FF_, VOS_, VFT_) andinclude/winuser.h(RT_, lines 813-842).
Evidence & references
- Microsoft, "PE Format", section ".rsrc Section"; "VS_VERSIONINFO structure" and "VS_FIXEDFILEINFO structure" (learn.microsoft.com).
- Constants cross-checked between pefile
resource_type(lines 405-430) and Wine winuser.h.