Пример #1
0
        /// <summary>
        /// to new a Smb request packet in type of the Command in SmbHeader.
        /// </summary>
        /// <param name="messageBytes">bytes contains packet</param>
        /// <returns>
        /// the new request packet.
        /// the null means that the utility don't know how to create the request.
        /// </returns>
        protected virtual SmbPacket CreateSmbRequestPacket(byte[] messageBytes)
        {
            SmbPacket smbRequest = null;

            using (MemoryStream stream = new MemoryStream(messageBytes, true))
            {
                using (Channel channel = new Channel(null, stream))
                {
                    //read smb header and new SmbPacket
                    if (messageBytes.Length >= CifsMessageUtils.PACKET_MINIMUM_LENGTH)
                    {
                        SmbHeader smbHeader = channel.Read <SmbHeader>();
                        smbRequest = CifsMessageUtils.CreateSmbRequestPacket(smbHeader, channel);
                    }
                }
            }

            return(smbRequest);
        }
        /// <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);
        }