From 330dce8861d9ca5818d3ccdaf22166946b054bf9 Mon Sep 17 00:00:00 2001 From: newbit <1999047-newbit@users.noreply.gitlab.com> Date: Sat, 2 Mar 2024 19:28:18 +0100 Subject: [PATCH] Added support for elevated write permissions --- README.md | 21 +++++++++++------- rootAVD.bat | 63 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b9e4105..4e7f564 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,11 @@ rootAVD.bat system-images\android-25\google_apis_playstore\armeabi-v7a\ramdisk.i * In both cases, the script will search in it for AVD system-images and adb binarys * `ANDROID_HOME` Sets the path to the SDK installation directory -> [AOSP Variables reference](https://developer.android.com/tools/variables#envar) +### Notes for Microsoft Visual Studio AVDs +* `ANDROID_HOME` needs to be set properly i.e. `set ANDROID_HOME="C:\Program Files (x86)\Android\android-sdk"` +* `"C:\Program Files (x86)\Android\android-sdk"` needs elevated write permissions +* the script will ask for user permissions, every time it needs to write to those locations + ### Notes for Apk Developers * [How-To SU](http://su.chainfire.eu) from [Chainfire's](https://github.com/Chainfire) [libsuperuser](https://github.com/Chainfire/libsuperuser) - Guidelines for problem-free su usage (for Android Developers) * [TopJohnWu's libsu](https://github.com/topjohnwu/libsu) - An Android library providing a complete solution for apps using root permissions @@ -373,19 +378,19 @@ rootAVD.bat system-images\android-25\google_apis_playstore\armeabi-v7a\ramdisk.i ### Change Logs -#### [December 2023] -* [rootAVD.sh] - Fixed GetUSBHPmod Download Links and typos - -#### [Novemver 2023] -* [rootAVD.bat] - Fixed another space issue - -#### [October 2023] -* [General] - Moved to GitLab +#### [March 2024] +* [rootAVD.bat] - Added support for elevated write permissions
Archive ### Change Logs +#### [December 2023] +* [rootAVD.sh] - Fixed GetUSBHPmod Download Links and typos +#### [November 2023] +* [rootAVD.bat] - Fixed another space issue +#### [October 2023] +* [General] - Moved to GitLab #### [August 2023] * [rootAVD.sh] - Added Pagesize Padding in the fakeboot.img * [rootAVD.sh] - Updated the creation of the fakeboot.img diff --git a/rootAVD.bat b/rootAVD.bat index 040e375..7cdb149 100644 --- a/rootAVD.bat +++ b/rootAVD.bat @@ -33,9 +33,9 @@ IF %DEBUG% ( echo ListAllAVDs=%ListAllAVDs% echo InstallApps=%InstallApps% echo NOPARAMSATALL=%NOPARAMSATALL% + echo COPYASADMIN=%COPYASADMIN% ) - IF NOT %InstallApps% ( REM If there is no file to work with, abort the script IF "%1" == "" ( @@ -58,6 +58,8 @@ for /F "delims=" %%i in ("%AVDPATHWITHRDFFILE%") do ( set RDFFILE=%%~nxi ) +call :testWritePerm %RDFFILE% + REM If we can CD into the ramdisk.img, it is not a file! cd %AVDPATHWITHRDFFILE% >nul 2>&1 IF "%ERRORLEVEL%"=="0" ( @@ -136,7 +138,15 @@ IF "%ERRORLEVEL%"=="0" ( REM In Debug-Mode we can skip parts of the script IF NOT %DEBUG% ( IF %RAMDISKIMG% ( - call :pullfromAVD ramdiskpatched4AVD.img "%AVDPATHWITHRDFFILE%" + + IF %COPYASADMIN% ( + call :pullfromAVD ramdiskpatched4AVD.img + powershell.exe -Command "Start-Process -Wait cmd '/c copy """"%ROOTAVD%\ramdiskpatched4AVD.img"""" """"%AVDPATHWITHRDFFILE%""""' -Verb RunAs" + del /Q ramdiskpatched4AVD.img + ) ELSE ( + call :pullfromAVD ramdiskpatched4AVD.img "%AVDPATHWITHRDFFILE%" + ) + call :pullfromAVD Magisk.apk "%ROOTAVD%" Apps call :pullfromAVD Magisk.zip @@ -202,7 +212,13 @@ exit /B 0 IF EXIST "%BZFILE%" ( call :create_backup %KRFILE% echo [*] Copy %BZFILE% ^(Kernel^) into kernel-ranchu - copy "%BZFILE%" "%AVDPATH%%KRFILE%" >Nul + + IF %COPYASADMIN% ( + echo [^^!] with elevated write permissions + powershell.exe -Command "Start-Process -Wait cmd '/c copy """"%BZFILE%"""" """"%AVDPATH%%KRFILE%""""' -Verb RunAs" + ) ELSE ( + copy "%BZFILE%" "%AVDPATH%%KRFILE%" >Nul 2>&1 + ) IF "%ERRORLEVEL%"=="0" ( del "%BZFILE%" "%INITRAMFS%" @@ -282,16 +298,42 @@ exit /B 0 ENDLOCAL exit /B 0 +:testWritePerm + set FILE=%1 + set TEMPFILE=%FILE%.temp + + echo [*] Testing for write permissions + echo [-] creating TEMPFILE File + copy "%AVDPATH%%FILE%" "%AVDPATH%%TEMPFILE%" >Nul 2>&1 + IF NOT "%ERRORLEVEL%"=="0" ( + set COPYASADMIN=%true% + echo [^!] elevated write permissions are needed to access ^$ANDROID_HOME + ) + + IF NOT %COPYASADMIN% ( + echo [-] deleating TEMPFILE File + echo [^^!] NO elevated write permissions are needed to access ^$ANDROID_HOME + del /Q "%AVDPATH%%TEMPFILE%" + ) +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 + echo [*] creating Backup File + + IF %COPYASADMIN% ( + echo [^^!] with elevated write permissions + powershell.exe -Command "Start-Process -Wait cmd '/c copy """"%AVDPATH%%FILE%"""" """"%AVDPATH%%BACKUPFILE%""""' -Verb RunAs" + ) ELSE ( + copy "%AVDPATH%%FILE%" "%AVDPATH%%BACKUPFILE%" >Nul 2>&1 + ) + IF EXIST "%AVDPATH%%BACKUPFILE%" ( echo [-] Backup File was created ) @@ -378,7 +420,13 @@ 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 + + IF %COPYASADMIN% ( + echo [^!] with elevated write permissions + powershell.exe -Command "Start-Process -Wait cmd '/c copy """"%%i"""" """"%%~di%%~pi%%~ni""""' -Verb RunAs" + ) ELSE ( + copy "%%i" "%%~di%%~pi%%~ni" >nul 2>&1 + ) ) echo [*] Backups still remain in place REM call :_Exit 2> nul @@ -396,6 +444,7 @@ exit /B 0 set ListAllAVDs=%false% set InstallApps=%false% set NOPARAMSATALL=%false% + set COPYASADMIN=%false% REM While debugging and developing you can turn this flag on echo.%params%| FIND /I "DEBUG">Nul && (