-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathiKeyHelper.bat
More file actions
1562 lines (1187 loc) · 48.5 KB
/
iKeyHelper.bat
File metadata and controls
1562 lines (1187 loc) · 48.5 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
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
:: iKeyHelper
:: Copyright (C) 2012 Callum Jones
:: See attached license
:: if you get all the tools, pop them in resources\tools\
@ECHO OFF
title iKeyHelper
::------------------------------------------------------------------------------------
setlocal enableextensions enabledelayedexpansion
:beginning
set tools=%appdata%\iKeyHelper\bin
set logdir=%appdata%\iKeyHelper\logs
set tempdir=%temp%\iKeyHelper
if not exist %appdata%\iKeyHelper mkdir %appdata%\iKeyHelper >NUL
if not exist %tools% mkdir %tools% >NUL
if not exist %tempdir% mkdir %tempdir% >NUL
if not exist %logdir% mkdir %logdir% >NUL
if "%uuid%"=="" (
set uuid=iKeyHelper~git
set version=%uuid%
)
call :log #############################################################################
call :log Starting iKeyHelper v%version% on %date%
call :log #############################################################################
if "%uuid%"=="iKeyHelper~git" (
REM check for tools
call :toolcheck 7za.exe
call :toolcheck binmay.exe
call :toolcheck curl.exe
call :toolcheck dmg.exe
call :toolcheck genpass.exe
call :toolcheck hfsplus.exe
call :toolcheck iconv.dll
call :toolcheck ideviceinfo.exe
call :toolcheck injectpois0n.exe
call :toolcheck intl.dll
call :toolcheck irecovery.exe
call :toolcheck libcurl.dll
call :toolcheck libeay32.dll
call :toolcheck libglib-2.0-0.dll
call :toolcheck libpng12.dll
call :toolcheck libssl32.dll
call :toolcheck libxml2.dll
call :toolcheck readline5.dll
call :toolcheck ssr.exe
call :toolcheck xpwntool.exe
call :toolcheck zlib1.dll
)
title iKeyHelper v%version% - (c) 2012 cj
cls
if not exist %UserProfile%\iKeyHelper mkdir %UserProfile%\iKeyHelper >NUL
if not exist "%UserProfile%\iKeyHelper\iKeyHelper.settings.bat" (
echo Cannot find settings file.
echo Downloading new settings file.
pushd %UserProfile%\iKeyHelper
call %tools%\curl -LO https://github.com/cj123/iKeyHelper/raw/master/resources/iKeyHelper.settings.bat --progress-bar
popd
)
:: parse the settings
call %UserProfile%\iKeyHelper\iKeyHelper.settings.bat this-is-meant-to-be-run
if not exist %tempdir% mkdir %tempdir% >NUL
:: Run on startup
color 0%fontcolour%
cd %tempdir%
:: delete me some stuffs
if exist * del * /S /Q >> %logme%
if exist dlipsw rmdir dlipsw /S /Q >> %logme%
if exist IPSW rmdir IPSW /S /Q >> %logme%
if exist tools rmdir tools /S /Q >> %logme%
if exist decrypted rmdir decrypted /S /Q >> %logme%
if exist *.txt del *.txt /S /Q >> %logme%
cls
cd %tools%
if not exist %appdata%\iKeyHelper\bin\genpass.exe (
echo Extracting Files...
:: Extract the tools
if not exist %tempdir% mkdir %tempdir% >nul
if not exist %tools% mkdir %tools% >nul
copy %MYFILES%\7za.exe %tools%\7za.exe >nul
call 7za.exe x -y -mmt %appdata%\iKeyHelper\tools.zip >> %logme%
)
if "%viewlog%"=="yes" (
if exist %tools%\baretail.exe (
taskkill /F /IM "baretail.exe" 2>NUL >NUL
start "" %tools%\baretail "%logme%"
)
)
:: check for old files and remove them
call :log Clearing existing files
if exist %tempdir%\kbags rmdir /S /Q %tempdir%\kbags >> %logme%
if exist %tempdir%\IPSW rmdir /S /Q %tempdir%\IPSW >> %logme%
if exist %tempdir%\ipad-bb rmdir /S /Q %tempdir%\ipad-bb >> %logme%
if exist %tempdir%\dlipsw rmdir /S /Q %tempdir%\dlipsw >> %logme%
if exist %tempdir%\keys.txt del /S /Q if exist %tempdir%\keys.txt >> %logme%
if exist %tempdir%\kbags.txt del /S /Q %tempdir%\kbags.txt >> %logme%
cls
goto top
:top
cd %tempdir%
cls
set IPSW=
echo [v=%version%]
echo.
echo iKeyHelper
echo --------------
echo ________________________________________________________________________________
echo Drag in an...
echo.
echo $$$$$$\ $$$$$$$\ $$$$$$\ $$\ $$\
echo \_$$ _^|$$ __$$\ $$ __$$\ $$ ^| $\ $$ ^|
echo $$ ^| $$ ^| $$ ^|$$ / \__^|$$ ^|$$$\ $$ ^|
echo $$ ^| $$$$$$$ ^|\$$$$$$\ $$ $$ $$\$$ ^|
echo $$ ^| $$ ____/ \____$$\ $$$$ _$$$$ ^|
echo $$ ^| $$ ^| $$\ $$ ^|$$$ / \$$$ ^|
echo $$$$$$\ $$ ^| \$$$$$$ ^|$$ / \$$ ^|
echo \______^|\__^| \______/ \__/ \__^|
echo.
echo.
echo ...or type "x" to download from Apple.
if not exist "\Windows\System32\libusb0.dll" (
echo ^|______________________________________________________________________________^|
echo ^| Error: You do not have libusb. Please take care when installing it. ^|
CALL :log error Unable to find LibUSB. Please install it.
)
if not exist "%ProgramFiles%\iTunes\" (
echo ^|______________________________________________________________________________^|
echo ^| Error: You do not have iTunes. Please install it from apple.com/itunes ^|
CALL :log error Unable to find iTunes. Please install it.
)
echo.
echo ________________________________________________________________________________
:: open readme (once)
if not exist %appdata%\iKeyHelper\readme.txt (
call :log Opening README
start "http://www.icj.me/iKeyHelper"
echo read >%appdata%\iKeyHelper\readme.txt
)
set /P quotedinfile=- File: %=%
:: Remove quotes from infile if they exist, then put them back ;)
CALL :dequote quotedinfile
set IPSW="%quotedinfile%"
if %IPSW%=="x" (
goto downloadme
) else if %IPSW%=="dl" (
goto downloadme
)
goto checkloop
:downloadme
call :log Opening IPSW downloader...
cls
echo.
echo Download an...
echo.
echo $$$$$$\ $$$$$$$\ $$$$$$\ $$\ $$\
echo \_$$ _^|$$ __$$\ $$ __$$\ $$ ^| $\ $$ ^|
echo $$ ^| $$ ^| $$ ^|$$ / \__^|$$ ^|$$$\ $$ ^|
echo $$ ^| $$$$$$$ ^|\$$$$$$\ $$ $$ $$\$$ ^|
echo $$ ^| $$ ____/ \____$$\ $$$$ _$$$$ ^|
echo $$ ^| $$ ^| $$\ $$ ^|$$$ / \$$$ ^|
echo $$$$$$\ $$ ^| \$$$$$$ ^|$$ / \$$ ^|
echo \______^|\__^| \______/ \__/ \__^|
echo.
echo --------------------------------------------------------------------------------
echo - You have chosen to download an IPSW file.
echo - Which device are you downloading for? (e.g. iPhone3,1)
set /P dldevice=- Device: %=%
echo - Which firmware do you wish to download? (e.g. 5.0.1)
set /P dlfw=- Firmware: %=%
if exist %tempdir%\dlipsw rmdir %tempdir%\dlipsw >NUL
if not exist %tempdir%\dlipsw mkdir %tempdir%\dlipsw >NUL
cd %tempdir%\dlipsw
if exist url.txt del url.txt /S /Q >NUL
echo - Fetching Link...
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent http://api.ios.icj.me/v2/%dldevice%/%dlfw%/url -I>response.txt
:: check for multiple buildids
findstr "300 Multiple Choices" response.txt > nul
if errorlevel 1 (
set downloadlink=http://api.ios.icj.me/v2/%dldevice%/%dlfw%
goto downloadipsw
)
<nul set /p "= - Multiple BuildIDs Found: "
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent http://api.ios.icj.me/v2/%dldevice%/%dlfw%/buildid>choices.txt
:: clean up the text file
ssr 0 """ "" choices.txt
ssr 0 "," "" choices.txt
ssr 0 "{" "" choices.txt
ssr 0 "}" "" choices.txt
ssr 0 "[" "" choices.txt
ssr 0 "]" "" choices.txt
for %%a in ("choices.txt") do (
for /f "tokens=2 delims=:" %%B in ('find "buildid" ^< %%a') do (
call :addtovar %%B
)
)
echo %buildids%
set /P dlid=- Choose one BuildID: %=%
set downloadlink=http://api.ios.icj.me/v2/%dldevice%/%dlid%
goto downloadipsw
:downloadipsw
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent %downloadlink%/url -I>response.txt
findstr "200 OK" response.txt > nul
if errorlevel 1 (
echo - Error: Link not found.
echo - Press any key to return to the IPSW downloader.
call :log error Unable to find IPSW link
pause >NUL
goto downloadme
)
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent %downloadlink%/filename>ipsw_name.txt
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent %downloadlink%/url>url.txt
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent %downloadlink%/filesize>filesize.txt
set /p ipswName=<ipsw_name.txt
set /p downloadlink=<url.txt
set /p filesize=<filesize.txt
echo - Downloading %ipswName%... [%filesize%MB]
call :log downloading IPSW from %downloadlink%
echo --------------------------------------------------------------------------------
call %tools%\curl -LO %downloadlink% --progress-bar
call :log IPSW Name: %ipswName%
:: check for my HDD for IPSWs :P
if exist "G:\Apple Firmware" (
call :log moving %ipswName% to "%UserProfile%\Desktop\%ipswName%"
if not exist "G:\Apple Firmware\%dldevice%" mkdir "G:\Apple Firmware\%dldevice%" >NUL
if not exist "G:\Apple Firmware\%dldevice%\Official" mkdir "G:\Apple Firmware\%dldevice%\Official" >NUL
move /y "%ipswName%" "G:\Apple Firmware\%dldevice%\Official\%ipswName%" >> %logme%
if not exist "G:\Apple Firmware\%dldevice%\Official\%ipswName%" (
call :log error IPSW move failed
) else (
call :log IPSW move succeeded
)
set IPSW="G:\Apple Firmware\%dldevice%\Official\%ipswName%"
cls
echo - IPSW download finished^^! Saved to "G:\Apple Firmware\%dldevice%\Official\%ipswName%"
) else (
call :log moving %ipswName% to "%UserProfile%\Desktop\%ipswName%"
move /y "%ipswName%" "%UserProfile%\Desktop\%ipswName%" >> %logme%
if not exist "%UserProfile%\Desktop\%ipswName%" (
call :log error IPSW move failed
) else (
call :log IPSW move succeeded
)
set IPSW="%UserProfile%\Desktop\%ipswName%"
cls
echo - IPSW download finished^^! Saved to "%UserProfile%\Desktop\%ipswName%"
)
echo - Press any key to continue...
pause >NUL
:checkloop
echo.
echo --------------------------------------------------------------------------------
echo.
cls
echo [v=%version%]
echo Running iKeyHelper
echo ----------------------
echo.
echo.
call :log Detected input file as %IPSW%
:: start the timer
set starttime=%time%
:: create userside directory
if not exist "%bundledir%" (
mkdir "%bundledir%" >NUL
call :log Making directory: %bundledir%
)
:: check whether this is infact an IPSW...
echo %IPSW% | findstr ".ipsw" >NUL
if not "%ERRORLEVEL%"=="0" (
CALL :log error This isn't an IPSW.
echo -^^!- Error^^! This is not an IPSW. Try again, but use some brain cells next time?
echo -^^!- Press any key to go back to the menu...
pause >NUL
goto beginning
)
:: get the short file name of the IPSW.
call :sfn %IPSW%
<nul set /p "= - Extracting Files... "
cd %tempdir%
:: extract ipsw except RootFS and Ramdisks
call :log Unzipping %IPSW%...
call %tools%\7za.exe e -oIPSW -mmt %IPSW% kernel* Firmware/* *.plist >> %logme%
echo Done^^!
<nul set /p "= - IPSW Info: "
call :parse %tempdir%\IPSW\Restore.plist ProductVersion
call :parse %tempdir%\IPSW\Restore.plist MarketingVersion
if not %ProductVersion%==%MarketingVersion% (
set marketingversionexists=yes
set MarketingVersiontitle= [%MarketingVersion%]
) else (
set marketingversionexists=no
)
<nul set /p "= iOS %ProductVersion%%MarketingVersiontitle% "
call :parse %tempdir%\IPSW\Restore.plist Platform
call :parse %tempdir%\IPSW\BuildManifest.plist BuildTrain
call :parse %tempdir%\IPSW\Restore.plist ProductType
call :parse %tempdir%\IPSW\BuildManifest.plist BuildNumber
<nul set /p "= (%BuildNumber%) "
if exist %tempdir%\temp.txt del %tempdir%\temp.txt /S /Q >> %logme%
if exist %tempdir%\sha1.txt del %tempdir%\sha1.txt /S /Q >> %logme%
for %%a in (%IPSW%) do (
set /a sizeofipsw=%%~za / 1048576
)
call :log %shortipsw% size: %sizeofipsw%MB
set bdid=%ProductType:,=%
call :tolowercase %bdid%
call :log Getting Device Definitions...
pushd %UserProfile%\iKeyHelper
call %tools%\curl -LO --silent https://github.com/cj123/iKeyHelper/raw/master/resources/device_definitions.bat >> %logme%
popd
call %UserProfile%\iKeyHelper\device_definitions.bat %bdid%
<nul set /p "= for %deviceid% "
if exist %tempdir%\boardid rmdir %tempdir%\boardid /S /Q >NUL
call :log Device recognized as %deviceid%
title iKeyHelper v%version% running %deviceid%, iOS %ProductVersion%%MarketingVersiontitle% (%BuildNumber%) - (c) 2012 cj
:: ipsw name
set ipswname=%shortipsw:_Restore.ipsw=%
set ipswname=%ipswname: =%
:: baseband version detection
call :log Detecting Baseband version
pushd %tempdir%\IPSW
if exist baseband.txt del baseband.txt /S /Q >NUL
if "%boardid%"=="n90" (
dir /B /OS *.Release.bbfw >>baseband.txt
%tools%\ssr.exe 0 "ICE3_" "Baseband:" baseband.txt
%tools%\ssr.exe 0 "_BOOT_" /SSR_NL/ baseband.txt
:: yay a fun bit
FOR /F "tokens=2 delims=:" %%a IN ('find "Baseband" ^<baseband.txt') DO set baseband=%%a
) else if "%boardid%"=="n90b" (
dir /B /OS *.Release.bbfw >>baseband.txt
%tools%\ssr.exe 0 "ICE3_" "Baseband:" baseband.txt
%tools%\ssr.exe 0 "_BOOT_" /SSR_NL/ baseband.txt
:: yay a fun bit
FOR /F "tokens=2 delims=:" %%a IN ('find "Baseband" ^<baseband.txt') DO set baseband=%%a
) else if "%boardid%"=="n94" (
dir /B /OS Trek-*.Release.bbfw >>baseband.txt
%tools%\ssr.exe 0 "Trek-" "Baseband:" baseband.txt
%tools%\ssr.exe 0 ".Release.bbfw" /SSR_NL/ baseband.txt
:: yay a fun bit
FOR /F "tokens=2 delims=:" %%a IN ('find "Baseband" ^<baseband.txt') DO set baseband=%%a
) else if "%boardid%"=="n92" (
:: should be Phoenix-VE.RS.ION.Release.bbfw ?
::del Phoenix* /S /Q >NUL 2>NUL
dir /B /OS *.Release.bbfw >>baseband.txt
%tools%\ssr.exe 0 "Phoenix-" "Baseband:" baseband.txt
%tools%\ssr.exe 0 ".Release" /SSR_NL/ baseband.txt
:: yay a fun bit
FOR /F "tokens=2 delims=:" %%a IN ('find "Baseband" ^<baseband.txt') DO set baseband=%%a
) else (
call :log This device does not have a baseband^^! [or-baseband-detection-is-not-supported]
set baseband=
)
popd
if "%boardid%"=="n90" (
echo - Baseband %baseband%
) else if "%boardid%"=="n92" (
echo - Baseband %baseband%
) else if "%boardid%"=="n90b" (
echo - Baseband %baseband%
) else (
REM yes this is important
echo.
)
if "%requiresdevice%"=="yes" (
echo - This firmware requires you to be using an %deviceid% to get keys.
<nul set /p "= - Please plug in your %deviceid% in NORMAL mode... "
goto devicecheck
) else (
echo - Use any A4 device to get keys for this firmware.
goto nodevicecheck
)
:devicecheck
set detectedDevice=
for /F "tokens=2 delims=: " %%t in ('%tools%\ideviceinfo.exe ^| findstr "HardwareModel"') do set detectedDevice=%%t
set detectedDevice=%detectedDevice: =%
set detectedID=
for /F "tokens=2 delims=: " %%v in ('%tools%\ideviceinfo.exe ^| findstr "ProductType"') do set detectedID=%%v
%tools%\ideviceinfo.exe | find /I /N "No device found">NUL
if "%ERRORLEVEL%"=="1" (
echo Found device^^!
call :log Device found in NORMAL mode.
) else (
ping localhost -n 6 >nul
CALL :log error No NORMAL device found. Rechecking...
goto devicecheck
)
call :log if not "%detectedDevice%"=="%boardid%ap"
call :log Device is %detectedDevice%.
if /I not "%detectedDevice%"=="%boardid%ap" (
echo -^^!- Error: You have not plugged in a %deviceid%^^! This is an %detectedID%.
echo - Press any key to return to main screen...
pause >NUL
goto beginning
)
goto nodevicecheck
:nodevicecheck
:: get the file names from manifest
for /f "tokens=*" %%a IN ('find "applelogo" ^<%tempdir%\IPSW\manifest') do set applelogo=%%a
for /f "tokens=*" %%a IN ('find "batterylow0" ^<%tempdir%\IPSW\manifest') do set batterylow0=%%a
for /f "tokens=*" %%a IN ('find "batterylow1" ^<%tempdir%\IPSW\manifest') do set batterylow1=%%a
for /f "tokens=*" %%a IN ('find "glyphcharging" ^<%tempdir%\IPSW\manifest') do set glyphcharging=%%a
for /f "tokens=*" %%a IN ('find "batterycharging0" ^<%tempdir%\IPSW\manifest') do set batterycharging0=%%a
for /f "tokens=*" %%a IN ('find "batterycharging1" ^<%tempdir%\IPSW\manifest') do set batterycharging1=%%a
for /f "tokens=*" %%a IN ('find "glyphplugin" ^<%tempdir%\IPSW\manifest') do set glyphplugin=%%a
for /f "tokens=*" %%a IN ('find "batteryfull" ^<%tempdir%\IPSW\manifest') do set batteryfull=%%a
for /f "tokens=*" %%a IN ('find "LLB" ^<%tempdir%\IPSW\manifest') do set LLB=%%a
for /f "tokens=*" %%a IN ('find "iBoot" ^<%tempdir%\IPSW\manifest') do set iBoot=%%a
for /f "tokens=*" %%a IN ('find "DeviceTree" ^<%tempdir%\IPSW\manifest') do set DeviceTree=%%a
for /f "tokens=*" %%a IN ('find "recoverymode" ^<%tempdir%\IPSW\manifest') do set RecoveryMode=%%a
set iBSS=iBSS.%boardid%ap.RELEASE.dfu
set iBEC=iBEC.%boardid%ap.RELEASE.dfu
set kernel=kernelcache.RELEASE.%boardid%
cd IPSW
<nul set /p "= - Getting Ramdisk Information... "
if exist %tempdir%\IPSW\oldstyle.txt del %tempdir%\IPSW\oldstyle.txt /S /Q >> %logme%
:: Ramdisk identification, Done properly :)
:: edit out un-needed strings using hex.
%tools%\binmay.exe -i %tempdir%\IPSW\Restore.plist -o %tempdir%\Restore.txt -s 0A 09 09 2>NUL
%tools%\binmay.exe -i %tempdir%\Restore.txt -o %tempdir%\Restore1.txt -s 09 09 09 2>NUL
:: then add a space before + after </string>
%tools%\ssr.exe 0 "</string>" " </string> " %tempdir%\Restore1.txt >NUL
:: then add a space after <key>Update</key><string>
%tools%\ssr.exe 0 "<key>Update</key><string>" "/SSR_NL/Update:" %tempdir%\Restore1.txt >NUL
:: and after <key>User</key><string>
%tools%\ssr.exe 0 "<key>User</key><string>" "/SSR_NL/User:" %tempdir%\Restore1.txt >NUL
:: remove 3C 2F 73 74 72 69 6E 67 3E (</string>) -- yes, i know, couldve just Done this above, who cares --- it works
%tools%\binmay.exe -i %tempdir%\Restore1.txt -o %tempdir%\Restore2.txt -s "3C 2F 73 74 72 69 6E 67 3E" 2>NUL
:: replace User with restore, for easier identification
%tools%\ssr.exe 1 "User" "Restore" %tempdir%\Restore2.txt
%tools%\ssr.exe 1 "User" "NotherRD" %tempdir%\Restore2.txt
%tools%\ssr.exe 1 "User" "RootFS" %tempdir%\Restore2.txt
%tools%\binmay.exe -i %tempdir%\Restore2.txt -o %tempdir%\Restore4.txt -s 20 20 20 2>NUL
%tools%\ssr.exe 0 ".dmg" ".dmg/SSR_NL/" %tempdir%\Restore4.txt >NUL
:: set restore as the word after Restore:
FOR /F "tokens=2 delims=:" %%a IN ('find "Restore" ^<%tempdir%\Restore4.txt') DO set restore=%%a
FOR /F "tokens=2 delims=:" %%a IN ('find "NotherRD" ^<%tempdir%\Restore4.txt') DO set notherRD=%%a
if "%notherRD%"=="%restore%" (
FOR /F "tokens=2 delims=:" %%a IN ('find "RootFS" ^<%tempdir%\Restore4.txt') DO set rootfilesystem=%%a
) else (
set rootfilesystem=%notherRD%
)
:: same as above but for update
FOR /F "tokens=2 delims=:" %%a IN ('find "Update" ^<%tempdir%\Restore4.txt') DO set update=%%a
FOR /F "tokens=2 delims=:" %%a IN ('find "Update" ^<%tempdir%\Restore4.txt') DO set updateishere=yes
if exist %tempdir%\Restore4.txt del %tempdir%\Restore4.txt /S /Q >NUL
:: checking ramdisk numbers!!!
set update=%update: =%
set restore=%restore: =%
set rootfilesystem=%rootfilesystem: =%
if "%updateishere%"=="yes" (
echo %update%> dmgs.txt
set updateishere=yes
)
echo %restore%>> dmgs.txt
echo %rootfilesystem%>> dmgs.txt
::%tools%\binmay.exe -i %tempdir%\IPSW\dmgs.txt -o %tempdir%\IPSW\dmgs-f.txt -s 20 20 20 2>NUL
::ping -n 3 localhost >NUL
REM for /f "tokens=* delims= " %%a in (%tempdir%\IPSW\dmgs.txt) do (
REM set /a n+=1
REM set ramdisk!n!=%%a
REM )
REM if not "%updateishere%"=="yes" (
REM CALL :log error No Update Ramdisk. Continuing...
REM set restore=%ramdisk1%
REM set rootfilesystem=%ramdisk2%
REM ) else (
REM :: assume all 3 ramdisks are there.
REM set update=%ramdisk1%
REM set restore=%ramdisk2%
REM set rootfilesystem=%ramdisk3%
REM )
echo Done^^!
call :log Ramdisks-Update-%update%-Restore-%restore%-Rootfs-%rootfilesystem%
%tools%\7za.exe e -o%tempdir%\IPSW -mmt %IPSW% %update% %restore% >> %logdir%\%timestamp%
echo bgcolor 0 0 0 >>%tempdir%\kbags.txt
echo go fbecho iKeyHelper v%version% by Callum Jones ^<cj@icj.me^> >>%tempdir%\kbags.txt
echo go fbecho ========================================>>%tempdir%\kbags.txt
echo go fbecho - Loading iOS %ProductVersion%%MarketingVersiontitle% (%BuildNumber%) >>%tempdir%\kbags.txt
echo go fbecho ^> for %ProductType% (%url_parsing_device%) >>%tempdir%\kbags.txt
echo go fbecho ========================================>>%tempdir%\kbags.txt
if exist *.txt del *.txt /S /Q >NUL
if exist *asr del *asr /S /Q >NUL
call :log Getting KBAGs...
:: delete the files
if exist %tempdir%\Restore.txt del %tempdir%\Restore.txt /S /Q >NUL
if exist %tempdir%\Restore1.txt del %tempdir%\Restore1.txt /S /Q >NUL
if exist %tempdir%\Restore2.txt del %tempdir%\Restore2.txt /S /Q >NUL
:kbags
<nul set /p "= - Grabbing KBAGs... "
call :grabkbag %LLB% >>%tempdir%\kbags.txt
call :grabkbag %iBoot% >>%tempdir%\kbags.txt
call :grabkbag %devicetree% >>%tempdir%\kbags.txt
call :grabkbag %applelogo% >>%tempdir%\kbags.txt
call :grabkbag %recoverymode% >>%tempdir%\kbags.txt
call :grabkbag %batterylow0% >>%tempdir%\kbags.txt
call :grabkbag %batterylow1% >>%tempdir%\kbags.txt
call :grabkbag %glyphcharging% >>%tempdir%\kbags.txt
call :grabkbag %glyphplugin% >>%tempdir%\kbags.txt
call :grabkbag %batterycharging0% >>%tempdir%\kbags.txt
call :grabkbag %batterycharging1% >>%tempdir%\kbags.txt
call :grabkbag %batteryfull% >>%tempdir%\kbags.txt
call :grabkbag %ibss% >>%tempdir%\kbags.txt
call :grabkbag %ibec% >>%tempdir%\kbags.txt
call :grabkbag %kernel% >>%tempdir%\kbags.txt
pushd %tempdir%\IPSW\
:: run this TWICE.
if exist %tempdir%\IPSW\%restore% (
%tools%\xpwntool.exe %tempdir%\IPSW\%restore% %tempdir%\IPSW\%restore%.dec >NUL 2>NUL
%tools%\hfsplus %tempdir%\IPSW\%restore%.dec extract /usr/sbin/asr %restore:~0,-4%_asr >NUL 2>NUL
if not exist %restore:~0,-4%_asr (
::echo doing RESTORE
set restoreenc=y
call :log Restore is encrypted
call :grabkbag %restore% >>%tempdir%\kbags.txt
) else (
set restoreenc=n
call :log Restore not encrypted
echo go echo %restore% >>%tempdir%\kbags.txt
echo go echo *Not_Encrypted >>%tempdir%\kbags.txt
)
)
if "%updateishere%"=="yes" (
%tools%\xpwntool.exe %tempdir%\IPSW\%update% %tempdir%\IPSW\%update%.dec >NUL 2>NUL
%tools%\hfsplus %tempdir%\IPSW\%update%.dec extract /usr/sbin/asr %update:~0,-4%_asr >NUL 2>NUL
if not exist %update:~0,-4%_asr (
::echo DOING UPDATE
set updateenc=y
call :log Update is encrypted
call :grabkbag %update% >>%tempdir%\kbags.txt
) else (
set updateenc=n
call :log Update is not encrypted
echo go echo %update% >>%tempdir%\kbags.txt
echo go echo *Not_Encrypted >>%tempdir%\kbags.txt
)
)
:: remove files
if exist %update:~0,-4%_asr del %update:~0,-4%_asr /S /Q >NUL
if exist %restore:~0,-4%_asr del %restore:~0,-4%_asr /S /Q >NUL
if exist %update%.dec del %update%.dec /S /Q >NUL
if exist %restore%.dec del %restore%.dec /S /Q >NUL
popd
echo go fbecho ===================================>>%tempdir%\kbags.txt
echo go fbecho - Done>>%tempdir%\kbags.txt
echo go fbecho - Rebooting...>>%tempdir%\kbags.txt
echo go fbecho ===================================>>%tempdir%\kbags.txt
echo Done^^!
echo /exit >>%tempdir%\kbags.txt
:: close open iTunes windows (if they exist)
tasklist /FI "IMAGENAME eq iTunes.exe" 2>NUL | find /I /N "iTunes.exe">NUL
if "%ERRORLEVEL%"=="0" (
echo - Closing iTunes
taskkill /F /IM "iTunes.exe" >nul
)
:: close open iTunesHelper (if it is open)
tasklist /FI "IMAGENAME eq iTunesHelper.exe" 2>NUL | find /I /N "iTunesHelper.exe">NUL
if "%ERRORLEVEL%"=="0" (
echo - Closing iTunesHelper
taskkill /F /IM "iTunesHelper.exe" >nul
)
::checking for dfu
<nul set /p "= - Please Enter DFU mode... "
goto dfucheck
:dfucheck
%tools%\irecovery.exe -c | find /I /N "DFU">> %logme%
if "%ERRORLEVEL%"=="0" (
echo Found device^^!
call :log Device found in DFU mode.
) else (
ping localhost -n 6 >nul
CALL :log error No DFU device found. Rechecking...
goto dfucheck
)
:found-recovery
call %tools%\irecovery.exe -c "setenv boot-args 2" >> %logme%
call %tools%\irecovery.exe -c "saveenv" >> %logme%
call :log Extracting RootFS
start /B "" %tools%\7za.exe e -o%tempdir%\IPSW -mmt %IPSW% %rootfilesystem% >NUL
cd %tempdir%
:: injectpois0n
call :log Starting Injectpois0n.
<nul set /p "= - Running injectpois0n... "
call %tools%\injectpois0n.exe -2 >> %logdir%\%timestamp% 2>NUL
call :log Injectpois0n finished.
if exist %tempdir%\iBSS* del %tempdir%\iBSS* /S /Q >> %logme%
echo Done^^!
goto elsewhere
:elsewhere
:: run irecovery -s to get rid of unneeded junk :)
start /B %tools%\irecovery -s >> %logme%
ping localhost -n 5 >nul
taskkill /F /IM "irecovery.exe" 2>NUL >nul
cd %tempdir%\IPSW\
:: call %tools%\irecovery -c "bgcolor 0 100 100" >nul
:: close open irecovery windows (if they exist)
tasklist /FI "IMAGENAME eq irecovery.exe" 2>NUL | find /I /N "irecovery.exe">NUL
if "%ERRORLEVEL%"=="0" (
echo - Closing any open iRecovery command windows
taskkill /F /IM "irecovery.exe" >nul
)
cd %tempdir%
<nul set /p "= - Getting keys... "
%tools%\irecovery -s gp-keys.txt < kbags.txt >> %logme%
cd %tempdir%\IPSW\
goto loop1
:loop1
tasklist /FI "IMAGENAME eq irecovery.exe" 2>NUL | find /I /N "irecovery.exe">NUL
if "%ERRORLEVEL%"=="0" (
goto loop1
)
:: reboot
call :log Rebooting Device.
<nul set /p "= Rebooting... "
%tools%\irecovery -c "setenv auto-boot true" >> %logme%
%tools%\irecovery -c "saveenv" >> %logme%
%tools%\irecovery -c "reboot" >> %logme%
echo Done^^!
call :log formatting text file.
pushd %tempdir%
%tools%\binmay.exe -i gp-keys.txt -o keys.txt -s 00 2>NUL
%tools%\ssr.exe 0 """ "'" keys.txt
%tools%\ssr.exe 0 " " "" keys.txt
%tools%\ssr.exe 0 "-iv" "* /SSR_QUOTE//SSR_QUOTE//SSR_QUOTE/IV/SSR_QUOTE//SSR_QUOTE//SSR_QUOTE/: " keys.txt
%tools%\ssr.exe 0 "-k" "/SSR_NL/* /SSR_QUOTE//SSR_QUOTE//SSR_QUOTE/Key/SSR_QUOTE//SSR_QUOTE//SSR_QUOTE/: " keys.txt
%tools%\ssr.exe 0 "Not_Encrypted" "Not Encrypted" keys.txt
:: rootfs key grabbing
:: parse all iv's to ivs.txt
echo 1 >ivs.txt
echo 2 >>ivs.txt
for %%a in ("%tempdir%\keys.txt") do (
for /f "tokens=3" %%B in ('find "'''IV''': " ^< %%a') do (
echo %%B >>ivs.txt
)
)
if exist temp.txt del temp.txt /S /Q >NUL
move ivs.txt temp.txt >NUL
%tools%\binmay.exe -i temp.txt -o ivs.txt -s 20 0D 0A 2>NUL
if exist temp.txt del temp.txt /S /Q >NUL
for /f "tokens=* delims= " %%a in (ivs.txt) do (
set /a ivz+=1
set iv!ivz!=%%a
)
:: parse all keys to key.txt
echo 1 >key.txt
echo 2 >>key.txt
for %%a in ("%tempdir%\keys.txt") do (
for /f "tokens=3" %%B in ('find "'''Key''': " ^< %%a') do (
echo %%B >>key.txt
)
)
if exist temp.txt del temp.txt /S /Q >NUL
move key.txt temp.txt >NUL
%tools%\binmay.exe -i temp.txt -o key.txt -s 20 0D 0A 2>NUL
if exist temp.txt del temp.txt /S /Q >NUL
for /f "tokens=* delims= " %%a in (key.txt) do (
set /a keyz+=1
set key!keyz!=%%a
)
goto back-to-me
:back-to-me
if %boardid%==n94 (
echo - Extracting RootFS...
%tools%\7za.exe e -o%tempdir%\IPSW -mmt %IPSW% %rootfilesystem% >> %logme%
)
if not exist %tempdir%\decrypted mkdir %tempdir%\decrypted\ >NUL
cd %tempdir%
if exist %tempdir%\decrypted\%update%.dec del %tempdir%\decrypted\%update%.dec /S /Q >NUL
if exist %tempdir%\decrypted\%restore%.dec del %tempdir%\decrypted\%restore%.dec /S /Q >NUL
call :log Update Ramdisk Shiz
if not "%update%"=="" (
if not "%updateenc%"=="n" (
%tools%\xpwntool %tempdir%\IPSW\%update% %tempdir%\decrypted\%update%.dec -iv %iv19% -k %key19% >NUL
) else (
%tools%\xpwntool %tempdir%\IPSW\%update% %tempdir%\decrypted\%update%.dec >NUL
)
)
call :log Restore Ramdisk Shiz
if not "%restore%"=="" (
if not "%restoreenc%"=="n" (
%tools%\xpwntool %tempdir%\IPSW\%restore% %tempdir%\decrypted\%restore%.dec -iv %iv18% -k %key18% >NUL
) else (
%tools%\xpwntool %tempdir%\IPSW\%restore% %tempdir%\decrypted\%restore%.dec >NUL
)
)
goto rootfs-check
:rootfs-check
if not exist %tempdir%\IPSW\%rootfilesystem% (
call :log error No RootFS extracted!
goto rootfs-check
) else (
call :log Found extracted RootFS
)
<nul set /p "= - Getting RootFS Key... "
call :log Getting RootFS Key using restore
%tools%\genpass.exe -p %platform% -r decrypted/%restore%.dec -f IPSW/%rootfilesystem% >%tempdir%\IPSW\genpass.txt 2>NUL
findstr /C:"vfdecrypt key" %tempdir%\IPSW\genpass.txt >NUL
if not "%ERRORLEVEL%"=="0" (
CALL :log error RootFS key not found -trying update
%tools%\genpass.exe -p %platform% -r decrypted/%update%.dec -f IPSW/%rootfilesystem% >%tempdir%\IPSW\genpass.txt 2>NUL
)
call :log Decrypting RootFS TEST
%tools%\dmg.exe extract %tempdir%\IPSW\%rootfilesystem% %tempdir%\decrypted\%rootfilesystem%.dec -k %rtkey% 2>decryptedcheck.txt
findstr /C:"readUDIFResourceFile - signature incorrect" decryptedcheck.txt >NUL
if "%errorlevel%"=="0" (
call :log error Genpass and vfdecrypt key failed-tryingupdate
%tools%\genpass.exe -p %platform% -r decrypted/%update%.dec -f IPSW/%rootfilesystem% >%tempdir%\IPSW\genpass.txt 2>NUL
)
findstr /C:"vfdecrypt key" %tempdir%\IPSW\genpass.txt >NUL
if "%errorlevel%"=="0" (
for %%a in ("%tempdir%\IPSW\genpass.txt") do (
for /f "tokens=3" %%B in ('find "vfdecrypt key: " ^< %%a') do (
echo %%B >>pass.txt
move pass.txt temp.txt >NUL
%tools%\binmay.exe -i temp.txt -o pass.txt -s 20 0D 0A 2>NUL
if exist temp.txt del temp.txt /S /Q >NUL
)
)
for /f "tokens=* delims= " %%a in (pass.txt) do set rtkey=%%a
echo Done^^!
) else (
call :log error Genpass and vfdecrypt key failed
echo FAILED^^!
)
if "%bdid%"=="ipad11" goto ipadbb
if "%bdid%"=="iphone21" goto ipadbb
goto noipadbb
:ipadbb
:: Get the baseband for iPad from ramdisk
if exist %tempdir%\ipad-bb rmdir %tempdir%\ipad-bb /S /Q >NUL
call :log Getting iPad/3G[S] Baseband
if not exist %tempdir%\ipad-bb mkdir %tempdir%\ipad-bb
pushd %tempdir%\ipad-bb
:: hfsplus to the rescue! (lol)
%tools%\hfsplus "%tempdir%\decrypted\%restore%.dec" extractall /usr/local/standalone/firmware/ >NUL 2>NUL
:: check if its wrapped in a BBFW file
if exist ICE2.Release.bbfw (
call :log BBFW EXISTS
%tools%\7za x -y -mmt ICE2.Release.bbfw >NUL
) else (
call :log BBFW NO EXISTY
)
dir /OS /B %tempdir%\ipad-bb\*.eep > %tempdir%\bb.txt 2>&1
%tools%\ssr 0 "ICE2_" "" %tempdir%\bb.txt
%tools%\ssr 0 ".eep" "" %tempdir%\bb.txt
if "%bdid%"=="ipad11" (
set /p baseband=< %tempdir%\bb.txt
)
if "%bdid%"=="iphone21" (
for /f "tokens=* delims= " %%a in (%tempdir%\bb.txt) do (
set /a v+=1
if "!v!"=="2" (
set baseband=%%a
)
)
)
call :log iPad/3G[S]Baseband: %baseband%
popd
goto noipadbb
:noipadbb
:: i'm sure there's a reason behind this but at the moment it looks absolutely stupid.
echo . >NUL
pushd %temp%\iKeyHelper
:: get url for firmware
%tools%\curl -A "iKeyHelper - %uuid% - %version%" --silent http://api.ios.icj.me/v2/%boardid%ap/%BuildNumber%/url >url.txt
set /p downloadurl=<url.txt
popd
echo iKeyHelper %version% by cj>iphonewikikeys.txt
if "%username%"=="Callum" (
echo %ipswname% Keys and IV's Grabbed by cj ^<cj@icj.me^> on %date%>>iphonewikikeys.txt
) else (
echo %ipswname% Keys and IV's Grabbed by %username% on %date%>>iphonewikikeys.txt
)
echo.>>iphonewikikeys.txt
echo ------------------------------------------- KEYS ------------------------------------------->>iphonewikikeys.txt
echo.>>iphonewikikeys.txt
echo {{keys>>iphonewikikeys.txt
if not %MarketingVersion%==%ProductVersion% (
if not "%downloadurl%"=="" (
echo ^| version = %ProductVersion% ^(%MarketingVersion%^)>>iphonewikikeys.txt