ServiceManageDlg.cpp
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:8k
源码类别:

网络截获/分析

开发平台:

Visual C++

  1. // ServiceManageDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyClient.h"
  5. #include "ServiceManageDlg.h"
  6. #include "resource.h"
  7. #include "TcpTran.h"
  8. #include "ServiceManageEditDlg.h"
  9. /*
  10.  作者:海啸 lyyer English Name: Jack 
  11.   blog:http://lyyer.blog.sohu.com
  12.   website:http://www.cnGSG.com
  13.   海啸网络安全组织
  14. */
  15. #include "comm.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CServiceManageDlg dialog
  23. CServiceManageDlg  *m_servicemanagedlg = NULL;
  24. static int Svritem = 0;
  25. //void OnStartManageService();
  26. CServiceManageDlg::CServiceManageDlg(CWnd* pParent /*=NULL*/)
  27. : CDialog(CServiceManageDlg::IDD, pParent)
  28. {
  29. //{{AFX_DATA_INIT(CServiceManageDlg)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. m_servicemanagedlg = this;
  33. }
  34. void CServiceManageDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CServiceManageDlg)
  38. DDX_Control(pDX, IDC_LIST, m_list);
  39. //}}AFX_DATA_MAP
  40. }
  41. DWORD WINAPI InitListService(std::vector<SERVICEINFO *> pServInfo)
  42. {
  43. m_servicemanagedlg->m_list.DeleteAllItems();
  44. for(DWORD i = 0; i < pServInfo.size(); i++)
  45. {
  46.         CString tmp = _T("");
  47. /*
  48. tmp.Format("%d",pServInfo[i]->num); //****得到vector[i] 里的结构的一部分**** //pVecTor->at(i).PID
  49.     m_servicemanagedlg->m_list.InsertItem(i,"");
  50.     m_servicemanagedlg->m_list.SetItemText(i,0,tmp);
  51. */    
  52.     tmp.Format("%s",pServInfo[i]->ServiceName);
  53.     m_servicemanagedlg->m_list.InsertItem(i,(const char *)0);
  54.       m_servicemanagedlg->m_list.SetItemText(i,0,tmp);
  55.      tmp.Format("%s",pServInfo[i]->ServiceDetail); 
  56.     m_servicemanagedlg->m_list.InsertItem(i,(const char *)1);
  57.     m_servicemanagedlg->m_list.SetItemText(i,1,tmp);
  58.      tmp.Format("%s",pServInfo[i]->ServiceState); 
  59.     m_servicemanagedlg->m_list.InsertItem(i,(const char *)2);
  60.     m_servicemanagedlg->m_list.SetItemText(i,2,tmp);
  61.      
  62. tmp.Format("%s",pServInfo[i]->ServiceStartType); 
  63.     m_servicemanagedlg->m_list.InsertItem(i,(const char *)3);
  64.     m_servicemanagedlg->m_list.SetItemText(i,3,tmp);
  65. /*  */
  66. }
  67. return 0;
  68. }
  69. void OnServiceStart()
  70. {
  71. COMMAND m_command;
  72. int len = 0;
  73.     //extern  SOCKET g__clientsocket ;
  74. memset((char  *)&m_command, 0,sizeof(m_command));
  75.     m_command.wCmd = CMD_SERVICE_MANAGE;
  76.     m_command.DataSize = 0;
  77. CTcpTran m_tcptran ; 
  78.     int sbuf = 0; 
  79.     
  80. len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
  81.     if (len<0)
  82. {
  83. len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);    
  84.     }
  85. int servicelen = m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)&sbuf,sizeof(int),0,60,NULL,false);
  86. if (servicelen>0)
  87. {
  88. std::vector<SERVICEINFO *> pServiceInfo;
  89.         SERVICEINFO *tmp = new SERVICEINFO; //一样的问题 
  90. // 
  91.         for(int i=0;i<sbuf;i++)
  92. {
  93. tmp = new SERVICEINFO;
  94. memset(tmp, 0,sizeof(SERVICEINFO));
  95. m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)tmp,sizeof(SERVICEINFO),0,60,0,false);
  96. pServiceInfo.push_back(tmp);
  97. //delete tmp;
  98. }
  99.         /*
  100. for(int jj = 0;jj<pServiceInfo.size();jj++)
  101. {
  102. AfxMessageBox(pServiceInfo[jj]->ServiceName);
  103. }
  104. */
  105. InitListService(pServiceInfo);
  106. }
  107. }
  108. BOOL CServiceManageDlg::OnInitDialog()
  109. {
  110. CDialog::OnInitDialog();
  111. // TODO: Add extra initialization here
  112. LONG mlStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
  113. mlStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;
  114. m_list.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)mlStyle);
  115. LV_COLUMN lvc;
  116. lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH /*| LVCF_FMT*/;
  117. m_list.DeleteAllItems();
  118.   //m_list.InsertColumn(0,"编号",LVCFMT_LEFT,50);
  119.     m_list.InsertColumn(0,"服务名称",LVCFMT_LEFT,120);
  120. m_list.InsertColumn(1,"描述",LVCFMT_LEFT,270);
  121. m_list.InsertColumn(2,"状态",LVCFMT_LEFT,80);
  122. m_list.InsertColumn(3,"启动类型",LVCFMT_LEFT,80);
  123. OnServiceStart();
  124. return TRUE;
  125. }
  126. BEGIN_MESSAGE_MAP(CServiceManageDlg, CDialog)
  127. ON_WM_CONTEXTMENU()
  128. //{{AFX_MSG_MAP(CServiceManageDlg)
  129. ON_COMMAND(ID_MANAGE_SERVICE_EDIT, OnManageServiceEdit)
  130. ON_COMMAND(ID_MANAGE_SERVICE_REFRESH, OnManageServiceRefresh)
  131. ON_COMMAND(ID_MANAGE_SERVICE_DEL, OnManageServiceDel)
  132. ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
  133. //}}AFX_MSG_MAP
  134. END_MESSAGE_MAP()
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CServiceManageDlg message handlers
  137. void CServiceManageDlg::OnContextMenu(CWnd*, CPoint point)
  138. {
  139. // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_SERVICE_MANAGE_DLG)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
  140. }
  141. void CServiceManageDlg::OnManageServiceEdit() 
  142. {
  143. // TODO: Add your command handler code here
  144. CServiceManageEditDlg m_servicemanageeditdlg;
  145. m_servicemanageeditdlg.m_ClientSocket = ClientSocket;
  146. // get service pram
  147. CString id;
  148. //char *m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,0); 
  149. //strcpy(m_servicemanageeditdlg.ServiceName,m_chsvr);
  150.     m_servicemanageeditdlg.ServiceName=m_list.GetItemText(Svritem,0); 
  151. m_servicemanageeditdlg.ServiceState=m_list.GetItemText(Svritem,2); 
  152. m_servicemanageeditdlg.ServiceStartType=m_list.GetItemText(Svritem,3); 
  153. //id = m_list.GetItemText(Svritem,2);
  154. // m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,2); 
  155. // strcpy(m_servicemanageeditdlg.ServiceState,m_chsvr);
  156. //
  157. // m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,3); 
  158. // strcpy(m_servicemanageeditdlg.ServiceStartType,m_chsvr);
  159. m_servicemanageeditdlg.DoModal();
  160. }
  161. void CServiceManageDlg::OnManageServiceRefresh() 
  162. {
  163. // TODO: Add your command handler code here
  164. OnServiceStart();
  165. }
  166. void CServiceManageDlg::OnManageServiceDel() 
  167. {
  168. // TODO: Add your command handler code here
  169. COMMAND m_command;
  170. int len = 0;
  171.     //extern  SOCKET g__clientsocket ;
  172. memset((char  *)&m_command, 0,sizeof(m_command));
  173.     m_command.wCmd = CMD_SERVICE_DEL;
  174.    
  175.     // get SvrID 
  176. CString id;
  177. DWORD tmp_Serviceid = 0;
  178. id = m_list.GetItemText(Svritem,0);
  179. char *m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,0); 
  180. strcpy(m_command.tmp,m_chsvr);
  181. CTcpTran m_tcptran ; 
  182.     int sbuf = 0; 
  183.     
  184. len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
  185.     if (len<0)
  186. {
  187. len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);    
  188.     }
  189. int Svrlen = m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)&sbuf,sizeof(int),0,60,NULL,false);
  190. if (Svrlen>0)
  191. {
  192. std::vector<SERVICEINFO *> pServiceInfo;
  193.         SERVICEINFO *tmp = new SERVICEINFO; //一样的问题 
  194. // 
  195.         for(int i=0;i<sbuf;i++)
  196. {
  197. tmp = new SERVICEINFO;
  198. memset(tmp, 0,sizeof(SERVICEINFO));
  199. m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)tmp,sizeof(SERVICEINFO),0,60,0,false);
  200. pServiceInfo.push_back(tmp);
  201. //delete tmp;
  202. }
  203. InitListService(pServiceInfo);
  204. }
  205. }
  206. void CServiceManageDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
  207. {
  208. // TODO: Add your control notification handler code here
  209. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  210. if(pNMListView->iItem != -1)
  211.     {
  212. //调试用代码
  213. ////////////////////////////////////////////////////////////////////////
  214.         //        CString strtemp;
  215.         //        strtemp.Format("单击的是第%d行第%d列",
  216.         //                        pNMListView->iItem, pNMListView->iSubItem);
  217.         //        AfxMessageBox(strtemp);
  218. ////////////////////////////////////////////////////////////////////////
  219.                 Svritem  = pNMListView->iItem;
  220.     }
  221. *pResult = 0;
  222. }