diff --git a/BurnOutSharp/Matching/ContentMatch.cs b/BurnOutSharp/Matching/ContentMatch.cs
index d4d86fe8..b272ab26 100644
--- a/BurnOutSharp/Matching/ContentMatch.cs
+++ b/BurnOutSharp/Matching/ContentMatch.cs
@@ -3,7 +3,7 @@ using System.Diagnostics.Eventing.Reader;
namespace BurnOutSharp.Matching
{
///
- /// Single matching criteria
+ /// Content matching criteria
///
internal class ContentMatch
{
diff --git a/BurnOutSharp/Matching/Matcher.cs b/BurnOutSharp/Matching/Matcher.cs
index 7e1fbb81..91186d3e 100644
--- a/BurnOutSharp/Matching/Matcher.cs
+++ b/BurnOutSharp/Matching/Matcher.cs
@@ -14,9 +14,15 @@ namespace BurnOutSharp.Matching
///
public IEnumerable ContentMatches { get; set; }
+ ///
+ /// Set of all path matches
+ ///
+ public IEnumerable PathMatches { get; set; }
+
///
/// Function to get a version for this Matcher
///
+ /// TODO: Can this be made more generic?
public Func GetVersion { get; set; }
///
@@ -24,7 +30,7 @@ namespace BurnOutSharp.Matching
///
public string ProtectionName { get; set; }
- #region Constructors
+ #region ContentMatch Constructors
public Matcher(byte?[] needle, string protectionName)
: this(new List { needle }, null, protectionName) { }
@@ -56,10 +62,42 @@ namespace BurnOutSharp.Matching
#endregion
+ #region PathMatch Constructors
+
+ public Matcher(string needle, string protectionName)
+ : this(new List { needle }, null, protectionName) { }
+
+ public Matcher(List needles, string protectionName)
+ : this(needles, null, protectionName) { }
+
+ public Matcher(string needle, Func getVersion, string protectionName)
+ : this(new List { needle }, getVersion, protectionName) { }
+
+ public Matcher(List needles, Func getVersion, string protectionName)
+ : this(needles.Select(n => new PathMatch(n)).ToList(), getVersion, protectionName) { }
+
+ public Matcher(PathMatch needle, string protectionName)
+ : this(new List() { needle }, null, protectionName) { }
+
+ public Matcher(List needles, string protectionName)
+ : this(needles, null, protectionName) { }
+
+ public Matcher(PathMatch needle, Func getVersion, string protectionName)
+ : this(new List() { needle }, getVersion, protectionName) { }
+
+ public Matcher(List needles, Func getVersion, string protectionName)
+ {
+ PathMatches = needles;
+ GetVersion = getVersion;
+ ProtectionName = protectionName;
+ }
+
+ #endregion
+
#region Matching
///
- /// Determine wheter all content matches pass
+ /// Determine whether all content matches pass
///
/// Byte array representing the file contents
/// Tuole of passing status and matching positions
@@ -85,6 +123,55 @@ namespace BurnOutSharp.Matching
return (true, positions);
}
+ ///
+ /// Determine whether all content matches pass
+ ///
+ /// List of strings to try to match
+ /// Tuole of passing status and matching values
+ public (bool, List) MatchesAll(List stack)
+ {
+ // If no path matches are defined, we fail out
+ if (PathMatches == null || !PathMatches.Any())
+ return (false, null);
+
+ // Initialize the value list
+ List values = new List();
+
+ // Loop through all path matches and make sure all pass
+ foreach (var pathMatch in PathMatches)
+ {
+ (bool match, string value) = pathMatch.Match(stack);
+ if (!match)
+ return (false, null);
+ else
+ values.Add(value);
+ }
+
+ return (true, values);
+ }
+
+ ///
+ /// Determine whether any content matches pass
+ ///
+ /// List of strings to try to match
+ /// Tuole of passing status and matching values
+ public (bool, string) MatchesAny(List stack)
+ {
+ // If no path matches are defined, we fail out
+ if (PathMatches == null || !PathMatches.Any())
+ return (false, null);
+
+ // Loop through all path matches and make sure all pass
+ foreach (var pathMatch in PathMatches)
+ {
+ (bool match, string value) = pathMatch.Match(stack);
+ if (match)
+ return (true, value);
+ }
+
+ return (false, null);
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/BurnOutSharp/Matching/PathMatch.cs b/BurnOutSharp/Matching/PathMatch.cs
new file mode 100644
index 00000000..fafe9fcc
--- /dev/null
+++ b/BurnOutSharp/Matching/PathMatch.cs
@@ -0,0 +1,43 @@
+using System.Collections.Generic;
+
+namespace BurnOutSharp.Matching
+{
+ ///
+ /// Path matching criteria
+ ///
+ internal class PathMatch
+ {
+ ///
+ /// String to match
+ ///
+ public string Needle { get; set; }
+
+ public PathMatch(string needle)
+ {
+ Needle = needle;
+ }
+
+ #region Matching
+
+ ///
+ /// Get if this match can be found in a stack
+ ///
+ /// List of strings to search for the given content
+ public (bool, string) Match(List stack)
+ {
+ // If either array is null or empty, we can't do anything
+ if (stack == null || stack.Count == 0 || Needle == null || Needle.Length == 0)
+ return (false, null);
+
+ foreach (string stackItem in stack)
+ {
+ if (stackItem.Contains(Needle))
+ return (true, stackItem);
+ }
+
+ return (false, null);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file