Example #1
0
 public static void WriteCreateContextList(byte[] buffer, int offset, List <CreateContext> createContexts)
 {
     for (int index = 0; index < createContexts.Count; index++)
     {
         CreateContext createContext = createContexts[index];
         int           length        = createContext.Length;
         int           paddedLength  = (int)Math.Ceiling((double)length / 8) * 8;
         if (index < createContexts.Count - 1)
         {
             createContext.Next = (uint)paddedLength;
         }
         else
         {
             createContext.Next = 0;
         }
         createContext.WriteBytes(buffer, offset);
         offset += paddedLength;
     }
 }
Example #2
0
        public static int GetCreateContextListLength(List <CreateContext> createContexts)
        {
            int result = 0;

            for (int index = 0; index < createContexts.Count; index++)
            {
                CreateContext createContext = createContexts[index];
                int           length        = createContext.Length;
                if (index < createContexts.Count - 1)
                {
                    int paddedLength = (int)Math.Ceiling((double)length / 8) * 8;
                    result += paddedLength;
                }
                else
                {
                    result += length;
                }
            }
            return(result);
        }
Example #3
0
 public CreateResponse(byte[] buffer, int offset) : base(buffer, offset)
 {
     StructureSize         = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
     OplockLevel           = (OplockLevel)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2);
     Flags                 = (CreateResponseFlags)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
     CreateAction          = (CreateAction)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
     CreationTime          = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 8);
     LastAccessTime        = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 16);
     LastWriteTime         = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 24);
     ChangeTime            = FileTimeHelper.ReadNullableFileTime(buffer, offset + SMB2Header.Length + 32);
     AllocationSize        = LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 40);
     EndofFile             = LittleEndianConverter.ToInt64(buffer, offset + SMB2Header.Length + 48);
     FileAttributes        = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 56);
     Reserved2             = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 60);
     FileId                = new FileID(buffer, offset + SMB2Header.Length + 64);
     CreateContextsOffsets = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 80);
     CreateContextsLength  = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 84);
     if (CreateContextsLength > 0)
     {
         CreateContexts = CreateContext.ReadCreateContextList(buffer, offset + (int)CreateContextsOffsets);
     }
 }
Example #4
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     ByteWriter.WriteByte(buffer, offset + 2, (byte)OplockLevel);
     ByteWriter.WriteByte(buffer, offset + 3, (byte)Flags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)CreateAction);
     FileTimeHelper.WriteFileTime(buffer, offset + 8, CreationTime);
     FileTimeHelper.WriteFileTime(buffer, offset + 16, LastAccessTime);
     FileTimeHelper.WriteFileTime(buffer, offset + 24, LastWriteTime);
     FileTimeHelper.WriteFileTime(buffer, offset + 32, ChangeTime);
     LittleEndianWriter.WriteInt64(buffer, offset + 40, AllocationSize);
     LittleEndianWriter.WriteInt64(buffer, offset + 48, EndofFile);
     LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes);
     LittleEndianWriter.WriteUInt32(buffer, offset + 60, Reserved2);
     FileId.WriteBytes(buffer, offset + 64);
     CreateContextsOffsets = 0;
     CreateContextsLength  = (uint)CreateContext.GetCreateContextListLength(CreateContexts);
     if (CreateContexts.Count > 0)
     {
         CreateContextsOffsets = SMB2Header.Length + 88;
         CreateContext.WriteCreateContextList(buffer, 88, CreateContexts);
     }
 }
Example #5
0
 public CreateRequest(byte[] buffer, int offset) : base(buffer, offset)
 {
     StructureSize        = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
     SecurityFlags        = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 2);
     RequestedOplockLevel = (OplockLevel)ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
     ImpersonationLevel   = (ImpersonationLevel)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
     SmbCreateFlags       = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 8);
     Reserved             = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 16);
     DesiredAccess        = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 24);
     FileAttributes       = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 28);
     ShareAccess          = (ShareAccess)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 32);
     CreateDisposition    = (CreateDisposition)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 36);
     CreateOptions        = (CreateOptions)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 40);
     NameOffset           = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 44);
     NameLength           = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 46);
     CreateContextsOffset = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 48);
     CreateContextsLength = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 52);
     Name = ByteReader.ReadUTF16String(buffer, offset + NameOffset, NameLength / 2);
     if (CreateContextsLength > 0)
     {
         CreateContexts = CreateContext.ReadCreateContextList(buffer, (int)CreateContextsOffset);
     }
 }