forked from awong-dev/insanity-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidb
executable file
·42 lines (32 loc) · 1.17 KB
/
idb
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
#!/bin/bash
SCRIPT_DIR="$(dirname $0)"
. "$SCRIPT_DIR/env.sh"
LOCAL_LIBS=/tmp/ndk-android-libs
LOCAL_BIN=/tmp/ndk-test-bin
GDBSERVER=$NDK/prebuilt/android-arm/gdbserver/gdbserver
GDB=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/${TOOLCHAIN_PLATFORM}-x86_64/bin/arm-linux-androideabi-gdb
if [ ! -d $LOCAL_LIBS/system/lib ]; then
mkdir -p $LOCAL_LIBS/system/lib
mkdir -p $LOCAL_BIN
#1. Download all shared libs from phone to disk.
adb pull /system/lib $LOCAL_LIBS/system/lib
#2. Push gdbserver to the phone.
adb push $GDBSERVER /data/local/tmp/
fi
#3. Port forward
adb forward tcp:5039 tcp:5039
#4. Grab the binaries off the phone.
rm -f $LOCAL_BIN/*
adb pull /data/local/tmp/libcxx/ $LOCAL_BIN
#5. Determine Binary name
BINARY=$(basename $(ls $LOCAL_BIN/testit_*))
#6. Run gdbserver on the phone.
adb shell LD_LIBRARY_PATH=/data/local/tmp/libcxx LIBUNWIND_PRINT_UNWINDING=1 /data/local/tmp/gdbserver :5039 /data/local/tmp/libcxx/$BINARY &
sleep 1
#7. Run gdb
$GDB \
-ex "set solib-search-path $LOCAL_BIN:$LOCAL_LIBS/system/lib" \
-ex "set solib-absolute-prefix $LOCAL_LIBS" \
-ex "target remote :5039" \
-ex "break main" -ex "continue" \
$LOCAL_BIN/$BINARY