Added comprehensive Help Menu

This commit is contained in:
NewBit
2021-05-02 21:59:39 +02:00
parent fd55f87011
commit 42bc235399
3 changed files with 399 additions and 100 deletions
+8 -13
View File
@@ -17,9 +17,8 @@ A Script to...
* `adb shell` will connect to the running AVD
## rootAVD Help Menu
### Linux & MacOS
### Linux & MacOS & Windows
```
./rootAVD.sh
rootAVD A Script to root AVD by NewBit XDA
Usage: rootAVD [DIR/ramdisk.img] [OPTIONS] | [EXTRA_CMDS]
@@ -93,12 +92,6 @@ Command Examples:
./rootAVD.sh ~/Library/Android/sdk/system-images/android-S/google_apis_playstore/x86_64/ramdisk.img InstallPrebuiltKernelModules DEBUG PATCHFSTAB GetUSBHPmodZ
```
#### Windows
```
set PATH=%LOCALAPPDATA%\Android\Sdk\platform-tools;%PATH%
rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_playstore\x86_64\ramdisk.img
```
### Notes
* Android 12 (S) rev.2 needs Magisk v22.1+ or Canary
* With the new Menu, you can choose between the newest Magisk, Canary and Stable, Version.
@@ -136,6 +129,13 @@ rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_plays
* [[Mar. 2021] - Android 10 (Q) API 29 Google Apis Play Store x86_64 r08 Darwin/MacOS Production Build](https://dl.google.com/android/repository/sys-img/google_apis_playstore/x86_64-29_r08-darwin.zip)
* [[Mar. 2021] - Android 10 (Q) API 29 Google Apis Play Store x86_64 r08 Windows Production Build](https://dl.google.com/android/repository/sys-img/google_apis_playstore/x86_64-29_r08-windows.zip)
### Change Logs
#### [May 2021]
* [rootAVD.sh] - Added comprehensive Help Menu
<details>
<summary>Archive</summary>
### Change Logs
#### [Apr. 2021]
* [General] - Added comprehensive Help Menu
@@ -150,11 +150,6 @@ rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_plays
* [General] - Added "restore" to put back your backup files
* [General] - Updated local Magisk App v22.1
* [rootAVD.sh] - Added Option to Download the USB HOST Permissions Module
<details>
<summary>Archive</summary>
### Change Logs
#### [Mar. 2021]
* [General] - Add a Download Manager Function for bad TLS record using wget
* [rootAVD.bat] - Adjustments to run with the updated rootAVD.sh
+386 -80
View File
@@ -1,5 +1,8 @@
@echo off
SetLocal EnableDelayedExpansion
SetLocal DisableDelayedExpansion
set true=1==1
set false=1==0
REM ##########################################################################################
REM #
REM # Magisk Boot Image Patcher - original created by topjohnwu and modded by shakalaca's
@@ -7,114 +10,417 @@ REM # modded by NewBit XDA for Android Studio AVD
REM # Successfully tested on Android API:
REM # [Dec. 2019] - 29 Google Apis Play Store x86_64 Production Build
REM # [Jan. 2021] - 30 Google Apis Play Store x86_64 Production Build
REM # [Mar. 2021] - 30 Android (S) Google Apis Play Store x86_64 Production Build rev 1
REM # [Mar. 2021] - 30 Android (S) Google Apis Play Store x86_64 Production Build rev 2
REM # [Apr. 2021] - 30 Android (S) Google Apis Play Store x86_64 Production Build rev 3
REM #
REM ##########################################################################################
REM rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_playstore\x86_64\ramdisk.img
REM rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-30\google_apis_playstore\x86_64\ramdisk.img
REM rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-29\google_apis_playstore\x86_64\ramdisk.img
if "%1" == "" (
echo "rootAVD needs a path with file to an AVD ramdisk"
echo "rootAVD will backup your ramdisk.img and replace it when finished"
echo "rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-30\google_apis_playstore\x86_64\ramdisk.img"
echo "rootAVD.bat %LOCALAPPDATA%\Android\Sdk\system-images\android-S\google_apis_playstore\x86_64\ramdisk.img"
exit /B 0
call :ProcessArguments %*
if %DEBUG% (
echo [^!] We are in Debug Mode
REM echo on
)
set RAMDISKFILE=%1
set BACKUPFILE=%RAMDISKFILE%.bak
set ROOTAVD="%cd%"
set MAGISKZIP=%ROOTAVD%\Magisk.zip
CD %RAMDISKFILE%
IF "%ERRORLEVEL%"=="0" (
echo "[*] Please give a PATH to a file, not just a Directory"
exit /B 0
if not %ENVFIXTASK% (
REM If there is no file to work with, abort the script
if not exist "%1" (
call :ShowHelpText
)
)
IF NOT EXIST %RAMDISKFILE% (
echo "[*] %RAMDISKFILE% doesn't exist"
exit /B 0
REM Set Folders and FileNames
echo [*] Set Directorys
set AVDPATHWITHRDFFILE=%1
for /F "delims=" %%i in ("%AVDPATHWITHRDFFILE%") do (
set AVDPATH=%%~dpi
set RDFFILE=%%~nxi
)
IF NOT EXIST %BACKUPFILE% (
echo "[*] create Backup File"
copy %RAMDISKFILE% %BACKUPFILE%
) ELSE (
echo "[-] Backup exists already"
REM If we can CD into the ramdisk.img, it is not a file!
cd %AVDPATHWITHRDFFILE% >nul 2>&1
if "%ERRORLEVEL%"=="0" (
call :ShowHelpText
)
echo "[-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell"
if %restore% (
call :restore_backups
)
call :TestADB
REM The Folder where the script was called from
set ROOTAVD=%cd%
set MAGISKZIP=%ROOTAVD%Magisk.zip
REM Kernel Names
set BZFILE=%ROOTAVD%bzImage
set KRFILE=kernel-ranchu
set ADBWORKDIR=/data/data/com.android.shell
set ADBBASEDIR=%ADBWORKDIR%/Magisk
set ADBWORKS=
adb shell -n echo true > tmpFile
set /P ADBWORKS=<tmpFile
del tmpFile
echo [-] In any AVD via ADB, you can execute code without root in /data/data/com.android.shell
IF "%ADBWORKS%" == "true" (
echo "[-] ADB connectoin possible"
) ELSE (
echo "[*] no ADB connectoin possible"
exit /B 0
REM change to ROOTAVD directory
cd %ROOTAVD%
echo [*] looking for Magisk installer Zip
if not exist "%MAGISKZIP%" (
echo [-] Please download Magisk.zip file
call :_Exit 2> nul
)
echo "[*] looking for Magisk installer Zip"
IF NOT EXIST %MAGISKZIP% (
echo "[-] Please download Magisk.zip file"
exit /B 0
)
echo "[*] Cleaning up the ADB working space"
echo [*] Cleaning up the ADB working space
adb shell rm -rf %ADBBASEDIR%
echo "[*] Creating the ADB working space"
echo [*] Creating the ADB working space
adb shell mkdir %ADBBASEDIR%
echo "[-] Copy Magisk installer Zip"
adb push %MAGISKZIP% %ADBBASEDIR%
call :pushtoAVD %MAGISKZIP%
REM Proceed with ramdisk
set INITRAMFS=%ROOTAVD%initramfs.img
if %RAMDISKIMG% (
REM Is it a ramdisk named file?
if not "%RDFFILE%" == "ramdisk.img" (
echo [!] please give a path to a ramdisk file
call :_Exit 2> nul
)
call :create_backup %RDFFILE%
call :pushtoAVD %AVDPATHWITHRDFFILE%
echo "[*] Copy the original AVD ramdisk.img into Magisk DIR"
adb push %RAMDISKFILE% %ADBBASEDIR%
if %InstallKernelModules% (
if exist "%INITRAMFS%" (
call :pushtoAVD %INITRAMFS%
)
)
)
echo "[-] Copy rootAVD Script into Magisk DIR"
echo [-] Copy rootAVD Script into Magisk DIR
adb push rootAVD.sh %ADBBASEDIR%
echo "[-] Convert Script to Unix Ending"
echo [-] Convert Script to Unix Ending
adb -e shell "dos2unix %ADBBASEDIR%/rootAVD.sh"
echo "[-] run the actually Boot/Ramdisk/Kernel Image Patch Script"
echo "[*] from Magisk by topjohnwu and modded by NewBit XDA"
adb shell sh %ADBBASEDIR%/rootAVD.sh "ranchu"
echo "[-] After the ramdisk.img file is patched and compressed,"
echo "[*] pull it back in the Magisk DIR"
adb pull %ADBBASEDIR%/ramdiskpatched4AVD.img
echo [-] run the actually Boot/Ramdisk/Kernel Image Patch Script
echo [*] from Magisk by topjohnwu and modded by NewBit XDA
adb shell sh %ADBBASEDIR%/rootAVD.sh %*
echo "[-] pull Magisk.apk to Apps\"
adb pull %ADBBASEDIR%/Magisk.apk Apps\
if "%ERRORLEVEL%"=="1" (
REM In Debug-Mode we can skip parts of the script
if not %DEBUG% (
if %RAMDISKIMG% (
call :pullfromAVD ramdiskpatched4AVD.img %AVDPATHWITHRDFFILE%
call :pullfromAVD Magisk.apk %ROOTAVD%Apps\
call :pullfromAVD Magisk.zip
if %InstallPrebuiltKernelModules% (
call :pullfromAVD %BZFILE%
call :InstallKernelModules
)
if %InstallKernelModules% (
call :InstallKernelModules
)
echo [-] Clean up the ADB working space
adb shell rm -rf %ADBBASEDIR%
echo "[-] pull Magisk.zip to Apps\"
adb pull %ADBBASEDIR%/Magisk.zip
call :installapps
echo "[-] Clean up the ADB working space"
adb shell rm -rf %ADBBASEDIR%
echo "[*] Move and rename the patched ramdisk.img to the original AVD DIR"
copy ramdiskpatched4AVD.img %RAMDISKFILE%
del ramdiskpatched4AVD.img
call :installapps
echo "[-] reboot the AVD and see if it worked"
echo "[-] Root and Su with Magisk for Android Studio AVDs"
echo "[-] Modded by NewBit XDA - Jan. 2021"
echo "[*] Huge Credits and big Thanks to topjohnwu and shakalaca"
EXIT /B %ERRORLEVEL%
:INSTALLAPPS
ECHO "[-] Install all APKs placed in the Apps folder"
FOR %%i IN (APPS\*.apk) DO (
echo "[*] Trying to install %%i"
adb install -r -d %%i
echo [-] reboot the AVD and see if it worked
echo [-] Root and Su with Magisk for Android Studio AVDs
echo [-] Modded by NewBit XDA - Jan. 2021
echo [*] Huge Credits and big Thanks to topjohnwu and shakalaca
)
)
)
EXIT /B 0
exit /B %ERRORLEVEL%
:InstallKernelModules
SetLocal EnableDelayedExpansion
if exist "%BZFILE%" (
call :create_backup %KRFILE%
echo [*] Copy %BZFILE% ^(Kernel^) into kernel-ranchu
copy %BZFILE% %AVDPATH%%KRFILE% >Nul
if "%ERRORLEVEL%"=="0" (
del %BZFILE% %INITRAMFS%
)
)
EndLocal
exit /B 0
:pullfromAVD
SetLocal EnableDelayedExpansion
set SRC=%1
set DST=%2
set ADBPULLECHO=
for /F "delims=" %%i in ("%SRC%") do (
set SRC=%%~nxi
)
for /F "delims=" %%i in ("%DST%") do (
set DST=%%~nxi
)
adb pull %ADBBASEDIR%/%SRC% %2 > tmpFile 2>&1
set /P ADBPULLECHO=<tmpFile
del tmpFile
echo.%ADBPULLECHO%| FIND /I "error">Nul || (
echo [*] Pull %SRC% into %DST%
echo [-] %ADBPULLECHO%
)
EndLocal
exit /B 0
:pushtoAVD
SetLocal EnableDelayedExpansion
set SRC=%1
set ADBPUSHECHO=
for /F "delims=" %%i in ("%SRC%") do (
set SRC=%%~nxi
)
echo [*] Push %SRC% into %ADBBASEDIR%
adb push %1 %ADBBASEDIR% > tmpFile 2>&1
set /P ADBPUSHECHO=<tmpFile
del tmpFile
echo [-] %ADBPUSHECHO%
ENDLOCAL
exit /B 0
:create_backup
SetLocal EnableDelayedExpansion
set FILE=%1
set BACKUPFILE=%FILE%.backup
REM If no backup file exist, create one
if not exist %AVDPATH%%BACKUPFILE% (
echo [*] create Backup File
copy %AVDPATH%%FILE% %AVDPATH%%BACKUPFILE% >Nul
) else (
echo [-] Backup exists already
)
ENDLOCAL
exit /B 0
:TestADB
SetLocal EnableDelayedExpansion
set HOME=%LOCALAPPDATA%\
set ADB_DIR_W=Android\Sdk\platform-tools\
set ADB_DIR=""
set ADB_EX=""
echo [-] Test if ADB SHELL is working
if exist %HOME%%ADB_DIR_W% (
set ADB_DIR=%ADB_DIR_W%
) else (
echo [^^!] ADB not found, please install platform-tools and add it to your %%PATH%%
call :_Exit 2> nul
)
for /f "delims=" %%i in ('dir %HOME%%ADB_DIR%adb.exe /s /b /a-d') do (
set ADB_EX=%%i
)
REM call set ADB_EX=%%ADB_EX:!HOME!=%%
IF %ADB_EX% == "" (
echo [^^!] ADB binary not found in %%LOCALAPPDATA%%\%ADB_DIR%
call :_Exit 2> nul
)
set ADBWORKS=
adb shell -n echo true > tmpFile 2>&1
set /P ADBWORKS=<tmpFile
del tmpFile
echo.%ADBWORKS%| FIND /I "recognized">Nul && (
echo [^^!] ADB is not in your Path, try to
echo set PATH=%%LOCALAPPDATA%%\Android\Sdk\platform-tools;%%PATH%%
call :_Exit 2> nul
)
if "%ADBWORKS%" == "true" (
echo [-] ADB connectoin possible
) else (
echo [*] no ADB connection possible
call :_Exit 2> nul
)
ENDLOCAL
exit /B 0
:restore_backups
for /f "delims=" %%i in ('dir %AVDPATH%*.backup /s /b /a-d') do (
echo [^!] Restoring %%~ni%%~xi to %%~ni
copy %%i %%~di%%~pi%%~ni >nul 2>&1
)
echo [*] Backups still remain in place
call :_Exit 2> nul
:ProcessArguments
set params=%*
set DEBUG=%false%
set PATCHFSTAB=%false%
set GetUSBHPmodZ=%false%
set ENVFIXTASK=%false%
set RAMDISKIMG=%false%
set restore=%false%
set InstallKernelModules=%false%
set InstallPrebuiltKernelModules=%false%
REM While debugging and developing you can turn this flag on
echo.%params%| FIND /I "DEBUG">Nul && (
set DEBUG=%true%
REM Shows whatever line get executed...
REM echo on
)
REM Call rootAVD with PATCHFSTAB if you want the RAMDISK merge your modded fstab.ranchu before Magisk Mirror gets mounted
echo.%params%| FIND /I "PATCHFSTAB">Nul && (
set PATCHFSTAB=%true%
)
REM Call rootAVD with GetUSBHPmodZ to download the usbhostpermissons module
echo.%params%| FIND /I "GetUSBHPmodZ">Nul && (
set GetUSBHPmodZ=%true%
)
IF "%1"=="EnvFixTask" (
REM AVD requires additional setup
set ENVFIXTASK=%true%
) ELSE (
set RAMDISKIMG=%true%
)
IF "%2" == "restore" (
set restore=%true%
) ELSE IF "%2"=="InstallKernelModules" (
set InstallKernelModules=%true%
) ELSE IF "%2"=="InstallPrebuiltKernelModules" (
set InstallPrebuiltKernelModules=%true%
)
exit /B 0
:installapps
echo [-] Install all APKs placed in the Apps folder
FOR %%i IN (APPS\*.apk) DO (
echo [*] Trying to install %%i
adb install -r -d %%i
)
exit /B 0
:ShowHelpText
echo rootAVD A Script to root AVD by NewBit XDA
echo.
echo Usage: rootAVD [DIR/ramdisk.img] [OPTIONS] ^| [EXTRA_CMDS]
echo or: rootAVD EnvFixTask
echo.
echo Requires Additional Setup fix:
echo EnvFixTask construct Magisk Environment manual
echo - only works with an already Magisk patched ramdisk.img
echo - without [DIR/ramdisk.img] [OPTIONS] [PATCHFSTAB]
echo - needed since Android 12 (S) rev.1
echo - Grant Shell Su Permissions will pop up a few times
echo - the AVD will reboot automatically
echo.
echo Main operation mode:
echo DIR a path to an AVD system-image
echo - must always be the 1st Argument after rootAVD
echo.
echo ADB Path ^| Ramdisk DIR:
echo [M]ac/Darwin: export PATH=~/Library/Android/sdk/platform-tools:\$PATH
echo ~/Library/Android/sdk/system-images/android-\$API/google_apis_playstore/x86_64/
echo.
echo [L]inux: export PATH=~/Android/Sdk/platform-tools:\$PATH
echo ~/Android/Sdk/system-images/android-\$API/google_apis_playstore/x86_64/
echo.
echo [W]indows: set PATH=%%LOCALAPPDATA%%\Android\Sdk\platform-tools;%%PATH%%
echo %%LOCALAPPDATA%%\Android\Sdk\system-images\android-^$API\google_apis_playstore\x86_64\
echo.
echo ^$API: 25,29,30,S,etc.
echo.
echo Except for EnvFixTask, ramdisk.img must be untouched (stock).
echo.
echo Options:
echo restore restore all existing .backup files, but doesn't delete them
echo - the AVD doesn't need to be running
echo - no other Argument after will be processed
echo.
echo InstallKernelModules install custom build kernel and its modules into ramdisk.img
echo - kernel (bzImage) and its modules (initramfs.img) are inside rootAVD
echo - both files will be deleted after installation
echo.
echo InstallPrebuiltKernelModules download and install an AOSP prebuilt kernel and its modules into ramdisk.img
echo - similar to InstallKernelModules, but the AVD needs to be online
echo.
echo Options are exclusive, only one at the time will be processed.
echo.
echo Extra Commands:
echo DEBUG Debugging Mode, prevents rootAVD to pull back any patched file
echo.
echo PATCHFSTAB fstab.ranchu will get patched to automount Block Devices like /dev/block/sda1
echo - other entries can be added in the script as well
echo - a custom build Kernel might be necessary
echo.
echo GetUSBHPmodZ The USB HOST Permissions Module Zip will be downloaded into /sdcard/Download
echo.
echo Extra Commands can be combined, there is no particular order.
echo.
echo Notes: rootAVD will
echo - always create .backup files of ramdisk.img and kernel-ranchu
echo - replace both when done patching
echo - show a Menu, to choose the Magisk Version (Stable || Canary), if the AVD is online
echo - make the choosen Magisk Version to its local
echo - install all APKs placed in the Apps folder
echo.
echo Command Examples:
call :FindSystemImages
call :_Exit 2> nul
:FindSystemImages
SetLocal EnableDelayedExpansion
set HOME=%LOCALAPPDATA%\
set SYSIM_DIR_W=Android\Sdk\system-images\
set SYSIM_DIR=
set SYSIM_EX=
IF EXIST %HOME%%SYSIM_DIR_W% (
set SYSIM_DIR=%SYSIM_DIR_W%
) ELSE (
exit /B 0
)
for /f "delims=" %%i in ('dir %HOME%%SYSIM_DIR%ramdisk.img /s /b /a-d') do (
set SYSIM_EX=%%i
)
call set SYSIM_EX=%%SYSIM_EX:!HOME!=%%
IF NOT %SYSIM_EX% == "" (
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX%
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX% DEBUG PATCHFSTAB GetUSBHPmodZ
echo rootAVD.bat EnvFixTask
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX% restore
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX% InstallKernelModules
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX% InstallPrebuiltKernelModules
echo rootAVD.bat %%LOCALAPPDATA%%\%SYSIM_EX% InstallPrebuiltKernelModules GetUSBHPmodZ PATCHFSTAB DEBUG
)ELSE (
echo rootAVD.bat
)
ENDLOCAL
exit /B 0
:_Exit
()
goto :eof
+5 -7
View File
@@ -167,9 +167,9 @@ construct_environment() {
if [[ "$ROOT" == "" ]]; then
ROOT=$(id -u)
fi
echo "[-] Constructing environment - PAY ATTENTION to the AVDs Screen"
if [[ $ROOT -eq 0 ]]; then
echo "[-] Constructing environment - PAY ATTENTION to the AVDs Screen"
echo "[!] we are root"
local BBBIN=$BB
local COMMONDIR=$BASEDIR/assets
@@ -496,7 +496,7 @@ DownLoadFile() {
fi
$BB dd if=$DST count=$COUNT bs=$BS of=$OF > /dev/null 2>&1
mv -f $OF $DST
$BB wget -q $DST --no-check-certificate $URL$SRC -c
$BB wget -q -O $DST --no-check-certificate $URL$SRC -c
RESULT="$?"
done
echo "[!] Downloading File $SRC complete!"
@@ -1036,8 +1036,6 @@ InstallMagiskToAVD() {
get_flags
api_level_arch_detect
$ENVFIXTASK && construct_environment
if $RANCHU; then
@@ -1071,12 +1069,12 @@ FindSystemImages() {
echo "${bold}./rootAVD.sh $SYSIM_EX${normal}"
if [[ ! $SYSIM_EX == "" ]]; then
echo "${bold}./rootAVD.sh $SYSIM_EX GetUSBHPmodZ PATCHFSTAB DEBUG${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX DEBUG PATCHFSTAB GetUSBHPmodZ${normal}"
echo "${bold}./rootAVD.sh EnvFixTask${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX restore${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX InstallKernelModules${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX InstallPrebuiltKernelModules${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX InstallPrebuiltKernelModules DEBUG PATCHFSTAB GetUSBHPmodZ${normal}"
echo "${bold}./rootAVD.sh $SYSIM_EX InstallPrebuiltKernelModules GetUSBHPmodZ PATCHFSTAB DEBUG${normal}"
fi
}