forked from MistakesMultiplied/cathook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattach-libnamed.sh
executable file
·57 lines (43 loc) · 1.77 KB
/
attach-libnamed.sh
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
#!/usr/bin/env bash
# Thank you LWSS
# https://github.com/LWSS/Fuzion/commit/a53b6c634cde0ed47b08dd587ba40a3806adf3fe
[[ ! -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"
# Get a Random name from the build_names file.
FILENAME=$(shuf -n 1 build_names)
# Create directory if it doesn't exist
if [ ! -d "/lib/i386-linux-gnu/" ]; then
mkdir /lib/i386-linux-gnu/
fi
# In case this file exists, get another one. ( checked it works )
while [ -f "/lib/i386-linux-gnu/${FILENAME}" ]; do
FILENAME=$(shuf -n 1 build_names)
done
# echo $FILENAME > build_id # For detaching
sudo cp "bin/libcathook.so" "/lib/i386-linux-gnu/${FILENAME}"
echo loading "$FILENAME" to "$proc"
gdbbin="gdb"
$gdbbin -n -q -batch \
-ex "attach $proc" \
-ex "echo \033[1mCalling dlopen\033[0m\n" \
-ex "call ((void*(*)(const char*, int))dlopen)(\"/lib/i386-linux-gnu/$FILENAME\", 1)" \
-ex "echo \033[1mCalling dlerror\033[0m\n" \
-ex "call ((char*(*)(void))dlerror)()" \
-ex "detach" \
-ex "quit"
sudo rm "/lib/i386-linux-gnu/${FILENAME}"