-
Notifications
You must be signed in to change notification settings - Fork 46
/
URTool.bat
1143 lines (1086 loc) · 44.7 KB
/
URTool.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
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
::DISCLAIMER: this tool can be used for free, the credits to JamFlux and other authors must be visible where the ROM has been published
@shift /0
@echo OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET APP_NAME=UR-Tool Prime v1.8 semi-stable
SET AUTHORS=[by JamFlux]
SET APP_DESCRIPTION=Extract and Repack system formats on android 5-8.1
set CYGWIN=nodosfilewarning
SET Cecho=bins\cecho.exe
SET busybox=bins\busybox.exe
set imgextractor="bins\ImgExtractor.exe"
TITLE %APP_NAME% %AUTHORS%
:start
mode con: cols=75 lines=15
if exist 01-Project rmdir /q /s 01-Project
if exist 1-Finish rmdir /q /s 1-Finish
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo.
%cecho% {4f}%APP_DESCRIPTION%{#}
TIMEOUT /T 3 /nobreak > NUL & cls
::Find .zip files into executable directory
mode con: cols=75 lines=28
:ZIP_FILES
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo.
echo *****************************************************
%cecho% {0b}Please, select a zip to work with:{#}
echo.
echo *****************************************************
echo.
echo.
SET /A i=1
FOR %%k IN (*.zip) DO (
SET ZIP!i!=%%k
echo * !i! - %%k
SET /A i+=1
)
echo.
echo.
SET /P NUMBER=* Choose the number:
IF NOT DEFINED NUMBER GOTO :ZIP_FILES
IF /I %NUMBER% GEQ %i% GOTO :ZIP_FILES
IF /I %NUMBER% LSS 1 GOTO :ZIP_FILES
SET FILE=!ZIP%NUMBER%!
IF NOT EXIST "%FILE%" GOTO :ZIP_FILES
::The main menu
:work_place
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
echo * Working with:
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
%cecho% * {0a}Avalaible Menu{#}
echo.
echo.
echo * 1- Extract android image (BIN,IMG,DAT-BR are supported)
echo * 2- Repack android folder to its original format
echo * 3- Exit
echo.
echo.
SET /P NUMBER=* Select an option:
IF "%NUMBER%"=="1" GOTO Just_Unpack
IF "%NUMBER%"=="2" GOTO Just_Repack
IF "%NUMBER%"=="3" GOTO Exit
::IF "%NUMBER%"=="4" GOTO Make_zip
::Determining ROM format
:Just_Unpack
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
echo * Working with:
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * {0a}Extracting zip files...{#}
echo.
IF NOT EXIST "01-Project" MKDIR "01-Project"
IF NOT EXIST "01-Project\1-Sources" MKDIR "01-Project\1-Sources"
IF NOT EXIST "01-Project\temp" MKDIR "01-Project\temp"
IF NOT EXIST "01-Project\system" MKDIR "01-Project\system"
IF NOT EXIST "01-Project\1-Sources" MKDIR "01-Project\1-Sources"
::Copying extracted files to source folder
bins\7z e "%FILE%" n system.new.dat.br -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n system.new.dat -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n system.img -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n payload.bin -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n vendor.new.dat.br -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n vendor.new.dat -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n vendor.img -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n boot.img -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n system.transfer.list -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n vendor.transfer.list -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n file_contexts -o01-Project\1-Sources >nul
bins\7z e "%FILE%" n file_contexts.bin -o01-Project\1-Sources >nul
if exist 01-Project\1-Sources\vendor.* (goto un_vendor) else goto next
:next
::Looking for system or vendor compression format
if exist 01-Project\1-Sources\system.new.dat.br echo new.dat.br format found >>01-Project\temp\system.new.dat.br.br
if exist 01-Project\1-Sources\system.new.dat echo new.dat format found >>01-Project\temp\system.new.dat.dat
if exist 01-Project\1-Sources\payload.bin echo payload.bin format found >>01-Project\temp\payload.bin.bin
if exist 01-Project\1-Sources\system.img echo system.img format found >>01-Project\temp\system.img.img
FOR /R 01-Project\temp %%A IN (*) DO SET format=%%~nA
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
echo * Working with:
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Current format is: {0a}!format!{#}
echo.
TIMEOUT /T 3 /nobreak > NUL
:check_format
cls
if "!format!"=="payload.bin" (goto un_payload) else goto next_1
:next_1
cls
if "!format!"=="system.new.dat.br" (goto un_brotli) else goto next_2
:next_2
cls
if "!format!"=="system.new.dat" (goto un_pack_dat) else goto next_3
:next_3
cls
if "!format!"=="system.img" (goto Extract_SYS) else goto not_supported
goto:eof
:un_vendor
::Unpacking vendor image
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
echo * Working with:
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * {0a}Vendor image found:{#} extracting...
echo.
if exist 01-Project\1-Sources\vendor.new.dat.br bins\brotli -d 01-Project\1-Sources\vendor.new.dat.br >nul
if exist 01-Project\1-Sources\vendor.new.dat bins\sdat2img 01-Project\1-Sources\vendor.transfer.list 01-Project\1-Sources\vendor.new.dat 01-Project\1-Sources\vendor.img >nul
if exist 01-Project\1-Sources\vendor.img bins\ImgExtractor 01-Project\1-Sources\vendor.img 01-Project\vendor >nul
call :Detect_vendor_size
call :write_vendor_symlinks
if exist 01-Project\1-Sources\vendor.new.dat.br !busybox! rm -rf 01-Project\1-Sources\vendor.new.dat.br >nul
if exist 01-Project\1-Sources\vendor.new.dat !busybox! rm -rf 01-Project\1-Sources\vendor.new.dat >nul
goto next
:not_supported
::Not supported android image
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%CECHO% {03}by JamFlux{#}
echo.
echo.
echo.
%CECHO% * {0f}I have found a format type error:{#}
echo.
echo.
echo.
echo *****************************************************
%CECHO% * The supplied zip {0c}does not contain a supported format{#}
echo.
echo.
%CECHO% * Valid formats are: {0a}system.IMG/NEW.DAT/BR/payload.BIN{#}
echo.
echo *****************************************************
echo.
pause>nul
rmdir /q /s 01-Project
goto ZIP_FILES
:un_payload
::Use only for A/B devices like pixel or mi a1, mi a2
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Unpacking {0a}!format!{#} system images...
echo.
bins\7z x "bins\payload.7z" -o01-Project\1-Sources >nul
move /y 01-Project\1-Sources\payload.bin 01-Project\1-Sources\payload_input >nul 2>nul
cd 01-Project\1-Sources
call payload_dumper.bat
cd ..\..
move /y 01-Project\1-Sources\payload_output\system.img 01-Project\1-Sources>nul 2>nul
move /y 01-Project\1-Sources\payload_output\boot.img 01-Project\1-Sources >nul 2>nul
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * {0a}Done{#}
echo.
if exist 01-Project\1-Sources\payload_input rmdir /q /s 01-Project\1-Sources\payload_input >nul 2>nul
if exist 01-Project\1-Sources\payload_output rmdir /q /s 01-Project\1-Sources\payload_output >nul 2>nul
if exist 01-Project\1-Sources\payload_dumper.exe !busybox! rm -rf 01-Project\1-Sources\payload_dumper.exe >nul 2>nul
if exist 01-Project\1-Sources\payload_dumper.bat !busybox! rm -rf 01-Project\1-Sources\payload_dumper.bat >nul 2>nul
TIMEOUT /T 2 /nobreak > NUL
goto Extract_SYS
:un_brotli
::Unpack brotli compressed image, ROMs above android 8.1
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Decompressing {0a}!format!{#} format...
echo.
bins\brotli.exe -dj 01-Project/1-Sources/system.new.dat.br >nul
:un_pack_dat
::Unpacking .dat compression
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Unpacking {0a}!format!{#} format...
echo.
bins\sdat2img 01-Project\1-Sources\system.transfer.list 01-Project\1-Sources\system.new.dat 01-Project\1-Sources\system.img >nul
if exist 01-Project\1-Sources\system.new.dat.br !busybox! rm -rf 01-Project\1-Sources\system.new.dat.br >nul 2>nul
if exist 01-Project\1-Sources\system.new.dat !busybox! rm -rf 01-Project\1-Sources\system.new.dat >nul 2>nul
TIMEOUT /T 1 /nobreak > NUL
goto Extract_SYS
:Extract_SYS
::Main function for editing ROM's stuff, extracting system image to simple files folder
call :Detect_system_size
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Extracting {0a}system.img{#}...
echo.
echo.
if not exist 01-Project\system mkdir 01-Project\system
:: ---> This is for extract system.img using 7z, this puts wrong symlinks format, so better is use into system folder zip ROM
bins\7z x -y "01-Project\1-Sources\system.img" -o"01-Project\system" >nul 2>nul
rmdir /q /s 01-Project\system\[SYS] >nul
:: <---
call :img_extractor
call :Remove_pics_with_spaces
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Grabbing {0a}symlinks{#} and {0a}permissions{#}...
echo.
echo.
::Converts android 7+ file_contexts.bin to plain format. Thanks to wuxianlin at github.
if not exist 01-Project\1-Sources\file_contexts call :File_Context_converter >nul 2>nul
::This part for grabbing symlinks and permissions was adapted from assayyed kitchen batch-script code. Thanks to Assayyed.
call :write_sys_symlinks
call :write_sys_permissions
if exist 01-Project\1-Sources\not_recursive !busybox! rm -rf 01-Project\1-Sources\not_recursive >nul
if exist 01-Project\1-Sources\permissions_sorted !busybox! rm -rf 01-Project\1-Sources\permissions_sorted >nul
if exist 01-Project\1-Sources\recursive !busybox! rm -rf 01-Project\1-Sources\recursive >nul
if exist 01-Project\1-Sources\rom_permissions !busybox! rm -rf 01-Project\1-Sources\rom_permissions >nul
if exist 01-Project\1-Sources\system_contexts !busybox! rm -rf 01-Project\1-Sources\system_contexts >nul
call :Detect_vendor_size
echo %SIZE%>>01-Project\1-Sources\sys_size.txt
echo.
if exist 01-Project\vendor echo %VSIZE%>>01-Project\1-Sources\vend_size.txt
if exist 01-Project\1-Sources\vendor.img !busybox! rm -rf 01-Project\1-Sources\vendor.img >nul
if exist 01-Project\1-Sources\vendor.transfer.list !busybox! rm -rf 01-Project\1-Sources\vendor.transfer.list >nul
echo.
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Done, see {0a}01-Project\system{#} folder.
echo.
echo.
if exist 01-Project\1-Sources\system.img !busybox! rm -rf 01-Project\1-Sources\system.img >nul 2>nul
if exist 01-Project\1-Sources\system.transfer.list !busybox! rm -rf 01-Project\1-Sources\system.transfer.list >nul 2>nul
if not exist 01-Project\1-Sources\file_contexts call :File_Context_converter >nul 2>nul
TIMEOUT /T 3 /nobreak > NUL
cd 01-Project/1-Sources
if exist original_symlinks del /q original_symlinks
cd ..\..
%busybox% sort -u < 01-Project/1-Sources/symlinks >> 01-Project/1-Sources/original_symlinks
if exist 01-Project\1-Sources\vendor_symlinks %busybox% sort -u < 01-Project/1-Sources/vendor_symlinks >> 01-Project/1-Sources/original_vendor_symlinks
if exist 01-Project\1-Sources\original_vendor_symlinks type 01-Project\1-Sources\original_vendor_symlinks >> 01-Project\1-Sources\original_symlinks
cd 01-Project/1-Sources
del /q symlinks
if exist vendor_symlinks del /q vendor_symlinks
if exist original_vendor_symlinks del /q original_vendor_symlinks
cd ..\..
bins\dos2unix -q 01-Project\1-Sources\original_symlinks
bins\dos2unix -q 01-Project\1-Sources\file_contexts
goto work_place
::Magic happen here --->
:File_Context_converter
if not exist 01-Project\1-Sources\file_contexts.bin call :File_Context_finder >nul 2>nul
bins\sefcontext_decompile -o 01-Project\1-Sources\file_contexts 01-Project\1-Sources\file_contexts.bin >nul 2>nul
if exist 01-Project\1-Sources\file_contexts %busybox% sort -u < 01-Project/1-Sources/file_contexts >> 01-Project/1-Sources/file_contexts_sorted
cd 01-Project/1-Sources
move /y file_contexts_sorted file_contexts > nul
cd ..\..
goto:eof
:File_Context_finder
xcopy bins\bootimg.exe 01-Project\1-Sources /y >nul
cd 01-Project\1-Sources
bootimg.exe --unpack-bootimg >nul 2>nul
bootimg.exe --unpack-ramdisk >nul 2>nul
if exist initrd\plat_file_contexts move /y initrd\plat_file_contexts initrd\file_contexts >nul
cd ..\..
move /y 01-Project\1-Sources\initrd\file_contexts 01-Project\1-Sources >nul 2>nul
move /y 01-Project\1-Sources\initrd\file_contexts.bin 01-Project\1-Sources >nul 2>nul
if exist 01-Project\1-Sources\initrd rmdir /q /s 01-Project\1-Sources\initrd >nul 2>nul
if exist 01-Project\1-Sources\bootimg.exe !busybox! rm -rf 01-Project\1-Sources\bootimg.exe >nul 2>nul
if exist 01-Project\1-Sources\bootimg.json !busybox! rm -rf 01-Project\1-Sources\bootimg.json >nul 2>nul
if exist 01-Project\1-Sources\*.gz !busybox! rm -rf 01-Project\1-Sources\*.gz >nul 2>nul
if exist 01-Project\1-Sources\cpiolist.txt !busybox! rm -rf 01-Project\1-Sources\cpiolist.txt >nul 2>nul
if exist 01-Project\1-Sources\kernel.gz.dt !busybox! rm -rf 01-Project\1-Sources\kernel.gz.dt >nul 2>nul
if exist 01-Project\1-Sources\unknown !busybox! rm -rf 01-Project\1-Sources\unknown >nul 2>nul
goto:eof
::Till here<---
:no project
:Sin_proyecto
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% {03}by JamFlux{#}
echo.
echo.
echo.
%cecho% * {0f}I have found a serious error:{#}
echo.
echo.
echo.
echo *****************************************************
%cecho% * The supplied zip {0c}doesn't have a build.prop{#}
echo.
echo.
%cecho% * Please, choose option {0a}1{#} before
echo.
echo * building a new system project.
echo *****************************************************
echo.
pause>nul
if exist 01-Project rmdir /q /s 01-Project
goto work_place
::Second part for re-pack!
:Just_Repack
:check_android_version
FOR /R 01-Project\temp %%A IN (*) DO SET format=%%~nA
if "!format!"=="payload.bin" (goto system_AB) else goto system_A
::Normal system android image
:system_A
if not exist 01-Project\system\build.prop goto Sin_proyecto
FOR /F "Tokens=2* Delims==" %%# In (
'TYPE "01-Project\system\build.prop" ^| FINDSTR "ro.build.version.release="'
) Do (
SET "release=%%#"
)
call :zipalign
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Repacking to: {0a}!format!{#} format...
echo.
if not exist 01-Project\2-New_system mkdir 01-Project\2-New_system >nul
if exist 01-Project\vendor bins\make_ext4fs -L vendor -T 2009110000 -S 01-Project\1-Sources\file_contexts -l %VSIZE% -a vendor 01-Project\2-New_system\vendor_ext4.img 01-Project\vendor\ >nul 2>nul
bins\make_ext4fs -L system -T 2009110000 -S 01-Project\1-Sources\file_contexts -C 01-Project\1-Sources\fs_config -l %SIZE% -a system 01-Project\2-New_system\system_ext4.img 01-Project\system\ >nul 2>nul
FOR %%B IN ("01-Project\2-New_system\system_ext4.img") DO SET SIZE2=%%~zB
echo %SIZE2% >> 01-Project\1-Sources\sys_size2.txt
if %SIZE2%==0 (goto no_fs_config) else (goto decide_format)
:decide_format
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Repacking to: {0a}!format!{#} format...
echo.
if "!format!"=="payload.bin" (goto Repack_IMG) else goto next_1.1
:next_1.1
cls
if "!format!"=="system.new.dat.br" (goto re_brotli) else goto next_2.1
:next_2.1
cls
if "!format!"=="system.new.dat" (goto re_pack_dat) else goto next_3.1
:next_3.1
cls
if "!format!"=="system.img" (goto Repack_IMG) else goto not_supported
goto:eof
if exist 01-Project\1-Sources\system.img !busybox! rm -rf 01-Project\1-Sources\system.img > nul
::Pixel and mi a1 system images, double system slot
:system_AB
if not exist 01-Project\system\system\build.prop goto Sin_proyecto
FOR /F "Tokens=2* Delims==" %%# In (
'TYPE "01-Project\system\system\build.prop" ^| FINDSTR "ro.build.version.release="'
) Do (
SET "release=%%#"
)
call :zipalign
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} A/B ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Repacking to: {0a}system.img{#} format...
echo.
if not exist 01-Project\2-New_system mkdir 01-Project\2-New_system >nul
if exist 01-Project\vendor bins\make_ext4fs -L vendor -T 2009110000 -S 01-Project\1-Sources\file_contexts -l %VSIZE% -a vendor 01-Project\2-New_system\vendor_ext4.img 01-Project\vendor\ >nul 2>nul
bins\make_ext4fs -L system -T 2009110000 -S 01-Project\1-Sources\file_contexts -C 01-Project\1-Sources\fs_config -l %SIZE% -a system 01-Project\2-New_system\system_ext4.img 01-Project\system\ >nul 2>nul
FOR %%B IN ("01-Project\2-New_system\system_ext4.img") DO SET SIZE2=%%~zB
echo %SIZE2% >> 01-Project\1-Sources\sys_size2.txt
if %SIZE2%==0 (goto no_fs_config_AB) else (goto decide_format2)
:decide_format2
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} A/B ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Done, see: {0a}1-Finish{#} folder
echo.
call :Limpieza
TIMEOUT /T 3 /nobreak > nul & cls
goto work_place
::Compression for brotli ROMs - android 8.1+
:re_brotli
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Compressing to: {0a}!format!{#} format...
echo.
bins\ext2simg -v 01-Project\2-New_system\system_ext4.img 01-Project\2-New_system\system.img >nul
TIMEOUT /T 3 /nobreak >nul
if exist 01-Project\2-New_system\vendor_ext4.img bins\ext2simg -v 01-Project\2-New_system\vendor_ext4.img 01-Project\2-New_system\vendor.img >nul
TIMEOUT /T 3 /nobreak >nul
bins\simg2sdat 01-Project\2-New_system\system.img 01-Project\2-New_system >nul
TIMEOUT /T 3 /nobreak >nul
if exist 01-Project\2-New_system\vendor.img bins\simg2sdat 01-Project\2-New_system\vendor.img 01-Project\2-New_system >nul
TIMEOUT /T 3 /nobreak >nul
call :Just_Touch
bins\brotli.exe -6 -j -w 24 01-Project\2-New_system\system.new.dat >nul 2>nul
TIMEOUT /T 3 /nobreak >nul
bins\brotli.exe -6 -j -w 24 01-Project\2-New_system\vendor.new.dat >nul 2>nul
TIMEOUT /T 3 /nobreak >nul
if exist 01-Project\2-New_system\system_ext4.img !busybox! rm -rf 01-Project\2-New_system\system_ext4.img
if exist 01-Project\2-New_system\vendor_ext4.img !busybox! rm -rf 01-Project\2-New_system\vendor_ext4.img
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Done, see: {0a}1-Finish{#} folder
echo.
call :Limpieza
TIMEOUT /T 3 /nobreak > nul & cls
goto work_place
::Simple re-packing function for .dat compression
:re_pack_dat
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Repacking to: {0a}!format!{#} format...
echo.
bins\ext2simg -v 01-Project\2-New_system\system_ext4.img 01-Project\2-New_system\system.img >nul
TIMEOUT /T 3 /nobreak >nul
if exist 01-Project\2-New_system\vendor_ext4.img bins\ext2simg -v 01-Project\2-New_system\vendor_ext4.img 01-Project\2-New_system\vendor.img >nul
TIMEOUT /T 3 /nobreak >nul
bins\simg2sdat 01-Project\2-New_system\system.img 01-Project\2-New_system >nul
TIMEOUT /T 3 /nobreak >nul
if exist 01-Project\2-New_system\vendor.img bins\simg2sdat 01-Project\2-New_system\vendor.img 01-Project\2-New_system >nul
TIMEOUT /T 3 /nobreak >nul
call :Just_Touch
if exist 01-Project\2-New_system\system_ext4.img !busybox! rm -rf 01-Project\2-New_system\system_ext4.img >nul
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Done, see: {0a}1-Finish{#} folder
echo.
call :Limpieza
TIMEOUT /T 3 /nobreak > nul & cls
goto work_place
::Repacking into stock ext4 raw image
:Repack_IMG
cls
echo.
echo.
echo ".##..##.#####.........######..####...####..##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo ".##..##.#####..######...##...##..##.##..##.##.....";
echo ".##..##.##..##..........##...##..##.##..##.##.....";
echo "..####..##..##..........##....####...####..######.";
echo "..................................................";
echo.
%cecho% Android version: {0a}!release!{#} {03}by JamFlux{#}
echo.
echo.
echo *****************************************************
%cecho% * Working with {0b}!format!{#} ROM:
echo.
%cecho% * {0b}!file!{#}
echo.
echo *****************************************************
echo.
echo.
echo.
%cecho% * Done, see: {0a}1-Finish{#} folder
echo.
call :Limpieza
TIMEOUT /T 3 /nobreak > nul
goto work_place
::It's needed for some reason...
:Just_Touch
!busybox! touch 01-Project\2-New_system\system.new.dat
TIMEOUT /T 3 /nobreak > nul
if exist 01-Project\2-New_system\vendor.new.dat !busybox! touch 01-Project\2-New_system\vendor.new.dat
TIMEOUT /T 3 /nobreak > nul
goto:eof
::Cleaning directories and non needed files
:Limpieza
if not exist 1-Finish mkdir 1-Finish
move /y 01-Project\2-New_system\system.new.dat.br 1-Finish >nul 2>nul
move /y 01-Project\2-New_system\system.new.dat 1-Finish >nul 2>nul
move /y 01-Project\2-New_system\system_ext4.img 1-Finish\system.img >nul 2>nul
move /y 01-Project\2-New_system\system.transfer.list 1-Finish >nul 2>nul
move /y 01-Project\2-New_system\vendor.new.dat.br 1-Finish >nul 2>nul
move /y 01-Project\2-New_system\vendor.new.dat 1-Finish >nul 2>nul
move /y 01-Project\2-New_system\vendor_ext4.img 1-Finish\vendor.img >nul 2>nul
move /y 01-Project\2-New_system\vendor.transfer.list 1-Finish >nul 2>nul
move /y 01-Project\1-Sources\boot.img 1-Finish >nul 2>nul
move /y 01-Project\1-Sources\file_contexts 1-Finish >nul 2>nul
move /y 01-Project\1-Sources\original_symlinks 1-Finish >nul 2>nul
move /y 01-Project\1-Sources\original_permissions 1-Finish >nul 2>nul
if exist 01-Project rmdir /q /s 01-Project >nul 2>nul
goto:eof
::--->Thanks to assayyed for his knowledge
:write_sys_symlinks
if not exist "01-Project\1-Sources\symlinks" for /f "delims=" %%a in ('bins\find 01-Project/system -type l ^| !busybox! sed "s/01-Project//"') do (
for /f "delims=" %%b in ('!busybox! readlink 01-Project%%a') do echo symlink("%%b", "%%a";;;| !busybox! sed "s/;;;/);/">>01-Project\1-Sources\symlinks
)
for /f "delims=" %%a in ('echo "%cd%" ^| !busybox! cut -d":" -f1') do set drive_up=%%a
for /f "delims=" %%a in ('echo "%cd%"^| !busybox! cut -d":" -f2') do set second=%%a
set drive_low=!drive_up!
for %%b in (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO SET drive_low=!drive_low:%%b=%%b!
for /f "delims=" %%a in ('echo \cygdrive\!drive_low!!second!\01-Project\system^| !busybox! tr \\ /') do set rm1=%%a
for /f "delims=" %%a in ('echo \cygdrive\!drive_up!!second!\01-Project\system^| !busybox! tr \\ /') do set rm2=%%a
set rm1=!rm1:/=\/!
set rm2=!rm2:/=\/!
set rm1=!rm1:"=!
set rm2=!rm2:"=!
set symlink_test=0
for /f "delims=" %%a in ('!busybox! grep -cw "symlink" 01-Project/1-Sources/symlinks') do set symlink_test=%%a
if exist "01-Project\system\bin\app_process64" (
!busybox! sed -i '/^symlink("app_process32", "\/system\/bin\/app_process"/d' 01-Project/1-Sources/symlinks
!busybox! sed -i '/^symlink("dalvikvm32", "\/system\/bin\/dalvikvm"/d' 01-Project/1-Sources/symlinks
)
:second
start bins\patchsyms.bat >nul
TIMEOUT /T 5 /nobreak > NUL
:third
if exist "01-Project\1-Sources\symlinks" !busybox! sort -u < "01-Project/1-Sources/symlinks" >> "01-Project/1-Sources/original_symlinks"
goto:eof
:write_vendor_symlinks
if not exist "01-Project\1-Sources\symlinks" for /f "delims=" %%a in ('bins\find 01-Project/vendor -type l ^| !busybox! sed "s/01-Project//"') do (
for /f "delims=" %%b in ('!busybox! readlink 01-Project%%a') do echo symlink("%%b", "%%a";;;| !busybox! sed "s/;;;/);/">>01-Project\1-Sources\vendor_symlinks
)
for /f "delims=" %%a in ('echo "%cd%" ^| !busybox! cut -d":" -f1') do set drive_up=%%a
for /f "delims=" %%a in ('echo "%cd%"^| !busybox! cut -d":" -f2') do set second=%%a
set drive_low=!drive_up!
for %%b in (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO SET drive_low=!drive_low:%%b=%%b!
for /f "delims=" %%a in ('echo \cygdrive\!drive_low!!second!\01-Project\vendor^| !busybox! tr \\ /') do set rm1=%%a
for /f "delims=" %%a in ('echo \cygdrive\!drive_up!!second!\01-Project\vendor^| !busybox! tr \\ /') do set rm2=%%a
set rm1=!rm1:/=\/!
set rm2=!rm2:/=\/!
set rm1=!rm1:"=!
set rm2=!rm2:"=!
set symlink_test=0
for /f "delims=" %%a in ('!busybox! grep -cw "symlink" 01-Project/1-Sources/vendor_symlinks') do set symlink_test=%%a
if exist "01-Project\vendor\bin\app_process64" (
!busybox! sed -i '/^symlink("app_process32", "\/vendor\/bin\/app_process"/d' 01-Project/1-Sources/vendor_symlinks
!busybox! sed -i '/^symlink("dalvikvm32", "\/vendor\/bin\/dalvikvm"/d' 01-Project/1-Sources/vendor_symlinks
)
:second
start bins\v_patchsyms.bat >nul
TIMEOUT /T 5 /nobreak > NUL
:third
if exist "01-Project\1-Sources\vendor_symlinks" !busybox! sort -u < "01-Project/1-Sources/symlinks" >> "01-Project/1-Sources/original_vendor_symlinks"
goto:eof
:write_sys_permissions
!busybox! sed 's/--//g' 01-Project\1-Sources\file_contexts | !busybox! grep "^/system/" | !busybox! sort > 01-Project\1-Sources\system_contexts
!busybox! sed 's/\\\././g; s/\\\+/+/g; s/(\/\.\*)?//g; s/\.\*//g; s/(\.\*)//g' 01-Project\1-Sources\system_contexts | bins\gawk "{ print $1, $NF }" | !busybox! sort > 01-Project\1-Sources\system_contexts2
!busybox! mv 01-Project\1-Sources\system_contexts2 01-Project\1-Sources\system_contexts
if exist "01-Project/1-Sources/file_contexts" for /f "delims=" %%f in ('!busybox! cat "bins\metadata.txt" ^| !busybox! cut -d"""" -f2') do (
set replace=no
for /f "delims=" %%a in ('!busybox! grep -m 1 "%%f " 01-Project\1-Sources\system_contexts ^| bins\gawk "{ print $NF }"') do set replace=%%a
if "!replace!"=="no" set replace=u:object_r:system_file:s0
if exist "01-Project%%f" !busybox! grep -w '"%%f"' bins/metadata.txt | !busybox! sed "s/REPLACE_HERE/!replace!/">>01-Project\1-Sources\rom_permissions
)
for /f "delims=" %%a in ('type 01-Project\1-Sources\system_contexts') do (
for /f "delims=" %%b in ('echo %%a ^| bins\gawk "{print $1}"') do set file2=%%b
for /f "delims=" %%b in ('echo %%a ^| bins\gawk "{print $NF}"') do set contexts=%%b
for /f "delims=" %%v in ('!busybox! grep -cw '"!file2!"' 01-Project/1-Sources/rom_permissions') do set check=%%v
for /f "delims=" %%z in ('echo !file2!') do if "!check!"=="0" if not exist "01-Project\system\bins\%%~nz" if exist "01-Project!file2!" echo set_metadata("!file2!", "capabilities", 0x0, "selabel", "!contexts!";;; | !busybox! sed "s/;;;/);/">>01-Project\1-Sources\rom_permissions
for /f "delims=" %%z in ('echo !file2!') do if exist "01-Project\system\bins\%%~nz" echo set_metadata("!file2!", "uid", 0, "gid", 2000, "mode", 0755, "capabilities", 0x0, "selabel", "!contexts!";;; | !busybox! sed "s/;;;/);/">>01-Project\1-Sources\rom_permissions
)