瀏覽代碼

NetBIOS: Minor code refactoring

Tal Aloni 5 年之前
父節點
當前提交
71e2e4096f

+ 2 - 4
SMBLibrary/NetBios/NBTConnectionReceiveBuffer.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  * 
  * You can redistribute this program and/or modify it under the terms of
  * the GNU Lesser Public License as published by the Free Software Foundation,
@@ -43,9 +43,7 @@ namespace SMBLibrary.NetBios
             {
                 if (!m_packetLength.HasValue)
                 {
-                    byte flags = ByteReader.ReadByte(m_buffer, m_readOffset + 1);
-                    int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(m_buffer, m_readOffset + 2);
-                    m_packetLength = 4 + trailerLength;
+                    m_packetLength = SessionPacket.GetSessionPacketLength(m_buffer, m_readOffset);
                 }
                 return m_bytesInBuffer >= m_packetLength.Value;
             }

+ 7 - 0
SMBLibrary/NetBios/SessionPackets/SessionPacket.cs

@@ -63,6 +63,13 @@ namespace SMBLibrary.NetBios
             }
         }
 
+        public static int GetSessionPacketLength(byte[] buffer, int offset)
+        {
+            byte flags = ByteReader.ReadByte(buffer, offset + 1);
+            int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(buffer, offset + 2);
+            return 4 + trailerLength;
+        }
+
         public static SessionPacket GetSessionPacket(byte[] buffer, int offset)
         {
             SessionPacketTypeName type = (SessionPacketTypeName)ByteReader.ReadByte(buffer, offset);