/// <summary> /// Encode the struct of TransData into the byte array in SmbData.Trans_Data /// </summary> protected override void EncodeTransData() { this.smbData.Trans_Data = CifsMessageUtils.ToBytes <ushort>(this.transData.OperationStatus); }
/// <summary> /// Encode the struct of SMB_COM_QUERY_INFORMATION_DISK_Response_SMB_Parameters /// into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_QUERY_INFORMATION_DISK_Response_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_LOGOFF_ANDX_Request_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_LOGOFF_ANDX_Request_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_WRITE_AND_UNLOCK_Response_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_WRITE_AND_UNLOCK_Response_SMB_Data>(this.SmbData)); }
/// <summary> /// Encode the struct of SMB_COM_CHECK_DIRECTORY_Response_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_CHECK_DIRECTORY_Response_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of Trans2Parameters into the byte array in SmbData.Trans2_Parameters /// </summary> protected override void EncodeTrans2Parameters() { this.smbData.Trans2_Parameters = CifsMessageUtils.ToBytes <TRANS2_FIND_NEXT2_Response_Trans2_Parameters>( this.trans2Parameters); }
/// <summary> /// Encode the struct of SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = CifsMessageUtils.ToStuct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_TRANSACTION2_InterimResponse_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_TRANSACTION2_InterimResponse_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_TRANSACTION2_InterimResponse_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_TRANSACTION2_InterimResponse_SMB_Data>(this.SmbData)); }
/// <summary> /// Encode the struct of NtTransParameters into the byte array in SmbData.NT_Trans_Parameters /// </summary> protected override void EncodeNtTransParameters() { this.smbData.Parameters = CifsMessageUtils.ToBytes <NT_TRANSACT_QUERY_QUOTA_Response_NT_Trans_Parameters>( this.ntTransParameters); }
/// <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>( CifsMessageUtils.ToBytes <SmbParameters>(this.smbParametersBlock)); }
/// <summary> /// Encode the struct of NtTransData into the byte array in SmbData.NT_Trans_Data /// </summary> protected override void EncodeNtTransData() { this.smbData.NT_Trans_Data = CifsMessageUtils.ToBytes <NT_TRANSACT_SET_QUOTA_Request_NT_Trans_Data>( this.ntTransData); }
/// <summary> /// Encode the struct of Trans2Data into the byte array in SmbData.Trans2_Data /// </summary> protected override void EncodeTrans2Data() { if (this.trans2Data.Data != null) { Type type = this.trans2Data.Data.GetType(); if (type == typeof(SMB_INFO_STANDARD_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_INFO_STANDARD_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_INFO_STANDARD_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_QUERY_PATH_INFORMATION)) { SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_QUERY_PATH_INFORMATION data = (SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data; if (data.ExtendedAttributeList != null) { this.smbData.Trans2_Data = new byte[data.SizeOfListInBytes]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); channel.Write <uint>(data.SizeOfListInBytes); foreach (SMB_FEA smbEa in data.ExtendedAttributeList) { channel.Write <SMB_FEA>(smbEa); } channel.EndWriteGroup(); } } } } else if (type == typeof(SMB_INFO_QUERY_ALL_EAS_OF_TRANS2_QUERY_PATH_INFORMATION)) { SMB_INFO_QUERY_ALL_EAS_OF_TRANS2_QUERY_PATH_INFORMATION easData = (SMB_INFO_QUERY_ALL_EAS_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data; if (easData.ExtendedAttributeList != null) { this.smbData.Trans2_Data = new byte[easData.SizeOfListInBytes]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); channel.Write <uint>(easData.SizeOfListInBytes); foreach (SMB_FEA smbEa in easData.ExtendedAttributeList) { channel.Write <SMB_FEA>(smbEa); } channel.EndWriteGroup(); } } } } else if (type == typeof(SMB_QUERY_FILE_BASIC_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_BASIC_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_BASIC_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_STANDARD_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_STANDARD_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_STANDARD_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_EA_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_EA_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_EA_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_ALL_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_ALL_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_ALL_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_ALT_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_ALT_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_ALT_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_STREAM_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_STREAM_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_STREAM_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_QUERY_FILE_COMPRESSION_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes < SMB_QUERY_FILE_COMPRESSION_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>( (SMB_QUERY_FILE_COMPRESSION_INFO_OF_TRANS2_QUERY_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(byte[])) { this.smbData.Trans2_Data = (byte[])this.trans2Data.Data; } else { // Branch for negative testing. } } else { this.smbData.Trans2_Data = new byte[0]; } }
/// <summary> /// Encode the struct of SMB_COM_TRANSACTION_SECONDARY_Request_SMB_Parameters /// into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_TRANSACTION_SECONDARY_Request_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_OPEN_PRINT_FILE_Response_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_OPEN_PRINT_FILE_Response_SMB_Data>(this.SmbData)); }
/// <summary> /// marshal the packet to bytes array. /// add TransportHeader(Zero StreamProtocolLength), if not set manually. /// </summary> /// <returns>the bytes of packet </returns> public override byte[] ToBytes() { byte[] packetBytes = packet.ToBytes(); return(ArrayUtility.ConcatenateArrays(CifsMessageUtils.ToBytes(packet.TransportHeader), packetBytes)); }
/// <summary> /// Encode the struct of Trans2Parameters into the byte array in SmbData.Trans2_Parameters /// </summary> protected override void EncodeTrans2Parameters() { this.smbData.Trans2_Parameters = CifsMessageUtils.ToBytes <TRANS2_QUERY_FS_INFORMATION_Request_Trans2_Parameters>( this.trans2Parameters); }
/// <summary> /// Encode the struct of Trans2Parameters into the byte array in SmbData.Trans2_Parameters /// </summary> protected override void EncodeTrans2Parameters() { this.smbData.Trans2_Parameters = CifsMessageUtils.ToBytes <TRANS2_SET_PATH_INFORMATION_Response_Trans2_Parameters>( this.trans2Parameters); }
protected override void EncodeTrans2Data() { int totalSize = 0; int fixedSize = 0; // The fixed size of each structure if (this.trans2Data.Data != null) { Type type = this.trans2Data.Data.GetType(); if (type == typeof(SMB_INFO_STANDARD_OF_TRANS2_FIND_FIRST2[])) { SMB_INFO_STANDARD_OF_TRANS2_FIND_FIRST2[] standardArray = ( SMB_INFO_STANDARD_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = (this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE ? 26 : 24; ushort resumeKeyLength = 4; if (isResumeKeyExisted) { totalSize = (resumeKeyLength + fixedSize) * standardArray.Length; } else { totalSize = fixedSize * standardArray.Length; } for (int i = 0; i < standardArray.Length; i++) { totalSize += standardArray[i].FileNameLength; } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < standardArray.Length; i++) { if (isResumeKeyExisted) { channel.Write <uint>(standardArray[i].ResumeKey); } channel.Write <SmbDate>(standardArray[i].CreationDate); channel.Write <SmbTime>(standardArray[i].CreationTime); channel.Write <SmbDate>(standardArray[i].LastAccessDate); channel.Write <SmbTime>(standardArray[i].LastAccessTime); channel.Write <SmbDate>(standardArray[i].LastWriteDate); channel.Write <SmbTime>(standardArray[i].LastWriteTime); channel.Write <uint>(standardArray[i].DataSize); channel.Write <uint>(standardArray[i].AllocationSize); channel.Write <SmbFileAttributes>(standardArray[i].Attributes); channel.Write <byte>(standardArray[i].FileNameLength); if ((this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { channel.Write <byte>(new byte()); } channel.WriteBytes(standardArray[i].FileName); if ((this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { channel.Write <ushort>(new ushort()); } else { channel.Write <byte>(new byte()); } } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_FIND_FIRST2[])) { SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_FIND_FIRST2[] queryEaArray = ( SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = 28; ushort resumeKeyLength = 4; if (isResumeKeyExisted) { totalSize = (resumeKeyLength + fixedSize) * queryEaArray.Length; } else { totalSize = fixedSize * queryEaArray.Length; } for (int i = 0; i < queryEaArray.Length; i++) { totalSize += queryEaArray[i].FileNameLength; } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < queryEaArray.Length; i++) { if (isResumeKeyExisted) { channel.Write <uint>(queryEaArray[i].ResumeKey); } channel.Write <SmbDate>(queryEaArray[i].CreationDate); channel.Write <SmbTime>(queryEaArray[i].CreationTime); channel.Write <SmbDate>(queryEaArray[i].LastAccessDate); channel.Write <SmbTime>(queryEaArray[i].LastAccessTime); channel.Write <SmbDate>(queryEaArray[i].LastWriteDate); channel.Write <SmbTime>(queryEaArray[i].LastWriteTime); channel.Write <uint>(queryEaArray[i].DataSize); channel.Write <uint>(queryEaArray[i].AllocationSize); channel.Write <SmbFileAttributes>(queryEaArray[i].Attributes); channel.Write <uint>(queryEaArray[i].EaSize); channel.Write <byte>(queryEaArray[i].FileNameLength); channel.WriteBytes(queryEaArray[i].FileName); channel.Write <byte>(new byte()); } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_FIND_FIRST2[])) { SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_FIND_FIRST2[] queryEaFromListArray = ( SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = 24; ushort resumeKeyLength = 4; if (isResumeKeyExisted) { totalSize = (resumeKeyLength + fixedSize) * queryEaFromListArray.Length; } else { totalSize = fixedSize * queryEaFromListArray.Length; } for (int i = 0; i < queryEaFromListArray.Length; i++) { totalSize += (int)(queryEaFromListArray[i].FileNameLength + queryEaFromListArray[i].EaSize); } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < queryEaFromListArray.Length; i++) { if (isResumeKeyExisted) { channel.Write <uint>(queryEaFromListArray[i].ResumeKey); } channel.Write <SmbDate>(queryEaFromListArray[i].CreationDate); channel.Write <SmbTime>(queryEaFromListArray[i].CreationTime); channel.Write <SmbDate>(queryEaFromListArray[i].LastAccessDate); channel.Write <SmbTime>(queryEaFromListArray[i].LastAccessTime); channel.Write <SmbDate>(queryEaFromListArray[i].LastWriteDate); channel.Write <SmbTime>(queryEaFromListArray[i].LastWriteTime); channel.Write <uint>(queryEaFromListArray[i].DataSize); channel.Write <uint>(queryEaFromListArray[i].AllocationSize); channel.Write <SmbFileAttributes>(queryEaFromListArray[i].Attributes); channel.Write <uint>(queryEaFromListArray[i].EaSize); if (queryEaFromListArray[i].ExtendedAttributeList != null) { foreach (SMB_FEA smbEa in queryEaFromListArray[i].ExtendedAttributeList) { channel.Write <SMB_FEA>(smbEa); } } channel.Write <byte>(queryEaFromListArray[i].FileNameLength); channel.WriteBytes(queryEaFromListArray[i].FileName); channel.Write <byte>(new byte()); } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])) { SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] fileInfoArray = ( SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = 64; // Including the fixed length of this structure. totalSize = fixedSize * fileInfoArray.Length; int pad = 0; for (int i = 0; i < fileInfoArray.Length; i++) { totalSize += (int)(fileInfoArray[i].FileNameLength); pad = (int)(fileInfoArray[i].NextEntryOffset - fixedSize - fileInfoArray[i].FileNameLength); if (pad > 0) { totalSize += pad; } } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < fileInfoArray.Length; i++) { fixedSize = 64; // Including the fixed length of this structure. channel.Write <SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>(fileInfoArray[i]); fixedSize += (int)fileInfoArray[i].FileNameLength; // Add the length of file name and pad. pad = (int)(fileInfoArray[i].NextEntryOffset - fixedSize); if (pad > 0) { channel.WriteBytes(new byte[pad]); } } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])) { SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] fullInfoArray = (SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = 68; // Including the fixed length of this structure. totalSize = fixedSize * fullInfoArray.Length; int pad = 0; for (int i = 0; i < fullInfoArray.Length; i++) { totalSize += (int)(fullInfoArray[i].FileNameLength + fullInfoArray[i].EaSize); pad = (int)(fullInfoArray[i].NextEntryOffset - fixedSize - fullInfoArray[i].FileNameLength); if (pad > 0) { totalSize += pad; } } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < fullInfoArray.Length; i++) { fixedSize = 68; // Including the fixed length of this structure. channel.Write <SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>(fullInfoArray[i]); fixedSize += (int)fullInfoArray[i].FileNameLength; // Add the length of file name and pad. pad = (int)(fullInfoArray[i].NextEntryOffset - fixedSize); if (pad > 0) { channel.WriteBytes(new byte[pad]); } } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])) { SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] bothInfoArray = ( SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; List <byte> buffer = new List <byte>(); for (int i = 0; i < bothInfoArray.Length; i++) { SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2 item = bothInfoArray[i]; // update the next entry offset. int len = CifsMessageUtils.GetSize <SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>(item); item.NextEntryOffset = (uint)len; if (i + 1 < bothInfoArray.Length) { item.NextEntryOffset += (uint)CifsMessageUtils.CalculatePadLength(len, 8); } byte[] data = CifsMessageUtils.ToBytes <SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>(item); buffer.AddRange(data); if (i + 1 < bothInfoArray.Length) { // 8 bytes align buffer.AddRange(new byte[CifsMessageUtils.CalculatePadLength(data.Length, 8)]); } } this.smbData.Trans2_Data = buffer.ToArray(); } else if (type == typeof(SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2[])) { SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2[] namesInfoArray = ( SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2[])this.trans2Data.Data; fixedSize = 12; // Including the fixed length of this structure. totalSize = fixedSize * namesInfoArray.Length; int pad = 0; for (int i = 0; i < namesInfoArray.Length; i++) { totalSize += (int)(namesInfoArray[i].FileNameLength); pad = (int)(namesInfoArray[i].NextEntryOffset - fixedSize - namesInfoArray[i].FileNameLength); if (pad > 0) { totalSize += pad; } } this.smbData.Trans2_Data = new byte[totalSize]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); for (int i = 0; i < namesInfoArray.Length; i++) { fixedSize = 12; // Including the fixed length of this structure. channel.Write <SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2>(namesInfoArray[i]); fixedSize += (int)namesInfoArray[i].FileNameLength; // Add the length of file name. pad = (int)(namesInfoArray[i].NextEntryOffset - fixedSize); if (pad > 0) { channel.WriteBytes(new byte[pad]); } } channel.EndWriteGroup(); } } } else { // Branch for negative testing. } } else { this.smbData.Trans2_Data = new byte[0]; } }
/// <summary> /// to decode the smb data: from the general SmbDada to the concrete Smb Data. /// </summary> protected override void DecodeData() { if (this.SmbDataBlock.ByteCount > 0) { using (MemoryStream stream = new MemoryStream(CifsMessageUtils.ToBytes <SmbData>(this.smbDataBlock))) { using (Channel channel = new Channel(null, stream)) { this.smbData.ByteCount = channel.Read <ushort>(); this.smbData.SecurityBlob = channel.ReadBytes(this.SmbParameters.SecurityBlobLength); // pad: if ((Marshal.SizeOf(this.SmbHeader) + Marshal.SizeOf(this.SmbParameters) + Marshal.SizeOf(this.smbData.ByteCount) + this.SmbParameters.SecurityBlobLength) % 2 != 0) { this.smbData.Pad = channel.ReadBytes(1); } else { this.smbData.Pad = new byte[0]; } // NativeOS: int nativeOSLen = 0; while (true) { if ((this.SmbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { byte data0 = channel.Peek <byte>(nativeOSLen++); byte data1 = channel.Peek <byte>(nativeOSLen++); if (data0 == 0 && data1 == 0) { break; } } else { byte data = channel.Peek <byte>(nativeOSLen++); if (data == 0) { break; } } } this.smbData.NativeOS = channel.ReadBytes(nativeOSLen); // NativeLanMan int nativeLanManLen = 0; while (true) { if ((this.SmbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { byte data0 = channel.Peek <byte>(nativeLanManLen++); byte data1 = channel.Peek <byte>(nativeLanManLen++); if (data0 == 0 && data1 == 0) { break; } } else { byte data = channel.Peek <byte>(nativeLanManLen++); if (data == 0) { break; } } } this.smbData.NativeLanMan = channel.ReadBytes(nativeLanManLen); } } } else { this.smbData.ByteCount = this.SmbDataBlock.ByteCount; } }
/// <summary> /// Encode the struct of SMB_COM_WRITE_AND_UNLOCK_Response_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_WRITE_AND_UNLOCK_Response_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_SESSION_SETUP_ANDX_Request_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = CifsMessageUtils.ToStuct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_SESSION_SETUP_ANDX_Request_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of TransParameters into the byte array in SmbData.Trans_Parameters /// </summary> protected override void EncodeTransParameters() { this.smbData.Trans_Parameters = CifsMessageUtils.ToBytes <TRANS_WRITE_NMPIPE_Response_Trans_Parameters>(this.transParameters); }
/// <summary> /// Encode the struct of Trans2Data into the byte array in SmbData.Trans2_Data /// </summary> protected override void EncodeTrans2Data() { if (this.trans2Data.Data != null) { Type type = this.trans2Data.Data.GetType(); if (type == typeof(SMB_INFO_STANDARD_OF_TRANS2_SET_PATH_INFORMATION)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes <SMB_INFO_STANDARD_OF_TRANS2_SET_PATH_INFORMATION>( (SMB_INFO_STANDARD_OF_TRANS2_SET_PATH_INFORMATION)this.trans2Data.Data); } else if (type == typeof(SMB_INFO_SET_EAS)) { SMB_INFO_SET_EAS data = (SMB_INFO_SET_EAS)this.trans2Data.Data; this.smbData.Trans2_Data = new byte[sizeOfListInBytesLength + CifsMessageUtils.GetSmbEAListSize( data.ExtendedAttributeList)]; using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data)) { using (Channel channel = new Channel(null, memoryStream)) { channel.BeginWriteGroup(); channel.Write <uint>(data.SizeOfListInBytes); if (data.ExtendedAttributeList != null) { foreach (SMB_FEA smbEa in data.ExtendedAttributeList) { channel.Write <byte>(smbEa.ExtendedAttributeFlag); channel.Write <byte>(smbEa.AttributeNameLengthInBytes); channel.Write <ushort>(smbEa.ValueNameLengthInBytes); if (smbEa.AttributeName != null) { channel.WriteBytes(smbEa.AttributeName); } if (smbEa.ValueName != null) { channel.WriteBytes(smbEa.ValueName); } } } channel.EndWriteGroup(); } } } else if (type == typeof(SMB_SET_FILE_BASIC_INFO)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes <SMB_SET_FILE_BASIC_INFO>( (SMB_SET_FILE_BASIC_INFO)this.trans2Data.Data); } else if (type == typeof(SMB_SET_FILE_ALLOCATION_INFO)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes <SMB_SET_FILE_ALLOCATION_INFO>( (SMB_SET_FILE_ALLOCATION_INFO)this.trans2Data.Data); } else if (type == typeof(SMB_SET_FILE_DISPOSITION_INFO)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes <SMB_SET_FILE_DISPOSITION_INFO>( (SMB_SET_FILE_DISPOSITION_INFO)this.trans2Data.Data); } else if (type == typeof(SMB_SET_FILE_END_OF_FILE_INFO)) { this.smbData.Trans2_Data = CifsMessageUtils.ToBytes <SMB_SET_FILE_END_OF_FILE_INFO>( (SMB_SET_FILE_END_OF_FILE_INFO)this.trans2Data.Data); } else { // Branch for negative testing. } } else { this.smbData.Trans2_Data = new byte[0]; } }
/// <summary> /// Encode the struct of SMB_COM_CHECK_DIRECTORY_Response_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_CHECK_DIRECTORY_Response_SMB_Data>(this.SmbData)); }
/// <summary> /// Encode the struct of NtTransParameters into the byte array in SmbData.NT_Trans_Parameters /// </summary> protected override void EncodeNtTransParameters() { this.smbData.NT_Trans_Parameters = CifsMessageUtils.ToBytes <NT_TRANSACT_SET_SECURITY_DESC_Request_NT_Trans_Parameters>( this.ntTransParameters); }
/// <summary> /// Encode the struct of SMB_COM_QUERY_INFORMATION_DISK_Response_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_QUERY_INFORMATION_DISK_Response_SMB_Data>(this.SmbData)); }
/// <summary> /// Encode the struct of SMB_COM_OPEN_PRINT_FILE_Response_SMB_Parameters into the struct of SmbParameters /// </summary> protected override void EncodeParameters() { this.smbParametersBlock = TypeMarshal.ToStruct <SmbParameters>( CifsMessageUtils.ToBytes <SMB_COM_OPEN_PRINT_FILE_Response_SMB_Parameters>(this.smbParameters)); }
/// <summary> /// Encode the struct of SMB_COM_LOGOFF_ANDX_Request_SMB_Data into the struct of SmbData /// </summary> protected override void EncodeData() { this.smbDataBlock = TypeMarshal.ToStruct <SmbData>( CifsMessageUtils.ToBytes <SMB_COM_LOGOFF_ANDX_Request_SMB_Data>(this.SmbData)); }
/// <summary> /// Encode the struct of TransParameters into the byte array in SmbData.Trans_Parameters /// </summary> protected override void EncodeTransParameters() { this.smbData.Trans_Parameters = CifsMessageUtils.ToBytes <TRANS_SET_NMPIPE_STATE_RequestTransParameters>( this.transParameters); }