Exemplo n.º 1
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbReadResponsePacket(SmbReadResponsePacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount            = packet.SmbParameters.WordCount;
            this.smbParameters.CountOfBytesReturned = packet.SmbParameters.CountOfBytesReturned;

            if (packet.smbParameters.Reserved != null)
            {
                this.smbParameters.Reserved = new ushort[packet.smbParameters.Reserved.Length];
                Array.Copy(packet.smbParameters.Reserved,
                           this.smbParameters.Reserved, packet.smbParameters.Reserved.Length);
            }
            else
            {
                this.smbParameters.Reserved = new ushort[0];
            }
            this.smbData.ByteCount        = packet.SmbData.ByteCount;
            this.smbData.BufferFormat     = packet.SmbData.BufferFormat;
            this.smbData.CountOfBytesRead = packet.SmbData.CountOfBytesRead;

            if (packet.smbData.Bytes != null)
            {
                this.smbData.Bytes = new byte[packet.smbData.Bytes.Length];
                Array.Copy(packet.smbData.Bytes, this.smbData.Bytes, packet.smbData.Bytes.Length);
            }
            else
            {
                this.smbData.Bytes = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbReadResponsePacket(SmbReadResponsePacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.CountOfBytesReturned = packet.SmbParameters.CountOfBytesReturned;

            if (packet.smbParameters.Reserved != null)
            {
                this.smbParameters.Reserved = new ushort[packet.smbParameters.Reserved.Length];
                Array.Copy(packet.smbParameters.Reserved,
                    this.smbParameters.Reserved, packet.smbParameters.Reserved.Length);
            }
            else
            {
                this.smbParameters.Reserved = new ushort[0];
            }
            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat = packet.SmbData.BufferFormat;
            this.smbData.CountOfBytesRead = packet.SmbData.CountOfBytesRead;

            if (packet.smbData.Bytes != null)
            {
                this.smbData.Bytes = new byte[packet.smbData.Bytes.Length];
                Array.Copy(packet.smbData.Bytes, this.smbData.Bytes, packet.smbData.Bytes.Length);
            }
            else
            {
                this.smbData.Bytes = new byte[0];
            }
        }
        public SmbReadResponsePacket CreateReadResponse(
            CifsServerPerConnection connection,
            SmbReadRequestPacket request,
            byte[] bytes)
        {
            bytes = bytes ?? new byte[0];
            SmbReadResponsePacket response = new SmbReadResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_READ_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.CountOfBytesReturned = (ushort)bytes.Length;
            smbParameters.Reserved = new ushort[4];
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            SMB_COM_READ_Response_SMB_Data smbData = response.SmbData;
            smbData.ByteCount = (ushort)(Marshal.SizeOf(response.SmbData.BufferFormat) + Marshal.SizeOf(
                    response.SmbData.CountOfBytesRead) + bytes.Length);
            smbData.CountOfBytesRead = (ushort)bytes.Length;
            smbData.BufferFormat = 0x01;
            smbData.Bytes = bytes;
            response.SmbData = smbData;

            return response;
        }