-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_firmware.py
47 lines (35 loc) · 1.27 KB
/
install_firmware.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
import usb.core
import time
def send_firmware():
fw = open("apex_latest_single_ep.bin", "rb").read()
it = 0
for i in range(0, len(fw), 0x100):
dev.ctrl_transfer(0x21, 0x01, it, 0, fw[i:i+0x100])
dev.ctrl_transfer(0xa1, 0x03, 0, 0, 6)
it += 1
def send_mysterious_file():
fw = open("mysterious_file.bin", "rb").read()
it = 0
for i in range(0, len(fw), 0x100):
dev.ctrl_transfer(0xa1, 0x02, it, 0, fw[i:i+0x100])
it += 1
dev = usb.core.find(idVendor=0x18d1, idProduct=0x9302)
if (dev == None):
print("Downloading firmware...")
dev = usb.core.find(idVendor=0x1a6e, idProduct=0x089a)
dev.reset()
hex_data = [0x00, 0x00, 0x00, 0xcb, 0xea, 0x6e, 0x01, 0x00, 0x00, 0x00, 0x70, 0x17, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00]
dev.ctrl_transfer(0x80, 0x06, 0x100, 0x00, bytearray(hex_data))
dev.ctrl_transfer(0x80, 0x06, 0x200, 0x00, 521)
send_firmware()
dev.ctrl_transfer(0x21, 0x01, 0x2b, 0x00, 0)
dev.ctrl_transfer(0xa1, 0x03, 0x00, 0x00, 6)
send_mysterious_file()
try:
dev.reset()
except usb.core.USBError:
print("Resetting...")
time.sleep(4)
dev = usb.core.find(idVendor=0x18d1, idProduct=0x9302)
if(dev):
print("Firmware downloaded correctly.")