forked from FeynmanTech/cathook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetach
More file actions
executable file
·37 lines (32 loc) · 795 Bytes
/
detach
File metadata and controls
executable file
·37 lines (32 loc) · 795 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
37
#!/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 Detaching from ${arr[$1]}
if grep -q $(realpath bin/libcathook.so) /proc/${arr[$1]}/maps; then
gdb -n -q -batch \
-ex "attach ${arr[$1]}" \
-ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \
-ex "set \$dlclose = (int(*)(void*)) dlclose" \
-ex "set \$library = \$dlopen(\"$(realpath libcathook.so)\", 6)" \
-ex "print \$library" \
-ex "call \$dlclose(\$library)" \
-ex "call \$dlclose(\$library)" \
-ex "detach" \
-ex "quit"
echo "Detached"
else
echo "not found!"
fi