/
auto-cli.bat
758 lines (713 loc) · 30.8 KB
/
auto-cli.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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
@echo off
setlocal enabledelayedexpansion
echo The source APKs are downloaded from discord cdn. They originate from apkmirror.
echo The JDK in use is also downloaded from discord cdn. It originates from zulu JDK.
echo Every file's integrity can be checked using checksums.
echo If you wish to abort, close this window.
echo.
pause
set batVersion=3.8
FOR /F "tokens=2 delims=:." %%C IN ('chcp') DO (
if %%C equ 708 (
chcp 65001 > nul
) else if %%C equ 720 (
chcp 65001 > nul
) else if %%C equ 862 (
chcp 65001 > nul
) else if %%C equ 864 (
chcp 65001 > nul
) else if %%C equ 1255 (
chcp 65001 > nul
) else if %%C equ 1256 (
chcp 65001 > nul
)
)
REM set script location to working dir
pushd "%~dp0"
REM check if powershell is present
set PS_check=0
:PScheck
where powershell >nul 2>nul
if not !errorlevel! equ 0 (
if !PS_check!==1 (
echo [91m FATAL: Powershell is missing. [0m
echo [91m Powershell was not found in PATH nor its default location. [0m
echo [91m The script cannot function without powershell being accessible. [0m
echo.
pause > nul 2> nul
EXIT
)
echo.
echo [93m Warning: Powershell is missing from your PATH variable. Attemping to fix for this session. [0m
set "PATH=!PATH!;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"
set PS_check=1
goto :PScheck
)
REM check if current directory contains non-ASCII characters
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "'%cd%' -match '[^\x00-\x7F]'"`) DO (
if "%%F" == "True" (
echo.
echo [91m ATTENTION [0m
echo [91m You are executing this script in a path that contains non-ASCII characters [0m
echo [91m Doing so will cause patching to fail in a later stage. [0m
echo [91m Please move the script to a different location and run it again. [0m
echo.
echo [91m Your current path: %0 [0m
pause > nul 2> nul
EXIT
)
)
REM check if major version is 3 at minimum
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "$Host.Version.Major"`) DO (
if not %%F geq 3 (
echo.
echo [91m ATTENTION [0m
echo [91m Your PowerShell, Version %%F is too old to run this script. [0m
echo [91m Please use the Windows Management Framework to update. [0m
echo [93m https://www.microsoft.com/en-us/download/details.aspx?id=54616 [0m
pause > nul 2> nul
EXIT
)
)
REM check if PATH is greater than 2048 to avoid unexpected behaviour
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "$env:PATH.Length"`) DO (
if %%F geq 2048 (
echo.
echo [93m Warning: Your current PATH variable is over 2047 characters long. Current value: %%F [0m
echo [93m If you encounter the script failing, this can be the cause. No immediate actions required. [0m
)
)
REM pre-escape usernames with single quotes
set "localappdata=%localappdata%"
set "PSlocalData=%localappdata%"
set "PSlocalData=!PSlocalData:'=''!"
REM create needed folders
mkdir "%localappdata%\revanced-cli\" > nul 2> nul
mkdir "%localappdata%\revanced-cli\keystore" > nul 2> nul
mkdir "%localappdata%\revanced-cli\apk_backups" > nul 2> nul
REM legacy function to preserve keystore from old versions
copy /y C:\revanced-cli-keystore\*.keystore "%localappdata%\revanced-cli\keystore" > nul 2> nul
REM refresh and enter output dir
rmdir /s /q revanced-cli-output > nul 2> nul
mkdir revanced-cli-output > nul 2> nul
cd revanced-cli-output
REM create link to install dir
mklink /D "backups and more" "%localappdata%\revanced-cli\" > nul 2> nul
echo.
set "MODE=main"
:modeChange
REM refresh input json
del "%localappdata%\revanced-cli\input.json" > nul 2> nul
powershell -NoProfile -NonInteractive -Command "Invoke-WebRequest 'https://raw.githubusercontent.com/taku-nm/auto-cli/!MODE!/input3.json' -OutFile '!PSlocalData!\revanced-cli\input.json' -Headers @{'Cache-Control'='no-cache'}"
if exist "%localappdata%\revanced-cli\input.json" (
set "inputJson=!PSlocalData!\revanced-cli\input.json"
) else (
echo [93m Input.json download failed... Attempting to circumvent geo-blocking... [0m
powershell -NoProfile -NonInteractive -Command "Invoke-WebRequest 'http://user737.bplaced.net/downloads/revanced/input3.json' -OutFile '!PSlocalData!\revanced-cli\input.json' -Headers @{'Cache-Control'='no-cache'}"
if exist "%localappdata%\revanced-cli\input.json" (
set "inputJson=!PSlocalData!\revanced-cli\input.json"
) else (
echo.
echo [91m FATAL [0m
echo [91m input.json could not be loaded... are you offline? [0m
echo Contact taku on ReVanced discord or open an issue on GitHub.
echo Include a screenshot of the entire terminal.
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
)
)
REM script version check
for /f %%i in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).batVersion"') do ( set "jsonBatVersion=%%i" )
if /i '%batVersion%' == '%jsonBatVersion%' (
echo [92m Script up-to-date! Version %batVersion% [0m
) else (
echo [93m This script is likely outdated. Check https://github.com/taku-nm/auto-cli/releases for new releases. [0m
echo [93m Your version: %batVersion% [0m
echo [93m Available version: %jsonBatVersion% [0m
)
REM wget setup
if exist "%localappdata%\revanced-cli\revanced-wget\" (
echo [92m Wget found! [0m
) else (
echo [93m No Wget found... Downloading... [0m
mkdir "%localappdata%\revanced-cli\revanced-wget\" > nul 2> nul
powershell -NoProfile -NonInteractive -Command "Invoke-WebRequest 'https://eternallybored.org/misc/wget/1.21.4/64/wget.exe' -OutFile '!PSlocalData!\revanced-cli\revanced-wget\wget.exe'"
)
set "WGET=%localappdata%\revanced-cli\revanced-wget\wget.exe"
set "WGET_ps=!PSlocalData!\revanced-cli\revanced-wget\wget.exe"
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "Get-FileHash -Algorithm SHA256 '%WGET_ps%' | Select-Object -ExpandProperty Hash"`) DO ( SET WGET_h=%%F )
if /i "%WGET_h%" == "6136e66e41acd14c409c2d3eb10d48a32febaba04267303d0460ed3bee746cc5 " (
echo [92m Wget integrity validated! [0m
) else (
echo [93m Wget integrity invalid... [0m
rmdir /s /q "%localappdata%\revanced-cli\revanced-wget\" > nul 2> nul
echo [93m Wget could not be validated... All downloads will likely revert to cURL or invoke webrequest... [0m
)
REM curl setup
if exist "%localappdata%\revanced-cli\revanced-curl\" (
echo [92m cURL found! [0m
) else (
echo [93m No cURL found... Downloading... [0m
powershell -NoProfile -NonInteractive -Command "Invoke-WebRequest 'https://curl.se/windows/dl-8.2.1_11/curl-8.2.1_11-win64-mingw.zip' -OutFile '!PSlocalData!\revanced-cli\curl.zip'"
powershell -NoProfile -NonInteractive -Command "Expand-Archive '!PSlocalData!\revanced-cli\curl.zip' -DestinationPath '!PSlocalData!\revanced-cli\'"
mkdir "%localappdata%\revanced-cli\revanced-curl\" > nul 2> nul
copy /y "%localappdata%\revanced-cli\curl-8.2.1_11-win64-mingw\bin\*.*" "%localappdata%\revanced-cli\revanced-curl\*.*" > nul 2> nul
rmdir /s /q "%localappdata%\revanced-cli\curl-8.2.1_11-win64-mingw\" > nul 2> nul
del "%localappdata%\revanced-cli\curl.zip"
)
set "CURL=%localappdata%\revanced-cli\revanced-curl\curl.exe"
set "CURL_ps=!PSlocalData!\revanced-cli\revanced-curl\curl.exe"
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "Get-FileHash -Algorithm SHA256 '%CURL_ps%' | Select-Object -ExpandProperty Hash"`) DO ( SET CURL_h=%%F )
if /i "%CURL_h%" == "7B27734E0515F8937B7195ED952BBBC6309EE1EEF584DAE293751018599290D1 " (
echo [92m cURL integrity validated! [0m
) else (
echo [93m cURL integrity invalid... [0m
rmdir /s /q "%localappdata%\revanced-cli\revanced-curl\" > nul 2> nul
if exist "%windir%\System32\curl.exe" (
echo [92m Windows cURL found... Attempting to fall back on that. [0m
set "CURL=%windir%\System32\curl.exe"
) else (
echo [93m cURL could not be validated... All downloads will likely revert to Invoke WebRequest... [0m
)
)
REM JDK setup
:jdk_integ_failed
if exist "%localappdata%\revanced-cli\revanced-jdk\" (
echo [92m JDK found! [0m
) else (
echo [93m No JDK found... Downloading... [0m
echo.
call :fetchToolsJson "%inputJson%" JDK
call :downloadWithFallback "%localappdata%\revanced-cli\!fname!" "!link!" "!hash!"
powershell -NoProfile -NonInteractive -Command "Expand-Archive '!PSlocalData!\revanced-cli\!fname!' -DestinationPath '!PSlocalData!\revanced-cli'"
del "%localappdata%\revanced-cli\!fname!"
)
set "JDK=%localappdata%\revanced-cli\revanced-jdk\bin\java.exe"
set "KEYTOOL=%localappdata%\revanced-cli\revanced-jdk\bin\keytool.exe"
set "JDK_ps=!PSlocalData!\revanced-cli\revanced-jdk\bin\java.exe"
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "Get-FileHash -Algorithm SHA256 '%JDK_ps%' | Select-Object -ExpandProperty Hash"`) DO ( SET JDK_h=%%F )
if /i "%JDK_h%" == "6BB6621B7783778184D62D1D9C2D761F361622DD993B0563441AF2364C8A720B " (
echo [92m JDK integrity validated! [0m
) else (
echo [93m JDK integrity invalid... Something must've become corrupted during the download [0m
echo Deleting JDK and retrying...
rmdir /s /q "%localappdata%\revanced-cli\revanced-jdk\" > nul 2> nul
goto jdk_integ_failed
)
REM check and create keystore password
if exist "%localappdata%\revanced-cli\keystore\keystore_password_do_not_share.txt" (
set /p KEY_PW=< "%localappdata%\revanced-cli\keystore\keystore_password_do_not_share.txt"
) else (
set KEY_PW=%random%%random%%random%%random%
echo !KEY_PW!>"%localappdata%\revanced-cli\keystore\keystore_password_do_not_share.txt"
)
REM check for and transform old keystores
if exist "%localappdata%\revanced-cli\keystore\*.keystore" (
echo [93m Old keystores found [0m
call :fetchToolsJson "%inputJson%" BCS
call :downloadWithFallback "%localappdata%\revanced-cli\!fname!" "!link!" "!hash!"
for %%i in ("%localappdata%\revanced-cli\keystore\*.keystore") DO (
if "%%i"=="%localappdata%\revanced-cli\keystore\PATCHED_Sync.keystore" (
move "%%i" "%%~dpi%%~ni.no_pw_keystore" > nul 2> nul
) else if "%%i"=="%localappdata%\revanced-cli\keystore\PATCHED_Relay.keystore" (
move "%%i" "%%~dpi%%~ni.no_pw_keystore" > nul 2> nul
) else (
"%KEYTOOL%" -storepasswd -storepass ReVanced -new !KEY_PW! -storetype bks -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "%localappdata%\revanced-cli\!fname!" -keystore "%%i" -alias alias
move "%%i" "%%~dpi%%~ni.secure_keystore" > nul 2> nul
echo [92m Keystore %%~ni transformed [0m
)
)
)
REM tools setup (cli, patches, integrations)
if exist "%localappdata%\revanced-cli\revanced-tools\" (
for %%i in (cli, patches, integrations) do (
call :checkTool %%i
set "%%i=%localappdata%\revanced-cli\revanced-tools\!fname!" > nul 2> nul
)
if !update! == 1 echo [93m Your ReVanced Tools are out of date or damaged... Re-downloading... [0m && goto update_jump
if !update! == 0 goto start
) else (
echo [93m No ReVanced Tools found... Downloading... [0m
:update_jump
mkdir "%localappdata%\revanced-cli\revanced-tools\" > nul 2> nul
call :getTools "cli, patches, integrations"
)
:start
set "KEYSTORE=%localappdata%\revanced-cli\keystore"
set "k=0"
echo.
if "!MODE!" == "dev" (
echo [93m You are currently in developer mode. Do you know what you are doing? [0m
)
echo.
REM generate app list
for /f "tokens=*" %%i in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.apps.fname"') do (
set /a "k=k+1"
for /f "tokens=*" %%j in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.apps[!k!].dname"') do (
echo [0m !k!. %%j
)
)
echo.
echo A. Custom
if "!MODE!" == "main" echo B. Developer Mode
if "!MODE!" == "dev" echo B. Normal Mode
echo.
set choice=
set /p choice=Type the number or letter to fetch the corresponding app and hit enter.
if not defined choice goto start
if %choice% geq 1 if %choice% leq %k% ( goto app_download )
if '%choice%'=='A' goto custom
if '%choice%'=='B' if "!MODE!" == "main" set "MODE=dev" && goto modeChange
if '%choice%'=='B' if "!MODE!" == "dev" set "MODE=main" && goto modeChange
echo "%choice%" is not valid, try again
echo.
goto start
:app_download
REM fetch config for app and download
call :fetchAppJson "%inputJson%" %choice%
echo Downloading !fname!
call :downloadWithFallback "!fname!" "!link!" "!hash!"
REM account for special cases such as tool modifiers and third party reddit clients
if defined tool_mod echo [93m Your selected app requires specific tools... They will now be loaded [0m && call :getTools "cli, patches, integrations" !tool_mod!
if defined uri call :redditOptions
REM patch app
call :fetchAppJson "%inputJson%" %choice%
echo Patching !fname!
if defined cmd_mod call :modifiedPatch && goto end
call :patchApp !fname!
goto end
:custom
if exist ..\revanced-cli-input\ (
echo [93m The revanced-cli-input folder already exists at the location you're running this script in. [0m
) else (
mkdir ..\revanced-cli-input\ > nul 2> nul
echo [92m The folder revanced-cli-input has been created at the location you're running this script in. [0m
)
echo Would you like to provide your own APK to patch or download one of the above and customize the rest?
set /p c_choice=Type the number to fetch the corresponding app from above and hit enter. Leave empty to provide your own APK.
if not defined c_choice goto custom_missing
if %c_choice% geq 1 if %c_choice% leq %k% (
call :fetchAppJson "%inputJson%" %c_choice%
echo Downloading !fname!
call :downloadWithFallback "!fname!" "!link!" "!hash!"
move /y "!fname!" "..\revanced-cli-input\input.apk" > nul 2> nul
echo [92m input.apk placed in revanced-cli-input [0m
)
:custom_missing
echo [93m Ensure that the ONLY files in revanced-cli-input are the app, cli, patches and integrations that you would want to use. [0m
echo The app [93mMUST[0m be called 'input.apk'
echo The CLI [93mMUST[0m be called 'cli.jar'
echo The patches [93mMUST[0m be called 'patches.jar'.
echo The integrations [93mMUST[0m be called 'integrations.apk'
echo [93m CLI, Patches and integrations are optional. Not providing them will cause the script to use official ReVanced tools. [0m
echo Once you're ready, press any key to continue...
pause > nul 2> nul
echo.
if exist ..\revanced-cli-input\input.apk (
echo [92m input.apk found! [0m
) else (
echo [91m input.apk missing! [0m
echo.
goto custom_missing
)
if exist ..\revanced-cli-input\cli.jar (
echo [92m cli.jar found! [0m
set CLI=..\revanced-cli-input\cli.jar
) else (
echo No cli.jar found... Continuing using official ReVanced CLI
)
if exist ..\revanced-cli-input\patches.jar (
echo [92m patches.jar found! [0m
set PATCHES=..\revanced-cli-input\patches.jar
) else (
echo No patches.jar found... Continuing using official ReVanced patches
)
if exist ..\revanced-cli-input\integrations.apk (
echo [92m integrations.apk found! [0m
set INTEGRATIONS=..\revanced-cli-input\integrations.apk
) else (
echo No integrations.apk found... Continuing using official ReVanced integrations
)
echo.
echo [92m All files loaded! [0m
if exist ..\revanced-cli-input\patches.jar (
echo You've selected a custom patch source. At the next step you will see all available patches.
echo.
pause
"%JDK%" -jar "%CLI%" list-patches -dopv "%PATCHES%"
) else (
echo You are using official ReVanced patches. [93m Please look up the patch names and capitalizations at https://revanced.app/patches. [0m
)
echo.
echo You now have the opportunity to include and exclude patches using the following syntax:[93m Including the quotes[0m
echo [92m -i "name of a patch to include" -e "name of a patch to exclude" -i "another patch to include" [0m
echo Type your options now. Leave empty to apply default patches. Hit enter once you're done.
echo.
set /p SELECTION=
del "%localappdata%\revanced-cli\options.json" > nul 2> nul
"%JDK%" -jar "%CLI%" options -o "%PATCHES%" > nul 2> nul
if exist .\options.json (
move /y "options.json" "%localappdata%\revanced-cli\" > nul 2> nul
echo An options.json as been created.
echo Pressing any key will open notepad for you to customize your install.
echo Don't be confused at default values that dont apply to the app you are patching.
echo If the patch isn't selected, it will not use those values.
echo Close notepad once you're ready. Don't forget to save within notepad.
pause > nul 2> nul
START "" /wait notepad "%localappdata%\revanced-cli\options.json"
set "optionsJson=%localappdata%\revanced-cli\options.json"
set "OPTIONS=--options="!optionsJson!""
) else (
echo.
echo [93mThe options.json could not be created.[0m Likely because the chosen CLI and patches are not compatible with each other.
echo If you want, you can press any key to continue despite this.
pause > nul 2> nul
set OPTIONS=
)
:filename
echo.
echo Final question: What app are you patching? This will be your output file.[93m No spaces. No file extensions.[0m
echo Giving it the same name as the last time you patched ensures that the same keystore is used, which allows for updates without needing to uninstall first.
echo Unlike previous versions, [93mDO NOT[0m add the PATCHED_ in the beginning.
echo [92m Example: WhatsApp [0m
echo.
set /p OUTPUT=
if '%OUTPUT%'=='' echo [91m Nu-uh! Provide a name. [0m && goto filename
echo.
"%JDK%" -jar "%CLI%" patch "..\revanced-cli-input\input.apk" -b "%PATCHES%" -m "%INTEGRATIONS%" %SELECTION% %OPTIONS% --keystore "%KEYSTORE%\PATCHED_%OUTPUT%.secure_keystore" --alias="alias" --keystore-password="%KEY_PW%" --keystore-entry-password="ReVanced" -o PATCHED_%OUTPUT%.apk
goto end
:end
rmdir /s /q C:\revanced-cli-keystore\ > nul 2> nul
rmdir /s /q PATCHED_!keyString!-resource-cache\ > nul 2> nul
del PATCHED_!keyString!-options.json > nul 2> nul
del !fname! > nul 2> nul
if exist PATCHED_*.apk (
copy /y "PATCHED_*.apk" "%localappdata%\revanced-cli\apk_backups" > nul 2> nul
ren "%localappdata%\revanced-cli\apk_backups\PATCHED_*.apk" "PATCHED_* %time:~0,2%%time:~3,2%-%DATE:/=%.backup" > nul 2> nul
echo.
echo [92m DONE! [0m
echo [92m Transfer the PATCHED app to your phone and open to the apk to install it [0m
if '%choice%' == 'A' ( echo [92m Location: %CD%\PATCHED_!OUTPUT!.apk [0m ) else ( echo [92m Location: %CD%\PATCHED_!fname! [0m )
if /i "!extra!!" == "true" call :extras
echo.
echo bat Version %batVersion%
echo.
echo Backups, keystore and supporting files can be found in AppData\Local\revanced-cli
echo To use the backup files, rename them to .apk instead of .backup
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
) else (
echo.
echo [91m FATAL [0m
echo [91m Something must've gone wrong during patching. Contact taku on ReVanced discord or open an issue on GitHub. [0m
echo.
echo Include a screenshot of the entire terminal.
echo Debug info:
if '%choice%' == 'A' (
echo.
echo Since you've used the custom option, it is likely that your chosen CLI version and patches don't work with each other.
echo [93mMake sure to include the versions of what you've been using with your help request.[0m
echo CLI: %CLI%
echo Patches: %PATCHES%
echo Integrations: %INTEGRATIONS%
echo Selection: %SELECTION%
echo Options: %OPTIONS%
echo Output: %OUTPUT%
echo c_Choice: %c_choice%
)
echo.
echo bat Version %batVersion%
echo Choice: %choice%
echo Appdata/Local: %localappdata%
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
)
REM functions
:fetchToolsJson
set fname=
set link=
set hash=
set tpc=0
for /f %%i in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.%~3tools.%~2.fname, (Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.%~3tools.%~2.link, (Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.%~3tools.%~2.hash"') do (
if !tpc!==0 (
set "fname=%%i"
) else if !tpc!==1 (
set "link=%%i"
) else if !tpc!==2 (
set "hash=%%i"
)
set /a "tpc=!tpc!+1"
)
if not defined fname goto fetchToolsFail
if "!MODE!" == "dev" (
echo Filename !fname!
echo Link !link!
echo Hash !hash!
)
EXIT /B 0
:fetchToolsFail
echo.
echo [91m FATAL [0m
echo [91m Something has gone wrong when attempting to fetch tool info. Contact taku on ReVanced discord or open an issue on GitHub. [0m
echo Include a screenshot of the entire terminal.
echo bat Version %batVersion%
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
:fetchAppJson
set "JSON=%~1"
set "index=%~2"
set fname=
set link=
set hash=
set patch_sel=
set uri=
set tool_mod=
set cmd_mod=
set extra=
set apc=0
for /f "tokens=* " %%i in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].fname, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].link, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].hash, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].patches, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].uri, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].toolMod, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].cmdMod, (Get-Content -Raw '!JSON!' | ConvertFrom-Json).downloads.apps[!index!].extras[0].enabled"') do (
if !apc!==0 (
set "fname=%%i"
) else if !apc!==1 (
set "link=%%i"
) else if !apc!==2 (
set "hash=%%i"
) else if !apc!==3 (
set "patch_sel=%%i"
) else if !apc!==4 (
set "uri=%%i"
) else if !apc!==5 (
set "tool_mod=%%i"
) else if !apc!==6 (
set "cmd_mod=%%i"
) else if !apc!==7 (
set "extra=%%i"
)
set /a "apc=!apc!+1"
)
if not defined fname goto fetchAppsFail
if "!MODE!" == "dev" (
echo Filename !fname!
echo Link !link!
echo Hash !hash!
echo Patch selection !patch_sel!
echo URI !uri!
echo Tool modifier !tool_mod!
echo Command modifier !cmd_mod!
echo Extra enabled? !extra!
)
EXIT /B 0
:fetchAppsFail
echo.
echo [91m FATAL [0m
echo [91m Something has gone wrong when attempting to fetch app info. Contact taku on ReVanced discord or open an issue on GitHub. [0m
echo Include a screenshot of the entire terminal.
echo bat Version %batVersion%
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
:fetchExtraJson
set fname=
set link=
set hash=
set epc=0
for /f %%i in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.extras.%~2.fname, (Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.extras.%~2.link, (Get-Content -Raw '%~1' | ConvertFrom-Json).downloads.extras.%~2.hash"') do (
if !epc!==0 (
set "fname=%%i"
) else if !epc!==1 (
set "link=%%i"
) else if !epc!==2 (
set "hash=%%i"
)
set /a "epc=!epc!+1"
)
if not defined fname goto fetchExtraFail
if "!MODE!" == "dev" (
echo Filename !fname!
echo Link !link!
echo Hash !hash!
)
EXIT /B 0
:fetchExtraFail
echo.
echo [91m FATAL [0m
echo [91m Something has gone wrong when attempting to fetch extras info. Contact taku on ReVanced discord or open an issue on GitHub. [0m
echo Include a screenshot of the entire terminal.
echo bat Version %batVersion%
echo.
echo Pressing any key will close this window.
pause > nul 2> nul
EXIT
:downloadWithFallback
set fallback=0
"!WGET!" -q --show-progress -O "%~1" "%~2"
set ram_h=
set "ram_path=%~1"
set "ram_path=!ram_path:'=''!"
:fallback
if '!fallback!'=='1' ( "!CURL!" -k -L "%~2" --output "%~1" )
if '!fallback!'=='2' ( powershell -NoProfile -NonInteractive -Command "Invoke-WebRequest '%~2' -OutFile '!ram_path!'" )
if "!MODE!" == "dev" (
echo ram_path !ram_path!
echo passed_value_1 "%~1"
echo passed_value_2 "%~2"
)
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "Get-FileHash -Algorithm SHA256 '!ram_path!' | Select-Object -ExpandProperty Hash"`) DO ( SET ram_h=%%F )
if /i "%ram_h%" == "%~3 " (
echo [92m Integrity validated %~1 [0m
) else (
if '!fallback!'=='0' (
echo [93m File integrity damaged... Something must've become corrupted during the download or wget had some issue... [0m
echo Falling back to cURL...
set /a "fallback=!fallback!+1"
goto fallback
)
if '!fallback!'=='1' (
echo [93m File integrity still damaged... Something must've become corrupted during the download or cURL had some issue... [0m
echo Falling back to Invoke Webrequest...
set /a "fallback=!fallback!+1"
goto fallback
)
if '!fallback!'=='2' (
echo [91m FATAL : Download or integrity check for %~1 failed completely! [0m
goto downloadFail
)
)
EXIT /B 0
:downloadFail
echo.
echo [91m A download or file integrity check failed... Is the Discord CDN down? Is your internet interrupted? [0m
echo Other causes might include a very outdated script... Check https://github.com/taku-nm/auto-cli for new releases.
echo Contact taku on ReVanced discord or open an issue on GitHub.
echo Include a screenshot of the entire terminal.
echo.
echo Pressing any key will end this script.
pause > nul 2> nul
EXIT
:checkTool
call :fetchToolsJson "%inputJson%" %~1
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -NoProfile -NonInteractive -Command "Get-FileHash -Algorithm SHA256 '!PSlocalData!\revanced-cli\revanced-tools\!fname!' | Select-Object -ExpandProperty Hash"`) DO ( SET ram_h=%%F )
if /i "%ram_h%" == "!hash! " (
echo [92m !fname! validated [0m
) else (
set update=1
)
EXIT /B 0
:patchApp
if "!MODE!" == "dev" (
echo Patch current Filename !fname!
echo JDK "%JDK%"
echo CLI "%CLI%"
echo Patches "%PATCHES%"
echo Integrations "%INTEGRATIONS%"
echo Patch selection !patch_sel!
echo Options !OPTIONS!
echo Keystore Path "%KEYSTORE%"
echo Keystore Password "%KEY_PW%"
)
set "inputString=%~1"
set "keyString=!inputString:.apk=!"
if "!inputString!"=="Relay.apk" (
if exist "%KEYSTORE%\PATCHED_Relay.no_pw_keystore" (
"%JDK%" -jar "%CLI%" patch %~1 -b "%PATCHES%" -m "%INTEGRATIONS%" !patch_sel! !OPTIONS! --keystore "%KEYSTORE%\PATCHED_Relay.no_pw_keystore" -o PATCHED_%~1
) else goto standard_patch
) else if "!inputString!"=="Sync.apk" (
if exist "%KEYSTORE%\PATCHED_Sync.no_pw_keystore" (
"%JDK%" -jar "%CLI%" patch %~1 -b "%PATCHES%" -m "%INTEGRATIONS%" !patch_sel! !OPTIONS! --keystore "%KEYSTORE%\PATCHED_Sync.no_pw_keystore" -o PATCHED_%~1
) else goto standard_patch
) else (
:standard_patch
"%JDK%" -jar "%CLI%" patch %~1 -b "%PATCHES%" -m "%INTEGRATIONS%" !patch_sel! !OPTIONS! --keystore "%KEYSTORE%\PATCHED_!keyString!.secure_keystore" --alias="alias" --keystore-password="%KEY_PW%" --keystore-entry-password="ReVanced" -o PATCHED_%~1
)
EXIT /B 0
:redditOptions
echo.
echo You're patching a third-party reddit client. This requires you to create a client ID.
echo [93m You can leave "description" and "about url" empty. Make sure to select "installed app". [0m
echo For "redirect uri" enter the following:
echo [92m !uri! [0m
echo Pressing any key will open your browser for you to create a reddit app.
pause > nul 2> nul
start https://www.reddit.com/prefs/apps
echo [93m Paste your client ID now. [0m It is written below "installed app". Do NOT place a space at the end. Press enter once you are done.
echo.
set /p client_id=
if not defined client_id echo [91m Provide a client ID [0m && goto redditOptions
del "%localappdata%\revanced-cli\options.json" > nul 2> nul
"%JDK%" -jar "%CLI%" options -o "%PATCHES%" > nul 2> nul
move /y "options.json" "%localappdata%\revanced-cli\" > nul 2> nul
set "optionsJson=%localappdata%\revanced-cli\options.json"
for /f "usebackq delims=" %%a in ("%optionsJson%") do (
set "jsonContent=!jsonContent!%%a"
)
set "NEW_jsonContent=!jsonContent:"Spoof client", "options" : [ { "key" : "client-id", "value" : null="Spoof client", "options" : [ { "key" : "client-id", "value" : "%client_id%"!"
echo !NEW_jsonContent! > "%optionsJson%"
set "OPTIONS=--options="!optionsJson!""
EXIT /B 0
:extras
set /a "m=0"
echo.
echo Additional apps (Skip if already installed):
echo.
for /f "tokens=*" %%j in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.apps[!index!].extras.ename"') do (
set /a "m=m+1"
for /f "tokens=*" %%r in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.apps[!index!].extras[!m!].required"') do (
if /i "%%r" == "true" set "status=[93m(Required)[0m"
if /i "%%r" == "false" set "status=(Optional)"
)
for /f "tokens=*" %%n in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.extras.%%j.dname"') do (
echo [0m !m!. %%n !status!
)
)
echo.
echo Download any of them now?
echo [93m Format your answer like this: 1, 2 [0m etc...
echo.
set eC=
set /p eC=[93m Leave empty to skip. [0m Press enter to confirm.
if not defined eC EXIT /B 0
set "eC_lastChar=!eC:~-1!"
if "!eC_lastChar!"=="," echo [91m Invalid formatting. Remove the comma at the end. [0m && goto :extras
if "!eC_lastChar!"==" " echo [91m Invalid formatting. Remove the space at the end. [0m && goto :extras
if !eC_lastChar! geq 1 if !eC_lastChar! leq 9 (
for /f "tokens=*" %%a in ("!eC!") do (
for %%b in (%%a) do (
if %%b geq 1 if %%b leq !m! (
for /f "tokens=*" %%q in ('powershell -NoProfile -NonInteractive -Command "(Get-Content -Raw '%inputJson%' | ConvertFrom-Json).downloads.apps[!index!].extras[%%b].ename"') do (
call :fetchExtraJson "%inputJson%" "%%q"
call :downloadWithFallback "!fname!" "!link!" "!hash!"
)
) else (
echo Selected App Nr. %%b is invalid. Skipping.
)
)
)
) else (
echo [91m Invalid answer. [0m
goto :extras
)
EXIT /B 0
:getTools
for /f "tokens=*" %%a in ("%~1") do (
for %%b in (%%a) do (
call :fetchToolsJson "%inputJson%" %%b %~2
call :downloadWithFallback "%localappdata%\revanced-cli\revanced-tools\!fname!" !link! !hash!
set "%%b=%localappdata%\revanced-cli\revanced-tools\!fname!"
)
)
EXIT /B 0
:modifiedPatch
set "inputString=!fname!"
set "keyString=!inputString:.apk=!"
set "cmd_mod=!cmd_mod:keyString=%keyString%!"
"%JDK%" -jar !cmd_mod!
EXIT /B 0