Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/system/bin/sh
- # default commands
- LOGCAT_BIN="su 0 logcat"
- SLEEP_BIN=sleep
- ADDR2LINE_BIN=addr2line
- TAIL_BIN=tail
- # do not use gdb and gdbserver coming with termux,
- # it is a segfaulting bullshit (compiled with clang???)
- GDBSERVER_BIN="su 0 ./gdbserver"
- GDB_BIN=~/arm-linux-androideabi-gdb
- # prevent ^C killing logcat
- BLOCKINT_BIN=~/blockint
- # shitty logcat switching terminal to CRLF, workaround it by \r
- PRINTF_BIN=printf
- CUT_BIN=cut
- AM_BIN=am
- KILLALL_BIN=killall
- KILLALL_ROOT_BIN="su 0 killall"
- # default options
- VARS=
- MODARGS=
- # for some reason it is -2 when not running from root
- USER=0
- ARGS=
- LOGCAT=
- PID=
- MOD=
- GDB=
- DELAY=1s
- GDBARGS=
- CR="$PRINTF_BIN \\r"
- while [ -n "$1" ]; do
- case $1 in
- *=*) VARS=$VARS$(echo $1|$CUT_BIN -d\= -f1),$(echo $1|$CUT_BIN -d= -f2),;shift 1 ;;
- -e) MODARGS="$MODARGS -e $2";shift 2;;
- -m) MODARGS="$MODARGS -e gamelibdir /data/data/in.celest.xash3d.$2/lib";MOD=$2;shift 2;;
- -h) echo Usage: startxash [-m modname] [-g gamedir] [ENV1=VALUE1] [args]; exit 0 ;;
- -g) MODARGS="$MODARGS -e gamedir $2";shift 2;;
- -u) USER=$2;shift 2;;
- -l) LOGCAT=1;$LOGCAT_BIN -G64k;$LOGCAT_BIN -c;shift 1;;
- -gdb) GDB=1;$LOGCAT_BIN -G64k;$LOGCAT_BIN -c;MODARGS="$MODARGS -e gdbsafe 1";shift 1;;
- -d) DELAY=$2;shift 2;;
- -c) GDBARGS="$GDBARGS -ex c";shift 1;;
- -log) LOG=1;ARGS="$ARGS$1 ";shift 1;;
- *) ARGS="$ARGS$1 ";shift 1 ;;
- esac
- done
- _addr2line()
- {
- addr2line -fCpi -e $7 $6|while read line; do echo "$line";$CR;done
- }
- runlogcat()
- {
- $BLOCKINT_BIN $LOGCAT_BIN < /dev/null|while read line;do
- case $line in
- I/ActivityManager*:\ Start\ proc\ *in.celest.xash3d.hl.test*)
- PID=$(echo $line|$CUT_BIN -d: -f2| $CUT_BIN -d\ -f4)
- $PRINTF_BIN Found\ PID:$PID\\r\\n
- if [ -n "$GDB" ]; then
- $SLEEP_BIN $DELAY
- $GDBSERVER_BIN --attach 127.0.0.1:6666 $(pidof in.celest.xash3d.hl.test) &
- fi
- echo "$line" ;;
- *\(*$PID*\):*) echo "$line";;
- ?/ActivityManager*\(pid\ $PID\)\ has\ died*) $KILLALL_ROOT_BIN logcat;echo end;;
- ?/DEBUG*\):*\#*)
- echo "$line"
- _addr2line $(echo $line|$CUT_BIN -d $($CR) -f1)
- ;;
- ?/DEBUG*\):*) echo "$line";;
- ?/AndroidRuntime*\):*) echo "$line";;
- *) ;;
- esac
- done
- }
- $AM_BIN start --user $USER -a in.celest.xash3d.START -n in.celest.xash3d.hl.test/in.celest.xash3d.XashActivity -e argv "$ARGS" --esa env "$VARS" $MODARGS
- if [ -n "$LOGCAT" ]; then
- runlogcat
- elif [ -n "$GDB" ]; then
- runlogcat &
- $SLEEP_BIN $DELAY
- $GDB_BIN -ex "set solib-search-path /data/data/in.celest.xash3d.$MOD/lib:/data/data/in.celest.xash3d.hl.test/lib:/system/lib/hw:/system/lib:/vendor/lib" -ex "file /system/bin/app_process" -ex "target remote 127.0.0.1:6666" -ex "handle SIG33 nostop" -ex "thread 1" $GDBARGS
- $KILLALL_ROOT logcat
- elif [ -n "$LOG" ]; then
- $TAIL_BIN -c0 -f $LOG| while read line; do case $line in
- *Sys_DestroyConsole:*) $KILLALL_BIN tail;;
- *) echo "$line";;esac;done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement