From 8611ce975fcd188f90b0d350e820b7ec1ef8cf78 Mon Sep 17 00:00:00 2001 From: Kuriko Moe Date: Mon, 8 Sep 2025 15:03:31 +0800 Subject: [PATCH] re-add dll hijack method --- justfile | 16 ++++----- src/dllmain.cpp | 9 +++++ src/proxy.h | 64 ++++++++++++++++++++++++++++++++++ third/dllmain.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++ third/version.def | 19 ++++++++++ xmake-requires.lock | 24 +++++++++++++ xmake.lua | 17 ++++----- 7 files changed, 217 insertions(+), 16 deletions(-) create mode 100644 src/proxy.h create mode 100644 third/dllmain.cpp create mode 100644 third/version.def diff --git a/justfile b/justfile index 9995961..340b908 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,5 @@ TEMPLATE_VER := "v1.0.0" -TARGET := "D:\\Games\\GamePlatforms\\SteamLibrary\\steamapps\\common\\Left 4 Dead 2" +TARGET := "D:\\Games\\Platforms\\SteamLibrary\\steamapps\\common\\Left 4 Dead 2" # use `just preset=x64-release config build` to override this preset := "x86-release-msvc" @@ -13,19 +13,19 @@ clean: rm -rf build build: - xmake f -m release + xmake f -m release -a x86 xmake copy: build cp build/windows/x86/release/kpatch.dll "{{TARGET}}" - cp build/windows/x86/release/left4dead2_fix.exe "{{TARGET}}" + # cp build/windows/x86/release/left4dead2_fix.exe "{{TARGET}}" cp kpatch.ini "{{TARGET}}" copyrel: xmake f -m release xmake cp build/windows/x86/release/kpatch.dll "{{TARGET}}" - cp build/windows/x86/release/left4dead2_fix.exe "{{TARGET}}" + # cp build/windows/x86/release/left4dead2_fix.exe "{{TARGET}}" release: rm release -rf @@ -34,11 +34,11 @@ release: # release xmake f -m release xmake - cp build/windows/x86/release/kpatch.dll release/ - cp build/windows/x86/release/left4dead2_fix.exe release/ + cp build/windows/x86/release/version.dll release/ cp assets/请读我.txt release/ - cp "assets/left4dead2_fix - Shortcut.lnk" release/ - cp third/4gb_patch.exe release/ + # cp build/windows/x86/release/left4dead2_fix.exe release/ + # cp third/4gb_patch.exe release/ + # cp "assets/left4dead2_fix - Shortcut.lnk" release/ cp kpatch.ini release/ @run: diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 2523a03..4d989b8 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -15,6 +15,8 @@ #include #include +#include "proxy.h" + #include "helper.hpp" #include "vars.h" @@ -163,6 +165,13 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: + // Setup proxy + char path[MAX_PATH]; + strcat_s(path, "C:\\Windows\\SysWOW64\\version.dll"); + GetWindowsDirectory(path, sizeof(path)); + version.dll = LoadLibrary(path); + setupFunctions(); + Main(nullptr); // HANDLE mainHandle = CreateThread(NULL, 0, Main, 0, CREATE_SUSPENDED, 0); // if (mainHandle) { diff --git a/src/proxy.h b/src/proxy.h new file mode 100644 index 0000000..599f6cc --- /dev/null +++ b/src/proxy.h @@ -0,0 +1,64 @@ +#include + +#pragma region Proxy +struct version_dll { + HMODULE dll; + FARPROC oGetFileVersionInfoA; + FARPROC oGetFileVersionInfoByHandle; + FARPROC oGetFileVersionInfoExA; + FARPROC oGetFileVersionInfoExW; + FARPROC oGetFileVersionInfoSizeA; + FARPROC oGetFileVersionInfoSizeExA; + FARPROC oGetFileVersionInfoSizeExW; + FARPROC oGetFileVersionInfoSizeW; + FARPROC oGetFileVersionInfoW; + FARPROC oVerFindFileA; + FARPROC oVerFindFileW; + FARPROC oVerInstallFileA; + FARPROC oVerInstallFileW; + FARPROC oVerLanguageNameA; + FARPROC oVerLanguageNameW; + FARPROC oVerQueryValueA; + FARPROC oVerQueryValueW; +} version; + +extern "C" { + void fGetFileVersionInfoA() { _asm jmp[version.oGetFileVersionInfoA] } + void fGetFileVersionInfoByHandle() { _asm jmp[version.oGetFileVersionInfoByHandle] } + void fGetFileVersionInfoExA() { _asm jmp[version.oGetFileVersionInfoExA] } + void fGetFileVersionInfoExW() { _asm jmp[version.oGetFileVersionInfoExW] } + void fGetFileVersionInfoSizeA() { _asm jmp[version.oGetFileVersionInfoSizeA] } + void fGetFileVersionInfoSizeExA() { _asm jmp[version.oGetFileVersionInfoSizeExA] } + void fGetFileVersionInfoSizeExW() { _asm jmp[version.oGetFileVersionInfoSizeExW] } + void fGetFileVersionInfoSizeW() { _asm jmp[version.oGetFileVersionInfoSizeW] } + void fGetFileVersionInfoW() { _asm jmp[version.oGetFileVersionInfoW] } + void fVerFindFileA() { _asm jmp[version.oVerFindFileA] } + void fVerFindFileW() { _asm jmp[version.oVerFindFileW] } + void fVerInstallFileA() { _asm jmp[version.oVerInstallFileA] } + void fVerInstallFileW() { _asm jmp[version.oVerInstallFileW] } + void fVerLanguageNameA() { _asm jmp[version.oVerLanguageNameA] } + void fVerLanguageNameW() { _asm jmp[version.oVerLanguageNameW] } + void fVerQueryValueA() { _asm jmp[version.oVerQueryValueA] } + void fVerQueryValueW() { _asm jmp[version.oVerQueryValueW] } +} + +void setupFunctions() { + version.oGetFileVersionInfoA = GetProcAddress(version.dll, "GetFileVersionInfoA"); + version.oGetFileVersionInfoByHandle = GetProcAddress(version.dll, "GetFileVersionInfoByHandle"); + version.oGetFileVersionInfoExA = GetProcAddress(version.dll, "GetFileVersionInfoExA"); + version.oGetFileVersionInfoExW = GetProcAddress(version.dll, "GetFileVersionInfoExW"); + version.oGetFileVersionInfoSizeA = GetProcAddress(version.dll, "GetFileVersionInfoSizeA"); + version.oGetFileVersionInfoSizeExA = GetProcAddress(version.dll, "GetFileVersionInfoSizeExA"); + version.oGetFileVersionInfoSizeExW = GetProcAddress(version.dll, "GetFileVersionInfoSizeExW"); + version.oGetFileVersionInfoSizeW = GetProcAddress(version.dll, "GetFileVersionInfoSizeW"); + version.oGetFileVersionInfoW = GetProcAddress(version.dll, "GetFileVersionInfoW"); + version.oVerFindFileA = GetProcAddress(version.dll, "VerFindFileA"); + version.oVerFindFileW = GetProcAddress(version.dll, "VerFindFileW"); + version.oVerInstallFileA = GetProcAddress(version.dll, "VerInstallFileA"); + version.oVerInstallFileW = GetProcAddress(version.dll, "VerInstallFileW"); + version.oVerLanguageNameA = GetProcAddress(version.dll, "VerLanguageNameA"); + version.oVerLanguageNameW = GetProcAddress(version.dll, "VerLanguageNameW"); + version.oVerQueryValueA = GetProcAddress(version.dll, "VerQueryValueA"); + version.oVerQueryValueW = GetProcAddress(version.dll, "VerQueryValueW"); +} +#pragma endregion diff --git a/third/dllmain.cpp b/third/dllmain.cpp new file mode 100644 index 0000000..9bad70d --- /dev/null +++ b/third/dllmain.cpp @@ -0,0 +1,84 @@ +#include + +#pragma region Proxy +struct version_dll { + HMODULE dll; + FARPROC oGetFileVersionInfoA; + FARPROC oGetFileVersionInfoByHandle; + FARPROC oGetFileVersionInfoExA; + FARPROC oGetFileVersionInfoExW; + FARPROC oGetFileVersionInfoSizeA; + FARPROC oGetFileVersionInfoSizeExA; + FARPROC oGetFileVersionInfoSizeExW; + FARPROC oGetFileVersionInfoSizeW; + FARPROC oGetFileVersionInfoW; + FARPROC oVerFindFileA; + FARPROC oVerFindFileW; + FARPROC oVerInstallFileA; + FARPROC oVerInstallFileW; + FARPROC oVerLanguageNameA; + FARPROC oVerLanguageNameW; + FARPROC oVerQueryValueA; + FARPROC oVerQueryValueW; +} version; + +extern "C" { + void fGetFileVersionInfoA() { _asm jmp[version.oGetFileVersionInfoA] } + void fGetFileVersionInfoByHandle() { _asm jmp[version.oGetFileVersionInfoByHandle] } + void fGetFileVersionInfoExA() { _asm jmp[version.oGetFileVersionInfoExA] } + void fGetFileVersionInfoExW() { _asm jmp[version.oGetFileVersionInfoExW] } + void fGetFileVersionInfoSizeA() { _asm jmp[version.oGetFileVersionInfoSizeA] } + void fGetFileVersionInfoSizeExA() { _asm jmp[version.oGetFileVersionInfoSizeExA] } + void fGetFileVersionInfoSizeExW() { _asm jmp[version.oGetFileVersionInfoSizeExW] } + void fGetFileVersionInfoSizeW() { _asm jmp[version.oGetFileVersionInfoSizeW] } + void fGetFileVersionInfoW() { _asm jmp[version.oGetFileVersionInfoW] } + void fVerFindFileA() { _asm jmp[version.oVerFindFileA] } + void fVerFindFileW() { _asm jmp[version.oVerFindFileW] } + void fVerInstallFileA() { _asm jmp[version.oVerInstallFileA] } + void fVerInstallFileW() { _asm jmp[version.oVerInstallFileW] } + void fVerLanguageNameA() { _asm jmp[version.oVerLanguageNameA] } + void fVerLanguageNameW() { _asm jmp[version.oVerLanguageNameW] } + void fVerQueryValueA() { _asm jmp[version.oVerQueryValueA] } + void fVerQueryValueW() { _asm jmp[version.oVerQueryValueW] } +} + +void setupFunctions() { + version.oGetFileVersionInfoA = GetProcAddress(version.dll, "GetFileVersionInfoA"); + version.oGetFileVersionInfoByHandle = GetProcAddress(version.dll, "GetFileVersionInfoByHandle"); + version.oGetFileVersionInfoExA = GetProcAddress(version.dll, "GetFileVersionInfoExA"); + version.oGetFileVersionInfoExW = GetProcAddress(version.dll, "GetFileVersionInfoExW"); + version.oGetFileVersionInfoSizeA = GetProcAddress(version.dll, "GetFileVersionInfoSizeA"); + version.oGetFileVersionInfoSizeExA = GetProcAddress(version.dll, "GetFileVersionInfoSizeExA"); + version.oGetFileVersionInfoSizeExW = GetProcAddress(version.dll, "GetFileVersionInfoSizeExW"); + version.oGetFileVersionInfoSizeW = GetProcAddress(version.dll, "GetFileVersionInfoSizeW"); + version.oGetFileVersionInfoW = GetProcAddress(version.dll, "GetFileVersionInfoW"); + version.oVerFindFileA = GetProcAddress(version.dll, "VerFindFileA"); + version.oVerFindFileW = GetProcAddress(version.dll, "VerFindFileW"); + version.oVerInstallFileA = GetProcAddress(version.dll, "VerInstallFileA"); + version.oVerInstallFileW = GetProcAddress(version.dll, "VerInstallFileW"); + version.oVerLanguageNameA = GetProcAddress(version.dll, "VerLanguageNameA"); + version.oVerLanguageNameW = GetProcAddress(version.dll, "VerLanguageNameW"); + version.oVerQueryValueA = GetProcAddress(version.dll, "VerQueryValueA"); + version.oVerQueryValueW = GetProcAddress(version.dll, "VerQueryValueW"); +} +#pragma endregion + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + char path[MAX_PATH]; + GetWindowsDirectory(path, sizeof(path)); + + // Example: "\\System32\\version.dll" + strcat_s(path, "\\add manual path\\version.dll"); + version.dll = LoadLibrary(path); + setupFunctions(); + + // Add here your code, I recommend you to create a thread + break; + case DLL_PROCESS_DETACH: + FreeLibrary(version.dll); + break; + } + return 1; +} diff --git a/third/version.def b/third/version.def new file mode 100644 index 0000000..94a52b1 --- /dev/null +++ b/third/version.def @@ -0,0 +1,19 @@ +LIBRARY version +EXPORTS + GetFileVersionInfoA=fGetFileVersionInfoA @1 + GetFileVersionInfoByHandle=fGetFileVersionInfoByHandle @2 + GetFileVersionInfoExA=fGetFileVersionInfoExA @3 + GetFileVersionInfoExW=fGetFileVersionInfoExW @4 + GetFileVersionInfoSizeA=fGetFileVersionInfoSizeA @5 + GetFileVersionInfoSizeExA=fGetFileVersionInfoSizeExA @6 + GetFileVersionInfoSizeExW=fGetFileVersionInfoSizeExW @7 + GetFileVersionInfoSizeW=fGetFileVersionInfoSizeW @8 + GetFileVersionInfoW=fGetFileVersionInfoW @9 + VerFindFileA=fVerFindFileA @10 + VerFindFileW=fVerFindFileW @11 + VerInstallFileA=fVerInstallFileA @12 + VerInstallFileW=fVerInstallFileW @13 + VerLanguageNameA=fVerLanguageNameA @14 + VerLanguageNameW=fVerLanguageNameW @15 + VerQueryValueA=fVerQueryValueA @16 + VerQueryValueW=fVerQueryValueW @17 diff --git a/xmake-requires.lock b/xmake-requires.lock index d0e1b07..ac7e4ce 100644 --- a/xmake-requires.lock +++ b/xmake-requires.lock @@ -2,6 +2,30 @@ __meta__ = { version = "1.0" }, + ["mingw|x86"] = { + ["minhook#31fecfc4"] = { + repo = { + branch = "master", + commit = "3d19345df6ab7745c5c779ee9b20166f96bc559a", + url = "https://github.com/xmake-io/xmake-repo.git" + }, + version = "v1.3.4" + }, + ["spdlog#31fecfc4"] = { + repo = { + branch = "master", + commit = "4333aa942c37880a4830485b0d2043d02d02391d", + url = "https://github.com/xmake-io/xmake-repo.git" + }, + version = "v1.15.3" + }, + ["vcpkg::detours#31fecfc4"] = { + version = "latest" + }, + ["vcpkg::inipp#31fecfc4"] = { + version = "latest" + } + }, ["mingw|x86_64"] = { ["minhook#31fecfc4"] = { repo = { diff --git a/xmake.lua b/xmake.lua index f69718e..6379771 100644 --- a/xmake.lua +++ b/xmake.lua @@ -13,17 +13,18 @@ add_requires("minhook") add_requires("vcpkg::detours") add_requires("vcpkg::inipp") -local name = "kpatch" +local name = "version" target(name) set_kind("shared") add_files("src/dllmain.cpp") add_packages("spdlog", "vcpkg::detours", "minhook", "vcpkg::inipp") + add_files("third/version.def") add_links("user32", "gdi32") -local name = "left4dead2_fix" -target(name) - set_kind("binary") - add_files("launcher/main.cpp") - add_files("assets/app.rc") - add_links("user32", "gdi32") - add_packages("vcpkg::detours") +-- local name = "left4dead2_fix" +-- target(name) +-- set_kind("binary") +-- add_files("launcher/main.cpp") +-- add_files("assets/app.rc") +-- add_links("user32", "gdi32") +-- add_packages("vcpkg::detours")