(self, w)
parent = w.ui.treeWidget


        # add sections

        for section in self.PE.sections:
            child  = QtWidgets.QTreeWidgetItem(None)            
            child.setText(0, section.Name)            
            parent.topLevelItem(3).addChild(child)
def writeData(self, w):

        if hasattr(self.PE, 'FileInfo'):
            for f in self.PE.FileInfo:
                if f.Key == 'StringFileInfo':
                    for st in f.StringTable:
                        for entry in st.entries:
                            #print entry
                            w.ui.tableWidget_2.setColumnWidth(0, 300)                        
                            if entry == 'CompanyName':
                                w.ui.tableWidget_2.setItem(0, 0, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'FileDescription':
                                w.ui.tableWidget_2.setItem(0, 1, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'FileVersion':
                                w.ui.tableWidget_2.setItem(0, 2, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'LegalCopyright':
                                w.ui.tableWidget_2.setItem(0, 3, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'OriginalFilename':
                                w.ui.tableWidget_2.setItem(0, 4, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'ProductName':
                                w.ui.tableWidget_2.setItem(0, 5, QtWidgets.QTableWidgetItem(st.entries[entry]))

                            if entry == 'ProductVersion':
                                w.ui.tableWidget_2.setItem(0, 6, QtWidgets.QTableWidgetItem(st.entries[entry]))



        
        if self.PE.is_exe():
            petype = 'EXE'
        elif self.PE.is_dll():
            petype = 'DLL'
        elif self.PE.is_driver():
            petype = 'Driver'
        else:
            petype = 'n/a'

        w.ui.tableWidget.setItem(0, 0, QtWidgets.QTableWidgetItem(petype))
        w.ui.tableWidget.setItem(1, 0, QtWidgets.QTableWidgetItem('{:,} bytes'.format(self.dataModel.getDataSize())))

        # add exports
        parent = w.ui.treeWidgetExports
        parent.setColumnWidth(0, 300) 

      
        if hasattr(self.PE, 'DIRECTORY_ENTRY_EXPORT'):
            try:
                rva = self.PE.get_offset_from_rva(self.PE.DIRECTORY_ENTRY_EXPORT.struct.Name)

                # very ygly, i know
                s = ''
                c = 'z'
                k = 0
                while c != '\0' and k < 50:
                    c = chr(self.dataModel.getBYTE(rva))
                    s += c
                    rva += 1
                    k += 1


                child = QtWidgets.QTreeWidgetItem(None)
                child.setText(0, s)

                parent.addTopLevelItem(child)
                parent.expandItem(child)
                
                for i, exp in enumerate(self.PE.DIRECTORY_ENTRY_EXPORT.symbols):

                    child = QtWidgets.QTreeWidgetItem(None)

                    if exp.name:
                        child.setText(0, exp.name)
                        child.setText(1, '0x{0:X}'.format(exp.address))

                        #parent.topLevelItem(i).addChild(child)

                        #parent.topLevelItem(i).addChild(child)
                    
                    parent.topLevelItem(0).addChild(child)

            except Exception as e:
                logger.error(e, exc_info=1)

        # add imports
        parent = w.ui.treeWidgetImports
        parent.setColumnWidth(0, 300) 
        try:
            for i, entry in enumerate(self.PE.DIRECTORY_ENTRY_IMPORT):
                
                child = QtWidgets.QTreeWidgetItem(None)
                child.setText(0, entry.dll.decode('cp437'))
                parent.addTopLevelItem(child)

                for imp in entry.imports:
                    child = QtWidgets.QTreeWidgetItem(None)
                    if imp.name:
                        child.setText(0, imp.name.decode('cp437'))
                        child.setText(1, '0x{0:X}'.format(imp.address-self.PE.OPTIONAL_HEADER.ImageBase))

                        parent.topLevelItem(i).addChild(child)

                    if imp.ordinal:
                        child.setText(0, 'ordinal:{0}'.format(imp.ordinal))
                        child.setText(1, '0x{0:X}'.format(imp.address-self.PE.OPTIONAL_HEADER.ImageBase))

                        parent.topLevelItem(i).addChild(child)
        except Exception as e:
            logger.error(e, exc_info=1)

        # populate with sections
        parent = w.ui.treeWidgetSections
        parent.setColumnWidth(0, 100) 
        parent.setColumnWidth(1, 80) 
        parent.setColumnWidth(2, 80) 
        parent.setColumnWidth(3, 80) 
        parent.setColumnWidth(4, 80)        

        for section in self.PE.sections:
            child  = QtWidgets.QTreeWidgetItem(None)
            child.setText(0, section.Name.decode('cp437'))
            child.setText(1, '{0:X}'.format(section.PointerToRawData))
            child.setText(2, '{0:X}'.format(section.SizeOfRawData))
            child.setText(3, '{0:X}'.format(section.VirtualAddress))
            child.setText(4, '{0:X}'.format(section.Misc_VirtualSize))

            child.setForeground(1, QtGui.QColor('green'))
            child.setForeground(2, QtGui.QColor('green'))


            child.setForeground(3, QtGui.QColor(183, 72, 197))
            child.setForeground(4, QtGui.QColor(183, 72, 197))
            
            # build characteristics string for every section
            fr = 'R' if section.IMAGE_SCN_MEM_READ else '-'
            fw = 'W' if section.IMAGE_SCN_MEM_WRITE else '-'
            fe = 'E' if section.IMAGE_SCN_MEM_EXECUTE else '-'

            fc = 'C' if section.IMAGE_SCN_CNT_CODE else '-'
            fi = 'I' if section.IMAGE_SCN_CNT_INITIALIZED_DATA else '-'
            fu = 'U' if section.IMAGE_SCN_CNT_UNINITIALIZED_DATA else '-'


            
            child.setText(5, '{0:X} {1}'.format(section.Characteristics, '[{0}{1}{2}  {3}{4}{5}]'.format(fr, fw, fe, fc, fi, fu)))

            for i in range(6)[1:]:
                child.setTextAlignment(i, QtCore.Qt.AlignRight)

            parent.addTopLevelItem(child)


        # populate with directories
        parent = w.ui.treeWidgetDirectories
        parent.setColumnWidth(0, 150) 

        for d in self.PE.OPTIONAL_HEADER.DATA_DIRECTORY:
            child  = QtWidgets.QTreeWidgetItem(None)
            child.setText(0, d.name.replace('IMAGE_DIRECTORY_ENTRY_', ''))

            if d.VirtualAddress != 0 and d.Size != 0:
                for i, section in enumerate(self.PE.sections):
                    if section.contains_rva(d.VirtualAddress):
                        child.setText(1, '{0} [{1}]'.format(section.Name.decode('cp437').strip('\0'), i))
                        child.setForeground(1, QtGui.QColor('red'))
                        break
                else:
                    child.setText(1, '{0}'.format('<outside>'))


                child.setText(2, '{0:X}'.format(d.VirtualAddress))
                child.setText(3, '{0:X}'.format(d.Size))
                child.setForeground(2, QtGui.QColor('green'))
                child.setForeground(3, QtGui.QColor('green'))
            else:
                child.setForeground(0, QtGui.QColor('lightgray'))

            parent.addTopLevelItem(child)

            for i in range(4)[1:]:
                child.setTextAlignment(i, QtCore.Qt.AlignRight)



        # populate Header
        parent = w.ui.treeWidgetHeader
        parent.setColumnWidth(0, 250) 

        bkbrush = QtGui.QBrush(QtGui.QColor(192, 165, 194))
        bkbrush2 = QtGui.QBrush(QtGui.QColor(232, 194, 229))

        child = QtWidgets.QTreeWidgetItem(None)

        child.setText(0, 'IMAGE_DOS_HEADER')
        child.setBackground(0, bkbrush)

        ch2 = QtWidgets.QTreeWidgetItem(['magic', 'word', '{0:X}'.format(int(self.PE.DOS_HEADER.e_magic))])
        ch2.setForeground(2, QtGui.QColor('green'))
        ch2.setForeground(1, QtGui.QColor(183, 72, 197))
        child.addChild(ch2)

        ch2 = QtWidgets.QTreeWidgetItem(['e_lfanew', 'word', '{0:X}'.format(int(self.PE.DOS_HEADER.e_lfanew))])
        ch2.setForeground(2, QtGui.QColor('green'))
        ch2.setForeground(1, QtGui.QColor(183, 72, 197))
        child.addChild(ch2)

        parent.addTopLevelItem(child)


        item = QtWidgets.QTreeWidgetItem(['IMAGE_NT_HEADERS'])
        item.setBackground(0, bkbrush)

        child = QtWidgets.QTreeWidgetItem(['Signature', 'word',  '{0:X}'.format(int(self.PE.NT_HEADERS.Signature))])
        child.setForeground(2, QtGui.QColor('green'))
        child.setForeground(1, QtGui.QColor(183, 72, 197))

        item.addChild(child)

        subitem = QtWidgets.QTreeWidgetItem(['IMAGE_FILE_HEADER'])
        subitem.setBackground(0, bkbrush2)

        child = QtWidgets.QTreeWidgetItem(['Machine', 'word',  '{0:X}'.format(int(self.PE.FILE_HEADER.Machine))])
        child.setForeground(2, QtGui.QColor('green'))
        child.setForeground(1, QtGui.QColor(183, 72, 197))

        subitem.addChild(child)

        child = QtWidgets.QTreeWidgetItem(['NumberOfSections', 'word',  '{0:X}'.format(int(self.PE.FILE_HEADER.NumberOfSections))])
        child.setForeground(2, QtGui.QColor('green'))
        child.setForeground(1, QtGui.QColor(183, 72, 197))

        subitem.addChild(child)

        child = QtWidgets.QTreeWidgetItem(['TimeDateStamp', 'dword',  '{0:X}'.format(int(self.PE.FILE_HEADER.TimeDateStamp))])
        child.setForeground(2, QtGui.QColor('green'))
        child.setForeground(1, QtGui.QColor(183, 72, 197))

        subitem.addChild(child)

        child = QtWidgets.QTreeWidgetItem(['Characteristics', 'dword',  '{0:X}'.format(int(self.PE.FILE_HEADER.Characteristics))])
        child.setForeground(2, QtGui.QColor('green'))
        child.setForeground(1, QtGui.QColor(183, 72, 197))

        subitem.addChild(child)
        item.addChild(subitem)


        subitem = QtWidgets.QTreeWidgetItem(['IMAGE_OPTIONAL_HEADER'])
        subitem.setBackground(0, bkbrush2)

        Data = [['Magic', 'word',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.Magic))],
                ['SizeOfCode', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfCode))],
                ['SizeOfInitializedData', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfInitializedData))],
                ['SizeOfUninitializedData', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfUninitializedData))],
                ['AddressOfEntryPoint', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.AddressOfEntryPoint))],
                ['BaseOfCode', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.BaseOfCode))],
                ['ImageBase', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.ImageBase))],
                ['SectionAlignment', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SectionAlignment))],
                ['FileAlignment', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.FileAlignment))],
                ['SizeOfImage', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfImage))],
                ['SizeOfHeaders', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfHeaders))],
                ['CheckSum', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.CheckSum))],
                ['Magic', 'word',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.Magic))],
                ['SizeOfCode', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfCode))],
                ['SizeOfInitializedData', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfInitializedData))],
                ['SizeOfUninitializedData', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfUninitializedData))],
                ['AddressOfEntryPoint', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.AddressOfEntryPoint))],
                ['BaseOfCode', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.BaseOfCode))],
                ['ImageBase', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.ImageBase))],
                ['SectionAlignment', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SectionAlignment))],
                ['FileAlignment', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.FileAlignment))],
                ['SizeOfImage', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfImage))],
                ['SizeOfHeaders', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.SizeOfHeaders))],
                ['CheckSum', 'dword',  '{0:X}'.format(int(self.PE.OPTIONAL_HEADER.CheckSum))]]

        for it in Data:
            child = QtWidgets.QTreeWidgetItem(it)

            child.setForeground(2, QtGui.QColor('green'))
            child.setForeground(1, QtGui.QColor(183, 72, 197))

            subitem.addChild(child)


        child = QtWidgets.QTreeWidgetItem(['IMAGE_DATA_DIRECTORY [16]'])
        child.setBackground(0, bkbrush2)

        for i, d in enumerate(self.PE.OPTIONAL_HEADER.DATA_DIRECTORY):
            subchild = QtWidgets.QTreeWidgetItem(['[{0}] {1}'.format(i, d.name.replace('IMAGE_DIRECTORY_ENTRY_', ''))])
            if d.VirtualAddress == 0 and d.Size == 0:
                subchild.setForeground(0, QtGui.QColor('lightgray'))

            c = QtWidgets.QTreeWidgetItem(['VirtualAddress', 'dword', '{0:X}'.format(int(d.VirtualAddress))])
            c.setForeground(2, QtGui.QColor('green'))
            c.setForeground(1, QtGui.QColor(183, 72, 197))
            subchild.addChild(c)

            c = QtWidgets.QTreeWidgetItem(['Size', 'dword', '{0:X}'.format(int(d.Size))])
            c.setForeground(2, QtGui.QColor('green'))
            c.setForeground(1, QtGui.QColor(183, 72, 197))
            subchild.addChild(c)

            child.addChild(subchild)


        subitem.addChild(child)

        item.addChild(subitem)


        parent.addTopLevelItem(item) # NT_HEADERS


        _item =  QtWidgets.QTreeWidgetItem(['{0}'.format('IMAGE_SECTION_HEADERS []')])
        parent.addTopLevelItem(_item)

        for i, section in enumerate(self.PE.sections):
            item =  QtWidgets.QTreeWidgetItem(['{0} [{1}]'.format('SECTION_HEADER', i)])
            item.setBackground(0, bkbrush)

            Data = [['Name', 'char[8]',  section.Name.decode('cp437')],
                    ['VirtualSize', 'dword',  '{0:X}'.format(int(section.Misc_VirtualSize))],
                    ['VirtualAddress', 'dword',  '{0:X}'.format(int(section.VirtualAddress))],
                    ['SizeOfRawData', 'dword',  '{0:X}'.format(int(section.SizeOfRawData))],
                    ['PointerToRawData', 'dword',  '{0:X}'.format(int(section.PointerToRawData))],
                    ['Characteristics', 'dword',  '{0:X}'.format(int(section.Characteristics))]
            ]

            for data in Data:
                child = QtWidgets.QTreeWidgetItem(data)
                child.setForeground(2, QtGui.QColor('green'))
                child.setForeground(1, QtGui.QColor(183, 72, 197))

                item.addChild(child)

            _item.addChild(item)



        #print self.PE


        """
        

        parent = w.ui.treeWidget


        # add sections

        for section in self.PE.sections:
            child  = QtWidgets.QTreeWidgetItem(None)            
            child.setText(0, section.Name)            
            parent.topLevelItem(3).addChild(child)
        """
def writeData ( self , w ) : if hasattr ( self . PE , 'FileInfo' ) : for f in self . PE . FileInfo : if f . Key == 'StringFileInfo' : for st in f . StringTable : for entry in st . entries : #print entry w . ui . tableWidget_2 . setColumnWidth ( 0 , 300 ) if entry == 'CompanyName' : w . ui . tableWidget_2 . setItem ( 0 , 0 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'FileDescription' : w . ui . tableWidget_2 . setItem ( 0 , 1 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'FileVersion' : w . ui . tableWidget_2 . setItem ( 0 , 2 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'LegalCopyright' : w . ui . tableWidget_2 . setItem ( 0 , 3 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'OriginalFilename' : w . ui . tableWidget_2 . setItem ( 0 , 4 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'ProductName' : w . ui . tableWidget_2 . setItem ( 0 , 5 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if entry == 'ProductVersion' : w . ui . tableWidget_2 . setItem ( 0 , 6 , QtWidgets . QTableWidgetItem ( st . entries [ entry ] ) ) if self . PE . is_exe ( ) : petype = 'EXE' elif self . PE . is_dll ( ) : petype = 'DLL' elif self . PE . is_driver ( ) : petype = 'Driver' else : petype = 'n/a' w . ui . tableWidget . setItem ( 0 , 0 , QtWidgets . QTableWidgetItem ( petype ) ) w . ui . tableWidget . setItem ( 1 , 0 , QtWidgets . QTableWidgetItem ( '{:,} bytes' . format ( self . dataModel . getDataSize ( ) ) ) ) # add exports parent = w . ui . treeWidgetExports parent . setColumnWidth ( 0 , 300 ) if hasattr ( self . PE , 'DIRECTORY_ENTRY_EXPORT' ) : try : rva = self . PE . get_offset_from_rva ( self . PE . DIRECTORY_ENTRY_EXPORT . struct . Name ) # very ygly, i know s = '' c = 'z' k = 0 while c != '\0' and k < 50 : c = chr ( self . dataModel . getBYTE ( rva ) ) s += c rva += 1 k += 1 child = QtWidgets . QTreeWidgetItem ( None ) child . setText ( 0 , s ) parent . addTopLevelItem ( child ) parent . expandItem ( child ) for i , exp in enumerate ( self . PE . DIRECTORY_ENTRY_EXPORT . symbols ) : child = QtWidgets . QTreeWidgetItem ( None ) if exp . name : child . setText ( 0 , exp . name ) child . setText ( 1 , '0x{0:X}' . format ( exp . address ) ) #parent.topLevelItem(i).addChild(child) #parent.topLevelItem(i).addChild(child) parent . topLevelItem ( 0 ) . addChild ( child ) except Exception as e : logger . error ( e , exc_info = 1 ) # add imports parent = w . ui . treeWidgetImports parent . setColumnWidth ( 0 , 300 ) try : for i , entry in enumerate ( self . PE . DIRECTORY_ENTRY_IMPORT ) : child = QtWidgets . QTreeWidgetItem ( None ) child . setText ( 0 , entry . dll . decode ( 'cp437' ) ) parent . addTopLevelItem ( child ) for imp in entry . imports : child = QtWidgets . QTreeWidgetItem ( None ) if imp . name : child . setText ( 0 , imp . name . decode ( 'cp437' ) ) child . setText ( 1 , '0x{0:X}' . format ( imp . address - self . PE . OPTIONAL_HEADER . ImageBase ) ) parent . topLevelItem ( i ) . addChild ( child ) if imp . ordinal : child . setText ( 0 , 'ordinal:{0}' . format ( imp . ordinal ) ) child . setText ( 1 , '0x{0:X}' . format ( imp . address - self . PE . OPTIONAL_HEADER . ImageBase ) ) parent . topLevelItem ( i ) . addChild ( child ) except Exception as e : logger . error ( e , exc_info = 1 ) # populate with sections parent = w . ui . treeWidgetSections parent . setColumnWidth ( 0 , 100 ) parent . setColumnWidth ( 1 , 80 ) parent . setColumnWidth ( 2 , 80 ) parent . setColumnWidth ( 3 , 80 ) parent . setColumnWidth ( 4 , 80 ) for section in self . PE . sections : child = QtWidgets . QTreeWidgetItem ( None ) child . setText ( 0 , section . Name . decode ( 'cp437' ) ) child . setText ( 1 , '{0:X}' . format ( section . PointerToRawData ) ) child . setText ( 2 , '{0:X}' . format ( section . SizeOfRawData ) ) child . setText ( 3 , '{0:X}' . format ( section . VirtualAddress ) ) child . setText ( 4 , '{0:X}' . format ( section . Misc_VirtualSize ) ) child . setForeground ( 1 , QtGui . QColor ( 'green' ) ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 3 , QtGui . QColor ( 183 , 72 , 197 ) ) child . setForeground ( 4 , QtGui . QColor ( 183 , 72 , 197 ) ) # build characteristics string for every section fr = 'R' if section . IMAGE_SCN_MEM_READ else '-' fw = 'W' if section . IMAGE_SCN_MEM_WRITE else '-' fe = 'E' if section . IMAGE_SCN_MEM_EXECUTE else '-' fc = 'C' if section . IMAGE_SCN_CNT_CODE else '-' fi = 'I' if section . IMAGE_SCN_CNT_INITIALIZED_DATA else '-' fu = 'U' if section . IMAGE_SCN_CNT_UNINITIALIZED_DATA else '-' child . setText ( 5 , '{0:X} {1}' . format ( section . Characteristics , '[{0}{1}{2}  {3}{4}{5}]' . format ( fr , fw , fe , fc , fi , fu ) ) ) for i in range ( 6 ) [ 1 : ] : child . setTextAlignment ( i , QtCore . Qt . AlignRight ) parent . addTopLevelItem ( child ) # populate with directories parent = w . ui . treeWidgetDirectories parent . setColumnWidth ( 0 , 150 ) for d in self . PE . OPTIONAL_HEADER . DATA_DIRECTORY : child = QtWidgets . QTreeWidgetItem ( None ) child . setText ( 0 , d . name . replace ( 'IMAGE_DIRECTORY_ENTRY_' , '' ) ) if d . VirtualAddress != 0 and d . Size != 0 : for i , section in enumerate ( self . PE . sections ) : if section . contains_rva ( d . VirtualAddress ) : child . setText ( 1 , '{0} [{1}]' . format ( section . Name . decode ( 'cp437' ) . strip ( '\0' ) , i ) ) child . setForeground ( 1 , QtGui . QColor ( 'red' ) ) break else : child . setText ( 1 , '{0}' . format ( '<outside>' ) ) child . setText ( 2 , '{0:X}' . format ( d . VirtualAddress ) ) child . setText ( 3 , '{0:X}' . format ( d . Size ) ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 3 , QtGui . QColor ( 'green' ) ) else : child . setForeground ( 0 , QtGui . QColor ( 'lightgray' ) ) parent . addTopLevelItem ( child ) for i in range ( 4 ) [ 1 : ] : child . setTextAlignment ( i , QtCore . Qt . AlignRight ) # populate Header parent = w . ui . treeWidgetHeader parent . setColumnWidth ( 0 , 250 ) bkbrush = QtGui . QBrush ( QtGui . QColor ( 192 , 165 , 194 ) ) bkbrush2 = QtGui . QBrush ( QtGui . QColor ( 232 , 194 , 229 ) ) child = QtWidgets . QTreeWidgetItem ( None ) child . setText ( 0 , 'IMAGE_DOS_HEADER' ) child . setBackground ( 0 , bkbrush ) ch2 = QtWidgets . QTreeWidgetItem ( [ 'magic' , 'word' , '{0:X}' . format ( int ( self . PE . DOS_HEADER . e_magic ) ) ] ) ch2 . setForeground ( 2 , QtGui . QColor ( 'green' ) ) ch2 . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) child . addChild ( ch2 ) ch2 = QtWidgets . QTreeWidgetItem ( [ 'e_lfanew' , 'word' , '{0:X}' . format ( int ( self . PE . DOS_HEADER . e_lfanew ) ) ] ) ch2 . setForeground ( 2 , QtGui . QColor ( 'green' ) ) ch2 . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) child . addChild ( ch2 ) parent . addTopLevelItem ( child ) item = QtWidgets . QTreeWidgetItem ( [ 'IMAGE_NT_HEADERS' ] ) item . setBackground ( 0 , bkbrush ) child = QtWidgets . QTreeWidgetItem ( [ 'Signature' , 'word' , '{0:X}' . format ( int ( self . PE . NT_HEADERS . Signature ) ) ] ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) item . addChild ( child ) subitem = QtWidgets . QTreeWidgetItem ( [ 'IMAGE_FILE_HEADER' ] ) subitem . setBackground ( 0 , bkbrush2 ) child = QtWidgets . QTreeWidgetItem ( [ 'Machine' , 'word' , '{0:X}' . format ( int ( self . PE . FILE_HEADER . Machine ) ) ] ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subitem . addChild ( child ) child = QtWidgets . QTreeWidgetItem ( [ 'NumberOfSections' , 'word' , '{0:X}' . format ( int ( self . PE . FILE_HEADER . NumberOfSections ) ) ] ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subitem . addChild ( child ) child = QtWidgets . QTreeWidgetItem ( [ 'TimeDateStamp' , 'dword' , '{0:X}' . format ( int ( self . PE . FILE_HEADER . TimeDateStamp ) ) ] ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subitem . addChild ( child ) child = QtWidgets . QTreeWidgetItem ( [ 'Characteristics' , 'dword' , '{0:X}' . format ( int ( self . PE . FILE_HEADER . Characteristics ) ) ] ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subitem . addChild ( child ) item . addChild ( subitem ) subitem = QtWidgets . QTreeWidgetItem ( [ 'IMAGE_OPTIONAL_HEADER' ] ) subitem . setBackground ( 0 , bkbrush2 ) Data = [ [ 'Magic' , 'word' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . Magic ) ) ] , [ 'SizeOfCode' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfCode ) ) ] , [ 'SizeOfInitializedData' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfInitializedData ) ) ] , [ 'SizeOfUninitializedData' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfUninitializedData ) ) ] , [ 'AddressOfEntryPoint' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . AddressOfEntryPoint ) ) ] , [ 'BaseOfCode' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . BaseOfCode ) ) ] , [ 'ImageBase' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . ImageBase ) ) ] , [ 'SectionAlignment' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SectionAlignment ) ) ] , [ 'FileAlignment' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . FileAlignment ) ) ] , [ 'SizeOfImage' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfImage ) ) ] , [ 'SizeOfHeaders' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfHeaders ) ) ] , [ 'CheckSum' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . CheckSum ) ) ] , [ 'Magic' , 'word' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . Magic ) ) ] , [ 'SizeOfCode' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfCode ) ) ] , [ 'SizeOfInitializedData' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfInitializedData ) ) ] , [ 'SizeOfUninitializedData' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfUninitializedData ) ) ] , [ 'AddressOfEntryPoint' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . AddressOfEntryPoint ) ) ] , [ 'BaseOfCode' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . BaseOfCode ) ) ] , [ 'ImageBase' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . ImageBase ) ) ] , [ 'SectionAlignment' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SectionAlignment ) ) ] , [ 'FileAlignment' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . FileAlignment ) ) ] , [ 'SizeOfImage' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfImage ) ) ] , [ 'SizeOfHeaders' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . SizeOfHeaders ) ) ] , [ 'CheckSum' , 'dword' , '{0:X}' . format ( int ( self . PE . OPTIONAL_HEADER . CheckSum ) ) ] ] for it in Data : child = QtWidgets . QTreeWidgetItem ( it ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subitem . addChild ( child ) child = QtWidgets . QTreeWidgetItem ( [ 'IMAGE_DATA_DIRECTORY [16]' ] ) child . setBackground ( 0 , bkbrush2 ) for i , d in enumerate ( self . PE . OPTIONAL_HEADER . DATA_DIRECTORY ) : subchild = QtWidgets . QTreeWidgetItem ( [ '[{0}] {1}' . format ( i , d . name . replace ( 'IMAGE_DIRECTORY_ENTRY_' , '' ) ) ] ) if d . VirtualAddress == 0 and d . Size == 0 : subchild . setForeground ( 0 , QtGui . QColor ( 'lightgray' ) ) c = QtWidgets . QTreeWidgetItem ( [ 'VirtualAddress' , 'dword' , '{0:X}' . format ( int ( d . VirtualAddress ) ) ] ) c . setForeground ( 2 , QtGui . QColor ( 'green' ) ) c . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subchild . addChild ( c ) c = QtWidgets . QTreeWidgetItem ( [ 'Size' , 'dword' , '{0:X}' . format ( int ( d . Size ) ) ] ) c . setForeground ( 2 , QtGui . QColor ( 'green' ) ) c . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) subchild . addChild ( c ) child . addChild ( subchild ) subitem . addChild ( child ) item . addChild ( subitem ) parent . addTopLevelItem ( item ) # NT_HEADERS _item = QtWidgets . QTreeWidgetItem ( [ '{0}' . format ( 'IMAGE_SECTION_HEADERS []' ) ] ) parent . addTopLevelItem ( _item ) for i , section in enumerate ( self . PE . sections ) : item = QtWidgets . QTreeWidgetItem ( [ '{0} [{1}]' . format ( 'SECTION_HEADER' , i ) ] ) item . setBackground ( 0 , bkbrush ) Data = [ [ 'Name' , 'char[8]' , section . Name . decode ( 'cp437' ) ] , [ 'VirtualSize' , 'dword' , '{0:X}' . format ( int ( section . Misc_VirtualSize ) ) ] , [ 'VirtualAddress' , 'dword' , '{0:X}' . format ( int ( section . VirtualAddress ) ) ] , [ 'SizeOfRawData' , 'dword' , '{0:X}' . format ( int ( section . SizeOfRawData ) ) ] , [ 'PointerToRawData' , 'dword' , '{0:X}' . format ( int ( section . PointerToRawData ) ) ] , [ 'Characteristics' , 'dword' , '{0:X}' . format ( int ( section . Characteristics ) ) ] ] for data in Data : child = QtWidgets . QTreeWidgetItem ( data ) child . setForeground ( 2 , QtGui . QColor ( 'green' ) ) child . setForeground ( 1 , QtGui . QColor ( 183 , 72 , 197 ) ) item . addChild ( child ) _item . addChild ( item ) #print self.PE