From 78295d2c15a80bc0ec64a3b4d691583fefc42184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 16 Nov 2024 21:42:52 +0800 Subject: [PATCH] fix --- .github/scripts/build_lunahook.py | 43 ++++++++----- .github/workflows/buildlunahook.yml | 18 ++---- cpp/LunaHook/LunaHook/engine32/WillPlus.cpp | 3 +- .../LunaHook/engines/pchooks/pchooks.cpp | 62 +++++++++---------- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/.github/scripts/build_lunahook.py b/.github/scripts/build_lunahook.py index 413770e6..c5319604 100644 --- a/.github/scripts/build_lunahook.py +++ b/.github/scripts/build_lunahook.py @@ -4,7 +4,7 @@ import subprocess rootDir = os.path.dirname(__file__) if not rootDir: rootDir = os.path.abspath(".") -rootDir=os.path.abspath(os.path.join(rootDir,'../../cpp/LunaHook')) +rootDir = os.path.abspath(os.path.join(rootDir, "../../cpp/LunaHook")) if len(sys.argv) and sys.argv[1] == "loadversion": os.chdir(rootDir) with open("CMakeLists.txt", "r", encoding="utf8") as ff: @@ -21,15 +21,15 @@ if len(sys.argv) and sys.argv[1] == "merge": language = ["Chinese", "English", "Russian", "TradChinese"] for lang in language: shutil.copytree( - f"build/{lang}_64/Release_{lang}", - f"../build/Release_{lang}", - dirs_exist_ok=True, - ) + f"build/{lang}_64/Release_{lang}", + f"../build/Release_{lang}", + dirs_exist_ok=True, + ) shutil.copytree( - f"build/{lang}_winxp/Release_{lang}_winxp", - f"../build/Release_{lang}", - dirs_exist_ok=True, - ) + f"build/{lang}_winxp/Release_{lang}_winxp", + f"../build/Release_{lang}", + dirs_exist_ok=True, + ) targetdir = f"../build/Release_{lang}" target = f"builds/Release_{lang}.zip" @@ -72,7 +72,7 @@ def build_langx_xp(lang, core): os.system(rf"curl -SLo YY-Thunks-1.0.7-Binary.zip " + url) os.system(rf"7z x -y YY-Thunks-1.0.7-Binary.zip -o../../libs/YY-Thunks") os.system("dir") - flags='' if core else ' -DBUILD_GUI=ON -DBUILD_CLI=ON ' + flags = "" if core else " -DBUILD_GUI=ON -DBUILD_CLI=ON " with open("do.bat", "w") as ff: ff.write( rf""" @@ -83,11 +83,26 @@ cmake --build ../build/x86_{lang}_xp --config Release --target ALL_BUILD -j 14 ) os.system(f"cmd /c do.bat") + os.chdir(os.path.join(rootDir, "scripts")) -if sys.argv[1] == "plg32": - os.system(f"cmd /c buildplugin32.bat") -elif sys.argv[1] == "plg64": - os.system(f"cmd /c buildplugin64.bat") +if sys.argv[1] == "plugin": + bits = sys.argv[2] + with open("buildplugin.bat", "w") as ff: + if bits == "32": + ff.write( + rf""" +cmake -DBUILD_CORE=OFF -DUSESYSQTPATH=1 -DBUILD_PLUGIN=ON ../CMakeLists.txt -G "Visual Studio 17 2022" -A win32 -T host=x86 -B ../build/plugin32 +cmake --build ../build/plugin32 --config Release --target ALL_BUILD -j 14 +""" + ) + else: + ff.write( + rf""" +cmake -DBUILD_CORE=OFF -DUSESYSQTPATH=1 -DBUILD_PLUGIN=ON ../CMakeLists.txt -G "Visual Studio 17 2022" -A x64 -T host=x64 -B ../build/plugin64 +cmake --build ../build/plugin64 --config Release --target ALL_BUILD -j 14 +""" + ) + os.system(f"cmd /c buildplugin.bat") elif sys.argv[1] == "build": lang = sys.argv[2] bit = sys.argv[3] diff --git a/.github/workflows/buildlunahook.yml b/.github/workflows/buildlunahook.yml index 18455dbd..2a7bd571 100644 --- a/.github/workflows/buildlunahook.yml +++ b/.github/workflows/buildlunahook.yml @@ -35,12 +35,10 @@ jobs: strategy: matrix: include: - - cmd: plg32 + - bits: 32 qtarch: win32_msvc2019 - target: plugin32 - - cmd: plg64 + - bits: 64 qtarch: win64_msvc2019_64 - target: plugin64 permissions: id-token: write attestations: write @@ -59,21 +57,17 @@ jobs: arch: ${{ matrix.qtarch }} dir: ${{ runner.temp }} setup-python: true - - run: python .github/scripts/build_lunahook.py ${{ matrix.cmd }} + - run: python .github/scripts/build_lunahook.py plugin ${{ matrix.bits }} - run: python .github/scripts/packlunahook.py - # - name: Generate attestation for artifact - # uses: actions/attest-build-provenance@v1 - # with: - # subject-path: builds/${{ matrix.target }}.zip - uses: actions/upload-artifact@v4 with: - name: ${{ matrix.target }} - path: cpp/LunaHook/builds/${{ matrix.target }}.zip + name: plugin${{ matrix.bits }} + path: cpp/LunaHook/builds/plugin${{ matrix.bits }}.zip - uses: softprops/action-gh-release@v2 with: tag_name: LunaHook - files: cpp/LunaHook/builds/${{ matrix.target }}.zip + files: cpp/LunaHook/builds/plugin${{ matrix.bits }}.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} build_x: diff --git a/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp b/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp index da4060d3..37463e30 100644 --- a/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp +++ b/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp @@ -1750,7 +1750,8 @@ bool WillPlus::attach_function() succ |= insertwillplus6(); succ |= willX(); succ |= _xxx(); - + PcHooks::hookGDIFunctions(GetGlyphOutlineA); + PcHooks::hookGDIFunctions(GetGlyphOutlineW); return succ; } diff --git a/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp b/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp index 66ebf6f0..853cdfc9 100644 --- a/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp +++ b/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp @@ -11,22 +11,30 @@ // http://bytes.com/topic/c/answers/135834-defining-wide-character-strings-macros // #define LPASTE(s) L##s // #define L(s) LPASTE(s) -#define NEW_HOOK(ptr, _dll, _fun, _data, _data_ind, _split_off, _split_ind, _type, _len_off) \ - { \ - HookParam hp; \ - wcsncpy_s(hp.module, _dll, MAX_MODULE_SIZE - 1); \ - strncpy_s(hp.function, #_fun, MAX_MODULE_SIZE - 1); \ - hp.offset = _data; \ - hp.index = _data_ind; \ - hp.split = _split_off; \ - hp.split_index = _split_ind; \ - hp.type = _type | MODULE_OFFSET | FUNCTION_OFFSET; \ - hp.length_offset = _len_off; \ - if ((!ptr) || \ - (GetModuleHandle(hp.module) && \ - GetProcAddress(GetModuleHandle(hp.module), hp.function) && \ - GetProcAddress(GetModuleHandle(hp.module), hp.function) == ptr)) \ - NewHook(hp, #_fun); \ + +Synchronized> hookonce; +#define NEW_HOOK(ptr, _dll, _fun, _data, _data_ind, _split_off, _split_ind, _type, _len_off) \ + { \ + HookParam hp; \ + wcsncpy_s(hp.module, _dll, MAX_MODULE_SIZE - 1); \ + strncpy_s(hp.function, #_fun, MAX_MODULE_SIZE - 1); \ + hp.offset = _data; \ + hp.index = _data_ind; \ + hp.split = _split_off; \ + hp.split_index = _split_ind; \ + hp.type = _type | MODULE_OFFSET | FUNCTION_OFFSET; \ + hp.length_offset = _len_off; \ + auto currptr = GetModuleHandle(hp.module) ? GetProcAddress(GetModuleHandle(hp.module), hp.function) : nullptr; \ + bool dohook = false; \ + if (ptr) \ + dohook = currptr == ptr; \ + else if (currptr) \ + dohook = hookonce->find(currptr) == hookonce->end(); \ + if (dohook) \ + { \ + NewHook(hp, #_fun); \ + hookonce->insert(currptr); \ + } \ } #define NEW_MODULE_HOOK(_module, _fun, _data, _data_ind, _split_off, _split_ind, _type, _len_off) \ @@ -42,7 +50,13 @@ hp.split_index = _split_ind; \ hp.type = _type | MODULE_OFFSET | FUNCTION_OFFSET; \ hp.length_offset = _len_off; \ - NewHook(hp, #_fun); \ + auto currptr = GetProcAddress(_module, hp.function); \ + auto dohook = currptr ? hookonce->find(currptr) == hookonce->end() : false; \ + if (dohook) \ + { \ + NewHook(hp, #_fun); \ + hookonce->insert(currptr); \ + } \ } #ifndef _WIN64 @@ -71,16 +85,6 @@ enum args }; #endif // _WIN64 -bool once_hookGDIFunctions = false; -bool once_hookGDIPlusFunctions = false; -bool once_hookD3DXFunctions = false; -bool once_hookOtherPcFunctions = false; -#define once_run_pchooks(x) \ - { \ - if (once_##x) \ - return; \ - once_##x = true; \ - } constexpr short arg_sz = (short)sizeof(void *); void PcHooks::hookGdiGdiplusD3dxFunctions() { @@ -98,7 +102,6 @@ void PcHooks::hookGdiGdiplusD3dxFunctions() // jichi 7/17/2014: Renamed from InitDefaultHook void PcHooks::hookGDIFunctions(void *ptr) { - once_run_pchooks(hookGDIFunctions); // gdi32.dll NEW_HOOK(ptr, L"gdi32.dll", GetTextExtentPoint32A, s_arg2, 0, s_arg1, 0, USING_STRING, s_arg3 / arg_sz) NEW_HOOK(ptr, L"gdi32.dll", GetTextExtentExPointA, s_arg2, 0, s_arg1, 0, USING_STRING, s_arg3 / arg_sz) @@ -139,7 +142,6 @@ void PcHooks::hookGDIFunctions(void *ptr) // jichi 6/18/2015: GDI+ functions void PcHooks::hookGDIPlusFunctions() { - once_run_pchooks(hookGDIPlusFunctions); HMODULE hModule = ::GetModuleHandleA("gdiplus.dll"); if (!hModule) return; @@ -162,7 +164,6 @@ void PcHooks::hookGDIPlusFunctions() void PcHooks::hookD3DXFunctions(HMODULE d3dxModule) { - once_run_pchooks(hookD3DXFunctions); if (GetProcAddress(d3dxModule, "D3DXCreateTextA")) { NEW_MODULE_HOOK(d3dxModule, D3DXCreateTextA, s_arg3, 0, 0, 0, USING_STRING, 0) @@ -219,7 +220,6 @@ void PcHooks::hookD3DXFunctions(HMODULE d3dxModule) // Note: All functions does not have NO_CONTEXT attribute and will be filtered. void PcHooks::hookOtherPcFunctions(void *ptr) { - once_run_pchooks(hookOtherPcFunctions); // int TextHook::InitHook(LPVOID addr, DWORD data, DWORD data_ind, DWORD split_off, DWORD split_ind, WORD type, DWORD len_off) // http://msdn.microsoft.com/en-us/library/78zh94ax.aspx