forked from FeynmanTech/cathook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach
More file actions
executable file
·37 lines (30 loc) · 716 Bytes
/
attach
File metadata and controls
executable file
·37 lines (30 loc) · 716 Bytes
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
#!/bin/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
echo Running instances: ${arr[@]}
echo Attaching to ${arr[$1]}
if grep -q $(realpath bin/libcathook.so) /proc/${arr[$1]}/maps; then
echo already loaded
exit
fi
echo loading $(realpath bin/libcathook.so) to ${arr[$1]}
gdb -n -q -batch \
-ex "attach ${arr[$1]}" \
-ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \
-ex "call \$dlopen(\"$(realpath bin/libcathook.so)\", 1)" \
-ex "call dlerror()" \
-ex 'print (char *) $2' \
-ex "detach" \
-ex "quit"