-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathfw_unpack.py
30 lines (21 loc) · 867 Bytes
/
fw_unpack.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
import libuvk5
import sys
import os
if len(sys.argv) not in [2,4]: print(f'Usage: {os.path.basename(sys.argv[0])} <encoded_firmware_in.bin> [<decoded_firmware_out.bin>] [<versionfile_out.bin>] ') ; exit(1)
infile = sys.argv[1]
if len(sys.argv)==4:
outfw = sys.argv[2]
outver = sys.argv[3]
else:
outfw = infile.replace('.bin','.dec.bin')
outver = infile.replace('.bin','.ver.bin')
encoded_firmware = open(infile,'rb').read()
if libuvk5.crc16_ccitt_le(encoded_firmware[:-2]) == encoded_firmware[-2:]:
print('CRC OK')
else:
print('CRC MISMATCH!')
decoded_firmware = libuvk5.firmware_xor(encoded_firmware[:-2])
open(outfw,'wb').write(decoded_firmware[:0x2000]+decoded_firmware[0x2000+16:])
print(f'Saved decoded firmware to {outfw}')
open(outver,'wb').write(decoded_firmware[0x2000:0x2000+16])
print(f'Saved version info to {outver}')