diff --git a/client/ClientDll.cpp b/client/ClientDll.cpp index 3b2daea..69553cd 100644 --- a/client/ClientDll.cpp +++ b/client/ClientDll.cpp @@ -198,7 +198,7 @@ int main(int argc, const char *argv[]) } } - if (!SetSelfStart(argv[0], REG_NAME)) { + if (!SetSelfStart(argv[0], REG_NAME, Logf)) { Mprintf("设置开机自启动失败,请用管理员权限运行.\n"); } diff --git a/client/ScreenCapturerDXGI.h b/client/ScreenCapturerDXGI.h index b996d13..f6f2aa0 100644 --- a/client/ScreenCapturerDXGI.h +++ b/client/ScreenCapturerDXGI.h @@ -273,11 +273,12 @@ private: BYTE* pData = (BYTE*)mapped.pData; int rowSize = m_ulFullWidth * 4; // ÿеֽRGBA + BYTE* dest = buffer + reservedBytes + (m_ulFullHeight - 1) * rowSize; + BYTE* src = pData; for (int y = 0; y < m_ulFullHeight; y++) { - // Ŀ껺λãӵײ - int destIndex = reservedBytes + (m_ulFullHeight - 1 - y) * rowSize; - int srcIndex = y * mapped.RowPitch; // Direct3D ƫ - memcpy(buffer + destIndex, pData + srcIndex, rowSize); + memcpy(dest, src, rowSize); + dest -= rowSize; + src += mapped.RowPitch; } // 7. diff --git a/client/ScreenManager.cpp b/client/ScreenManager.cpp index 7734c26..0d11e77 100644 --- a/client/ScreenManager.cpp +++ b/client/ScreenManager.cpp @@ -276,6 +276,40 @@ void CScreenManager::InitScreenSpy() } } +BOOL IsRunningAsSystem() { + HANDLE hToken; + PTOKEN_USER pTokenUser = NULL; + DWORD dwSize = 0; + BOOL isSystem = FALSE; + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) { + return FALSE; + } + + GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize); + pTokenUser = (PTOKEN_USER)malloc(dwSize); + + if (pTokenUser && GetTokenInformation(hToken, TokenUser, pTokenUser, + dwSize, &dwSize)) { + // 使用 WellKnownSid 创建 SYSTEM SID + BYTE systemSid[SECURITY_MAX_SID_SIZE]; + DWORD sidSize = sizeof(systemSid); + + if (CreateWellKnownSid(WinLocalSystemSid, NULL, systemSid, &sidSize)) { + isSystem = EqualSid(pTokenUser->User.Sid, systemSid); + if (isSystem){ + Mprintf("当前进程以 SYSTEM 身份运行。\n"); + } else { + Mprintf("当前进程未以 SYSTEM 身份运行。\n"); + } + } + } + + free(pTokenUser); + CloseHandle(hToken); + return isSystem; +} + BOOL CScreenManager::OnReconnect() { m_SendFirst = FALSE; @@ -320,19 +354,16 @@ DWORD WINAPI CScreenManager::WorkThreadProc(LPVOID lParam) This->SendFirstScreen(); } // 降低桌面检查频率,避免频繁的DC重置导致闪屏 - if (This->m_isGDI && This->IsRunAsService() && !This->m_virtual) { + if (This->IsRunAsService() && !This->m_virtual) { auto now = clock(); if (now - last_check > 500) { last_check = now; - // 使用公共函数检查并切换桌面(无需写权限) - if (SwitchToDesktopIfChanged(This->g_hDesk, 0)) { + if (SwitchToDesktopIfChanged(This->g_hDesk, 0) && This->m_isGDI) { // 桌面变化时重置屏幕捕获的DC - if (This->m_ScreenSpyObject) { - CScreenSpy* spy = dynamic_cast(This->m_ScreenSpyObject); - if (spy) { - spy->ResetDesktopDC(); - } + CScreenSpy* spy = (CScreenSpy*)(This->m_ScreenSpyObject); + if (spy) { + spy->ResetDesktopDC(); } } } @@ -884,13 +915,7 @@ VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength) return; } if (IsRunAsService()) { - // 获取当前活动桌面(带写权限,用于锁屏等安全桌面) - // 使用独立的静态变量避免与WorkThreadProc的g_hDesk并发冲突 - static HDESK s_inputDesk = NULL; - static clock_t s_lastCheck = 0; - static DWORD s_lastThreadId = 0; const int CHECK_INTERVAL = 100; // 桌面检测间隔(ms),快速响应锁屏/UAC切换 - // 首次调用或定期检测桌面是否变化(降低频率,避免每次输入都检测) auto now = clock(); if (!s_inputDesk || now - s_lastCheck > CHECK_INTERVAL) { diff --git a/client/ScreenManager.h b/client/ScreenManager.h index 932b952..0069374 100644 --- a/client/ScreenManager.h +++ b/client/ScreenManager.h @@ -17,6 +17,8 @@ bool LaunchApplication(TCHAR* pszApplicationFilePath, TCHAR* pszDesktopName); bool IsWindows8orHigher(); +BOOL IsRunningAsSystem(); + class IOCPClient; struct UserParam; @@ -58,8 +60,17 @@ public: } bool IsRunAsService() const { - return m_conn ? m_conn->iStartup == Startup_GhostMsc : false; + if (m_conn && (m_conn->iStartup == Startup_GhostMsc || m_conn->iStartup == Startup_TestRunMsc)) + return true; + static BOOL is_run_as_system = IsRunningAsSystem(); + return is_run_as_system; } + // ȡǰ棨дȨޣȰȫ棩 + // ʹöľ̬WorkThreadProcg_hDeskͻ + HDESK s_inputDesk = NULL; + clock_t s_lastCheck = 0; + DWORD s_lastThreadId = 0; + bool SwitchScreen(); virtual BOOL OnReconnect(); uint64_t m_DlgID = 0; diff --git a/client/auto_start.h b/client/auto_start.h index 19d4c8d..b0ce7a5 100644 --- a/client/auto_start.h +++ b/client/auto_start.h @@ -45,6 +45,8 @@ inline int DebugPrivilege() return 0; } +typedef void (*StartupLogFunc)(const char* file, int line, const char* format, ...); + /** * @brief ñ * @param[in] *sPath ע· @@ -54,26 +56,42 @@ inline int DebugPrivilege() * HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run * @note ״ҪԹԱȨУעд뿪 */ -inline BOOL SetSelfStart(const char* sPath, const char* sNmae) +inline BOOL SetSelfStart(const char* sPath, const char* sNmae, StartupLogFunc Log) { - DebugPrivilege(); +#define _Mprintf(format, ...) if (Log) Log(__FILE__, __LINE__, format, __VA_ARGS__) + + int n = DebugPrivilege(); + if (n != 0) { + _Mprintf("Ȩʧܣ룺%d\n", n); + return FALSE; + } // дע· -#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" +#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run" // עдϢ HKEY hKey = NULL; LONG lRet = RegOpenKeyExA(HKEY_CURRENT_USER, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey); // жǷɹ - if (lRet != ERROR_SUCCESS) + if (lRet != ERROR_SUCCESS) { + _Mprintf("עʧܣ룺%d\n", lRet); return FALSE; + } lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1); + if (lRet != ERROR_SUCCESS) { + _Mprintf("дעʧܣ룺%d\n", lRet); + } else { + _Mprintf("дעɹ%s -> %s\n", sNmae, sPath); + } + // رע RegCloseKey(hKey); +#undef _Mprintf + // жǷɹ return lRet == ERROR_SUCCESS; } diff --git a/client/test.cpp b/client/test.cpp index cf22998..083eb78 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -231,7 +231,7 @@ int main(int argc, const char *argv[]) } } - BOOL ok = SetSelfStart(argv[0], REG_NAME); + BOOL ok = SetSelfStart(argv[0], REG_NAME, Logf); if(!ok) { Mprintf("设置开机自启动失败,请用管理员权限运行.\n"); } diff --git a/lib/FileUpload_Lib.lib b/lib/FileUpload_Lib.lib index 50c1ce3..ab01293 100644 Binary files a/lib/FileUpload_Lib.lib and b/lib/FileUpload_Lib.lib differ diff --git a/lib/FileUpload_Libd.lib b/lib/FileUpload_Libd.lib index fb429f0..236b275 100644 Binary files a/lib/FileUpload_Libd.lib and b/lib/FileUpload_Libd.lib differ diff --git a/lib/FileUpload_Libx64.lib b/lib/FileUpload_Libx64.lib index 2ec44dd..3e43453 100644 Binary files a/lib/FileUpload_Libx64.lib and b/lib/FileUpload_Libx64.lib differ diff --git a/lib/FileUpload_Libx64d.lib b/lib/FileUpload_Libx64d.lib index 501e3af..e6acfc5 100644 Binary files a/lib/FileUpload_Libx64d.lib and b/lib/FileUpload_Libx64d.lib differ diff --git a/server/2015Remote/2015Remote.cpp b/server/2015Remote/2015Remote.cpp index ca597df..010b832 100644 --- a/server/2015Remote/2015Remote.cpp +++ b/server/2015Remote/2015Remote.cpp @@ -239,7 +239,11 @@ BOOL LaunchAsAdmin(const char* szFilePath, const char* verb) BOOL CMy2015RemoteApp::InitInstance() { +#if _DEBUG + BOOL runNormal = TRUE; +#else BOOL runNormal = THIS_CFG.GetInt("settings", "RunNormal", 0); +#endif char curFile[MAX_PATH] = { 0 }; GetModuleFileNameA(NULL, curFile, MAX_PATH); if (!runNormal && !IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) { diff --git a/server/2015Remote/CPasswordDlg.cpp b/server/2015Remote/CPasswordDlg.cpp index 485d075..830de75 100644 --- a/server/2015Remote/CPasswordDlg.cpp +++ b/server/2015Remote/CPasswordDlg.cpp @@ -142,6 +142,13 @@ void CPasswordDlg::OnCbnSelchangeComboBind() std::string hardwareID = CMy2015RemoteDlg::GetHardwareID(m_nBindType); m_sDeviceID = getFixedLengthID(hashSHA256(hardwareID)).c_str(); m_EditDeviceID.SetWindowTextA(m_sDeviceID); + auto master = THIS_CFG.GetStr("settings", "master", ""); + if (m_nBindType == 1) { + MessageBoxA("请确认是否正确设置公网地址(IP或域名)?\r\n" + "绑定IP后主控只能使用指定IP,绑定域名后\r\n" + "主控只能使用指定域名。当前公网地址: \r\n" + + CString(master.empty() ? "未设置" : master.c_str()), "提示", MB_OK | MB_ICONWARNING); + } } void CPasswordDlg::OnOK() diff --git a/server/2015Remote/Server.h b/server/2015Remote/Server.h index 4460877..66f7695 100644 --- a/server/2015Remote/Server.h +++ b/server/2015Remote/Server.h @@ -346,7 +346,7 @@ public: } virtual bool IsEqual(context *ctx) const { - return this == ctx || (GetPeerName() == ctx->GetPeerName() && GetPort() == ctx->GetPort()); + return this == ctx || this->GetPort() == ctx->GetPort(); } };