-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathandroid_lib_pull.sh
More file actions
executable file
·51 lines (42 loc) · 1.31 KB
/
android_lib_pull.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.31 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
#!/bin/bash
PKG_NAME=$1
SYSROOT="./android_sysroot"
TEMP_TAR="/data/local/tmp/sysroot_temp.tar"
PATHS_TO_PULL=(
"/system/lib64"
"/system/bin"
"/vendor/lib64"
"/apex/com.android.runtime"
"/apex/com.android.art"
"/apex/com.android.tethering"
)
adb get-state 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "adb not connected"
exit 1
fi
APP_LIB_PATHS=()
if [ ! -z "$PKG_NAME" ]; then
APK_PATH=$(adb shell pm path "$PKG_NAME" 2>/dev/null | head -n 1 | cut -d : -f 2)
if [ -z "$APK_PATH" ]; then
echo "cannot find'$PKG_NAME'"
echo "------------------------------------------------"
adb shell pm list package -3 | cut -d : -f 2
exit 1
fi
APP_BASE_DIR=$(dirname "$APK_PATH")
LIB_EXISTS=$(adb shell "ls -d $APP_BASE_DIR/lib 2>/dev/null")
if [ ! -z "$LIB_EXISTS" ]; then
APP_LIB_PATHS+=("$APP_BASE_DIR/lib")
APP_LIB_PATHS+=("$APP_BASE_DIR/oat")
fi
fi
TOTAL_PATHS=("${PATHS_TO_PULL[@]}" "${APP_LIB_PATHS[@]}")
adb shell "tar -cvf $TEMP_TAR ${TOTAL_PATHS[*]} 2>/dev/null"
mkdir -p "$SYSROOT"
adb pull "$TEMP_TAR" "$SYSROOT/sysroot.tar"
tar -xvf "$SYSROOT/sysroot.tar" -C "$SYSROOT"
rm "$SYSROOT/sysroot.tar"
adb shell rm "$TEMP_TAR"
echo "------------------------------------------------"
echo "[*] pwndbg> set sysroot $(realpath "$SYSROOT")"