From 0d3b1ec3b9f61ee68d349c1cc10d53ee96eef3f2 Mon Sep 17 00:00:00 2001 From: Ajin Abraham Date: Mon, 2 Dec 2024 21:43:53 -0800 Subject: [PATCH] Fix x86_64 Android AVD in Windows (#2471) --- scripts/start_avd.ps1 | 36 ++++++++++++++++++++++++++++++++++-- scripts/start_avd.sh | 6 ++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/start_avd.ps1 b/scripts/start_avd.ps1 index cc2038754..fca424646 100755 --- a/scripts/start_avd.ps1 +++ b/scripts/start_avd.ps1 @@ -51,5 +51,37 @@ if (-not $AVD_FOUND) { } # Start the emulator with user-defined AVD and port -Start-Process -FilePath $EMULATOR_PATH -ArgumentList "-avd $AVD_NAME -writable-system -no-snapshot -wipe-data -port $START_PORT" -Write-Output "Emulator started with AVD $AVD_NAME on port $START_PORT." \ No newline at end of file +Start-Process -NoNewWindow -FilePath $EMULATOR_PATH -ArgumentList "-avd $AVD_NAME -writable-system -no-snapshot -wipe-data -port $START_PORT" +Write-Output "Starting AVD $AVD_NAME on port $START_PORT." + +# Wait for the emulator to boot completely +Write-Output "Waiting for emulator to boot..." +& $ADB_PATH wait-for-device +Start-Sleep -Seconds 5 +Write-Output "Emulator booted successfully." + +# Allow /system remount +Write-Output "Restarting adb as root..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "root" + +Write-Output "Disabling AVB verification..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "shell avbctl disable-verification" + +Write-Output "Disabling verity..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "disable-verity" + +Write-Output "Restarting emulator..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "reboot" + +Write-Output "Waiting for emulator to reboot..." +& $ADB_PATH wait-for-device +Start-Sleep -Seconds 5 +Write-Output "Emulator rebooted successfully." + +Write-Output "Restarting adb as root..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "root" + +Write-Output "Remounting the filesystem..." +Start-Process -NoNewWindow -Wait -FilePath $ADB_PATH -ArgumentList "remount" + +Write-Output "Emulator ready for Dynamic Analysis with MobSF." diff --git a/scripts/start_avd.sh b/scripts/start_avd.sh index a4f30087c..10a5f2ece 100755 --- a/scripts/start_avd.sh +++ b/scripts/start_avd.sh @@ -66,7 +66,9 @@ done # Start the emulator with user-defined AVD and port "$EMULATOR_PATH" -avd "$AVD_NAME" -writable-system -no-snapshot -wipe-data -port "$START_PORT" >/dev/null 2>&1 & -echo "$(tput setaf 2)Emulator AVD $AVD_NAME started on port $START_PORT$(tput sgr0)" +echo "$(tput setaf 2)Starting AVD $AVD_NAME on port $START_PORT$(tput sgr0)" +echo "Waiting for emulator to boot..." +"$ADB_PATH" wait-for-device # Check if socat is available only on Linux if [ "$(uname)" = "Linux" ]; then @@ -124,7 +126,7 @@ if [ -n "$GAPPS_ZIP" ]; then tar -x --strip-components 2 -f $f -C $PLAY_EXTRACT_DIR || { echo "$(tput setaf 1)Error: Extraction failed$(tput sgr0)"; exit 1; } done - echo "Waiting for emulator to complete booting..." + echo "Waiting for the emulator to be ready..." sleep 25 echo "Installing PlayStore components" "$ADB_PATH" root