Format:Realm database file
| Magic | T-DB at offset 16 |
|---|---|
| Extensions | .realm, .realm.lock, .realm.management |
| License | Apache-2.0 |
| Website | https://github.com/realm/realm-core |
| On this wiki | Facts · Code · Notes · Topics |
Realm Core's .realm file: a 24-byte header with two top refs, the mnemonic "T-DB", two file-format version bytes and a flags byte whose low bit selects the live top ref; a streaming footer uses magic cookie 0x3034125237E526C8.
Overview
Realm (realm-core, used by the Realm SDKs for Android, iOS and others) stores a whole database in one memory-mapped .realm file with a copy-on-write structure of arrays addressed by byte offsets (refs). Sidecar files such as .realm.lock coordinate processes (Unverified: sidecar names).
Header
The file starts with the SlabAlloc Header of 24 bytes (src/realm/alloc_slab.hpp): m_top_ref[2] (two uint64 byte offsets of the top array), m_mnemonic[4] = 'T','-','D','B' at offset 16, m_file_format[2] at offset 20 (one byte per top ref), m_reserved at 22, m_flags at 23 whose bit 0 selects which top ref is current. A freshly created file has both top refs 0 and format bytes 0 (alloc_slab.cpp empty_file_header).
Validation (SlabAlloc::validate_header, alloc_slab.cpp): the file must be at least 24 bytes and a multiple of 8, the mnemonic must match, and the top ref chosen by bit 0 of the flags byte must be 8-aligned and inside the file; details in Fact:Realm database file/identification/Realm header validation. The two m_file_format bytes hold the file format version of each top-ref slot (24 at the pinned commit, list in Fact:Realm database file/enum/Realm file format versions).
Streaming form
A file written in streaming mode sets m_top_ref[0] to 0xFFFFFFFFFFFFFFFF and carries a 16-byte StreamingFooter at the end: the real top ref (uint64) and the magic cookie 0x3034125237E526C8.
Reversing notes
- Opening a non-Realm file fails with "header has invalid mnemonic. The file does not appear to be Realm file." (alloc_slab.cpp).
- The top ref points to the top array; further structure (groups, tables, columns, B+trees of arrays with an 8-byte node header) is in array.hpp and node_header.hpp. The 8-byte node header is in Fact:Realm database file/struct/Realm node header. Unverified: the table/column spec arrays.
- For an unencrypted open, validate_header words a bad mnemonic as 'either not a Realm file, is an encrypted Realm file but no encryption key was supplied, or is corrupted', which implies encrypted files do not show the plain mnemonic. Unverified: the encryption layout itself (AES, key supplied by the app) was not read.
Code & repositories
- https://github.com/realm/realm-core @
f8752e180b7f288feadffafdef818068755efe0a· license: Apache-2.0 (read from LICENSE; GitHub's API was busy)
Realm Core storage engine; src/realm/alloc_slab.hpp defines the file header.
Tested on: source read, not run: read selected files · checked 2026-10-18