-
Notifications
You must be signed in to change notification settings - Fork 116
/
libbash.so
2403 lines (1995 loc) · 68.2 KB
/
libbash.so
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
#!/system/bin/sh
AGVARR="$@"; SCRIPT="$0"; AGV1="$1"; AGV2="$2"; AGV3="$3"; AGV4="$4"; AGV5="$5"; exec 2>/dev/null; MYSCRIPT="$(realpath "$0")"; MYPATH="${MYSCRIPT%/*}"; busybox="$MYPATH/libbusybox.so"; PATH="$MYPATH:$PATH:/sbin:/system/bin:/system/xbin"; cmds="$SCRIPT $AGVARR"
unset LD_PRELOAD
if [ ! -f "$MYPATH/libbusybox.so" ]; then
echo "Missing libbusybox.so"; exit 1
fi
chmod 775 "$MYPATH/"*
RC='\033[0m' RED='\033[0;31m' BRED='\033[1;31m' GRAY='\033[1;30m' BLUE='\033[0;34m' BBLUE='\033[1;34m' CYAN='\033[0;34m' CYAN='\033[1;34m' WHITE='\033[1;37m' GREEN='\033[0;32m' BGREEN='\033[1;32m' YELLOW='\033[1;33m' PURPLE='\033[0;35m' BPURPLE='\033[1;35m' ORANGE='\033[0;33m'
# Get user id
test -z "$USER_ID" && USER_ID="$(id -u)"
# Get system information
API=$(getprop ro.build.version.sdk)
ABI=$(getprop ro.product.cpu.abi)
if [ "$ABI" = "x86" ]; then
ARCH=x86
ABI32=x86
IS64BIT=false
elif [ "$ABI" = "arm64-v8a" ]; then
ARCH=arm64
ABI32=armeabi-v7a
IS64BIT=true
elif [ "$ABI" = "x86_64" ]; then
ARCH=x64
ABI32=x86
IS64BIT=true
else
ARCH=arm
ABI=armeabi-v7a
ABI32=armeabi-v7a
IS64BIT=false
fi
DEVICE_API="$API"
DEVICE_ABI="$ABI"
DEVICE_ARCH="$ARCH"
DEVICE_ABI32="$ABI32"
DEVICE_64BIT="$IS64BIT"
# Detect if system is in live mode or not
BOOTMODE=false
if pidof zygote &>/dev/null || [ "$USER_ID" != 0 ]; then
BOOTMODE=true
fi
SYSTEM_AS_ROOT=true
# If BOOTMODE=true that mean system is in live mode, root dir will be "/", overwise in recovery mode, root dir will be /android
if $BOOTMODE; then
ROOTDIR=/
else
ROOTDIR=/android
fi
# detect if system boot type is system-as-root or not
if mount -t rootfs | grep -q " $ROOTDIR " || mount -t tmpfs | grep -q " $ROOTDIR "; then
SYSTEM_AS_ROOT=false
fi
magisk_name="magisk32"
[ "$IS64BIT" == true ] && magisk_name="magisk64"
help(){
echo "Magisk Installer script for emulator
usage: inmagisk [OPTION]
Available option:
install Open Menu for install Magisk
install:<build> Install/Update Magisk
uninstall Uninstall Magisk and its modules"
}
ui_print(){ echo -e "$1"; }
cre(){
echo -ne "${GRAY}@$1${RC}"
}
####################
# ENGLISH
####################
text_press_enter_menu="PRESS ENTER TO BACK TO MENU"
text_cannot_mm="Cannot install or this app is adready installed"
text_success_mm="Install success!"
text_warn_uninstall_magisk="Do you want to uninstall Magisk?"
text_done="Done!"
text_saved_magisk_apk_to="Saved Magisk APK to"
text_mount_rw_system="Mount system partition (Read-write)"
text_mount_ro_system="Mount system partition (Read-only)"
text_obtain_root="Obtain ROOT access..."
text_obtain_root_failed="Cannot obtain ROOT access"
text_recommended="Recommended"
text_install_app="Install Magisk app"
text_install_app_sug="Please install Magisk app by yourself"
text_install="Install"
text_setup="Initialize Magisk Core"
text_rm_magisk_files="Remove magisk additional files"
text_extract_magisk_apk="Extract Magisk APK"
text_failed_mount_system="Looks like the system partition is locked at read-only"
text_enter_magisk_apk="Enter path to your Magisk APK"
text_example="Example"
text_unpack_ramdisk="Unpack the ramdisk image"
text_unpack_ramdisk_fail="Unable to unpack the ramdisk image"
text_patch_ramdisk="Patching ramdisk image"
text_repack_ramdisk="Repack new ramdisk image"
text_repack_ramdisk_fail="Unable to repack new ramdisk image"
text_enter_path_ramdisk="Enter path to your ramdisk"
text_new_ramdisk="New ramdisk image was saved to"
text_uninstall_fail="! No Magisk found on system or GearLock"
text_cannot_mount_part="Unable to mount the partition!"
text_wrong_input="Wrong input, please enter again correctly"
text_enter_part="Enter the ${BGREEN}partition${RC} number where you got this ${BPURPLE}Android-x86 OS${RC} installed"
text_enter_ramdisk="Enter the ${BGREEN}ramdisk.img${RC} number from this ${BPURPLE}Android-x86 OS${RC}"
text_unpatch_ramdisk="Remove patch with magisk from ramdisk"
text_backup_not_exist="Backup not exist, cannot uninstall"
text_uninstall_magisk_in="Uninstall Magisk from system and GearLock"
text_restore_original_ramdisk="Restore ramdisk back to original"
text_choice=CHOICE
text_run_with_root="Run script with root access"
text_cannot_install_magisk="Unable to install Magisk!"
text_cannot_uninstall_magisk="Unable to uninstall Magisk!"
text_added_bs_module="Added Bluestacks Fix Magisk modules"
text_magisk_patched_ramdisk="Magisk patched ramdisk image detected"
text_saved_ramdisk_info="Saved ramdisk information to"
text_unsupport_ramdisk_format="Unsupported ramdisk format"
text_tell_remove_rusty_magisk="You may have rust-magisk installed, please remove it if present!!!"
text_magisk_tmpfs_directory="Magisk tmpfs path"
text_use_current_ramdisk_info="Do you want to use the current ramdisk information"
text_install_gearlock="Please install GearLock first"
text_building_gxp="Build GearLock extension"
text_saved_magisk_gxp_to="Saved extension to"
text_uninstalling_magisk="Uninstalling Magisk"
text_system_not_writeable="System is not writeable! Cannot completely uninstall."
text_grant_inter_access_permission="Please grant app the permission to access Internal Storage"
text_select_magisk_app="Select Magisk version you want to install"
text_guide_rm_magisk_app="Type \"rm\" with a number to delete target version"
text_ask_keep_modules="Do you want to preserve modules (Only remove Magisk)?"
text_cannot_detect_target_ramdisk="Unable to detect target ramdisk"
text_find_ramdisk_auto="It's difficult to detect target ramdisk correctly.
Do you want to automatically find the target ramdisk?"
text_enter_url="Custom link"
text_exported_apk="Exported Magisk apk into [Internal Storage]/Magisk"
text_export_apk_fail="Cannot export Magisk apk. Did you grant me permission?"
text_installation_ended="Installation ended. Press Enter to continue"
text_cannot_mm_recovery="Can't install app from Recovery Mode"
print_ramdisk_method(){
pd "light_cyan" "Install Magisk into ramdisk image"
echo " 1 - Direct install"
echo " 2 - Select ramdisk image and patch"
echo -n "[CHOICE]: "
}
print_unpatch_ramdisk(){
pd "light_cyan" "Remove Magisk in ramdisk"
echo " 1 - Direct uninstall"
echo " 2 - Select ramdisk image and patch"
echo -n "[CHOICE]: "
}
print_gxp_method(){
pd "light_cyan" "Install Magisk by using GearLock"
echo " 1 - Direct install"
echo " 2 - Export GearLock extension (GXP)"
echo -n "[CHOICE]: "
}
blissos_open_menu(){
echo -e "- If you are using ${BPURPLE}Bluestacks${RC} emulator"
echo -e "You can use ${BGREEN}BSTweaker 6.8.5+${RC} to enable Root access"
pd none "- If you are using ${BPURPLE}Android x86${RC} (BlissOS)"
pd none "You can press ${BGREEN}Alt+F1${RC} and type this command:"
}
print_info(){
if $BOOTMODE; then
p none " Magisk: "; $hasMagisk && pd light_green "$(magisk -v) ($(magisk -V))" || pd light_red "Not found"
p none " Android Level: "; [ "$SDK" -lt "28" ] && pd light_red "$SDK" || pd light_green "$SDK"
else
pd light_blue " Recovery Mode"
fi
p none " System-as-root: "; [ "$SYSTEM_AS_ROOT" == "true" ] && pd light_green "$SYSTEM_AS_ROOT" || pd light_red "$SYSTEM_AS_ROOT"
}
warn_reboot(){
echo " The device will reboot after a few seconds"
pd yellow " IF THE EMULATOR FREEZES, SIMPLY JUST REBOOT IT"
}
disable_magisk(){
[ -f "$DLPATH/disable" ] && p light_red "[ON]" || p light_red "[OFF]"
}
disable_magisk_process(){
[ -f "$DLPATH/disable" ] && rm -rf "$DLPATH/disable" || touch "$DLPATH/disable"
}
need_root_access(){
[ "$(whoami)" == "root" ] || abortc light_red "! Need root access to perform this action"
}
print_menu(){
pd gray "=============================================="
echo " Magisk Installer Script for Android-x86 and Emulator"
echo " Written by HuskyDG - Free to use"
# please don't change this or use "by HuskyDG + your name" for credits :((
echo -e "$(print_info)"
pd gray "=============================================="
echo " 1 - Install/Update Magisk"
pd gray " Integrate Magisk root into Android x86 emulator"
echo " 2 - Uninstall Magisk"
pd gray " Remove Magisk and its modules"
echo " 3 - Remove all other root methods"
pd gray " Only use if you cannot find Disable root option"
echo "----------"
echo " 0 - Exit menu"
p none "[CHOICE]: "
}
print_method(){
pd gray "=============================================="
echo " Install/Update Magisk"
pd gray "=============================================="
pd light_cyan "Install Magisk method"
echo " 1 - Install Magisk into \"/system\""
pd gray " The system partition must be mounted as read-write"
pd gray " Recommended for Android Emulator such as NoxPlayer, MuMu, ..."
echo " 2 - Install Magisk into ramdisk.img/initrd.img (systemless)"
pd gray " Use this option if you can find ramdisk.img"
pd gray " Recommended for Android x86 project"
echo " 3 - Install Magisk by using GearLock (system/systemless)"
pd gray " Use GearLock to active Magisk"
pd gray " Recommended for Android x86 project"
echo "----------"
echo " e - Export Magisk apk"
echo " 0 - Exit menu"
pd light_red "* Note: Uninstall rusty-magisk to avoid conflicts"
p none "[CHOICE]: "
}
print_magisk_builds(){
echo " 1 - Canary `cre topjohnwu`"
echo " 2 - Canary `cre TheHitMan7`"
echo " 3 - Stable `cre topjohnwu`"
echo " e - $text_enter_url"
}
print_menu_install(){
pd gray "=============================================="
echo " Install/Update Magisk"
pd gray "=============================================="
pd light_cyan "ONLINE"
print_magisk_builds
pd light_cyan "OFFLINE"
echo " a - Stable v24.1"
echo " x - Choose and install from another Magisk APK"
echo " z - Select downloaded Magisk APK"
pd green "* Please check my wiki page to select suitable Magisk build"
p none "[CHOICE]: "
}
####################
# TIẾNG VIỆT
####################
language_vn(){
text_press_enter_menu="NHẤN ENTER ĐỂ TRỞ VỀ MENU"
text_cannot_mm="Không thể cài đặt hoặc ứng dụng đã được cài đặt"
text_success_mm="Cài đặt thành công!"
text_warn_uninstall_magisk="Bạn có muốn gỡ cài đặt Magisk?"
text_ask_keep_modules="Bạn có muốn giữ lại các mô-đun không (Chỉ gỡ Magisk)?"
text_done="Đã xong!"
text_saved_magisk_apk_to="Đã lưu Magisk APK vào"
text_mount_rw_system="Gắn kết phân vùng system (Đọc-ghi)"
text_mount_ro_system="Gắn kết phân vùng system (Chỉ đọc)"
text_obtain_root="Đang lấy quyền ROOT.."
text_obtain_root_failed="Không thể lấy quyền ROOT"
text_recommended="Đề xuất"
text_install_app="Cài đặt ứng dụng Magisk"
text_install_app_sug="Vui lòng cài đặt ứng dụng Magisk thủ công"
text_install="Cài đặt"
text_setup="Thiết lập lõi Magisk"
text_rm_magisk_files="Loại bỏ các tệp bổ sung của Magisk"
text_extract_magisk_apk="Giải nén Magisk APK"
text_failed_mount_system="Gắn kết phân vùng system thất bại"
text_enter_magisk_apk="Nhập đường dẫn tới tệp Magisk APK của bạn"
text_example="Ví dụ"
text_unpack_ramdisk="Giải nén đĩa ảnh ramdisk"
text_unpack_ramdisk_fail="Không thể giải nén đĩa ảnh!"
text_patch_ramdisk="Đang vá đĩa ảnh ramdisk"
text_repack_ramdisk="Đóng gói lại với đĩa ảnh ramdisk mới"
text_repack_ramdisk_fail="Không thể đóng gói đĩa ảnh!"
text_enter_path_ramdisk="Nhập đường dẫn đến đĩa ảnh ramdisk.img"
text_new_ramdisk="Đĩa ảnh ramdisk mới đã lưu vào"
text_uninstall_fail="! Không tìm thấy Magisk trên hệ thống"
text_cannot_mount_part="Không thể gắn kết phân vùng!"
text_wrong_input="Sai dữ liệu, vui lòng nhập lại"
text_enter_part="Nhập số với ${BGREEN}phân vùng${RC} mà bạn đã cài đặt ${BPURPLE}Android-x86 OS${RC} này"
text_enter_ramdisk="Nhập số tương ứng với ${BGREEN}ramdisk.img${RC} từ ${BPURPLE}Android-x86 OS${RC}"
text_unpatch_ramdisk="Loại bỏ bản vá với magisk khỏi ramdisk"
text_unpatch_ramdisk="Loại bỏ bản vá Magisk khỏi ramdisk"
text_backup_not_exist="Bản sao lưu không tồn tại, không thể gỡ"
text_uninstall_magisk_in="Gỡ bỏ Magisk khỏi hệ thống và GearLock"
text_restore_original_ramdisk="Khôi phục ramdisk trở lại ban đầu"
text_choice="CHỌN"
text_run_with_root="Chạy script với quyền root"
text_cannot_install_magisk="Không thể cài đặt Magisk!"
text_cannot_uninstall_magisk="Không thể gỡ cài đặt Magisk!"
text_added_bs_module="Đã thêm Magisk mô-đun Bluestacks Fix"
text_magisk_patched_ramdisk="Đã phát hiện ramdisk đã vá với Magisk "
text_saved_ramdisk_info="Đã lưu thông tin ramdisk vào"
text_unsupport_ramdisk_format="Định dạng ramdisk không được hỗ trợ"
text_tell_remove_rusty_magisk="Bạn có thể đã cài rusty-magisk, vui lòng hãy gỡ nó nếu có!!!"
text_magisk_tmpfs_directory="Đường dẫn Magisk tmpfs"
text_use_current_ramdisk_info="Bạn có muốn sử dụng thông tin ramdisk hiện tại?"
text_install_gearlock="Hãy cài đặt GearLock trước đã"
text_building_gxp="Xây dựng phần mở rộng GearLock"
text_saved_magisk_gxp_to="Đã lưu phần mở rộng vào"
text_uninstalling_magisk="Đang gỡ bỏ Magisk"
text_system_not_writeable="Hệ thống không thể ghi! Không thể gỡ bỏ hoàn toàn"
text_grant_inter_access_permission="Vui lòng cung cấp cho ứng dụng quyền truy cập Bộ nhớ trong"
text_select_magisk_app="Lựa chọn phiên bản Magisk mà bạn muốn cài đặt"
text_guide_rm_magisk_app="Gõ \"rm\" với 1 con số để xóa phiên bản tương ứng"
text_find_ramdisk_auto="Rất khó để phát hiện ramdisk đích một cách chính xác.
Bạn có muốn tìm ramdisk tự động không?"
text_enter_url="Liên kết tùy chỉnh"
text_exported_apk="Đã xuất Magisk apk vào [Bộ nhớ trong]/Magisk"
text_export_apk_fail="Không thể xuất Magisk apk. Bạn đã cấp quyền truy cập chưa?"
text_installation_ended="Quá trình cài đặt đã kết thúc. Nhấn Enter để tiếp tục"
text_cannot_mm_recovery="Không thể cài đặt ứng dụng từ chế độ Recovery"
need_root_access(){
[ "$(whoami)" == "root" ] || abortc light_red "! Cần quyền truy cập root để thực hiện hành động này"
}
print_ramdisk_method(){
pd "light_cyan" "Cài đặt Magisk vào đĩa ảnh ramdisk"
echo " 1 - Cài đặt trực tiếp"
echo " 2 - Chọn đĩa ảnh ramdisk và vá"
echo -n "[CHỌN]: "
}
print_gxp_method(){
pd "light_cyan" "Cài đặt Magisk bằng GearLock"
echo " 1 - Cài đặt trực tiếp"
echo " 2 - Tạo tệp mở rộng GearLock (GXP)"
echo -n "[CHỌN]: "
}
print_unpatch_ramdisk(){
pd "light_cyan" "Loại bỏ Magisk khỏi ramdisk"
echo " 1 - Gỡ cài đặt trực tiếp"
echo " 2 - Chọn đĩa ảnh ramdisk và vá"
echo -n "[CHỌN]: "
}
warn_reboot(){
echo " Thiết bị sẽ khởi động trong vài giây nữa"
echo " NẾU HỆ THỐNG KHÔNG PHẢN HỒI, VUI LÒNG KHỞI ĐỘNG LẠI"
}
print_menu(){
pd gray "=============================================="
echo " Magisk on Android x86"
echo " by HuskyDG"
# please don't change this or use "by HuskyDG + your name" for credits :((
echo -e "$(print_info)"
pd gray "=============================================="
echo " 1 - Cài đặt hoặc cập nhật Magisk"
pd gray " Triển khai Magisk root vào Android-x86"
echo " 2 - Gỡ cài đặt Magisk"
pd gray " Loại bỏ Magisk và các mô-đun của nó"
echo " 3 - Loại bỏ các phương pháp ROOT khác"
pd gray " Chỉ sử dụng khi bạn không tìm thấy tùy chọn để tắt Root"
echo "----------"
echo " 0 - Thoát khỏi menu"
p none "[CHỌN]: "
}
blissos_open_menu(){
echo -e "- Nếu bạn đang sử dụng giả lập ${BPURPLE}Bluestacks${RC}"
echo -e "Bạn có thể sử dụng ${BGREEN}BSTweaker 6.8.5+${RC} để bật quyền Root"
pd none "- Nếu bạn đang sử dụng ${BPURPLE}Android x86${RC} như BlissOS";
pd none "Bạn có thể nhấn ${BGREEN}ALT+F1${RC} và gõ dòng lệnh:"
}
print_menu_install(){
pd gray "=============================================="
echo " Install/Update Magisk"
pd gray "=============================================="
pd light_cyan "TRỰC TUYẾN"
print_magisk_builds
pd light_cyan "NGOẠI TUYẾN"
echo " a - Stable v24.1"
echo " x - Chọn và cài đặt từ Magisk APK khác"
echo " z - Chọn phiên bản Magisk APK đã tải"
pd green "* Vui lòng kiểm tra trang wiki của tôi để chọn bản dựng Magisk phù hợp"
p none "[CHỌN]: "
}
print_method(){
pd gray "=============================================="
echo " Cài đặt hoặc cập nhật Magisk"
pd gray "=============================================="
pd light_cyan "Phương thức cài đặt Magisk"
echo " 1 - Cài đặt Magisk vào \"/system\""
pd gray " Phân vùng hệ thống có thể gắn kết đọc ghi"
pd gray " Khuyên dùng cho các giả lập Android như NoxPlayer, MuMu, ..."
echo " 2 - Cài đặt Magisk vào ramdisk.img hoặc initrd.img (systemless)"
pd gray " Sử dụng tùy chọn này nếu bạn tìm thấy Ramdisk"
pd gray " Khuyên dùng cho Android x86 project"
echo " 3 - Cài đặt Magisk bằng GearLock (system/systemless)"
pd gray " Cần có GearLock, sử dụng GearLock để kích hoạt Magisk"
pd gray " Khuyên dùng cho Android x86 project"
echo "----------"
echo " e - Xuất Magisk apk"
echo " 0 - Thoát khỏi menu"
pd light_red "* Lưu ý: Gỡ bỏ rusty-magisk để tránh bị xung đột"
p none "[CHỌN]: "
}
}
LANGUAGE="$(getprop persist.sys.locale)"
case "$LANGUAGE" in
"vi-VN")
language_vn
;;
esac
####################
# defind remount function
####################
mount_rw_system(){
IS_SYSTEM_MOUNT=false
if mount | grep rootfs | grep -q " / " || mount | grep tmpfs | grep -q " / "; then
# legacy rootfs
mount -o rw,remount "/system" && IS_SYSTEM_MOUNT=true
else
# system-as-root, mount "/"
mount -o rw,remount "/" && IS_SYSTEM_MOUNT=true
fi
}
mount_ro_system(){
IS_SYSTEM_MOUNT=false
if mount | grep rootfs | grep -q " / " || mount | grep tmpfs | grep -q " / "; then
# legacy rootfs
mount -o ro,remount "/system" && IS_SYSTEM_MOUNT=true
else
# system-as-root, mount "/"
mount -o ro,remount "/" && IS_SYSTEM_MOUNT=true
fi
}
####################
# defind print text with color function
####################
p(){
COLOR=$1;TEXT="$2";escape="$1"
[ "$COLOR" == "black" ] && escape="0;30"
[ "$COLOR" == "red" ] && escape="0;31"
[ "$COLOR" == "green" ] && escape="0;32"
[ "$COLOR" == "orange" ] && escape="0;33"
[ "$COLOR" == "blue" ] && escape="0;34"
[ "$COLOR" == "purple" ] && escape="0;35"
[ "$COLOR" == "cyan" ] && escape="0;36"
[ "$COLOR" == "light_gray" ] && escape="0;37"
[ "$COLOR" == "gray" ] && escape="1;30"
[ "$COLOR" == "light_red" ] && escape="1;31"
[ "$COLOR" == "light_green" ] && escape="1;32"
[ "$COLOR" == "yellow" ] && escape="1;33"
[ "$COLOR" == "light_blue" ] && escape="1;34"
[ "$COLOR" == "light_purple" ] && escape="1;35"
[ "$COLOR" == "light_cyan" ] && escape="1;36"
[ "$COLOR" == "white" ] && escape="1;37"
[ "$COLOR" == "none" ] && escape="0"
code="\033[${escape}m"
end_code="\033[0m"
echo -en "$code$TEXT$end_code"
}
pd(){
p "$1" "$2"; echo
}
abortc(){
ERR_CODE="$3"
pd "$1" "$2";
test -z "$ERR_CODE" && ERR_CODE=1
exit "$ERR_CODE"
}
if [ "$AGV1" != "noexec" ]; then
priv_dir=/data/data/magisk.term
[ -d "$priv_dir" ] && ! ls "$priv_dir" &>/dev/null && priv_dir=/data/data/com.termux
[ ! -d "$priv_dir" ] && priv_dir=/data/data/com.termux
[ ! -d "$priv_dir" ] && { echo "Something wrong! Abort"; exit; }
cd "$priv_dir"
DLPATH="$priv_dir/magisk"
if [ ! -d "$DLPATH" ]; then
rm -rf "$DLPATH" 2>/dev/null
mkdir -p "$DLPATH" 2>/dev/null
fi
mkdir "$DLPATH/save"
link(){ (
agv1="$1"; agv2="$2"
[ ! -f "$DLPATH/$agv2" ] && rm -rf "$DLPATH/$agv2" 2>/dev/null
ln -s "$(which "$agv1")" "$DLPATH/$agv2" 2>/dev/null
) }
link "libapp.so" "magisk.apk"
link "libbusybox.so" "busybox"
link "liblegacy.so" "legacy.zip"
link "libbash.so" "menu"
link "libgxp.so" "gearlock_extension.zip"
CACHEDIR="$priv_dir/cache/$$"
DISKINFO="/data/adb/diskinfo"
APKFILE="$JOBPWD/magisk.apk"
MAGISKCORE="/system/etc/init/magisk"
busybox_bin(){
mkdir -p "$DLPATH/bin"
"$busybox" busybox --install -s "$DLPATH/bin"
PATH="$DLPATH/bin:$PATH"
}
hasMagisk=false
[ ! -z "$(which magisk)" ] && [ ! -z "$(magisk -v)" ] && hasMagisk=true
busybox_bin 2>/dev/null
open_main(){
if [ "$AGV1" == "option" ] && [ "$AGV2" == "help" ]; then
help; exit
fi
if [ "$USER_ID" != "0" ]; then
p none "$text_run_with_root ? <Y/n> "
read ROOT
if [ "$ROOT" == "Y" -o "$ROOT" == "y" ]; then
export UNSHARE_MM=0
export ASH_STANDALONE=1
pd yellow "$text_obtain_root..."
( su -c "$cmds" || /system/xbin/su -c "$cmds" || /system/bin/su -c "$cmds" || /sbin/su -c "$cmds" ) 2>/dev/null
ERR_CODE="$?"
if [ "$ERR_CODE" != 0 ]; then
pd "light_red" "$text_obtain_root_failed"
blissos_open_menu
pd light_cyan "$DLPATH/menu"
fi
exit
elif ! [ "$ROOT" == "N" -o "$ROOT" == "n" ]; then
exit
fi
fi
while true; do
main;
done
}
fi
SDK="$(getprop ro.build.version.sdk)"
function cmdline() {
awk -F"${1}=" '{print $2}' < /proc/cmdline | cut -d' ' -f1 2> /dev/null
}
umount_magic_mods(){
# make sure there are no overlay under /system
# overwise we are write to virtual read-write system not real system partition
while mount -t overlay | grep -q " /system "; do
umount -l /system
done
# umount magic mount if some modules mount some files into these path
# because add files into these directory is useless
# if we don't umount it, we might write to magisk created tmpfs mountpoint or magisk module directory
local list_files="/system/etc
/system/etc/*
/system/addon.d
/system/addon.d/*
/system/etc/magisk
/system/etc/init
/system/etc/magisk/*
/system/etc/init/*
/magisk
/magisk/*"
for file in $list_files; do
while true; do
umount $list_files || break;
done
done
}
get_magisk_path(){
# get some information from magisk
MAGISK_TMP="$(magisk --path)"
MAGISKDIR="$MAGISK_TMP/.magisk"
if [ "$MAGISK_TMP" ]; then
MAGISK_MIRROR="$MAGISKDIR/mirror"
PATH="$MAGISK_TMP:$PATH"
fi
# SYSTEMDIR="/system"
# SYSTEMROOTDIR="/"
# [ "$MAGISK_TMP" ] && SYSTEMROOTDIR="/system_root"
# umount to make sure there are no magisk module mount on these folder
( umount_magic_mods ) &
# no need to use Magisk's mirror anymore
SYSTEMDIR="/system"
SYSTEMROOTDIR="/"
}
# This script is write by HuskyDG
ARG1="$1"
JOBPWD="${0%/*}"
bb=/data/local/tmp/busybox
get_tmpdir(){
TMPDIR="$CACHEDIR"
[ "$USER_ID" == "0" ] && TMPDIR=/dev/tmp
}
get_tmpdir
abort(){
ERR_CODE="$2"
echo "$1";
test -z "$ERR_CODE" && ERR_CODE=1
exit "$ERR_CODE"
}
gxp_template="$DLPATH/gearlock_extension.zip"
unshare_environment(){
if [ ! "$UNSHARE_MM" == "1" ]; then
export UNSHARE_MM=1
export ASH_STANDALONE=1
"$busybox" unshare -m "$busybox" sh -o standalone "$SCRIPT" "$AGV1" "$AGV2" "$AGV3" "$AGV4" "$AGV5"
exit
fi
}
[ "$USER_ID" == "0" ] && unshare_environment 2>/dev/null
[ "$USER_ID" == "0" ] && get_magisk_path
ISENCRYPTED=false
grep ' /data ' /proc/mounts | grep -q 'dm-' && ISENCRYPTED=true
[ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true
stable_magisk_link="https://github.com/topjohnwu/Magisk/releases/download/v24.1/Magisk-v24.1.apk"
canary_magisk_link="https://github.com/topjohnwu/magisk-files/blob/canary/app-debug.apk?raw=true"
clean_flash(){
umount -l "$TMPDIR"
rm -rf "$TMPDIR"
}
turn_back(){
p yellow "$text_press_enter_menu"
read
}
random(){
VALUE=$1; TYPE=$2; PICK="$3"; PICKC="$4"
TMPR=""
HEX="0123456789abcdef"; HEXC=16
CHAR="qwertyuiopasdfghjklzxcvbnm"; CHARC=26
NUM="0123456789"; NUMC=10
COUNT=$(seq 1 1 $VALUE)
list_pick=$HEX; C=$HEXC
[ "$TYPE" == "char" ] && list_pick=$CHAR && C=$CHARC
[ "$TYPE" == "number" ] && list_pick=$NUM && C=$NUMC
[ "$TYPE" == "custom" ] && list_pick="$PICK" && C=$PICKC
for i in $COUNT; do
random_pick=$(( $RANDOM % $C))
echo -n ${list_pick:$random_pick:1}
done
}
random_str(){
random_length=$(random 1 custom 56789 5);
random $random_length custom "qwertyuiopasdfghjklzxcvbnm0123456789QWERTYUIOPASDFGHJKLZXCVBNM" 63 | base64 | sed "s/=//g"
}
magisk_loader(){
MAGISKTMP_TYPE="$1"
test -z "$MAGISKTMP_TYPE" && MAGISKTMP_TYPE=1
MAGISKTMP=/sbin
[ "$MAGISK_IN_DEV" == "1" -o "$MAGISK_IN_DEV" == "true" ] && MAGISKTMP_TYPE=3
magisk_overlay=`random_str`
magisk_postfsdata=`random_str`
magisk_service=`random_str`
magisk_daemon=`random_str`
magisk_boot_complete=`random_str`
magisk_loadpolicy=`random_str`
dev_random=`random_str`
# always use "/dev/<random_string>" as magisk tmpfs
MAGISKTMP="/dev/$dev_random"
mount_sbin="mkdir -p \"$MAGISKTMP\"
mnt_tmpfs \"$MAGISKTMP\"
chmod 755 \"$MAGISKTMP\""
umount_sbin="umount /sbin"
# apply multiple sepolicy at same time
LOAD_MODULES_POLICY="rm -rf \"\$MAGISKTMP/.magisk/sepolicy.rules\"
for module in \$(ls /data/adb/modules); do
if ! [ -f \"/data/adb/modules/\$module/disable\" ] && [ -f \"/data/adb/modules/\$module/sepolicy.rule\" ]; then
echo \"## * module sepolicy: \$module\" >>\"\$MAGISKTMP/.magisk/sepolicy.rules\"
cat \"/data/adb/modules/\$module/sepolicy.rule\" >>\"\$MAGISKTMP/.magisk/sepolicy.rules\"
echo \"\" >>\"\$MAGISKTMP/.magisk/sepolicy.rules\"
fi
done
\$MAGISKTMP/magiskpolicy --live --apply \"\$MAGISKTMP/.magisk/sepolicy.rules\""
unset LOG_MAGISK
unset FORCE_MAGISKHIDE
unset ADD_FORCE_MAGISKHIDE
RM_RUSTY_MAGISK="#remove rusty-magisk gearlock module to make sure it is not conflicted with our magisk implement
rm /data/ghome/gearboot/overlay/rusty-magisk/init/init.superuser.rc
rm /data/.rusty-magisk/magisk.apk
rm /data/.rusty-magisk/magisk
rm /data/ghome/.local/bin/rusty-magisk"
ADDITIONAL_SCRIPT="( # addition script
rm -rf /data/adb/post-fs-data.d/fix_mirror_mount.sh
rm -rf /data/adb/service.d/fix_modules_not_show.sh
# additional script to deal with bullshit faulty design of emulator
# that close built-in root will remove magisk's /system/bin/su
echo \"
export PATH=\\\"\$MAGISKTMP:\\\$PATH\\\"
if [ -f \\\"/system/bin/magisk\\\" ]; then
umount -l /system/bin/su
rm -rf /system/bin/su
ln -fs ./magisk /system/bin/su
mount -o ro,remount /system/bin
umount -l /system/bin/magisk
mount --bind \\\"\$MAGISKTMP/magisk\\\" /system/bin/magisk
fi\" >\$MAGISKTMP/emu/magisksu_survival.sh
# additional script to deal with bullshit faulty design of Bluestacks
# that /system is a bind mountpoint
echo \"
SCRIPT=\\\"\\\$0\\\"
MAGISKTMP=\\\$(magisk --path) || MAGISKTMP=/sbin
( #fix bluestacks
MIRROR_SYSTEM=\\\"\\\$MAGISKTMP/.magisk/mirror/system\\\"
test ! -d \\\"\\\$MIRROR_SYSTEM/android/system\\\" && exit
test \\\"\\\$(cd /system; ls)\\\" == \\\"\\\$(cd \\\"\\\$MIRROR_SYSTEM\\\"; ls)\\\" && exit
mount --bind \\\"\\\$MIRROR_SYSTEM/android/system\\\" \\\"\\\$MIRROR_SYSTEM\\\" )
( #fix mount data mirror
function cmdline() {
awk -F\\\"\\\${1}=\\\" '{print \\\$2}' < /proc/cmdline | cut -d' ' -f1 2> /dev/null
}
SRC=\\\"\\\$(cmdline SRC)\\\"
BIPATH=\\\"\\\$(cmdline BOOT_IMAGE)\\\"
DATA=\\\"\\\$(cmdline DATA)\\\"
test -z \\\"\\\$SRC\\\" && SRC=\\\"\\\${BIPATH%/*}\\\"
test -z \\\"\\\$SRC\\\" && exit
test -z \\\"\\\$DATA\\\" && DATA=data
inode_data1=\\\$(ls -id \\\"\\\$MAGISKTMP/.magisk/mirror/data/\\\$SRC/\\\$DATA\\\" | awk '{ print \\\$1 }')
inode_data2=\\\$(ls -id \\\"\\\$MAGISKTMP/.magisk/mirror/data/\\\$SRC/data\\\" | awk '{ print \\\$1 }')
inode_data=\\\$(ls -id \\\"/data\\\" | awk '{ print \\\$1 }')
if [ \\\"\\\$inode_data1\\\" == \\\"\\\$inode_data\\\" ]; then
mount --bind \\\"\\\$MAGISKTMP/.magisk/mirror/data/\\\$SRC/\\\$DATA\\\" \\\"\\\$MAGISKTMP/.magisk/mirror/data\\\"
elif [ \\\"\\\$inode_data2\\\" == \\\"\\\$inode_data\\\" ]; then
mount --bind \\\"\\\$MAGISKTMP/.magisk/mirror/data/\\\$SRC/data\\\" \\\"\\\$MAGISKTMP/.magisk/mirror/data\\\"
fi )
rm -rf \\\"\\\$SCRIPT\\\"
\" >/data/adb/post-fs-data.d/fix_mirror_mount.sh
echo \"
SCRIPT=\\\"\\\$0\\\"
MAGISKTMP=\\\$(magisk --path) || MAGISKTMP=/sbin
set -x
exec 2>>\\\"\\\$MAGISKTMP/emu/record_logs.txt\\\"
inode_data1=\\\$(ls -id \\\"\\\$MAGISKTMP/.magisk/mirror/data/adb/modules\\\" | awk '{ print \\\$1 }')
inode_data2=\\\$(ls -id \\\"\\\$MAGISKTMP/.magisk/modules\\\" | awk '{ print \\\$1 }')
inode_data=\\\$(ls -id \\\"/data/adb/modules\\\" | awk '{ print \\\$1 }')
if [ \\\"\\\$inode_data2\\\" != \\\"\\\$inode_data\\\" ]; then
if [ \\\"\\\$inode_data1\\\" == \\\"\\\$inode_data\\\" ]; then
mount --bind \\\"\\\$MAGISKTMP/.magisk/mirror/data/adb/modules\\\" \\\"\\\$MAGISKTMP/.magisk/modules\\\"
fi
fi
rm -rf \\\"\\\$SCRIPT\\\"\" >/data/adb/service.d/fix_modules_not_show.sh
chmod 755 /data/adb/service.d/fix_modules_not_show.sh
chmod 755 /data/adb/post-fs-data.d/fix_mirror_mount.sh; )"
EXPORT_PATH="export PATH /sbin:/system/bin:/system/xbin:/vendor/bin:/gearlock/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin"
magiskloader="
on early-init
$EXPORT_PATH
on post-fs-data
$RM_RUSTY_MAGISK
start logd
start adbd
rm /dev/.magisk_unblock
exec u:r:su:s0 root root -- $MAGISKBASE/busybox sh -o standalone $MAGISKBASE/overlay.sh
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk --daemon
start $magisk_postfsdata
# wait all magisk post-fs-data jobs are completed or 40s has passed
wait /dev/.magisk_unblock 40
rm /dev/.magisk_unblock
service $magisk_postfsdata $MAGISKTMP/magisk --post-fs-data
user root
seclabel u:r:magisk:s0
oneshot
service $magisk_service $MAGISKTMP/magisk --service
class late_start
user root
seclabel u:r:magisk:s0
oneshot
on property:sys.boot_completed=1
$umount_sbin
start $magisk_boot_complete
# remove magisk service traces from some detection
# although detect modified init.rc is not always correct
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc.$magisk_postfsdata
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc.$magisk_service
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc.$magisk_boot_complete
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc_debug_pid.$magisk_postfsdata
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc_debug_pid.$magisk_service
exec u:r:magisk:s0 root root -- $MAGISKTMP/magisk resetprop --delete init.svc_debug_pid.$magisk_boot_complete
exec u:r:magisk:s0 root root -- $MAGISKTMP/busybox sh -o standalone $MAGISKTMP/emu/magisksu_survival.sh
service $magisk_boot_complete $MAGISKTMP/magisk --boot-complete
user root
seclabel u:r:magisk:s0
oneshot"
overlay_loader="#!$MAGISKBASE/busybox sh
export PATH=/sbin:/system/bin:/system/xbin
mnt_tmpfs(){ (
# MOUNT TMPFS ON A DIRECTORY
MOUNTPOINT=\"\$1\"
mkdir -p \"\$MOUNTPOINT\"
mount -t tmpfs -o \"mode=0755\" tmpfs \"\$MOUNTPOINT\" 2>/dev/null
) }
mnt_bind(){ (
# SHORTCUT BY BIND MOUNT
FROM=\"\$1\"; TO=\"\$2\"
if [ -L \"\$FROM\" ]; then
SOFTLN=\"\$(readlink \"\$FROM\")\"
ln -s \"\$SOFTLN\" \"\$TO\"
elif [ -d \"\$FROM\" ]; then
mkdir -p \"\$TO\" 2>/dev/null
mount --bind \"\$FROM\" \"\$TO\"
else
echo -n 2>/dev/null >\"\$TO\"
mount --bind \"\$FROM\" \"\$TO\"
fi
) }
exit_magisk(){
umount -l $MAGISKTMP
echo -n >/dev/.magisk_unblock
}
API=\$(getprop ro.build.version.sdk)
ABI=\$(getprop ro.product.cpu.abi)
if [ \"\$ABI\" = \"x86\" ]; then
ARCH=x86
ABI32=x86
IS64BIT=false
elif [ \"\$ABI\" = \"arm64-v8a\" ]; then
ARCH=arm64
ABI32=armeabi-v7a
IS64BIT=true
elif [ \"\$ABI\" = \"x86_64\" ]; then
ARCH=x64
ABI32=x86
IS64BIT=true
else
ARCH=arm
ABI=armeabi-v7a
ABI32=armeabi-v7a
IS64BIT=false
fi
magisk_name=\"magisk32\"
[ \"\$IS64BIT\" == true ] && magisk_name=\"magisk64\"
# umount previous /sbin tmpfs overlay
count=0
( magisk --stop ) &
# force umount /sbin tmpfs
until ! mount | grep -q \" /sbin \"; do
[ "$count" -gt "10" ] && break
umount -l /sbin 2>/dev/null