|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Radiography - View Hierarchy Scanner for Android |
| 4 | +# A wrapper script for the Radiography Stoic plugin |
| 5 | +# |
| 6 | + |
| 7 | +set -e |
| 8 | + |
| 9 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | +PLUGIN_APK="${SCRIPT_DIR}/stoic-plugin-debug.apk" |
| 11 | + |
| 12 | +# Check if stoic is installed |
| 13 | +if ! command -v stoic &> /dev/null; then |
| 14 | + echo "Error: 'stoic' command not found. Please install Stoic first." >&2 |
| 15 | + echo "See: https://github.com/block/stoic" >&2 |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Check if plugin APK exists |
| 20 | +if [[ ! -f "${PLUGIN_APK}" ]]; then |
| 21 | + echo "Error: Plugin APK not found at ${PLUGIN_APK}" >&2 |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Function to display usage |
| 26 | +usage() { |
| 27 | + cat << EOF |
| 28 | +Usage: radiography [OPTIONS] [PACKAGE] |
| 29 | +
|
| 30 | +Scan and print the view hierarchy of a running Android application using Radiography. |
| 31 | +
|
| 32 | +Arguments: |
| 33 | + PACKAGE Optional. The package name of the app to inspect. |
| 34 | + Can be specified as a positional argument or via --pkg/--package/-n. |
| 35 | + If not specified, Stoic will try to detect the foreground app. |
| 36 | +
|
| 37 | +Options: |
| 38 | + --pii Include PII (personally identifiable information) like text content |
| 39 | + --focused Scan only the focused window instead of all windows |
| 40 | + --pkg PACKAGE Specify the package name to inspect (same as -n, --package) |
| 41 | + --package PACKAGE Specify the package name to inspect (same as -n, --pkg) |
| 42 | + -n PACKAGE Specify the package name to inspect (same as --pkg, --package) |
| 43 | + -h, --help Display this help message |
| 44 | +
|
| 45 | +Device Selection (passed through to adb): |
| 46 | + -s SERIAL Use device with given serial number |
| 47 | + -d Use USB device |
| 48 | + -e Use emulator |
| 49 | +
|
| 50 | +Examples: |
| 51 | + # Scan the foreground app |
| 52 | + radiography |
| 53 | +
|
| 54 | + # Scan a specific app |
| 55 | + radiography com.example.myapp |
| 56 | +
|
| 57 | + # Scan with PII included |
| 58 | + radiography --pii com.example.myapp |
| 59 | +
|
| 60 | + # Scan only focused window |
| 61 | + radiography --focused com.example.myapp |
| 62 | +
|
| 63 | + # Scan on specific device |
| 64 | + radiography -s emulator-5554 com.example.myapp |
| 65 | +
|
| 66 | + # Use emulator |
| 67 | + radiography -e com.example.myapp |
| 68 | +
|
| 69 | + # Combine options |
| 70 | + radiography --pii --focused -s emulator-5554 com.example.myapp |
| 71 | +
|
| 72 | +For more information about Stoic, see: https://github.com/block/stoic |
| 73 | +For more information about Radiography, see: https://github.com/square/radiography |
| 74 | +EOF |
| 75 | +} |
| 76 | + |
| 77 | +# Parse arguments |
| 78 | +PLUGIN_ARGS=() |
| 79 | +STOIC_ARGS=() |
| 80 | +PACKAGE="" |
| 81 | + |
| 82 | +while [[ $# -gt 0 ]]; do |
| 83 | + case $1 in |
| 84 | + -h|--help) |
| 85 | + usage |
| 86 | + exit 0 |
| 87 | + ;; |
| 88 | + --pii|--focused) |
| 89 | + # Plugin arguments |
| 90 | + PLUGIN_ARGS+=("$1") |
| 91 | + shift |
| 92 | + ;; |
| 93 | + --pkg|--package|-n) |
| 94 | + # Package name arguments (passed through to stoic) |
| 95 | + if [[ $# -lt 2 ]]; then |
| 96 | + echo "Error: $1 requires a package name" >&2 |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + if [[ -n "${PACKAGE}" ]]; then |
| 100 | + echo "Error: Package already specified as '${PACKAGE}'" >&2 |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + PACKAGE_FLAG="$1" |
| 104 | + shift |
| 105 | + PACKAGE="$1" |
| 106 | + shift |
| 107 | + ;; |
| 108 | + -s|-d|-e) |
| 109 | + # ADB device selection arguments (passed through to stoic/adb) |
| 110 | + STOIC_ARGS+=("$1") |
| 111 | + if [[ "$1" == "-s" ]]; then |
| 112 | + if [[ $# -lt 2 ]]; then |
| 113 | + echo "Error: -s requires a device serial number" >&2 |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + shift |
| 117 | + STOIC_ARGS+=("$1") |
| 118 | + fi |
| 119 | + shift |
| 120 | + ;; |
| 121 | + -*) |
| 122 | + echo "Error: Unknown option: $1" >&2 |
| 123 | + echo "Run 'radiography --help' for usage information." >&2 |
| 124 | + exit 1 |
| 125 | + ;; |
| 126 | + *) |
| 127 | + # Assume it's the package name (positional argument) |
| 128 | + if [[ -n "${PACKAGE}" ]]; then |
| 129 | + echo "Error: Package already specified as '${PACKAGE}'" >&2 |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | + PACKAGE="$1" |
| 133 | + PACKAGE_FLAG="--pkg" # Default to --pkg when using positional argument |
| 134 | + shift |
| 135 | + ;; |
| 136 | + esac |
| 137 | +done |
| 138 | + |
| 139 | +# Build the stoic command |
| 140 | +STOIC_CMD=(stoic "${STOIC_ARGS[@]}") |
| 141 | + |
| 142 | +# Add package name if specified (preserve the flag the user used, or use --pkg as default) |
| 143 | +if [[ -n "${PACKAGE}" ]]; then |
| 144 | + STOIC_CMD+=("${PACKAGE_FLAG}" "${PACKAGE}") |
| 145 | +fi |
| 146 | + |
| 147 | +# Add the plugin APK and its arguments |
| 148 | +STOIC_CMD+=("${PLUGIN_APK}" "${PLUGIN_ARGS[@]}") |
| 149 | + |
| 150 | +# Execute stoic |
| 151 | +exec "${STOIC_CMD[@]}" |
0 commit comments