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