[+] 通用特征替换的数据结构与查找方法

This commit is contained in:
huiyadanli 2019-12-25 01:13:09 +08:00
parent fa4b15d7d2
commit 818a7e1dbd
7 changed files with 96 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -65,6 +65,25 @@ namespace RevokeMsgPatcher
"WeChatWin.dll", "WeChatWin.dll",
new List<ModifyInfo> new List<ModifyInfo>
{ {
new ModifyInfo {
Name="WeChatWin.dll",
Version="2.8.0.82",
SHA1Before="c359cc1a391441d261753f2844f9156638df8631",
SHA1After="d1b4dee8f7f91e34d68501987fd0675b33fe85da",
Changes = new List<Change>
{
new Change
{
Position =0x00285FC9,
Content =new byte[] { 0xEB }
},
new Change
{
Position =0x007E16B0,
Content =new byte[] { 0xC3 }
}
}
},
new ModifyInfo { new ModifyInfo {
Name="WeChatWin.dll", Name="WeChatWin.dll",
Version="2.7.2.76", Version="2.7.2.76",

View File

@ -5,15 +5,14 @@ using System.Linq;
namespace RevokeMsgPatcher.Assistant.Matcher namespace RevokeMsgPatcher.Assistant.Matcher
{ {
/// <summary> /// <summary>
/// 对16进制数据进行模糊查找 /// 对16进制数据进行通配符查找
/// 通配符的方式
/// </summary> /// </summary>
public class FuzzyMatcher public class FuzzyMatcher
{ {
public const byte wildcard = 0x3F; // 通配符 public const byte wildcard = 0x3F; // 通配符
/// <summary> /// <summary>
/// 模糊匹配所有 /// 通配符匹配所有符合查找串的位置
/// </summary> /// </summary>
/// <param name="content">被查找对象</param> /// <param name="content">被查找对象</param>
/// <param name="pattern">查找串</param> /// <param name="pattern">查找串</param>
@ -37,15 +36,44 @@ namespace RevokeMsgPatcher.Assistant.Matcher
res.Add(index); res.Add(index);
} }
} }
if (res.Count > 0)
{
return res.ToArray(); return res.ToArray();
} }
else }
/// <summary>
/// 通配符匹配所有符合查找串的位置,并排除已经替换的情况
/// </summary>
/// <param name="content">被查找对象</param>
/// <param name="searchBytes">查找串</param>
/// <param name="replaceBytes">替换串</param>
/// <returns></returns>
public static int[] MatchNotReplaced(byte[] content, byte[] searchBytes, byte[] replaceBytes)
{ {
return null; byte[] head = GetHead(searchBytes);
int[] indexs = BoyerMooreMatcher.MatchAll(content, head);
// 头串和查找串相同则直接返回,不同则继续判断是否符合查询串
List<int> res = new List<int>();
if (head.Length != searchBytes.Length)
{
foreach (int index in indexs)
{
if (IsEqual(content, index, searchBytes))
{
res.Add(index);
} }
} }
indexs = res.ToArray();
}
// 判断是否与替换串相同
res = new List<int>();
foreach (int index in indexs)
{
if (!IsEqual(content, index, replaceBytes))
{
res.Add(index);
}
}
return res.ToArray();
} }
/// <summary> /// <summary>

View File

@ -14,6 +14,11 @@ namespace RevokeMsgPatcher.Model
public Dictionary<string, List<ModifyInfo>> FileModifyInfos { get; set; } public Dictionary<string, List<ModifyInfo>> FileModifyInfos { get; set; }
/// <summary>
/// 通用的修改特征
/// </summary>
public Dictionary<string, List<ModifyInfo>> FileCommonModifyInfos { get; set; }
public HashSet<string> GetSupportVersions() public HashSet<string> GetSupportVersions()
{ {
// 使用 HashSet 防重 // 使用 HashSet 防重

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RevokeMsgPatcher.Model
{
public class CommonModifyInfo
{
public string Name { get; set; }
public string StartVersion { get; set; }
public string EndVersion { get; set; }
public List<Change> Changes { get; set; }
public CommonModifyInfo Clone()
{
CommonModifyInfo o = new CommonModifyInfo();
o.Name = Name;
o.StartVersion = StartVersion;
o.EndVersion = EndVersion;
List<Change> cs = new List<Change>();
foreach(Change c in Changes)
{
cs.Add(c.Clone());
}
o.Changes = cs;
return o;
}
}
}

View File

@ -11,8 +11,6 @@ namespace RevokeMsgPatcher.Model
{ {
public string Name { get; set; } public string Name { get; set; }
//public string RelativePath { get; set; }
public string Version { get; set; } public string Version { get; set; }
public string SHA1Before { get; set; } public string SHA1Before { get; set; }

View File

@ -60,6 +60,7 @@
<Compile Include="Model\App.cs" /> <Compile Include="Model\App.cs" />
<Compile Include="Model\Bag.cs" /> <Compile Include="Model\Bag.cs" />
<Compile Include="Model\Change.cs" /> <Compile Include="Model\Change.cs" />
<Compile Include="Model\CommonModifyInfo.cs" />
<Compile Include="Model\ModifyInfo.cs" /> <Compile Include="Model\ModifyInfo.cs" />
<Compile Include="Model\TargetInfo.cs" /> <Compile Include="Model\TargetInfo.cs" />
<Compile Include="Modifier\AppModifier.cs" /> <Compile Include="Modifier\AppModifier.cs" />