⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sinpackview.cpp

📁 这是一个嗅探器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		HTREEITEM arphdwaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strarphdwaddrlen,macdata);
		HTREEITEM arpprtaddrlen=ctrl.InsertItem("Protocol Address Length:  "+strarpprtaddrlen,macdata);
		HTREEITEM arptype=ctrl.InsertItem("Operation Type:  "+arp->GetOperation(),macdata);
		HTREEITEM arpsrchdwaddr=ctrl.InsertItem("Source Hardware Address:  "+arp->GetSrcHdwAddr(),macdata);
		HTREEITEM arpsrcprtaddr=ctrl.InsertItem("Source Protocol Address:  "+arp->GetSrcPrtAddr(),macdata);
		HTREEITEM arpdesthdwaddr=ctrl.InsertItem("Destination Hardware Address:  "+arp->GetDestHdwAddr(),macdata);
		HTREEITEM arpdestprtaddr=ctrl.InsertItem("Destination Protocol Address:  "+arp->GetDestPrtAddr(),macdata);
	}//Init for ARP

	//Init for RARP
	else if(ether->type==0x8035){
		rarp=new RARPGram(pkt_data+14,pkt_header->len-14);
		CString strrarphdwtype;
		CString strrarpprttype;
		CString strrarphdwaddrlen;
		CString strrarpprtaddrlen;
		strrarphdwtype.Format("%u",rarp->hdwaddrtype);
		strrarpprttype.Format("%u",rarp->prtaddrtype);
		strrarphdwaddrlen.Format("%u",rarp->hdwaddrlen);
		strrarpprtaddrlen.Format("%u",rarp->prtaddrlen);
		HTREEITEM rarphdwtype=ctrl.InsertItem("Hardware Address Type:  "+strrarphdwtype,macdata);
		HTREEITEM rarpprttype=ctrl.InsertItem("Protocol Address Type:  "+strrarpprttype+"  "+arp->GetPrtType(),macdata);
		HTREEITEM rarphdwaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strrarphdwaddrlen,macdata);
		HTREEITEM rarpprtaddrlen=ctrl.InsertItem("Hardware Address Length:  "+strrarpprtaddrlen,macdata);
		HTREEITEM rarptype=ctrl.InsertItem("Hardware Address Type:  "+rarp->GetOperation(),macdata);
		HTREEITEM rarpsrchdwaddr=ctrl.InsertItem("Source Hardware Address:  "+rarp->GetSrcHdwAddr(),macdata);
		HTREEITEM rarpsrcprtaddr=ctrl.InsertItem("Source Protocol Address:  "+rarp->GetSrcPrtAddr(),macdata);
		HTREEITEM rarpdesthdwaddr=ctrl.InsertItem("Destination Hardware Address:  "+rarp->GetDestHdwAddr(),macdata);
		HTREEITEM rarpdestprtaddr=ctrl.InsertItem("Destination Protocol Address:  "+rarp->GetDestPrtAddr(),macdata);
	}//Init for RARP
	ctrl.Expand(macdata,TVE_EXPAND);
	ctrl.SetScrollPos(SB_VERT,0);
}

void CSinPackView::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
}

Founder CSinPackView::GetFounder(CString name)
{
	Founder founder;
	founder.start=0;
	founder.len=0;

	//MAC
	if(name.Find("Mac Source",0)>=0){//根据所选的字段名,进行定位,以便通知CStcView显示,下同
		founder.start=6;//表示从跳过报文的前6个字节,然后开始,共6字节
		founder.len=6;
		return founder;
	}
	else if(name.Find("Mac Destination",0)>=0){
		founder.start=0;
		founder.len=6;
		return founder;
	}
	else if(name.Find("Mac Frame Type",0)>=0){
		founder.start=12;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Mac Data",0)>=0){
		founder.start=14;
		if(ether->type==0x0800)
			founder.len=ip->datalen+ip->IHL*4;
		else
			founder.len=28;
		return founder;
	}
	//IP
	else if(name.Find("IP Version",0)>=0){
		founder.start=14;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Length of IP Head",0)>=0){
		founder.start=14;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Service Type",0)>=0){
		founder.start=15;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Total Length",0)>=0){
		founder.start=16;
		founder.len=2;
		return founder;
	}
	else if(name.Find("IP Identification",0)>=0){
		founder.start=18;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Precedence")>=0){
		founder.start=15;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Delay")>=0){
		founder.start=15;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Throughtput")>=0){
		founder.start=15;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Reliability")>=0){
		founder.start=15;
		founder.len=1;
		return founder;
	}
	else if(name.Find("DF",0)>=0){
		founder.start=20;
		founder.len=1;
	}
	else if(name.Find("MF",0)>=0){
		founder.start=20;
		founder.len=1;
	}
	else if(name.Find("Fragment Offset",0)>=0){
		founder.start=20;
		founder.len=2;
	}
	else if(name.Find("Time to Live",0)>=0){
		founder.start=22;
		founder.len=1;
	}
	else if(name.Find("IP Protocol",0)>=0){
		founder.start=23;
		founder.len=1;
	}
	else if(name.Find("IP Header Check Sum",0)>=0){
		founder.start=24;
		founder.len=2;
	}
	else if(name.Find("IP Source",0)>=0){
		founder.start=26;
		founder.len=4;
		return founder;
	}
	else if(name.Find("IP Destination",0)>=0){
		founder.start=30;
		founder.len=4;
		return founder;
	}
	else if(name.Find("IP Options",0)>=0){
		founder.start=14+20;
		founder.len=ip->optlen;
		return founder;
	}
	else if(name.Find("IP Data",0)>=0){
		founder.start=14+ip->IHL*4;
		founder.len=ip->datalen;
		return founder;
	}
	//TCP
	else if(name.Find("TCP Source",0)>=0){
		founder.start=14+ip->IHL*4;
		founder.len=2;
		return founder;
	}
	else if(name.Find("TCP Destination",0)>=0){
		founder.start=14+ip->IHL*4+2;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Sequence",0)>=0){
		founder.start=14+ip->IHL*4+4;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Acknowledgement",0)>=0){
		founder.start=14+ip->IHL*4+8;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Length of TCP Head",0)>=0){
		founder.start=14+ip->IHL*4+12;
		founder.len=1;
		return founder;
	}
	else if(name.Find("TCP Flags",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("URG",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("ACK",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("PSH",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("RST",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("SYN",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("FIN",0)>=0){
		founder.start=14+ip->IHL*4+13;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Window Size",0)>=0){
		founder.start=14+ip->IHL*4+14;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Urgent Pointer",0)>=0){
		founder.start=14+ip->IHL*4+18;
		founder.len=2;
		return founder;
	}
	else if(name.Find("TCP Header Check Sum",0)>=0){
		founder.start=14+ip->IHL*4+16;
		founder.len=2;
		return founder;
	}
	else if(name.Find("TCP Options",0)>=0){
		founder.start=14+ip->IHL*4+20;
		founder.len=tcp->optlen;
		return founder;
	}
	else if(name.Find("TCP Data",0)>=0){
		founder.start=14+ip->IHL*4+tcp->headlen*4;
		founder.len=tcp->datalen;
		return founder;
	}
	//UDP
	else if(name.Find("UDP Source",0)>=0){
		founder.start=14+ip->IHL*4;
		founder.len=2;
		return founder;
	}
	else if(name.Find("UDP Destination",0)>=0){
		founder.start=14+ip->IHL*4+2;
		founder.len=2;
		return founder;
	}
	else if(name.Find("UDP Length",0)>=0){
		founder.start=14+ip->IHL*4+4;
		founder.len=2;
		return founder;
	}
	else if(name.Find("UDP Header Check Sum",0)>=0){
		founder.start=14+ip->IHL*4+6;
		founder.len=2;
		return founder;
	}
	else if(name.Find("UDP Data",0)>=0){
		founder.start=14+ip->IHL*4+8;
		founder.len=udp->datalen;
		return founder;
	}
	//ICMP
	else if(name.Find("ICMP Type",0)>=0){
		founder.start=14+ip->IHL*4;
		founder.len=1;
		return founder;
	}
	else if(name.Find("ICMP Code",0)>=0){
		founder.start=14+ip->IHL*4+1;
		founder.len=1;
		return founder;
	}
	else if(name.Find("ICMP Check Sum",0)>=0){
		founder.start=14+ip->IHL*4+2;
		founder.len=2;
		return founder;
	}
	else if(name.Find("ICMP Identification",0)>=0){
		founder.start=14+ip->IHL*4+4;
		founder.len=2;
		return founder;
	}
	else if(name.Find("ICMP Sequence",0)>=0){
		founder.start=14+ip->IHL*4+6;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Initial Time",0)>=0){
		founder.start=14+ip->IHL*4+8;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Receiving Time",0)>=0){
		founder.start=14+ip->IHL*4+12;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Sending Time",0)>=0){
		founder.start=14+ip->IHL*4+16;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Address Mask",0)>=0){
		founder.start=14+ip->IHL*4+8;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Gateway",0)>=0){
		founder.start=14+ip->IHL*4+4;
		founder.len=4;
		return founder;
	}
	else if(name.Find("ICMP Data",0)>=0){
		founder.start=14+ip->IHL*4+4;
		founder.len=icmp->datalen;
		return founder;
	}
	//ARP or RARP
	else if(name.Find("Hardware Address Type",0)>=0){
		founder.start=14;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Protocol Address Type",0)>=0){
		founder.start=14+2;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Hardware Address Length",0)>=0){
		founder.start=14+4;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Protocol Address Length",0)>=0){
		founder.start=14+5;
		founder.len=1;
		return founder;
	}
	else if(name.Find("Operation",0)>=0){
		founder.start=14+6;
		founder.len=2;
		return founder;
	}
	else if(name.Find("Source Hardware Address",0)>=0){
		founder.start=14+8;
		founder.len=6;
		return founder;
	}
	else if(name.Find("Source Protocol Address",0)>=0){
		founder.start=14+14;
		founder.len=4;
		return founder;
	}
	else if(name.Find("Destination Hardware Address",0)>=0){
		founder.start=14+18;
		founder.len=6;
		return founder;
	}
	else if(name.Find("Destination Protocol Address",0)>=0){
		founder.start=14+24;
		founder.len=4;
		return founder;
	}

	return founder;
}


void CSinPackView::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CTreeCtrl &ctrl=this->GetTreeCtrl();
	HTREEITEM h=pNMTreeView->itemNew.hItem;
	CString name=ctrl.GetItemText(h);
	Founder founder=this->GetFounder(name);
	unsigned int start,len;	
	start=founder.start;
	len=founder.len;
	::PostMessage(*((CMainFrame *)AfxGetApp()->GetMainWnd())->stcView,WM_MESSAGE_PACKET_SPECIFY,(WPARAM)start,(LPARAM)len);
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -