def set_ranges(self, ranges): self.setRowCount(0) i = 0 for range in sorted(ranges, key=lambda x: x['base'], reverse=True): self.insertRow(i) q = NotEditableTableWidgetItem(range['base']) q.setForeground(Qt.red) self.setItem(i, 0, q) q = NotEditableTableWidgetItem(str(range['size'])) q.setFlags(Qt.NoItemFlags) self.setItem(i, 1, q) q = NotEditableTableWidgetItem(range['protection']) q.setFlags(Qt.NoItemFlags) q.setTextAlignment(Qt.AlignCenter) self.setItem(i, 2, q) if 'file' in range: q = NotEditableTableWidgetItem(range['file']['path']) q.setFlags(Qt.NoItemFlags) q.setForeground(Qt.gray) self.setItem(i, 3, q) else: self.setItem(i, 3, NotEditableTableWidgetItem('')) i += 1 self.resizeRowsToContents() self.horizontalHeader().setStretchLastSection(True)
def __init__(self, app): super(ScriptsDialog, self).__init__(app) self.script = None self.setMinimumWidth(800) box = QVBoxLayout(self) table = ScriptsTable(app, self) table.setMinimumWidth(800) for script_name in sorted( app.get_dwarf().get_scripts_manager().get_scripts().keys()): script = app.get_dwarf().get_scripts_manager().get_script( script_name) info = script['info'] row = table.rowCount() table.insertRow(row) q = NotEditableTableWidgetItem(info['name']) q.set_data(script_name) table.setItem(row, 0, q) if 'author' in info: q = NotEditableTableWidgetItem(info['author']) q.setFlags(Qt.NoItemFlags) q.setForeground(Qt.lightGray) table.setItem(row, 1, q) if 'android' in info: q = NotEditableTableWidgetItem('X') q.setFlags(Qt.NoItemFlags) q.setTextAlignment(Qt.AlignCenter) q.setForeground(Qt.white) table.setItem(row, 2, q) if 'ios' in info: q = NotEditableTableWidgetItem('X') q.setFlags(Qt.NoItemFlags) q.setTextAlignment(Qt.AlignCenter) q.setForeground(Qt.white) table.setItem(row, 3, q) if 'description' in info: q = NotEditableTableWidgetItem(info['description']) q.setFlags(Qt.NoItemFlags) q.setForeground(Qt.lightGray) table.setItem(row, 4, q) box.addWidget(table) self.setLayout(box)
def disasm(self, range, offset): self.setRowCount(0) self.range = range self.offset = offset md = Cs(self.cs_arch, self.cs_mode) md.detail = True insts = 0 for i in md.disasm(self.range.data[self.offset:], self.range.base + self.offset): if insts > 128: break row = self.rowCount() self.insertRow(row) if insts == 0: sym = self.app.dwarf_api('getSymbolByAddress', i.address) if sym: module = '' if 'moduleName' in sym: module = '- %s' % sym['moduleName'] w = NotEditableTableWidgetItem('%s %s' % (sym['name'], module)) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.lightGray) self.setItem(row, 4, w) w = MemoryAddressWidget('0x%x' % i.address) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.red) w.set_address(i.address) w.set_offset(self.range.base - i.address) self.setItem(row, 0, w) w = NotEditableTableWidgetItem( binascii.hexlify(i.bytes).decode('utf8')) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.darkYellow) self.setItem(row, 1, w) is_jmp = False op_imm_value = 0 if CS_GRP_JUMP in i.groups or CS_GRP_CALL in i.groups: is_jmp = False if len(i.operands) > 0: for op in i.operands: if op.type == CS_OP_IMM: if len(i.operands) == 1: is_jmp = True if is_jmp: op_imm_value = op.value.imm sym = self.app.dwarf_api('getSymbolByAddress', op_imm_value) module = '' if 'moduleName' in sym: module = '- %s' % sym['moduleName'] w = NotEditableTableWidgetItem( '%s %s' % (sym['name'], module)) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.lightGray) self.setItem(row, 4, w) if is_jmp: w = MemoryAddressWidget(i.op_str) w.set_address(op_imm_value) w.setForeground(Qt.red) else: w = NotEditableTableWidgetItem(i.op_str) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.lightGray) self.setItem(row, 3, w) w = NotEditableTableWidgetItem(i.mnemonic.upper()) w.setFlags(Qt.NoItemFlags) w.setForeground(Qt.white) w.setTextAlignment(Qt.AlignCenter) w.setFont(QFont(None, 11, QFont.Bold)) self.setItem(row, 2, w) insts += 1 self.resizeColumnsToContents() self.scrollToTop()