/// <summary> /// to decode the smb data: from the general SmbDada to the concrete Smb Data. /// </summary> protected override void DecodeData() { this.smbData = TypeMarshal.ToStruct<SMB_COM_WRITE_AND_CLOSE_Request_SMB_Data>( TypeMarshal.ToBytes(this.smbDataBlock)); }
/// <summary> /// to create a WriteAndClose 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">This field MUST be a valid 16-bit signed integer indicating the file to which the data /// SHOULD be written.</param> /// <param name="writeOffsetInBytes">This field is a 16-bit unsigned integer indicating the number of bytes to /// be written to the file</param> /// <param name="lastWriteTime">This field is a 32-bit unsigned integer indicating the number of seconds since /// Jan 1, 1970, 00:00:00.0. The server SHOULD set the last write time of the file represented by the FID to /// this value. If the value is zero (0), the server SHOULD use the current local time of the server to set the /// value. Failure to set the time MUST not result in an error response from the server.</param> /// <param name="data">The raw bytes to be written to the file</param> /// <returns>a WriteAndClose request packet</returns> public SmbWriteAndCloseRequestPacket CreateWriteAndCloseRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, ushort fid, uint writeOffsetInBytes, UTime lastWriteTime, byte[] data) { if (data == null) { data = new byte[0]; } SmbWriteAndCloseRequestPacket packet = new SmbWriteAndCloseRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_WRITE_AND_CLOSE, messageId, uid, treeId, flags, flags2); SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters smbParameters = new SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters(); smbParameters.FID = fid; smbParameters.CountOfBytesToWrite = (ushort)data.Length; smbParameters.WriteOffsetInBytes = writeOffsetInBytes; smbParameters.LastWriteTime = lastWriteTime; smbParameters.Reserved = new uint[3]; // the correct length of Reserved word is always 3. smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_WRITE_AND_CLOSE_Request_SMB_Parameters>( smbParameters) / NumBytesOfWord); SMB_COM_WRITE_AND_CLOSE_Request_SMB_Data smbData = new SMB_COM_WRITE_AND_CLOSE_Request_SMB_Data(); smbData.Pad = 0; smbData.Data = data; smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.Pad) + smbData.Data.Length); packet.SmbParameters = smbParameters; packet.SmbData = smbData; return packet; }