From 24ca502e3af452603ed191948e5ece016e2204b2 Mon Sep 17 00:00:00 2001 From: DrFrugal Date: Mon, 30 Dec 2024 18:42:10 +0100 Subject: init --- Hook/Hook.cpp | 52 ++++++++++++++ Hook/Hook.def | 3 + Hook/Hook.vcxproj | 172 ++++++++++++++++++++++++++++++++++++++++++++++ Hook/Hook.vcxproj.filters | 39 +++++++++++ Hook/Hook.vcxproj.user | 4 ++ Hook/framework.h | 5 ++ Hook/packages.config | 4 ++ Hook/pch.cpp | 5 ++ Hook/pch.h | 13 ++++ 9 files changed, 297 insertions(+) create mode 100644 Hook/Hook.cpp create mode 100644 Hook/Hook.def create mode 100644 Hook/Hook.vcxproj create mode 100644 Hook/Hook.vcxproj.filters create mode 100644 Hook/Hook.vcxproj.user create mode 100644 Hook/framework.h create mode 100644 Hook/packages.config create mode 100644 Hook/pch.cpp create mode 100644 Hook/pch.h (limited to 'Hook') diff --git a/Hook/Hook.cpp b/Hook/Hook.cpp new file mode 100644 index 0000000..201bede --- /dev/null +++ b/Hook/Hook.cpp @@ -0,0 +1,52 @@ +#include "pch.h" +#include +#include +#include +#include +#include + +int cvarCallIndex = 0; +FILE* csvFile; + +std::string handleString(char* input) +{ + if (input == 0) return ""; // return empty string if it was a nullptr + std::string replacement = input; + std::size_t found = replacement.find("\""); + while (found != std::string::npos) { // escape double quotes by doubling them + replacement.replace(found, 1, "\"\""); + found = replacement.find("\"", found + 2); + } + return replacement; +} + +void* CVar__Register = (void*)0x00767fc0; +UINT32 __cdecl CVar__Register__Hook(char* name, char* description, UINT32 flags, char* defaultValue, PVOID callback, UINT32 category, BYTE saveToWTF, UINT32 param_8, BYTE param_9) +{ + void* callAddress = (void*)((uintptr_t)_ReturnAddress() - 5); // subtracting the length of a CALL instruction to find out where we have been called from + fprintf_s(csvFile, R"(%s"%i", "%p", "%s", "%s", "%i", "%s", "%p", "%i", "%hhu", "%i", "%hhu")", "\n", cvarCallIndex, callAddress, handleString(name).c_str(), handleString(description).c_str(), flags, defaultValue, callback, category, saveToWTF, param_8, param_9); + cvarCallIndex++; + return ((decltype(&CVar__Register__Hook))CVar__Register)(name, description, flags, defaultValue, callback, category, saveToWTF, param_8, param_9); +} + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + if (DetourIsHelperProcess()) return TRUE; + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + fopen_s(&csvFile, "CVar__Register_calls_3.3.5.12340.csv", "w"); + if (csvFile == 0) return -1; + fprintf_s(csvFile, R"("Index", "Call Address", "Name", "Description", "Flags", "Default Value", "Callback Address", "Category", "Save To WTF", "param_8", "param_9")"); + DetourRestoreAfterWith(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&CVar__Register, CVar__Register__Hook); + if (DetourTransactionCommit() != NO_ERROR) MessageBoxA(NULL, "DetourAttach failed", "error", 0); + break; + case DLL_PROCESS_DETACH: + fclose(csvFile); + break; + } + return TRUE; +} diff --git a/Hook/Hook.def b/Hook/Hook.def new file mode 100644 index 0000000..b0766d2 --- /dev/null +++ b/Hook/Hook.def @@ -0,0 +1,3 @@ +LIBRARY Hook +EXPORTS + DllMain @1 diff --git a/Hook/Hook.vcxproj b/Hook/Hook.vcxproj new file mode 100644 index 0000000..ff8d7c2 --- /dev/null +++ b/Hook/Hook.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {597797c6-99d2-4354-ac7d-a030ec7dfaac} + Hook + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;HOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + Hook.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;HOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + Hook.def + + + + + Level3 + true + _DEBUG;HOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + Hook.def + + + + + Level3 + true + true + true + NDEBUG;HOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + Hook.def + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Hook/Hook.vcxproj.filters b/Hook/Hook.vcxproj.filters new file mode 100644 index 0000000..53ccc8b --- /dev/null +++ b/Hook/Hook.vcxproj.filters @@ -0,0 +1,39 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + + + + Source Files + + + \ No newline at end of file diff --git a/Hook/Hook.vcxproj.user b/Hook/Hook.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/Hook/Hook.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Hook/framework.h b/Hook/framework.h new file mode 100644 index 0000000..a9744f8 --- /dev/null +++ b/Hook/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include diff --git a/Hook/packages.config b/Hook/packages.config new file mode 100644 index 0000000..7b19a9c --- /dev/null +++ b/Hook/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Hook/pch.cpp b/Hook/pch.cpp new file mode 100644 index 0000000..91c22df --- /dev/null +++ b/Hook/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/Hook/pch.h b/Hook/pch.h new file mode 100644 index 0000000..04ff4c2 --- /dev/null +++ b/Hook/pch.h @@ -0,0 +1,13 @@ +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef PCH_H +#define PCH_H + +// add headers that you want to pre-compile here +#include "framework.h" + +#endif //PCH_H -- cgit v1.2.3