本文整理汇总了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;
}