forked from FeynmanTech/cathook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attach-gdb
executable file
·52 lines (39 loc) · 1.35 KB
/
attach-gdb
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
52
#!/usr/bin/env bash
[[ ! -z "$SUDO_USER" ]] && RUNUSER="$SUDO_USER" || RUNUSER="$LOGNAME"
RUNCMD="sudo -u $RUNUSER"
$RUNCMD bash ./scripts/updater true
$RUNCMD bash ./report-crash true
line=$(pgrep -u $RUNUSER hl2_linux)
arr=($line)
if [ $# == 1 ]; then
proc=$1
else
if [ ${#arr[@]} == 0 ]; then
echo TF2 isn\'t running!
exit
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 "bin/libcathook.so" "$FILENAME"
echo loading "$FILENAME" to "$proc"
gdbbin="gdb"
if [ -x "./bin/gdb-arch-2021-02" ]; then
gdbbin="./bin/gdb-arch-2021-02"
fi
$gdbbin -n -q -batch \
-ex "attach $proc" \
-ex "echo \033[1mCalling dlopen\033[0m\n" \
-ex "call ((void*(*)(const char*, int))dlopen)(\"$FILENAME\", 1)" \
-ex "echo \033[1mCalling dlerror\033[0m\n" \
-ex "call ((char*(*)(void))dlerror)()" \
-ex "continue" \
-ex "backtrace"
rm $FILENAME