Each .iwa (iWork Archive) file in a Keynote presentation holds one
component of its object graph, such as the document or one master slide: a stream of
Protocol Buffers messages compressed with Snappy. This page follows the
iWorkFileFormat project; Apple has published none of it.
Chunk framing
The file is a run of chunks with 4-byte headers, like Snappy’s framing format but with no stream identifier chunk and no CRC-32C checksums.
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 1 | Chunk type | Always 0 in iWork files: Snappy-compressed. |
1 | 3 | Length | 24-bit little-endian length of the chunk data, without the header. |
4 | length | Data | One Snappy-compressed block. |
Snappy blocks
A block starts with the uncompressed length as a varint, then elements whose tag byte’s low two bits give the kind:
| Tag bits 0–1 | Element | Layout |
|---|---|---|
00 | Literal | Bits 2–7: length − 1 (0–59); 60–63 mean length − 1 follows in 1–4 little-endian bytes. Then the bytes. |
01 | Copy, 1-byte offset | Bits 2–4: length − 4. Bits 5–7: top three bits of an 11-bit offset; the next byte is the low eight. |
10 | Copy, 2-byte offset | Bits 2–7: length − 1. Then a 16-bit little-endian offset. |
11 | Copy, 4-byte offset | Bits 2–7: length − 1. Then a 32-bit little-endian offset. |
A copy repeats bytes from offset bytes back in the output, possibly overlapping.
Object stream
The decompressed data is a sequence of objects: a varint length, an
ArchiveInfo message of that length, and the payload or payloads it
describes (in practice one).
message ArchiveInfo {
optional uint64 identifier = 1; // unique across the presentation
repeated MessageInfo message_infos = 2;
}
message MessageInfo {
required uint32 type = 1; // which message the payload is
repeated uint32 version = 2 [packed = true]; // format version, 1.0.5 when documented
required uint32 length = 3; // payload length in bytes
repeated FieldInfo field_infos = 4; // not seen in practice
repeated uint64 object_references = 5 [packed = true];
repeated uint64 data_references = 6 [packed = true];
}
Objects refer to each other by identifier, across files.
object_references and data_references list the objects and
data files an object uses. A reader needs each payload’s Protocol Buffers definition;
iWorkFileFormat extracted them from the programs with proto-dump.
Message types
Type numbers come from each program’s TSPRegistry. Keynote uses the
shared iWork frameworks’ numbers and its own KN types. These are the
numbers iWorkFileFormat extracted from Keynote 6 (2013).
| Prefix | Framework | Type numbers |
|---|---|---|
KN | Keynote itself | 1–148 (66 types) |
TSK | Kit: document, commands, undo | 200–215 and a few more |
TSS | Styles and themes | 400–418 |
TSA | Application | 600–602 |
TSWP | Text | 2001–2406 |
TSD | Drawables: shapes, images, movies | 3002–3060 |
TSCE | Calculation engine | 4000–4005 |
TSCH | Charts | 5000–5132 |
TST | Tables | 6000–6256 |
TSP | Persistence | 11000–11008 |
| Type | Message | Type | Message |
|---|---|---|---|
| 1 | KN.DocumentArchive (the root) | 14 | TSWP.TextualAttachmentArchive |
| 2 | KN.ShowArchive | 15 | KN.NoteArchive (presenter notes) |
| 3 | KN.UIStateArchive | 16 | KN.RecordingArchive |
| 4 | KN.SlideNodeArchive | 17 | KN.RecordingEventTrackArchive |
| 5 | KN.SlideArchive | 18 | KN.RecordingMovieTrackArchive |
| 6 | KN.SlideArchive (also) | 19 | KN.ClassicStylesheetRecordArchive |
| 7 | KN.PlaceholderArchive | 20 | KN.ClassicThemeRecordArchive |
| 8 | KN.BuildArchive (an animation build) | 21 | KN.Soundtrack |
| 9 | KN.SlideStyleArchive | 22 | KN.SlideNumberAttachmentArchive |
| 10 | KN.ThemeArchive | 23 | KN.DesktopUILayoutArchive |
| 11 | KN.PasteboardNativeStorageArchive | 24 | KN.CanvasSelectionArchive |
| 12 | KN.PlaceholderArchive (also) | 25 | KN.SlideCollectionSelectionArchive |
Types 100 to 148 are 43 undo commands and command helpers, such as
KN.CommandShowInsertSlideArchive (101) and
KN.CommandSlideInsertDrawablesArchive (104). Type 10011 is
TSWP.SectionPlaceholderArchive in Keynote’s registry. Shared types
include TSWP.StorageArchive (2001, text), TSD.DrawableArchive
(3002), TSD.ImageArchive (3005), TSD.MovieArchive (3007),
TST.TableInfoArchive (6000), TSP.PackageMetadata (11006) and
TSP.ObjectContainer (11008). Every number is listed on
message type numbers, and the fields
of the messages on document
messages, slides, builds and
transitions, text and styles and
drawables.