-
Notifications
You must be signed in to change notification settings - Fork 3
/
restore-firm0firm1.py
executable file
·49 lines (36 loc) · 1.47 KB
/
restore-firm0firm1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import os
import sys
import time
def doexit(msg, errcode=0):
print(msg)
input('Press Enter to continue...')
sys.exit(errcode)
def doexit(msg, errcode=0):
print(msg)
input('Press Enter to continue...')
sys.exit(errcode)
if not os.path.isfile('NAND-patched.bin'):
doexit('NAND-patched.bin not found.', errcode=1)
if not os.path.isfile('firm0firm1.bak'):
doexit('firm0firm1.bak was not found.', errcode=1)
if os.path.isfile('NAND-unpatched.bin'):
doexit('NAND-unpatched.bin was found.\n'
'In order to prevent writing a good backup with a bad one, the '
'install has stopped. Please move or delete the old file if you '
'are sure you want to continue.', errcode=1)
readsize = 0x100000 # must be divisible by 0x3AF00000 and 0x4D800000
print('Trying to open NAND-patched.bin...')
with open('NAND-patched.bin', 'rb+') as nand:
print('Restoring firm0firm1.back.')
nand.seek(0xB130000)
with open('firm0firm1.bak', 'rb') as f:
firm_final = f.read(0x800000)
start_time = time.time()
for curr in range(0x800000 // readsize):
print('Writing {:06X} ({:>5.1f}%)'.format((curr + 1) * readsize,
(((curr + 1) * readsize) / 0x800000) * 100), end='\r')
nand.write(bytes(firm_final[curr * readsize:(curr + 1) * readsize]))
os.rename('NAND-patched.bin', 'NAND-unpatched.bin')
doexit('\nWriting finished in {:>.2f} seconds.'.format(
time.time() - start_time))