mirror of
https://github.com/huiyadanli/RevokeMsgPatcher.git
synced 2025-05-24 06:17:36 +08:00
[+] 添加特征码识别替换的版本范围判定
This commit is contained in:
parent
000dfa969e
commit
8630dc83df
File diff suppressed because one or more lines are too long
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace RevokeMsgPatcher.Matcher
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace RevokeMsgPatcher.Assistant.Matcher
|
|
||||||
{
|
{
|
||||||
public class BoyerMooreMatcher
|
public class BoyerMooreMatcher
|
||||||
{
|
{
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace RevokeMsgPatcher.Assistant.Matcher
|
namespace RevokeMsgPatcher.Matcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 对16进制数据进行通配符查找
|
/// 对16进制数据进行通配符查找
|
|
@ -69,6 +69,40 @@ namespace RevokeMsgPatcher.Modifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断版本是否处于版本范围,特殊版本的可以重载此方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="version">当前版本</param>
|
||||||
|
/// <param name="start">起始版本</param>
|
||||||
|
/// <param name="end">结束版本,为空为不限制</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsInVersionRange(string version, string start, string end)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int v = Convert.ToInt32(version.Replace(".", ""));
|
||||||
|
int s = Convert.ToInt32(start.Replace(".", ""));
|
||||||
|
int e = 0;
|
||||||
|
if (string.IsNullOrEmpty(end))
|
||||||
|
{
|
||||||
|
e = int.MaxValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e = Convert.ToInt32(end.Replace(".", ""));
|
||||||
|
}
|
||||||
|
if (v >= s && v <= e)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("判断版本范围时出错:" + e.Message);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a.初始化修改器
|
/// a.初始化修改器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -115,6 +149,17 @@ namespace RevokeMsgPatcher.Modifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 多个版本范围,匹配通用的补丁替换方式
|
||||||
|
foreach (CommonModifyInfo commonModifyInfo in config.FileCommonModifyInfos[editor.FileName])
|
||||||
|
{
|
||||||
|
// editor.FileVersion 在 StartVersion 和 EndVersion 之间
|
||||||
|
if (IsInVersionRange(editor.FileVersion, commonModifyInfo.StartVersion, commonModifyInfo.EndVersion))
|
||||||
|
{
|
||||||
|
editor.FileCommonModifyInfo = commonModifyInfo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 补丁前SHA1匹配上,肯定是正确的dll
|
// 补丁前SHA1匹配上,肯定是正确的dll
|
||||||
if (matchingSHA1Before != null)
|
if (matchingSHA1Before != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,8 @@ namespace RevokeMsgPatcher.Modifier
|
||||||
|
|
||||||
public string FileBakPath { get; set; }
|
public string FileBakPath { get; set; }
|
||||||
|
|
||||||
|
private string fileReplacedPath;
|
||||||
|
|
||||||
private string version;
|
private string version;
|
||||||
public string FileVersion
|
public string FileVersion
|
||||||
{
|
{
|
||||||
|
@ -45,27 +47,48 @@ namespace RevokeMsgPatcher.Modifier
|
||||||
|
|
||||||
public TargetInfo FileTargetInfo { get; set; }
|
public TargetInfo FileTargetInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过比对SHA1得到的特定版本的修改信息
|
||||||
|
/// </summary>
|
||||||
public ModifyInfo FileModifyInfo { get; set; }
|
public ModifyInfo FileModifyInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通过比对版本范围得到的通用查找替换的修改信息
|
||||||
|
/// </summary>
|
||||||
|
public CommonModifyInfo FileCommonModifyInfo { get; set; }
|
||||||
|
|
||||||
public FileHexEditor(string installPath, TargetInfo target)
|
public FileHexEditor(string installPath, TargetInfo target)
|
||||||
{
|
{
|
||||||
FileTargetInfo = target.Clone();
|
FileTargetInfo = target.Clone();
|
||||||
FileName = FileTargetInfo.Name;
|
FileName = FileTargetInfo.Name;
|
||||||
FilePath = Path.Combine(installPath, FileTargetInfo.RelativePath);
|
FilePath = Path.Combine(installPath, FileTargetInfo.RelativePath);
|
||||||
FileBakPath = FilePath + ".h.bak";
|
FileBakPath = FilePath + ".h.bak";
|
||||||
|
fileReplacedPath = FilePath + ".h.process";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备份
|
||||||
|
/// </summary>
|
||||||
public void Backup()
|
public void Backup()
|
||||||
{
|
{
|
||||||
File.Copy(FilePath, FileBakPath, true);
|
File.Copy(FilePath, FileBakPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 打补丁
|
||||||
|
/// 优先使用特定的补丁信息(存在对应SHA1信息)
|
||||||
|
/// 不存在补丁信息,使用通用版本替换方法
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Patch()
|
public bool Patch()
|
||||||
{
|
{
|
||||||
FileUtil.EditMultiHex(FilePath, FileModifyInfo.Changes);
|
FileUtil.EditMultiHex(FilePath, FileModifyInfo.Changes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 还原
|
||||||
|
/// </summary>
|
||||||
public void Restore()
|
public void Restore()
|
||||||
{
|
{
|
||||||
File.Copy(FileBakPath, FilePath, true);
|
File.Copy(FileBakPath, FilePath, true);
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
<Compile Include="FormMain.Designer.cs">
|
<Compile Include="FormMain.Designer.cs">
|
||||||
<DependentUpon>FormMain.cs</DependentUpon>
|
<DependentUpon>FormMain.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Matcher\BoyerMooreMatcher.cs" />
|
||||||
|
<Compile Include="Matcher\FuzzyMatcher.cs" />
|
||||||
<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" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user