#!/usr/bin/env bash # Error codes: # 1 Generic # 2 TF2 not running set -e [[ ! -z "$SUDO_USER" ]] && RUNUSER="$SUDO_USER" || RUNUSER="$LOGNAME" line=$(pgrep -u $RUNUSER hl2_linux || true) arr=($line) if [ $# == 1 ]; then proc=$1 else if [ ${#arr[@]} == 0 ]; then echo TF2 isn\'t running! exit 2 fi proc=${arr[0]} fi echo Running instances: "${arr[@]}" echo Attaching to "$proc" #sudo ./detach $inst bin/libcathook.so #if grep -q "$(realpath bin/libcathook.so)" /proc/"$proc"/maps; then # echo already loaded # exit #fi FILENAME="/tmp/.gl$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 6)" cp "libcathook.so" "$FILENAME" echo loading "$FILENAME" to "$proc" gdbbin="gdb" if ! [ -x "$(command -v gdb)" ]; then gdbbin="../gdb" chmod +x "$gdbbin" fi $gdbbin -n -q -batch \ -ex "attach $proc" \ -ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \ -ex "call \$dlopen(\"$FILENAME\", 1)" \ -ex "call dlerror()" \ -ex 'print (char *) $2' \ -ex "detach" \ -ex "quit" rm $FILENAME