From 8902cfd399544b380b77a88ee96ef18a80cdccad Mon Sep 17 00:00:00 2001 From: Tim Perry <1526883+pimterry@users.noreply.github.com> Date: Tue, 24 Jun 2025 12:44:58 +0000 Subject: [PATCH] Try setting up an emulator in CI --- .github/workflows/ci.yml | 62 +++++++++++++++++++++++++++++++++- test/android/setup-emulator.sh | 47 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 test/android/setup-emulator.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae11398..602aa44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,4 +46,64 @@ jobs: asset_name: android-frida-interception-script-${{ github.ref }}.js file: ./build/android-frida-interception-script.js tag: ${{ github.ref }} - repo_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + repo_token: ${{ secrets.GITHUB_TOKEN }} + + test-android: + name: Test on Android emulator + runs-on: ubuntu-latest + strategy: + matrix: + api-level: [30] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Frida CLI + run: | + pip install --user frida-tools + echo "$HOME/.local/bin" >> $GITHUB_PATH + + # Apparently significantly improves emulator performance: + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + # Cache the emulator AVD: + - name: AVD cache + uses: actions/cache@v4 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ matrix.api-level }} + + - name: Create AVD and cache snapshot + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: google_apis + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + script: | + echo "Generated AVD snapshot for caching." + + - name: Run tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: google_apis + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + script: | + adb devices + bash test/android/setup-emulator.sh + echo "Emulator ready to test" + adb shell pgrep -f frida-server \ No newline at end of file diff --git a/test/android/setup-emulator.sh b/test/android/setup-emulator.sh new file mode 100755 index 0000000..d69e7de --- /dev/null +++ b/test/android/setup-emulator.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +# Assumes: Android emulator/device is available via ADB and Frida CLI is installed on computer +# Wait for device, install APK, and set up Frida server (all idempotent) + +# Wait for emulator/device to be available +adb wait-for-device +adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' +echo "Emulator/device booted." + +# Download and install APK if not already installed +APK_PATH="/tmp/pinning-demo.apk" +APK_URL="https://github.com/httptoolkit/android-ssl-pinning-demo/releases/download/v1.4.1/pinning-demo.apk" +PACKAGE="tech.httptoolkit.pinning_demo" +if ! adb shell pm list packages | grep -q "$PACKAGE"; then + wget -q $APK_URL -O $APK_PATH + adb install -r $APK_PATH + echo "APK installed." +else + echo "APK already installed." +fi + +# Set up Frida server +FRIDA_VERSION=$(frida --version) +FRIDA_SERVER_URL="https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/frida-server-${FRIDA_VERSION}-android-x86.xz" +FRIDA_SERVER_LOCAL="/tmp/frida-server" +FRIDA_SERVER_REMOTE="/data/local/tmp/frida-server" + +if ! adb shell pgrep -f frida-server > /dev/null; then + if [ ! -f $FRIDA_SERVER_LOCAL ]; then + wget -q $FRIDA_SERVER_URL -O /tmp/frida-server.xz + unxz -f /tmp/frida-server.xz + chmod +x $FRIDA_SERVER_LOCAL + fi + adb root || true + sleep 1 + adb push $FRIDA_SERVER_LOCAL $FRIDA_SERVER_REMOTE + echo 'Pushed' + adb shell "chmod 755 $FRIDA_SERVER_REMOTE" + echo 'chmoded' + adb shell "ls -l $FRIDA_SERVER_REMOTE" + adb shell "$FRIDA_SERVER_REMOTE" & + echo "Frida server started on device." +else + echo "Frida server already running." +fi