Exemplo n.º 1
0
        /// <summary>
        /// decode the batched request packet
        /// </summary>
        /// <param name="channel">the channel of bytes to read</param>
        /// <param name="smbBatchedRequest">the batched request</param>
        /// <returns>the consumed length of batched response packet</returns>
        protected virtual int DecodeBatchedRequest(
            Channel channel, SmbBatchedRequestPacket smbBatchedRequest)
        {
            int batchedConsumedLength = 0;

            batchedConsumedLength += smbBatchedRequest.ReadAndxFromChannel(channel);

            return(batchedConsumedLength);
        }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 protected SmbBatchedRequestPacket(SmbBatchedRequestPacket packet)
     : base(packet)
 {
     lock (packet)
     {
         if (packet.andxPacket != null)
         {
             this.andxPacket = packet.AndxPacket.Clone() as SmbPacket;
         }
     }
 }
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 protected SmbBatchedRequestPacket(SmbBatchedRequestPacket packet)
     : base(packet)
 {
     lock (packet)
     {
         if (packet.andxPacket != null)
         {
             this.andxPacket = packet.AndxPacket.Clone() as SmbPacket;
         }
     }
 }
        /// <summary>
        /// to read the andx packet from the channel
        /// </summary>
        /// <param name="channel">the channel started with the SmbParameters of the andx.</param>
        /// <returns>the size in bytes of the SmbParameters, SmbData and andx if existed of the andx.</returns>
        internal int ReadAndxFromChannel(Channel channel)
        {
            int consumedLen = 0;

            if (this.AndxCommand != SmbCommand.SMB_COM_NO_ANDX_COMMAND)
            {
                SmbHeader andxHeader = this.SmbHeader;
                andxHeader.Protocol       = CifsMessageUtils.SMB_PROTOCOL_ANDXPACKET;
                andxHeader.Command        = this.AndxCommand;
                this.andxPacket           = CifsMessageUtils.CreateSmbRequestPacket(andxHeader, channel);
                this.andxPacket.SmbHeader = andxHeader;
                consumedLen += this.andxPacket.ReadParametersFromChannel(channel);
                consumedLen += this.andxPacket.ReadDataFromChannel(channel);
                SmbBatchedRequestPacket batchedRequest = this.andxPacket as SmbBatchedRequestPacket;
                if (batchedRequest != null)
                {
                    consumedLen += batchedRequest.ReadAndxFromChannel(channel);
                }
            }
            return(consumedLen);
        }
Exemplo n.º 5
0
        /// <summary>
        /// decode packet from bytes
        /// </summary>
        /// <param name="messageBytes">bytes contains packet</param>
        /// <param name="consumedLength">the bytes length which are consumed when decode.</param>
        /// <returns>the decoded packet from the bytes array. if failed, return null.</returns>
        protected SmbPacket DecodeSmbRequestFromBytes(
            byte[] messageBytes,
            out int consumedLength)
        {
            consumedLength = 0;
            SmbPacket smbRequest = null;

            using (MemoryStream memoryStream = new MemoryStream(messageBytes, false))
            {
                using (Channel channel = new Channel(null, memoryStream))
                {
                    smbRequest = CreateSmbRequestPacket(messageBytes);
                    if (smbRequest == null)
                    {
                        return(null);
                    }

                    // decode smb header
                    SmbHeader smbHeader = channel.Read <SmbHeader>();
                    consumedLength += smbRequest.HeaderSize;

                    // set packet header
                    smbRequest.SmbHeader = smbHeader;

                    // read SmbParameters:
                    consumedLength += smbRequest.ReadParametersFromChannel(channel);

                    // read SmbData:
                    consumedLength += smbRequest.ReadDataFromChannel(channel);

                    // read andx:
                    SmbBatchedRequestPacket smbBatchedRequest = smbRequest as SmbBatchedRequestPacket;
                    if (smbBatchedRequest != null)
                    {
                        consumedLength += DecodeBatchedRequest(channel, smbBatchedRequest);
                    }
                }
            }
            return(smbRequest);
        }
 /// <summary>
 /// decode the batched request packet
 /// </summary>
 /// <param name="channel">the channel of bytes to read</param>
 /// <param name="smbBatchedRequest">the batched request</param>
 /// <returns>the consumed length of batched request packet</returns>
 protected override int DecodeBatchedRequest(Channel channel, SmbBatchedRequestPacket smbBatchedRequest)
 {
     // do not process batched request.
     return 0;
 }
        /// <summary>
        /// decode the batched request packet
        /// </summary>
        /// <param name="channel">the channel of bytes to read</param>
        /// <param name="smbBatchedRequest">the batched request</param>
        /// <returns>the consumed length of batched response packet</returns>
        protected virtual int DecodeBatchedRequest(
            Channel channel, SmbBatchedRequestPacket smbBatchedRequest)
        {
            int batchedConsumedLength = 0;

            batchedConsumedLength += smbBatchedRequest.ReadAndxFromChannel(channel);

            return batchedConsumedLength;
        }