當前位置: 首頁>>代碼示例>>C#>>正文


C# MatchCollection.GetMatchesInHeaders方法代碼示例

本文整理匯總了C#中System.Text.RegularExpressions.MatchCollection.GetMatchesInHeaders方法的典型用法代碼示例。如果您正苦於以下問題:C# MatchCollection.GetMatchesInHeaders方法的具體用法?C# MatchCollection.GetMatchesInHeaders怎麽用?C# MatchCollection.GetMatchesInHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Text.RegularExpressions.MatchCollection的用法示例。


在下文中一共展示了MatchCollection.GetMatchesInHeaders方法的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.GetMatchesInHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。