Forráskód Böngészése

Improved SMB1Message implementation

Tal Aloni 8 éve
szülő
commit
241eafc732
2 módosított fájl, 10 hozzáadás és 15 törlés
  1. 8 13
      SMBLibrary/SMB1/SMB1Message.cs
  2. 2 2
      SMBLibrary/Server/SMBServer.cs

+ 8 - 13
SMBLibrary/SMB1/SMB1Message.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2017 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,
@@ -95,24 +95,19 @@ namespace SMBLibrary.SMB1
             return buffer;
         }
 
-        public static bool IsValidSMBMessage(byte[] buffer)
+        public static bool IsValidSMB1Message(byte[] buffer)
         {
-            if (buffer[0] == SMB1Header.ProtocolSignature[0] &&
-                buffer[1] == SMB1Header.ProtocolSignature[1] &&
-                buffer[2] == SMB1Header.ProtocolSignature[2] &&
-                buffer[3] == SMB1Header.ProtocolSignature[3])
+            if (buffer.Length >= 4)
             {
-                return true;
-            }
-            else
-            {
-                return false;
+                byte[] signature = ByteReader.ReadBytes(buffer, 0, 4);
+                return ByteUtils.AreByteArraysEqual(signature, SMB1Header.ProtocolSignature);
             }
+            return false;
         }
 
-        public static SMB1Message GetSMBMessage(byte[] buffer)
+        public static SMB1Message GetSMB1Message(byte[] buffer)
         {
-            if (!IsValidSMBMessage(buffer))
+            if (!IsValidSMB1Message(buffer))
             {
                 throw new InvalidRequestException("Invalid SMB message signature");;
             }

+ 2 - 2
SMBLibrary/Server/SMBServer.cs

@@ -202,12 +202,12 @@ namespace SMBLibrary.Server
             {
                 SMB1Message message = null;
 #if DEBUG
-                message = SMB1Message.GetSMBMessage(packet.Trailer);
+                message = SMB1Message.GetSMB1Message(packet.Trailer);
                 System.Diagnostics.Debug.Print("[{0}] Message Received: {1} Commands, First Command: {2}, Packet length: {3}", DateTime.Now.ToString("HH:mm:ss:ffff"), message.Commands.Count, message.Commands[0].CommandName.ToString(), packet.Length);
 #else
                 try
                 {
-                    message = SMB1Message.GetSMBMessage(packet.Trailer);
+                    message = SMB1Message.GetSMB1Message(packet.Trailer);
                 }
                 catch (Exception)
                 {