Browse Source

SMB_COM_OPEN_ANDX request and response: Implemented client related functionality

Tal Aloni 7 years ago
parent
commit
7159909bc9

+ 28 - 4
SMBLibrary/SMB1/Commands/OpenAndXRequest.cs

@@ -18,9 +18,9 @@ namespace SMBLibrary.SMB1
     {
         public const int ParametersLength = 30;
         // Parameters:
-        //CommandName AndXCommand;
-        //byte AndXReserved;
-        //ushort AndXOffset;
+        // CommandName AndXCommand;
+        // byte AndXReserved;
+        // ushort AndXOffset;
         public OpenFlags Flags;
         public AccessModeOptions AccessMode;
         public SMBFileAttributes SearchAttrs;
@@ -60,7 +60,31 @@ namespace SMBLibrary.SMB1
 
         public override byte[] GetBytes(bool isUnicode)
         {
-            throw new NotImplementedException();
+            this.SMBParameters = new byte[ParametersLength];
+            int parametersOffset = 4;
+            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)Flags);
+            AccessMode.WriteBytes(this.SMBParameters, ref parametersOffset);
+            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)SearchAttrs);
+            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)FileAttrs);
+            UTimeHelper.WriteUTime(this.SMBParameters, ref parametersOffset, CreationTime);
+            OpenMode.WriteBytes(this.SMBParameters, ref parametersOffset);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, AllocationSize);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, Timeout);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, Reserved);
+
+            int padding = 0;
+            if (isUnicode)
+            {
+                padding = 1;
+                this.SMBData = new byte[padding + FileName.Length * 2 + 2];
+            }
+            else
+            {
+                this.SMBData = new byte[FileName.Length + 1];
+            }
+            SMB1Helper.WriteSMBString(this.SMBData, padding, isUnicode, FileName);
+
+            return base.GetBytes(isUnicode);
         }
 
         public override CommandName CommandName

+ 13 - 4
SMBLibrary/SMB1/Commands/OpenAndXResponse.cs

@@ -18,9 +18,9 @@ namespace SMBLibrary.SMB1
     {
         public const int ParametersLength = 30;
         // Parameters:
-        //CommandName AndXCommand;
-        //byte AndXReserved;
-        //ushort AndXOffset;
+        // CommandName AndXCommand;
+        // byte AndXReserved;
+        // ushort AndXOffset;
         public ushort FID;
         public SMBFileAttributes FileAttrs;
         public DateTime? LastWriteTime; // UTime
@@ -38,7 +38,16 @@ namespace SMBLibrary.SMB1
 
         public OpenAndXResponse(byte[] buffer, int offset) : base(buffer, offset, false)
         {
-            throw new NotImplementedException();
+            int parametersOffset = 4;
+            FID = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
+            FileAttrs = (SMBFileAttributes)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
+            LastWriteTime = UTimeHelper.ReadNullableUTime(this.SMBParameters, ref parametersOffset);
+            FileDataSize = LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
+            AccessRights = (AccessRights)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
+            ResourceType = (ResourceType)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
+            NMPipeStatus = NamedPipeStatus.Read(this.SMBParameters, ref parametersOffset);
+            OpenResults = OpenResults.Read(this.SMBParameters, ref parametersOffset);
+            Reserved = ByteReader.ReadBytes(this.SMBParameters, ref parametersOffset, 6);
         }
 
         public override byte[] GetBytes(bool isUnicode)

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

@@ -305,11 +305,11 @@ namespace SMBLibrary.SMB1
                     {
                         if (wordCount * 2 == OpenAndXResponse.ParametersLength)
                         {
-                            throw new NotImplementedException();
+                            return new OpenAndXResponse(buffer, offset);
                         }
                         else if (wordCount * 2 == OpenAndXResponseExtended.ParametersLength)
                         {
-                            throw new NotImplementedException();
+                            return new OpenAndXResponseExtended(buffer, offset);
                         }
                         else if (wordCount == 0)
                         {