/// <summary> /// Deep copy constructor. /// </summary> public SmbTransaction2SecondaryRequestPacket(SmbTransaction2SecondaryRequestPacket packet) : base(packet) { this.InitDefaultValue(); this.smbParameters.WordCount = packet.SmbParameters.WordCount; 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.FID = packet.SmbParameters.FID; 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]; } if (packet.smbData.Trans2_Parameters != null) { this.smbData.Trans2_Parameters = new byte[packet.smbData.Trans2_Parameters.Length]; Array.Copy(packet.smbData.Trans2_Parameters, this.smbData.Trans2_Parameters, packet.smbData.Trans2_Parameters.Length); } else { this.smbData.Trans2_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]; } if (packet.smbData.Trans2_Data != null) { this.smbData.Trans2_Data = new byte[packet.smbData.Trans2_Data.Length]; Array.Copy(packet.smbData.Trans2_Data, this.smbData.Trans2_Data, packet.smbData.Trans2_Data.Length); } else { this.smbData.Trans2_Data = new byte[0]; } }
/// <summary> /// Deep copy constructor. /// </summary> public SmbTransaction2SecondaryRequestPacket(SmbTransaction2SecondaryRequestPacket packet) : base(packet) { this.InitDefaultValue(); this.smbParameters.WordCount = packet.SmbParameters.WordCount; 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.FID = packet.SmbParameters.FID; 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]; } if (packet.smbData.Trans2_Parameters != null) { this.smbData.Trans2_Parameters = new byte[packet.smbData.Trans2_Parameters.Length]; Array.Copy(packet.smbData.Trans2_Parameters, this.smbData.Trans2_Parameters, packet.smbData.Trans2_Parameters.Length); } else { this.smbData.Trans2_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]; } if (packet.smbData.Trans2_Data != null) { this.smbData.Trans2_Data = new byte[packet.smbData.Trans2_Data.Length]; Array.Copy(packet.smbData.Trans2_Data, this.smbData.Trans2_Data, packet.smbData.Trans2_Data.Length); } else { this.smbData.Trans2_Data = new byte[0]; } }
/// <summary> /// to split a trans2 request to a trans2 request with trans2 secondary requests. /// </summary> /// <param name="trans2Request">the trans2 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 trans2 request with trans2 secondary requests.</returns> public SmbPacket[] CreateTrans2With2ndRequests( SmbTransaction2RequestPacket trans2Request, int parameterCount, int dataCount) { trans2Request.ToBytes(); trans2Request.isDivided = true; int paramLength = 0; if (trans2Request.SmbData.Trans2_Parameters != null) { paramLength = trans2Request.SmbData.Trans2_Parameters.Length; } double paramNumber = Math.Ceiling((double)paramLength / parameterCount); int dataLength = 0; if (trans2Request.SmbData.Trans2_Data != null) { dataLength = trans2Request.SmbData.Trans2_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[] trans2Parameters = trans2Request.SmbData.Trans2_Parameters; byte[] trans2Data = trans2Request.SmbData.Trans2_Data; SMB_COM_TRANSACTION2_Request_SMB_Data trans2SmbData = trans2Request.SmbData; if (paramLength > parameterCount) { trans2SmbData.Trans2_Parameters = new byte[parameterCount]; Array.Copy(trans2Parameters, trans2SmbData.Trans2_Parameters, parameterCount); } if (dataLength > dataCount) { trans2SmbData.Trans2_Data = new byte[dataCount]; Array.Copy(trans2Data, trans2SmbData.Trans2_Data, dataCount); } trans2Request.SmbData = trans2SmbData; trans2Request.UpdateCountAndOffset(); packetList.Add(trans2Request); int currentIndex = 1; int remainedParamCount = trans2Request.SmbParameters.TotalParameterCount - parameterCount; int remainedDataCount = trans2Request.SmbParameters.TotalDataCount - dataCount; while (currentIndex < packetCount) { SmbTransaction2SecondaryRequestPacket packet = new SmbTransaction2SecondaryRequestPacket(); SmbHeader header = trans2Request.SmbHeader; header.Command = SmbCommand.SMB_COM_TRANSACTION2_SECONDARY; packet.SmbHeader = header; // Set Smb_Parameters SMB_COM_TRANSACTION2_SECONDARY_Request_SMB_Parameters smbParameters = new SMB_COM_TRANSACTION2_SECONDARY_Request_SMB_Parameters(); smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize< SMB_COM_TRANSACTION2_SECONDARY_Request_SMB_Parameters>(smbParameters) / NumBytesOfWord); smbParameters.TotalParameterCount = trans2Request.SmbParameters.TotalParameterCount; smbParameters.TotalDataCount = trans2Request.SmbParameters.TotalDataCount; smbParameters.FID = trans2Request.FID; // Set Smb_Data SMB_COM_TRANSACTION2_SECONDARY_Request_SMB_Data smbData = new SMB_COM_TRANSACTION2_SECONDARY_Request_SMB_Data(); if (remainedParamCount > parameterCount) { smbData.Trans2_Parameters = new byte[parameterCount]; Array.Copy(trans2Parameters, parameterCount * currentIndex, smbData.Trans2_Parameters, 0, parameterCount); smbParameters.ParameterDisplacement = (ushort)(parameterCount * currentIndex); remainedParamCount -= parameterCount; } else if (remainedParamCount > 0) { smbData.Trans2_Parameters = new byte[remainedParamCount]; Array.Copy(trans2Parameters, parameterCount * currentIndex, smbData.Trans2_Parameters, 0, remainedParamCount); smbParameters.ParameterDisplacement = (ushort)(parameterCount * currentIndex); remainedParamCount -= parameterCount; } else { smbData.Trans2_Parameters = new byte[0]; } if (remainedDataCount > dataCount) { smbData.Trans2_Data = new byte[dataCount]; Array.Copy(trans2Data, dataCount * currentIndex, smbData.Trans2_Data, 0, dataCount); smbParameters.DataDisplacement = (ushort)(dataCount * currentIndex); remainedDataCount -= dataCount; } else if (remainedDataCount > 0) { smbData.Trans2_Data = new byte[remainedDataCount]; Array.Copy(trans2Data, dataCount * currentIndex, smbData.Trans2_Data, 0, remainedDataCount); smbParameters.DataDisplacement = (ushort)(dataCount * currentIndex); remainedDataCount -= dataCount; } else { smbData.Trans2_Data = new byte[0]; } packet.SmbParameters = smbParameters; packet.SmbData = smbData; currentIndex++; packet.UpdateCountAndOffset(); packetList.Add(packet); } } else { packetList.Add(trans2Request); } return packetList.ToArray(); }