Exemplo n.º 1
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 = TreeConnectHelper.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);
            SMBHelper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeFileSystem);

            return(base.GetBytes(isUnicode));
        }
        public TreeConnectAndXResponse(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            OptionalSupport = (OptionalSupportFlags)LittleEndianConverter.ToUInt16(this.SMBParameters, 4);

            int    dataOffset    = 0;
            string serviceString = ByteReader.ReadNullTerminatedAnsiString(this.SMBData, ref dataOffset);

            NativeFileSystem = SMBHelper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);

            Service = TreeConnectHelper.GetServiceName(serviceString);
        }
Exemplo n.º 3
0
        public TreeConnectAndXResponseExtended(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            int parametersOffset = 4;

            OptionalSupport               = (OptionalSupportFlags)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
            MaximalShareAccessRights      = new AccessMask(this.SMBParameters, ref parametersOffset);
            GuestMaximalShareAccessRights = new AccessMask(this.SMBParameters, ref parametersOffset);

            int    dataOffset    = 0;
            string serviceString = ByteReader.ReadNullTerminatedAnsiString(this.SMBData, ref dataOffset);

            NativeFileSystem = SMBHelper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);

            Service = TreeConnectHelper.GetServiceName(serviceString);
        }
        public ServiceName Service; // OEM string

        public TreeConnectAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
        {
            int parametersOffset = 4;

            Flags = (TreeConnectFlags)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
            ushort passwordLength = LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);

            int dataOffset = 0;

            Password = ByteReader.ReadBytes(this.SMBData, ref dataOffset, passwordLength);
            if (isUnicode)
            {
                // wordCount is 1 byte
                int padding = (1 + passwordLength) % 2;
                dataOffset += padding;
            }
            Path = SMBHelper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
            // Should be read as OEM string but it doesn't really matter
            string serviceString = ByteReader.ReadNullTerminatedAnsiString(this.SMBData, ref dataOffset);

            Service = TreeConnectHelper.GetServiceName(serviceString);
        }
        public override byte[] GetBytes(bool isUnicode)
        {
            ushort passwordLength = (ushort)Password.Length;

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

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

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

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

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

            return(base.GetBytes(isUnicode));
        }