-
Notifications
You must be signed in to change notification settings - Fork 1
/
Batch CIA 3DS Decryptor Redux.bat
405 lines (396 loc) · 16.1 KB
/
Batch CIA 3DS Decryptor Redux.bat
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
@echo off
color 1F
mode con cols=64 lines=25
setlocal EnableDelayedExpansion
set ScriptVersion=v1.0.4
set state=0
set permanentstate=0
set count3DS=0
set countCIA=0
set convertToCCI=0
set rootdir=%cd%
set content=bin^\CTR_Content.txt
set logfile=log^\programlog.txt
title Batch CIA 3DS Decryptor Redux %ScriptVersion%
if not exist "log" mkdir log
echo Batch CIA 3DS Decryptor Redux>%logfile%
echo [i] = Information>>%logfile%
echo [^^!] = Error>>%logfile%
echo [#] = Debug>>%logfile%
echo [^^] = Warning>>%logfile%
echo.>>%logfile%
echo Batch CIA 3DS Decryptor Redux %ScriptVersion%>>%logfile%
echo %date% - %time:~0,-3% = [i] Script started>>%logfile%
if not "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto unsupported
if exist "*.cia" (
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo CIA files were found. Do you want to convert them to CCI^?
echo Please be aware that this doesn^'t work with DLCs or updates.
echo.
echo This applies to all CIA files that have been found.
echo.
echo [Y] Yes
echo [N] No
echo.
set /p question=Enter:
if /i "!question!"=="y" goto EnableCCI
goto DisableCCI
)
:EnableCCI
set convertToCCI=1
:DisableCCI
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo Decrypting...
echo.
set "validchars=-_abcdefghijklmnopqrstuvwxyz1234567890. "
for %%b in (*) do (
set "newname="
set "oldname=%%b"
call :validate
if /i "%%b" neq "!newname!" ren "%%~sb" "!newname!"
)
goto continueScript
:validate
if not defined oldname goto :eof
set "c1=%oldname:~0,1%"
set "oldname=%oldname:~1%"
if "!validchars:%c1%=!" neq "%validchars%" set "newname=%newname%%c1%"
goto validate
:continueScript
for %%a in (bin\*.ncch) do (
echo %date% - %time:~0,-3% = [i] Found unused NCCH file. Start deleting.>>%logfile%
del "%%a"
)
for %%x in (*.3ds) do set /a count3DS+=1
if not "%count3DS%"=="0" (
if "%count3DS%"=="1" echo %date% - %time:~0,-3% = [i] Found %count3DS% CIA file. Start decrypting.>>%logfile%
if %count3DS% GTR 1 echo %date% - %time:~0,-3% = [i] Found %count3DS% CIA files. Start decrypting.>>%logfile%
)
for %%a in (*.3ds) do (
set CUTN=%%~na
if /i x!CUTN!==x!CUTN:decrypted=! (
echo | bin\decrypt.exe "%%a%" >nul
set state=1
set ARG=
for %%f in ("bin\!CUTN!.*.ncch") do (
if %%f==bin\!CUTN!.Main.ncch set i=0
if %%f==bin\!CUTN!.Manual.ncch set i=1
if %%f==bin\!CUTN!.DownloadPlay.ncch set i=2
if %%f==bin\!CUTN!.Partition4.ncch set i=3
if %%f==bin\!CUTN!.Partition5.ncch set i=4
if %%f==bin\!CUTN!.Partition6.ncch set i=5
if %%f==bin\!CUTN!.N3DSUpdateData.ncch set i=6
if %%f==bin\!CUTN!.UpdateData.ncch set i=7
set ARG=!ARG! -i "%%f:!i!:!i!"
)
bin\makerom.exe -f cci -ignoresign -target p -o "%rootdir%\!CUTN!-decrypted.3ds"!ARG! >nul 2>nul
if not exist "!CUTN!-decrypted.3ds" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for !CUTN!.3ds>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for !CUTN!.3ds>>%logfile%
set permanentstate=1
)
)
for %%a in (bin\*.ncch) do del /s "%%a" >nul 2>&1
)
for %%x in (*.cia) do set /a countCIA+=1
if not "%countCIA%"=="0" (
if "%countCIA%"=="1" echo %date% - %time:~0,-3% = [i] Found %countCIA% CIA file. Start decrypting.>>%logfile%
if %countCIA% GTR 1 echo %date% - %time:~0,-3% = [i] Found %countCIA% CIA files. Start decrypting.>>%logfile%
)
for %%a in (*.cia) do (
set CUTN=%%~na
if /i x!CUTN!==x!CUTN:decrypted=! (
if exist "!content!" del /s "!content!" >nul 2>&1
set CryptoKey=1
set CIAType=0
bin\ctrtool.exe --seeddb=bin\seeddb.bin "%%a" >!content!
set FILE=!content!
for /f "skip=1 delims=" %%x in ('findstr "TitleId" !content!') do set "TitleId=%%x"
for /f "delims=" %%y in ('findstr /c:"Crypto Key" !content!') do set "CryptoKey=%%y"
for /f "tokens=4 delims= " %%z in ('findstr "TitleVersion" !content!') do set "TitleVersion=%%z"
set TitleId=!TitleId:~18!
set TitleVersion=!TitleVersion:~1,-1!
echo "!CryptoKey!" | findstr "Secure" >nul 2>nul
if "!errorlevel!"=="0" (
set /a i=0
set ARG=
REM eShop Gamecard Applications
findstr /i /pr "00040000" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
set state=1
echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" [!TitleId! v!TitleVersion!] is a eShop or Gamecard title>>%logfile%
set CIAType=1
echo | bin\decrypt.exe "%%a" >nul 2>nul
for %%f in ("bin\!CUTN!.*.ncch") do (
set ARG=!ARG! -i "%%f:!i!:!i!"
set /a i+=1
)
echo %date% - %time:~0,-3% = [i] Calling makerom for eShop or Gamecard CIA [!TitleId!]>>%logfile%
bin\makerom.exe -f cia -ignoresign -target p -o "%rootdir%\!CUTN! Game-decrypted.cia"!ARG! -ver !TitleVersion! >nul 2>nul
if not exist "%rootdir%\!CUTN! Game-decrypted.cia" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
if "!convertToCCI!"=="0" set permanentstate=1
)
)
REM System Applications
findstr /i /pr "00040010 0004001b 00040030 0004009b 000400db 00040130 00040138" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
set state=1
call :checkCIASysFile
set CIAType=1
echo | bin\decrypt.exe "%%a" >nul 2>nul
for %%f in ("bin\!CUTN!.*.ncch") do (
set ARG=!ARG! -i "%%f:!i!:!i!"
set /a i+=1
)
echo %date% - %time:~0,-3% = [i] Calling makerom for system title CIA [!TitleId!]>>%logfile%
bin\makerom.exe -f cia -ignoresign -target p -o "%rootdir%\!CUTN! System-decrypted.cia"!ARG! -ver !TitleVersion! >nul 2>nul
if not exist "%rootdir%\!CUTN! System-decrypted.cia" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
if "!convertToCCI!"=="0" set permanentstate=1
)
)
REM Demos
findstr /i /pr "00040002" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
set state=1
echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" [!TitleId! v!TitleVersion!] is a demo title>>%logfile%
set CIAType=1
echo | bin\decrypt.exe "%%a" >nul 2>nul
for %%f in ("bin\!CUTN!.*.ncch") do (
set ARG=!ARG! -i "%%f:!i!:!i!"
set /a i+=1
)
echo %date% - %time:~0,-3% = [i] Calling makerom for demo CIA [!TitleId!]>>%logfile%
bin\makerom.exe -f cia -ignoresign -target p -o "%rootdir%\!CUTN! Demo-decrypted.cia"!ARG! -ver !TitleVersion! >nul 2>nul
if not exist "%rootdir%\!CUTN! Demo-decrypted.cia" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
if "!convertToCCI!"=="0" set permanentstate=1
)
)
REM Patches and DLCs
findstr /i /pr "0004000e 0004008c" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
set state=1
echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" [!TitleId! v!TitleVersion!] is a update or DLC title>>%logfile%
set CIAType=1
set TEXT="ContentId:"
set /a X=0
echo | bin\decrypt.exe "%%a" >nul 2>nul
for %%f in ("bin\!CUTN!.*.ncch") do (
set ARG=!ARG! -i "%%f:!i!:!i!"
set /a i+=1
)
for /f "delims=" %%d in ('findstr /c:!TEXT! !FILE!') do (
set CONLINE=%%d
call :EXF
)
REM Patches
findstr /i /pr "0004000e" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
echo %date% - %time:~0,-3% = [i] Calling makerom for update CIA [!TitleId! v!TitleVersion!]>>%logfile%
bin\makerom.exe -f cia -ignoresign -target p -o "!CUTN! Patch-decrypted.cia"!ARG! -ver !TitleVersion! >nul 2>nul
if not exist "%rootdir%\!CUTN! Patch-decrypted.cia" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
)
)
REM DLCs
findstr /i /pr "0004008c" !FILE! | findstr /C:"Title id" >nul 2>nul
if not errorlevel 1 (
echo %date% - %time:~0,-3% = [i] Calling makerom for DLC CIA [!TitleId! v!TitleVersion!]>>%logfile%
bin\makerom.exe -f cia -dlc -ignoresign -target p -o "!CUTN! DLC-decrypted.cia"!ARG! -ver !TitleVersion! >nul 2>nul
if not exist "%rootdir%\!CUTN! DLC-decrypted.cia" (
echo %date% - %time:~0,-3% = [^^!] Decrypting failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Decrypting succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
)
)
)
if "!convertToCCI!"=="1" (
for %%a in (*-decrypted.cia) do (
set CUTN=%%~na
bin\makerom.exe -ciatocci "!CUTN!.cia" -o "!CUTN!.cci" >nul 2>nul
del /F /Q "%rootdir%\!CUTN!.cia" >nul 2>nul
if not exist "%rootdir%\!CUTN!.cci" (
echo %date% - %time:~0,-3% = [^^!] Converting to CCI failed for [!TitleId! v!TitleVersion!]>>%logfile%
set state=0
) else (
echo %date% - %time:~0,-3% = [i] Converting to CCI succeeded for [!TitleId! v!TitleVersion!]>>%logfile%
set permanentstate=1
)
)
)
if "!CIATYPE!"=="0" echo %date% - %time:~0,-3% = [^^!] Could not determine CIA type [!CUTN!.cia]>>%logfile%
) else (
echo "!CryptoKey!" | findstr "None" >nul 2>nul
if "!errorlevel!"=="0" (
echo %date% - %time:~0,-3% = [^^!] CIA file "!CUTN!.cia" [!TitleId! v!TitleVersion!] is already decrypted>>%logfile%
set state=0
) else (
set /p ctrtool_data=<!content!
echo "!ctrtool_data!" | findstr "ERROR" >nul 2>nul
if "!errorlevel!"=="0" echo %date% - %time:~0,-3% = [^^!] CIA is invalid [!CUTN!.cia]>>%logfile%
set state=0
)
)
REM TWL titles
findstr /i /pr "00048005 0004800f 00048004" !FILE! >nul 2>nul
if "!errorlevel!"=="0" call :checkCIATWLFile
)
for %%a in (bin\*.ncch) do del /s "%%a" >nul 2>&1
)
if exist "!content!" del /s "!content!" >nul 2>&1
if "%state%"=="0" if "%permanentstate%"=="0" goto noFilesDecrypted
if "%state%"=="0" if "%permanentstate%"=="1" goto someFilesDecrypted
echo %date% - %time:~0,-3% = [i] Decrypting process succeeded>>%logfile%
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo Decrypting finished^^!
echo.
echo Please review "%logfile%" for more details.
echo.
echo Press any key to exit.
echo.
pause
echo %date% - %time:~0,-3% = [i] Script execution ended>>%logfile%
exit
:EXF
if !X! geq !i! (
if exist bin\!CUTN!.!i!.ncch (
set CONLINE=!CONLINE:~24,8!
call :GETX !CONLINE!, ID
set ARG=!ARG! -i "bin\!CUTN!.!i!.ncch:!i!:!ID!"
set /a i+=1
) else (
set /a i+=1
goto EXF
)
)
exit/B
:GETX v dec
set /a dec=0x%~1
if [%~2] neq [] set %~2=%dec%
exit/b
:noFilesDecrypted
echo %date% - %time:~0,-3% = [i] No files where decrypted>>%logfile%
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo No files where decrypted^^!
echo.
echo Please review "%logfile%" for more details.
echo.
echo Press any key to exit.
echo.
echo %date% - %time:~0,-3% = [i] Script execution ended>>%logfile%
pause
endlocal
exit
:someFilesDecrypted
echo %date% - %time:~0,-3% = [i] Some files where decrypted>>%logfile%
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo Some files where decrypted^^!
echo.
echo Please review "%logfile%" for more details.
echo.
echo Press any key to exit.
echo.
echo %date% - %time:~0,-3% = [i] Script execution ended>>%logfile%
pause
endlocal
exit
:unsupported
echo %date% - %time:~0,-3% = [^!] 32-bit operating systems are not supported>>%logfile%
cls
echo.
echo ############################################################
echo ### ###
echo ### Batch CIA 3DS Decryptor Redux %ScriptVersion% ###
echo ### ###
echo ############################################################
echo.
echo.
echo.
echo.
echo This script only supports 64-bit operating systems^!
echo Script execution halted^!
echo.
echo Press any key to exit.
echo.
echo %date% - %time:~0,-3% = [i] Script execution ended>>%logfile%
pause
exit
:checkCIASysFile
findstr /i /pr "00040010" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a system application>>%logfile%
findstr /i /pr "0004001b 000400db" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a system data archive>>%logfile%
findstr /i /pr "00040030" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a system applet>>%logfile%
findstr /i /pr "0004009b" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a shared data archive>>%logfile%
findstr /i /pr "00040130" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a system module>>%logfile%
findstr /i /pr "00040138" !FILE! | findstr /C:"Title id" >nul 2>nul
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CIA file "!CUTN!.cia" is a system firmware>>%logfile%
exit /b
:checkCIATWLFile
findstr /i /pr "00048005" !FILE! | findstr /C:"TitleId"
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CTRTool does not support TWL titles "!CUTN!.cia" [!TitleId! v!TitleVersion!] [System Application]>>%logfile%
findstr /i /pr "0004800f" !FILE! | findstr /C:"TitleId"
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CTRTool does not support TWL titles "!CUTN!.cia" [!TitleId! v!TitleVersion!] [System Data Archive]>>%logfile%
findstr /i /pr "00048004" !FILE! | findstr /C:"TitleId"
if "%errorlevel%"=="0" echo %date% - %time:~0,-3% = [i] CTRTool does not support TWL titles "!CUTN!.cia" [!TitleId! v!TitleVersion!] [3DS DSiWare Ports]>>%logfile%
exit /b