forked from FeynmanTech/cathook
/
attach-gdb
executable file
·67 lines (50 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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
sudo ./scripts/auto-updater &
gdb -n -q -batch \
-ex "attach $proc" \
-ex "continue" \
-ex "backtrace"
rm $FILENAME