A key is stored as a key node (nk) in a cell.
This page follows Maxim Suhanov’s Windows registry file format specification. Offsets are counted from
the start of the hive bins data unless said otherwise.
Key node
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 2 | Signature | nk |
| 2 | 2 | Flags | Bit mask, below |
| 4 | 8 | Last written timestamp | FILETIME (UTC) |
| 12 | 4 | Access bits | Windows 8 and Server 2012 onwards; before that a reserved field called Spare |
| 16 | 4 | Parent | Offset of the parent key node; no meaning on a disk for the root key node |
| 20 | 4 | Number of subkeys | |
| 24 | 4 | Number of volatile subkeys | |
| 28 | 4 | Subkeys list offset | May point at an index root |
| 32 | 4 | Volatile subkeys list offset | No meaning on a disk: volatile keys are not written to a file |
| 36 | 4 | Number of key values | |
| 40 | 4 | Key values list offset | A list of 4-byte offsets of key values, in no required order |
| 44 | 4 | Key security offset | The sk cell, see Security descriptors |
| 48 | 4 | Class name offset | |
| 52 | 4 | Largest subkey name length | Bytes, the name read as UTF-16LE; in later versions split in four fields, below |
| 56 | 4 | Largest subkey class name length | Bytes |
| 60 | 4 | Largest value name length | Bytes, the name read as UTF-16LE |
| 64 | 4 | Largest value data size | Bytes |
| 68 | 4 | WorkVar | A cached index, below |
| 72 | 2 | Key name length | Bytes |
| 74 | 2 | Class name length | Bytes |
| 76 | … | Key name string | ASCII (extended) or UTF-16LE: see the flags |
An extended ASCII string is one made from UTF-16LE characters with codes below 256 by dropping the high zero byte of each.
From Windows Vista, Windows Server 2003 SP2 and Windows XP SP3 the largest subkey name length field is split, counting bits from the start of the field’s lowest-addressed byte:
| Bits | Length | Field |
|---|---|---|
| 0 | 16 | Largest subkey name length |
| 16 | 4 | Virtualization control flags |
| 20 | 4 | User flags (Wow64 flags) |
| 24 | 8 | Debug |
Beware that a C compiler may pack the two 4-bit fields right to left, so the first bit field would sit in the less significant bits; the table gives the order in which they are stored in the file. In Windows debug symbols UserFlags is defined before VirtControlFlags for this reason.
From Windows 10 “Redstone 1” Insider builds the access bits field is split into: access bits (1 byte), layered key bit fields (1 byte) and 2 spare bytes. The layered key byte, counting bits from the most significant: bit 0 is Inherit class, bits 1 to 5 are spare, bits 6 and 7 are Layer semantics.
Flags
In Windows XP and Windows Server 2003 the first four bits, counting from the most significant bit, are
reserved for user flags (set through NtSetInformationKey()). The other bits are:
| Mask | Name | Meaning |
|---|---|---|
0x0001 | KEY_VOLATILE | Volatile; not expected to be set in a file |
0x0002 | KEY_HIVE_EXIT | Mount point of another hive; not expected to be set in a file |
0x0004 | KEY_HIVE_ENTRY | The root key of this hive |
0x0008 | KEY_NO_DELETE | The key cannot be deleted |
0x0010 | KEY_SYM_LINK | A symbolic link: its target is a UTF-16LE string (REG_LINK) in a value named SymbolicLinkValue |
0x0020 | KEY_COMP_NAME | The key name is an ASCII string, possibly extended ASCII; otherwise UTF-16LE |
0x0040 | KEY_PREDEF_HANDLE | A predefined handle, stored in the number of key values field |
0x0080 | VirtualSource | Virtualized at least once (Windows Vista on) |
0x0100 | VirtualTarget | Is virtual |
0x0200 | VirtualStore | Part of a virtual store path |
From Windows Vista the user flags moved out of the first four bits of Flags into the User
flags field (also called Wow64 flags); in Windows XP and Server 2003 they stay in the old place. In
Windows Vista and 7 the fourth bit from the top of Flags is set in many key nodes of the initial hives
on an installation image; it cannot be read through NtQueryKey().
Access bits
| Mask | Meaning |
|---|---|
0x1 | Accessed before the registry was initialised with NtInitializeRegistry() during boot |
0x2 | Accessed after that |
Zero means the access history is clear.
User flags, virtualization control flags and debug
| Field | Mask | Meaning |
|---|---|---|
| User flags | 0x1 | A 32-bit key: created through Wow64, or not to be used by a 64-bit program (not used for user-mode keys from Windows 7) |
| User flags | 0x2 | Created by the reflection process |
| User flags | 0x4 | Disable registry reflection for this key |
| User flags | 0x8 | Old location: execute int 3 on access (replaced by Debug); new location: disable reflection if a key exists in the other view and was not created by the caller (pre-release Windows Vista only) |
| Virtualization control | 0x2 | REG_KEY_DONT_VIRTUALIZE: no write virtualization |
| Virtualization control | 0x4 | REG_KEY_DONT_SILENT_FAIL: no open virtualization |
| Virtualization control | 0x8 | REG_KEY_RECURSE_FLAG: pass the flags to new subkeys |
| Debug | 0x01 … 0x80 | A checked kernel with CmpRegDebugBreakEnabled set executes int 3 on: open, delete, security change, subkey created, subkey deleted, value set, value deleted, key virtualized (in that bit order) |
Layered keys
Layered keys, from Windows 10 “Redstone 1” Insider builds, implement the containerised registry: a kernel builds a stack of key nodes from a host hive (top layer) and a differencing hive and merges them. Inherit class 0 means the layered key keeps the class name of the node first accessed; 1 means it takes the class name of an upper node with the bit set to 0. Layer semantics:
| Value | Name | Meaning |
|---|---|---|
| 0 | This node and its “parents” can join the layered key | |
| 1 | IsTombstone | This node and its parents cannot join; a tombstone has no class name, subkeys or values |
| 2 | IsSupersedeLocal | This node can join but its parents cannot |
| 3 | IsSupersedeTree | As 2; subkeys other than tombstones must have the same value |
Class name and WorkVar
A class name is typically a UTF-16LE string with no particular meaning (Microsoft used class names to store the keys of the Syskey encryption). In Windows 2000, WorkVar may hold the zero-based index of the subkey found by the last lookup, to speed up repeated access; it is not used as of Windows XP.
Subkey lists
Each list starts with a 2-byte signature and a 2-byte count of elements. All elements must be sorted ascending by the upper-case key name, compared by character code.
| Record | Signature | Element | Notes |
|---|---|---|---|
| Index leaf | li | 4 bytes: key node offset | |
| Fast leaf | lf | 8 bytes: key node offset, then a 4-byte name hint | The hint is the first four characters of the name as extended ASCII, padded with zeros; if the name cannot be converted, the first byte is zero. Not used when the minor version is 1 or 2. |
| Hash leaf | lh | 8 bytes: key node offset, then a 4-byte name hash | Used when the minor version is greater than 4 |
| Index root | ri | 4 bytes: offset of a subkey list | Divides a long list. An index root cannot point at another index root and a subkey list cannot point at one; the elements across all lists of one index root must be sorted as a whole. |
The name hash: let H be 0 as a 32-bit value; for each character code C of the upper-case name as UTF-16 code units, H = 37 × H + C. The result is the hash.