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


C# Channel.Peek方法代码示例

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


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

示例1: ReadDfsPath

        /// <summary>
        /// Get Dfs path from channel.
        /// </summary>
        /// <param name="channel">channel with Dfs path data</param>
        /// <returns>Dfs path in string</returns>
        /// <exception cref=" System.InvalidOperationException">Fail to get dfs path from channel.</exception>
        private string ReadDfsPath(Channel channel)
        {
            int pathLength = 0;

            while (channel.Peek<ushort>(pathLength) != 0)
            {
                pathLength += sizeofWord;
            }

            string dfsPAth = Encoding.Unicode.GetString(channel.ReadBytes(pathLength));
            channel.ReadBytes(sizeofWord);
            return dfsPAth;
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:19,代码来源:DfscReferralResponsePacket.cs

示例2: 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

示例3: 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

示例4: DecodeData

        /// <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;
            }
        }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:86,代码来源:SmbSessionSetupAndxRequestPacket.cs

示例5: CreateTransactionResponsePacket

        /// <summary>
        /// createt the transactions packet
        /// </summary>
        /// <param name="request">the request packet</param>
        /// <param name="smbHeader">the smb header of response packet</param>
        /// <param name="channel">the channel contains the packet bytes</param>
        /// <returns>the response packet</returns>
        private SmbPacket CreateTransactionResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek<byte>(0) == 0 && channel.Peek<ushort>(1) == 0)
            {
                return smbPacket;
            }

            SmbTransactionRequestPacket transactionRequest = request as SmbTransactionRequestPacket;
            if (transactionRequest == null)
            {
                return smbPacket;
            }
            switch (smbClient.Capability.TransactionSubCommand)
            {
                case TransSubCommandExtended.TRANS_EXT_MAILSLOT_WRITE:
                    smbPacket = new SmbTransMailslotWriteResponsePacket();
                    break;

                case TransSubCommandExtended.TRANS_EXT_RAP:
                    smbPacket = new SmbTransRapResponsePacket();
                    break;

                default:
                    break;

            }

            // the packet is find
            if (smbPacket != null)
            {
                return smbPacket;
            }

            // if no setup command. break
            if (transactionRequest.SmbParameters.SetupCount == 0)
            {
                return smbPacket;
            }

            // decode packet using the setup command
            switch ((TransSubCommand)transactionRequest.SmbParameters.Setup[0])
            {
                case TransSubCommand.TRANS_SET_NMPIPE_STATE:
                    smbPacket = new SmbTransSetNmpipeStateResponsePacket();
                    break;

                case TransSubCommand.TRANS_QUERY_NMPIPE_STATE:
                    smbPacket = new SmbTransQueryNmpipeStateResponsePacket();
                    break;

                case TransSubCommand.TRANS_RAW_READ_NMPIPE:
                    smbPacket = new SmbTransRawReadNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_QUERY_NMPIPE_INFO:
                    smbPacket = new SmbTransQueryNmpipeInfoResponsePacket();
                    break;

                case TransSubCommand.TRANS_PEEK_NMPIPE:
                    smbPacket = new SmbTransPeekNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_TRANSACT_NMPIPE:
                    smbPacket = new SmbTransTransactNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_READ_NMPIPE:
                    smbPacket = new SmbTransReadNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_WRITE_NMPIPE:
                    smbPacket = new SmbTransWriteNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_WAIT_NMPIPE:
                    smbPacket = new SmbTransWaitNmpipeResponsePacket();
                    break;

                case TransSubCommand.TRANS_CALL_NMPIPE:
                    smbPacket = new SmbTransCallNmpipeResponsePacket();
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:97,代码来源:SmbClientDecodePacket.cs

示例6: CreateTransaction2ResponsePacket

        private SmbPacket CreateTransaction2ResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek<byte>(0) == 0 && channel.Peek<ushort>(1) == 0)
            {
                return smbPacket;
            }

            SmbTransaction2RequestPacket transaction2Request = request as SmbTransaction2RequestPacket;
            if (transaction2Request == null)
            {
                return smbPacket;
            }

            // if no setup command. break
            if (transaction2Request.SmbParameters.SetupCount == 0)
            {
                return smbPacket;
            }

            // decode packet using the setup command
            switch ((Trans2SubCommand)transaction2Request.SmbParameters.Setup[0])
            {
                case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                    SmbTrans2QueryFileInformationRequestPacket queryFileRequest =
                        transaction2Request as SmbTrans2QueryFileInformationRequestPacket;
                    if (queryFileRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFileInformationResponsePacket(
                            queryFileRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                    SmbTrans2QueryPathInformationRequestPacket queryPathRequest =
                       transaction2Request as SmbTrans2QueryPathInformationRequestPacket;
                    if (queryPathRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryPathInformationResponsePacket(
                            queryPathRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                    smbPacket = new SmbTrans2SetFileInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                    smbPacket = new SmbTrans2SetPathInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                    SmbTrans2QueryFsInformationRequestPacket queryFsRequest =
                        transaction2Request as SmbTrans2QueryFsInformationRequestPacket;
                    if (queryFsRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFsInformationResponsePacket(
                            queryFsRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                    smbPacket = new SmbTrans2SetFsInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_FIND_FIRST2:
                    SmbTrans2FindFirst2RequestPacket first2Request =
                       transaction2Request as SmbTrans2FindFirst2RequestPacket;
                    if (first2Request != null)
                    {
                        smbPacket = new SmbTrans2FindFirst2ResponsePacket(first2Request.Trans2Parameters.InformationLevel,
                            (first2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_FIND_NEXT2:
                    SmbTrans2FindNext2RequestPacket next2Request =
                       transaction2Request as SmbTrans2FindNext2RequestPacket;
                    if (next2Request != null)
                    {
                        smbPacket = new SmbTrans2FindNext2ResponsePacket(next2Request.Trans2Parameters.InformationLevel,
                            (next2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                    smbPacket = new SmbTrans2GetDfsReferralResponsePacket();
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:98,代码来源:SmbClientDecodePacket.cs

示例7: CreateNtTransactionResponsePacket

        /// <summary>
        /// create the nt transaction packet
        /// </summary>
        /// <param name="request">the request packet</param>
        /// <param name="smbHeader">the smb header of response packet</param>
        /// <param name="channel">the channel contains the packet bytes</param>
        /// <returns>the response packet</returns>
        private SmbPacket CreateNtTransactionResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek<byte>(0) == 0 && channel.Peek<ushort>(1) == 0)
            {
                return smbPacket;
            }

            SmbNtTransactRequestPacket ntTransactRequest = request as SmbNtTransactRequestPacket;
            if (ntTransactRequest == null)
            {
                return smbPacket;
            }

            // find regular packet
            switch ((uint)ntTransactRequest.SmbParameters.Function)
            {
                case (uint)NtTransSubCommand.NT_TRANSACT_RENAME:
                    smbPacket = new SmbNtTransRenameResponsePacket();
                    break;

                case (uint)NtTransSubCommand.NT_TRANSACT_CREATE:
                    smbPacket = new SmbNtTransactCreateResponsePacket();
                    break;

                case (uint)NtTransSubCommand.NT_TRANSACT_IOCTL:

                    NT_TRANSACT_IOCTL_SETUP setup =
                       CifsMessageUtils.ToStuct<NT_TRANSACT_IOCTL_SETUP>(
                       CifsMessageUtils.ToBytesArray<ushort>(ntTransactRequest.SmbParameters.Setup));

                    switch ((NtTransFunctionCode)setup.FunctionCode)
                    {
                        case NtTransFunctionCode.FSCTL_SRV_ENUMERATE_SNAPSHOTS:
                            smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsResponsePacket();
                            break;

                        case NtTransFunctionCode.FSCTL_SRV_REQUEST_RESUME_KEY:
                            smbPacket = new SmbNtTransFsctlSrvRequestResumeKeyResponsePacket();
                            break;

                        case NtTransFunctionCode.FSCTL_SRV_COPYCHUNK:
                            smbPacket = new SmbNtTransFsctlSrvCopyChunkResponsePacket();
                            break;

                        default:
                            smbPacket = new SmbNtTransactIoctlResponsePacket();
                            break;
                    }

                    break;

                case (uint)SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA:
                    smbPacket = new SmbNtTransQueryQuotaResponsePacket();
                    break;

                case (uint)SmbNtTransSubCommand.NT_TRANSACT_SET_QUOTA:
                    smbPacket = new SmbNtTransSetQuotaResponsePacket();
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
开发者ID:pyq881120,项目名称:WindowsProtocolTestSuites,代码行数:74,代码来源:SmbClientDecodePacket.cs


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