Esempio n. 1
0
bool CI8DeskSvr::StartRemoteControl()
{
	stdex::tString strFilePath = utility::GetAppPath() + _T("WinVNC\\");
	SetDllDirectory(strFilePath.c_str());

	strFilePath += TEXT("WinVNC.dll");
	m_hRemoteCtrl = LoadLibrary(strFilePath.c_str());
	if (m_hRemoteCtrl == NULL)
		return false;

	typedef BOOL (WINAPI* PFNSTARTVNC)();
	PFNSTARTVNC pfnStartVNC = GetProcAddress(m_hRemoteCtrl, "_StartVNC@0");
	if (pfnStartVNC == NULL)
		return false;

	try
	{
		pfnStartVNC(); 
	}
	catch(...)
	{
		m_pLogger->WriteLog(LM_INFO, TEXT("加载远程控制客户端失败。\r\n"));
		BOOL (WINAPI* pfnStopVNC)();
		pfnStopVNC = GetProcAddress(m_hRemoteCtrl, "_StopVNC@0");
		if (pfnStopVNC == NULL)
			return false;

		pfnStopVNC(); 
	}

	m_pLogger->WriteLog(LM_INFO, TEXT("加载远程控制客户端成功。\r\n"));
	return true;
}
Esempio n. 2
0
	bool CCliMgr::UnInitialize()
	{
		if (m_pLogger)
		{
			m_pLogger->WriteLog(LM_INFO, TEXT("Plug UnInitialize"));
			m_pLogger->SetAddDateBefore(false);
			m_pLogger->WriteLog(LM_INFO, TEXT("=========================================================\r\n\r\n"));
		}
		return true;
	}
Esempio n. 3
0
	void CCliMgr::KillProcess(LPCTSTR lpszSvrName)
	{
		DWORD aProcesses[1024] = {0}, cbNeeded = 0, cProcesses = 0, MemSize = 0;
		if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ))
		{
			DWORD dwError = GetLastError();
			_com_error Error(dwError);
			m_pLogger->WriteLog(LM_INFO, TEXT("GetSysProcess (EnumProcess) Error:%d:%s"), dwError, Error.ErrorMessage());
			return;
		}
		cProcesses = cbNeeded / sizeof(DWORD);
		tstring sModName = lpszSvrName;
		for (DWORD idx=0; idx<cProcesses; idx++)
		{
			TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
			HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ|PROCESS_TERMINATE, FALSE, aProcesses[idx]);
			if (NULL != hProcess)
			{
				if (0 == GetModuleFileNameEx(hProcess, NULL, szProcessName, MAX_PATH))
				{
					CloseHandle( hProcess );
					continue;
				}
				string strProcName = ProcessImagePath(szProcessName);
				if (stricmp(sModName.c_str(), strProcName.c_str()) == 0)
				{
					TerminateProcess(hProcess,0);
					CloseHandle( hProcess );
					return ;
				}
				CloseHandle( hProcess );
			}
		}	
	}
Esempio n. 4
0
	virtual DWORD OnStart()
	{
		if (m_pLogger == NULL || m_hExited == NULL)
		{
			Stop();
			return ERROR_SUCCESS;
		}
		m_pLogger->SetLogFileName(SERVICE_NAME);
		m_pLogger->SetAddDateBefore(false);
		m_pLogger->WriteLog(LM_INFO, TEXT("============================="));
		m_pLogger->SetAddDateBefore(true);

		if (OneInstance())
		{
			Stop();
			return ERROR_SUCCESS;
		}


		if ((m_hThread = (HANDLE)_beginthreadex(NULL, 0, WorkThread, this, 0, NULL)) == NULL)
		{
			Stop();
			return ERROR_SUCCESS;
		}

		return ERROR_SUCCESS;
	}
Esempio n. 5
0
	bool CCliMgr::Initialize(IPlugMgr* pPlugMgr)
	{
		if (pPlugMgr == NULL || (m_pLogger = pPlugMgr->CreateLogger()) == NULL)
			return false;
		m_pPlugMgr =  pPlugMgr;
		m_Hy.SetLogger(m_pLogger);
		m_pLogger->SetLogFileName(CLIMGR_PLUG_NAME);
		m_pLogger->SetAddDateBefore(false);
		m_pLogger->WriteLog(LM_INFO, TEXT("========================================================="));
		m_pLogger->SetAddDateBefore(true);
		m_pLogger->WriteLog(LM_INFO, TEXT("Plug Initialize"));
		if (!m_Hy.IsInitialize())
		{
			m_pLogger->WriteLog(LM_INFO, TEXT("HY Initialize Fail."));
			return false;
		}
		return true;
	}
Esempio n. 6
0
	virtual DWORD OnStop()
	{

		ReportStatusToSCM(SERVICE_STOP_PENDING);
		if (m_hThread != NULL && m_hThread != NULL)
		{
			SetEvent(m_hExited);
			WaitForSingleObject(m_hThread, INFINITE);
			CloseHandle(m_hThread);
			m_hThread = NULL;
		}
		if (m_pLogger)
		{
			m_pLogger->WriteLog(LM_INFO, TEXT("%s: stoped."), GetSvrName());
			m_pLogger->SetAddDateBefore(false);
			m_pLogger->WriteLog(LM_INFO, TEXT("=============================\r\n\r\n"));
		}
		KillService(TEXT("DNAService.exe"));
		return ERROR_SUCCESS;
	}
Esempio n. 7
0
void CI8DeskSvr::FreeRemoteCtrlPlug()
{
	if (m_hRemoteCtrl != NULL)
	{
		BOOL (WINAPI* pfnStopVNC)();
		pfnStopVNC = GetProcAddress(m_hRemoteCtrl, "StopVNC");
		if (pfnStopVNC != NULL)
			pfnStopVNC(); 
		FreeLibrary(m_hRemoteCtrl);
	}
	m_hRemoteCtrl = NULL;

	m_pLogger->WriteLog(LM_INFO, TEXT("释放远程控制客户端成功。"));
}
Esempio n. 8
0
	BOOL CCliMgr::RunProcess(LPCSTR lpImage, LPCSTR lpPara)
	{
		if(!lpImage)
		{
			return FALSE;
		}
		HANDLE hToken;
		if(!GetTokenByName(hToken, "explorer.exe"))
		{
			m_pLogger->WriteLog(LM_INFO, TEXT("OpenProcessToken Faile!"));
			return FALSE;
		}
		STARTUPINFO si = {0};
		PROCESS_INFORMATION pi = {0};
		si.cb= sizeof(STARTUPINFO);
		si.lpDesktop = TEXT("winsta0\\default");
 		LPVOID lpEnv = NULL;
 		CreateEnvironmentBlock(&lpEnv, hToken, FALSE);
		BOOL bResult = CreateProcessAsUser(hToken, NULL, (LPSTR)lpPara, NULL, NULL,
			FALSE, CREATE_UNICODE_ENVIRONMENT, lpEnv, NULL, &si, &pi);
		CloseHandle(hToken);
		m_pLogger->WriteLog(LM_INFO, TEXT("%s."),lpPara);
		if(bResult)
		{
			CloseHandle(pi.hThread);
			CloseHandle(pi.hProcess);
			m_pLogger->WriteLog(LM_INFO, TEXT("CreateProcessAsUser ok."));
		}
		else
		{
			DWORD ir = GetLastError();
			m_pLogger->WriteLog(LM_INFO, TEXT("CreateProcessAsUser false."));
		}
		if (lpEnv)
			DestroyEnvironmentBlock(lpEnv);
		return bResult;
	}
Esempio n. 9
0
	void CCliMgr::StopService(LPCTSTR lpszSvrName)
	{
		SC_HANDLE   schSCManager;
		SERVICE_STATUS svcStatus;
		BOOL success;
		schSCManager = OpenSCManager(
			NULL,                   // machine (NULL == local)
			NULL,                   // database (NULL == default)
			SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE  // access required
			);
		if (schSCManager == NULL)
			return ;

		//打开服务    
		SC_HANDLE hService = ::OpenService(schSCManager, lpszSvrName, SERVICE_ALL_ACCESS);   
		if (hService != NULL)   
		{   
			success = QueryServiceStatus(hService,&svcStatus);
			if (!success)
			{
				return;
			}
			if (svcStatus.dwCurrentState == SERVICE_RUNNING)
			{
					success = ControlService(
					hService,           // handle to service
					SERVICE_CONTROL_STOP, // control code
					&svcStatus            // pointer to service status structure
					);
					if (!success)
					{
						DWORD dwError = GetLastError();
						_com_error Error(dwError);
						m_pLogger->WriteLog(LM_INFO, TEXT("Stop Service:%s  Erorr:%d:%s"),lpszSvrName, dwError, (LPCTSTR)Error.ErrorMessage());
					}

			}
			::CloseServiceHandle(hService);   
		}   
		::CloseServiceHandle(schSCManager); 

		return ;
	}
Esempio n. 10
0
	bool CCliMgr::ExecCmd(LPSTR pOutData, int nOutLen, LPSTR& pInData, int& nInLen, bool bNeedAck /* = true */)
	{
		ICommunication* pICommunication = m_pPlugMgr->GetCommunication();
		CAutoLock<ICommunication> lock(pICommunication);
		if (!pICommunication->ExecCmd(pOutData, nOutLen, pInData, nInLen, bNeedAck))
			return false;

		if (!bNeedAck)
			return true;

		CPackageHelper in(pInData);
		DWORD dwStatus = in.popDWORD();
		if (dwStatus == CMD_RET_FAIL)
		{
			char szError[4096] = {0};
			in.popString(szError);
			m_pLogger->WriteLog(LM_INFO, "Exec Cmd Error:%s", szError);
			CoTaskMemFree(pInData);
			pInData = NULL;
			nInLen = 0;
			return false;
		}
		return true;
	}
Esempio n. 11
0
	tstring CCliMgr::GetWmiInfo( LPCTSTR lpszClass,LPCTSTR lpszField)
	{
		tstring SysInfo,strtmp;
		HRESULT ret;
		ret = CoInitialize(NULL);
		ret = CoInitializeSecurity( NULL,
			-1,
			NULL,
			NULL,
			RPC_C_AUTHN_LEVEL_PKT,
			RPC_C_IMP_LEVEL_IMPERSONATE,
			NULL,
			EOAC_NONE,
			0
			);
		if (ret == S_OK || ret== RPC_E_TOO_LATE )
		{
			IWbemLocator * pIWbemLocator = NULL;
			IWbemServices * pWbemServices = NULL;
			IEnumWbemClassObject * pEnumObject  = NULL;
			BSTR bstrNamespace = (L"root\\cimv2");// 通过 IWbemLocator 和 IWbemServices 这两个 COM 接口访问 WMI, 获取系统信息
			if(CoCreateInstance (CLSID_WbemAdministrativeLocator, NULL,
				CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown ,(void**)&pIWbemLocator) 
				== S_OK)
			{
				if(pIWbemLocator->ConnectServer(
					bstrNamespace,  // Namespace
					NULL,			// Userid
					NULL,           // PW
					NULL,           // Locale
					0,              // flags
					NULL,           // Authority
					NULL,           // Context
					&pWbemServices
					) == S_OK)
				{
					HRESULT hRes;
					_bstr_t strQuery = (L"Select * from Win32_OperatingSystem");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
							if(hRes == S_OK)
							{
								strtmp = "操作系统的名称: "+_getWmiInfo(pClassObject,"Caption")+"\r\n";
								SysInfo = SysInfo + strtmp;
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
					strQuery = (L"Select * from Win32_DiskDrive");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
							if(hRes == S_OK)
							{
								strtmp = "硬盘的Model: "+_getWmiInfo(pClassObject,"Model")+"\r\n";
								SysInfo = SysInfo + strtmp;
								m_pLogger->WriteLog(LM_INFO, TEXT("硬盘的Model: %s"),_getWmiInfo(pClassObject,"Model").c_str());
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}					
					strQuery = (L"Select * from Win32_LogicalDisk");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							while( pEnumObject->Next( WBEM_INFINITE, 
								uCount, &pClassObject, &uReturned) == S_OK )
							{
								if (atoi(_getWmiInfo(pClassObject,"DriveType").c_str()) != 3)
									continue;
								tstring str;
								str =_getWmiInfo(pClassObject,"Name");
								strtmp = "盘符: " +str+"    ";
								m_pLogger->WriteLog(LM_INFO, TEXT("盘符: %s"),str.c_str());
								tstring drv;
								drv += toupper(str[0]);										
								if(m_Hy.IsDriverProtected((char *)drv.c_str()))
								{
									strtmp = strtmp+ "还原状态: 保护 ";
									m_pLogger->WriteLog(LM_INFO, TEXT("还原状态: 保护 "));
								}
								else
								{
									strtmp = strtmp+ "还原状态: 未保护 ";
									m_pLogger->WriteLog(LM_INFO, TEXT("还原状态: 未保护 "));	
								}
								strtmp = strtmp+ "  剩余空间: "+_getWmiInfo(pClassObject,"FreeSpace")+"\r\n";
								SysInfo = SysInfo + strtmp;
								m_pLogger->WriteLog(LM_INFO, TEXT("剩余空间: %s"),_getWmiInfo(pClassObject,"FreeSpace").c_str());
								
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
					strQuery = (L"Select * from Win32_processor");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
							if(hRes == S_OK)
							{
								strtmp = "处理器的制造厂商: "+_getWmiInfo(pClassObject,"Manufacturer") + "\r\n";
								strtmp = strtmp + "处理器的名称: "+_getWmiInfo(pClassObject,"Caption") + "\r\n";
								SysInfo = SysInfo + strtmp;

								m_pLogger->WriteLog(LM_INFO, TEXT("处理器的制造厂商: %s"),_getWmiInfo(pClassObject,"Manufacturer").c_str());
								m_pLogger->WriteLog(LM_INFO, TEXT("处理器的名称: %s"),_getWmiInfo(pClassObject,"Caption").c_str());
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
					strQuery = (L"Select * from Win32_LogicalMemoryConfiguration");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
							if(hRes == S_OK)
							{
								strtmp = "物理内存大小: "+_getWmiInfo(pClassObject,"TotalPhysicalMemory") + "\r\n";
								strtmp = strtmp + "页面文件大小: "+_getWmiInfo(pClassObject,"TotalPageFileSpace") + "\r\n";
								strtmp = strtmp + "虚拟内存大小: "+_getWmiInfo(pClassObject,"TotalVirtualMemory") + "\r\n";
								SysInfo = SysInfo + strtmp;

								m_pLogger->WriteLog(LM_INFO, TEXT("物理内存大小: %s"),_getWmiInfo(pClassObject,"TotalPhysicalMemory").c_str());
								m_pLogger->WriteLog(LM_INFO, TEXT("页面文件大小: %s"),_getWmiInfo(pClassObject,"TotalPageFileSpace").c_str());
								m_pLogger->WriteLog(LM_INFO, TEXT("虚拟内存大小: %s"),_getWmiInfo(pClassObject,"TotalVirtualMemory").c_str());
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
					strQuery = (L"Select * from Win32_VideoController");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
							if(hRes == S_OK)
							{
								strtmp = "显卡名称: "+_getWmiInfo(pClassObject,"Name") + "\r\n";
								SysInfo = SysInfo + strtmp;
								m_pLogger->WriteLog(LM_INFO, TEXT("显卡名称: %s"),_getWmiInfo(pClassObject,"Name").c_str());
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
					strQuery = (L"Select * from Win32_NetworkAdapter where (Netconnectionstatus = 2)");
					hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
					if(hRes == S_OK)
					{
						ULONG uCount = 1, uReturned;
						IWbemClassObject * pClassObject = NULL;
						hRes = pEnumObject->Reset();
						if(hRes == S_OK)
						{
							while( pEnumObject->Next( WBEM_INFINITE, 
								uCount, &pClassObject, &uReturned) == S_OK )
							{
								tstring str;
								str =_getWmiInfo(pClassObject,"MACAddress");
								if (!str.empty())
								{
									str =_getWmiInfo(pClassObject,"PNPDeviceID");
									size_t pos =  str.find("PCI",0);
									if (pos != tstring::npos)
									{
										tstring str = _getWmiInfo(pClassObject,"Caption");
										size_t pos = str.find(']');
										if (pos != tstring::npos)
											str = str.substr(pos+1);
										strtmp = "网卡名称: "+str + "\r\n";
										SysInfo = SysInfo + strtmp;
										m_pLogger->WriteLog(LM_INFO,  "网卡名称: %s" , str.c_str()) ;	
									}
								}
							}
							if (pClassObject != NULL)
								pClassObject->Release();				
						}
					}
				}
			}
			if (pIWbemLocator)
				pIWbemLocator->Release();
			if (pWbemServices)
				pWbemServices->Release();
			if (pEnumObject)
				pEnumObject->Release();
		}
		CoUninitialize();
		if (!SysInfo.empty())
		{
			m_SysInfo = SysInfo;
		}
		return SysInfo;
	}
Esempio n. 12
0
	void CCliMgr::GetSysService()
	{
		SC_HANDLE schManager = OpenSCManager(NULL, NULL, SERVICE_QUERY_STATUS);
		if (schManager == NULL)
		{
			DWORD dwError = GetLastError();
			_com_error Error(dwError);
			m_pLogger->WriteLog(LM_INFO, TEXT("GetSysService-OpenSCManager Error:%d:%s"), dwError, Error.ErrorMessage());
			return ;
		}

		DWORD dwSize = 0, dwCount = 0;
		LPENUM_SERVICE_STATUS st = (LPENUM_SERVICE_STATUS)LocalAlloc(LPTR, 64*1024);
		LPQUERY_SERVICE_CONFIG sc = (LPQUERY_SERVICE_CONFIG)LocalAlloc(LPTR, 4 * 1024);
		if (!EnumServicesStatus(schManager, SERVICE_TYPE_ALL, SERVICE_ACTIVE, st, 1024*64, &dwSize, &dwCount, NULL))
		{
			DWORD dwError = GetLastError();
			_com_error Error(dwError);
			m_pLogger->WriteLog(LM_INFO, TEXT("EnumServicesStatus Error:%d:%s"), dwError, Error.ErrorMessage());
		}

		CMarkup xml;
		xml.SetDoc("<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n");
		xml.AddElem("ServiceLst");
		xml.IntoElem();
		
		for (DWORD idx=0; idx<dwCount; idx++)
		{
			SC_HANDLE hService = ::OpenService(schManager,st[idx].lpServiceName,SERVICE_QUERY_CONFIG);
			if(hService)
			{
				DWORD dwSize = 0;
				::QueryServiceConfig(hService, sc, 4 * 1024, &dwSize);
				CloseServiceHandle(hService);
			}
			if (st[idx].ServiceStatus.dwCurrentState == SERVICE_RUNNING)
			{
				TCHAR buf[MAX_PATH] = {0};
				_stprintf(buf, TEXT("%s  %s  %s)\r\n"), st[idx].lpServiceName, sc->lpBinaryPathName, st[idx].lpDisplayName);

				string strProcName = ProcessImagePath(sc->lpBinaryPathName);
				xml.AddElem("Service");
				xml.AddAttrib("Name",		 st[idx].lpServiceName);
				xml.AddAttrib("Application", strProcName.c_str());
				xml.AddAttrib("DisplayName", st[idx].lpDisplayName);
				m_pLogger->WriteLog(LM_INFO, buf);
			}
		}
		xml.OutOfElem();
		string data=xml.GetDoc();
		char *pData = NULL;
		int  nSize = data.size() + 1024;
		char* buf= new char[nSize];
		_packageheader* pheader = (_packageheader*)buf;
		InitPackage(pheader, CMD_GAME_CLIENTTOCON);
		CPackageHelper out(buf);
		out.pushDWORD(Ctrl_ViewSviInfo);
		out.pushString(data.c_str(), data.size());
		pheader->Length = out.GetOffset();
		if (!ExecCmd(buf, pheader->Length, pData, nSize, false))
			m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewSviInfo Fail.");			
		else
		{
			m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewSviInfo Success.");
			CoTaskMemFree(pData);
		}
		delete []buf;
		LocalFree(st);
		LocalFree(sc);
		CloseServiceHandle(schManager);
	}
Esempio n. 13
0
	void CCliMgr::GetSysProcess()
	{
		DWORD aProcesses[1024] = {0}, cbNeeded = 0, cProcesses = 0, MemSize = 0;
		if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ))
		{
			DWORD dwError = GetLastError();
			_com_error Error(dwError);
			m_pLogger->WriteLog(LM_INFO, TEXT("GetSysProcess (EnumProcess) Error:%d:%s"), dwError, Error.ErrorMessage());
			return;
		}
		cProcesses = cbNeeded / sizeof(DWORD);
		m_pLogger->WriteLog(LM_INFO, TEXT("Process Num:%d"), cProcesses);
		CMarkup xml;
		xml.SetDoc("<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n");
		xml.AddElem("ProcessLst");
		xml.IntoElem();
		for (DWORD idx=0; idx<cProcesses; idx++)
		{
			TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
			HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, aProcesses[idx]);
			if (NULL == hProcess)
				continue;
			else
			{
				if (0 == GetModuleFileNameEx(hProcess, NULL, szProcessName, MAX_PATH))
				{
					CloseHandle( hProcess );
					continue;
				}
				PROCESS_MEMORY_COUNTERS pmc = {0};
				pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS);
				if ( ::GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
				{
					MemSize = pmc.WorkingSetSize;
				}
				CloseHandle( hProcess );
			}
			string strProcName = ProcessImagePath(szProcessName);		
 			TCHAR buf[MAX_PATH] = {0};
 			_stprintf(buf, TEXT("%s  %d  (PID: %u)\r\n"), szProcessName,MemSize, aProcesses[idx]);
			xml.AddElem("Process");
			xml.AddAttrib("Name",	strProcName);    
			xml.AddAttrib("Pid",	aProcesses[idx]);    
			xml.AddAttrib("Memory",	MemSize);				
			m_pLogger->WriteLog(LM_INFO, buf);
		}
		xml.OutOfElem();
		string data=xml.GetDoc(); 
		char *pData = NULL;
		int  nSize = data.size() +1024;
		char* buf= new char[nSize];
		_packageheader* pheader = (_packageheader*)buf;
		InitPackage(pheader, CMD_GAME_CLIENTTOCON);
		CPackageHelper out(buf);
		out.pushDWORD(Ctrl_ViewProcInfo);
		out.pushString(data.c_str(), data.size());
		pheader->Length = out.GetOffset();

		if (!ExecCmd(buf, pheader->Length, pData, nSize,false))
			m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewProcInfo Fail.");			
		else
		{
			m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewProcInfo Success.");
			CoTaskMemFree(pData);
		}
		delete []buf;
	}
Esempio n. 14
0
	void CCliMgr::UdpRecvNotify(char* pData, int length, sockaddr_in& from)
	{
		_packageheader* pheader = reinterpret_cast<_packageheader*>(pData);
		CPackageHelper  in(pData);

		m_pLogger->WriteLog(LM_INFO, TEXT("Recv Server UDP Cmd."));

		DWORD dwCRC = in.popDWORD();
		E_CliCtrlCmd cmd = (E_CliCtrlCmd)in.popDWORD();
		switch (cmd)
		{
		case Ctrl_InstallProt:
			{	
				bool bProtArea = (in.popDWORD() == 1);
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv Prot Install, Prot All Area:%s"), 
					bProtArea ?  TEXT("true") : TEXT("false"));
				/*是否安装还原*/
				if (!m_Hy.IsInstallHy())
				{
					if (bProtArea)
					{
						m_Hy.InstallHy("CDEFGHIJKLMNOPQRSTUVWXYZ");
					}
					else
						m_Hy.InstallHy("");
				}
				else
				{
					if (bProtArea)
						m_Hy.ProtArea("CDEFGHIJKLMNOPQRSTUVWXYZ");
				}
				//写注册表,以使还原不自检。
				SHSetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Session Manager", 
					"BootExecute", REG_MULTI_SZ, "", 0);
			}
			break;
		case Ctrl_RemoveProt:
			{
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv Remove Prot."));
				m_Hy.RemoveHy();
			}
			break;
		case Ctrl_ProtArea:
			{
				char ProtArea[30] ={0};
				in.popString(ProtArea);
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv Prot Area Cmd:%s"), ProtArea);				
				m_Hy.ProtArea(ProtArea);
				in.popString(ProtArea);
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv UnProt Area Cmd:%s"), ProtArea);				
				m_Hy.UnProtArea(ProtArea);
			}
			break;
		case Ctrl_ShutDown:
			{
				bool bReboot = (in.popDWORD() == 1);
				m_pLogger->WriteLog(LM_INFO, bReboot ? TEXT("Recv ReBoot Machine Cmd.") : 
					TEXT("Recv ShutDown Machine Cmd."));
				m_Hy.ShutDown(bReboot);
			}
			break;
		case Ctrl_ExecFile:
			{
				char szFile[MAX_PATH] = {0};
				in.popString(szFile);
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv Run Exe File:%s"), szFile);
				
				tstring root = GetRunGameExe();
				root = root +tstring(szFile);
				RunProcess(root.c_str(),root.c_str());
			}
			break;
		case Ctrl_ViewSysInfo:	//得到系统信息
			{
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv View System Info Cmd."));

				GetWmiInfo("Win32_DiskDrive","Manufacturer");
				char *pData = NULL;
				int  nSize = m_SysInfo.size() +1024;
				char* buf= new char[nSize];
				_packageheader* pheader = (_packageheader*)buf;
				InitPackage(pheader, CMD_GAME_CLIENTTOCON);
				
				CPackageHelper out(buf);
				out.pushDWORD(Ctrl_ViewSysInfo);
				out.pushString(m_SysInfo.c_str(), m_SysInfo.size());
				pheader->Length = out.GetOffset();
				if (!ExecCmd(buf, pheader->Length, pData, nSize,false))
					m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewSysInfo Fail.");			
				else
				{
					m_pLogger->WriteLog(LM_INFO, "Report Ctrl_ViewSysInfo Success.");
					CoTaskMemFree(pData);
				}
				delete []buf;
				
			}
			break;
		case Ctrl_ViewProcInfo: //系统进程的控制
			{
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv View Process Info Cmd."));
				GetSysProcess();
			}
			break;
		case Ctrl_ViewSviInfo: //服务控制
			{
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv View Service Info Cmd."));
				GetSysService();
			}
			break;
		case Ctrl_KillProcSvr: //杀进程,停服务
			{
				m_pLogger->WriteLog(LM_INFO, TEXT("Recv KillProcSvr Cmd."));
				char Name[MAX_PATH] ={0};
				if (in.popDWORD())
				{
					in.popString(Name);
					KillProcess(Name);
				}
				else
				{
					in.popString(Name);
					StopService(Name);
				}				
			}
			break;
		}
	}
Esempio n. 15
0
void CI8DeskSvr::RegDNAService()
{
	m_pLogger->WriteLog(LM_INFO, TEXT("Start Check DNAService."));
	TCHAR path[MAX_PATH] = {0};
	GetModuleFileName(NULL, path, MAX_PATH);
	PathRemoveFileSpec(path);
	PathAddBackslash(path);
	lstrcat(path, TEXT("DNAService\\DNAService.exe"));
	stdex::tString szDNAService(path);
	szDNAService.insert(0, TEXT("\""));
	szDNAService += TEXT("\"");

	std::pair<stdex::tString, bool> cmd[] =
	{
		std::make_pair(TEXT("-UnRegServer"),	true),
		std::make_pair(TEXT("-RegServer"),		true),
		std::make_pair(TEXT("-Service"),		true),
	};
	if (!IsService())
	{
		cmd[2].second = false;
	}
	else
	{
		utility::CAutoService schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (schSCManager.IsValid())
		{
			utility::CAutoService schService = OpenService(schSCManager, TEXT("DNAS"), SERVICE_ALL_ACCESS);
			if (schService.IsValid())
			{
				char buf[4096] = {0};
				LPQUERY_SERVICE_CONFIG lpConfig = reinterpret_cast<LPQUERY_SERVICE_CONFIG>(buf);
				DWORD dwSize = sizeof(buf);
				DWORD dwNeedSize = 0;
				QueryServiceConfig(schService, lpConfig, dwSize, &dwNeedSize);
				if (lstrcmpi(lpConfig->lpBinaryPathName, szDNAService.c_str()) == 0)
				{
					m_pLogger->WriteLog(LM_INFO, TEXT("Registry DNAService Success."));
					return ;
				}
			}
		}
	}
	for (int idx=0; idx<_countof(cmd);idx++)
	{
		if (!cmd[idx].second)
			continue;

		TCHAR line[1024] = {0};
		_stprintf(line, TEXT("%s %s"), szDNAService.c_str(), cmd[idx].first.c_str());

		STARTUPINFO si = {sizeof(si)};
		PROCESS_INFORMATION pi = {0};

		if (!CreateProcess(NULL, line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
		{
			DWORD dwError = GetLastError();
			_com_error Error(dwError);
			m_pLogger->WriteLog(LM_INFO, TEXT("[%s]:fail:%d:%s"), line, dwError, Error.ErrorMessage());
			m_pLogger->WriteLog(LM_INFO, TEXT("Registry DNAService Fail."));
			return ;
		}
		WaitForSingleObject(pi.hProcess, INFINITE);
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
	}
	m_pLogger->WriteLog(LM_INFO, TEXT("Registry DNAService Success."));
}