コード例 #1
0
        /// <summary>
        /// to split a nttrans request to a nttrans request with nttrans secondary requests.
        /// </summary>
        /// <param name="ntTransRequest">the nttrans request packet to be split.</param>
        /// <param name="parameterCount">the parameter count with which to split the request packet.</param>
        /// <param name="dataCount">the data count with which to split the request packet.</param>
        /// <returns>a requests array of the split nttrans request with nttrans secondary requests.</returns>
        public SmbPacket[] CreateNtTransWith2ndRequests(
            SmbNtTransactRequestPacket ntTransRequest,
            int parameterCount,
            int dataCount)
        {
            ntTransRequest.ToBytes();
            ntTransRequest.isDivided = true;
            int paramLength = 0;

            if (ntTransRequest.SmbData.NT_Trans_Parameters != null)
            {
                paramLength = ntTransRequest.SmbData.NT_Trans_Parameters.Length;
            }
            double paramNumber = Math.Ceiling((double)paramLength / parameterCount);
            int dataLength = 0;

            if (ntTransRequest.SmbData.NT_Trans_Data != null)
            {
                dataLength = ntTransRequest.SmbData.NT_Trans_Data.Length;
            }
            int dataNumber = (int)Math.Ceiling((double)dataLength / dataCount);
            double packetCount = paramNumber > dataNumber ? paramNumber : dataNumber;
            List<SmbPacket> packetList = new List<SmbPacket>();

            if (packetCount > 1)
            {
                byte[] ntTransParameters = ntTransRequest.SmbData.NT_Trans_Parameters;
                byte[] ntTransData = ntTransRequest.SmbData.NT_Trans_Data;

                SMB_COM_NT_TRANSACT_Request_SMB_Data ntTransSmbData = ntTransRequest.SmbData;

                if (paramLength > parameterCount)
                {
                    ntTransSmbData.NT_Trans_Parameters = new byte[parameterCount];
                    Array.Copy(ntTransParameters, ntTransSmbData.NT_Trans_Parameters, parameterCount);
                }

                if (dataLength > dataCount)
                {
                    ntTransSmbData.NT_Trans_Data = new byte[dataCount];
                    Array.Copy(ntTransData, ntTransSmbData.NT_Trans_Data, dataCount);
                }
                ntTransRequest.SmbData = ntTransSmbData;
                ntTransRequest.UpdateCountAndOffset();
                packetList.Add(ntTransRequest);
                int currentIndex = 1;
                long remainedParamCount = ntTransRequest.SmbParameters.TotalParameterCount - parameterCount;
                long remainedDataCount = ntTransRequest.SmbParameters.TotalDataCount - dataCount;

                while (currentIndex < packetCount)
                {
                    SmbNtTransactSecondaryRequestPacket packet = new SmbNtTransactSecondaryRequestPacket();
                    SmbHeader header = ntTransRequest.SmbHeader;
                    header.Command = SmbCommand.SMB_COM_NT_TRANSACT_SECONDARY;
                    packet.SmbHeader = header;

                    // Set Smb_Parameters
                    SMB_COM_NT_TRANSACT_SECONDARY_Request_SMB_Parameters smbParameters =
                        new SMB_COM_NT_TRANSACT_SECONDARY_Request_SMB_Parameters();
                    smbParameters.Reserved1 = new byte[3];
                    smbParameters.TotalParameterCount = ntTransRequest.SmbParameters.TotalParameterCount;
                    smbParameters.TotalDataCount = ntTransRequest.SmbParameters.TotalDataCount;
                    smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<
                        SMB_COM_NT_TRANSACT_SECONDARY_Request_SMB_Parameters>(smbParameters) / NumBytesOfWord);

                    // Set Smb_Data
                    SMB_COM_NT_TRANSACT_SECONDARY_Request_SMB_Data smbData = new SMB_COM_NT_TRANSACT_SECONDARY_Request_SMB_Data();

                    if (remainedParamCount > parameterCount)
                    {
                        smbData.NT_Trans_Parameters = new byte[parameterCount];
                        Array.Copy(ntTransParameters, parameterCount * currentIndex, smbData.NT_Trans_Parameters, 0, parameterCount);
                        smbParameters.ParameterDisplacement = (ushort)(parameterCount * currentIndex);
                        remainedParamCount -= parameterCount;
                    }
                    else if (remainedParamCount > 0)
                    {
                        smbData.NT_Trans_Parameters = new byte[remainedParamCount];
                        Array.Copy(ntTransParameters, parameterCount * currentIndex, smbData.NT_Trans_Parameters, 0, remainedParamCount);
                        smbParameters.ParameterDisplacement = (ushort)(parameterCount * currentIndex);
                        remainedParamCount -= parameterCount;
                    }
                    else
                    {
                        smbData.NT_Trans_Parameters = new byte[0];
                    }

                    if (remainedDataCount > dataCount)
                    {
                        smbData.NT_Trans_Data = new byte[dataCount];
                        Array.Copy(ntTransData, dataCount * currentIndex, smbData.NT_Trans_Data, 0, dataCount);
                        smbParameters.DataDisplacement = (ushort)(dataCount * currentIndex);
                        remainedDataCount -= dataCount;
                    }
                    else if (remainedDataCount > 0)
                    {
                        smbData.NT_Trans_Data = new byte[remainedDataCount];
                        Array.Copy(ntTransData, dataCount * currentIndex, smbData.NT_Trans_Data, 0, remainedDataCount);
                        smbParameters.DataDisplacement = (ushort)(dataCount * currentIndex);
                        remainedDataCount -= dataCount;
                    }
                    else
                    {
                        smbData.NT_Trans_Data = new byte[0];
                    }

                    packet.SmbParameters = smbParameters;
                    packet.SmbData = smbData;
                    currentIndex++;
                    packet.UpdateCountAndOffset();
                    packetList.Add(packet);
                }
            }
            else
            {
                packetList.Add(ntTransRequest);
            }

            return packetList.ToArray();
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbNtTransactSecondaryRequestPacket(SmbNtTransactSecondaryRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();
            this.smbParameters.WordCount = packet.SmbParameters.WordCount;

            if (packet.smbParameters.Reserved1 != null)
            {
                this.smbParameters.Reserved1 = new byte[packet.smbParameters.Reserved1.Length];
                Array.Copy(packet.smbParameters.Reserved1, this.smbParameters.Reserved1,
                    packet.smbParameters.Reserved1.Length);
            }
            else
            {
                this.smbParameters.Reserved1 = new byte[0];
            }
            this.smbParameters.TotalParameterCount = packet.SmbParameters.TotalParameterCount;
            this.smbParameters.TotalDataCount = packet.SmbParameters.TotalDataCount;
            this.smbParameters.ParameterCount = packet.SmbParameters.ParameterCount;
            this.smbParameters.ParameterOffset = packet.SmbParameters.ParameterOffset;
            this.smbParameters.ParameterDisplacement = packet.SmbParameters.ParameterDisplacement;
            this.smbParameters.DataCount = packet.SmbParameters.DataCount;
            this.smbParameters.DataOffset = packet.SmbParameters.DataOffset;
            this.smbParameters.DataDisplacement = packet.SmbParameters.DataDisplacement;
            this.smbParameters.Reserved2 = packet.SmbParameters.Reserved2;
            this.smbData.ByteCount = packet.SmbData.ByteCount;

            if (packet.smbData.Pad1 != null)
            {
                this.smbData.Pad1 = new byte[packet.smbData.Pad1.Length];
                Array.Copy(packet.smbData.Pad1, this.smbData.Pad1, packet.smbData.Pad1.Length);
            }
            else
            {
                this.smbData.Pad1 = new byte[0];
            }
            this.smbData.NT_Trans_Parameters = new byte[packet.smbParameters.ParameterCount];

            if (packet.smbData.NT_Trans_Parameters != null)
            {
                Array.Copy(packet.smbData.NT_Trans_Parameters,
                    this.smbData.NT_Trans_Parameters, packet.smbParameters.ParameterCount);
            }
            else
            {
                this.smbData.NT_Trans_Parameters = new byte[0];
            }

            if (packet.smbData.Pad2 != null)
            {
                this.smbData.Pad2 = new byte[packet.smbData.Pad2.Length];
                Array.Copy(packet.smbData.Pad2, this.smbData.Pad2, packet.smbData.Pad2.Length);
            }
            else
            {
                this.smbData.Pad2 = new byte[0];
            }
            this.smbData.NT_Trans_Data = new byte[packet.smbParameters.DataCount];

            if (this.smbData.NT_Trans_Data != null)
            {
                Array.Copy(packet.smbData.NT_Trans_Data, this.smbData.NT_Trans_Data, packet.smbParameters.DataCount);
            }
            else
            {
                this.smbData.NT_Trans_Data = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbNtTransactSecondaryRequestPacket(SmbNtTransactSecondaryRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();
            this.smbParameters.WordCount = packet.SmbParameters.WordCount;

            if (packet.smbParameters.Reserved1 != null)
            {
                this.smbParameters.Reserved1 = new byte[packet.smbParameters.Reserved1.Length];
                Array.Copy(packet.smbParameters.Reserved1, this.smbParameters.Reserved1,
                           packet.smbParameters.Reserved1.Length);
            }
            else
            {
                this.smbParameters.Reserved1 = new byte[0];
            }
            this.smbParameters.TotalParameterCount   = packet.SmbParameters.TotalParameterCount;
            this.smbParameters.TotalDataCount        = packet.SmbParameters.TotalDataCount;
            this.smbParameters.ParameterCount        = packet.SmbParameters.ParameterCount;
            this.smbParameters.ParameterOffset       = packet.SmbParameters.ParameterOffset;
            this.smbParameters.ParameterDisplacement = packet.SmbParameters.ParameterDisplacement;
            this.smbParameters.DataCount             = packet.SmbParameters.DataCount;
            this.smbParameters.DataOffset            = packet.SmbParameters.DataOffset;
            this.smbParameters.DataDisplacement      = packet.SmbParameters.DataDisplacement;
            this.smbParameters.Reserved2             = packet.SmbParameters.Reserved2;
            this.smbData.ByteCount = packet.SmbData.ByteCount;

            if (packet.smbData.Pad1 != null)
            {
                this.smbData.Pad1 = new byte[packet.smbData.Pad1.Length];
                Array.Copy(packet.smbData.Pad1, this.smbData.Pad1, packet.smbData.Pad1.Length);
            }
            else
            {
                this.smbData.Pad1 = new byte[0];
            }
            this.smbData.NT_Trans_Parameters = new byte[packet.smbParameters.ParameterCount];

            if (packet.smbData.NT_Trans_Parameters != null)
            {
                Array.Copy(packet.smbData.NT_Trans_Parameters,
                           this.smbData.NT_Trans_Parameters, packet.smbParameters.ParameterCount);
            }
            else
            {
                this.smbData.NT_Trans_Parameters = new byte[0];
            }

            if (packet.smbData.Pad2 != null)
            {
                this.smbData.Pad2 = new byte[packet.smbData.Pad2.Length];
                Array.Copy(packet.smbData.Pad2, this.smbData.Pad2, packet.smbData.Pad2.Length);
            }
            else
            {
                this.smbData.Pad2 = new byte[0];
            }
            this.smbData.NT_Trans_Data = new byte[packet.smbParameters.DataCount];

            if (this.smbData.NT_Trans_Data != null)
            {
                Array.Copy(packet.smbData.NT_Trans_Data, this.smbData.NT_Trans_Data, packet.smbParameters.DataCount);
            }
            else
            {
                this.smbData.NT_Trans_Data = new byte[0];
            }
        }