View Single Post
Old 03-26-2012, 06:11 PM   #4
KevinH
Guru
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 871
Karma: 393922
Join Date: Nov 2009
Device: many
Hi,

Yes, seeking 78 bytes in will get you the palm database index of sections/records and the first record is the mobi header.

This is true for older style mobis but not fully for new style KF8 mobis. Newer style mobis KF8 mobis actually have two mobi header records inside the .mobi file. The first is at record 0 (just like above) and the second follows immediately after the 8 byte record whose value is 'BOUNDARY'. You have to walk through the palm db to find it.

Starting at byte 78 is a table whose entries have two big endian word values (8 bytes). The first value is the offset in the file to the start of that record, and the second is a flag value. So to read the 0'th record of the palm db file you read the 4 byte big endian value which is stored at byte 78, and the next four bytes are its flag value.

To read the starting offset of the ith record you read the 4 byte big endian value which is stored at byte 78 + (8*i) in the file.

The total number of records in the table are provided by the two bytes at position 76 in the file (again stored big endian).

So it is easy to read the structure of the palmdb that makes up .mobi files and hop to the start of any record in the palmdb file.

So to find record 0 is exactly as you described. Walking the records are easy looking for one that is exactly 8 bytes long whose value is BOUNDARY and then the very next records is another mobi header (this time a mobi 8 header).

The only other problem case would be Topaz files which are also stored in palmdbs but do not have a similar header structure. The easier way to find and ignore them is to see if the file starts with "TPZ".

Hope this helps,

Kevin
KevinH is offline   Reply With Quote