Browse Source

SMB1: Minor implementation improvements

Tal Aloni 7 years ago
parent
commit
b3445530ac

+ 2 - 2
SMBLibrary/SMB1/Commands/SessionSetupAndXRequestExtended.cs

@@ -27,8 +27,8 @@ namespace SMBLibrary.SMB1
         public ServerCapabilities Capabilities;
         // Data:
         public byte[] SecurityBlob;
-        public string NativeOS;     // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
-        public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeOS = String.Empty;     // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeLanMan = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
 
         public SessionSetupAndXRequestExtended(): base()
         {

+ 7 - 4
SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs

@@ -11,6 +11,9 @@ using Utilities;
 
 namespace SMBLibrary.SMB1
 {
+    /// <summary>
+    /// SMB_COM_SESSION_SETUP_ANDX Response
+    /// </summary>
     public class SessionSetupAndXResponse : SMBAndXCommand
     {
         public const int ParametersLength = 6;
@@ -20,9 +23,9 @@ namespace SMBLibrary.SMB1
         //ushort AndXOffset;
         public SessionSetupAction Action;
         // Data:
-        public string NativeOS;      // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
-        public string NativeLanMan;  // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
-        public string PrimaryDomain; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeOS = String.Empty;      // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeLanMan = String.Empty;  // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string PrimaryDomain = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
 
         public SessionSetupAndXResponse() : base()
         {
@@ -62,7 +65,7 @@ namespace SMBLibrary.SMB1
             {
                 this.SMBData = new byte[NativeOS.Length + NativeLanMan.Length + PrimaryDomain.Length + 3];
             }
-            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode,  NativeOS);
+            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS);
             SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan);
             SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain);
 

+ 5 - 4
SMBLibrary/SMB1/Commands/SessionSetupAndXResponseExtended.cs

@@ -11,6 +11,9 @@ using Utilities;
 
 namespace SMBLibrary.SMB1
 {
+    /// <summary>
+    /// SMB_COM_SESSION_SETUP_ANDX Response, NT LAN Manager dialect, Extended Security response
+    /// </summary>
     public class SessionSetupAndXResponseExtended : SMBAndXCommand
     {
         public const int ParametersLength = 8;
@@ -22,14 +25,12 @@ namespace SMBLibrary.SMB1
         private ushort SecurityBlobLength;
         // Data:
         public byte[] SecurityBlob;
-        public string NativeOS;     // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
-        public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeOS = String.Empty;     // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
+        public string NativeLanMan = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
 
         public SessionSetupAndXResponseExtended() : base()
         {
             SecurityBlob = new byte[0];
-            NativeOS = String.Empty;
-            NativeLanMan = String.Empty;
         }
 
         public SessionSetupAndXResponseExtended(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)

+ 1 - 1
SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs

@@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1
     /// </summary>
     public class WriteRawFinalResponse : SMB1Command
     {
-        public ushort ParametersLength = 2;
+        public const ushort ParametersLength = 2;
         // Parameters;
         public ushort Count;
 

+ 1 - 1
SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs

@@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1
     /// </summary>
     public class WriteRawInterimResponse : SMB1Command
     {
-        public ushort ParametersLength = 2;
+        public const ushort ParametersLength = 2;
         // Parameters;
         public ushort Available;
 

+ 11 - 0
SMBLibrary/SMB1/SMB1Header.cs

@@ -114,6 +114,17 @@ namespace SMBLibrary.SMB1
             {
                 return (Flags2 & HeaderFlags2.Unicode) > 0;
             }
+            set
+            {
+                if (value)
+                {
+                    this.Flags2 |= HeaderFlags2.Unicode;
+                }
+                else
+                {
+                    this.Flags2 &= ~HeaderFlags2.Unicode;
+                }
+            }
         }
 
         public static bool IsValidSMB1Header(byte[] buffer)