Introduction
A registry hive is one of the binary files in which Windows
keeps the registry: the tree of keys and values that holds the settings of the system and its programs.
The machine’s registry is built from several hives (SYSTEM, SOFTWARE,
SAM, SECURITY and others), and each user’s settings are a hive of their own
(NTUSER.DAT). Boot configuration data (BCD) is a hive too. Every one of them
starts with the four characters regf, which is why the format is called REGF.
This reference follows Maxim Suhanov’s public specification, Windows registry file format specification (licensed CC BY 4.0), and describes what is stored in the file, not how the registry behaves in a running system. The text export of the registry, which is a different format, is covered under .REG.
Files that belong to a hive
A stable hive is made of a primary file, which holds the data, and up to two transaction log files, which let Windows finish a write that a crash cut short. A backup copy of the primary file may also exist; it has the same format. Examples from the specification for Windows 8.1 and Windows Vista:
\Windows\System32\config\SYSTEM, withSYSTEM.LOG1andSYSTEM.LOG2(and, as an artefact of an installation image, an emptySYSTEM.LOG);\Boot\BCDwithBCD.LOG1andBCD.LOG2;- Windows XP:
systemwith one log file,system.LOG, and a backupsystem.sav.
The log files have their own layout, described on Transaction logs. A log that records writes through the Transactional Registry (TxR) is a different thing: it lives in Common Log File System files, which the specification does not cover.
Structure
A primary file is a 4096-byte base block followed by
the hive bins. Each bin is a multiple of 4096 bytes, starts with a 32-byte header and is
filled, without gaps, with cells. A cell is the unit of
storage: its first four bytes are its size (negative when the cell is in use), and its data is one of
the records below. Offsets between records are counted from the start of the first hive bin, that is,
file offset minus 4096, and the value 0xFFFFFFFF points nowhere. Anything after the last
bin (padding or remnants) is not part of the hive.
0Base block signatureregf, sequence numbers, version, root cell offset, bins size, checksum4096 bytes4096Hive bin headerhbin(offset, size) and then cells:nk,vk,sk,li,lf,lh,ri,db, raw data, free cellsmultiple of 4096…More hive bins up to the size the base block statesvaries…Padding or remnant data after the last binany
How the records point at each other:
- The base block points to the root cell, which holds a key node (
nk). - A key node points to its parent key node, to a list of its subkeys (each a key node), to a list of its
values, and to a key security item (
sk, see Security descriptors). - A subkey list can be split into several lists with an index root (
ri). - A key value (
vk) holds its data inside itself, in one more cell, or, for data over 16,344 bytes, in a big data record (db) that lists the cells holding the pieces.
In the explorer
Drop a hive (NTUSER.DAT, SYSTEM, SOFTWARE, SAM,
SECURITY, BCD, a .hve or .hiv file, or any .dat that
starts with regf) on the page. The structure tree follows the file: the base block with every field and its
checksum, the hive bins, each bin’s header and cells, and each cell’s fields (key nodes, values, security items, subkey
lists, big data), with free cells marked. The tabs show the hive as a registry:
- Hive: the base block, the sequence numbers, the version, whether the hive is dirty and why, and every problem found (a wrong checksum, a cell that does not fit its bin, a key whose parent or counts disagree with the lists, an unsorted subkey list, a wrong name hash, a security item with the wrong reference count).
- Keys: the root key with its values, decoded by type, and its subkeys; each subkey opens the same way. Tables of any length are read a page at a time.
- Security: the security items, each with its owner, group, DACL and SACL entries, SIDs and key rights.
- Recovered: keys and values found in free cells, labelled as recovered and never mixed with live data.
- Logs: when the hive is dropped together with its
.LOG1and.LOG2files (drop the folder or select all of them), the logs, in the old or the new format, with their dirty pages, sequence numbers and the Marvin32 hashes of the new format, and whether they apply to the hive. A log file can also be opened on its own.
A hive of hundreds of megabytes opens by reading its base block and its root key. The walks that read every cell and key (the consistency check, the count of free cells, the recovered records) are made at open only for a hive up to 16 MiB, and otherwise when their section is opened.
Not described
Known, not yet covered
- Viewer: transaction logs are not applied: the viewer lists their dirty pages, hashes and sequence numbers and says whether they apply, with a simple test (the log’s timestamp for the old format, entries not older than the hive’s sequence number for the new one). It does not work out the recovered hive or follow every rule about where recovery stops.
- Viewer: the data of
REG_RESOURCE_LIST,REG_FULL_RESOURCE_DESCRIPTORandREG_RESOURCE_REQUIREMENTS_LISTvalues is shown as bytes, and so is value data of unknown types. - Viewer: access-control entries of the types reserved, resource attribute and scoped policy ID are named but not taken apart, and the application data of callback entries is not shown.
- Viewer: layered keys are shown by their raw layer byte and the tombstone flag; the layers of a host hive and a differencing hive are not merged. Hives of versions 1.1 and 1.2 are read by the specification’s notes but no real Windows NT 3.x hive was available to check them.
- Reference: hive versions 1.1 and 1.2 (Windows NT 3.1, 3.5 and 3.51) are covered only by the notes the specification gives (hive bins and cells); pre-release hives of version 1.0 are outside the specification.
- Reference: Transactional Registry (TxR) and the CLFS files it writes are outside the specification and are not described.
- Reference: the layout of security descriptors, ACLs, ACEs and SIDs comes from Microsoft’s MS-DTYP specification, not from the hive specification. The descriptor, ACL and ACE header pages of MS-DTYP were read for this reference; the layouts of the object and callback ACE bodies were not fetched, and ACE types other than the common ones are named but not taken apart (Security descriptors).
- Reference: the exact way Windows treats a hive in memory (locking, lazy flushing, the reorganisation schedule beyond what the specification says) is not described; these pages say what is stored in the file.
- Reference: these pages were checked against the test hives of the yarp project (small hives and logs, some written by Windows 7, 8.1 and 10, with the hives Windows recovered from the logs) and hives made for the viewer’s tests; no full NTUSER.DAT or SYSTEM hive of a real installation was checked.
Unknown
- Viewer: a recovered value is not tied to the key that owned it, because a value record does not say; recovered records are found by their signatures at 8-byte steps inside free cells, so a record whose cell was written over, or that sits at another offset, is not found. How Windows turns names with characters above 255 into the four-character hints of a fast leaf is not specified, so the viewer checks hints only for plain ASCII names.
- Reference: the exact on-disk meaning of fields that the specification calls unused or reserved (the Spare field of a hive bin header, the reserved areas of the base block not named there) is documented nowhere public.
- Reference: hives of the Windows 10 containerised registry (layered keys) are covered as far as the specification goes; how a kernel merges layers is not documented in the file format.
Links
Software
- Registry Editor (regedit) – built into Windows; opens the live registry and can load a hive file into it (Windows)
- Registry Explorer – Eric Zimmerman’s viewer for offline hives, with their transaction logs (Windows)
Developers
- yarp – Maxim Suhanov’s library for reading hives, applying transaction logs and recovering deleted data (Python)
- libregf – library and tools for reading registry files (C)
- hivex – library for reading and writing hives (C)
- python-registry – read-only access to hives (Python)
Reference
- Windows registry file format specification – Maxim Suhanov’s specification, the source of these pages
- Windows NT Registry File (REGF) format – Joachim Metz’s document in libregf
- MS-DTYP: SECURITY_DESCRIPTOR – Microsoft’s layout of the security descriptors stored in
skcells