This commit is contained in:
辉鸭蛋
2024-06-14 23:18:46 +08:00
parent 4de179192d
commit f734a67586
10 changed files with 239 additions and 31 deletions
+55 -24
View File
@@ -22,7 +22,11 @@ namespace RevokeMsgPatcher.Modifier
{
protected App config;
public App Config { set { config = value; } get { return config; } }
public App Config
{
set { config = value; }
get { return config; }
}
protected List<FileHexEditor> editors;
@@ -56,18 +60,22 @@ namespace RevokeMsgPatcher.Modifier
foreach (FileHexEditor editor in editors) // 多种文件
{
// 精确版本匹配
bool haven = false;
foreach (ModifyInfo modifyInfo in config.FileModifyInfos[editor.FileName]) // 多个版本信息
if (config.FileModifyInfos != null && config.FileModifyInfos.Count > 0)
{
if (editor.FileVersion == modifyInfo.Version)
bool haven = false;
foreach (ModifyInfo modifyInfo in config.FileModifyInfos[editor.FileName]) // 多个版本信息
{
haven = true;
break;
if (editor.FileVersion == modifyInfo.Version)
{
haven = true;
break;
}
}
if (haven)
{
i++;
}
}
if (haven)
{
i++;
}
}
@@ -102,16 +110,19 @@ namespace RevokeMsgPatcher.Modifier
categories.Add(c);
}
}
// 获取已经安装过的功能类型
SortedSet<string> replaced = ModifyFinder.FindReplacedFunction(editor.FilePath, commonModifyInfo.ReplacePatterns);
foreach (string c in replaced)
{
installed.Add(c);
}
inRange = true;
break;
}
}
if (inRange)
{
j++;
@@ -132,7 +143,6 @@ namespace RevokeMsgPatcher.Modifier
label.ForeColor = Color.Red;
UIController.AddMsgToPanel(panel, "无功能选项");
}
}
/// <summary>
@@ -146,6 +156,7 @@ namespace RevokeMsgPatcher.Modifier
{
return false;
}
int success = 0, count = 0;
foreach (TargetInfo info in config.FileTargetInfos.Values)
{
@@ -159,6 +170,7 @@ namespace RevokeMsgPatcher.Modifier
}
}
}
if (success == count && success >= 1)
{
return true;
@@ -189,6 +201,7 @@ namespace RevokeMsgPatcher.Modifier
{
Console.WriteLine("判断版本范围时出错:" + e.Message);
}
return false;
}
@@ -207,6 +220,7 @@ namespace RevokeMsgPatcher.Modifier
return commonModifyInfo;
}
}
return null;
}
@@ -225,6 +239,7 @@ namespace RevokeMsgPatcher.Modifier
break;
}
}
if (i == editors.Count)
{
return true;
@@ -253,11 +268,13 @@ namespace RevokeMsgPatcher.Modifier
editors.Add(editor);
}
}
if (editors.Count == 0)
{
MessageBox.Show("当前版本没有对应的文件修改信息,请确认补丁信息是否正常!");
return false;
}
return true;
}
@@ -272,26 +289,30 @@ namespace RevokeMsgPatcher.Modifier
{
// 通过SHA1和文件版本判断是否可以打补丁 根据不同结果返回不同的提示
ModifyInfo matchingSHA1Before = null, matchingSHA1After = null, matchingVersion = null;
foreach (ModifyInfo modifyInfo in config.FileModifyInfos[editor.FileName]) // 多个版本信息
if (config.FileModifyInfos != null && config.FileModifyInfos.Count > 0)
{
if (modifyInfo.Name == editor.FileName) // 保险用的无用判断
foreach (ModifyInfo modifyInfo in config.FileModifyInfos[editor.FileName]) // 多个版本信息
{
if (editor.FileSHA1 == modifyInfo.SHA1After)
if (modifyInfo.Name == editor.FileName) // 保险用的无用判断
{
matchingSHA1After = modifyInfo;
}
else if (editor.FileSHA1 == modifyInfo.SHA1Before)
{
matchingSHA1Before = modifyInfo;
}
if (editor.FileSHA1 == modifyInfo.SHA1After)
{
matchingSHA1After = modifyInfo;
}
else if (editor.FileSHA1 == modifyInfo.SHA1Before)
{
matchingSHA1Before = modifyInfo;
}
if (editor.FileVersion == modifyInfo.Version)
{
matchingVersion = modifyInfo;
if (editor.FileVersion == modifyInfo.Version)
{
matchingVersion = modifyInfo;
}
}
}
}
// 补丁前SHA1匹配上,肯定是正确的dll
if (matchingSHA1Before != null)
{
@@ -299,6 +320,7 @@ namespace RevokeMsgPatcher.Modifier
editor.TargetChanges = matchingSHA1Before.Changes;
continue;
}
// 补丁后SHA1匹配上,肯定已经打过补丁
if (matchingSHA1After != null)
{
@@ -324,6 +346,7 @@ namespace RevokeMsgPatcher.Modifier
{
replacePatterns = editor.FileCommonModifyInfo.ReplacePatterns.Where(info => categories.Contains(info.Category)).ToList();
}
// 如果能顺利得到 TargetChanges 不报错则可以使用特征替换方式
editor.TargetChanges = ModifyFinder.FindChanges(editor.FilePath, replacePatterns);
continue;
@@ -335,6 +358,7 @@ namespace RevokeMsgPatcher.Modifier
{
throw new BusinessException("not_support", $"不支持的文件:名称 {editor.FileName} 版本 {editor.FileVersion}");
}
// SHA1不匹配,但是版本匹配,可能dll已经被其他补丁程序修改过
if (matchingVersion != null)
{
@@ -357,6 +381,7 @@ namespace RevokeMsgPatcher.Modifier
{
throw new Exception("补丁安装失败,原因:无对应的文件修改器");
}
foreach (FileHexEditor editor in editors)
{
if (editor == null)
@@ -364,11 +389,13 @@ namespace RevokeMsgPatcher.Modifier
throw new Exception("补丁安装失败,原因:文件修改器初始化失败!");
}
}
// 再备份所有文件
foreach (FileHexEditor editor in editors)
{
editor.Backup();
}
// 打补丁!
List<FileHexEditor> done = new List<FileHexEditor>(); // 已经打上补丁的
try
@@ -394,8 +421,10 @@ namespace RevokeMsgPatcher.Modifier
{
editor.Restore();
}
throw ex;
}
return true;
}
@@ -408,6 +437,7 @@ namespace RevokeMsgPatcher.Modifier
return false;
}
}
return true;
}
@@ -440,6 +470,7 @@ namespace RevokeMsgPatcher.Modifier
editor.Restore();
}
}
return true;
}
else
@@ -448,4 +479,4 @@ namespace RevokeMsgPatcher.Modifier
}
}
}
}
}
+79
View File
@@ -0,0 +1,79 @@
using RevokeMsgPatcher.Model;
using RevokeMsgPatcher.Utils;
using System;
using System.Collections.Generic;
using System.IO;
namespace RevokeMsgPatcher.Modifier
{
class QQNTModifier : AppModifier
{
public QQNTModifier(App config)
{
this.config = config;
}
/// <summary>
/// 自动寻找获取微信安装路径
/// </summary>
/// <returns></returns>
public override string FindInstallPath()
{
try
{
string installPath = PathUtil.FindInstallPathFromRegistryWOW6432Node("QQ");
if (!string.IsNullOrEmpty(installPath))
{
installPath = Path.GetDirectoryName(installPath);
if (IsAllFilesExist(installPath))
{
return installPath;
}
}
installPath = PathUtil.FindInstallPathFromRegistry("QQNT");
if (!IsAllFilesExist(installPath))
{
List<string> defaultPathList = PathUtil.GetDefaultInstallPaths(@"Tencent\QQNT");
foreach (string defaultPath in defaultPathList)
{
if (IsAllFilesExist(defaultPath))
{
return defaultPath;
}
}
}
else
{
return installPath;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return null;
}
/// <summary>
/// 获取整个APP的当前版本
/// </summary>
/// <returns></returns>
public override string GetVersion()
{
if (editors != null && editors.Count > 0)
{
foreach (FileHexEditor editor in editors)
{
if (editor.FileName == "QQ.exe")
{
return editor.FileVersion;
}
}
}
return "";
}
}
}