/// <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_DELETE_Request_SMB_Parameters>( TypeMarshal.ToBytes(this.smbParametersBlock)); }
/// <summary> /// to create a Delete 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="searchAttributes">The file attributes of the file(s) to be deleted. If the value of this /// field is zero, then only normal files MUST be matched for deletion. If the System or Hidden attributes /// MUST be specified, then entries with those attributes are matched in addition to the normal files. /// Read-only files MAY NOT be deleted. The read-only attribute of the file MUST be cleared before the file /// MAY be deleted.</param> /// <param name="fileNames">The pathname of the file(s) to be deleted, relative to the supplied TID. Wildcards /// MAY be used in the filename component of the path.</param> /// <returns>a Delete request packet</returns> public SmbDeleteRequestPacket CreateDeleteRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, SmbFileAttributes searchAttributes, string[] fileNames) { if (fileNames == null) { fileNames = new string[0]; } SmbDeleteRequestPacket packet = new SmbDeleteRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_DELETE, messageId, uid, treeId, flags, flags2); SMB_COM_DELETE_Request_SMB_Parameters smbParameters = new SMB_COM_DELETE_Request_SMB_Parameters(); smbParameters.SearchAttributes = searchAttributes; smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord); SMB_COM_DELETE_Request_SMB_Data smbData = new SMB_COM_DELETE_Request_SMB_Data(); smbData.ByteCount = 0; smbData.BufferFormatAndFileName = new byte[0]; bool isUnicode = (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE; const int bufferFormatSize = 1; // the size in bytes of BufferFormat is always 1. const int nullTerminalSize = 1; // the num of null Terminal character is always 1. foreach (string file in fileNames) { if (isUnicode) { smbData.ByteCount += (byte)(bufferFormatSize + (file.Length + nullTerminalSize) * 2); } else { smbData.ByteCount += (byte)(bufferFormatSize + (file.Length + nullTerminalSize)); } } smbData.BufferFormatAndFileName = new byte[smbData.ByteCount]; int index = 0; foreach (string file in fileNames) { smbData.BufferFormatAndFileName[index++] = (byte)DataBufferFormat.SmbString; byte[] fileNameBytes = CifsMessageUtils.ToSmbStringBytes(file, isUnicode); Array.Copy(fileNameBytes, 0, smbData.BufferFormatAndFileName, index, fileNameBytes.Length); index += fileNameBytes.Length; } packet.SmbParameters = smbParameters; packet.SmbData = smbData; return packet; }