Debian Codegraph @

format_docs/pdb/ereader.txt

raw
1 About
2 -----
3
4 The eReader format has evolved and changed over time. Subsequently, there are
5 multiple versions of the eReader format. There are also two different tools
6 that can create eReader files. The official tools are Makebook and Dropbook.
7 Dropbook is the newer official tool that has replaced Makebook. However,
8 Makebook is still in wide use because it supports a wider range of platforms
9 than Dropbook. Dropbook is a GUI application that only runs on Windows and
10 Apple’s OS X.
11
12
13 PDB Identity
14 -------
15
16 PNRdPPrs
17
18
19 202 and 132 headers
20 -----------------------------------------
21
22 Older files have a record 0 size of 202 and occasionally 116. Newer files have
23 a record 0 size of 132. As of this writing the 202 files only support text and
24 images. The image format in the 202 files is the same as the 132 files. The 132
25 files support a number of additional features.
26
27
28 Record 0, eReader header (202)
29 ------------------
30
31 Note all values are in 2 byte increments. Like values are condensed into a
32 range. The range can be broken into 2 byte sections which represent the actual
33 stored values.
34
35 bytes content comments
36
37 0-2 Version Non-DRM books 2 and 4.
38 2-8 Garbage
39 8-10 Non-Text Offset Start of Non text area (images) will run to the
40 end of the section list.
41 10-14 Unknown
42 14-24 Garbage
43 24-28 Unknown
44 28-98 Garbage
45 98-100 Unknown
46 100-110 Garbage
47 110-114 Unknown
48 114-116 Garbage
49 116-202 Unknown
50
51 * Garbage: Intentionally random values.
52
53
54 Text Records (202)
55 ------------------
56
57 Text starts with section 1 and continues until the section indicated by the
58 Non-Text Offset. All text records are PalmDoc compressed.
59
60 Each character in the compressed data is xored with 0xA5.
61
62 A decompression example in sudo Python:
63
64 for num in range(1, Non-Text Offset):
65 text += decompress_pamldoc(''.join([chr(ord(x) ^ 0xA5) for x in section_data(num)])).decode('cp1252', 'replace')
66
67
68 Dropbook 132 files
69 ------------------
70
71 The following sections apply to the newer Dropbook created files.
72
73
74 Record 0, eReader header (132)
75 ----------------------------
76
77 This is only for 132 byte header files created by Dropbook.
78
79 bytes content comments
80
81 0-2 compression Specifies compression and drm. 2 = palmdoc,
82 10 = zlib. 260 and 272 = DRM
83 2-6 unknown Value of 0 is used
84 6-8 encoding Always 25152 (0x6240). All text must be
85 encoded as Latin-1 cp1252
86 8-10 Number of small pages The number of small font pages. If page
87 index is not build in then 0.
88 10-12 Number of large pages The number of large font pages. If page
89 index is not build in then 0.
90 12-14 Non-Text record start The location of the first non text records.
91 record 1 to this value minus 1 are all text
92 records
93 14-16 Number of chapters The number of chapter index records
94 contained in the file
95 16-18 Number of small index The number of small font page index records
96 contained in the file
97 18-20 Number of large index The number of large font page index records
98 contained in the file
99 20-22 Number of images The number of images contained in the file
100 22-24 Number of links The number of links contained in the file
101 24-26 Metadata available Is there a metadata record in the file?
102 0 = None, 1 = There is a metadata record
103 26-28 Unknown Value of 0 is used
104 28-30 Number of Footnotes The number of footnote records in the file
105 30-32 Number of Sidebars The number of sidebar records in the file
106 32-34 Chapter index record start The location of chapter index records. If
107 there are no chapters use the value for the
108 Last data record.
109 34-36 2560 Magic value that must be set to 2560
110 36-38 Small page index start The location of small font page index
111 records. If page table is not built in use
112 the value for the Last data record.
113 38-40 Large page index start The location of large font page index
114 records. If page table is not built in use
115 the value for the Last data record.
116 40-42 Image data record start The location of the first image record. If
117 there are no images use the value for the
118 Last data record.
119 42-44 Links record start The location of the first link index
120 record. If there are no links use the value
121 for the Last data record.
122 44-46 Metadata record start The location of the metadata record. If
123 there is no metadata use the value for the
124 Last data record.
125 46-48 Unknown Value of 0 is used
126 48-50 Footnote record start The location of the first footnote record.
127 If there are no footnotes use the value for
128 the Last data record.
129 50-52 Sidebar record start The location of the first sidebar record.
130 If there are no sidebars use the value for
131 the Last data record.
132 52-54 Last data record The location of the last data record
133 54-132 Unknown Value of 0 is used
134
135 Note: All values are in 2 byte increments. All bytes in the table that have a
136 range larger than 2 can be broken into 2 byte segments and have different
137 values set for each grouping.
138
139
140 Records Order
141 -------------
142
143 Though the order of this sections is described in eReader header,
144 DropBook makes the following order:
145
146 1. eReader Header
147 2. Compressed text
148 3. Small font page index
149 4. Large font page index
150 5. Chapter index
151 6. Links index
152 7. Images
153 8. (Extrapolation: there should be one more record type here though it has
154 not yet been uncovered what it might be).
155 9. Metadata
156 10. Sidebar records
157 11. Footnote records
158 12. Text block size record
159 13. "MeTaInFo\x00" word record
160
161
162 Text Records
163 ------------
164
165 All text records use cp1252 encoding (although eReader documents talk about
166 UTF-8 as well). Their total compressed size is unknown however, anything below
167 3560 Bytes is known to work. The text will be either zlib or palmdoc
168 compressed. Use the compression value from the eReader header to determine
169 which. All text utalizes the Palm Markup Language (PML) for formatting.
170
171 Starting with DropBook 1.6.0 text is divided into 8KB (8192 bytes) blocks
172 trimming the end to the closest space character and then being compressed.
173 Earlier version of DropBook 1.5.2 tries to behave the same way, though
174 sometimes it trims the block in unexpected place.
175
176
177 Chapter Index Records
178 ---------------------
179
180 Each chapter record corresponds to 1 chapter and points at the place in the
181 book. Chapter record takes a form of 'offset name\x00' First 4 bytes are offset
182 of the original pml file where the chapter index points to (offset of
183 the \x|\X?|\C? tags). Then without a space goes a name of a chapter in chapter
184 index. It should contain only text, all formatting tags should be removed.
185 \U and \a tags are not permitted in chapter name. To maintain sub-chapters
186 4*n spaces (\x20) are added to the beginning of the name, where "n" is level of
187 chapter: 0 for \x tag and N for \CN="" and \XN tags. And then an ending
188 \x00 symbol.
189
190
191 Image Records
192 -------------
193
194 Image records must be smaller than 65505 Bytes. They must also be 8bit PNG
195 images.
196
197 An image record takes the form 'PNG name\x00... image_data'
198
199 bytes content comments
200
201 0-4 PNG There must be a space after PNG.
202 4-36 image name. The image name must be 32 exactly 32 Bytes long. Pad
203 the right side of the name with \x00 characters for
204 names shorter than 32 characters.
205 36-58 Unknown
206 58-60 width Width of an image
207 60-62 height Height of an image
208 62-? The image data raw image data in 8 bit PNG format
209
210 Note: DropBooks seems to change something in png raw data. Like reencoding or
211 something, but plain insertion of png image there still works.
212
213
214 Links Records
215 -------------
216
217 Links records are constructed the same way as chapter ones. Each link anchor
218 record corresponds to 1 link anchor and points at the place in the book. Link
219 record takes a form of 'offset name\x00' First 4 bytes are offset of the
220 original pml file where the link anchor points to (offset of the \Q tag). Then
221 without a space goes a name of a link anchor. It should contain only text, all
222 formatting tags should be removed. \U and \a tags are not permitted in link
223 anchor name. And then an ending \x00 symbol.
224
225
226 Footnote Records
227 ----------------
228
229 The first footnote record is a \x00 separated list of footnote ids. All
230 subsequent footnote records are the footnote text corresponding to the id's
231 position in the list. Footnote text is compressed in the same manner as normal
232 text records
233
234 E.G.
235
236 footnote section 1 = 'notice1\x00notice2\x00notice3\x00'
237 footnote section 2 = 'Text for notice 1'
238 footnote section 3 = 'Text for notice 2'
239 footnote section 4 = 'Text for notice 3'
240
241 Starting with Dropbook 1.5.2 first record looks a bit different. It is sequence
242 of \x00\x01 then 1 byte of footnote id length, then footnote id then \x00.
243
244 E.G.
245
246 footnote section 1 = '\x00\x01\x07notice1\x00\x00\x01\x0Afootnote10\x00'
247
248
249 Sidebar Records
250 ---------------
251
252 The first sidebar record is a \x00 separated list of sidebar ids. All
253 subsequent sidebar records are the sidebar text corresponding to the id's
254 position in the list. Sidebar text is compressed in the same manner as normal
255 text records
256
257 E.G.
258
259 sidebar section 1 = 'notice1\x00notice2\x00notice3\x00'
260 sidebar section 2 = 'Text for notice 1'
261 sidebar section 3 = 'Text for notice 2'
262 sidebar section 4 = 'Text for notice 3'
263
264 Starting with Dropbook 1.5.2 first record looks a bit different. It is sequence
265 of \x00\x01 then 1 byte of sidebar's id length, then sidebar's id then \x00.
266
267 E.G.
268
269 sidebar section 1 = '\x00\x01\x07notice1\x00\x00\x01\x09sidebar10\x00'
270
271
272 Metadata Record
273 ---------------
274
275 \x00 separated list of string.
276
277 Metadata takes the form:
278
279 title\x00
280 author\x00
281 copyright\x00
282 publisher\x00
283 isbn\x00
284
285 E.G.
286
287 Gibraltar Earth\x00Michael McCollum\x001999\x00Sci Fi Arizona\x001929381255\x00
288
289 The metadata record is always followed by a record which contains 'MeTaInFo\x00'
290
291 Note: Starting with DropBook 1.5.2 'MeTaInFo\x00' is not following Metadata
292 Record. It is a separate record that ends the file and there are some more
293 records between Metadata record and 'MeTaInFo\x00' record.
294
295
296 Text Sizes Record
297 -----------------
298
299 There is a special record that contains the initial size of all text blocks
300 before compression. It is just a sequence of 2-byte blocks which are containing
301 the sizes.
302
303 E.G.
304
305 \x1F\xFB\x20\x00\x20\x00\x1F\xFE\x1F\xFD\x09\x46
306
307 Note: By this we can judge that theoretical maximum of initial block size is
308 65535 bytes.
309