-
Notifications
You must be signed in to change notification settings - Fork 8
/
asmui.py
executable file
·112 lines (92 loc) · 3.15 KB
/
asmui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python3
import tkinter as tk
from tkinter import N,E,W,S
import bsl
import intellibus as ib
from threading import Thread
import sys
import os
import struct
if len(sys.argv) < 2:
print('Usage: {} PORT'.format(sys.argv[0]), file=sys.stderr)
sys.exit(255)
bus = ib.Intellibus(sys.argv[1], debug='tx,rx')
thr = Thread(target=bus.run)
thr.start()
os.chdir('bsl')
class ReplyListener:
def __init__(self, data_callback, opcode=0):
self.data_callback = data_callback
self.opcode = opcode
def receive(self, pkt, synced):
if type(pkt) is ib.Message and pkt.getcmd() == self.opcode:
self.data_callback(pkt.getarg())
top = tk.Tk()
top.title('ASM Execution')
pw = tk.PanedWindow(orient=tk.VERTICAL)
tbCode = tk.Text()
tbOutput = tk.Text()
def add_output(text):
tbOutput.insert(tk.END, '\n'+text)
tbOutput.see(tk.END)
head = tk.Frame(relief=tk.SUNKEN, borderwidth=1)
tk.Label(head, text='Reply opcode: ').pack(side=tk.LEFT)
numReply = tk.Entry(head, width=5)
numReply.insert(tk.END, '1337')
numReply.pack(side=tk.LEFT)
tk.Label(head, text=' Body: r15:r14 → ').pack(side=tk.LEFT)
numSize = tk.Entry(head, width=3)
numSize.insert(tk.END, '64')
numSize.pack(side=tk.LEFT)
tk.Label(head, text=' byte(s)').pack(side=tk.LEFT)
def on_rx(data):
global tbOutput
add_output(ib.hexdump(data))
reply_listener = ReplyListener(on_rx)
bus.add_listener(reply_listener)
def process_code(code, opcode, datasize):
prefix = ib.fromhex(''.join([
'D4F01400', # mov r15, [r0+#14h]
'D4E01200', # mov r14, [r0+#12h]
'E6F4'+ib.tohex(struct.pack('<H', datasize + 4)), # mov r4, #(size+4)
'E6F5'+ib.tohex(struct.pack('<H', opcode)), # mov r5, #(opcode)
'DC1F', # exts r15, #2
'B84E', # mov [r14], r4
'C45E0200', # mov [r14+#2], r5
'08E4', # add r14, #4
'18F0' # addc r15, #0
]))
suffix = b'\xDB\0' # rets
return prefix + bsl.assemble(code) + suffix
def btnExec_click():
global reply_listener
code = tbCode.get('1.0', 'end')
add_output(code)
datasize = int(numSize.get())
reply_listener.opcode = int(numReply.get())
code = process_code(code, reply_listener.opcode, datasize)
bus.send(0, 0x7FFE, (31337, code))
def btnClear_click():
tbOutput.delete('1.0', tk.END)
def btnReset_click():
bus.send(0, 0x7FFE, (32, b''))
btnExec = tk.Button(text='Execute', command=btnExec_click)
btnClear = tk.Button(text='Clear Output', command=btnClear_click)
btnReset = tk.Button(text='Reboot Panel', command=btnReset_click)
head.grid(row=0, column=0, columnspan=2, sticky=W+E)
pw.add(tbCode)
pw.add(tbOutput)
pw.grid(row=1, column=0, columnspan=2, sticky=N+E+W+S)
btnClear.grid(row=2, column=0, sticky=W+E)
btnReset.grid(row=3, column=0, sticky=W+E)
btnExec.grid(row=2, column=1, rowspan=2, sticky=N+E+W+S)
top.grid_rowconfigure(1, weight=1)
top.grid_columnconfigure(0, weight=1)
top.grid_columnconfigure(1, weight=2)
try:
top.mainloop()
except KeyboardInterrupt:
pass
finally:
bus.stop()
thr.join()