-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProdinfoRestore.te
More file actions
236 lines (195 loc) · 5.95 KB
/
ProdinfoRestore.te
File metadata and controls
236 lines (195 loc) · 5.95 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#REQUIRE KEYS
#REQUIRE SD
#REQUIRE VER 4.0.0
version = "1.3"
Title = {
color(0x4040FF)
println("Prodinfo Restore", version, "\n\n")
color(0xFFFFFF)
}
BackupProd = {
mkdir("sd:/tegraexplorer")
mkdir("sd:/tegraexplorer/prodinfo")
backup_path = "sd:/tegraexplorer/prodinfo"
if (fsexists(combinepath(backup_path, "PRODINFO_BAK.bin"))){
color(0xFFFF00)
println("WARNING")
color(0xFFFFFF)
println("A backup already exist in ", backup_path)
println("Do you want to overwrite it? \n")
res = menu(["No", "Yes"], 0)
if (res == 0){
exit()
}
clear()
Title()
}
println("Backing up PRODINFO...")
if (mmcread(combinepath(backup_path, "PRODINFO_BAK.bin"), "PRODINFO")){
color(0xFF0000)
println("ERROR! Failed to back up PRODINFO! \n\nPress any key to exit!")
pause()
exit()
}
color(0x00FF00)
println("Successfully backed up PRODINFO to", combinepath(backup_path, "PRODINFO_BAK.bin"), "\n")
color(0XFFFFFF)
println("Press any key to continue...")
pause()
}
RestoreProdBin = {
if (ptype == 0){
color(0xFF0000)
println("ERROR! \nSize is not correct! \nFailed to restore from", path2restore, "\n\nPress any key to exit!")
pause()
exit()
}
if (ptype == 1){
println("Restoring full PRODINFO from", path2restore, "...")
if (mmcwrite(path2restore, "PRODINFO")){
color(0xFF0000)
println("ERROR! Failed to restore PRODINFO! \n\nPress any key to exit!")
pause()
exit()
}
}
if (ptype == 2){
println("Restoring partial PRODINFO from", path2restore, "...")
if (mmcwrite(path2restore, "PRODINFO")){
color(0xFF0000)
println("ERROR! Failed to restore PRODINFO! \n\nPress any key to exit!")
pause()
exit()
}
}
color(0x00FF00)
println("Successfully restored PRODINFO!")
println()
color(0xFFFF00)
print("Press any key to exit...")
pause()
exit()
}
CheckProdinfoPath = {
println("From what do you want to restore?\n")
res = menu(["AMS automatic backup", "sd:/prodinfo.bin"], 0, [0x00FFFF, 0x00FFFF])
clear()
Title()
if (res == 0){
SetAMSPath()
if (ams_backupnotfound){
color(0xFF0000)
println("ERROR! Failed to find a non blanked AMS automatic backup! \n\nPress any key to exit!")
pause()
exit()
}
}
if (res == 1){
SetProdinfoBinPath()
}
file2restore = readfile(path2restore)
}
SetAMSPath = {
ams_autobackupdir = readdir("sd:/atmosphere/automatic_backups")
ams_backupnotfound = 1
println("Checking for AMS automatic backup...")
if (ams_autobackupdir.result){
color(0xFF0000)
println("ERROR! Failed to open sd:/atmosphere/automatic_backups \n\nPress any key to exit!")
pause()
exit()
}
prodinfoSTR = "PRODINFO"
nullSTR = "0000000000"
ams_autobackupdir.files.foreach("binfilename"){
if (binfilename.len() == 27){
splitted = binfilename.split("_")
if (splitted.len() == 2){
if ((splitted[0].bytes().find(nullSTR.bytes()) == -1) && (splitted[1].bytes().find(prodinfoSTR.bytes()) != -1)){
color(0x00FF00)
println("Found AMS Automatic Backup:", binfilename)
println()
color(0xFFFFFF)
ams_backupnotfound = 0
path2restore = combinepath("sd:/atmosphere/automatic_backups", binfilename)
break()
}
}
}
}
}
SetProdinfoBinPath = {
println("Checking for prodinfo.bin backup...")
if (fsexists("sd:/prodinfo.bin").not()){
color(0xFF0000)
println("ERROR! Failed to find a file named prodinfo.bin! \nBe sure to place your prodinfo.bin on the root of the sd! \n\nPress any key to exit!")
pause()
exit()
}
color(0x00FF00)
println("Found prodinfo.bin")
color(0xFFFFFF)
path2restore = "sd:/prodinfo.bin"
}
CheckProdinfoSize = {
ptype = 0
if (file2restore.len() == 4176896){
ptype = 1
println("Using full PRODINFO backup!")
CheckCAL0()
println()
}
if (file2restore.len() == 32768){
ptype = 2
println("Using partial PRODINFO backup!")
CheckCAL0()
println()
}
}
CheckCAL0 = {
CAL0 = ["BYTE[]", 0x43, 0x41, 0x4C, 0x30]
head = file2restore.slice(0x0, 0x4).project()
if ((head == CAL0).not()){
color(0xFF0000)
println("ERROR!", path2restore, "is not valid! Found", head.bytestostr(), "instead of", CAL0.bytestostr())
println("\nPress any key to exit!")
pause()
exit()
}
}
Title()
if (emu()){
println("EmuMMC enabled! \nWhere do you want to restore your PRODINFO partition?\n")
res = menu(["Cancel", "SysMMC", "EmuMMC"], 0, [0xFF00FF, 0x00FFFF, 0x00FFFF])
}.else(){
println("EmuMMC disabled! \nRestoring on sysMMC?")
res = menu(["No", "Yes"],0)
}
if (res == 0){
exit()
}
if (res == 1){
mmcread = emmcread
mmcwrite = emmcwrite
}
if (res == 2){
mmcread = emummcread
mmcwrite = emummcwrite
}
CheckProdinfoPath()
CheckProdinfoSize()
BackupProd()
clear()
Title()
color(0xFF0000)
println("WARNING")
color(0xFFFF00)
println("Proceeding will OVERWRITE your current PRODINFO! \nIf you don't know what you are doing, please exit immediatly!\n")
color(0xFF0000)
println("Press Power to proceed. Press any other key to exit.")
if (pause().power.not()){
exit()
}
clear()
Title()
RestoreProdBin()