/// <summary> /// to decode the smb parameters: from the general SmbParameters to the concrete Smb Parameters. /// </summary> protected override void DecodeParameters() { this.smbParameters = TypeMarshal.ToStruct<SMB_COM_IOCTL_Request_SMB_Parameters>( TypeMarshal.ToBytes(this.smbParametersBlock)); }
/// <summary> /// to create an IoctlSecondary request packet. /// </summary> /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a /// request.</param> /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param> /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is /// accessing.</param> /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the /// message</param> /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the /// message. Unspecified bits are reserved and MUST be zero.</param> /// <param name="fid">The Fid of the device or file to which the IOCTL is to be sent.</param> /// <param name="category">The implementation dependent device category for the request.</param> /// <param name="function">The implementation dependent device function for the request.</param> /// <param name="maxParameterCount">The maximum number of SMB_Data.Parameters bytes that the client accepts in /// the IOCTL response. The server MUST NOT return more than this number of bytes in the SMB_Data.Parameter /// field of the response.</param> /// <param name="maxDataCount">The maximum number of SMB_Data.Data bytes that the client accepts in the IOCTL /// response. The server MUST NOT return more than this number of bytes in the SMB_Data.Data field.</param> /// <param name="timeout"> the maximum number of milliseconds the server SHOULD wait for completion of the /// transaction before generating a timeout and returning a response to the client. The client SHOULD set /// this to 0 to indicate that no time-out is expected.</param> /// <param name="parameters">IOCTL parameter bytes. The contents are implementation dependent.</param> /// <param name="data">Transaction data bytes. The contents are implementation dependent.</param> /// <returns>a IoctlSecondary request packet</returns> public SmbIoctlSecondaryRequestPacket CreateIoctlSecondaryRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, ushort fid, IoctlCategory category, IoctlFunction function, ushort maxParameterCount, ushort maxDataCount, uint timeout, byte[] parameters, byte[] data) { if (parameters == null) { parameters = new byte[0]; } if (data == null) { data = new byte[0]; } SmbIoctlSecondaryRequestPacket packet = new SmbIoctlSecondaryRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_IOCTL_SECONDARY, messageId, uid, treeId, flags, flags2); SMB_COM_IOCTL_Request_SMB_Parameters smbParameters = new SMB_COM_IOCTL_Request_SMB_Parameters(); smbParameters.FID = fid; smbParameters.Category = category; smbParameters.Function = function; smbParameters.MaxParameterCount = maxParameterCount; smbParameters.TotalParameterCount = (ushort)parameters.Length; smbParameters.ParameterCount = (ushort)parameters.Length; smbParameters.MaxDataCount = maxDataCount; smbParameters.TotalDataCount = (ushort)data.Length; smbParameters.DataCount = (ushort)data.Length; smbParameters.Timeout = timeout; smbParameters.Reserved = 0; smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord); SMB_COM_IOCTL_Request_SMB_Data smbData = new SMB_COM_IOCTL_Request_SMB_Data(); // The size of the preceding SmbParameters part plus Header part is an odd number for all cifs messages // If the format is Unicode, needs to add one 16 bits align pad if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { // pad 1 byte for 16-bits align: smbData.Pad1 = new byte[1]; } else { smbData.Pad1 = new byte[0]; } smbData.Parameters = parameters; // pad 1 byte for 16-bits align of needed: smbData.Pad2 = new byte[smbData.Parameters.Length % twoBytesAlign]; smbData.Data = data; smbData.ByteCount = (ushort)(smbData.Pad1.Length + smbData.Parameters.Length + smbData.Pad2.Length + smbData.Data.Length); smbParameters.ParameterOffset = (ushort)(Marshal.SizeOf(packet.SmbHeader) + Marshal.SizeOf(smbParameters) + Marshal.SizeOf(smbData.ByteCount) + smbData.Pad1.Length); smbParameters.DataOffset = (ushort)(smbParameters.ParameterOffset + smbData.Parameters.Length + smbData.Pad2.Length); packet.SmbParameters = smbParameters; packet.SmbData = smbData; return packet; }