291
|
1 from PyQt4.QtCore import *
|
|
2 from PyQt4.QtGui import *
|
|
3
|
|
4
|
|
5 class DisAsmModel(QAbstractTableModel):
|
|
6 def __init__(self):
|
|
7 super().__init__()
|
|
8 self.outs = None
|
|
9 self.instructions = []
|
|
10 self.headers = ['Address', 'Bytes', 'Instruction']
|
|
11 self.txts = []
|
|
12 self.txts.append(lambda i: '0x{:08x}'.format(i.address))
|
|
13 self.txts.append(lambda i: str(i.encode()))
|
|
14 self.txts.append(lambda i: str(i))
|
|
15
|
|
16 def rowCount(self, parent):
|
|
17 return len(self.instructions)
|
|
18
|
|
19 def columnCount(self, parent):
|
|
20 return len(self.headers)
|
|
21
|
|
22 def data(self, index, role):
|
|
23 if not index.isValid():
|
|
24 return
|
|
25 row, col = index.row(), index.column()
|
|
26 if role == Qt.DisplayRole:
|
|
27 i = self.instructions[row]
|
|
28 return self.txts[col](i)
|
|
29
|
|
30 def headerData(self, section, orientation, role):
|
|
31 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
|
|
32 return self.headers[section]
|
|
33
|
|
34 def setInstructions(self, ins):
|
|
35 self.instructions = ins
|
|
36 self.modelReset.emit()
|
|
37
|
|
38
|
|
39 class Disassembly(QTableView):
|
|
40 def __init__(self):
|
|
41 super().__init__()
|
|
42 self.dm = DisAsmModel()
|
|
43 self.setModel(self.dm)
|
|
44
|
|
45 def showPos(self, p):
|
|
46 for i in self.dm.instructions:
|
|
47 if i.address == p:
|
|
48 row = self.dm.instructions.index(i)
|
|
49 self.selectRow(row)
|
|
50
|