-
Notifications
You must be signed in to change notification settings - Fork 11
/
ctrl.py
executable file
·57 lines (47 loc) · 1.63 KB
/
ctrl.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
#!/usr/bin/env python3
import os
import sys
import struct
import libssam
from libssam import Controller, Request
def main():
cmd_name = sys.argv[1]
if cmd_name == 'help':
print(f'Usage:')
print(f' {sys.argv[0]} <command> [args...]')
print(f'')
print(f'Commands:')
print(f' help')
print(f' display this help message')
print(f'')
print(f' request <tc> <tid> <cid> <iid> <flags> [payload...]')
print(f' basic command with optional payload')
print(f'')
print(f'Arguments:')
print(f' <tc>: command target category')
print(f' <tid>: command target ID')
print(f' <cid>: command ID')
print(f' <iid>: command instance ID')
print(f' <flags>: request flags')
print(f' [payload...]: optional payload bytes, separated by whitespace')
elif cmd_name == 'request':
tc = int(sys.argv[2], 0)
tid = int(sys.argv[3], 0)
cid = int(sys.argv[4], 0)
iid = int(sys.argv[5], 0)
flg = int(sys.argv[6], 0)
pld = [int(x, 0) for x in sys.argv[7:]]
rqst = Request(tc, tid, cid, iid, flg, pld)
with Controller() as ctrl:
rsp = ctrl.request(rqst)
if rsp:
print(' '.join(['{:02x}'.format(x) for x in rsp]))
else:
print(f"Error: Unknown command '{cmd_name}'")
print(f'')
print(f'Usage:')
print(f' {sys.argv[0]} <command> [args...]')
print(f'')
print(f"Run '{sys.argv[0]} help' for more information")
if __name__ == '__main__':
main()