示例#1
0
文件: pdb.py 项目: mcrewson/biblio
def _parse_ereader_header132(raw):
    h = Storage()
    h.compression, _unknown1, h.encoding, h.number_small_pages, h.number_large_pages, h.non_text_records, h.number_chapters, h.number_small_index, h.number_large_index, h.number_images, h.number_links, h.metadata_available, _unknown2, h.number_footnotes, h.number_sidebars, h.chapter_index_records, h.magic_2560, h.small_page_index_record, h.large_page_index_record, h.image_data_record, h.links_record, h.metadata_record, _unknown3, h.footnote_record, h.sidebar_record, h.last_data_record, = struct.unpack(
        ">HLHHHHHHHHHHHHHHHHHHHHHHH", raw[:54]
    )

    return h
示例#2
0
文件: pdb.py 项目: mcrewson/biblio
def _parse_palmdoc_header(raw):
    h = Storage()

    h.compression, _unused, h.text_length, h.record_count, h.record_size, h.current_position, = struct.unpack(
        ">HHLHHL", raw[0:0x10]
    )

    return h
示例#3
0
文件: mobi.py 项目: mcrewson/biblio
def _parse_mobi_header (raw):
    mobiheader = Storage()

    mobiheader.compression, \
    _unused, \
    mobiheader.text_length, \
    mobiheader.record_count, \
    mobiheader.record_size, \
    mobiheader.encryption, \
    _unknown, \
        = struct.unpack('>HHLHHHH', raw[0:0x10])

    # Some ancient MOBI files have no more metadata than this
    if len(raw) <= 16:
        return mobiheader

    mobiheader.identifier, \
    mobiheader.header_length, \
    mobiheader.mobi_type, \
    mobiheader.text_encoding, \
    mobiheader.unique_id, \
    mobiheader.file_version, \
    mobiheader.ortographic_index_record, \
    mobiheader.inflection_index_record, \
    mobiheader.index_names_record, \
    mobiheader.index_keys_record, \
    mobiheader.extra_index0_record, \
    mobiheader.extra_index1_record, \
    mobiheader.extra_index2_record, \
    mobiheader.extra_index3_record, \
    mobiheader.extra_index4_record, \
    mobiheader.extra_index5_record, \
    mobiheader.first_nonbook_record, \
    mobiheader.fullname_offset, \
    mobiheader.fullname_length, \
    mobiheader.locale, \
    mobiheader.dictionary_input_language, \
    mobiheader.dictionary_output_language, \
    mobiheader.min_version, \
    mobiheader.first_image_record, \
    mobiheader.huffman_record, \
    mobiheader.huffman_record_count, \
    mobiheader.huffman_table_record, \
    mobiheader.huffman_table_length, \
    mobiheader.exth_flags, \
        = struct.unpack('>4sLLLLLLLLLLLLLLLLLLLLLLLLLLLL', raw[0x10:0x84])

    if len(raw) >= 0xb4:
        mobiheader.drm_offset, \
        mobiheader.drm_count, \
        mobiheader.drm_size, \
        mobiheader.drm_flags, \
            = struct.unpack('>LLLL', raw[0xa4:0xb4])

    if mobiheader.header_length < 0xe4 or \
       mobiheader.header_length > 0xf8:
        mobiheader.extra_flags = 0
    else:
        mobiheader.extra_flags, = struct.unpack('>H', raw[0xf2:0xf4])

    fullname_end = mobiheader.fullname_offset + mobiheader.fullname_length
    if fullname_end < len(raw):
        mobiheader.fullname = raw[mobiheader.fullname_offset:fullname_end]
    else:
        mobiheader.fullname = None

    if mobiheader.exth_flags & 0x40:
        mobiheader.exth = _parse_exth_header(raw[16 + mobiheader.header_length:])

    return mobiheader