From 478bbdfdab126ea194bce40dd5fff17ffb0f7556 Mon Sep 17 00:00:00 2001 From: Changhua Date: Mon, 8 Jul 2024 00:51:26 +0800 Subject: [PATCH] Impl x32/x64 check --- WeChatFerry/com/util.cpp | 28 ++++++++++++++++++++++++++++ WeChatFerry/com/util.h | 1 + WeChatFerry/sdk/sdk.cpp | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/WeChatFerry/com/util.cpp b/WeChatFerry/com/util.cpp index 273a1bd..5e906e6 100644 --- a/WeChatFerry/com/util.cpp +++ b/WeChatFerry/com/util.cpp @@ -180,6 +180,34 @@ DWORD GetWeChatPid() return pid; } +enum class WindowsArchiture { x32, x64 }; +static WindowsArchiture GetWindowsArchitecture() +{ +#ifdef _WIN64 + return WindowsArchiture::x64; +#else + return WindowsArchiture::x32; +#endif +} + +BOOL IsProcessX64(DWORD pid) +{ + BOOL isWow64 = false; + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid); + if (!hProcess) + return false; + BOOL result = IsWow64Process(hProcess, &isWow64); + CloseHandle(hProcess); + if (!result) + return false; + if (isWow64) + return false; + else if (GetWindowsArchitecture() == WindowsArchiture::x32) + return false; + else + return true; +} + int OpenWeChat(DWORD *pid) { *pid = GetWeChatPid(); diff --git a/WeChatFerry/com/util.h b/WeChatFerry/com/util.h index 00e50bb..8f252df 100644 --- a/WeChatFerry/com/util.h +++ b/WeChatFerry/com/util.h @@ -24,6 +24,7 @@ typedef struct PortPath { } PortPath_t; DWORD GetWeChatPid(); +BOOL IsProcessX64(DWORD pid); int OpenWeChat(DWORD *pid); int GetWeChatVersion(wchar_t *version); size_t GetWstringByAddress(UINT64 address, wchar_t *buffer, UINT64 buffer_size); diff --git a/WeChatFerry/sdk/sdk.cpp b/WeChatFerry/sdk/sdk.cpp index ff754d5..5a14180 100644 --- a/WeChatFerry/sdk/sdk.cpp +++ b/WeChatFerry/sdk/sdk.cpp @@ -47,6 +47,11 @@ int WxInitSDK(bool debug, int port) return status; } + if (!IsProcessX64(wcPid)) { + MessageBox(NULL, L"只支持 64 位微信", L"WxInitSDK", 0); + return -1; + } + Sleep(2000); // 等待微信打开 wcProcess = InjectDll(wcPid, spyDllPath, &spyBase); if (wcProcess == NULL) {