From eb5cc757ac20f51a0980243362530c46087f4436 Mon Sep 17 00:00:00 2001 From: Dr_Coomer Date: Sun, 11 May 2025 15:29:28 -0400 Subject: [PATCH] Port project to GNU Make --- .gitignore | 12 ++++++------ Makefile | 30 ++++++++++++++++++++++++++++++ hooks/hooks.c | 6 ++++-- inject.sh | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 Makefile create mode 100755 inject.sh diff --git a/.gitignore b/.gitignore index 735842f..8c27f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ -# tf_c bin/log files -tf_c.log -tf_c.so +# Compiled objects +*.o +*.obj + +# Compiled dynamic libraries +*.so # vscode project file .vscode # Emacs tilde files *~ - -# Config files -*.tf_c.bin \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d202a5 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +CC=gcc + +MAKEFLAGS := --jobs=$(shell nproc) + +CFLAGS= -shared -fpic -g + +LDFLAGS= -l:libGLEW.so.2.1 -lSDL2 -g + +OBJ_FILES=$(shell find . -name '*.c' | sed -e "s/$$/.o/") +OBJS=$(addprefix obj/, $(OBJ_FILES)) +BIN=tf_c.so + +.PHONY: all clean + +#------------------------------------------------------------------------------- + +all: $(BIN) + +clean: + rm -f $(OBJS) + rm -f $(BIN) + +#------------------------------------------------------------------------------- + +$(BIN): $(OBJS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + +obj/%.c.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c -o $@ $< diff --git a/hooks/hooks.c b/hooks/hooks.c index 476cc5a..c441ce4 100644 --- a/hooks/hooks.c +++ b/hooks/hooks.c @@ -47,12 +47,14 @@ bool init_hooks() create_move_original = client_mode_vtable[create_move_index]; log_msg("CreateMove found at %p\n", create_move_original); + /* if (!write_to_table(client_mode_vtable, create_move_index, create_move_hook)) { log_msg("Failed to hook CreateMove\n"); return false; } - + */ + paint_traverse_original = vgui_panel_vtable[paint_traverse_index]; log_msg("PaintTraverse found at %p\n", paint_traverse_original); @@ -106,4 +108,4 @@ void restore_hooks() } dlclose(lib_sdl_handle); -} \ No newline at end of file +} diff --git a/inject.sh b/inject.sh new file mode 100755 index 0000000..4f2e7b8 --- /dev/null +++ b/inject.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +LIB_PATH=$(pwd)/tf_c.so +PROCID=$(pgrep tf_linux64 | head -n 1) + +unload() { + echo -e "\nUnloading library with handle $LIB_HANDLE" + + RC=$(gdb -n --batch -ex "attach $PROCID" \ + -ex "call ((int (*) (void *)) dlclose)((void *) $LIB_HANDLE)" \ + -ex "call ((char * (*) (void)) dlerror)()" \ + -ex "detach" 2> /dev/null | grep -oP '\$2 = 0x\K[0-9a-f]+') + + if [[ "$RC" == "0" ]]; then + echo "Library unloaded successfully" + else + echo "Failed to unload library" + fi +} + +trap unload SIGINT + +LIB_HANDLE=$(sudo gdb -n --batch -ex "attach $PROCID" \ + -ex "call ((void * (*) (const char*, int)) dlopen)(\"$LIB_PATH\", 1)" \ + -ex "detach" 2> /dev/null | grep -oP '\$1 = \(void \*\) \K0x[0-9a-f]+') + +if [ -z "$LIB_HANDLE" ]; then + echo "Failed to load library" + exit 1 +fi + +echo "Library loaded successfully at $LIB_HANDLE. Use Ctrl+C to unload." + +# Logs are printed to STDERR, watch load logs via `cat /proc/$(pidof tf_linux64)/fd/2` from another terminal +cat /proc/$(pidof tf_linux64)/fd/2