| Line 31... |
Line 31... |
| 31 |
from libemcore import Error
|
31 |
from libemcore import Error
|
| 32 |
import libemcoredata
|
32 |
import libemcoredata
|
| 33 |
|
33 |
|
| 34 |
|
34 |
|
| 35 |
def s5l8701cryptdfu(data):
|
35 |
def s5l8701cryptdfu(data):
|
| 36 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
36 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, b"\0")
|
| 37 |
header = "87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
37 |
header = b"87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
| 38 |
emcore = libemcore.Emcore()
|
38 |
emcore = libemcore.Emcore()
|
| 39 |
addr = emcore.memalign(0x10, len(data) + 0x800)
|
39 |
addr = emcore.memalign(0x10, len(data) + 0x800)
|
| 40 |
emcore.write(addr, header.ljust(0x800, "\0") + data)
|
40 |
emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
| 41 |
emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x10)
|
41 |
emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x10)
|
| 42 |
emcore.hmac_sha1(addr, 0x40, addr + 0x40)
|
42 |
emcore.hmac_sha1(addr, 0x40, addr + 0x40)
|
| 43 |
emcore.aesencrypt(addr, len(data) + 0x800, 1)
|
43 |
emcore.aesencrypt(addr, len(data) + 0x800, 1)
|
| 44 |
data = emcore.read(addr, len(data) + 0x800)
|
44 |
data = emcore.read(addr, len(data) + 0x800)
|
| 45 |
emcore.free(addr)
|
45 |
emcore.free(addr)
|
| Line 56... |
Line 56... |
| 56 |
emcore.free(addr)
|
56 |
emcore.free(addr)
|
| 57 |
return data
|
57 |
return data
|
| 58 |
|
58 |
|
| 59 |
|
59 |
|
| 60 |
def s5l8701cryptfirmware(data):
|
60 |
def s5l8701cryptfirmware(data):
|
| 61 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
61 |
data = data.ljust((len(data) + 0x3f) & ~0x3f, b"\0")
|
| 62 |
header = "\0\0\0\0\x02\0\0\0\x01\0\0\0\x40\0\0\0\0\0\0\0" + struct.pack("<I", len(data))
|
62 |
header = b"\0\0\0\0\x02\0\0\0\x01\0\0\0\x40\0\0\0\0\0\0\0" + struct.pack("<I", len(data))
|
| 63 |
emcore = libemcore.Emcore()
|
63 |
emcore = libemcore.Emcore()
|
| 64 |
addr = emcore.memalign(0x10, len(data) + 0x800)
|
64 |
addr = emcore.memalign(0x10, len(data) + 0x800)
|
| 65 |
emcore.write(addr, header.ljust(0x800, "\0") + data)
|
65 |
emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
| 66 |
emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x1c)
|
66 |
emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x1c)
|
| 67 |
emcore.hmac_sha1(addr, 0x200, addr + 0x1d4)
|
67 |
emcore.hmac_sha1(addr, 0x200, addr + 0x1d4)
|
| 68 |
emcore.aesencrypt(addr + 0x800, len(data), 1)
|
68 |
emcore.aesencrypt(addr + 0x800, len(data), 1)
|
| 69 |
data = emcore.read(addr, len(data) + 0x800)
|
69 |
data = emcore.read(addr, len(data) + 0x800)
|
| 70 |
emcore.free(addr)
|
70 |
emcore.free(addr)
|
| Line 80... |
Line 80... |
| 80 |
emcore.free(addr)
|
80 |
emcore.free(addr)
|
| 81 |
return data
|
81 |
return data
|
| 82 |
|
82 |
|
| 83 |
|
83 |
|
| 84 |
def s5l8702cryptnor(data):
|
84 |
def s5l8702cryptnor(data):
|
| 85 |
data = data.ljust((len(data) + 0xf) & ~0xf, "\0")
|
85 |
data = data.ljust((len(data) + 0xf) & ~0xf, b"\0")
|
| 86 |
header = "87021.0\x01\0\0\0\0" + struct.pack("<I", len(data)) + hashlib.sha1(data).digest()[:0x10]
|
86 |
header = b"87021.0\x01\0\0\0\0" + struct.pack("<I", len(data)) + hashlib.sha1(data).digest()[:0x10]
|
| 87 |
emcore = libemcore.Emcore()
|
87 |
emcore = libemcore.Emcore()
|
| 88 |
addr = emcore.memalign(0x10, len(data))
|
88 |
addr = emcore.memalign(0x10, len(data))
|
| 89 |
emcore.write(addr, header.ljust(0x800, "\0") + data)
|
89 |
emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
| 90 |
emcore.aesencrypt(addr + 0x800, len(data), 2)
|
90 |
emcore.aesencrypt(addr + 0x800, len(data), 2)
|
| 91 |
emcore.aesencrypt(addr + 0x10, 0x10, 2)
|
91 |
emcore.aesencrypt(addr + 0x10, 0x10, 2)
|
| 92 |
emcore.write(addr + 0x40, hashlib.sha1(emcore.read(addr, 0x40)).digest()[:0x10])
|
92 |
emcore.write(addr + 0x40, hashlib.sha1(emcore.read(addr, 0x40)).digest()[:0x10])
|
| 93 |
emcore.aesencrypt(addr + 0x40, 0x10, 2)
|
93 |
emcore.aesencrypt(addr + 0x40, 0x10, 2)
|
| 94 |
data = emcore.read(addr, len(data) + 0x800)
|
94 |
data = emcore.read(addr, len(data) + 0x800)
|
| Line 106... |
Line 106... |
| 106 |
return data
|
106 |
return data
|
| 107 |
|
107 |
|
| 108 |
|
108 |
|
| 109 |
def s5l8702genpwnage(data):
|
109 |
def s5l8702genpwnage(data):
|
| 110 |
cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8702pwnage.cer", "rb").read()
|
110 |
cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8702pwnage.cer", "rb").read()
|
| 111 |
data = data.ljust(max(0x840, (len(data) + 0xf) & ~0xf), "\0")
|
111 |
data = data.ljust(max(0x840, (len(data) + 0xf) & ~0xf), b"\0")
|
| 112 |
header = ("87021.0\x03\0\0\0\0" + struct.pack("<IIII", len(data) - 0x830, len(data) - 0x4f6, len(data) - 0x7b0, 0x2ba)).ljust(0x40, "\0")
|
112 |
header = (b"87021.0\x03\0\0\0\0" + struct.pack("<IIII", len(data) - 0x830, len(data) - 0x4f6, len(data) - 0x7b0, 0x2ba)).ljust(0x40, b"\0")
|
| 113 |
emcore = libemcore.Emcore()
|
113 |
emcore = libemcore.Emcore()
|
| 114 |
addr = emcore.memalign(0x10, len(data))
|
114 |
addr = emcore.memalign(0x10, len(data))
|
| 115 |
emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
115 |
emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
| 116 |
emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
116 |
emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
| 117 |
data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, "\0")
|
117 |
data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, b"\0")
|
| 118 |
emcore.free(addr)
|
118 |
emcore.free(addr)
|
| 119 |
return data
|
119 |
return data
|
| 120 |
|
120 |
|
| 121 |
|
121 |
|
| 122 |
def s5l8720genpwnage(data):
|
122 |
def s5l8720genpwnage(data):
|
| 123 |
cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8720pwnage.cer", "rb").read()
|
123 |
cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8720pwnage.cer", "rb").read()
|
| 124 |
data = data.ljust(max(0x640, (len(data) + 0xf) & ~0xf), "\0")
|
124 |
data = data.ljust(max(0x640, (len(data) + 0xf) & ~0xf), b"\0")
|
| 125 |
header = ("87202.0\x03\0\0\0\0" + struct.pack("<IIII", len(data) - 0x630, len(data) - 0x2f2, len(data) - 0x5b0, 0x2be)).ljust(0x40, "\0")
|
125 |
header = (b"87202.0\x03\0\0\0\0" + struct.pack("<IIII", len(data) - 0x630, len(data) - 0x2f2, len(data) - 0x5b0, 0x2be)).ljust(0x40, b"\0")
|
| 126 |
emcore = libemcore.Emcore()
|
126 |
emcore = libemcore.Emcore()
|
| 127 |
addr = emcore.memalign(0x10, len(data))
|
127 |
addr = emcore.memalign(0x10, len(data))
|
| 128 |
emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
128 |
emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
| 129 |
emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
129 |
emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
| 130 |
data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, "\0")
|
130 |
data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, b"\0")
|
| 131 |
emcore.free(addr)
|
131 |
emcore.free(addr)
|
| 132 |
return data
|
132 |
return data
|
| 133 |
|
133 |
|
| 134 |
|
134 |
|
| 135 |
def s5l8701cryptdfufile(infile, outfile):
|
135 |
def s5l8701cryptdfufile(infile, outfile):
|