Index: emcore/trunk/tools/ipodcrypt.py |
— | — | @@ -27,18 +27,18 @@ |
28 | 28 |
|
29 | 29 |
|
30 | 30 | def usage():
|
31 | | - print ""
|
32 | | - print "Please provide a command and (if needed) parameters as command line arguments"
|
33 | | - print ""
|
34 | | - print "Available commands:"
|
35 | | - print " s5l8701-cryptdfu <infile> <outfile>"
|
36 | | - print " s5l8701-decryptdfu <infile> <outfile>"
|
37 | | - print " s5l8701-cryptfirmware <infile> <outfile>"
|
38 | | - print " s5l8701-decryptfirmware <infile> <outfile>"
|
39 | | - print " s5l8702-cryptnor <infile> <outfile>"
|
40 | | - print " s5l8702-decryptnor <infile> <outfile>"
|
41 | | - print " s5l8702-genpwnage <infile> <outfile>"
|
42 | | - print " s5l8720-genpwnage <infile> <outfile>"
|
| 31 | + print("")
|
| 32 | + print("Please provide a command and (if needed) parameters as command line arguments")
|
| 33 | + print("")
|
| 34 | + print("Available commands:")
|
| 35 | + print(" s5l8701-cryptdfu <infile> <outfile>")
|
| 36 | + print(" s5l8701-decryptdfu <infile> <outfile>")
|
| 37 | + print(" s5l8701-cryptfirmware <infile> <outfile>")
|
| 38 | + print(" s5l8701-decryptfirmware <infile> <outfile>")
|
| 39 | + print(" s5l8702-cryptnor <infile> <outfile>")
|
| 40 | + print(" s5l8702-decryptnor <infile> <outfile>")
|
| 41 | + print(" s5l8702-genpwnage <infile> <outfile>")
|
| 42 | + print(" s5l8720-genpwnage <infile> <outfile>")
|
43 | 43 | exit(2)
|
44 | 44 |
|
45 | 45 |
|
Index: emcore/trunk/tools/libipodcrypto.py |
— | — | @@ -33,11 +33,11 @@ |
34 | 34 |
|
35 | 35 |
|
36 | 36 | def s5l8701cryptdfu(data):
|
37 | | - data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
38 | | - header = "87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
| 37 | + data = data.ljust((len(data) + 0x3f) & ~0x3f, b"\0")
|
| 38 | + header = b"87011.0\0\0\x08\0\0" + struct.pack("<I", len(data))
|
39 | 39 | emcore = libemcore.Emcore()
|
40 | 40 | addr = emcore.memalign(0x10, len(data) + 0x800)
|
41 | | - emcore.write(addr, header.ljust(0x800, "\0") + data)
|
| 41 | + emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
42 | 42 | emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x10)
|
43 | 43 | emcore.hmac_sha1(addr, 0x40, addr + 0x40)
|
44 | 44 | emcore.aesencrypt(addr, len(data) + 0x800, 1)
|
— | — | @@ -58,11 +58,11 @@ |
59 | 59 |
|
60 | 60 |
|
61 | 61 | def s5l8701cryptfirmware(data):
|
62 | | - data = data.ljust((len(data) + 0x3f) & ~0x3f, "\0")
|
63 | | - 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 | + data = data.ljust((len(data) + 0x3f) & ~0x3f, b"\0")
|
| 63 | + 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))
|
64 | 64 | emcore = libemcore.Emcore()
|
65 | 65 | addr = emcore.memalign(0x10, len(data) + 0x800)
|
66 | | - emcore.write(addr, header.ljust(0x800, "\0") + data)
|
| 66 | + emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
67 | 67 | emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x1c)
|
68 | 68 | emcore.hmac_sha1(addr, 0x200, addr + 0x1d4)
|
69 | 69 | emcore.aesencrypt(addr + 0x800, len(data), 1)
|
— | — | @@ -82,11 +82,11 @@ |
83 | 83 |
|
84 | 84 |
|
85 | 85 | def s5l8702cryptnor(data):
|
86 | | - data = data.ljust((len(data) + 0xf) & ~0xf, "\0")
|
87 | | - header = "87021.0\x01\0\0\0\0" + struct.pack("<I", len(data)) + hashlib.sha1(data).digest()[:0x10]
|
| 86 | + data = data.ljust((len(data) + 0xf) & ~0xf, b"\0")
|
| 87 | + header = b"87021.0\x01\0\0\0\0" + struct.pack("<I", len(data)) + hashlib.sha1(data).digest()[:0x10]
|
88 | 88 | emcore = libemcore.Emcore()
|
89 | 89 | addr = emcore.memalign(0x10, len(data))
|
90 | | - emcore.write(addr, header.ljust(0x800, "\0") + data)
|
| 90 | + emcore.write(addr, header.ljust(0x800, b"\0") + data)
|
91 | 91 | emcore.aesencrypt(addr + 0x800, len(data), 2)
|
92 | 92 | emcore.aesencrypt(addr + 0x10, 0x10, 2)
|
93 | 93 | emcore.write(addr + 0x40, hashlib.sha1(emcore.read(addr, 0x40)).digest()[:0x10])
|
— | — | @@ -108,13 +108,13 @@ |
109 | 109 |
|
110 | 110 | def s5l8702genpwnage(data):
|
111 | 111 | cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8702pwnage.cer", "rb").read()
|
112 | | - data = data.ljust(max(0x840, (len(data) + 0xf) & ~0xf), "\0")
|
113 | | - 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 | + data = data.ljust(max(0x840, (len(data) + 0xf) & ~0xf), b"\0")
|
| 113 | + 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")
|
114 | 114 | emcore = libemcore.Emcore()
|
115 | 115 | addr = emcore.memalign(0x10, len(data))
|
116 | 116 | emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
117 | 117 | emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
118 | | - data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, "\0")
|
| 118 | + data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, b"\0")
|
119 | 119 | emcore.free(addr)
|
120 | 120 | return data
|
121 | 121 |
|
— | — | @@ -121,13 +121,13 @@ |
122 | 122 |
|
123 | 123 | def s5l8720genpwnage(data):
|
124 | 124 | cert = open(os.path.dirname(__file__) + "/libipodcrypto/s5l8720pwnage.cer", "rb").read()
|
125 | | - data = data.ljust(max(0x640, (len(data) + 0xf) & ~0xf), "\0")
|
126 | | - 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 | + data = data.ljust(max(0x640, (len(data) + 0xf) & ~0xf), b"\0")
|
| 126 | + 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")
|
127 | 127 | emcore = libemcore.Emcore()
|
128 | 128 | addr = emcore.memalign(0x10, len(data))
|
129 | 129 | emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
|
130 | 130 | emcore.aesencrypt(addr + 0x40, 0x10, 1)
|
131 | | - data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, "\0")
|
| 131 | + data = emcore.read(addr, 0x50) + data + cert.ljust((len(cert) + 0xf) & ~0xf, b"\0")
|
132 | 132 | emcore.free(addr)
|
133 | 133 | return data
|
134 | 134 |
|