| Line 33... |
Line 33... |
| 33 |
def nano2gcryptdfu(data):
|
33 |
def nano2gcryptdfu(data):
|
| 34 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
34 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
| 35 |
header = "87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
35 |
header = "87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
| 36 |
embios = libembios.Embios()
|
36 |
embios = libembios.Embios()
|
| 37 |
embios.write(0x08000000, header.ljust(0x800, "\0") + data)
|
37 |
embios.write(0x08000000, header.ljust(0x800, "\0") + data)
|
| 38 |
embios.timeout = 20000
|
38 |
embios.lib.dev.timeout = 20000
|
| 39 |
embios.hmac_sha1(0x08000800, len(data), 0x08000010)
|
39 |
embios.hmac_sha1(0x08000800, len(data), 0x08000010)
|
| 40 |
embios.hmac_sha1(0x08000000, 0x40, 0x08000040)
|
40 |
embios.hmac_sha1(0x08000000, 0x40, 0x08000040)
|
| 41 |
embios.aesencrypt(0x08000000, len(data) + 0x800, 1)
|
41 |
embios.aesencrypt(0x08000000, len(data) + 0x800, 1)
|
| 42 |
return embios.read(0x08000000, len(data) + 0x800)
|
42 |
return embios.read(0x08000000, len(data) + 0x800)
|
| 43 |
|
43 |
|
| 44 |
|
44 |
|
| 45 |
def nano2gdecryptdfu(data):
|
45 |
def nano2gdecryptdfu(data):
|
| 46 |
embios = libembios.Embios()
|
46 |
embios = libembios.Embios()
|
| 47 |
embios.write(0x08000000, data)
|
47 |
embios.write(0x08000000, data)
|
| 48 |
embios.timeout = 20000
|
48 |
embios.lib.dev.timeout = 20000
|
| 49 |
embios.aesdecrypt(0x08000000, len(data), 1)
|
49 |
embios.aesdecrypt(0x08000000, len(data), 1)
|
| 50 |
return embios.read(0x08000800, len(data) - 0x800)
|
50 |
return embios.read(0x08000800, len(data) - 0x800)
|
| 51 |
|
51 |
|
| 52 |
|
52 |
|
| 53 |
def nano2gcryptfirmware(data):
|
53 |
def nano2gcryptfirmware(data):
|
| 54 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
54 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
| 55 |
header = "\0\0\0\0\0x02\0\0\0\0x01\0\0\0\0x40\0\0\0\0\0\0\0" + struct.pack("<I", len(data))
|
55 |
header = "\0\0\0\0\0x02\0\0\0\0x01\0\0\0\0x40\0\0\0\0\0\0\0" + struct.pack("<I", len(data))
|
| 56 |
embios = libembios.Embios()
|
56 |
embios = libembios.Embios()
|
| 57 |
embios.write(0x08000000, header.ljust(0x800, "\0") + data)
|
57 |
embios.write(0x08000000, header.ljust(0x800, "\0") + data)
|
| 58 |
embios.timeout = 20000
|
58 |
embios.lib.dev.timeout = 20000
|
| 59 |
embios.hmac_sha1(0x08000800, len(data), 0x0800001c)
|
59 |
embios.hmac_sha1(0x08000800, len(data), 0x0800001c)
|
| 60 |
embios.hmac_sha1(0x08000000, 0x200, 0x080001d4)
|
60 |
embios.hmac_sha1(0x08000000, 0x200, 0x080001d4)
|
| 61 |
embios.aesencrypt(0x08000800, len(data), 1)
|
61 |
embios.aesencrypt(0x08000800, len(data), 1)
|
| 62 |
return embios.read(0x08000000, len(data) + 0x800)
|
62 |
return embios.read(0x08000000, len(data) + 0x800)
|
| 63 |
|
63 |
|
| 64 |
|
64 |
|
| 65 |
def nano2gdecryptfirmware(data):
|
65 |
def nano2gdecryptfirmware(data):
|
| 66 |
embios = libembios.Embios()
|
66 |
embios = libembios.Embios()
|
| 67 |
embios.write(0x08000000, data)
|
67 |
embios.write(0x08000000, data)
|
| 68 |
embios.timeout = 20000
|
68 |
embios.lib.dev.timeout = 20000
|
| 69 |
embios.aesdecrypt(0x08000800, len(data) - 0x800, 1)
|
69 |
embios.aesdecrypt(0x08000800, len(data) - 0x800, 1)
|
| 70 |
return embios.read(0x08000800, len(data) - 0x800)
|
70 |
return embios.read(0x08000800, len(data) - 0x800)
|
| 71 |
|
71 |
|
| 72 |
|
72 |
|
| 73 |
def nano2gcryptdfufile(infile, outfile):
|
73 |
def nano2gcryptdfufile(infile, outfile):
|