当前位置: 首页>>代码示例>>C#>>正文


C# Channel.Read方法代码示例

本文整理汇总了C#中Channel.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.Read方法的具体用法?C# Channel.Read怎么用?C# Channel.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Channel的用法示例。


在下文中一共展示了Channel.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadNtAsciiStringBuffer

        /// <summary>
        /// Read null terminated ASCII string buffer from the current position of channel
        /// </summary>
        /// <param name="channel">The ptf channel</param>
        /// <returns>The read string buffer, null terminator included</returns>
        /// <exception cref="System.InvalidOperationException">Thrown when can't get the string buffer</exception>
        public static byte[] ReadNtAsciiStringBuffer(Channel channel)
        {
            List<byte> ntStringList = new List<byte>();

            while (channel.Stream.Position < channel.Stream.Length)
            {
                byte temp = channel.Read<byte>();
                ntStringList.Add(temp);
                if (temp == 0)
                {
                    return ntStringList.ToArray();
                }
            }

            throw new InvalidOperationException(
                "Reach the end of the channel stream, but still can't find the terminator");
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:23,代码来源:ChannelHelper.cs

示例2: DecodeTrans2Parameters

 /// <summary>
 /// to decode the Trans2 parameters: from the general Trans2Parameters to the concrete Trans2 Parameters.
 /// </summary>
 protected override void DecodeTrans2Parameters()
 {
     using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Parameters))
     {
         using (Channel channel = new Channel(null, memoryStream))
         {
             this.trans2Parameters.InformationLevel = channel.Read<SetInformationLevel>();
             this.trans2Parameters.Reserved = channel.Read<uint>();
             this.trans2Parameters.FileName = channel.ReadBytes(this.smbParameters.ParameterCount - infoLevelLength
                 - reservedLength);
         }
     }
 }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:16,代码来源:SmbTrans2SetPathInformationRequestPacket.cs

示例3: ReadDataFromChannel

        /// <summary>
        /// to unmarshal the SmbDada struct from a channel. the open response need to parse specially, because its 
        /// data only contains a ByteCount. 
        /// </summary>
        /// <param name = "channel">the channel started with SmbDada. </param>
        /// <returns>the size in bytes of the SmbDada. </returns>
        protected override int ReadDataFromChannel(Channel channel)
        {
            this.smbDataBlock.ByteCount = channel.Read<ushort>();

            this.DecodeData();

            return 2;
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:14,代码来源:SmbOpenAndxResponsePacket.cs

示例4: DecodeTrans2Data

        /// <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)
            {
                using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                {
                    using (Channel channel = new Channel(null, memoryStream))
                    {
                        this.trans2Data.ReferralResponse.PathConsumed = channel.Read<ushort>();
                        this.trans2Data.ReferralResponse.NumberOfReferrals = channel.Read<ushort>();
                        this.trans2Data.ReferralResponse.ReferralHeaderFlags = channel.Read<ReferralHeaderFlags>();

                        if (this.trans2Data.ReferralResponse.NumberOfReferrals == 0)
                        {
                            return;
                        }

                        ushort versionNumber = channel.Peek<ushort>(0);

                        switch (versionNumber)
                        {
                            case 0x0001:
                                List<DFS_REFERRAL_V1> referral1List = new List<DFS_REFERRAL_V1>();

                                for (int i = 0; i < this.trans2Data.ReferralResponse.NumberOfReferrals; i++)
                                {
                                    referral1List.Add(channel.Read<DFS_REFERRAL_V1>());
                                }
                                this.trans2Data.ReferralResponse.ReferralEntries = referral1List.ToArray();
                                break;

                            case 0x0002:
                                List<DFS_REFERRAL_V2> referral2List = new List<DFS_REFERRAL_V2>();

                                for (int i = 0; i < this.trans2Data.ReferralResponse.NumberOfReferrals; i++)
                                {
                                    DFS_REFERRAL_V2 referral2 = new DFS_REFERRAL_V2();
                                    referral2.VersionNumber = channel.Read<ushort>();
                                    referral2.Size = channel.Read<ushort>();
                                    referral2.ServerType = channel.Read<ushort>();
                                    referral2.ReferralEntryFlags = channel.Read<ushort>();
                                    referral2.Proximity = channel.Read<uint>();
                                    referral2.TimeToLive = channel.Read<uint>();
                                    referral2.DFSPathOffset = channel.Read<ushort>();
                                    referral2.DFSAlternatePathOffset = channel.Read<ushort>();
                                    referral2.NetworkAddressOffset = channel.Read<ushort>();
                                    referral2List.Add(referral2);
                                }
                                int fixedListSize = this.trans2Data.ReferralResponse.NumberOfReferrals * referralV2FixedSize;
                                byte[] pathData = channel.ReadBytes(this.smbData.Trans2_Data.Length - fixedListSize
                                    - referralHeaderSize);

                                for (int i = 0; i < referral2List.Count; i++)
                                {
                                    int leftCount = referral2List.Count - i;
                                    DFS_REFERRAL_V2 referral2 = referral2List[i];
                                    int dfsPathOffset = referral2.DFSPathOffset - leftCount * referralV2FixedSize;
                                    int dfsAlternatePathOffset = referral2.DFSAlternatePathOffset -
                                        leftCount * referralV2FixedSize;
                                    int targetPathOffset = referral2.NetworkAddressOffset - leftCount * referralV2FixedSize;
                                    int pathLength = 0;
                                    byte wordLength = 2;

                                    for (int j = dfsPathOffset; ; j += wordLength)
                                    {
                                        if (pathData[j] == 0 && pathData[j + 1] == 0)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            pathLength += wordLength;
                                        }
                                    }
                                    referral2.DFSPath = Encoding.Unicode.GetString(pathData, dfsPathOffset, pathLength);
                                    pathLength = 0;

                                    for (int j = dfsAlternatePathOffset; ; j += wordLength)
                                    {
                                        if (pathData[j] == 0 && pathData[j + 1] == 0)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            pathLength += wordLength;
                                        }
                                    }
                                    referral2.DFSAlternatePath = Encoding.Unicode.GetString(pathData, dfsAlternatePathOffset,
                                        pathLength);
                                    pathLength = 0;

                                    for (int j = targetPathOffset; ; j += wordLength)
                                    {
                                        if (pathData[j] == 0 && pathData[j + 1] == 0)
                                        {
                                            break;
//.........这里部分代码省略.........
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:101,代码来源:SmbTrans2GetDfsReferalFinalResponsePacket.cs

示例5: DecodeTransData

        /// <summary>
        /// to decode the Trans data: from the general TransDada to the concrete Trans Data.
        /// </summary>
        protected override void DecodeTransData()
        {
            if (this.smbData.Trans_Data != null && this.smbData.Trans_Data.Length > 0)
            {
                using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans_Data))
                {
                    using (Channel channel = new Channel(null, memoryStream))
                    {
                        this.transData.OutputBufferSize = channel.Read<ushort>();
                        this.transData.InputBufferSize = channel.Read<ushort>();
                        this.transData.MaximumInstances = channel.Read<byte>();
                        this.transData.CurrentInstances = channel.Read<byte>();
                        this.transData.PipeNameLength = channel.Read<byte>();

                        if ((this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
                        {
                            this.transData.Pad = new byte[1]{ channel.Read<byte>()};
                        }
                        this.transData.PipeName = channel.ReadBytes(this.transData.PipeNameLength);
                    }
                }
            }
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:26,代码来源:SmbTransQueryNmpipeInfoSuccessResponsePacket.cs

示例6: FromBytes

        /// <summary>
        /// Decode the payload data from byte array to RESP_GET_DFS_REFERRAL structure.
        /// And assign the result to referralResponse field.
        /// </summary>
        /// <param name="payloadData">RESP_GET_DFS_REFERRAL in byte array</param>
        /// <exception cref=" System.InvalidOperationException">
        /// Fail to decode payload data to RESP_GET_DFS_REFERRAL structure
        /// </exception>
        /// <exception cref=" System.FormatException">payloadData is null or empty</exception>
        private void FromBytes(byte[] payloadData)
        {
            if (payloadData != null && payloadData.Length > 0)
            {
                using (MemoryStream memoryStream = new MemoryStream(payloadData))
                {
                    Channel channel = new Channel(null, memoryStream);

                    // Read the referral header
                    this.referralResponse.PathConsumed = channel.Read<ushort>();
                    this.referralResponse.NumberOfReferrals = channel.Read<ushort>();
                    this.referralResponse.ReferralHeaderFlags = channel.Read<ReferralHeaderFlags>();

                    // Read Referral Entries
                    if (this.referralResponse.NumberOfReferrals > 0)
                    {
                        this.versionNumber = channel.Peek<ushort>(0);

                        switch (this.versionNumber)
                        {
                            case 0x0001:
                                List<DFS_REFERRAL_V1> referral1List = new List<DFS_REFERRAL_V1>();
                                // The total size of VersionNumber, Size, ServerType and ReferralEntryFlags in DFS_REFERRAL_V1
                                const ushort referralV1fixedSize = 8;

                                for (int i = 0; i < this.referralResponse.NumberOfReferrals; i++)
                                {
                                    DFS_REFERRAL_V1 referral1 = new DFS_REFERRAL_V1();
                                    referral1.VersionNumber = channel.Read<ushort>();
                                    referral1.Size = channel.Read<ushort>();
                                    referral1.ServerType = channel.Read<ushort>();
                                    referral1.ReferralEntryFlags = channel.Read<ushort>();
                                    referral1.ShareName = Encoding.Unicode.GetString(channel.ReadBytes(referral1.Size
                                        - referralV1fixedSize - sizeofWord));
                                    channel.ReadBytes(sizeofWord);
                                    referral1List.Add(referral1);
                                }
                                this.referralResponse.ReferralEntries = referral1List.ToArray();
                                break;

                            case 0x0002:
                                DecodeReferralV2(channel);
                                break;

                            case 0x0003:
                            case 0x0004:
                                // The offset from beginning of DFS_REFERRAL_V3V4 to ReferralEntryFlags field
                                ushort flagOffset = 6;
                                ReferralEntryFlags_Values referralEntryFlags = channel.Peek<ReferralEntryFlags_Values>(flagOffset);

                                if ((referralEntryFlags & ReferralEntryFlags_Values.NameListReferral)
                                    == ReferralEntryFlags_Values.NameListReferral)
                                {
                                    this.isNameListReferral = true;
                                    DecodeReferralV3V4_NameListReferral(channel);
                                }
                                else
                                {
                                    this.isNameListReferral = false;
                                    DecodeReferralV3V4_NonNameListReferral(channel);
                                }
                                break;

                            default:
                                throw new InvalidOperationException("The version number of Referral Entry is not correct.");
                        }
                    }
                }
            }
            else
            {
                throw new FormatException("payload byte array is null or empty for decoding.");
            }
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:83,代码来源:DfscReferralResponsePacket.cs

示例7: DecodeReferralV3V4_NameListReferral

        /// <summary>
        /// Decode the payload for type of Referral Entry V3V4_NameListReferral
        /// </summary>
        /// <param name="channel">channel with payload data</param>
        /// <exception cref=" System.InvalidOperationException">
        /// Fail to decode payload data to ReferralV3V4_NameListReferral structure
        /// </exception>
        private void DecodeReferralV3V4_NameListReferral(Channel channel)
        {
            bool isDfsPathFollowed = false;
            List<DFS_REFERRAL_V3V4_NameListReferral> tempList = new List<DFS_REFERRAL_V3V4_NameListReferral>();
            // The total size of all fields in front of Padding field in DFS_REFERRAL_V3V4_NameListReferral
            const ushort referral3FixedSize = 18;

            for (int i = 0; i < this.referralResponse.NumberOfReferrals; i++)
            {
                DFS_REFERRAL_V3V4_NameListReferral referral3 = new DFS_REFERRAL_V3V4_NameListReferral();

                // Read the fixed portion of DFS_REFERRAL_V3V4_NameListReferral
                referral3.VersionNumber = channel.Read<ushort>();
                referral3.Size = channel.Read<ushort>();
                referral3.ServerType = channel.Read<ushort>();
                referral3.ReferralEntryFlags = channel.Read<ReferralEntryFlags_Values>();
                referral3.TimeToLive = channel.Read<uint>();
                referral3.SpecialNameOffset = channel.Read<ushort>();
                referral3.NumberOfExpandedNames = channel.Read<ushort>();
                referral3.ExpandedNameOffset = channel.Read<ushort>();
                referral3.Padding = channel.ReadBytes(referral3.Size - referral3FixedSize);

                if (i == 0 && referral3.SpecialNameOffset == referral3.Size)
                {
                    isDfsPathFollowed = true;
                }

                // The Dfs paths of immediately follows each referral entry. Read the paths orderly.
                if (isDfsPathFollowed)
                {
                    // Get the Dfs paths from channel
                    // TD does not mention whether padding data exists between Dfs paths.
                    // Drop the possibly exists padding data
                    referral3.SpecialName = ReadDfsPath(channel);
                    ReadPadding(channel, referral3.ExpandedNameOffset - referral3.SpecialNameOffset
                        - (referral3.SpecialName.Length + 1) * sizeofWord);
                    referral3.DCNameArray = new string[referral3.NumberOfExpandedNames];

                    for (int j = 0; j < referral3.NumberOfExpandedNames; j++)
                    {
                        referral3.DCNameArray[j] = ReadDfsPath(channel);
                    }
                }
                tempList.Add(referral3);
            }

            // All Dfs paths follow the last referral entry.Read the paths after all entries have been read.
            if (!isDfsPathFollowed)
            {
                ushort referralFixedSize = tempList[0].Size;
                byte[] pathData = channel.ReadBytes((int)(channel.Stream.Length - channel.Stream.Position));

                for (int i = 0; i < tempList.Count; i++)
                {
                    // Calculate the offsets of Dfs paths
                    int leftCount = tempList.Count - i;
                    DFS_REFERRAL_V3V4_NameListReferral referral3 = tempList[i];
                    int specialNameOffset = referral3.SpecialNameOffset - leftCount * referralFixedSize;
                    int dcNameOffset = referral3.ExpandedNameOffset - leftCount * referralFixedSize;

                    // Get the Dfs paths
                    referral3.SpecialName = ReadDfsPath(pathData, specialNameOffset);
                    referral3.DCNameArray = new string[referral3.NumberOfExpandedNames];

                    for (int j = 0; j < referral3.NumberOfExpandedNames; j++)
                    {
                        referral3.DCNameArray[j] = ReadDfsPath(pathData, dcNameOffset);
                        dcNameOffset += referral3.DCNameArray[j].Length * sizeofWord;
                    }
                    tempList[i] = referral3;
                }
            }
            this.referralResponse.ReferralEntries = tempList.ToArray();
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:81,代码来源:DfscReferralResponsePacket.cs

示例8: DecodeData

        /// <summary>
        /// to decode the smb data: from the general SmbDada to the concrete Smb Data.
        /// </summary>
        protected override void DecodeData()
        {
            using (MemoryStream memoryStream = new MemoryStream(CifsMessageUtils.ToBytes<SmbData>(this.smbDataBlock)))
            {
                using (Channel channel = new Channel(null, memoryStream))
                {
                    this.smbData.ByteCount = channel.Read<ushort>();
                    this.smbData.Password = channel.ReadBytes(this.SmbParameters.PasswordLength);

                    // pad:
                    if ((Marshal.SizeOf(this.SmbHeader) + Marshal.SizeOf(this.SmbParameters)
                        + Marshal.SizeOf(this.smbData.ByteCount) + this.SmbParameters.PasswordLength) % 2 != 0)
                    {
                        this.smbData.Pad = channel.ReadBytes(1);
                    }
                    else
                    {
                        this.smbData.Pad = new byte[0];
                    }

                    // Path:
                    this.smbData.Path = CifsMessageUtils.ReadNullTerminatedString(channel,
                        (this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);

                    // Service:
                    this.smbData.Service = channel.ReadBytes(this.smbData.ByteCount - this.smbData.Password.Length
                        - this.smbData.Pad.Length - this.smbData.Path.Length);
                }
            }
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:33,代码来源:SmbTreeConnectAndxRequestPacket.cs

示例9: DecodeTrans2Parameters

 /// <summary>
 /// to decode the Trans2 parameters: from the general Trans2Parameters to the concrete Trans2 Parameters.
 /// </summary>
 protected override void DecodeTrans2Parameters()
 {
     if (this.smbData.Trans2_Parameters != null)
     {
         using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Parameters))
         {
             using (Channel channel = new Channel(null, memoryStream))
             {
                 this.trans2Parameters.Reserved = channel.Read<uint>();
                 this.trans2Parameters.DirectoryName = channel.ReadBytes(this.smbParameters.ParameterCount
                     - reservedLength);
             }
         }
     }
 }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:18,代码来源:SmbTrans2CreateDirectoryRequestPacket.cs

示例10: DecodeNtTransData

        /// <summary>
        /// to decode the NtTrans data: from the general NtTransDada to the concrete NtTrans Data. 
        /// </summary>
        protected override void DecodeNtTransData()
        {
            NT_TRANSACT_ENUMERATE_SNAPSHOTS_Response_NT_Trans_Data data
                = new NT_TRANSACT_ENUMERATE_SNAPSHOTS_Response_NT_Trans_Data();

            using (MemoryStream stream = new MemoryStream(this.smbData.Data))
            {
                using (Channel channel = new Channel(null, stream))
                {
                    data.NumberOfSnapShots = channel.Read<uint>();
                    data.NumberOfSnapShotsReturned = channel.Read<uint>();
                    data.SnapShotArraySize = channel.Read<uint>();
                    if (data.NumberOfSnapShotsReturned > 0)
                    {
                        data.snapShotMultiSZ = channel.ReadBytes((int)data.SnapShotArraySize);
                    }
                }
            }

            this.NtTransData = data;

            if (this.ntTransData.snapShotMultiSZ == null || this.ntTransData.SnapShotArraySize <= 2)
            {
                return;
            }

            string snapshot = Encoding.Unicode.GetString(this.ntTransData.snapShotMultiSZ);
            this.SnapShots = new Collection<string>(snapshot.Trim('\0').Split('\0'));
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:32,代码来源:SmbNtTransFsctlSrvEnumerateSnapshotsResponsePacket.cs

示例11: DecodeTrans2Data

        /// <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();
                }
            }
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:25,代码来源:SmbTrans2CreateDirectoryRequestPacket.cs

示例12: DecodeTrans2Parameters

 /// <summary>
 /// to decode the Trans2 parameters: from the general Trans2Parameters to the concrete Trans2 Parameters.
 /// </summary>
 protected override void DecodeTrans2Parameters()
 {
     using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Parameters))
     {
         using (Channel channel = new Channel(null, memoryStream))
         {
             this.trans2Parameters.SearchAttributes = channel.Read<SmbFileAttributes>();
             this.trans2Parameters.SearchCount = channel.Read<ushort>();
             this.trans2Parameters.Flags = channel.Read<Trans2FindFlags>();
             this.trans2Parameters.InformationLevel = channel.Read<FindInformationLevel>();
             this.trans2Parameters.SearchStorageType = channel.Read<Trans2FindFirst2SearchStorageType>();
             this.trans2Parameters.FileName = channel.ReadBytes(this.SmbParameters.ParameterCount
                 - trans2ParametersLength);
         }
     }
 }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:19,代码来源:SmbTrans2FindFirst2RequestPacket.cs

示例13: DecodeTrans2Data

        /// <summary>
        /// to decode the Trans2 data: from the general Trans2Dada to the concrete Trans2 Data.
        /// </summary>
        protected override void DecodeTrans2Data()
        {
            if (this.trans2Parameters.InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
            {
                using (MemoryStream memoryStream = new MemoryStream(this.smbData.Trans2_Data))
                {
                    using (Channel channel = new Channel(null, memoryStream))
                    {
                        this.trans2Data.GetExtendedAttributeList.SizeOfListInBytes = channel.Read<uint>();
                        uint sizeOfListInBytes =
                            this.trans2Data.GetExtendedAttributeList.SizeOfListInBytes - sizeOfListInBytesLength;
                        List<SMB_GEA> attributeList = new List<SMB_GEA>();

                        while (sizeOfListInBytes > 0)
                        {
                            SMB_GEA smbQueryEa = channel.Read<SMB_GEA>();
                            attributeList.Add(smbQueryEa);
                            sizeOfListInBytes -= (uint)(EA.SMB_QUERY_EA_FIXED_SIZE + smbQueryEa.AttributeName.Length);
                        }
                        this.trans2Data.GetExtendedAttributeList.GEAList = attributeList.ToArray();
                    }
                }
            }
            else
            {
                this.trans2Data.GetExtendedAttributeList.GEAList = new SMB_GEA[0];
            }
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:31,代码来源:SmbTrans2FindFirst2RequestPacket.cs

示例14: DecodeData

        /// <summary>
        /// to decode the smb data: from the general SmbDada to the concrete Smb Data.
        /// </summary>
        protected override void DecodeData()
        {
            using (MemoryStream memoryStream = new MemoryStream(CifsMessageUtils.ToBytes<SmbData>(this.smbDataBlock)))
            {
                using (Channel channel = new Channel(null, memoryStream))
                {
                    this.smbData.ByteCount = channel.Read<ushort>();
                    int pad1Length = this.smbParameters.ParameterOffset > 0 ?
                        (int)(this.smbParameters.ParameterOffset - this.HeaderSize
                        - SmbComTransactionPacket.SmbParametersWordCountLength - this.smbParameters.WordCount * 2
                        - SmbComTransactionPacket.SmbDataByteCountLength) : 0;

                    this.smbData.Pad1 = channel.ReadBytes(pad1Length);
                    this.smbData.Parameters = channel.ReadBytes((int)this.smbParameters.ParameterCount);
                    this.smbData.Pad2 = channel.ReadBytes((int)(this.smbParameters.DataOffset - this.smbParameters.ParameterOffset
                        - this.smbParameters.ParameterCount));
                    this.smbData.Data = channel.ReadBytes((int)this.smbParameters.DataCount);
                }
                this.DecodeNtTransParameters();
                this.DecodeNtTransData();
            }
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:25,代码来源:SmbNtTransactSuccessResponsePacket.cs

示例15: DecodeData

        /// <summary>
        /// to decode the smb data: from the general SmbDada to the concrete Smb Data.
        /// </summary>
        protected override void DecodeData()
        {
            this.smbData = new SMB_COM_TRANSACTION_Request_SMB_Data();
            using (MemoryStream memoryStream = new MemoryStream(CifsMessageUtils.ToBytes<SmbData>(this.smbDataBlock)))
            {
                using (Channel channel = new Channel(null, memoryStream))
                {
                    this.smbData.ByteCount = channel.Read<ushort>();

                    bool isUnicode = (this.smbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE;
                    if (isUnicode)
                    {
                        byte padLength = 1;
                        channel.ReadBytes(padLength);
                        List<ushort> array = new List<ushort>();
                        ushort letter;

                        do
                        {
                            letter = channel.Read<ushort>();
                            array.Add(letter);
                        }
                        while (letter != new ushort());
                        this.smbData.Name = CifsMessageUtils.ToBytesArray(array.ToArray());
                    }
                    else
                    {
                        List<byte> array = new List<byte>();
                        byte letter;

                        do
                        {
                            letter = channel.Read<byte>();
                            array.Add(letter);
                        }
                        while (letter != new byte());

                        this.smbData.Name = array.ToArray();
                    }

                    // the padding length of Pad1.
                    int pad1Length = this.smbParameters.ParameterOffset - this.HeaderSize
                        - this.smbParameters.WordCount * 2 - SmbComTransactionPacket.SmbParametersWordCountLength
                        - SmbComTransactionPacket.SmbDataByteCountLength - this.smbData.Name.Length;

                    // sub the padding bytes for Name.
                    if (isUnicode)
                    {
                        pad1Length -= 1;
                    }

                    // read Pad1 from channel.
                    if (pad1Length > 0)
                    {
                        this.smbData.Pad1 = channel.ReadBytes(pad1Length);
                    }

                    this.smbData.Trans_Parameters = channel.ReadBytes(this.smbParameters.ParameterCount);
                    if (this.smbParameters.DataOffset > 0)
                    {
                        this.smbData.Pad2 = channel.ReadBytes(this.smbParameters.DataOffset
                            - this.smbParameters.ParameterOffset - this.smbParameters.ParameterCount);
                        this.smbData.Trans_Data = channel.ReadBytes(this.smbParameters.DataCount);
                    }
                    else
                    {
                        this.smbData.Pad2 = new byte[0];
                        this.smbData.Trans_Data = new byte[0];
                    }
                }
            }
            this.DecodeTransParameters();
            this.DecodeTransData();
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:77,代码来源:SmbTransactionRequestPacket.cs


注:本文中的Channel.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。