FridaSetupScript.sh
3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/system/bin/sh
# =============================================================================
# FridaSetupScript.sh — frida-server device initialisation
#
# Purpose:
# Download the correct frida-server binary for the device architecture,
# install it to /data/local/tmp/, and start it.
#
# Usage (executed via RootShell on the Android device):
# su -c "sh /data/local/tmp/FridaSetupScript.sh [frida_version]"
#
# Arguments:
# $1 (optional) frida-server version to install, e.g. "16.2.1".
# Defaults to the value of FRIDA_VERSION below.
#
# Requirements:
# - Root shell (su)
# - curl or wget available on the device
# - Internet access (or a local mirror set via FRIDA_MIRROR)
# =============================================================================
set -e
FRIDA_VERSION="${1:-16.2.1}"
FRIDA_INSTALL_DIR="/data/local/tmp"
FRIDA_SERVER_BIN="$FRIDA_INSTALL_DIR/frida-server"
FRIDA_MIRROR="https://github.com/frida/frida/releases/download"
# ---------------------------------------------------------------------------
# 1. Detect device ABI
# ---------------------------------------------------------------------------
ARCH="$(getprop ro.product.cpu.abi)"
case "$ARCH" in
arm64-v8a) FRIDA_ARCH="android-arm64" ;;
armeabi-v7a) FRIDA_ARCH="android-arm" ;;
x86_64) FRIDA_ARCH="android-x86_64" ;;
x86) FRIDA_ARCH="android-x86" ;;
*)
echo "[frida-setup] ERROR: unsupported ABI: $ARCH" >&2
exit 1
;;
esac
echo "[frida-setup] Device ABI: $ARCH → frida arch: $FRIDA_ARCH"
# ---------------------------------------------------------------------------
# 2. Download frida-server
# ---------------------------------------------------------------------------
FILENAME="frida-server-${FRIDA_VERSION}-${FRIDA_ARCH}.xz"
DOWNLOAD_URL="$FRIDA_MIRROR/${FRIDA_VERSION}/${FILENAME}"
COMPRESSED_PATH="$FRIDA_INSTALL_DIR/$FILENAME"
echo "[frida-setup] Downloading $DOWNLOAD_URL …"
if command -v curl > /dev/null 2>&1; then
curl -fSL -o "$COMPRESSED_PATH" "$DOWNLOAD_URL"
elif command -v wget > /dev/null 2>&1; then
wget -q -O "$COMPRESSED_PATH" "$DOWNLOAD_URL"
else
echo "[frida-setup] ERROR: neither curl nor wget found" >&2
exit 1
fi
echo "[frida-setup] Download complete: $COMPRESSED_PATH"
# ---------------------------------------------------------------------------
# 3. Decompress
# ---------------------------------------------------------------------------
if command -v xz > /dev/null 2>&1; then
xz -d "$COMPRESSED_PATH"
DECOMPRESSED="$FRIDA_INSTALL_DIR/frida-server-${FRIDA_VERSION}-${FRIDA_ARCH}"
else
# Fallback: use busybox xz or a pre-extracted binary pushed via adb.
echo "[frida-setup] WARNING: xz not available, assuming binary was pre-extracted" >&2
DECOMPRESSED="$COMPRESSED_PATH"
fi
mv "$DECOMPRESSED" "$FRIDA_SERVER_BIN"
# ---------------------------------------------------------------------------
# 4. Set executable permission
# ---------------------------------------------------------------------------
chmod 755 "$FRIDA_SERVER_BIN"
echo "[frida-setup] Installed: $FRIDA_SERVER_BIN"
# ---------------------------------------------------------------------------
# 5. Start frida-server
# ---------------------------------------------------------------------------
# Kill any previous instance before starting a fresh one.
pkill -f frida-server 2>/dev/null || true
sleep 0.5
setsid "$FRIDA_SERVER_BIN" &>/dev/null &
sleep 1
# ---------------------------------------------------------------------------
# 6. Verify the process is running
# ---------------------------------------------------------------------------
if ps | grep -v grep | grep -q frida-server; then
VERSION_OUT="$($FRIDA_SERVER_BIN --version 2>/dev/null || echo 'unknown')"
echo "[frida-setup] frida-server $VERSION_OUT is running (port 27042)"
exit 0
else
echo "[frida-setup] ERROR: frida-server did not start" >&2
exit 1
fi