From 2de25ae24f7f0d9c2546a2277fbf17d5890f3391 Mon Sep 17 00:00:00 2001 From: Wizzard <25581244+Wizzard@users.noreply.toomuchslop.com> Date: Fri, 8 Dec 2023 18:14:48 -0500 Subject: [PATCH] Add .gitignore and inject.sh --- .gitignore | 35 +++++++++++++++++++++++++++++ inject.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .gitignore create mode 100755 inject.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9370ef4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Folders +build/ + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/inject.sh b/inject.sh new file mode 100755 index 0000000..305d1f6 --- /dev/null +++ b/inject.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +pid=$(pidof "hl2_linux") +libpath=$(realpath "libcstrike-basehook.so") + +if [ "$pid" == "" ]; then + echo "inject.sh: process not running." + exit 1 +fi + +# Used to echo the command. For debugging. +#set -x + +if [ "$1" == "unload" ]; then + sudo gdb -n -q -batch \ + -ex "attach $pid" \ + -ex "set \$dlopen = (void* (*)(char*, int))dlopen" \ + -ex "set \$dlclose = (int (*)(void*))dlclose" \ + -ex "set \$dlerror = (char* (*)(void))dlerror" \ + \ + -ex "set \$self = \$dlopen(\"$libpath\", 6)" \ + -ex "call \$dlclose(\$self)" \ + -ex "call \$dlclose(\$self)" \ + \ + -ex "call \$dlerror()" \ + -ex "detach" \ + -ex "quit" + + exit 0 +fi + +if grep -q "$libpath" "/proc/$pid/maps"; then + echo -e "goldsource-cheat already loaded. Reloading...\n"; + + # 0x2 -> RTLD_NOW + # 0x6 -> RTLD_LAZY | RTLD_NOLOAD + # For more info on the 3 mid lines, see self_unload() in main.c + sudo gdb -n -q -batch \ + -ex "attach $pid" \ + -ex "set \$dlopen = (void* (*)(char*, int))dlopen" \ + -ex "set \$dlclose = (int (*)(void*))dlclose" \ + -ex "set \$dlerror = (char* (*)(void))dlerror" \ + \ + -ex "set \$self = \$dlopen(\"$libpath\", 6)" \ + -ex "call \$dlclose(\$self)" \ + -ex "call \$dlclose(\$self)" \ + \ + -ex "call \$dlopen(\"$libpath\", 2)" \ + -ex "call \$dlerror()" \ + -ex "detach" \ + -ex "quit" +else + sudo gdb -n -q -batch \ + -ex "attach $pid" \ + -ex "set \$dlopen = (void* (*)(char*, int))dlopen" \ + -ex "set \$dlclose = (int (*)(void*))dlclose" \ + -ex "set \$dlerror = (char* (*)(void))dlerror" \ + -ex "call \$dlopen(\"$libpath\", 2)" \ + -ex "call \$dlerror()" \ + -ex "detach" \ + -ex "quit" +fi + +set +x +echo -e "\nDone."