forked from matriex/System_Extractor-Linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext
executable file
·772 lines (718 loc) · 19.8 KB
/
ext
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
#!/bin/bash
#
# System Extractor Linux
# Copyright (C) 2016-2017 matrixex
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ////////FUNCTIONS/////////
EXT_CHECK() {
if [ ! -e tools ]
then
clear
echo
echo " Folder 'tools' not found , the extractor won't "
echo " work , unless you place it in right place "
exit 0
fi
if [ ! -e ext ]
then
clear
echo
echo " Don't modify or reaname script ext , it is associated "
echo " with all functions/folders , so just do ./ext don't REN"
exit 0
fi
#Check for python - installed OR NOT
#PYTHON IS REQUIRED FOR DAT, SO ITS A MAJOR ISSUE IF NOT PYTHON
CHK=`python --version 2>/dev/null`
if [ $? == 127 ]
then
clear
echo
echo
cecho R " Programe " "Python" " is not installed , please install python"
echo
echo " otherwise extractor will not work properly "
echo
echo " TRY : apt-get install python or your friend GOOGLE"
echo
echo
exit 1
fi
#JAVA , EXT. WILL WORK BUT ZIP SIGN WON'T --MINOR ISSUE
CHK=`java -version 2>/dev/null`
if [ $? == 127 ]
then
clear
echo
echo
echo " JAVA SDK is not installed , please install JAVA"
echo
echo " DEVELOPMENT KIT , it is required to SIGN FILES "
echo
read -p " Ignore and continue (y/n) : " OPTN
if [ $OPTN == y ]
then
L_JAVA=0
EXT_MAIN
else
exit 1
fi
fi
}
#COLOR
#USAGE: cecho TYPE=R|G|Y|B|P|C|W "msg1" "color_msg2" "msg3"
cecho ()
{
#Case didn't work out for me in cygwin
if [ "$1" == "R" ]
then
echo -e "$2""\033[0;91m$3\033[0m""$4" # Red
elif [ "$1" == "G" ]
then
echo -e "$2""\033[0;92m$3\033[0m""$4" # Green
elif [ "$1" == "Y" ]
then
echo -e "$2""\033[0;93m$3\033[0m""$4" # Yellow
elif [ "$1" == "B" ]
then
echo -e "$2""\033[0;94m$3\033[0m""$4" # Blue
elif [ "$1" == "P" ]
then
echo -e "$2""\033[0;95m$3\033[0m""$4" # Purple
elif [ "$1" == "C" ]
then
echo -e "$2""\033[0;96m$3\033[0m""$4" # Cyan
elif [ "$1" == "W" ]
then
echo -e "$2""\033[0;97m$3\033[0m""$4" # White
fi
}
#PAUSE -like batch
WAIT() {
echo
read -p "$1Press enter key to continue . . ."
echo
}
#Extract DAT
E_DAT() {
unset DATE_STR
DATE_STR=`date '+%m-%d-%a_%H-%M-%S'`
#For not conflicting with previous extracted files
#Based on dxdia's kitchen
extract=extract_$DATE_STR
mkdir $extract
clear
echo
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo ":: ::"
echo -e ":: Copy " "\033[0;92msystem.new.dat\033[0m"" , ""\033[0;92msystem.transfer.list\033[0m"" ::"
echo ":: ::"
echo -e "::" " to ""\033[0;97m$extract\033[0m"" folder. ::"
echo ":: ::"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WAIT ""
clear
if [ ! -f $extract/system.new.dat ]
then
echo
cecho R " File" " system.new.dat " "does not exist! "
echo
cecho P " in " "$extract " "folder , try again by "
echo
echo " placing system.new.dat in mentioned folder "
rm -rf $extract
WAIT " "
EXT_MAIN
fi
if [ ! -f $extract/system.transfer.list ]
then
echo
cecho R " File" " system.transfer.list " "does not exist!"
echo
cecho P " in " "$extract " "folder , try again by "
echo
echo " placing system.transfer.list in mentioned folder "
rm -rf $extract
WAIT " "
EXT_MAIN
fi
#Script tesded on Ubuntu
#Modified on 10/16/2016
cd $extract
echo
echo " Found system.new.dat & system.transfer.list"
echo
sleep 0.5
echo " converting system.new.dat to system.img "
cp ../tools/UNI/sdat2img.py .
python sdat2img.py system.transfer.list system.new.dat system.img
echo
if [ -f system.img ] #IF-2
then
rm -f system.new.dat
rm -f system.transfer.list
rm -f sdat2img.py
echo " Successfully Converted into System.img"
sleep 1
if [ `uname | grep Linux` ] #IF-1
then
echo
cecho W "" " Mounting system.img to output folder"
echo
read -p " Hit Enter to continue to mount"
echo
if [ ! -e output ]
then
mkdir output
fi
#IN Ubuntu mount worked but in other OS
#IDK it will or will not work
sudo mount -t ext4 -o loop system.img output/
if [ $? == 0 ]
then
echo
echo " DONE! Mounted system.img in output folder"
echo
cd ..
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
EXT_MAIN
else
echo
echo " Mount Failed Please try another method!"
echo
cd ..
WAIT " "
EXT_MAIN
fi
elif [ `uname | grep CYGWIN` ]
then
cp ../tools/Cygwin/ImgExtractor.exe .
echo
cecho W "" " Converting system.img to system_ folder"
sleep 2
./ImgExtractor.exe system.img -i
if [ -e system_ ]
then
rm -f ImgExtractor.exe
echo
echo " Extracted system.img to system_ folder"
echo
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
echo
echo
cd ..
EXT_MAIN
fi
fi #FI-1
fi #FI-2
}
#Extract OREO: DAT.BR +VENDOR
E_OREO() {
unset DATE_STR
DATE_STR=`date '+%m-%d-%a_%H-%M-%S'`
#For not conflicting with previous extracted files
#Based on dxdia's kitchen
extract=extract_$DATE_STR
mkdir $extract
clear
echo
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo ":: ::"
echo -e ":: Copy " "\033[0;92msystem.new.dat.br\033[0m"" , ""\033[0;92msystem.transfer.list\033[0m"" ::"
echo -e ":: (and " "\033[0;92mvendor.new.dat.br\033[0m"" , ""\033[0;92mvendor.transfer.list\033[0m"") ::"
echo ":: ::"
echo -e "::" " to ""\033[0;97m$extract\033[0m"" folder. ::"
echo ":: ::"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WAIT ""
clear
if [ ! -f $extract/system.new.dat.br ]
then
echo
cecho R " File" " system.new.dat.br " "does not exist! "
echo
cecho P " in " "$extract " "folder , try again by "
echo
echo " placing system.new.dat.br in mentioned folder "
rm -rf $extract
WAIT " "
EXT_MAIN
fi
if [ ! -f $extract/system.transfer.list ]
then
echo
cecho R " File" " system.transfer.list " "does not exist!"
echo
cecho P " in " "$extract " "folder , try again by "
echo
echo " placing system.transfer.list in mentioned folder "
rm -rf $extract
WAIT " "
EXT_MAIN
fi
if [ -f $extract/vendor.new.dat.br ] && [ ! -f $extract/vendor.transfer.list ]
then
echo
cecho R " File" " vendor.transfer.list " "is missing!"
echo
cecho P " Remember to also put it into " "$extract" "folder"
rm -rf $extract
WAIT " "
EXT_MAIN
fi
#Script tested on Ubuntu
#Modified on 10/16/2016
cd $extract
if [ -f vendor.new.dat.br ]
then
echo "Vendor image detected. Decompressing with Brotli..."
brotli -jd -o system.new.dat system.new.dat.br & \
brotli -jd -o vendor.new.dat vendor.new.dat.br
else
echo "Decompressing System with Brotli..."
brotli -jd -o system.new.dat system.new.dat.br
fi
if [ -f vendor.new.dat.br ] && [ ! -s vendor.new.dat ]
then sleep 15 #still unpacking?
fi
echo
if [ -f vendor.new.dat ]
then echo " Found vendor.new.dat & vendor.transfer.list"
fi
echo " Found system.new.dat & system.transfer.list"
echo
sleep 0.5
if [ -f vendor.new.dat ]
then
echo " converting vendor.new.dat to vendor.img "
python2 ../tools/UNI/sdat2img.py vendor.transfer.list vendor.new.dat vendor.img
if e2fsck -nv vendor.img
then
rm vendor.new.dat
echo " Successfully Converted into Vendor.img"
sleep 1
if [ $(uname | grep Linux) ]
then
echo
cecho W "" " Mounting vendor.img to vendor_ folder"
echo
read -p " Hit Enter to continue to mount"
echo
if [ ! -e vendor_ ]
then mkdir vendor_
fi
#TODO: This requires user input(
sudo mount -t ext4 -o loop vendor.img vendor_/
if [ $? == 0 ]
then
echo
echo " Half done! Mounted vendor.img to vendor_!"
echo
else
echo
echo " Vendor mount failed! Try it yourself. "
echo " ex: udisksctl loop-setup -f vendor.img"
echo
fi
fi
fi
fi
echo " converting system.new.dat to system.img "
cp ../tools/UNI/sdat2img.py .
python sdat2img.py system.transfer.list system.new.dat system.img
echo
if [ -f system.img ] #IF-2
then
rm -f system.new.dat
rm -f sdat2img.py
echo " Successfully Converted into System.img"
sleep 1
if [ `uname | grep Linux` ] #IF-1
then
echo
cecho W "" " Mounting system.img to system_ folder"
echo
read -p " Hit Enter to continue to mount"
echo
if [ ! -e system_ ]
then
mkdir system_
fi
#IN Ubuntu mount worked but in other OS
#IDK it will or will not work
sudo mount -t ext4 -o loop system.img system_/
if [ $? == 0 ]
then
echo
echo " DONE! Mounted system.img in system_ folder"
echo
cd ..
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
EXT_MAIN
else
echo
echo " Mount Failed Please try another method!"
echo
cd ..
WAIT " "
EXT_MAIN
fi
elif [ `uname | grep CYGWIN` ]
then
cp ../tools/Cygwin/ImgExtractor.exe .
echo
cecho W "" " Converting system.img to system_ folder"
sleep 2
./ImgExtractor.exe system.img -i
if [ -e system_ ]
then
rm -f ImgExtractor.exe
echo
echo " Extracted system.img to system_ folder"
echo
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
echo
echo
cd ..
EXT_MAIN
fi
fi #FI-1
fi #FI-2
}
#Unmount output - mounted while extracting DAT
UN_MNT() {
clear
echo
echo " This section is for Unmounting output folder "
echo
echo " which is mounted during extraction of DAT"
echo
read -p " Hit enter to continue"
if [ -e "$extract/output" ]
then
clear
cd $extract
echo " Trying to Unmount system.img IF MOUNTED in output folder"
echo
read -p " Hit enter to try "
echo
#ROOT IS REQUIRED
sudo umount output/
echo
echo " DONE "
echo
read enter
cd ..
EXT_MAIN
fi
}
#Repack DAT to system
R_DAT() {
echo "UNDER CONST."
clear
unset DATE_STR
DATE_STR=`date '+%m-%d-%a_%H-%M-%S'`
#For not conflicting with previous extracted files
#Based on dxdia's kitchen
ROM=ROM_$DATE_STR
mkdir $ROM
echo
echo
cecho G " Creating folder" " `pwd`/$ROM"
echo
cecho C " Place your" " system " "folder into the $ROM " "folder"
echo
WAIT " "
cd $ROM
if [ -e system/app ]
then
echo
read -p " Enter size in MB :" M_BYTE
#1MB == 1048576
SIZE="$(($M_BYTE*1048576))"
echo $SIZE bytes
./make_ext4fs -T 0 -S file_contexts -l $SIZE -a system system_new.img output/
fi
FILENAME=`find *.* 2>/dev/null`
SIZE=$(du -sb $FILENAME | awk '{print $1}')
}
#IMAGE MENU MOUNT, UNMOUNT etc
IMG() {
echo "UNDER CONST."
}
#ROM - ZIP SIGN
SIGN_ZIP() {
if [ "$L_JAVA" == "0" ]
then
clear
echo
echo
echo " JAVA IS NOT INSTALLED , So zip signing will "
echo
echo " not work unless you install JAVA SE DEVLOPMENT"
echo
echo " -KIT 7 or higher, on your current OS/platform "
echo
read -p ""
EXT_MAIN
fi
#Script Starts here
clear
echo
unset DATE_STR
DATE_STR=`date '+%m-%d-%a_%H-%M-%S'`
sign_files=sign_$DATE_STR
#This sign_-->"date"<-- is for not conflicting with previously
#created folder
mkdir $sign_files
echo
echo " This section is only for ZIP sign of ROM or any other"
echo
echo " ZIP which contain META-INF folder NOT for apk signing"
echo
echo " Also one zip at a time, don't place multiple zips "
echo
cecho W "" " ZIP FILE MUST NOT CONTAIN SPACE"
sleep 1
echo
cecho G " Creating folder" " `pwd`/$sign_files"
echo
cecho C " Copy your ZIP file into the" " $sign_files " "folder"
WAIT
cd $sign_files
ZIP_N=`find *.zip 2>/dev/null`
if [ $? == 0 ]
then
clear
cp ../tools/UNI/SIGN_TOOLS/testkey.* .
cp ../tools/UNI/SIGN_TOOLS/signapk.jar .
echo
echo
echo " Signing $ZIP_N .... "
ZIP_F="signed_$ZIP_N"
java -jar signapk.jar testkey.x509.pem testkey.pk8 $ZIP_N $ZIP_F
if [ $? == 0 ]
then
rm -f testkey.*
rm -f signapk.jar
rm -f $ZIP_N
echo
echo
echo " SIGNED $ZIP_F "
echo
cecho G "" " Found in `pwd`/$sign_files" " folder"
cd ..
WAIT
EXT_MAIN
else
clear
echo
cecho R "" " Signing failed "
echo
echo " Possible reasons :"
echo
echo " 1) Java not installed properly , PATH to java"
echo " is not set, try typing java in terminal "
echo
echo " 2) Zip file does not contain META-INF folder "
echo
echo " 3) Corrupted ZIP file "
echo
echo " That's all , try again"
cd ..
rm -rf $sign_files
WAIT
EXT_MAIN
fi
elif [ $? == 1 ]
then
clear
echo
echo
cecho R " NO " "ZIP" " FILE FOUND"
rm -rf $sign_files
WAIT
EXT_MAIN
else
clear
echo
cecho R "" " UNKNOWN REASON "
echo
echo " Either copy your zip file to sign_folder "
echo
echo " or Use a different zip file "
WAIT
EXT_MAIN
fi
}
#START - HOME
EXT_START() {
clear
echo
echo
cecho W "" " Marshmallow/Lollipop "
cecho W "" " System extractor & repack "
cecho G " (" "by matrix" ")"
cecho C "" " $DATE_STR"
echo
cecho W "" " Menu"
echo
cecho C " 1 - " "Unpack" " system.new.dat.br (and vendor.new.dat.br)"
echo
cecho C " 2 - " "Unpack" " system.new.dat"
echo
cecho C " 3 - " "Repack" " system.new.dat"
echo
cecho C " 4 - " "Unpack" " system.img"
echo
cecho C " 5 - " "Sign" " ZIP files"
echo
cecho C " u - " "Unmount" " output"
echo
cecho C " x - " "Exit"
echo
echo
}
E_SYS() {
unset DATE_STR
DATE_STR=`date '+%m-%d-%a_%H-%M-%S'`
#For not conflicting with previous extracted files
#Based on dxdia's kitchen
extract=extract_$DATE_STR
mkdir $extract
clear
echo
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo ":: ::"
echo -e ":: Copy " "\033[0;92msystem.img\033[0m"" ::"
echo ":: ::"
echo -e "::" " to ""\033[0;97m$extract\033[0m"" folder. ::"
echo ":: ::"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WAIT ""
clear
if [ ! -f $extract/system.img ]
then
echo
cecho R " File" " system.img " "does not exist! "
echo
cecho P " in " "$extract " "folder , try again by "
echo
echo " placing system.img in mentioned folder "
rm -rf $extract
WAIT " "
EXT_MAIN
fi
cd $extract
echo
echo " Found system.img"
echo
sleep 0.5
echo " converting system.img to system.raw.img "
if [ `uname | grep Linux` ] #IF-1
then
cp ../tools/UNI/simg2img .
./simg2img system.img system.raw.img
elif [ `uname | grep CYGWIN` ]
then
cp ../tools/Cygwin/simg2img.exe .
./simg2img.exe system.img system.raw.img
fi
echo
if [ -f system.raw.img ] #IF-2
then
rm -f system.img
rm -f simg2img simg2img.exe
echo " Successfully Converted into System.raw.img"
sleep 1
if [ `uname | grep Linux` ] #IF-1
then
echo
cecho W "" " Mounting system.raw.img to output folder"
echo
read -p " Hit Enter to continue to mount"
echo
if [ ! -e output ]
then
mkdir output
fi
#IN Ubuntu mount worked but in other OS
#IDK it will or will not work
sudo mount -t ext4 -o loop system.raw.img output/
if [ $? == 0 ]
then
echo
echo " DONE! Mounted system.raw.img in output folder"
echo
cd ..
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
EXT_MAIN
else
echo
echo " Mount Failed Please try another method!"
echo
cd ..
WAIT " "
EXT_MAIN
fi
elif [ `uname | grep CYGWIN` ]
then
cp ../tools/Cygwin/ImgExtractor.exe .
echo
cecho W "" " Converting system.raw.img to system_ folder"
sleep 2
./ImgExtractor.exe system.raw.img -i
if [ -e system_ ]
then
rm -f ImgExtractor.exe
echo
echo " Extracted system.raw.img to system_ folder"
echo
read -p " ALL DONE HIT ENTER TO CONTINUE TO MENU"
echo
echo
cd ..
EXT_MAIN
fi
fi
fi
}
#MENU
EXT_MAIN() {
while :
do
clear
unset DATE_STR
DATE_STR=`date '+%m-%d-%y'`
EXT_START
read -p "Enter option: " CHOICE
case "$CHOICE" in
1) E_OREO ;; #CONTRIB
2) E_DAT ;; #DONE
3) clear ; echo NOT YET DONE ; exit ;;
4) E_SYS ;;
5) SIGN_ZIP ;; #DONE
u|U) UN_MNT ;; #DONE
X|x) clear; echo; echo "Thanks for using."; echo; exit 1;;
*) cecho R "" " Invalid option"; sleep 0.3; continue;;
esac
done
}
#DEPLOYING function
EXT_CHECK
EXT_MAIN