diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 283b411..088c013 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ jobs: include: [ { name: Chrome++_x86, arch: x86 }, { name: Chrome++_x64, arch: x64 }, + { name: Chrome++_arm64, arch: arm64 } ] name: ${{ matrix.name }} diff --git a/.gitmodules b/.gitmodules index 4622a60..47eff22 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ -[submodule "minhook"] - path = minhook - url = https://github.com/TsudaKageyu/minhook [submodule "mini_gzip"] path = mini_gzip url = https://github.com/Bush2021/mini_gzip +[submodule "detours"] + path = detours + url = https://github.com/microsoft/Detours diff --git a/VC-LTL5.lua b/VC-LTL5.lua index 095bcb5..b7c445d 100644 --- a/VC-LTL5.lua +++ b/VC-LTL5.lua @@ -33,6 +33,8 @@ target("VC-LTL-5") archpath = "Win32" elseif arch=="x64" then archpath = "x64" + elseif arch=="arm64" then + archpath = "arm64" end cprint("${color.warning}Platform : %s", archpath) local libpath = VC_LTL_Root .. [[TargetPlatform\]] .. WindowsTargetPlatformMinVersion..[[\lib\]] .. archpath .. ";" @@ -41,4 +43,4 @@ target("VC-LTL-5") -- print(runenvs.INCLUDE) -- print(runenvs.LIB) - end) + end) \ No newline at end of file diff --git a/detours b/detours new file mode 160000 index 0000000..4b8c659 --- /dev/null +++ b/detours @@ -0,0 +1 @@ +Subproject commit 4b8c659f549b0ab21cf649377c7a84eb708f5e68 diff --git a/minhook b/minhook deleted file mode 160000 index 91cc946..0000000 --- a/minhook +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 91cc9466e383d13a43d7cf33c7c8fdccb27095d3 diff --git a/src/appid.h b/src/appid.h index 80d0389..f8e2bf4 100644 --- a/src/appid.h +++ b/src/appid.h @@ -5,10 +5,7 @@ #include #include -typedef HRESULT(WINAPI* pPSStringFromPropertyKey)(REFPROPERTYKEY pkey, - LPWSTR psz, - UINT cch); -pPSStringFromPropertyKey RawPSStringFromPropertyKey = nullptr; +auto RawPSStringFromPropertyKey = PSStringFromPropertyKey; HRESULT WINAPI MyPSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, @@ -24,17 +21,12 @@ HRESULT WINAPI MyPSStringFromPropertyKey(REFPROPERTYKEY pkey, } void SetAppId() { - HMODULE Propsys = LoadLibrary(L"Propsys.dll"); - - PBYTE PSStringFromPropertyKey = - (PBYTE)GetProcAddress(Propsys, "PSStringFromPropertyKey"); - MH_STATUS status = - MH_CreateHook(PSStringFromPropertyKey, MyPSStringFromPropertyKey, - (LPVOID*)&RawPSStringFromPropertyKey); - if (status == MH_OK) { - MH_EnableHook(PSStringFromPropertyKey); - } else { - DebugLog(L"MH_CreateHook PSStringFromPropertyKey failed:%d", status); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&RawPSStringFromPropertyKey, MyPSStringFromPropertyKey); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"SetAppId failed %d", status); } } diff --git a/src/chrome++.cpp b/src/chrome++.cpp index 914f0e2..b7d1bca 100644 --- a/src/chrome++.cpp +++ b/src/chrome++.cpp @@ -6,7 +6,7 @@ HMODULE hInstance; #define MAGIC_CODE 0x1603ABD9 -#include "MinHook.h" +#include "detours.h" #include "version.h" #include "hijack.h" @@ -68,22 +68,20 @@ void InstallLoader() { MODULEINFO mi; GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &mi, sizeof(MODULEINFO)); - PBYTE entry = (PBYTE)mi.EntryPoint; - - // Jump from the original entry to the loader. - MH_STATUS status = MH_CreateHook(entry, Loader, (LPVOID*)&ExeMain); - if (status == MH_OK) { - MH_EnableHook(entry); - } else { - DebugLog(L"MH_CreateHook InstallLoader failed:%d", status); + ExeMain = (Startup)mi.EntryPoint; + + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&ExeMain, Loader); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"InstallLoader failed: %d", status); } } -#define EXTERNC extern "C" -// -EXTERNC __declspec(dllexport) void portable() {} +__declspec(dllexport) void portable() {} -EXTERNC BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) { +BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) { if (dwReason == DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(hModule); hInstance = hModule; @@ -91,13 +89,7 @@ EXTERNC BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) { // Maintain the original function of system DLLs. LoadSysDll(hModule); - // Install the loader after successfully initializing MinHook. - MH_STATUS status = MH_Initialize(); - if (status == MH_OK) { - InstallLoader(); - } else { - DebugLog(L"MH_Initialize failed:%d", status); - } + InstallLoader(); } return TRUE; } diff --git a/src/green.h b/src/green.h index f679a42..10838a2 100644 --- a/src/green.h +++ b/src/green.h @@ -3,6 +3,12 @@ #include +auto RawUpdateProcThreadAttribute = UpdateProcThreadAttribute; +auto RawCryptUnprotectData = CryptUnprotectData; +auto RawLogonUserW = LogonUserW; +auto RawIsOS = IsOS; +auto RawNetUserGetInfo = NetUserGetInfo; + BOOL WINAPI FakeGetComputerName(_Out_ LPTSTR lpBuffer, _Inout_ LPDWORD lpnSize) { return false; @@ -19,6 +25,38 @@ BOOL WINAPI FakeGetVolumeInformation(_In_opt_ LPCTSTR lpRootPathName, return false; } +#ifndef PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON +#define PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON \ + (0x00000001ui64 << 44) +#endif +// #ifndef +// PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON +// #define +// PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON \ +// (0x00000001ui64 << 28) +// #endif + +BOOL WINAPI MyUpdateProcThreadAttribute( + __inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, + __in DWORD dwFlags, + __in DWORD_PTR Attribute, + __in_bcount_opt(cbSize) PVOID lpValue, + __in SIZE_T cbSize, + __out_bcount_opt(cbSize) PVOID lpPreviousValue, + __in_opt PSIZE_T lpReturnSize) { + if (Attribute == PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY && + cbSize >= sizeof(DWORD64)) { + // https://source.chromium.org/chromium/chromium/src/+/main:sandbox/win/src/process_mitigations.cc;l=362;drc=4c2fec5f6699ffeefd93137d2bf8c03504c6664c + PDWORD64 policy_value_1 = &((PDWORD64)lpValue)[0]; + *policy_value_1 &= ~PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON; + // *policy_value_1 &= + // ~PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON; + } + return RawUpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, + lpValue, cbSize, lpPreviousValue, + lpReturnSize); +} + BOOL WINAPI MyCryptProtectData(_In_ DATA_BLOB* pDataIn, _In_opt_ LPCWSTR szDataDescr, @@ -33,17 +71,6 @@ MyCryptProtectData(_In_ DATA_BLOB* pDataIn, return true; } -typedef BOOL(WINAPI* pCryptUnprotectData)( - _In_ DATA_BLOB* pDataIn, - _Out_opt_ LPWSTR* ppszDataDescr, - _In_opt_ DATA_BLOB* pOptionalEntropy, - _Reserved_ PVOID pvReserved, - _In_opt_ CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, - _In_ DWORD dwFlags, - _Out_ DATA_BLOB* pDataOut); - -pCryptUnprotectData RawCryptUnprotectData = nullptr; - BOOL WINAPI MyCryptUnprotectData(_In_ DATA_BLOB* pDataIn, _Out_opt_ LPWSTR* ppszDataDescr, @@ -63,15 +90,6 @@ MyCryptUnprotectData(_In_ DATA_BLOB* pDataIn, return true; } -typedef DWORD(WINAPI* pLogonUserW)(LPCWSTR lpszUsername, - LPCWSTR lpszDomain, - LPCWSTR lpszPassword, - DWORD dwLogonType, - DWORD dwLogonProvider, - PHANDLE phToken); - -pLogonUserW RawLogonUserW = nullptr; - DWORD WINAPI MyLogonUserW(LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword, @@ -85,10 +103,6 @@ DWORD WINAPI MyLogonUserW(LPCWSTR lpszUsername, return ret; } -typedef BOOL(WINAPI* pIsOS)(DWORD dwOS); - -pIsOS RawIsOS = nullptr; - BOOL WINAPI MyIsOS(DWORD dwOS) { DWORD ret = RawIsOS(dwOS); if (dwOS == OS_DOMAINMEMBER) { @@ -98,13 +112,6 @@ BOOL WINAPI MyIsOS(DWORD dwOS) { return ret; } -typedef NET_API_STATUS(WINAPI* pNetUserGetInfo)(LPCWSTR servername, - LPCWSTR username, - DWORD level, - LPBYTE* bufptr); - -pNetUserGetInfo RawNetUserGetInfo = nullptr; - NET_API_STATUS WINAPI MyNetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level, @@ -118,143 +125,39 @@ NET_API_STATUS WINAPI MyNetUserGetInfo(LPCWSTR servername, return ret; } -#ifndef PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON -#define PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON \ - (0x00000001ui64 << 44) -#endif - -// #ifndef PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON -// #define PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON \ -// (0x00000001ui64 << 28) -// #endif - -typedef BOOL(WINAPI* pUpdateProcThreadAttribute)( - LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, - DWORD dwFlags, - DWORD_PTR Attribute, - PVOID lpValue, - SIZE_T cbSize, - PVOID lpPreviousValue, - PSIZE_T lpReturnSize); - -pUpdateProcThreadAttribute RawUpdateProcThreadAttribute = nullptr; - -BOOL WINAPI MyUpdateProcThreadAttribute( - __inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, - __in DWORD dwFlags, - __in DWORD_PTR Attribute, - __in_bcount_opt(cbSize) PVOID lpValue, - __in SIZE_T cbSize, - __out_bcount_opt(cbSize) PVOID lpPreviousValue, - __in_opt PSIZE_T lpReturnSize) { - if (Attribute == PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY && - cbSize >= sizeof(DWORD64)) { - // https://source.chromium.org/chromium/chromium/src/+/main:sandbox/win/src/process_mitigations.cc;l=362;drc=4c2fec5f6699ffeefd93137d2bf8c03504c6664c - PDWORD64 policy_value_1 = &((PDWORD64)lpValue)[0]; - *policy_value_1 &= - ~PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON; - // *policy_value_1 &= - // ~PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON; - } - return RawUpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, - lpValue, cbSize, lpPreviousValue, - lpReturnSize); -} - void MakeGreen() { - HMODULE kernel32 = LoadLibraryW(L"kernel32.dll"); - if (kernel32) { - PBYTE GetComputerNameW = - (PBYTE)GetProcAddress(kernel32, "GetComputerNameW"); - PBYTE GetVolumeInformationW = - (PBYTE)GetProcAddress(kernel32, "GetVolumeInformationW"); + auto RawGetComputerNameW = GetComputerNameW; + auto RawGetVolumeInformationW = GetVolumeInformationW; + auto RawCryptProtectData = CryptProtectData; - MH_STATUS status = - MH_CreateHook(GetComputerNameW, FakeGetComputerName, nullptr); - if (status == MH_OK) { - MH_EnableHook(GetComputerNameW); - } else { - DebugLog(L"MH_CreateHook GetComputerNameW failed:%d", status); - } - status = - MH_CreateHook(GetVolumeInformationW, FakeGetVolumeInformation, nullptr); - if (status == MH_OK) { - MH_EnableHook(GetVolumeInformationW); - } else { - DebugLog(L"MH_CreateHook GetVolumeInformationW failed:%d", status); - } - } + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); - // components/os_crypt/os_crypt_win.cc - HMODULE Crypt32 = LoadLibraryW(L"Crypt32.dll"); - if (Crypt32) { - PBYTE CryptProtectData = (PBYTE)GetProcAddress(Crypt32, "CryptProtectData"); - PBYTE CryptUnprotectData = - (PBYTE)GetProcAddress(Crypt32, "CryptUnprotectData"); - - MH_STATUS status = - MH_CreateHook(CryptProtectData, MyCryptProtectData, nullptr); - if (status == MH_OK) { - MH_EnableHook(CryptProtectData); - } else { - DebugLog(L"MH_CreateHook CryptProtectData failed:%d", status); - } - status = MH_CreateHook(CryptUnprotectData, MyCryptUnprotectData, - (LPVOID*)&RawCryptUnprotectData); - if (status == MH_OK) { - MH_EnableHook(CryptUnprotectData); - } else { - DebugLog(L"MH_CreateHook CryptUnprotectData failed:%d", status); - } - } + // kernel32.dll + DetourAttach((LPVOID*)&RawGetComputerNameW, FakeGetComputerName); + DetourAttach((LPVOID*)&RawGetVolumeInformationW, FakeGetVolumeInformation); + DetourAttach((LPVOID*)&RawUpdateProcThreadAttribute, + MyUpdateProcThreadAttribute); - HMODULE Advapi32 = LoadLibraryW(L"Advapi32.dll"); - if (Advapi32) { - PBYTE LogonUserW = (PBYTE)GetProcAddress(Advapi32, "LogonUserW"); - - MH_STATUS status = - MH_CreateHook(LogonUserW, MyLogonUserW, (LPVOID*)&RawLogonUserW); - if (status == MH_OK) { - MH_EnableHook(LogonUserW); - } else { - DebugLog(L"MH_CreateHook LogonUserW failed:%d", status); - } - } - - HMODULE Shlwapi = LoadLibraryW(L"Shlwapi.dll"); - if (Shlwapi) { - PBYTE IsOS = (PBYTE)GetProcAddress(Shlwapi, "IsOS"); + // components/os_crypt/os_crypt_win.cc + // crypt32.dll + DetourAttach((LPVOID*)&RawCryptProtectData, MyCryptProtectData); + DetourAttach((LPVOID*)&RawCryptUnprotectData, MyCryptUnprotectData); - MH_STATUS status = MH_CreateHook(IsOS, MyIsOS, (LPVOID*)&RawIsOS); - if (status == MH_OK) { - MH_EnableHook(IsOS); - } else { - DebugLog(L"MH_CreateHook IsOS failed:%d", status); - } - } + // advapi32.dll + DetourAttach((LPVOID*)&RawLogonUserW, MyLogonUserW); - HMODULE Netapi32 = LoadLibraryW(L"Netapi32.dll"); - if (Netapi32) { - PBYTE NetUserGetInfo = (PBYTE)GetProcAddress(Netapi32, "NetUserGetInfo"); + // shlwapi.dll + DetourAttach((LPVOID*)&RawIsOS, MyIsOS); - MH_STATUS status = MH_CreateHook(NetUserGetInfo, MyNetUserGetInfo, - (LPVOID*)&RawNetUserGetInfo); - if (status == MH_OK) { - MH_EnableHook(NetUserGetInfo); - } else { - DebugLog(L"MH_CreateHook NetUserGetInfo failed:%d", status); - } - } + // netapi32.dll + DetourAttach((LPVOID*)&RawNetUserGetInfo, MyNetUserGetInfo); - LPVOID ppUpdateProcThreadAttribute = nullptr; - MH_STATUS status = MH_CreateHookApiEx( - L"kernel32", "UpdateProcThreadAttribute", &MyUpdateProcThreadAttribute, - (LPVOID*)&RawUpdateProcThreadAttribute, &ppUpdateProcThreadAttribute); - if (status == MH_OK) { - MH_EnableHook(ppUpdateProcThreadAttribute); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"MakeGreen failed: %d", status); } else { - DebugLog(L"MH_CreateHookApiEx UpdateProcThreadAttribute failed: %d", - status); + DebugLog(L"MakeGreen success"); } } diff --git a/src/pakpatch.h b/src/pakpatch.h index 3e26d35..5b7c672 100644 --- a/src/pakpatch.h +++ b/src/pakpatch.h @@ -4,16 +4,12 @@ #include "pakfile.h" DWORD resources_pak_size = 0; - HANDLE resources_pak_map = nullptr; +HANDLE resources_pak_file = nullptr; -typedef HANDLE(WINAPI* pMapViewOfFile)(_In_ HANDLE hFileMappingObject, - _In_ DWORD dwDesiredAccess, - _In_ DWORD dwFileOffsetHigh, - _In_ DWORD dwFileOffsetLow, - _In_ SIZE_T dwNumberOfBytesToMap); - -pMapViewOfFile RawMapViewOfFile = nullptr; +auto RawCreateFile = CreateFileW; +auto RawCreateFileMapping = CreateFileMappingW; +auto RawMapViewOfFile = MapViewOfFile; HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject, _In_ DWORD dwDesiredAccess, @@ -28,7 +24,15 @@ HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject, // No more hook needed. resources_pak_map = nullptr; - MH_DisableHook(MapViewOfFile); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourDetach((LPVOID*)&RawMapViewOfFile, MyMapViewOfFile); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Unhook RawMapViewOfFile failed %d", status); + } else { + DebugLog(L"Unhook RawMapViewOfFile success"); + } if (buffer) { // Traverse the gzip file. @@ -79,18 +83,6 @@ HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject, dwFileOffsetLow, dwNumberOfBytesToMap); } -HANDLE resources_pak_file = nullptr; - -typedef HANDLE(WINAPI* pCreateFileMapping)(_In_ HANDLE hFile, - _In_opt_ LPSECURITY_ATTRIBUTES - lpAttributes, - _In_ DWORD flProtect, - _In_ DWORD dwMaximumSizeHigh, - _In_ DWORD dwMaximumSizeLow, - _In_opt_ LPCTSTR lpName); - -pCreateFileMapping RawCreateFileMapping = nullptr; - HANDLE WINAPI MyCreateFileMapping(_In_ HANDLE hFile, _In_opt_ LPSECURITY_ATTRIBUTES lpAttributes, _In_ DWORD flProtect, @@ -105,11 +97,24 @@ HANDLE WINAPI MyCreateFileMapping(_In_ HANDLE hFile, // No more hook needed. resources_pak_file = nullptr; - MH_DisableHook(CreateFileMappingW); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourDetach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Unhook RawCreateFileMapping failed %d", status); + } else { + DebugLog(L"Unhook RawCreateFileMapping success"); + } - if (MH_CreateHook(MapViewOfFile, MyMapViewOfFile, - (LPVOID*)&RawMapViewOfFile) == MH_OK) { - MH_EnableHook(MapViewOfFile); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&RawMapViewOfFile, MyMapViewOfFile); + status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Hook RawMapViewOfFile failed %d", status); + } else { + DebugLog(L"Hook RawMapViewOfFile success"); } return resources_pak_map; @@ -118,17 +123,6 @@ HANDLE WINAPI MyCreateFileMapping(_In_ HANDLE hFile, dwMaximumSizeLow, lpName); } -typedef HANDLE(WINAPI* pCreateFile)(_In_ LPCTSTR lpFileName, - _In_ DWORD dwDesiredAccess, - _In_ DWORD dwShareMode, - _In_opt_ LPSECURITY_ATTRIBUTES - lpSecurityAttributes, - _In_ DWORD dwCreationDisposition, - _In_ DWORD dwFlagsAndAttributes, - _In_opt_ HANDLE hTemplateFile); - -pCreateFile RawCreateFile = nullptr; - HANDLE WINAPI MyCreateFile(_In_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, @@ -144,25 +138,40 @@ HANDLE WINAPI MyCreateFile(_In_ LPCTSTR lpFileName, resources_pak_file = file; resources_pak_size = GetFileSize(resources_pak_file, nullptr); - if (MH_CreateHook(CreateFileMappingW, MyCreateFileMapping, - (LPVOID*)&RawCreateFileMapping) == MH_OK) { - MH_EnableHook(CreateFileMappingW); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Hook RawCreateFileMapping failed %d", status); + } else { + DebugLog(L"Hook RawCreateFileMapping success"); } // No more hook needed. - MH_DisableHook(CreateFileW); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourDetach((LPVOID*)&RawCreateFile, MyCreateFile); + status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Unhook RawCreateFile failed %d", status); + } else { + DebugLog(L"Unhook RawCreateFile success"); + } } return file; } void PakPatch() { - MH_STATUS status = - MH_CreateHook(CreateFileW, MyCreateFile, (LPVOID*)&RawCreateFile); - if (status == MH_OK) { - MH_EnableHook(CreateFileW); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&RawCreateFile, MyCreateFile); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Hook RawCreateFile failed %d", status); } else { - DebugLog(L"MH_CreateHook CreateFileW failed:%d", status); + DebugLog(L"Hook RawCreateFile success"); } } diff --git a/src/patch.h b/src/patch.h index fa4932f..2c50c57 100644 --- a/src/patch.h +++ b/src/patch.h @@ -74,13 +74,15 @@ void MakePatch() { // } HMODULE ntdll = GetModuleHandle(L"ntdll.dll"); if (ntdll) { - PBYTE LdrLoadDll = (PBYTE)GetProcAddress(ntdll, "LdrLoadDll"); - MH_STATUS status = - MH_CreateHook(LdrLoadDll, MyLdrLoadDll, (LPVOID*)&RawLdrLoadDll); - if (status == MH_OK) { - MH_EnableHook(LdrLoadDll); - } else { - DebugLog(L"MH_CreateHook LdrLoadDll failed:%d", status); + RawLdrLoadDll = (pLdrLoadDll)GetProcAddress(ntdll, "LdrLoadDll"); + if (RawLdrLoadDll) { + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach((LPVOID*)&RawLdrLoadDll, MyLdrLoadDll); + auto status = DetourTransactionCommit(); + if (status != NO_ERROR) { + DebugLog(L"Hook LdrLoadDll failed %d", status); + } } } } diff --git a/xmake.lua b/xmake.lua index 8ded445..e768c0c 100644 --- a/xmake.lua +++ b/xmake.lua @@ -15,19 +15,21 @@ end add_cxflags("/utf-8") -add_links("gdiplus", "kernel32", "user32", "gdi32", "winspool", "comdlg32") -add_links("advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32") +-- add_links("gdiplus", "kernel32", "user32", "gdi32", "winspool", "comdlg32") +-- add_links("advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32") +add_links("kernel32", "user32", "shell32", "oleaut32", "propsys", "shlwapi", "crypt32", "advapi32", "netapi32") -target("minhook") +target("detours") set_kind("static") - add_files("minhook/src/**.c") - add_includedirs("minhook/include", {public=true}) + add_files("detours/src/*.cpp|uimports.cpp") + add_includedirs("detours/src", {public=true}) target("chrome_plus") set_kind("shared") set_targetdir("$(buildir)/release") set_basename("version") - add_deps("minhook") + add_deps("detours") + add_links("detours") add_files("src/*.cpp") add_files("src/*.rc") add_links("user32") @@ -35,4 +37,4 @@ target("chrome_plus") after_build(function (target) os.rm("$(buildir)/release/version.exp") os.rm("$(buildir)/release/version.lib") - end) + end) \ No newline at end of file