# Path: modules/unipath.py
# def pathof(s, enc=fsencoding):
#     if s is None:
#         return None
#     if isinstance(s, text_type):
#         return s
#     if isinstance(s, binary_type):
#         try:
#             return s.decode(enc)
#         except:
#             pass
#     return s


import struct
import string
import re
from PIL import Image
from io import BytesIO
from .unipath import pathof

            if remove_personal_label:
                datain_rec0 = add_exth(datain_rec0, exth_cdetype, b"EBOK");
                exth = read_exth(datain_rec0, exth_asin)
                if len(exth) == 0:
                    datain_rec0 = add_exth(datain_rec0, exth_asin, bytes(to_base(document_id.int, base=32, min_num_digits=10), 'ascii'))
                # exth = read_exth(datain_rec0, exth_cdecontentkey)
                # if len(exth) == 0:
                #     datain_rec0 = add_exth(datain_rec0, exth_cdecontentkey, bytes(to_base(document_id.int, base=32, min_num_digits=10), 'ascii'))

            self.result_file = writesection(self.result_file, 0, datain_rec0)

            firstimage = getint(datain_rec0, first_resc_record)

            # Only keep the correct EXTH 116 StartOffset, KG 2.5 carries over the one from the mobi7 part, which then points at garbage in the mobi8 part, and confuses FW 3.4
            kf8starts = read_exth(datain_kfrec0, 116)
            # If we have multiple StartOffset, keep only the last one
            kf8start_count = len(kf8starts)
            while kf8start_count > 1:
                kf8start_count -= 1
                datain_kfrec0 = del_exth(datain_kfrec0, 116)

            exth_cover = read_exth(datain_kfrec0, exth_cover_offset)
            if len(exth_cover) > 0:
                cover_index, = struct.unpack_from('>L', exth_cover[0], 0)
                cover_index += firstimage
            else:
                cover_index = 0xffffffff

            exth_thumb = read_exth(datain_kfrec0, exth_thumb_offset)

# Path: modules/unipath.py
# def pathof(s, enc=fsencoding):
#     if s is None:
#         return None
#     if isinstance(s, text_type):
#         return s
#     if isinstance(s, binary_type):
#         try:
#             return s.decode(enc)
#         except:
#             pass
#     return s


# Path: modules/mobi_split.py
import struct
import string
import re
from PIL import Image
from io import BytesIO
from .unipath import pathof


            if remove_personal_label:
                datain_rec0 = add_exth(datain_rec0, exth_cdetype, b"EBOK");
                exth = read_exth(datain_rec0, exth_asin)
                if len(exth) == 0:
                    datain_rec0 = add_exth(datain_rec0, exth_asin, bytes(to_base(document_id.int, base=32, min_num_digits=10), 'ascii'))
                # exth = read_exth(datain_rec0, exth_cdecontentkey)
                # if len(exth) == 0:
                #     datain_rec0 = add_exth(datain_rec0, exth_cdecontentkey, bytes(to_base(document_id.int, base=32, min_num_digits=10), 'ascii'))

            self.result_file = writesection(self.result_file, 0, datain_rec0)

            firstimage = getint(datain_rec0, first_resc_record)

            # Only keep the correct EXTH 116 StartOffset, KG 2.5 carries over the one from the mobi7 part, which then points at garbage in the mobi8 part, and confuses FW 3.4
            kf8starts = read_exth(datain_kfrec0, 116)
            # If we have multiple StartOffset, keep only the last one
            kf8start_count = len(kf8starts)
            while kf8start_count > 1:
                kf8start_count -= 1
                datain_kfrec0 = del_exth(datain_kfrec0, 116)

            exth_cover = read_exth(datain_kfrec0, exth_cover_offset)
            if len(exth_cover) > 0:
                cover_index, = struct.unpack_from('>L', exth_cover[0], 0)
                cover_index += firstimage
            else:
                cover_index = 0xffffffff

            exth_thumb = read_exth(datain_kfrec0, exth_thumb_offset)

            if len(exth_thumb) > 0: