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


// ContentView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "snifferpro.h" 
#include "ContentView.h" 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CContentView 
 
IMPLEMENT_DYNCREATE(CContentView, CListView) 
 
CContentView::CContentView() 
{ 
	buf=NULL; 
	buflen=0; 
} 
 
CContentView::~CContentView() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CContentView, CListView) 
	//{{AFX_MSG_MAP(CContentView) 
	ON_MESSAGE(WM_MESSAGE_PACKET_SPECIFY,OnPacketSpecify) 
	ON_MESSAGE(WM_MESSAGE_PACKET_SELECT,OnPacketSelect) 
	ON_MESSAGE(WM_MESSAGE_PACKET_REASSEMBLY,OnPacketReassembly) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CContentView drawing 
 
void CContentView::OnDraw(CDC* pDC) 
{ 
	CDocument* pDoc = GetDocument(); 
	// TODO: add draw code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CContentView diagnostics 
 
#ifdef _DEBUG 
void CContentView::AssertValid() const 
{ 
	CListView::AssertValid(); 
} 
 
void CContentView::Dump(CDumpContext& dc) const 
{ 
	CListView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CContentView message handlers 
 
void CContentView::OnInitialUpdate()  
{ 
	CListView::OnInitialUpdate(); 
	 
	// TODO: Add your specialized code here and/or call the base class 
	((CMainFrame *)AfxGetApp()->GetMainWnd())->conView=this; 
	CListCtrl &ctrl=this->GetListCtrl(); 
 
	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 CContentView::OnPacketSelect(const struct pcap_pkthdr *pkt_header,const u_char *pkt_data) 
{ 
	if(buf!=NULL){ 
		delete[] buf; 
		buf=NULL; 
		buflen=0; 
	} 
	int len=pkt_header->len; 
	int indexRow; 
	int indexColumn; 
	int nRow; 
	int nColumn; 
	int current; 
	char strAddr[5]; 
	char strByte[4]; 
	char strContext[20]; 
	unsigned char *pos; 
	//unsigned char *buf; 
	CListCtrl &ctrl=this->GetListCtrl(); 
  
	 
	buf=new unsigned char[pkt_header->len]; 
	memcpy(buf,pkt_data,pkt_header->len); 
	buflen=pkt_header->len; 
 
	nRow=len/16; 
	if(len%16>0) 
		nRow++; 
	nColumn=18; 
	//Init Column Position 
	ctrl.DeleteAllItems(); 
	for(indexRow=0,current=0;indexRowGetListCtrl(); 
	char str[10]; 
	sprintf(str,"%d,%d",start,len); 
	MessageBox(str); 
	indexRow=start/16; 
	indexColumn=start%16+1; 
	//BOOL SetItemState( int nItem, LVITEM* pItem );  
	UINT mask=ctrl.GetItemState(indexRow,LVIS_SELECTED); 
	ctrl.SetItemState(indexRow,LVIS_SELECTED,mask); 
} 
 
void CContentView::OnPacketReassembly() 
{ 
	if(buf!=NULL){ 
		delete[] buf; 
		buf=NULL; 
		buflen=0; 
	} 
	 
	int count=((CMainFrame *)AfxGetApp()->GetMainWnd())->founders.GetSize(); 
	int total=0; 
	//unsigned char *buf; 
	unsigned char *pos; 
	int index=0; 
	int indexRow; 
	int indexColumn; 
	int nRow; 
	int nColumn; 
	int current; 
	char strAddr[5]; 
	char strByte[3]; 
	char strContext[20]; 
	CListCtrl &ctrl=this->GetListCtrl(); 
 
 
	for(int i=0;iGetMainWnd())->founders.GetAt(i).len; 
	} 
	buf=new unsigned char[total]; 
	buflen=total; 
	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