Ejemplo n.º 1
0
        public override byte[] GetBytes(bool isUnicode)
        {
            SecurityBlobLength = (ushort)SecurityBlob.Length;

            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxBufferSize);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxMpxCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, VcNumber);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 10, SessionKey);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 14, SecurityBlobLength);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 16, Reserved);

            int padding = 0;

            if (isUnicode)
            {
                // A Unicode string MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header.
                // Note: SMBData starts at an odd offset.
                padding      = (SecurityBlobLength + 1) % 2;
                this.SMBData = new byte[SecurityBlob.Length + (NativeOS.Length + 1) * 2 + (NativeLanMan.Length + 1) * 2];
            }
            else
            {
                this.SMBData = new byte[SecurityBlob.Length + NativeOS.Length + 1 + NativeLanMan.Length + 1];
            }
            int offset = 0;

            ByteWriter.WriteBytes(this.SMBData, ref offset, SecurityBlob);
            offset += padding;
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 2
0
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 28;

            if (isUnicode)
            {
                length += FileName.Length * 2 + 2;
            }
            else
            {
                length += FileName.Length + 1;
            }

            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)Flags);
            AccessMode.WriteBytes(parameters, 2);
            LittleEndianWriter.WriteUInt16(parameters, 4, Reserved1);
            LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)FileAttributes);
            UTimeHelper.WriteUTime(parameters, 8, CreationTime);
            OpenMode.WriteBytes(parameters, 12);
            LittleEndianWriter.WriteUInt32(parameters, 14, AllocationSize);
            ByteWriter.WriteBytes(parameters, 18, Reserved, 10);
            SMB1Helper.WriteSMBString(parameters, 28, isUnicode, FileName);
            return(parameters);
        }
Ejemplo n.º 3
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)SearchAttributes);

            if (isUnicode)
            {
                int padding = 1;
                this.SMBData = new byte[2 + OldFileName.Length * 2 + NewFileName.Length * 2 + 4 + padding];
            }
            else
            {
                this.SMBData = new byte[2 + OldFileName.Length + NewFileName.Length + 2];
            }
            int dataOffset = 0;

            ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat1);
            SMB1Helper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, OldFileName);
            ByteWriter.WriteByte(this.SMBData, ref dataOffset, BufferFormat2);
            if (isUnicode)
            {
                dataOffset++; // padding
            }
            SMB1Helper.WriteSMBString(this.SMBData, ref dataOffset, isUnicode, NewFileName);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 4
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, (ushort)Action);

            int offset = 0;

            if (isUnicode)
            {
                // A Unicode string MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header.
                // Note: SMBData starts at an odd offset.
                int padding = 1;
                this.SMBData = new byte[padding + NativeOS.Length * 2 + NativeLanMan.Length * 2 + PrimaryDomain.Length * 2 + 6];
                offset       = padding;
            }
            else
            {
                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, NativeLanMan);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 5
0
        public override byte[] GetBytes(bool isUnicode)
        {
            SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, (ushort)Flags);
            AccessMode.WriteBytes(SMBParameters, ref parametersOffset);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, (ushort)SearchAttrs);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, (ushort)FileAttrs);
            UTimeHelper.WriteUTime(SMBParameters, ref parametersOffset, CreationTime);
            OpenMode.WriteBytes(SMBParameters, ref parametersOffset);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, AllocationSize);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, Timeout);
            LittleEndianWriter.WriteUInt32(SMBParameters, ref parametersOffset, Reserved);

            int padding = 0;

            if (isUnicode)
            {
                padding = 1;
                SMBData = new byte[padding + FileName.Length * 2 + 2];
            }
            else
            {
                SMBData = new byte[FileName.Length + 1];
            }
            SMB1Helper.WriteSMBString(SMBData, padding, isUnicode, FileName);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 6
0
        public override byte[] GetBytes(bool isUnicode)
        {
            ushort securityBlobLength = (ushort)SecurityBlob.Length;

            SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(SMBParameters, 4, (ushort)Action);
            LittleEndianWriter.WriteUInt16(SMBParameters, 6, securityBlobLength);

            int padding = 0;

            if (isUnicode)
            {
                // A Unicode string MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header.
                // Note: SMBData starts at an odd offset.
                padding = (1 + securityBlobLength) % 2;
                SMBData = new byte[SecurityBlob.Length + padding + NativeOS.Length * 2 + NativeLanMan.Length * 2 + 4];
            }
            else
            {
                SMBData = new byte[SecurityBlob.Length + NativeOS.Length + NativeLanMan.Length + 2];
            }
            int offset = 0;

            ByteWriter.WriteBytes(SMBData, ref offset, SecurityBlob);
            offset += padding;
            SMB1Helper.WriteSMBString(SMBData, ref offset, isUnicode, NativeOS);
            SMB1Helper.WriteSMBString(SMBData, ref offset, isUnicode, NativeLanMan);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 7
0
        public override byte[] GetBytes(bool isUnicode)
        {
            ChallengeLength = (byte)Challenge.Length;

            SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(SMBParameters, 0, DialectIndex);
            ByteWriter.WriteByte(SMBParameters, 2, (byte)SecurityMode);
            LittleEndianWriter.WriteUInt16(SMBParameters, 3, MaxMpxCount);
            LittleEndianWriter.WriteUInt16(SMBParameters, 5, MaxNumberVcs);
            LittleEndianWriter.WriteUInt32(SMBParameters, 7, MaxBufferSize);
            LittleEndianWriter.WriteUInt32(SMBParameters, 11, MaxRawSize);
            LittleEndianWriter.WriteUInt32(SMBParameters, 15, SessionKey);
            LittleEndianWriter.WriteUInt32(SMBParameters, 19, (uint)Capabilities);
            FileTimeHelper.WriteFileTime(SMBParameters, 23, SystemTime);
            LittleEndianWriter.WriteInt16(SMBParameters, 31, ServerTimeZone);
            ByteWriter.WriteByte(SMBParameters, 33, ChallengeLength);

            // [MS-CIFS] <90> Padding is not added before DomainName
            // DomainName and ServerName are always in Unicode
            SMBData = new byte[Challenge.Length + (DomainName.Length + 1) * 2 + (ServerName.Length + 1) * 2];
            int offset = 0;

            ByteWriter.WriteBytes(SMBData, ref offset, Challenge);
            SMB1Helper.WriteSMBString(SMBData, ref offset, true, DomainName);
            SMB1Helper.WriteSMBString(SMBData, ref offset, true, ServerName);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 8
0
        public override byte[] GetBytes(bool isUnicode)
        {
            NameLength         = (ushort)FileName.Length;
            this.SMBParameters = new byte[ParametersLength];
            ByteWriter.WriteByte(this.SMBParameters, 0, (byte)AndXCommand);
            ByteWriter.WriteByte(this.SMBParameters, 1, AndXReserved);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, AndXOffset);
            ByteWriter.WriteByte(this.SMBParameters, 4, Reserved);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 5, NameLength);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 7, (uint)Flags);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 11, RootDirectoryFID);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 15, (uint)DesiredAccess);
            LittleEndianWriter.WriteInt64(this.SMBParameters, 19, AllocationSize);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 27, (uint)ExtFileAttributes);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 31, (uint)ShareAccess);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 35, (uint)CreateDisposition);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 39, (uint)CreateOptions);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 43, (uint)ImpersonationLevel);
            ByteWriter.WriteByte(this.SMBParameters, 47, (byte)SecurityFlags);

            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));
        }
Ejemplo n.º 9
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)OptionalSupport);
            MaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
            GuestMaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);

            // Should be written as OEM string but it doesn't really matter
            string serviceString = ServiceNameHelper.GetServiceString(Service);

            if (isUnicode)
            {
                this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length * 2 + 3];
            }
            else
            {
                this.SMBData = new byte[serviceString.Length + NativeFileSystem.Length + 2];
            }

            int offset = 0;

            ByteWriter.WriteNullTerminatedAnsiString(this.SMBData, ref offset, serviceString);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeFileSystem);

            return(base.GetBytes(isUnicode));
        }
        public override byte[] GetData(bool isUnicode)
        {
            if (PipeName == null)
            {
                return(new byte[0]);
            }

            int length = 8;

            if (isUnicode)
            {
                length += PipeName.Length * 2 + 2;
            }
            else
            {
                length += PipeName.Length + 1;
            }
            byte[] data = new byte[length];
            LittleEndianWriter.WriteUInt16(data, 0, OutputBufferSize);
            LittleEndianWriter.WriteUInt16(data, 2, InputBufferSize);
            ByteWriter.WriteByte(data, 4, MaximumInstances);
            ByteWriter.WriteByte(data, 5, CurrentInstances);
            ByteWriter.WriteByte(data, 6, PipeNameLength);
            SMB1Helper.WriteSMBString(data, 8, isUnicode, PipeName);
            return(data);
        }
Ejemplo n.º 11
0
        public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
        {
            uint fileNameLength = (uint)(isUnicode ? FileName.Length * 2 : FileName.Length);

            LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
            LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex);
            LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength);
            SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
        }
Ejemplo n.º 12
0
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 4;

            length += isUnicode ? DirectoryName.Length * 2 + 2 : DirectoryName.Length + 1 + 1;
            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt32(parameters, 0, Reserved);
            SMB1Helper.WriteSMBString(parameters, 4, isUnicode, DirectoryName);
            return(parameters);
        }
Ejemplo n.º 13
0
        public override void WriteBytes(byte[] buffer, ref int offset, bool isUnicode)
        {
            uint fileNameLength = (byte)(isUnicode ? FileName.Length * 2 : FileName.Length);

            LittleEndianWriter.WriteUInt32(buffer, ref offset, NextEntryOffset);
            LittleEndianWriter.WriteUInt32(buffer, ref offset, FileIndex);
            FileTimeHelper.WriteFileTime(buffer, ref offset, CreationTime);
            FileTimeHelper.WriteFileTime(buffer, ref offset, LastAccessTime);
            FileTimeHelper.WriteFileTime(buffer, ref offset, LastWriteTime);
            FileTimeHelper.WriteFileTime(buffer, ref offset, LastAttrChangeTime);
            LittleEndianWriter.WriteInt64(buffer, ref offset, EndOfFile);
            LittleEndianWriter.WriteInt64(buffer, ref offset, AllocationSize);
            LittleEndianWriter.WriteUInt32(buffer, ref offset, (uint)ExtFileAttributes);
            LittleEndianWriter.WriteUInt32(buffer, ref offset, fileNameLength);
            SMB1Helper.WriteSMBString(buffer, ref offset, isUnicode, FileName);
        }
Ejemplo n.º 14
0
        public override byte[] GetBytes(bool isUnicode)
        {
            int length = 1;

            if (isUnicode)
            {
                length += DirectoryName.Length * 2 + 2;
            }
            else
            {
                length += DirectoryName.Length + 1;
            }
            this.SMBData = new byte[length];
            ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
            SMB1Helper.WriteSMBString(this.SMBData, 1, isUnicode, DirectoryName);
            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 15
0
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 6;

            if (isUnicode)
            {
                length += FileName.Length * 2 + 2;
            }
            else
            {
                length += FileName.Length + 1;
            }
            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)InformationLevel);
            LittleEndianWriter.WriteUInt32(parameters, 2, Reserved);
            SMB1Helper.WriteSMBString(parameters, 6, isUnicode, FileName);
            return(parameters);
        }
Ejemplo n.º 16
0
        public override byte[] GetBytes(bool isUnicode)
        {
            Capabilities &= ~Capabilities.ExtendedSecurity;

            OEMPasswordLength     = (ushort)OEMPassword.Length;
            UnicodePasswordLength = (ushort)UnicodePassword.Length;

            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxBufferSize);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxMpxCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 8, VcNumber);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 10, SessionKey);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 14, OEMPasswordLength);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, UnicodePasswordLength);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 18, Reserved);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 22, (uint)Capabilities);

            int padding = 0;

            if (isUnicode)
            {
                // A Unicode string MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header.
                // Note: SMBData starts at an odd offset.
                padding      = (1 + OEMPasswordLength + UnicodePasswordLength) % 2;
                this.SMBData = new byte[OEMPassword.Length + UnicodePassword.Length + padding + (AccountName.Length + 1) * 2 + (PrimaryDomain.Length + 1) * 2 + (NativeOS.Length + 1) * 2 + (NativeLanMan.Length + 1) * 2];
            }
            else
            {
                this.SMBData = new byte[OEMPassword.Length + UnicodePassword.Length + AccountName.Length + 1 + PrimaryDomain.Length + 1 + NativeOS.Length + 1 + NativeLanMan.Length + 1];
            }
            int offset = 0;

            ByteWriter.WriteBytes(this.SMBData, ref offset, OEMPassword);
            ByteWriter.WriteBytes(this.SMBData, ref offset, UnicodePassword);
            offset += padding;
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, AccountName);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS);
            SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan);

            return(base.GetBytes(isUnicode));
        }
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 8;

            if (isUnicode)
            {
                length += PipeName.Length * 2 + 2;
            }
            else
            {
                length += PipeName.Length + 1;
            }
            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt16(parameters, 0, OutputBufferSize);
            LittleEndianWriter.WriteUInt16(parameters, 2, InputBufferSize);
            ByteWriter.WriteByte(parameters, 4, MaximumInstances);
            ByteWriter.WriteByte(parameters, 5, CurrentInstances);
            ByteWriter.WriteByte(parameters, 6, PipeNameLength);
            SMB1Helper.WriteSMBString(parameters, 8, isUnicode, PipeName);
            return(parameters);;
        }
Ejemplo n.º 18
0
        public override byte[] GetBytes(bool isUnicode)
        {
            this.SMBParameters = new byte[ParametersLength];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, (ushort)FileAttributes);
            UTimeHelper.WriteUTime(this.SMBParameters, 2, LastWriteTime);
            ByteWriter.WriteBytes(this.SMBParameters, 6, Reserved, 10);

            int length = 1;

            if (isUnicode)
            {
                length += FileName.Length * 2 + 2;
            }
            else
            {
                length += FileName.Length + 1;
            }
            this.SMBData = new byte[length];
            ByteWriter.WriteByte(this.SMBData, 0, BufferFormat);
            SMB1Helper.WriteSMBString(this.SMBData, 1, isUnicode, FileName);

            return(base.GetBytes(isUnicode));
        }
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 12;

            if (isUnicode)
            {
                length += FileName.Length * 2 + 2;
            }
            else
            {
                length += FileName.Length + 1;
            }

            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt16(parameters, 0, (ushort)SearchAttributes);
            LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount);
            LittleEndianWriter.WriteUInt16(parameters, 4, (ushort)Flags);
            LittleEndianWriter.WriteUInt16(parameters, 6, (ushort)InformationLevel);
            LittleEndianWriter.WriteUInt32(parameters, 8, (uint)SearchStorageType);
            SMB1Helper.WriteSMBString(parameters, 12, isUnicode, FileName);

            return(parameters);
        }
        public override byte[] GetParameters(bool isUnicode)
        {
            int length = 12;

            if (isUnicode)
            {
                length += FileName?.Length * 2 + 2 ?? 0;
            }
            else
            {
                length += FileName?.Length + 1 ?? 0;
            }

            byte[] parameters = new byte[length];
            LittleEndianWriter.WriteUInt16(parameters, 0, SID);
            LittleEndianWriter.WriteUInt16(parameters, 2, SearchCount);
            LittleEndianWriter.WriteUInt16(parameters, 4, (ushort)InformationLevel);
            LittleEndianWriter.WriteUInt32(parameters, 6, ResumeKey);
            LittleEndianWriter.WriteUInt16(parameters, 10, (ushort)Flags);
            SMB1Helper.WriteSMBString(parameters, 12, isUnicode, FileName !);

            return(parameters);
        }
Ejemplo n.º 21
0
        public override byte[] GetBytes(bool isUnicode)
        {
            ushort passwordLength = (ushort)Password.Length;

            SMBParameters = new byte[ParametersLength];
            int parametersOffset = 4;

            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, (ushort)Flags);
            LittleEndianWriter.WriteUInt16(SMBParameters, ref parametersOffset, passwordLength);

            string serviceString = ServiceNameHelper.GetServiceString(Service);
            int    dataLength    = Password.Length + serviceString.Length + 1;

            if (isUnicode)
            {
                int padding = (1 + passwordLength) % 2;
                dataLength += Path.Length * 2 + 2 + padding;
            }
            else
            {
                dataLength += Path.Length + 1;
            }
            SMBData = new byte[dataLength];
            int dataOffset = 0;

            ByteWriter.WriteBytes(SMBData, ref dataOffset, Password);
            if (isUnicode)
            {
                // wordCount is 1 byte
                int padding = (1 + passwordLength) % 2;
                dataOffset += padding;
            }
            SMB1Helper.WriteSMBString(SMBData, ref dataOffset, isUnicode, Path);
            ByteWriter.WriteNullTerminatedAnsiString(SMBData, ref dataOffset, serviceString);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 22
0
        public override byte[] GetBytes(bool isUnicode)
        {
            byte   SetupCount     = (byte)(Setup.Length / 2);
            ushort ParameterCount = (ushort)TransParameters.Length;
            ushort DataCount      = (ushort)TransData.Length;

            // WordCount + ByteCount are additional 3 bytes
            ushort ParameterOffset = (ushort)(SMB1Header.Length + 3 + (FixedSMBParametersLength + Setup.Length));

            if (this is Transaction2Request)
            {
                ParameterOffset += 1;
            }
            else
            {
                if (isUnicode)
                {
                    ParameterOffset += (ushort)(Name.Length * 2 + 2);
                }
                else
                {
                    ParameterOffset += (ushort)(Name.Length + 1);
                }
            }
            int padding1 = (4 - (ParameterOffset % 4)) % 4;

            ParameterOffset += (ushort)padding1;
            ushort DataOffset = (ushort)(ParameterOffset + ParameterCount);
            int    padding2   = (4 - (DataOffset % 4)) % 4;

            DataOffset += (ushort)padding2;

            this.SMBParameters = new byte[FixedSMBParametersLength + Setup.Length];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, TotalParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, TotalDataCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxDataCount);
            ByteWriter.WriteByte(this.SMBParameters, 8, MaxSetupCount);
            ByteWriter.WriteByte(this.SMBParameters, 9, Reserved1);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, (ushort)Flags);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 12, Timeout);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, Reserved2);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 18, ParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 20, ParameterOffset);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 22, DataCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 24, DataOffset);
            ByteWriter.WriteByte(this.SMBParameters, 26, SetupCount);
            ByteWriter.WriteByte(this.SMBParameters, 27, Reserved3);
            ByteWriter.WriteBytes(this.SMBParameters, 28, Setup);

            int offset;

            if (this is Transaction2Request)
            {
                int nameLength = 1;
                this.SMBData = new byte[nameLength + padding1 + ParameterCount + padding2 + DataCount];
                offset       = nameLength;
            }
            else
            {
                if (isUnicode)
                {
                    int namePadding = 1;
                    this.SMBData = new byte[namePadding + Name.Length * 2 + 2 + padding1 + ParameterCount + padding2 + DataCount];
                    offset       = namePadding;
                }
                else
                {
                    this.SMBData = new byte[Name.Length + 1 + padding1 + ParameterCount + padding2 + DataCount];
                    offset       = 0;
                }
                SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, Name);
            }
            ByteWriter.WriteBytes(this.SMBData, offset + padding1, TransParameters);
            ByteWriter.WriteBytes(this.SMBData, offset + padding1 + ParameterCount + padding2, TransData);

            return(base.GetBytes(isUnicode));
        }
Ejemplo n.º 23
0
        public override byte[] GetBytes(bool isUnicode)
        {
            if (Setup.Length % 2 > 0)
            {
                throw new Exception("Setup length must be a multiple of 2");
            }

            byte   setupCount          = (byte)(Setup.Length / 2);
            ushort transParameterCount = (ushort)TransParameters.Length;
            ushort transDataCount      = (ushort)TransData.Length;

            // WordCount + ByteCount are additional 3 bytes
            int nameLength;
            int namePadding;

            if (this is Transaction2Request)
            {
                namePadding = 0;
                nameLength  = 1;
            }
            else
            {
                if (isUnicode)
                {
                    namePadding = 1;
                    nameLength  = Name.Length * 2 + 2;
                }
                else
                {
                    namePadding = 0;
                    nameLength  = Name.Length + 1;
                }
            }
            ushort transParameterOffset = (ushort)(SMB1Header.Length + 3 + (FixedSMBParametersLength + Setup.Length + namePadding + nameLength));
            int    padding1             = (4 - (transParameterOffset % 4)) % 4;

            transParameterOffset += (ushort)padding1;
            ushort transDataOffset = (ushort)(transParameterOffset + transParameterCount);
            int    padding2        = (4 - (transDataOffset % 4)) % 4;

            transDataOffset += (ushort)padding2;

            this.SMBParameters = new byte[FixedSMBParametersLength + Setup.Length];
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, TotalParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 2, TotalDataCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 4, MaxParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 6, MaxDataCount);
            ByteWriter.WriteByte(this.SMBParameters, 8, MaxSetupCount);
            ByteWriter.WriteByte(this.SMBParameters, 9, Reserved1);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 10, (ushort)Flags);
            LittleEndianWriter.WriteUInt32(this.SMBParameters, 12, Timeout);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 16, Reserved2);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 18, transParameterCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 20, transParameterOffset);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 22, transDataCount);
            LittleEndianWriter.WriteUInt16(this.SMBParameters, 24, transDataOffset);
            ByteWriter.WriteByte(this.SMBParameters, 26, setupCount);
            ByteWriter.WriteByte(this.SMBParameters, 27, Reserved3);
            ByteWriter.WriteBytes(this.SMBParameters, 28, Setup);

            int offset;

            this.SMBData = new byte[namePadding + nameLength + padding1 + transParameterCount + padding2 + transDataCount];
            offset       = namePadding;
            if (this is Transaction2Request)
            {
                offset += nameLength;
            }
            else
            {
                SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, Name);
            }
            ByteWriter.WriteBytes(this.SMBData, offset + padding1, TransParameters);
            ByteWriter.WriteBytes(this.SMBData, offset + padding1 + transParameterCount + padding2, TransData);

            return(base.GetBytes(isUnicode));
        }