def load_filelist(self, link): self.task = task.create_task(link) filelist = self.task.filelist self.ui.file_list.setRowCount(len(filelist)) self.ui.file_list.setColumnCount(2) self.ui.file_list.setHorizontalHeaderLabels(['文件', '大小']) self.ui.file_list.horizontalHeader().setStretchLastSection(True) self.ui.file_list.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.ui.file_list.setEditTriggers(QAbstractItemView.NoEditTriggers) raw = 0 for file in filelist: name = file['name'] size = file['size'] size = tools.sizeof(size) item_name = QTableWidgetItem(name) item_size = QTableWidgetItem(size) item_size.setTextAlignment(Qt.AlignCenter) self.ui.file_list.setItem(raw, 0, item_name) self.ui.file_list.setItem(raw, 1, item_size) raw += 1
def refresh(self): task = self.__task p = task.downloaded / task.size * 100 self.ui.progressBar.setValue(p) self.ui.label_speed\ .setText(tools.sizeof((task.downloaded - self.__last) * 2) + '/s') print(task.downloaded / task.size) self.__last = task.downloaded if p == 100: self.__timer.stop() self.finished.emit(self.__task.info) self.__task.wait()
def _parseSymbolTable(self): """Parses the symbol table of the file and stores it in self.symbolTable.""" try: dynStr = strTable(section=self.sections[".dynstr"]) dynSym = self.sections[".dynsym"] except: warnings.warn("Section {} missing. Can't parse Symbol Table.".\ format(sys.exc_info()[1].args[0])) return structure = "Elf32_Sym" if self.is32() else "Elf64_Sym" if not dynSym.sh_entsize == sizeof(structure): warnings.warn("'sh_entsize' of .dynsym Section does not match sizeof(structure). "\ "This will probably cause errors or wrong data.") times = int(dynSym.dataLen / sizeof(structure)) offset = 0 data = dynSym.read() self.symbolTable = symbolTable() for i in range(times): _data = self._unpackData(structure, data[offset:\ offset+sizeof(structure)]) _data.st_name = dynStr.getString(_data.st_name) if _data.st_shndx == SHN_UNDEF: self.symbolTable.imports.append(_data) else: self.symbolTable.exports.append(_data) offset += sizeof(structure) del self.symbolTable.imports[0]
def _parseRelocations(self): """Parses the relocations of the file and stores them in self.relocations.""" self.relocations = {"rel": list(), "rela": list()} rels = self.findRelSections() relS = "Elf32_Rel" if self.is32() else "Elf64_Rel" relaS = "Elf32_Rela" if self.is32() else "Elf64_Rela" for rel in rels["rel"]: if not rel.sh_entsize == sizeof(relS): warnings.warn("'sh_entsize' of {} Section does not match sizeof(structure). "\ "This will probably cause errors or wrong data.".format(rel.sh_name)) times = int(rel.dataLen / sizeof(relS)) offset = 0 data = rel.read() for i in range(times): _data = self._unpackData(relS, data[offset:\ offset+sizeof(relS)]) self.relocations["rel"].append(_data) offset += sizeof(relS) for rel in rels["rela"]: if not rel.sh_entsize == sizeof(relaS): warnings.warn("'sh_entsize' of {} Section does not match sizeof(structure). "\ "This will probably cause errors or wrong data.".format(rel.sh_name)) times = int(rel.dataLen / sizeof(relaS)) offset = 0 data = rel.read() for i in range(times): _data = self._unpackData(relaS, data[offset:\ offset+sizeof(relS)]) self.relocations["rela"].append(_data) offset += sizeof(relaS)
def __init__(self, task, parent=None): super().__init__(parent) self.ui = ui_downloading_item.Ui_Form() self.ui.setupUi(self) self.__task = task self.__last = task.downloaded # 初始化控件 self.ui.label_title.setText('<h3>%s</h1>' % task.title) self.ui.label_speed.setText('暂停') self.ui.label_size.setText('<h4>%s</h4>' % tools.sizeof(task.size)) self.ui.progressBar.setValue(task.downloaded / task.size * 100) # 初始化右键菜单选项 self.a_start = QAction('开始任务', self) self.a_stop = QAction('暂停任务', self) self.a_rm = QAction('移除任务', self) self.a_start.triggered.connect(self.start) self.a_stop.triggered.connect(self.stop) self.a_rm.triggered.connect(self.remove) self.__timer = QtCore.QTimer() self.__timer.timeout.connect(self.refresh)
def _parseDynamicTags(self): """Parses the dynamic tags of the file and stores it in self.dynamicTags.""" try: dynamic = self.sections[".dynamic"] except: warnings.warn( "Section .dynamic missing. Can't parse Dynamic Tags.") return structure = "Elf32_Dyn" if self.is32() else "Elf64_Dyn" if not dynamic.sh_entsize == sizeof(structure): warnings.warn("'sh_entsize' of .dynamic Section does not match sizeof(structure). "\ "This will probably cause errors or wrong data.") times = int(dynamic.dataLen / sizeof(structure)) offset = 0 data = dynamic.read() self.dynamicTags = list() for i in range(times): _data = self._unpackData(structure, data[offset:\ offset+sizeof(structure)]) self.dynamicTags.append(_data) offset += sizeof(structure) del self.dynamicTags[-1] if not ".dynstr" in self.sections: warnings.warn("Section .dynstr missing. This may cause errors while parsing "\ "dynamic tags.") strTab = None else: strTab = strTable(section=self.sections[".dynstr"]) strIndexes = { "DT_NEEDED", "DT_SONAME", "DT_RPATH", "DT_RUNPATH", "DT_SUNW_AUXILIARY", "DT_SUNW_FILTER", "DT_AUXILIARY", "DT_CONFIG", "DT_DEPAUDIT", "DT_AUDIT" } strIndexes = [TAGS[k] for k in strIndexes] for i in range(len(self.dynamicTags)): value = self.dynamicTags[i] if value.d_tag in strIndexes: if strTab: if strTab.getString(value.d_val): self.dynamicTags[i].d_val = strTab.getString( value.d_val) try: value.d_tag = TAGS[value.d_tag] except: pass