Subversion Repositories freemyipod

Rev

Rev 186 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 186 Rev 272
Line 28... Line 28...
28
import libembios
28
import libembios
29
from libembios import Error
29
from libembios import Error
30
import libembiosdata
30
import libembiosdata
31
 
31
 
32
 
32
 
33
def nano2gcryptdfu(data):
33
def s5l8701cryptdfu(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.lib.dev.timeout = 20000
38
    embios.lib.dev.timeout = 20000
Line 40... Line 40...
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 s5l8701decryptdfu(data):
46
    embios = libembios.Embios()
46
    embios = libembios.Embios()
47
    embios.write(0x08000000, data)
47
    embios.write(0x08000000, data)
48
    embios.lib.dev.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 s5l8701cryptfirmware(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\x02\0\0\0\x01\0\0\0\x40\0\0\0\0\0\0\0" + struct.pack("<I", len(data))
55
    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))
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.lib.dev.timeout = 20000
58
    embios.lib.dev.timeout = 20000
Line 60... Line 60...
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 s5l8701decryptfirmware(data):
66
    embios = libembios.Embios()
66
    embios = libembios.Embios()
67
    embios.write(0x08000000, data)
67
    embios.write(0x08000000, data)
68
    embios.lib.dev.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 s5l8701cryptdfufile(infile, outfile):
74
    print(outfile)
74
    print(outfile)
75
    infile = open(infile, "rb")
75
    infile = open(infile, "rb")
76
    outfile = open(outfile, "wb")
76
    outfile = open(outfile, "wb")
77
    outfile.write(nano2gcryptdfu(infile.read()))
77
    outfile.write(s5l8701cryptdfu(infile.read()))
78
    infile.close()
78
    infile.close()
79
    outfile.close()
79
    outfile.close()
80
 
80
 
81
 
81
 
82
def nano2gdecryptdfufile(infile, outfile):
82
def s5l8701decryptdfufile(infile, outfile):
83
    infile = open(infile, "rb")
83
    infile = open(infile, "rb")
84
    outfile = open(outfile, "wb")
84
    outfile = open(outfile, "wb")
85
    outfile.write(nano2gdecryptdfu(infile.read()))
85
    outfile.write(s5l8701decryptdfu(infile.read()))
86
    infile.close()
86
    infile.close()
87
    outfile.close()
87
    outfile.close()
88
 
88
 
89
 
89
 
90
def nano2gcryptfirmwarefile(infile, outfile):
90
def s5l8701cryptfirmwarefile(infile, outfile):
91
    infile = open(infile, "rb")
91
    infile = open(infile, "rb")
92
    outfile = open(outfile, "wb")
92
    outfile = open(outfile, "wb")
93
    outfile.write(nano2gcryptfirmware(infile.read()))
93
    outfile.write(s5l8701cryptfirmware(infile.read()))
94
    infile.close()
94
    infile.close()
95
    outfile.close()
95
    outfile.close()
96
 
96
 
97
 
97
 
98
def nano2gdecryptfirmwarefile(infile, outfile):
98
def s5l8701decryptfirmwarefile(infile, outfile):
99
    infile = open(infile, "rb")
99
    infile = open(infile, "rb")
100
    outfile = open(outfile, "wb")
100
    outfile = open(outfile, "wb")
101
    outfile.write(nano2gdecryptfirmware(infile.read()))
101
    outfile.write(s5l8701decryptfirmware(infile.read()))
102
    infile.close()
102
    infile.close()
103
    outfile.close()
103
    outfile.close()