From bb1aa5cd07810254e64e78f47d86de46b80e154f Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 28 Oct 2018 17:32:16 +0100 Subject: [PATCH] Add attach-gdb --- CMakeLists.txt | 2 +- attach-gdb | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 attach-gdb diff --git a/CMakeLists.txt b/CMakeLists.txt index f19c8fa3..3765f1b6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ set(DataPath "/opt/cathook/data" CACHE FILEPATH "Data location") set(VACBypass 0 CACHE BOOL "Textmode VAC bypass") set(Textmode 0 CACHE BOOL "Various textmode-only features for bots") set(EnableTextmodeStdin 0 CACHE BOOL "Textmode Stdin -> Console bridge (EXPERIMENTAL)") -set(EnableWarnings 1 CACHE BOOL "Enable compile warnings") +set(EnableWarnings 0 CACHE BOOL "Enable compile warnings") set(EnableNullGraphics 0 CACHE BOOL "Enable experimental textmode hooks (CRASHES)") set(EnableOnlineFeatures 0 CACHE BOOL "Enable online features (WIP)") diff --git a/attach-gdb b/attach-gdb new file mode 100755 index 00000000..ba742100 --- /dev/null +++ b/attach-gdb @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +line=$(pidof hl2_linux) +arr=($line) +inst=$1 +if [ $# == 0 ]; then + inst=0 +fi + +if [ ${#arr[@]} == 0 ]; then + echo TF2 isn\'t running! + exit +fi + +if [ $inst -gt ${#arr[@]} ] || [ $inst == ${#arr[@]} ]; then + echo wrong index! + exit +fi + +proc=${arr[$inst]} + +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 + +# pBypass for crash dumps being sent +# You may also want to consider using -nobreakpad in your launch options. +sudo rm -rf /tmp/dumps # Remove if it exists +sudo mkdir /tmp/dumps # Make it as root +sudo chmod 000 /tmp/dumps # No permissions + +FILENAME="/tmp/.gl$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)" + +cp "bin/libcathook.so" "$FILENAME" + +echo loading "$FILENAME" to "$proc" + +sudo killall -19 steam +sudo killall -19 steamwebhelper + +gdb -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 "catch syscall exit exit_group" \ + -ex "detach" \ + -ex "quit" + +sudo killall -18 steamwebhelper +sudo killall -18 steam + +gdb -n -q -batch \ + -ex "attach $proc" \ + -ex "continue" \ + -ex "backtrace" + +rm $FILENAME