コード例 #1
0
    def parseRecordInfoList(self):
        records = {}
        # read in all records in info list
        for recordID in range(self.header['number of records']):
            headerfmt = '>II'
            headerlen = calcsize(headerfmt)
            fields = [
                "record Data Offset",
                "UniqueID",
            ]
            # create tuple with info
            results = zip(
                fields,
                unpack(headerfmt,
                       self.contents[self.offset:self.offset + headerlen]))

            # increment offset into file
            self.offset += headerlen

            # convert tuple to dictionary
            resultsDict = utils.toDict(results)

            # futz around with the unique ID record, as the uniqueID's top 8 bytes are
            # really the "record attributes":
            resultsDict['record Attributes'] = (resultsDict['UniqueID']
                                                & 0xFF000000) >> 24
            resultsDict['UniqueID'] = resultsDict['UniqueID'] & 0x00FFFFFF

            # store into the records dict
            records[resultsDict['UniqueID']] = resultsDict

        return records
コード例 #2
0
    def parseEXTHHeader(self):
        headerfmt = '>III'
        headerlen = calcsize(headerfmt)

        fields = ['identifier', 'header length', 'record Count']

        # unpack header, zip up into list of tuples
        results = zip(
            fields,
            unpack(headerfmt,
                   self.contents[self.offset:self.offset + headerlen]))

        # convert tuple array to dictionary
        resultsDict = utils.toDict(results)

        self.offset += headerlen
        resultsDict['records'] = {}
        for record in range(resultsDict['record Count']):
            recordType, recordLen = unpack(
                ">II", self.contents[self.offset:self.offset + 8])
            recordData = self.contents[self.offset + 8:self.offset + recordLen]
            resultsDict['records'][recordType] = recordData
            self.offset += recordLen

        return resultsDict
コード例 #3
0
    def parseMobiHeader(self):
        headerfmt = '> IIII II 40s III IIIII IIII I 36s IIII 8s HHIIIII'
        headerlen = calcsize(headerfmt)

        fields = [
            "identifier", "header length", "Mobi type", "text Encoding",
            "Unique-ID", "Generator version", "-Reserved",
            "First Non-book index", "Full Name Offset", "Full Name Length",
            "Language", "Input Language", "Output Language", "Format version",
            "First Image index", "First Huff Record", "Huff Record Count",
            "First DATP Record", "DATP Record Count", "EXTH flags",
            "-36 unknown bytes, if Mobi is long enough", "DRM Offset",
            "DRM Count", "DRM Size", "DRM Flags",
            "-Usually Zeros, unknown 8 bytes", "-Unknown", "Last Image Record",
            "-Unknown", "FCIS record", "-Unknown", "FLIS record", "Unknown"
        ]

        # unpack header, zip up into list of tuples
        results = zip(
            fields,
            unpack(headerfmt,
                   self.contents[self.offset:self.offset + headerlen]))

        # convert tuple array to dictionary
        resultsDict = utils.toDict(results)

        resultsDict['Start Offset'] = self.offset

        resultsDict['Full Name'] = (
            self.contents[self.records[0]['record Data Offset'] +
                          resultsDict['Full Name Offset']:self.
                          records[0]['record Data Offset'] +
                          resultsDict['Full Name Offset'] +
                          resultsDict['Full Name Length']])

        resultsDict['Has DRM'] = resultsDict['DRM Offset'] != 0xFFFFFFFF

        resultsDict['Has EXTH Header'] = (resultsDict['EXTH flags']
                                          & 0x40) != 0

        self.offset += resultsDict['header length']

        def onebits(x, width=16):
            return len(
                list(
                    filter(lambda x: x == "1",
                           (str((x >> i) & 1)
                            for i in range(width - 1, -1, -1)))))

        resultsDict['extra bytes'] = 2 * onebits(
            unpack(">H", self.contents[self.offset - 2:self.offset])[0]
            & 0xFFFE)

        return resultsDict
コード例 #4
0
    def parsePalmDOCHeader(self):
        headerfmt = '>HHIHHHH'
        headerlen = calcsize(headerfmt)
        fields = [
            "Compression", "Unused", "text length", "record count",
            "record size", "Encryption Type", "Unknown"
        ]
        offset = self.records[0]['record Data Offset']
        # create tuple with info
        results = zip(
            fields, unpack(headerfmt,
                           self.contents[offset:offset + headerlen]))

        # convert tuple array to dictionary
        resultsDict = utils.toDict(results)

        self.offset = offset + headerlen
        return resultsDict
コード例 #5
0
    def parseHeader(self):
        headerfmt = '>32shhIIIIII4s4sIIH'
        headerlen = calcsize(headerfmt)
        fields = [
            "name", "attributes", "version", "created", "modified", "backup",
            "modnum", "appInfoId", "sortInfoID", "type", "creator",
            "uniqueIDseed", "nextRecordListID", "number of records"
        ]

        # unpack header, zip up into list of tuples
        results = zip(
            fields,
            unpack(headerfmt,
                   self.contents[self.offset:self.offset + headerlen]))

        # increment offset into file
        self.offset += headerlen

        # convert tuple array to dictionary
        resultsDict = utils.toDict(results)

        return resultsDict