fix: #64 Size of MSG is different on Win32 and Win64

This commit is contained in:
yuanyuanxiang
2025-04-01 03:57:38 +08:00
parent 2dbdc1860f
commit 1492ef4bd2
4 changed files with 102 additions and 14 deletions

View File

@@ -273,17 +273,24 @@ VOID CScreenManager::SendNextScreen(const char* szBuffer, ULONG ulNextSendLength
VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength) VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
{ {
// <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>Ϸ<EFBFBD> int msgSize = sizeof(MSG64);
if (ulLength % sizeof(MSG) != 0) if (ulLength % 28 == 0) // 32λ<32><CEBB><EFBFBD>ƶ˷<C6B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
return; msgSize = 28;
else if (ulLength % 48 == 0) // 64λ<34><CEBB><EFBFBD>ƶ˷<C6B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
msgSize = 48;
else return; // <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>Ϸ<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ULONG ulMsgCount = ulLength / sizeof(MSG); ULONG ulMsgCount = ulLength / msgSize;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < ulMsgCount; ++i) BYTE* ptr = szBuffer;
MSG32 msg32;
MSG64 msg64;
for (int i = 0; i < ulMsgCount; ++i, ptr += msgSize)
{ {
MSG *Msg = (MSG *)(szBuffer + i * sizeof(MSG)); MSG64* Msg = msgSize == 48 ? (MSG64*)ptr :
(MSG64*)msg64.Create(msg32.Create(ptr, msgSize));
switch (Msg->message) switch (Msg->message)
{ {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:

View File

@@ -241,3 +241,86 @@ inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::st
} }
return false; return false;
} }
#ifdef _WIN32
#ifdef _WINDOWS
#include <afxwin.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
class MSG32 { // <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(32λ)
public:
uint32_t hwnd;
uint32_t message;
uint32_t wParam;
uint32_t lParam;
uint32_t time;
POINT pt;
MSG32(const void* buffer, int size) {
if (size == sizeof(MSG32)) {
memcpy(this, buffer, sizeof(MSG32));
}
else {
memset(this, 0, sizeof(MSG32));
}
}
MSG32() {
memset(this, 0, sizeof(MSG32));
}
MSG32* Create(const void* buffer, int size) {
if (size == sizeof(MSG32)) {
memcpy(this, buffer, sizeof(MSG32));
}
else {
memset(this, 0, sizeof(MSG32));
}
return this;
}
};
// Windows <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢMSG<53><47>32λ<32><CEBB>64λϵͳ<CFB5>´<EFBFBD>С<EFBFBD><D0A1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>¿<EFBFBD>ƽ̨<C6BD>ܹ<EFBFBD>Զ<EFBFBD>̿<EFBFBD><CCBF><EFBFBD><EFBFBD>
// <20><>Ҫʹ<D2AA><CAB9><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(ͳһ<CDB3><D2BB><EFBFBD><EFBFBD>64λwindows <20><>MSG<53><47><EFBFBD><EFBFBD>)
class MSG64 { // <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(64λ)
public:
uint64_t hwnd;
uint64_t message;
uint64_t wParam;
uint64_t lParam;
uint64_t time;
POINT pt;
MSG64(const MSG& msg) :hwnd((uint64_t)msg.hwnd), message(msg.message), wParam(msg.wParam),
lParam(msg.lParam), time(msg.time), pt(msg.pt) {}
MSG64(const MSG32& msg) :hwnd((uint64_t)msg.hwnd), message(msg.message), wParam(msg.wParam),
lParam(msg.lParam), time(msg.time), pt(msg.pt) {}
MSG64(const void* buffer, int size) {
if (size == sizeof(MSG64)) {
memcpy(this, buffer, sizeof(MSG64));
}
else {
memset(this, 0, sizeof(MSG64));
}
}
MSG64() {
memset(this, 0, sizeof(MSG64));
}
MSG64* Create(const MSG32* msg32) {
hwnd = msg32->hwnd;
message = msg32->message;
wParam = msg32->wParam;
lParam = msg32->lParam;
time = msg32->time;
pt = msg32->pt;
return this;
}
};
#endif

View File

@@ -535,8 +535,7 @@ BOOL CScreenSpyDlg::PreTranslateMessage(MSG* pMsg)
case WM_MBUTTONUP: case WM_MBUTTONUP:
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
MSG Msg; MSG64 Msg(*pMsg);
memcpy(&Msg, pMsg, sizeof(MSG));
Msg.lParam = MAKEDWORD(HIWORD(pMsg->lParam) + m_ulVScrollPos, LOWORD(pMsg->lParam) + m_ulHScrollPos); Msg.lParam = MAKEDWORD(HIWORD(pMsg->lParam) + m_ulVScrollPos, LOWORD(pMsg->lParam) + m_ulHScrollPos);
Msg.pt.x += m_ulHScrollPos; Msg.pt.x += m_ulHScrollPos;
Msg.pt.y += m_ulVScrollPos; Msg.pt.y += m_ulVScrollPos;
@@ -551,8 +550,7 @@ BOOL CScreenSpyDlg::PreTranslateMessage(MSG* pMsg)
return TRUE; return TRUE;
if (pMsg->wParam != VK_LWIN && pMsg->wParam != VK_RWIN) if (pMsg->wParam != VK_LWIN && pMsg->wParam != VK_RWIN)
{ {
MSG Msg; MSG64 Msg(*pMsg);
memcpy(&Msg, pMsg, sizeof(MSG));
Msg.lParam = MAKEDWORD(HIWORD(pMsg->lParam) + m_ulVScrollPos, LOWORD(pMsg->lParam) + m_ulHScrollPos); Msg.lParam = MAKEDWORD(HIWORD(pMsg->lParam) + m_ulVScrollPos, LOWORD(pMsg->lParam) + m_ulHScrollPos);
Msg.pt.x += m_ulHScrollPos; Msg.pt.x += m_ulHScrollPos;
Msg.pt.y += m_ulVScrollPos; Msg.pt.y += m_ulVScrollPos;
@@ -567,15 +565,15 @@ BOOL CScreenSpyDlg::PreTranslateMessage(MSG* pMsg)
} }
VOID CScreenSpyDlg::SendCommand(MSG* Msg) VOID CScreenSpyDlg::SendCommand(const MSG64* Msg)
{ {
if (!m_bIsCtrl) if (!m_bIsCtrl)
return; return;
const int length = sizeof(MSG) + 1; const int length = sizeof(MSG64) + 1;
BYTE szData[length + 3]; BYTE szData[length + 3];
szData[0] = COMMAND_SCREEN_CONTROL; szData[0] = COMMAND_SCREEN_CONTROL;
memcpy(szData + 1, Msg, sizeof(MSG)); memcpy(szData + 1, Msg, sizeof(MSG64));
szData[length] = 0; szData[length] = 0;
m_iocpServer->OnClientPreSending(m_ContextObject, szData, length); m_iocpServer->OnClientPreSending(m_ContextObject, szData, length);
} }

View File

@@ -59,7 +59,7 @@ public:
CString m_strClientIP; CString m_strClientIP;
BOOL m_bIsTraceCursor; BOOL m_bIsTraceCursor;
CCursorInfo m_CursorInfo; //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ϵͳ<CFB5>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD> CCursorInfo m_CursorInfo; //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ϵͳ<CFB5>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>
VOID SendCommand(MSG* Msg); VOID SendCommand(const MSG64* Msg);
VOID UpdateServerClipboard(char *szBuffer,ULONG ulLength); VOID UpdateServerClipboard(char *szBuffer,ULONG ulLength);
VOID SendServerClipboard(void); VOID SendServerClipboard(void);