-
Notifications
You must be signed in to change notification settings - Fork 1
/
magisk.bat
129 lines (88 loc) · 2.65 KB
/
magisk.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
@echo off
if '%~1' =='install' (goto :install_modules) else (goto :CheckApiVersion)
:CheckApiVersion
SetLocal EnableDelayedExpansion
echo [-] Pushing All Modules placed in the Modules folder
for /f "delims=" %%A in ('adb shell getprop ro.build.version.sdk' ) do (
echo [-] Your device api Version %%A
set version=%%A
goto :list_images %%A
)
ENDLOCAL
exit /B 0
:list_images
setlocal EnableExtensions EnableDelayedExpansion
set HOME="%LOCALAPPDATA%\"
set SYSIM_DIR_W=Android\Sdk\system-images\
SetLocal EnableDelayedExpansion
echo %version%
for /f "delims=*" %%G in ('dir %HOME%%SYSIM_DIR%ramdisk.img /b /s /a-d') do (
set "str1=%%G"
if "!str1:%version%=!" == "!str1!" ( set ramdisk_path=%%G) else (
set ramdisk_path=%%G
goto :create-backup ramdisk_path
)
)
ENDLOCAL
exit /B 0
:create-backup ramdisk_path
SetLocal EnableDelayedExpansion
echo %ramdisk_path%
set BACKUPFILE=%ramdisk_path%.backup
REM If no backup file exist, create one
if not exist %BACKUPFILE% (
echo [*] create Backup File
copy %ramdisk_path% %BACKUPFILE% >Nul
echo [*] created Backup File
copy %ramdisk_path% ramdisk.img
goto :install
) else (
echo [-] Backup exists already
copy %ramdisk_path% ramdisk.img
goto :install
)
ENDLOCAL
exit /B 0
:install
set tool_Path= %cd%/magisktoemulator
SetLocal EnableDelayedExpansion
echo %tool_Path%/patch.bat
call %tool_Path%/patch.bat canary
copy ramdisk.img %ramdisk_path%
call :ShutDownAVD
ENDLOCAL
exit /B 0
:install_modules
SetLocal EnableDelayedExpansion
echo %~1
SetLocal EnableDelayedExpansion
echo [-] Pushing All Modules placed in the Modules folder
for %%i in (modules\*.zip) do (
set module=%%i
for /f "delims=" %%A in ('adb push !module! /data/local/tmp 2^>^&1' ) do (
echo [-] %%A
)
)
goto :install_ma
ENDLOCAL
exit /B 0
:ShutDownAVD
SetLocal EnableDelayedExpansion
set ADBPULLECHO=
REM adb shell reboot -p > tmpFile 2>&1
adb shell setprop sys.powerctl shutdown > tmpFile 2>&1
set /P ADBPULLECHO=<tmpFile
del tmpFile
echo.%ADBPULLECHO%| FIND /I "error">Nul || (
echo [-] Trying to shut down the AVD
)
echo [^^!] If the AVD doesnt shut down, try it manually^^!
EndLocal
exit /B 0
:install_ma
set ADBWORKDIR=/data/data/com.android.shell
SetLocal EnableDelayedExpansion
echo [-] Install all Modules placed in the Apps folder
adb shell "su -c 'for i in $(find /data/local/tmp -name '*.zip'); do magisk --install-module "$i"; done'"
ENDLOCAL
exit /B 0