diff --git a/client/ScreenManager.cpp b/client/ScreenManager.cpp index f7fb308..e6ff6d8 100644 --- a/client/ScreenManager.cpp +++ b/client/ScreenManager.cpp @@ -38,7 +38,7 @@ int UninitFileUpload() { return 0; } -std::vector GetClipboardFiles() +std::vector GetClipboardFiles(int &result) { return{}; } @@ -446,7 +446,8 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength) break; } case COMMAND_SCREEN_GET_CLIPBOARD: { - auto files = GetClipboardFiles(); + int result = 0; + auto files = GetClipboardFiles(result); if (!files.empty()) { char h[100] = {}; memcpy(h, szBuffer + 1, ulLength - 1); @@ -481,7 +482,8 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength) } case COMMAND_GET_FILE: { // 发送文件 - auto files = GetClipboardFiles(); + int result = 0; + auto files = GetClipboardFiles(result); std::string dir = (char*)(szBuffer + 1); if (!files.empty() && !dir.empty()) { IOCPClient* pClient = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType()); diff --git a/common/file_upload.h b/common/file_upload.h index 759fdf6..f003d5c 100644 --- a/common/file_upload.h +++ b/common/file_upload.h @@ -19,7 +19,7 @@ int InitFileUpload(const std::string hmac, int chunkSizeKb = 64, int sendDuratio int UninitFileUpload(); -std::vector GetClipboardFiles(); +std::vector GetClipboardFiles(int& result); bool GetCurrentFolderPath(std::string& outDir); diff --git a/lib/FileUpload_Libx64.lib b/lib/FileUpload_Libx64.lib index 8849da3..bbf0bf2 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 a9a25e2..1370fec 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 4fe6f49..70a9463 100644 --- a/server/2015Remote/2015Remote.cpp +++ b/server/2015Remote/2015Remote.cpp @@ -166,19 +166,22 @@ static BOOL HandleServiceCommandLine() // -service: 作为服务运行 if (cmdLine.Find(_T("-service")) != -1) { - ServerService_Run(); + int r = ServerService_Run(); + Mprintf("[HandleServiceCommandLine] ServerService_Run %s", r ? "failed" : "succeed"); return TRUE; } // -install: 安装服务 if (cmdLine.Find(_T("-install")) != -1) { - ServerService_Install(); + BOOL r = ServerService_Install(); + Mprintf("[HandleServiceCommandLine] ServerService_Install %s", !r ? "failed" : "succeed"); return TRUE; } // -uninstall: 卸载服务 if (cmdLine.Find(_T("-uninstall")) != -1) { - ServerService_Uninstall(); + BOOL r = ServerService_Uninstall(); + Mprintf("[HandleServiceCommandLine] ServerService_Uninstall %s", !r ? "failed" : "succeed"); return TRUE; } @@ -186,6 +189,7 @@ static BOOL HandleServiceCommandLine() // 此模式下正常运行GUI,但使用不同的互斥量名称避免冲突 if (cmdLine.Find(_T("-agent")) != -1) { // 继续正常启动GUI,但标记为代理模式 + Mprintf("[HandleServiceCommandLine] Run service agent: '%s'", cmdLine.GetString()); return FALSE; } @@ -193,7 +197,9 @@ static BOOL HandleServiceCommandLine() BOOL registered = FALSE; BOOL running = FALSE; char servicePath[MAX_PATH] = { 0 }; - ServerService_CheckStatus(®istered, &running, servicePath, MAX_PATH); + BOOL r = ServerService_CheckStatus(®istered, &running, servicePath, MAX_PATH); + Mprintf("[HandleServiceCommandLine] ServerService_CheckStatus %s", !r ? "failed" : "succeed"); + char curPath[MAX_PATH]; GetModuleFileNameA(NULL, curPath, MAX_PATH); @@ -202,22 +208,22 @@ static BOOL HandleServiceCommandLine() ExtractExePathFromServicePath(servicePath, serviceExePath, MAX_PATH); if (registered && _stricmp(curPath, serviceExePath) != 0) { - Mprintf("ServerService Uninstall: %s\n", servicePath); + Mprintf("[HandleServiceCommandLine] ServerService Uninstall: %s\n", servicePath); ServerService_Uninstall(); registered = FALSE; } if (!registered) { - Mprintf("ServerService Install: %s\n", curPath); + Mprintf("[HandleServiceCommandLine] ServerService Install: %s\n", curPath); return ServerService_Install(); } else if (!running) { int r = ServerService_Run(); - Mprintf("ServerService Run '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed"); + Mprintf("[HandleServiceCommandLine] ServerService Run '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed"); if (r) { r = ServerService_StartSimple(); - Mprintf("ServerService Start '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed"); + Mprintf("[HandleServiceCommandLine] ServerService Start '%s' %s\n", curPath, r == ERROR_SUCCESS ? "succeed" : "failed"); return r == ERROR_SUCCESS; } - return FALSE; + return TRUE; } return TRUE; } @@ -268,11 +274,14 @@ BOOL CMy2015RemoteApp::InitInstance() { char curFile[MAX_PATH] = { 0 }; GetModuleFileNameA(NULL, curFile, MAX_PATH); - if (!IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) + if (!IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) { + Mprintf("[InitInstance] 程序没有管理员权限,用户选择以管理员身份重新运行。"); return FALSE; + } // 首先处理服务命令行参数 if (HandleServiceCommandLine()) { + Mprintf("[InitInstance] 服务命令已处理,退出。"); return FALSE; // 服务命令已处理,退出 } @@ -286,11 +295,13 @@ BOOL CMy2015RemoteApp::InitInstance() m_Mutex = NULL; MessageBox("一个主控程序已经在运行,请检查任务管理器。", "提示", MB_ICONINFORMATION); + Mprintf("[InitInstance] 一个主控程序已经在运行,退出。"); return FALSE; } } #endif + Mprintf("[InitInstance] 主控程序启动运行。"); SetUnhandledExceptionFilter(&whenbuged); // 创建并显示启动画面 @@ -371,7 +382,10 @@ int CMy2015RemoteApp::ExitInstance() // 只有在代理模式退出时才停止服务 if (IsAgentMode()) { ServerService_Stop(); + Mprintf("[InitInstance] 主控程序为代理模式,停止服务。"); } + Mprintf("[InitInstance] 主控程序退出运行。"); + return CWinApp::ExitInstance(); } diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index 20b1a42..4f0f1a0 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -2215,13 +2215,17 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject) switch (cmd) { case COMMAND_GET_FILE: { // 发送文件 - auto files = GetClipboardFiles(); + int result; + auto files = GetClipboardFiles(result); if (!files.empty()) { std::string dir = (char*)(szBuffer + 1); std::string hash = GetPwdHash(), hmac = GetHMAC(100); std::thread(FileBatchTransferWorker, files, dir, ContextObject, SendData, FinishSend, hash, hmac).detach(); } + else { + Mprintf("GetClipboardFiles failed: %d\n", result); + } break; } case COMMAND_SEND_FILE: { @@ -3857,6 +3861,9 @@ void CMy2015RemoteDlg::RemoveRemoteWindow(HWND wnd) LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { + if (g_2015RemoteDlg == NULL) + return S_OK; + if (nCode == HC_ACTION) { do { static CDialogBase* operateWnd = nullptr; @@ -3883,7 +3890,8 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam break; } // [1] 本地 -> 远程 - auto files = GetClipboardFiles(); + int result; + auto files = GetClipboardFiles(result); if (!files.empty()) { // 获取远程目录 BYTE szBuffer[100] = { COMMAND_GET_FOLDER }; @@ -3891,6 +3899,7 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam memcpy((char*)szBuffer + 1, masterId.c_str(), masterId.length()); memcpy((char*)szBuffer + 1 + masterId.length(), hmac.c_str(), hmac.length()); dlg->m_ContextObject->Send2Client(szBuffer, sizeof(szBuffer)); + Mprintf("【Ctrl+V】 从本地拷贝文件到远程 \n"); } else { CString strText = GetClipboardText(); if (!strText.IsEmpty()) { @@ -3898,9 +3907,12 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam szBuffer[0] = COMMAND_SCREEN_SET_CLIPBOARD; memcpy(szBuffer + 1, strText.GetString(), strText.GetLength()); dlg->m_ContextObject->Send2Client(szBuffer, strText.GetLength() + 1); - Mprintf("【Ctrl+V】 从本地拷贝到远程 \n"); + Mprintf("【Ctrl+V】 从本地拷贝文本到远程 \n"); SAFE_DELETE_ARRAY(szBuffer); } + else { + Mprintf("【Ctrl+V】 本地剪贴板没有文本或文件: %d \n", result); + } } } else if (g_2015RemoteDlg->m_pActiveSession && operateWnd) { auto screen = (CScreenSpyDlg*)(g_2015RemoteDlg->m_pActiveSession); @@ -3913,12 +3925,9 @@ LRESULT CALLBACK CMy2015RemoteDlg::LowLevelKeyboardProc(int nCode, WPARAM wParam std::string masterId = GetPwdHash(), hmac = GetHMAC(100); memcpy((char*)bToken + 1, masterId.c_str(), masterId.length()); memcpy((char*)bToken + 1 + masterId.length(), hmac.c_str(), hmac.length()); - auto files = GetClipboardFiles(); - if (!files.empty()) { - if (::OpenClipboard(nullptr)) { - EmptyClipboard(); - CloseClipboard(); - } + if (::OpenClipboard(nullptr)) { + EmptyClipboard(); + CloseClipboard(); } g_2015RemoteDlg->m_pActiveSession->m_ContextObject->Send2Client(bToken, sizeof(bToken)); Mprintf("【Ctrl+V】 从远程拷贝到本地 \n"); diff --git a/server/2015Remote/ScreenSpyDlg.cpp b/server/2015Remote/ScreenSpyDlg.cpp index c0b1652..66569b8 100644 --- a/server/2015Remote/ScreenSpyDlg.cpp +++ b/server/2015Remote/ScreenSpyDlg.cpp @@ -52,7 +52,7 @@ int UninitFileUpload() { return 0; } -std::vector GetClipboardFiles() +std::vector GetClipboardFiles(int &result) { return{}; } diff --git a/server/2015Remote/ServerServiceWrapper.cpp b/server/2015Remote/ServerServiceWrapper.cpp index 1a817d9..e95b8d4 100644 --- a/server/2015Remote/ServerServiceWrapper.cpp +++ b/server/2015Remote/ServerServiceWrapper.cpp @@ -451,7 +451,7 @@ BOOL ServerService_Install(void) return err == 0; } -void ServerService_Uninstall(void) +BOOL ServerService_Uninstall(void) { SC_HANDLE schSCManager = OpenSCManager( NULL, @@ -461,7 +461,7 @@ void ServerService_Uninstall(void) if (schSCManager == NULL) { Mprintf("ERROR: OpenSCManager failed (%d)\n", (int)GetLastError()); - return; + return FALSE; } SC_HANDLE schService = OpenServiceA( @@ -473,7 +473,7 @@ void ServerService_Uninstall(void) if (schService == NULL) { Mprintf("ERROR: OpenService failed (%d)\n", (int)GetLastError()); CloseServiceHandle(schSCManager); - return; + return FALSE; } // 停止服务 @@ -501,14 +501,17 @@ void ServerService_Uninstall(void) } } + BOOL r = FALSE; // 删除服务 Mprintf("Deleting service...\n"); if (DeleteService(schService)) { Mprintf("SUCCESS: Service uninstalled successfully\n"); + r = TRUE; } else { Mprintf("ERROR: DeleteService failed (%d)\n", (int)GetLastError()); } CloseServiceHandle(schService); CloseServiceHandle(schSCManager); + return r; } diff --git a/server/2015Remote/ServerServiceWrapper.h b/server/2015Remote/ServerServiceWrapper.h index 64823e6..9337fb0 100644 --- a/server/2015Remote/ServerServiceWrapper.h +++ b/server/2015Remote/ServerServiceWrapper.h @@ -52,7 +52,7 @@ int ServerService_Stop(void); BOOL ServerService_Install(void); // 卸载服务 -void ServerService_Uninstall(void); +BOOL ServerService_Uninstall(void); // 服务工作线程 DWORD WINAPI ServerService_WorkerThread(LPVOID lpParam);