Пример #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;
                }
            }
        }
        /// <summary>
        /// to decode the Trans2 data: from the general Trans2Dada to the concrete Trans2 Data.
        /// </summary>
        protected override void DecodeTrans2Data()
        {
            using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
            {
                using (Channel channel = new Channel(null, memoryStream))
                {
                    this.trans2Data.ExtendedAttributeList.SizeOfListInBytes = channel.Read <uint>();
                    uint sizeOfListInBytes =
                        this.trans2Data.ExtendedAttributeList.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);
                    }
                    this.trans2Data.ExtendedAttributeList.FEAList = attributeList.ToArray();
                }
            }
        }
        protected override void DecodeTrans2Data()
        {
            if (this.smbData.Trans2_Data != null && this.smbData.Trans2_Data.Length > 0)
            {
                using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                {
                    using (Channel channel = new Channel(null, memoryStream))
                    {
                        switch (this.informationLevel)
                        {
                        case FindInformationLevel.SMB_INFO_STANDARD:
                            SMB_INFO_STANDARD_OF_TRANS2_FIND_FIRST2[] standardArray =
                                new SMB_INFO_STANDARD_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < standardArray.Length; i++)
                            {
                                if (isResumeKeyExisted)
                                {
                                    standardArray[i].ResumeKey = channel.Read <uint>();
                                }
                                standardArray[i].CreationDate   = channel.Read <SmbDate>();
                                standardArray[i].CreationTime   = channel.Read <SmbTime>();
                                standardArray[i].LastAccessDate = channel.Read <SmbDate>();
                                standardArray[i].LastAccessTime = channel.Read <SmbTime>();
                                standardArray[i].LastWriteDate  = channel.Read <SmbDate>();
                                standardArray[i].LastWriteTime  = channel.Read <SmbTime>();
                                standardArray[i].DataSize       = channel.Read <uint>();
                                standardArray[i].AllocationSize = channel.Read <uint>();
                                standardArray[i].Attributes     = channel.Read <SmbFileAttributes>();
                                standardArray[i].FileNameLength = channel.Read <byte>();

                                if ((this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
                                {
                                    channel.Read <byte>();
                                }
                                standardArray[i].FileName = channel.ReadBytes(standardArray[i].FileNameLength);

                                if ((this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
                                {
                                    channel.Read <ushort>();
                                }
                                else
                                {
                                    channel.Read <byte>();
                                }
                            }
                            this.trans2Data.Data = standardArray;
                            break;

                        case FindInformationLevel.SMB_INFO_QUERY_EA_SIZE:
                            SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_FIND_FIRST2[] queryEaArray =
                                new SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < queryEaArray.Length; i++)
                            {
                                if (isResumeKeyExisted)
                                {
                                    queryEaArray[i].ResumeKey = channel.Read <uint>();
                                }
                                queryEaArray[i].CreationDate   = channel.Read <SmbDate>();
                                queryEaArray[i].CreationTime   = channel.Read <SmbTime>();
                                queryEaArray[i].LastAccessDate = channel.Read <SmbDate>();
                                queryEaArray[i].LastAccessTime = channel.Read <SmbTime>();
                                queryEaArray[i].LastWriteDate  = channel.Read <SmbDate>();
                                queryEaArray[i].LastWriteTime  = channel.Read <SmbTime>();
                                queryEaArray[i].DataSize       = channel.Read <uint>();
                                queryEaArray[i].AllocationSize = channel.Read <uint>();
                                queryEaArray[i].Attributes     = channel.Read <SmbFileAttributes>();
                                queryEaArray[i].EaSize         = channel.Read <uint>();
                                queryEaArray[i].FileNameLength = channel.Read <byte>();
                                queryEaArray[i].FileName       = channel.ReadBytes(queryEaArray[i].FileNameLength);
                                channel.Read <byte>();
                            }
                            this.trans2Data.Data = queryEaArray;
                            break;

                        case FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
                            SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_FIND_FIRST2[] queryEaFromListArray =
                                new SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < queryEaFromListArray.Length; i++)
                            {
                                if (isResumeKeyExisted)
                                {
                                    queryEaFromListArray[i].ResumeKey = channel.Read <uint>();
                                }
                                queryEaFromListArray[i].CreationDate   = channel.Read <SmbDate>();
                                queryEaFromListArray[i].CreationTime   = channel.Read <SmbTime>();
                                queryEaFromListArray[i].LastAccessDate = channel.Read <SmbDate>();
                                queryEaFromListArray[i].LastAccessTime = channel.Read <SmbTime>();
                                queryEaFromListArray[i].LastWriteDate  = channel.Read <SmbDate>();
                                queryEaFromListArray[i].LastWriteTime  = channel.Read <SmbTime>();
                                queryEaFromListArray[i].DataSize       = channel.Read <uint>();
                                queryEaFromListArray[i].AllocationSize = channel.Read <uint>();
                                queryEaFromListArray[i].Attributes     = channel.Read <SmbFileAttributes>();
                                queryEaFromListArray[i].EaSize         = channel.Read <uint>();
                                uint           eaSize        = queryEaFromListArray[i].EaSize - eaSizeLength;
                                List <SMB_FEA> attributeList = new List <SMB_FEA>();

                                while (eaSize > 0)
                                {
                                    SMB_FEA smbEa = channel.Read <SMB_FEA>();
                                    attributeList.Add(smbEa);
                                    eaSize -= (uint)(EA.SMB_EA_FIXED_SIZE + smbEa.AttributeName.Length +
                                                     smbEa.ValueName.Length);
                                }
                                queryEaFromListArray[i].ExtendedAttributeList = attributeList.ToArray();
                                queryEaFromListArray[i].FileNameLength        = channel.Read <byte>();
                                queryEaFromListArray[i].FileName = channel.ReadBytes(queryEaFromListArray[i].FileNameLength);
                                channel.Read <byte>();
                            }
                            this.trans2Data.Data = queryEaFromListArray;
                            break;

                        case FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO:
                            SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] fileInfoArray =
                                new SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < fileInfoArray.Length; i++)
                            {
                                uint fixedSize = 64;                                // Including the fixed length of this structure.
                                fileInfoArray[i] = channel.Read <SMB_FIND_FILE_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>();
                                fixedSize       += fileInfoArray[i].FileNameLength; // Add the length of file name and pad.
                                int pad = (int)(fileInfoArray[i].NextEntryOffset - fixedSize);

                                if (pad > 0)
                                {
                                    channel.ReadBytes(pad);
                                }
                            }
                            this.trans2Data.Data = fileInfoArray;
                            break;

                        case FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO:
                            SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] fullInfoArray =
                                new SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < fullInfoArray.Length; i++)
                            {
                                uint fixedSize = 68;                                // Including the fixed length of this structure.
                                fullInfoArray[i] = channel.Read <SMB_FIND_FILE_FULL_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2>();
                                fixedSize       += fullInfoArray[i].FileNameLength; // Add the length of file name and pad.
                                int pad = (int)(fullInfoArray[i].NextEntryOffset - fixedSize);

                                if (pad > 0)
                                {
                                    channel.ReadBytes(pad);
                                }
                            }
                            this.trans2Data.Data = fullInfoArray;
                            break;

                        case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
                            SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[] bothInfoArray =
                                new SMB_FIND_FILE_BOTH_DIRECTORY_INFO_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < bothInfoArray.Length; i++)
                            {
                                uint fixedSize = 94;     // Including the fixed length of this structure.

                                bothInfoArray[i].NextEntryOffset = channel.Read <uint>();
                                bothInfoArray[i].FileIndex       = channel.Read <uint>();
                                bothInfoArray[i].CreationTime    = channel.Read <FileTime>();
                                bothInfoArray[i].LastAccessTime  = channel.Read <FileTime>();
                                bothInfoArray[i].LastWriteTime   = channel.Read <FileTime>();
                                bothInfoArray[i].LastChangeTime  = channel.Read <FileTime>();
                                bothInfoArray[i].EndOfFile       = channel.Read <ulong>();
                                bothInfoArray[i].AllocationSize  = channel.Read <ulong>();
                                bothInfoArray[i].FileAttributes  = channel.Read <SmbFileAttributes32>();
                                bothInfoArray[i].FileNameLength  = channel.Read <uint>();
                                bothInfoArray[i].EaSize          = channel.Read <uint>();
                                bothInfoArray[i].ShortNameLength = channel.Read <byte>();
                                bothInfoArray[i].Reserved        = channel.Read <byte>();
                                bothInfoArray[i].ShortName       = channel.ReadBytes(24);
                                bothInfoArray[i].FileName        = channel.ReadBytes((int)bothInfoArray[i].FileNameLength);
                                fixedSize += bothInfoArray[i].FileNameLength;     // Add the length of file name.
                                int pad = (int)(bothInfoArray[i].NextEntryOffset - fixedSize);

                                if (pad > 0)
                                {
                                    channel.ReadBytes(pad);
                                }
                            }
                            this.trans2Data.Data = bothInfoArray;
                            break;

                        case FindInformationLevel.SMB_FIND_FILE_NAMES_INFO:
                            SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2[] namesInfoArray =
                                new SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2[this.trans2Parameters.SearchCount];

                            for (int i = 0; i < namesInfoArray.Length; i++)
                            {
                                uint fixedSize = 12;                                  // Including the fixed length of this structure.
                                namesInfoArray[i] = channel.Read <SMB_FIND_FILE_NAMES_INFO_OF_TRANS2_FIND_FIRST2>();
                                fixedSize        += namesInfoArray[i].FileNameLength; // Add the length of file name.
                                int pad = (int)(namesInfoArray[i].NextEntryOffset - fixedSize);

                                if (pad > 0)
                                {
                                    channel.ReadBytes(pad);
                                }
                            }
                            this.trans2Data.Data = namesInfoArray;
                            break;
                        }
                    }
                }
            }
        }
        protected override void DecodeTrans2Data()
        {
            if (this.smbData.Trans2_Data != null && this.smbData.Trans2_Data.Length > 0)
            {
                switch (this.informationLevel)
                {
                case QueryInformationLevel.SMB_INFO_STANDARD:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_INFO_STANDARD_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_INFO_QUERY_EA_SIZE:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_INFO_QUERY_EA_SIZE_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST:
                    if (this.smbData.Trans2_Data != null && this.smbData.Trans2_Data.Length > 0)
                    {
                        using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                        {
                            using (Channel channel = new Channel(null, memoryStream))
                            {
                                SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_QUERY_PATH_INFORMATION data = new
                                                                                                     SMB_INFO_QUERY_EAS_FROM_LIST_OF_TRANS2_QUERY_PATH_INFORMATION();
                                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 QueryInformationLevel.SMB_INFO_QUERY_ALL_EAS:
                    if (this.smbData.Trans2_Data != null && this.smbData.Trans2_Data.Length > 0)
                    {
                        using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                        {
                            using (Channel channel = new Channel(null, memoryStream))
                            {
                                SMB_INFO_QUERY_ALL_EAS_OF_TRANS2_QUERY_PATH_INFORMATION easData = new
                                                                                                  SMB_INFO_QUERY_ALL_EAS_OF_TRANS2_QUERY_PATH_INFORMATION();
                                easData.SizeOfListInBytes = channel.Read <uint>();
                                uint           sizeOfList = easData.SizeOfListInBytes - sizeOfListInBytesLength;
                                List <SMB_FEA> eaList     = new List <SMB_FEA>();

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

                case QueryInformationLevel.SMB_QUERY_FILE_BASIC_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_BASIC_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_STANDARD_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_STANDARD_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_EA_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_EA_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_NAME_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_ALL_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_ALT_NAME_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_ALT_NAME_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_STREAM_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_STREAM_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;

                case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO:
                    this.trans2Data.Data = CifsMessageUtils.ToStuct <
                        SMB_QUERY_FILE_COMPRESSION_INFO_OF_TRANS2_QUERY_PATH_INFORMATION>(this.smbData.Trans2_Data);
                    break;
                }
            }
        }