Ejemplo n.º 1
0
        /// <summary>
        /// to decode the Trans2 data: from the general Trans2Dada to the concrete Trans2 Data.
        /// </summary>
        protected override void DecodeTrans2Data()
        {
            if (this.smbData.Trans2_Data != null && this.smbData.Trans2_Data.Length > 0)
            {
                switch (this.trans2Parameters.InformationLevel)
                {
                case SetInformationLevel.SMB_INFO_STANDARD:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct
                                           <SMB_INFO_STANDARD_OF_TRANS2_SET_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case SetInformationLevel.SMB_INFO_SET_EAS:
                    using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                    {
                        using (Channel channel = new Channel(null, memoryStream))
                        {
                            SMB_INFO_SET_EAS data = new SMB_INFO_SET_EAS();
                            data.SizeOfListInBytes = channel.Read <uint>();
                            uint           sizeOfListInBytes = data.SizeOfListInBytes - sizeOfListInBytesLength;
                            List <SMB_FEA> attributeList     = new List <SMB_FEA>();

                            while (sizeOfListInBytes > 0)
                            {
                                SMB_FEA smbEa = channel.Read <SMB_FEA>();
                                attributeList.Add(smbEa);
                                sizeOfListInBytes -= (uint)(EA.SMB_EA_FIXED_SIZE + smbEa.AttributeName.Length +
                                                            smbEa.ValueName.Length);
                            }
                            data.ExtendedAttributeList = attributeList.ToArray();
                            this.trans2Data.Data       = data;
                        }
                    }
                    break;

                case SetInformationLevel.SMB_SET_FILE_BASIC_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct
                                           <SMB_SET_FILE_BASIC_INFO>(this.smbData.Trans2_Data);
                    break;

                case SetInformationLevel.SMB_SET_FILE_ALLOCATION_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct
                                           <SMB_SET_FILE_ALLOCATION_INFO>(this.smbData.Trans2_Data);
                    break;

                case SetInformationLevel.SMB_SET_FILE_DISPOSITION_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct
                                           <SMB_SET_FILE_DISPOSITION_INFO>(this.smbData.Trans2_Data);
                    break;

                case SetInformationLevel.SMB_SET_FILE_END_OF_FILE_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct
                                           <SMB_SET_FILE_END_OF_FILE_INFO>(this.smbData.Trans2_Data);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <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
                {
                    // Branch for negative testing.
                }
            }
            else
            {
                this.smbData.Trans2_Data = new byte[0];
            }
        }