|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Assumes: Android emulator/device is available via ADB and Frida CLI is installed on computer |
| 5 | +# Wait for device, install APK, and set up Frida server (all idempotent) |
| 6 | + |
| 7 | +# Wait for emulator/device to be available |
| 8 | +adb wait-for-device |
| 9 | +adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' |
| 10 | +echo "Emulator/device booted." |
| 11 | + |
| 12 | +# Download and install APK if not already installed |
| 13 | +APK_PATH="/tmp/pinning-demo.apk" |
| 14 | +APK_URL="https://github.com/httptoolkit/android-ssl-pinning-demo/releases/download/v1.4.1/pinning-demo.apk" |
| 15 | +PACKAGE="app.htp.demo" |
| 16 | +if ! adb shell pm list packages | grep -q "$PACKAGE"; then |
| 17 | + wget -q $APK_URL -O $APK_PATH |
| 18 | + adb install -r $APK_PATH |
| 19 | + echo "APK installed." |
| 20 | +else |
| 21 | + echo "APK already installed." |
| 22 | +fi |
| 23 | + |
| 24 | +# Set up Frida server |
| 25 | +FRIDA_VERSION=$(frida --version) |
| 26 | +FRIDA_SERVER_URL="https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/frida-server-${FRIDA_VERSION}-android-x86_64.xz" |
| 27 | +FRIDA_SERVER_LOCAL="/tmp/frida-server" |
| 28 | +FRIDA_SERVER_REMOTE="/data/local/tmp/frida-server" |
| 29 | + |
| 30 | +if ! adb shell pgrep -f frida-server > /dev/null; then |
| 31 | + if [ ! -f $FRIDA_SERVER_LOCAL ]; then |
| 32 | + wget -q $FRIDA_SERVER_URL -O /tmp/frida-server.xz |
| 33 | + unxz -f /tmp/frida-server.xz |
| 34 | + chmod +x $FRIDA_SERVER_LOCAL |
| 35 | + fi |
| 36 | + adb root || true |
| 37 | + adb remount || true |
| 38 | + adb push $FRIDA_SERVER_LOCAL $FRIDA_SERVER_REMOTE |
| 39 | + adb shell "chmod 755 $FRIDA_SERVER_REMOTE" |
| 40 | + adb shell "$FRIDA_SERVER_REMOTE &" |
| 41 | + echo "Frida server started on device." |
| 42 | +else |
| 43 | + echo "Frida server already running." |
| 44 | +fi |
0 commit comments