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


C# MatchCollection.GetMatchesInBody方法代码示例

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


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

示例1: CalcResults

        /// <summary>
        /// This method is where result "confidence" is calculated. A list of all the occurences of the "canary" should be passed in. 
        /// </summary>
        /// <param name="s">Session object with request/response</param>
        /// <param name="matches">These are the canary matches..</param>
        /// <param name="lookAheadFromMatchLoc"></param>
        /// <returns></returns>
        public List<ResponseResult> CalcResults(Session s, MatchCollection matches,  UnicodeTestCases mappings, string canary,int lookAheadFromMatchLoc)
        {
            List<ResponseResult> ret = new List<ResponseResult>();

            //BUGBUG: Chris says he's getting an exception because the unicode char is not being associated with the session..

            if (s.Chr == null)
            {
                return ret;
            }

            foreach (ResponseHeaderMatch hMatch in matches.GetMatchesInHeaders()) {
                ResponseResult rr = new ResponseResult(hMatch);
                //Get the match context in each header. Multipule headers could have the same key.. so
                //a list is returned that contains each "string value" to a given key. Each element representing a different
                //value for the same key.

                foreach(string headerValue in s.Response.Headers[hMatch.HeaderName]){

                    int forwardDif = 0;

                    int offset = hMatch.Offset + hMatch.Token.TokenLength + lookAheadFromMatchLoc;
                    if (offset  > headerValue.Length) {
                        forwardDif = offset - headerValue.Length;
                    }
                    string context = headerValue.Substring(hMatch.Offset - 4, hMatch.Token.TokenLength + lookAheadFromMatchLoc - forwardDif);

                    UnicodeTestCase mapping = mappings.GetMappingFromSourceCodePoint(s.Chr.CodePoint);
                    // At this point i have the context of the "canary" + 5 chars ahead.. this is where logic can be introduced
                    // to determine "the type of match"
                    rr.Chr = mapping.SourcePoint;
                    rr.Transformation = this.DeduceTransformation(context, mapping, canary);
                    rr.Context = context;
                    rr.TestCase = mapping;
                    //Add to result list
                    System.Diagnostics.Debug.Write(s.Fsession.fullUrl);
                    ret.Add(rr);
                }
            }

            //This will change.. the response should be responsible for returning bytes based off detected encoding..
            //That logic will be moved into the Response class at a later point.
            string body = Encoding.UTF8.GetString(s.Response.BodyBytes);

            //Now we find matches in the body..
            foreach (BodyMatch bMatch in matches.GetMatchesInBody()) {
                ResponseResult rr = new ResponseResult(bMatch);
                //Get the match context.
                int dif = 0;
                int offset = bMatch.Offset + lookAheadFromMatchLoc + bMatch.Token.TokenLength;

                if (offset > body.Length) {
                    dif = offset - body.Length;
                }

                string context = body.Substring(bMatch.Offset - 4, bMatch.Token.TokenLength + lookAheadFromMatchLoc - dif);

                UnicodeTestCase mapping = mappings.GetMappingFromSourceCodePoint(s.Chr.CodePoint);

                rr.Context = context;
                rr.Chr = mapping.SourcePoint;
                rr.Transformation = this.DeduceTransformation(context, mapping, canary);
                rr.TestCase = mapping;

                //System.Diagnostics.Debug.Write(s.Fsession.fullUrl);
                ret.Add(rr);

            }
              //Add to result list.
            return ret;
        }
开发者ID:timshao1120,项目名称:wtgw,代码行数:78,代码来源:ResponseEngine.cs


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