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

📄 packetnbns.cs

📁 一个抓包工具
💻 CS
📖 第 1 页 / 共 3 页
字号:
						Function.SetPosition( ref mNode3 , Index - 2 , 2 , false );
						mNode3.Nodes.Add( Function.DecodeBitField( PNbns.Additionals.Items[i].Flags , 0x1000 , "Name is being deregistered", "Name is not being deregistered" ) );
						Function.SetPosition( ref mNode3 , Index - 2 , 2 , false );
						mNode3.Nodes.Add( Function.DecodeBitField( PNbns.Additionals.Items[i].Flags , 0x0800 , "Name is in conflict", "Name is not in conflict" ) );
						Function.SetPosition( ref mNode3 , Index - 2 , 2 , false );
						mNode3.Nodes.Add( Function.DecodeBitField( PNbns.Additionals.Items[i].Flags , 0x0400 , "Name is active", "Name is not active" ) );
						Function.SetPosition( ref mNode3 , Index - 2 , 2 , false );
						mNode3.Nodes.Add( Function.DecodeBitField( PNbns.Additionals.Items[i].Flags , 0x0200 , "Permanent node name", "Not permanent node name" ) );
						Function.SetPosition( ref mNode3 , Index - 2 , 2 , false );
						mNode2.Nodes.Add( mNode3 );

						PNbns.Additionals.Items[i].Address = Function.GetIpAddress( PacketData , ref Index );
						Tmp = "Address : " + PNbns.Additionals.Items[i].Address;
						mNode2.Nodes.Add( Tmp );
						Function.SetPosition( ref mNode2 , Index - 4 , 4 , false );

						mNode1.Nodes.Add( mNode2 );
					}

					mNodex.Nodes.Add( mNode1 );
				}


				/*if( PNbns.AuthorityRRS > 0 )
				{
					mNode1 = new TreeNode();
					mNode1.Text = "AUTHORITY RECORDS";

					for( i = 1; i <= PNbns.AuthorityRRS; i ++ )
					{
						mNode2 = new TreeNode();
						mNode2.Text = "Authority Record " + i.ToString();

						Tmp = "Name :" + PNbns.AuthorityObject[i-1].Name;
						mNode2.Nodes.Add( Tmp );

						Tmp = "Type : " + Function.ReFormatString( PNbns.AuthorityObject[i-1].Type , PNbns.AuthorityObject[i-1].TypeStr );
						mNode2.Nodes.Add( Tmp );

						Tmp = "Class : " + Function.ReFormatString( PNbns.AuthorityObject[i-1].Class , PNbns.AuthorityObject[i-1].ClassStr );
						mNode2.Nodes.Add( Tmp );

						mNode1.Nodes.Add( mNode2 );

					}

					mNode.Nodes.Add( mNode1 );
				}*/

				Function.SetPosition( ref mNodex , kk , Index - kk , true );

				LItem.SubItems[ Const.LIST_VIEW_PROTOCOL_INDEX ].Text = "NBNS";
				LItem.SubItems[ Const.LIST_VIEW_INFO_INDEX ].Text = "Netbios name service";

				mNode.Add( mNodex );
				
			}
			catch( Exception Ex )
			{
				mNode.Add( mNodex );
				Tmp = "[ Malformed NBNS packet. Remaining bytes don't fit an NBNS packet. Possibly due to bad decoding ]";
				mNode.Add( Tmp );
				Tmp = "[ Exception raised is <" + Ex.GetType().ToString() + "> at packet index <" + Index.ToString() + "> ]";
				mNode.Add( Tmp );
				LItem.SubItems[ Const.LIST_VIEW_INFO_INDEX ].Text = "[ Malformed NBNS packet. Remaining bytes don't fit an NBNS packet. Possibly due to bad decoding ]";

				return false;
			}

			return true;

		}


		public static bool Parser( byte [] PacketData , 
			ref int Index , 
			ref ListViewItem LItem )
		{
			int i = 0;
			byte NNumber = 0;
			PACKET_NBNS PNbns;
			string [] NBFlagsNodeTypeList = new string[4];
			string [] NameFlagsNodeTypeList = new string[3];
			string [] OpCodeList = new string[16];
			string [] ReplyList = new string[8];

			/*for( i = 0; i < 8; i ++ )
				ReplyList[i] = "Unknown";

			for( i = 0; i < 16; i ++ )
				OpCodeList[i] = "Unknown";

			NBFlagsNodeTypeList[0] = "B-mode node";
			NBFlagsNodeTypeList[1] = "P-mode node";
			NBFlagsNodeTypeList[2] = "M-mode node";
			NBFlagsNodeTypeList[3] = "H-mode node";

			NameFlagsNodeTypeList[Const.NAME_FLAGS_B_NODE] = "B-mode node";
			NameFlagsNodeTypeList[Const.NAME_FLAGS_P_NODE] = "P-mode node";
			NameFlagsNodeTypeList[Const.NAME_FLAGS_M_NODE] = "M-mode node";

			OpCodeList[Const.OPCODE_QUERY] = "Name query";			OpCodeList[Const.OPCODE_REGISTRATION] = "Registration";			OpCodeList[Const.OPCODE_RELEASE] = "Release";			OpCodeList[Const.OPCODE_WACK] = "Wait for acknowledgment";			OpCodeList[Const.OPCODE_REFRESH] = "Refresh";			OpCodeList[Const.OPCODE_REFRESHALT] = "Refresh (alternate opcode)";			OpCodeList[Const.OPCODE_MHREGISTRATION] = "Multi-homed registration";
			ReplyList[Const.RCODE_NOERROR] = "No error";			ReplyList[Const.RCODE_FMTERROR] = "Request was invalidly formatted";			ReplyList[Const.RCODE_SERVFAIL] = "Server failure";			ReplyList[Const.RCODE_NAMEERROR] = "Requested name does not exist";			ReplyList[Const.RCODE_NOTIMPL] = "Request is not implemented";			ReplyList[Const.RCODE_REFUSED] = "Request was refused";			ReplyList[Const.RCODE_ACTIVE] = "Name is owned by another node";			ReplyList[Const.RCODE_CONFLICT] = "Name is in conflict";*/
			try
			{

				PNbns.TransactionId = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				PNbns.Flags = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				PNbns.QuestionRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				PNbns.AnswerRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				PNbns.AuthorityRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
				PNbns.AdditionalRRS = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );

				if( PNbns.QuestionRRS > 0 )
				{
					PNbns.Questions.Items = new QUESTION_ITEM[ PNbns.QuestionRRS ];
					for( i = 0; i < PNbns.QuestionRRS; i ++ )
					{
						PNbns.Questions.Items[i].Name = Function.GetNetBiosName( PacketData , ref Index , ref NNumber );
						PNbns.Questions.Items[i].Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.Questions.Items[i].Class = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );

					}

				}

				if( PNbns.AnswerRRS > 0 )
				{
					PNbns.Answers.Name = Function.GetNetBiosName( PacketData , ref Index , ref NNumber );
					PNbns.Answers.Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.Class = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.TimeToLive = Function.Get4Bytes( PacketData , ref Index , Const.VALUE );
					PNbns.Answers.DataLength = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfNames = PacketData[ Index ++ ];

					if( PNbns.Answers.NumberOfNames > 0 )
					{
						PNbns.Answers.Items = new ANSWER_ITEM[PNbns.Answers.NumberOfNames];

						for( i = 0; i < PNbns.Answers.NumberOfNames; i ++ )
						{
							PNbns.Answers.Items[i].Name = Function.GetNetBiosNameSerial( PacketData , ref Index , ref NNumber );
							PNbns.Answers.Items[i].Name += " ( " + Const.GetNetBiosNames( NNumber ) + " )";
							PNbns.Answers.Items[i].Flags = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						}
					}
					
					PNbns.Answers.UnitId = Function.GetMACAddress( PacketData , ref Index );
					PNbns.Answers.Jumpers = PacketData[ Index ++ ];
					PNbns.Answers.TestResult = PacketData[ Index ++ ];
					PNbns.Answers.VersionNumber = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.PeriodOfStatistics = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.CRCs = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfAlignmentErrors = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfCollisions = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfSendAborts = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfGoodSends = Function.Get4Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfReceives = Function.Get4Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfRetransmits = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfNoResourceConditions = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfCommandBlocks = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.NumberOfPendingSessions = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.MaxNumberOfPendingSessions = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.MaxTotalSessionPossible = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
					PNbns.Answers.SessionDataPacketSize = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );

				}

				if( PNbns.AuthorityRRS > 0 )
				{
					/*PNbns.AuthorityObject = new QUESTION_ITEM[ PNbns.AuthorityRRS ];
					for( i = 0; i < PNbns.AuthorityRRS; i ++ )
					{
						PNbns.AuthorityObject[i].Name = "";
						while( PacketData[ Index ] != 0 )
							PNbns.AuthorityObject[i].Name += (char) PacketData[ Index ++ ];

						Index ++;
						u = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.AuthorityObject[i].Type = u;
						PNbns.AuthorityObject[i].TypeStr = GetTypeString( u );

						u = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.AuthorityObject[i].Class = u;
						PNbns.AuthorityObject[i].ClassStr = GetClassString( u );
					}*/
				}

				if( PNbns.AdditionalRRS > 0 )
				{
					PNbns.Additionals.Items = new ADDITIONAL_ITEM[ PNbns.AdditionalRRS ];
					for( i = 0; i < PNbns.AdditionalRRS; i ++ )
					{
						PNbns.Additionals.Items[i].Name = Function.GetNetBiosName( PacketData , ref Index , ref NNumber );
						PNbns.Additionals.Items[i].Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.Additionals.Items[i].Class = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.Additionals.Items[i].TimeToLive = Function.Get4Bytes( PacketData , ref Index , Const.VALUE );
						PNbns.Additionals.Items[i].DataLength = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.Additionals.Items[i].Flags = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
						PNbns.Additionals.Items[i].Address = Function.GetIpAddress( PacketData , ref Index );
					}

				}


				/*if( PNbns.AuthorityRRS > 0 )
				{
					mNode1 = new TreeNode();
					mNode1.Text = "AUTHORITY RECORDS";

					for( i = 1; i <= PNbns.AuthorityRRS; i ++ )
					{
						mNode2 = new TreeNode();
						mNode2.Text = "Authority Record " + i.ToString();

						Tmp = "Name :" + PNbns.AuthorityObject[i-1].Name;
						mNode2.Nodes.Add( Tmp );

						Tmp = "Type : " + Function.ReFormatString( PNbns.AuthorityObject[i-1].Type , PNbns.AuthorityObject[i-1].TypeStr );
						mNode2.Nodes.Add( Tmp );

						Tmp = "Class : " + Function.ReFormatString( PNbns.AuthorityObject[i-1].Class , PNbns.AuthorityObject[i-1].ClassStr );
						mNode2.Nodes.Add( Tmp );

						mNode1.Nodes.Add( mNode2 );

					}

					mNode.Nodes.Add( mNode1 );
				}*/

				LItem.SubItems[ Const.LIST_VIEW_PROTOCOL_INDEX ].Text = "NBNS";
				LItem.SubItems[ Const.LIST_VIEW_INFO_INDEX ].Text = "Netbios name service";

			}
			catch
			{
				LItem.SubItems[ Const.LIST_VIEW_INFO_INDEX ].Text = "[ Malformed NBNS packet. Remaining bytes don't fit an NBNS packet. Possibly due to bad decoding ]";

				return false;
			}

			return true;

		}

	}
}

⌨️ 快捷键说明

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