freemyipod r788 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r787‎ | r788 | r789 >
Date:17:32, 18 November 2011
Author:theseven
Status:new
Tags:
Comment:
(lib)ipodcrypt.py: Make this work in Python 3
Modified paths:
  • /emcore/trunk/tools/ipodcrypt.py (modified) (history)
  • /emcore/trunk/tools/libipodcrypto.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/ipodcrypt.py
@@ -27,18 +27,18 @@
2828
2929
3030 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>")
4343 exit(2)
4444
4545
Index: emcore/trunk/tools/libipodcrypto.py
@@ -33,11 +33,11 @@
3434
3535
3636 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))
3939 emcore = libemcore.Emcore()
4040 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)
4242 emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x10)
4343 emcore.hmac_sha1(addr, 0x40, addr + 0x40)
4444 emcore.aesencrypt(addr, len(data) + 0x800, 1)
@@ -58,11 +58,11 @@
5959
6060
6161 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))
6464 emcore = libemcore.Emcore()
6565 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)
6767 emcore.hmac_sha1(addr + 0x800, len(data), addr + 0x1c)
6868 emcore.hmac_sha1(addr, 0x200, addr + 0x1d4)
6969 emcore.aesencrypt(addr + 0x800, len(data), 1)
@@ -82,11 +82,11 @@
8383
8484
8585 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]
8888 emcore = libemcore.Emcore()
8989 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)
9191 emcore.aesencrypt(addr + 0x800, len(data), 2)
9292 emcore.aesencrypt(addr + 0x10, 0x10, 2)
9393 emcore.write(addr + 0x40, hashlib.sha1(emcore.read(addr, 0x40)).digest()[:0x10])
@@ -108,13 +108,13 @@
109109
110110 def s5l8702genpwnage(data):
111111 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")
114114 emcore = libemcore.Emcore()
115115 addr = emcore.memalign(0x10, len(data))
116116 emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
117117 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")
119119 emcore.free(addr)
120120 return data
121121
@@ -121,13 +121,13 @@
122122
123123 def s5l8720genpwnage(data):
124124 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")
127127 emcore = libemcore.Emcore()
128128 addr = emcore.memalign(0x10, len(data))
129129 emcore.write(addr, header + hashlib.sha1(header).digest()[:0x10])
130130 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")
132132 emcore.free(addr)
133133 return data
134134