修复绕过无操作检测失效的问题

This commit is contained in:
梅浩东
2025-04-02 12:08:01 +08:00
parent 6e33755820
commit 9a862ad71d
2 changed files with 86 additions and 9 deletions
+72
View File
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static ProtoBuf.Serializer;
namespace BarrageGrab
{
@@ -359,4 +360,75 @@ namespace BarrageGrab
}
}
/// <summary>
/// 模式匹配相关扩展方法
/// </summary>
public static class PatternMatchExtensions
{
/// <summary>
/// 判断是否匹配任意一个通配符
/// </summary>
/// <param name="str">要匹配的字符串</param>
/// <param name="patterns">通配符表达式数组</param>
/// <returns>是否匹配</returns>
public static bool WildcardMatchAny(this string str, params string[] patterns)
{
return patterns.Any(x => x.WildcardMatch(str));
}
/// <summary>
/// 判断是否匹配通配符
/// </summary>
/// <param name="wildcard">通配符表达式</param>
/// <param name="s">要匹配的字符串</param>
/// <param name="ignoreCase">是否忽略大小写</param>
/// <returns>是否匹配</returns>
public static bool WildcardMatch(this string wildcard, string s, bool ignoreCase = false)
{
return wildcard.WildcardMatch(s, 0, 0, ignoreCase);
}
// 递归匹配通配符
private static bool WildcardMatch(this string wildcard, string s, int wildcardIndex, int sIndex, bool ignoreCase)
{
while (wildcardIndex != wildcard.Length)
{
char c = wildcard[wildcardIndex];
switch (c)
{
case '*':
if (wildcardIndex == wildcard.Length - 1)
{
return true;
}
return Enumerable.Range(sIndex, s.Length - sIndex).Any((int i) => wildcard.WildcardMatch(s, wildcardIndex + 1, i, ignoreCase));
default:
{
char c2 = (ignoreCase ? char.ToLower(c) : c);
if (s.Length == sIndex)
{
return false;
}
char c3 = (ignoreCase ? char.ToLower(s[sIndex]) : s[sIndex]);
if (c2 != c3)
{
return false;
}
break;
}
case '?':
break;
}
wildcardIndex++;
sIndex++;
}
return sIndex == s.Length;
}
}
}