Esempio n. 1
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     ReadChannelInfoOffset = 0;
     ReadChannelInfoLength = (ushort)ReadChannelInfo.Length;
     if (ReadChannelInfo.Length > 0)
     {
         ReadChannelInfoOffset = SMB2Header.Length + FixedSize;
     }
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     ByteWriter.WriteByte(buffer, offset + 2, Padding);
     ByteWriter.WriteByte(buffer, offset + 3, (byte)Flags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, ReadLength);
     LittleEndianWriter.WriteUInt64(buffer, offset + 8, Offset);
     FileId.WriteBytes(buffer, offset + 16);
     LittleEndianWriter.WriteUInt32(buffer, offset + 32, MinimumCount);
     LittleEndianWriter.WriteUInt32(buffer, offset + 36, Channel);
     LittleEndianWriter.WriteUInt32(buffer, offset + 40, RemainingBytes);
     LittleEndianWriter.WriteUInt16(buffer, offset + 44, ReadChannelInfoOffset);
     LittleEndianWriter.WriteUInt16(buffer, offset + 46, ReadChannelInfoLength);
     if (ReadChannelInfo.Length > 0)
     {
         ByteWriter.WriteBytes(buffer, offset + FixedSize, ReadChannelInfo);
     }
     else
     {
         // The client MUST set one byte of [the buffer] field to 0
         ByteWriter.WriteBytes(buffer, offset + FixedSize, new byte[1]);
     }
 }
Esempio n. 2
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved1);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, Reserved2);
     FileId.WriteBytes(buffer, offset + 8);
 }
Esempio n. 3
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     // Note: DataLength is UInt32 while WriteChannelInfoOffset is UInt16
     // so it is best to put WriteChannelInfo before Data.
     WriteChannelInfoOffset = 0;
     WriteChannelInfoLength = (ushort)WriteChannelInfo.Length;
     if (WriteChannelInfo.Length > 0)
     {
         WriteChannelInfoOffset = SMB2Header.Length + FixedSize;
     }
     DataOffset = 0;
     DataLength = (uint)Data.Length;
     if (Data.Length > 0)
     {
         DataOffset = (ushort)(SMB2Header.Length + FixedSize + WriteChannelInfo.Length);
     }
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     LittleEndianWriter.WriteUInt16(buffer, offset + 2, DataOffset);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, DataLength);
     LittleEndianWriter.WriteUInt64(buffer, offset + 8, Offset);
     FileId.WriteBytes(buffer, offset + 16);
     LittleEndianWriter.WriteUInt32(buffer, offset + 32, Channel);
     LittleEndianWriter.WriteUInt32(buffer, offset + 36, RemainingBytes);
     LittleEndianWriter.WriteUInt16(buffer, offset + 40, WriteChannelInfoOffset);
     LittleEndianWriter.WriteUInt16(buffer, offset + 42, WriteChannelInfoLength);
     LittleEndianWriter.WriteUInt32(buffer, offset + 44, (uint)Flags);
     if (WriteChannelInfo.Length > 0)
     {
         ByteWriter.WriteBytes(buffer, offset + FixedSize, WriteChannelInfo);
     }
     if (Data.Length > 0)
     {
         ByteWriter.WriteBytes(buffer, offset + FixedSize + WriteChannelInfo.Length, Data);
     }
 }
Esempio n. 4
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     InputOffset  = 0;
     InputCount   = (uint)Input.Length;
     OutputOffset = 0;
     OutputCount  = (uint)Output.Length;
     if (Input.Length > 0)
     {
         InputOffset = SMB2Header.Length + FixedLength;
     }
     if (Output.Length > 0)
     {
         OutputOffset = SMB2Header.Length + FixedLength + (uint)Input.Length;
     }
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, CtlCode);
     FileId.WriteBytes(buffer, offset + 8);
     LittleEndianWriter.WriteUInt32(buffer, offset + 24, InputOffset);
     LittleEndianWriter.WriteUInt32(buffer, offset + 28, InputCount);
     LittleEndianWriter.WriteUInt32(buffer, offset + 32, MaxInputResponse);
     LittleEndianWriter.WriteUInt32(buffer, offset + 36, OutputOffset);
     LittleEndianWriter.WriteUInt32(buffer, offset + 40, OutputCount);
     LittleEndianWriter.WriteUInt32(buffer, offset + 44, MaxOutputResponse);
     LittleEndianWriter.WriteUInt32(buffer, offset + 48, (uint)Flags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 52, Reserved2);
     if (Input.Length > 0)
     {
         ByteWriter.WriteBytes(buffer, offset + FixedLength, Input);
     }
     if (Output.Length > 0)
     {
         ByteWriter.WriteBytes(buffer, offset + FixedLength + Input.Length, Output);
     }
 }
Esempio n. 5
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Locks.Count);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)(LSN & 0x0F) << 28 | (uint)(LockSequenceIndex & 0x0FFFFFFF));
     FileId.WriteBytes(buffer, offset + 8);
     LockElement.WriteLockList(buffer, offset + 24, Locks);
 }
Esempio n. 6
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Flags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, OutputBufferLength);
     FileId.WriteBytes(buffer, offset + 8);
     LittleEndianWriter.WriteUInt32(buffer, offset + 24, (uint)CompletionFilter);
     LittleEndianWriter.WriteUInt32(buffer, offset + 28, Reserved);
 }
Esempio n. 7
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     BufferOffset = 0;
     BufferLength = (uint)Buffer.Length;
     if (Buffer.Length > 0)
     {
         BufferOffset = SMB2Header.Length + FixedSize;
     }
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     ByteWriter.WriteByte(buffer, offset + 2, (byte)InfoType);
     ByteWriter.WriteByte(buffer, offset + 3, FileInfoClass);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, BufferLength);
     LittleEndianWriter.WriteUInt16(buffer, offset + 8, BufferOffset);
     LittleEndianWriter.WriteUInt16(buffer, offset + 10, Reserved);
     LittleEndianWriter.WriteUInt32(buffer, offset + 12, AdditionalInformation);
     FileId.WriteBytes(buffer, offset + 16);
     ByteWriter.WriteBytes(buffer, offset + FixedSize, Buffer);
 }
Esempio n. 8
0
 public override void WriteCommandBytes(byte[] buffer, int offset)
 {
     FileNameOffset = 0;
     FileNameLength = (ushort)(FileName.Length * 2);
     if (FileName.Length > 0)
     {
         FileNameOffset = SMB2Header.Length + FixedLength;
     }
     LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
     ByteWriter.WriteByte(buffer, offset + 2, (byte)FileInformationClass);
     ByteWriter.WriteByte(buffer, offset + 3, (byte)Flags);
     LittleEndianWriter.WriteUInt32(buffer, offset + 4, FileIndex);
     FileId.WriteBytes(buffer, offset + 8);
     LittleEndianWriter.WriteUInt16(buffer, offset + 24, FileNameOffset);
     LittleEndianWriter.WriteUInt16(buffer, offset + 26, FileNameLength);
     LittleEndianWriter.WriteUInt32(buffer, offset + 28, OutputBufferLength);
     ByteWriter.WriteUTF16String(buffer, offset + 32, FileName);
 }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
        public override void WriteCommandBytes(byte[] buffer, int offset)
        {
            InputOffset  = 0;
            InputCount   = (uint)Input.Length;
            OutputOffset = 0;
            OutputCount  = (uint)Output.Length;
            if (Input.Length > 0)
            {
                InputOffset = SMB2Header.Length + FixedLength;
            }
            // MS-SMB2: the output offset MUST be set to InputOffset + InputCount rounded up to a multiple of 8
            int paddedInputLength = (int)Math.Ceiling((double)Input.Length / 8) * 8;

            if (Output.Length > 0)
            {
                OutputOffset = SMB2Header.Length + FixedLength + (uint)paddedInputLength;
            }
            LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
            LittleEndianWriter.WriteUInt16(buffer, offset + 2, Reserved);
            LittleEndianWriter.WriteUInt32(buffer, offset + 4, CtlCode);
            FileId.WriteBytes(buffer, offset + 8);
            LittleEndianWriter.WriteUInt32(buffer, offset + 24, InputOffset);
            LittleEndianWriter.WriteUInt32(buffer, offset + 28, InputCount);
            LittleEndianWriter.WriteUInt32(buffer, offset + 32, OutputOffset);
            LittleEndianWriter.WriteUInt32(buffer, offset + 36, OutputCount);
            LittleEndianWriter.WriteUInt32(buffer, offset + 40, Flags);
            LittleEndianWriter.WriteUInt32(buffer, offset + 44, Reserved2);
            if (Input.Length > 0)
            {
                ByteWriter.WriteBytes(buffer, offset + FixedLength, Input);
            }
            if (Output.Length > 0)
            {
                ByteWriter.WriteBytes(buffer, offset + FixedLength + paddedInputLength, Output);
            }
        }