A KF8 book has up to four indexes, each starting at a record named in the MOBI header: the skeleton index (0xFC), the fragment index (0xF8), the NCX index for the table of contents (0xF4) and the guide index (0x104). They use the same index records as MOBI. Amazon has not documented them; tag meanings follow KindleUnpack and calibre.
How an index is stored
Each index is a run of records:
- A meta
INDXrecord: the INDX header, then aTAGXtable listing the tags an entry may have, each with a value count, a bit mask and an end-of-control-byte flag. - One or more
INDXrecords of entries, each ending in anIDXTtable of UInt16 entry offsets. CNCXrecords holding strings the entries refer to, as forward-encoded length plus bytes; a string’s reference is record number × 0x10000 + offset.
An entry is a length byte and its key text, then the control bytes, then the tag values as forward-encoded variable-width integers, decoded with the TAGX masks. The full layout of these records, field by field, is on the MOBI page Index and other records; it is identical in KF8.
Skeleton index
One entry per XHTML file, in the order the files are stored in flow 0. The key is a
name such as SKEL0000000000, numbered from 0.
| Tag | Values | Meaning |
|---|---|---|
| 1 | 1 | The number of fragments that belong to this skeleton. |
| 6 | 2 | The skeleton’s start in flow 0, and its length in bytes. Files may carry the pair twice; readers use the first. |
The file number of a skeleton is its position in the index, from 0.
Fragment index
One entry per fragment, in the order the fragments are stored. The key is the fragment’s insert position, written in decimal digits: where in the rebuilt text the fragment goes (see skeletons and fragments).
| Tag | Values | Meaning |
|---|---|---|
| 2 | 1 | A CNCX reference to a selector naming the element the fragment is inserted into, such as P-//*[@aid='0']. |
| 3 | 1 | The file number: the skeleton this fragment belongs to. |
| 4 | 1 | The sequence number of the fragment in the book, from 0. |
| 6 | 2 | The fragment’s start and its length. KindleUnpack and calibre use only the length: the fragments of a skeleton follow it directly in flow 0, one after another. |
The fragment number used in kindle:pos:fid links is the position of the
entry in this index, from 0.
NCX index (table of contents)
Built from the source book’s NCX or navigation document. One entry per table of contents item, in reading order.
| Tag | Values | Meaning |
|---|---|---|
| 1 | 1 | The target’s position in the raw text. |
| 2 | 1 | The length of text the item covers. |
| 3 | 1 | The label, as a CNCX reference. |
| 4 | 1 | The depth, 0 for top-level items. |
| 5 | 1 | A class name, as a CNCX reference. |
| 6 | 2 | The target as a fragment number and an offset, the same two numbers as in a kindle:pos:fid link. This is the tag KF8 readers use. |
| 21 | 1 | The parent item’s number. |
| 22 | 1 | The first child’s number. |
| 23 | 1 | The last child’s number. |
| 69–73 | 1 each | Periodicals only: image, description, author, image caption and image attribution. |
Guide index
Built from the source OPF’s guide: landmarks such as the cover, the
table of contents and where the text starts. The key is the guide type, such as
toc, text or cover.
| Tag | Values | Meaning |
|---|---|---|
| 1 | 1 | The title, as a CNCX reference. |
| 3 | 1 | The file number the landmark points into (older files). |
| 6 | 2 | The target as a fragment number and offset (newer files). |
KindleUnpack turns the key start into the EPUB guide type
text and prefixes unknown types with other..
Other indexes
Dictionaries also have orthographic and inflection indexes, at the MOBI header’s 0x28 and 0x2C, as in MOBI dictionaries. Their tags are not publicly documented.