ProcManageDlg.cpp
资源名称:Visualhk.rar [点击查看]
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:7k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // ProcManageDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyClient.h"
- #include "ProcManageDlg.h"
- #include "resource.h"
- #include "MyClientDlg.h"
- #include "comm.h"
- #include "TcpTran.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /*
- 作者:海啸 lyyer English Name: Jack
- blog:http://lyyer.blog.sohu.com
- website:http://www.cnGSG.com
- 海啸网络安全组织
- */
- static int nrItemNum = 0;
- static DWORD procitem = 0;
- //extern SOCKET g__clientsocket ;
- /////////////////////////////////////////////////////////////////////////////
- // CProcManageDlg dialog
- CProcManageDlg *m_procmanagedlg = NULL;
- DWORD WINAPI InitList(std::vector<PROCESSINFO *> pVecTor)
- {
- //std::vector<PROCESSINFO> *pVecTor = (std::vector<PROCESSINFO>) lp;
- //std::vector<PROCESSINFO> *pVecTor =(vector<PROCESSINFO> ) lp;
- m_procmanagedlg->m_list.DeleteAllItems();
- for(DWORD i = 0; i < pVecTor.size(); i++)
- {
- CString tmp = _T("");
- tmp.Format("%d",pVecTor[i]->PID); //****得到vector[i] 里的结构的一部分**** //pVecTor->at(i).PID
- m_procmanagedlg->m_list.InsertItem(i,"");
- m_procmanagedlg->m_list.SetItemText(i,0,tmp);
- tmp.Format("%s",pVecTor[i]->ProcName);
- m_procmanagedlg->m_list.InsertItem(i,(const char *)1);
- m_procmanagedlg->m_list.SetItemText(i,1,tmp);
- tmp.Format("%s",pVecTor[i]->ProcPath);
- m_procmanagedlg->m_list.InsertItem(i,(const char *)2);
- m_procmanagedlg->m_list.SetItemText(i,2,tmp);
- }
- return 0;
- }
- CProcManageDlg::CProcManageDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CProcManageDlg::IDD, pParent)
- {
- m_procmanagedlg=this;
- //{{AFX_DATA_INIT(CProcManageDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CProcManageDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CProcManageDlg)
- DDX_Control(pDX, IDC_LIST, m_list);
- //}}AFX_DATA_MAP
- }
- void OnStart()
- {
- COMMAND m_command;
- int len = 0;
- //extern SOCKET g__clientsocket ;
- memset((char *)&m_command, 0,sizeof(m_command));
- m_command.wCmd = CMD_PROCESS_MANAGE;
- m_command.DataSize = 0;
- CTcpTran m_tcptran ;
- int buf = 0;
- len = m_tcptran.mysend(m_procmanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- if (len<0)
- {
- len = m_tcptran.mysend(m_procmanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- }
- int processlen = m_tcptran.myrecv(m_procmanagedlg->ClientSocket,(char *)&buf,sizeof(int),0,60,NULL,false);
- if (processlen>0)
- {
- std::vector<PROCESSINFO *> pProcInfo;
- PROCESSINFO *tmp = new PROCESSINFO; //一样的问题
- //
- for(int i=0;i<buf;i++)
- {
- tmp = new PROCESSINFO;
- memset(tmp, 0,sizeof(PROCESSINFO));
- m_tcptran.myrecv(m_procmanagedlg->ClientSocket,(char *)tmp,sizeof(PROCESSINFO),0,60,0,false);
- pProcInfo.push_back(tmp);
- //delete tmp;
- }
- InitList(pProcInfo);
- }
- }
- BOOL CProcManageDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- LONG lStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
- lStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;
- m_list.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)lStyle);
- LV_COLUMN lvc;
- lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH /*| LVCF_FMT*/;
- m_list.DeleteAllItems();
- m_list.InsertColumn(0,"进程ID",LVCFMT_LEFT,50);
- m_list.InsertColumn(1,"进程名称",LVCFMT_LEFT,110);
- m_list.InsertColumn(2,"路径",LVCFMT_LEFT,360);
- OnStart();
- return TRUE;
- }
- BEGIN_MESSAGE_MAP(CProcManageDlg, CDialog)
- ON_WM_CONTEXTMENU()
- //{{AFX_MSG_MAP(CProcManageDlg)
- ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
- ON_COMMAND(ID_MANAGEPROC_REFLUSH, OnManageprocReflush)
- ON_COMMAND(ID_MANAGEPROC_KILL, OnManageprocKill)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CProcManageDlg message handlers
- void CProcManageDlg::OnContextMenu(CWnd*, CPoint point)
- {
- // 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_PROC_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); }
- }
- void CProcManageDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- if(pNMListView->iItem != -1)
- {
- //调试用代码
- ////////////////////////////////////////////////////////////////////////
- // CString strtemp;
- // strtemp.Format("单击的是第%d行第%d列",
- // pNMListView->iItem, pNMListView->iSubItem);
- // AfxMessageBox(strtemp);
- ////////////////////////////////////////////////////////////////////////
- procitem = pNMListView->iItem;
- }
- *pResult = 0;
- }
- void CProcManageDlg::OnManageprocReflush()
- {
- // TODO: Add your command handler code here
- OnStart();
- }
- void CProcManageDlg::OnManageprocKill()
- {
- // TODO: Add your command handler code here
- COMMAND m_command;
- int len = 0;
- //extern SOCKET g__clientsocket ;
- memset((char *)&m_command, 0,sizeof(m_command));
- m_command.wCmd = CMD_PROCESS_KILL;
- // get PID
- CString id;
- DWORD tmp_pid = 0;
- id = m_list.GetItemText(procitem,0);
- // id.Format("%d",tmp_pid);
- tmp_pid = _ttoi(id);
- m_command.DataSize = tmp_pid;
- CTcpTran m_tcptran ;
- int buf = 0;
- len = m_tcptran.mysend(m_procmanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- if (len<0)
- {
- len = m_tcptran.mysend(m_procmanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- }
- int processlen = m_tcptran.myrecv(m_procmanagedlg->ClientSocket,(char *)&buf,sizeof(int),0,60,NULL,false);
- if (processlen>0)
- {
- std::vector<PROCESSINFO *> pProcInfo;
- PROCESSINFO *tmp = new PROCESSINFO; //一样的问题
- //
- for(int i=0;i<buf;i++)
- {
- tmp = new PROCESSINFO;
- memset(tmp, 0,sizeof(PROCESSINFO));
- m_tcptran.myrecv(m_procmanagedlg->ClientSocket,(char *)tmp,sizeof(PROCESSINFO),0,60,0,false);
- pProcInfo.push_back(tmp);
- //delete tmp;
- }
- InitList(pProcInfo);
- }
- }