comparison python/ide/disasm.py @ 295:917eab04b8b7

Added disasm
author Windel Bouwman
date Thu, 28 Nov 2013 21:10:32 +0100
parents python/disasm.py@b07d28a5ca56
children dcae6574c974
comparison
equal deleted inserted replaced
294:e89cca5779b0 295:917eab04b8b7
1 from PyQt4.QtCore import *
2 from PyQt4.QtGui import *
3 import binascii
4
5
6 class DisAsmModel(QAbstractTableModel):
7 def __init__(self):
8 super().__init__()
9 self.outs = None
10 self.instructions = []
11 self.headers = ['Address', 'Bytes', 'Instruction']
12 self.txts = []
13 self.txts.append(lambda i: '0x{:08x}'.format(i.address))
14 self.txts.append(lambda i: binascii.hexlify(i.encode()).decode('ascii'))
15 self.txts.append(lambda i: str(i))
16
17 def rowCount(self, parent):
18 return len(self.instructions)
19
20 def columnCount(self, parent):
21 return len(self.headers)
22
23 def data(self, index, role):
24 if not index.isValid():
25 return
26 row, col = index.row(), index.column()
27 if role == Qt.DisplayRole:
28 i = self.instructions[row]
29 return self.txts[col](i)
30
31 def headerData(self, section, orientation, role):
32 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
33 return self.headers[section]
34
35 def setInstructions(self, ins):
36 self.instructions = ins
37 self.modelReset.emit()
38
39
40 class Disassembly(QTableView):
41 def __init__(self):
42 super().__init__()
43 self.dm = DisAsmModel()
44 self.setModel(self.dm)
45
46 def showPos(self, p):
47 for i in self.dm.instructions:
48 if i.address == p:
49 row = self.dm.instructions.index(i)
50 self.selectRow(row)
51