www.pudn.com > SnifferPro.rar > StcView.cpp


// StcView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "SnifferPro.h" 
#include "StcView.h" 
#include "MainFrm.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CStcView 
 
IMPLEMENT_DYNCREATE(CStcView, CFormView) 
 
CStcView::CStcView() 
	: CFormView(CStcView::IDD) 
{ 
	//{{AFX_DATA_INIT(CStcView) 
	buf=NULL; 
	buflen=0; 
	isReassembly=FALSE; 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
CStcView::~CStcView() 
{ 
} 
 
void CStcView::DoDataExchange(CDataExchange* pDX) 
{ 
	CFormView::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStcView) 
	DDX_Control(pDX, IDC_STC_LIST, m_list); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CStcView, CFormView) 
	//{{AFX_MSG_MAP(CStcView) 
	ON_MESSAGE(WM_MESSAGE_PACKET_SELECT,OnPacketSelect) 
	ON_MESSAGE(WM_MESSAGE_PACKET_SPECIFY,OnPacketSpecify) 
	ON_MESSAGE(WM_MESSAGE_PACKET_REASSEMBLY,OnPacketReassembly) 
	ON_COMMAND(ID_FILE_REASSEMBLY, OnFileReassembly) 
	ON_UPDATE_COMMAND_UI(ID_FILE_REASSEMBLY, OnUpdateFileReassembly) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStcView diagnostics 
 
#ifdef _DEBUG 
void CStcView::AssertValid() const 
{ 
	CFormView::AssertValid(); 
} 
 
void CStcView::Dump(CDumpContext& dc) const 
{ 
	CFormView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CStcView message handlers 
 
void CStcView::OnInitialUpdate()  
{ 
	CFormView::OnInitialUpdate(); 
	((CMainFrame *)AfxGetApp()->GetMainWnd())->stcView=this; 
	// TODO: Add your specialized code here and/or call the base class 
	CListCtrl &ctrl=this->m_list; 
	//初始化 
	DWORD log = GetWindowLong(ctrl.GetSafeHwnd(),GWL_STYLE); 
	log |= LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS; 
	SetWindowLong(ctrl.GetSafeHwnd(),GWL_STYLE,log); 
	ctrl.InsertColumn(0,"Address",LVCFMT_LEFT,60); 
	ctrl.InsertColumn(1,"0",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(2,"1",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(3,"2",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(4,"3",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(5,"4",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(6,"5",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(7,"6",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(8,"7",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(9,"8",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(10,"9",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(11,"A",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(12,"B",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(13,"C",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(14,"D",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(15,"E",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(16,"F",LVCFMT_LEFT,30); 
	ctrl.InsertColumn(17,"Context",LVCFMT_LEFT,150); 
} 
 
 
 
 
 
void CStcView::OnPacketSelect(const struct pcap_pkthdr *pkt_header,const u_char *pkt_data) 
{ 
	//清空上次内容 
	if(buf!=NULL){ 
		delete[] buf; 
		buf=NULL; 
		buflen=0; 
	} 
	int len;//总长(字节) 
	int indexRow;//当前行号 
	int indexColumn;//当前列号 
	int nRow;//总行数 
	int nColumn;//总列数 
	int current;//当前位置 
	int type;//类型:IP,ARP,RARP 
	char strAddr[5];//每行字节起始地址 
	char strByte[3];//每个字节的十六进制表示 
	char strContext[20];//每16个字节作为字符串输出 
	unsigned char *pos;//指向当前位置 
 
	//Init  
	CListCtrl &ctrl=this->m_list; 
	this->isReassembly=FALSE; 
 
	pos=(unsigned char *)(pkt_data+12); 
	type=(*pos)*0x100+(*(pos+1)); 
	if(type==0x0800){//IP 
		pos=(unsigned char *)(pkt_data+16); 
		len=(*pos)*0x100+(*(pos+1))+14; 
	} 
	else{//ARP of RARP 
		len=28+14; 
	} 
 
	buf=new unsigned char[len]; 
	memcpy(buf,pkt_data,len); 
	buflen=len; 
 
	nRow=len/16; 
	if(len%16>0) 
		nRow++; 
	nColumn=18; 
	//Init Column Position 
	ctrl.DeleteAllItems(); 
	m_list.totallen=buflen; 
	m_list.index=0; 
 
	for(indexRow=0,current=0;indexRowisReassembly){ 
		MessageBox("处于重组状态,不予显示报文对应字段!"); 
		return; 
	} 
	//将原来高亮显示内容取消 
	m_list.index=0; 
	indexRow=0; 
	indexColumn=1; 
	for(int i=0;i<(int)buflen;i++){ 
		this->m_list.GetItemText(indexRow,indexColumn,str,10); 
		str[2]='F';//标志位,表示该SubItem不高亮(False) 
		str[3]=0; 
		this->m_list.SetItemText(indexRow,indexColumn,str); 
		if(indexColumn==16){//列号超16则进入下一行,列号回0,行号加1 
			indexColumn=1; 
			indexRow++; 
		} 
		else 
			indexColumn++; 
	} 
	//设置新的高亮内容 
	indexRow=start/16; 
	indexColumn=start%16+1; 
	for(i=0;im_list.GetItemText(indexRow,indexColumn,str,10); 
		str[2]='T'; 
		str[3]=0; 
		this->m_list.SetItemText(indexRow,indexColumn,str); 
		if(indexColumn==16){//列号超16则进入下一行,列号回0,行号加1 
			indexColumn=1; 
			indexRow++; 
		} 
		else 
			indexColumn++; 
	} 
} 
 
 
void CStcView::OnFileReassembly()  
{ 
	// TODO: Add your command handler code here 
 
} 
 
void CStcView::OnUpdateFileReassembly(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	 
} 
 
 
 
void CStcView::OnPacketReassembly() 
{ 
//清空上次内容 
	if(buf!=NULL){ 
		delete[] buf; 
		buf=NULL; 
		buflen=0; 
	} 
	int indexRow;//当前行号 
	int indexColumn;//当前列号 
	int nRow;//总行数 
	int nColumn;//总列数 
	int current;//当前位置 
	int count;//定位器数量 
	char strAddr[5];//每行字节起始地址 
	char strByte[3];//每个字节的十六进制表示 
	char strContext[20];//每16个字节作为字符串输出	 
	int total=0; 
	unsigned char *pos; 
	int index=0; 
	CMyListCtrl &ctrl=this->m_list; 
 
	this->isReassembly=TRUE; 
 
	count=((CMainFrame *)AfxGetApp()->GetMainWnd())->founders.GetSize(); 
	for(int i=0;iGetMainWnd())->founders.GetAt(i).len; 
	} 
	buf=new unsigned char[total]; 
	buflen=total; 
	m_list.totallen=buflen; 
	m_list.index=0; 
	for(i=0;iGetMainWnd())->founders.GetAt(i).index; 
		int len=((CMainFrame *)AfxGetApp()->GetMainWnd())->founders.GetAt(i).len; 
		int start=((CMainFrame *)AfxGetApp()->GetMainWnd())->founders.GetAt(i).start; 
		memcpy(buf+index,(unsigned char *)(((CMainFrame *)AfxGetApp()->GetMainWnd())->mulPackView->pkt_datas.GetAt(position)+start),len); 
		index+=len; 
	} 
 
	nRow=total/16; 
	if(total%16>0) 
		nRow++; 
	nColumn=18; 
	//Init Column Position 
	if(total<102400){//total<100K 
	ctrl.DeleteAllItems(); 
	for(indexRow=0,current=0;indexRow