def __init__(self, mh, files): self.mh = mh self.sect = self.mh.sect self.files = files self.isNCX = False self.mi = MobiIndex(self.sect) self.ncxidx = self.mh.ncxidx self.indx_data = None
def __init__(self, mh, sect, debug=False): self.sect = sect self.mi = MobiIndex(sect) self.mh = mh self.skelidx = mh.skelidx self.dividx = mh.dividx self.othidx = mh.othidx self.fdst = mh.fdst self.flowmap = {} self.flows = None self.flowinfo = [] self.parts = None self.partinfo = [] self.fdsttbl = [0, 0xffffffff] self.DEBUG = debug # read in and parse the FDST info which is very similar in format to the Palm DB section # parsing except it provides offsets into rawML file and not the Palm DB file # this is needed to split up the final css, svg, etc flow section # that can exist at the end of the rawML file if self.fdst != 0xffffffff: header = self.sect.loadSection(self.fdst) if header[0:4] == "FDST": num_sections, = struct.unpack_from('>L', header, 0x08) sections = header[0x0c:] self.fdsttbl = struct.unpack_from('>%dL' % (num_sections * 2), sections, 0)[::2] + (0xfffffff, ) else: print "Error: K8 Mobi with Missing FDST info" if self.DEBUG: print "\nFDST Section Map: %d entries" % len(self.fdsttbl) for j in xrange(len(self.fdsttbl)): print " %d - %0x" % (j, self.fdsttbl[j]) # read/process skeleton index info to create the skeleton table skeltbl = [] if self.skelidx != 0xffffffff: outtbl, ctoc_text = self.mi.getIndexData(self.skelidx) fileptr = 0 for [text, tagMap] in outtbl: # file number, skeleton name, divtbl record count, start position, length skeltbl.append( [fileptr, text, tagMap[1][0], tagMap[6][0], tagMap[6][1]]) fileptr += 1 self.skeltbl = skeltbl if self.DEBUG: print "\nSkel Table: %d entries" % len(self.skeltbl) print "table: filenum, skeleton name, div tbl record count, start position, length" for j in xrange(len(self.skeltbl)): print self.skeltbl[j] # read/process the div index to create to <div> (and <p>) table divtbl = [] if self.dividx != 0xffffffff: outtbl, ctoc_text = self.mi.getIndexData(self.dividx) for [text, tagMap] in outtbl: # insert position, ctoc offset (aidtext), file number, sequence number, start position, length ctocoffset = tagMap[2][0] ctocdata = ctoc_text[ctocoffset] divtbl.append([ int(text), ctocdata, tagMap[3][0], tagMap[4][0], tagMap[6][0], tagMap[6][1] ]) self.divtbl = divtbl if self.DEBUG: print "\nDiv (Fragment) Table: %d entries" % len(self.divtbl) print "table: file position, link id text, file num, sequence number, start position, length" for j in xrange(len(self.divtbl)): print self.divtbl[j] # read / process other index <guide> element of opf othtbl = [] if self.othidx != 0xffffffff: outtbl, ctoc_text = self.mi.getIndexData(self.othidx) for [text, tagMap] in outtbl: # ref_type, ref_title, div/frag number ctocoffset = tagMap[1][0] ref_title = ctoc_text[ctocoffset] ref_type = text fileno = None if 3 in tagMap.keys(): fileno = tagMap[3][0] if 6 in tagMap.keys(): fileno = tagMap[6][0] othtbl.append([ref_type, ref_title, fileno]) self.othtbl = othtbl if self.DEBUG: print "\nOther (Guide) Table: %d entries" % len(self.othtbl) print "table: ref_type, ref_title, divtbl entry number" for j in xrange(len(self.othtbl)): print self.othtbl[j]
def __init__(self, mh, sect, files, debug=False): self.sect = sect self.files = files self.mi = MobiIndex(sect) self.mh = mh self.skelidx = mh.skelidx self.fragidx = mh.fragidx self.guideidx = mh.guideidx self.fdst = mh.fdst self.flowmap = {} self.flows = None self.flowinfo = [] self.parts = None self.partinfo = [] self.fdsttbl = [0, 0xffffffff] self.DEBUG = debug # read in and parse the FDST info which is very similar in format to the Palm DB section # parsing except it provides offsets into rawML file and not the Palm DB file # this is needed to split up the final css, svg, etc flow section # that can exist at the end of the rawML file if self.fdst != 0xffffffff: header = self.sect.loadSection(self.fdst) if header[0:4] == "FDST": num_sections, = struct.unpack_from('>L', header, 0x08) self.fdsttbl = struct.unpack_from('>%dL' % (num_sections * 2), header, 12)[::2] + (mh.rawSize, ) sect.setsectiondescription(self.fdst, "KF8 FDST INDX") if self.DEBUG: print "\nFDST Section Map: %d sections" % num_sections for j in xrange(num_sections): print "Section %d: 0x%08X - 0x%08X" % ( j, self.fdsttbl[j], self.fdsttbl[j + 1]) else: print "\nError: K8 Mobi with Missing FDST info" # read/process skeleton index info to create the skeleton table skeltbl = [] if self.skelidx != 0xffffffff: # for i in xrange(2): # fname = 'skel%04d.dat' % i # data = self.sect.loadSection(self.skelidx + i) # open(pathof(fname), 'wb').write(data) outtbl, ctoc_text = self.mi.getIndexData(self.skelidx, "KF8 Skeleton") fileptr = 0 for [text, tagMap] in outtbl: # file number, skeleton name, fragtbl record count, start position, length skeltbl.append( [fileptr, text, tagMap[1][0], tagMap[6][0], tagMap[6][1]]) fileptr += 1 self.skeltbl = skeltbl if self.DEBUG: print "\nSkel Table: %d entries" % len(self.skeltbl) print "table: filenum, skeleton name, frag tbl record count, start position, length" for j in xrange(len(self.skeltbl)): print self.skeltbl[j] # read/process the fragment index to create the fragment table fragtbl = [] if self.fragidx != 0xffffffff: # for i in xrange(3): # fname = 'frag%04d.dat' % i # data = self.sect.loadSection(self.fragidx + i) # open(pathof(fname), 'wb').write(data) outtbl, ctoc_text = self.mi.getIndexData(self.fragidx, "KF8 Fragment") for [text, tagMap] in outtbl: # insert position, ctoc offset (aidtext), file number, sequence number, start position, length ctocoffset = tagMap[2][0] ctocdata = ctoc_text[ctocoffset] fragtbl.append([ int(text), ctocdata, tagMap[3][0], tagMap[4][0], tagMap[6][0], tagMap[6][1] ]) self.fragtbl = fragtbl if self.DEBUG: print "\nFragment Table: %d entries" % len(self.fragtbl) print "table: file position, link id text, file num, sequence number, start position, length" for j in xrange(len(self.fragtbl)): print self.fragtbl[j] # read / process guide index for guide elements of opf guidetbl = [] if self.guideidx != 0xffffffff: # for i in xrange(3): # fname = 'guide%04d.dat' % i # data = self.sect.loadSection(self.guideidx + i) # open(pathof(fname), 'wb').write(data) outtbl, ctoc_text = self.mi.getIndexData(self.guideidx, "KF8 Guide elements)") for [text, tagMap] in outtbl: # ref_type, ref_title, frag number ctocoffset = tagMap[1][0] ref_title = ctoc_text[ctocoffset] ref_type = text fileno = None if 3 in tagMap.keys(): fileno = tagMap[3][0] if 6 in tagMap.keys(): fileno = tagMap[6][0] guidetbl.append([ref_type, ref_title, fileno]) self.guidetbl = guidetbl if self.DEBUG: print "\nGuide Table: %d entries" % len(self.guidetbl) print "table: ref_type, ref_title, fragtbl entry number" for j in xrange(len(self.guidetbl)): print self.guidetbl[j]