Example #1
0
    def GetWindowsInfo(self):
        '''Gets information from the #WINDOWS file.
        Checks the #WINDOWS file to see if it has any info that was
        not found in #SYSTEM (topics, index or default page.
        '''
        result, ui = chmlib.chm_resolve_object(self.file, '/#WINDOWS')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            return -1

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0l, 8)
        if (size < 8):
            return -2

        buff = array.array('B', text)
        num_entries = self.GetDWORD(buff, 0)
        entry_size = self.GetDWORD(buff, 4)

        if num_entries < 1:
            return -3

        size, text = chmlib.chm_retrieve_object(self.file, ui, 8l, entry_size)
        if (size < entry_size):
            return -4

        buff = array.array('B', text)
        toc_index = self.GetDWORD(buff, 0x60)
        idx_index = self.GetDWORD(buff, 0x64)
        dft_index = self.GetDWORD(buff, 0x68)

        result, ui = chmlib.chm_resolve_object(self.file, '/#STRINGS')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            return -5

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0l, ui.length)
        if (size == 0):
            return -6

        if (not self.topics):
            self.topics = self.GetString(text, toc_index)
            if not self.topics.startswith("/"):
                self.topics = "/" + self.topics

        if (not self.index):
            self.index = self.GetString(text, idx_index)
            if not self.index.startswith("/"):
                self.index = "/" + self.index

        if (dft_index != 0):
            self.home = self.GetString(text, dft_index)
            if not self.home.startswith("/"):
                self.home = "/" + self.home
Example #2
0
    def GetWindowsInfo(self):
        '''Gets information from the #WINDOWS file.
        Checks the #WINDOWS file to see if it has any info that was
        not found in #SYSTEM (topics, index or default page.
        '''
        result, ui = chmlib.chm_resolve_object(self.file, '/#WINDOWS')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            return -1

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0, 8)
        if (size < 8):
            return -2

        buff = array.array('B', text)
        num_entries = self.GetDWORD(buff, 0)
        entry_size = self.GetDWORD(buff, 4)

        if num_entries < 1:
            return -3

        size, text = chmlib.chm_retrieve_object(self.file, ui, 8, entry_size)
        if (size < entry_size):
            return -4

        buff = array.array('B', text)
        toc_index = self.GetDWORD(buff, 0x60)
        idx_index = self.GetDWORD(buff, 0x64)
        dft_index = self.GetDWORD(buff, 0x68)

        result, ui = chmlib.chm_resolve_object(self.file, '/#STRINGS')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            return -5

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0, ui.length)
        if (size == 0):
            return -6

        if (not self.topics):
            self.topics = self.GetString(text, toc_index)
            if not self.topics.startswith("/"):
                self.topics = "/" + self.topics

        if (not self.index):
            self.index = self.GetString(text, idx_index)
            if not self.index.startswith("/"):
                self.index = "/" + self.index

        if (dft_index != 0):
            self.home = self.GetString(text, dft_index)
            if not self.home.startswith("/"):
                self.home = "/" + self.home
Example #3
0
 def RetrieveObject(self, ui, start = -1, length = -1):
     '''Retrieves the contents of a document.
     This function takes a UnitInfo and two optional arguments, the first
     being the start address and the second is the length. These define
     the amount of data to be read from the archive.
     '''
     if self.file and ui:
         if length == -1:
             len = ui.length
         else:
             len = length
         if start == -1:
             st = 0l
         else:
             st = long(start)
         return chmlib.chm_retrieve_object(self.file, ui, st, len)
     else:
         return (0, '')
Example #4
0
    def GetIndex(self):
        '''Reads and returns the index tree.
        This auxiliary function reads and returns the index tree file
        contents for the CHM archive.
        '''
        if (self.index == None):
            return None

        if self.index:
            res, ui = chmlib.chm_resolve_object(self.file, self.index)
            if (res != chmlib.CHM_RESOLVE_SUCCESS):
                return None

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0l, ui.length)
        if (size == 0):
            sys.stderr.write('GetIndex: file size = 0\n')
            return None
        return text
Example #5
0
 def RetrieveObject(self, ui, start=-1, length=-1):
     '''Retrieves the contents of a document.
     This function takes a UnitInfo and two optional arguments, the first
     being the start address and the second is the length. These define
     the amount of data to be read from the archive.
     '''
     if self.file and ui:
         if length == -1:
             len = ui.length
         else:
             len = length
         if start == -1:
             st = 0l
         else:
             st = long(start)
         return chmlib.chm_retrieve_object(self.file, ui, st, len)
     else:
         return (0, '')
Example #6
0
    def GetIndex(self):
        """Reads and returns the index tree.
        This auxiliary function reads and returns the index tree file
        contents for the CHM archive.
        """
        if self.index is None:
            return None

        if self.index:
            res, ui = chmlib.chm_resolve_object(self.file, self.index)
            if res != chmlib.CHM_RESOLVE_SUCCESS:
                return None

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0L, ui.length)
        if size == 0:
            sys.stderr.write("GetIndex: file size = 0\n")
            return None
        return text
Example #7
0
    def GetIndex(self):
        '''Reads and returns the index tree.
        This auxiliary function reads and returns the index tree file
        contents for the CHM archive.
        '''
        if (self.index is None):
            return None

        if self.index:
            res, ui = chmlib.chm_resolve_object(self.file, self.index)
            if (res != chmlib.CHM_RESOLVE_SUCCESS):
                return None

        size, text = chmlib.chm_retrieve_object(self.file, ui, 0, ui.length)
        if (size == 0):
            sys.stderr.write('GetIndex: file size = 0\n')
            return None
        return text
Example #8
0
    def GetArchiveInfo(self):
        '''Obtains information on CHM archive.
        This function checks the /#SYSTEM file inside the CHM archive to
        obtain the index, home page, topics, encoding and title. It is called
        from LoadCHM.
        '''

        #extra.is_searchable crashed...
        #self.searchable = extra.is_searchable (self.file)
        self.searchable = False
        self.lcid = None

        result, ui = chmlib.chm_resolve_object(self.file, '/#SYSTEM')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            sys.stderr.write('GetArchiveInfo: #SYSTEM does not exist\n')
            return 0

        size, text = chmlib.chm_retrieve_object(self.file, ui, 4l, ui.length)
        if (size == 0):
            sys.stderr.write('GetArchiveInfo: file size = 0\n')
            return 0

        buff = array.array('B', text)

        index = 0
        while (index < size):
            cursor = buff[index] + (buff[index+1] * 256)

            if (cursor == 0):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.topics = '/' + text[index:index+cursor-1]
            elif (cursor == 1):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.index = '/' + text[index:index+cursor-1]
            elif (cursor == 2):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.home = '/' + text[index:index+cursor-1]
            elif (cursor == 3):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.title = text[index:index+cursor-1]
            elif (cursor == 4):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.lcid = buff[index] + (buff[index+1] * 256)
            elif (cursor == 6):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                tmp = text[index:index+cursor-1]
                if not self.topics:
                    tmp1 = '/' + tmp + '.hhc'
                    tmp2 = '/' + tmp + '.hhk'
                    res1, ui1 = chmlib.chm_resolve_object(self.file, tmp1)
                    res2, ui2 = chmlib.chm_resolve_object(self.file, tmp2)
                    if (not self.topics) and \
                           (res1 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.topics = '/' + tmp + '.hhc'
                    if (not self.index) and \
                           (res2 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.index = '/' + tmp + '.hhk'
            elif (cursor == 16):
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
                self.encoding = text[index:index+cursor-1]
            else:
                index += 2
                cursor = buff[index] + (buff[index+1] * 256)
                index += 2
            index += cursor

        self.GetWindowsInfo()

        if not self.lcid:
            self.lcid = extra.get_lcid (self.file)

        return 1
Example #9
0
    def GetArchiveInfo(self):
        """Obtains information on CHM archive.
        This function checks the /#SYSTEM file inside the CHM archive to
        obtain the index, home page, topics, encoding and title. It is called
        from LoadCHM.
        """

        # extra.is_searchable crashed...
        # self.searchable = extra.is_searchable (self.file)
        self.searchable = False
        self.lcid = None

        result, ui = chmlib.chm_resolve_object(self.file, "/#SYSTEM")
        if result != chmlib.CHM_RESOLVE_SUCCESS:
            sys.stderr.write("GetArchiveInfo: #SYSTEM does not exist\n")
            return 0

        size, text = chmlib.chm_retrieve_object(self.file, ui, 4L, ui.length)
        if size == 0:
            sys.stderr.write("GetArchiveInfo: file size = 0\n")
            return 0

        buff = array.array("B", text)

        index = 0
        while index < size:
            cursor = buff[index] + (buff[index + 1] * 256)

            if cursor == 0:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.topics = "/" + text[index : index + cursor - 1]
            elif cursor == 1:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.index = "/" + text[index : index + cursor - 1]
            elif cursor == 2:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.home = "/" + text[index : index + cursor - 1]
            elif cursor == 3:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.title = text[index : index + cursor - 1]
            elif cursor == 4:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.lcid = buff[index] + (buff[index + 1] * 256)
            elif cursor == 6:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                tmp = text[index : index + cursor - 1]
                if not self.topics:
                    tmp1 = "/" + tmp + ".hhc"
                    tmp2 = "/" + tmp + ".hhk"
                    res1, ui1 = chmlib.chm_resolve_object(self.file, tmp1)
                    res2, ui2 = chmlib.chm_resolve_object(self.file, tmp2)
                    if (not self.topics) and (res1 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.topics = "/" + tmp + ".hhc"
                    if (not self.index) and (res2 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.index = "/" + tmp + ".hhk"
            elif cursor == 16:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.encoding = text[index : index + cursor - 1]
            else:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
            index += cursor

        self.GetWindowsInfo()

        if not self.lcid:
            self.lcid = extra.get_lcid(self.file)

        return 1
Example #10
0
    def GetArchiveInfo(self):
        '''Obtains information on CHM archive.
        This function checks the /#SYSTEM file inside the CHM archive to
        obtain the index, home page, topics, encoding and title. It is called
        from LoadCHM.
        '''

        # extra.is_searchable crashed...
        # self.searchable = extra.is_searchable (self.file)
        self.searchable = False
        self.lcid = None

        result, ui = chmlib.chm_resolve_object(self.file, '/#SYSTEM')
        if (result != chmlib.CHM_RESOLVE_SUCCESS):
            sys.stderr.write('GetArchiveInfo: #SYSTEM does not exist\n')
            return 0

        size, text = chmlib.chm_retrieve_object(self.file, ui, 4, ui.length)
        if (size == 0):
            sys.stderr.write('GetArchiveInfo: file size = 0\n')
            return 0

        buff = array.array('B', text)

        index = 0
        while (index < size):
            cursor = buff[index] + (buff[index + 1] * 256)

            if (cursor == 0):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.topics = '/' + text[index:index + cursor - 1]
            elif (cursor == 1):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.index = '/' + text[index:index + cursor - 1]
            elif (cursor == 2):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.home = '/' + text[index:index + cursor - 1]
            elif (cursor == 3):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.title = text[index:index + cursor - 1]
            elif (cursor == 4):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.lcid = buff[index] + (buff[index + 1] * 256)
            elif (cursor == 6):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                tmp = text[index:index + cursor - 1]
                if not self.topics:
                    tmp1 = '/' + tmp + '.hhc'
                    tmp2 = '/' + tmp + '.hhk'
                    res1, ui1 = chmlib.chm_resolve_object(self.file, tmp1)
                    res2, ui2 = chmlib.chm_resolve_object(self.file, tmp2)
                    if (not self.topics) and \
                           (res1 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.topics = '/' + tmp + '.hhc'
                    if (not self.index) and \
                           (res2 == chmlib.CHM_RESOLVE_SUCCESS):
                        self.index = '/' + tmp + '.hhk'
            elif (cursor == 16):
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
                self.encoding = text[index:index + cursor - 1]
            else:
                index += 2
                cursor = buff[index] + (buff[index + 1] * 256)
                index += 2
            index += cursor

        self.GetWindowsInfo()

        if not self.lcid:
            self.lcid = extra.get_lcid(self.file)

        return 1