Skip to content

Commit

Permalink
Impl x32/x64 check
Browse files Browse the repository at this point in the history
  • Loading branch information
lich0821 committed Jul 7, 2024
1 parent 0279b11 commit 478bbdf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions WeChatFerry/com/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions WeChatFerry/com/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions WeChatFerry/sdk/sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 478bbdf

Please sign in to comment.