Przeglądaj źródła

NetBios: PositiveNameQueryResponse: Added read constructor

Tal Aloni 5 lat temu
rodzic
commit
254e78a969

+ 14 - 0
SMBLibrary/NetBios/NameServicePackets/PositiveNameQueryResponse.cs

@@ -21,6 +21,7 @@ namespace SMBLibrary.NetBios
 
         public NameServicePacketHeader Header;
         public ResourceRecord Resource;
+        // Resource Data:
         public KeyValuePairList<byte[], NameFlags> Addresses = new KeyValuePairList<byte[], NameFlags>();
 
         public PositiveNameQueryResponse()
@@ -32,6 +33,19 @@ namespace SMBLibrary.NetBios
             Resource = new ResourceRecord(NameRecordType.NB);
         }
 
+        public PositiveNameQueryResponse(byte[] buffer, int offset)
+        {
+            Header = new NameServicePacketHeader(buffer, ref offset);
+            Resource = new ResourceRecord(buffer, ref offset);
+            int position = 0;
+            while (position < Resource.Data.Length)
+            {
+                NameFlags nameFlags = (NameFlags)BigEndianReader.ReadUInt16(Resource.Data, ref position);
+                byte[] address = ByteReader.ReadBytes(Resource.Data, ref position, 4);
+                Addresses.Add(address, nameFlags);
+            }
+        }
+
         public byte[] GetBytes()
         {
             Resource.Data = GetData();