diff --git a/RevokeMsgPatcher.Assistant/JsonData.cs b/RevokeMsgPatcher.Assistant/JsonData.cs index 8b1663e..57475df 100644 --- a/RevokeMsgPatcher.Assistant/JsonData.cs +++ b/RevokeMsgPatcher.Assistant/JsonData.cs @@ -798,5 +798,51 @@ namespace RevokeMsgPatcher } }; } + + public App DingTalk() + { + return new App + { + Name = "DingTalk", + MainAppRelativePath = @"main\current\DingTalk.exe", + FileTargetInfos = new Dictionary + { + { + "MainFrame.dll", + new TargetInfo + { + Name = "MainFrame.dll", + RelativePath = @"main\current\MainFrame.dll" + } + } + }, + FileCommonModifyInfos = new Dictionary> + { + { + "MainFrame.dll", + new List + { + new CommonModifyInfo + { + Name="MainFrame.dll", + StartVersion="4.0.00.00", + EndVersion="", + ReplacePatterns = new List + { + new ReplacePattern + { + Search = ByteUtil.HexStringToByteArray("CC CC CC CC CC CC CC 55 8B EC 83 E4 F8 6A FF 68"), + Replace = ByteUtil.HexStringToByteArray("CC CC CC CC CC CC CC C3 8B EC 83 E4 F8 6A FF 68"), + Start = 0x400000, + Category = "防撤回" + } + } + } + } + } + } + }; + } + } } diff --git a/RevokeMsgPatcher/Matcher/ModifyFinder.cs b/RevokeMsgPatcher/Matcher/ModifyFinder.cs index 4bb75cd..efff2bc 100644 --- a/RevokeMsgPatcher/Matcher/ModifyFinder.cs +++ b/RevokeMsgPatcher/Matcher/ModifyFinder.cs @@ -1,4 +1,5 @@ using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Utils; using System; using System.Collections.Generic; using System.IO; @@ -10,8 +11,8 @@ namespace RevokeMsgPatcher.Matcher // TODO 该逻辑需要优化! public static List FindChanges(string path, List replacePatterns) { - // 读取整个文件(dll) - byte[] fileByteArray = File.ReadAllBytes(path); + // 读取整个文件(dll) // 20200721 钉钉:读取 先不改了! + byte[] fileByteArray = FileUtil.ReadFileBytes(path, replacePatterns[0].Start); List changes = new List(); // 匹配且需要替换的地方 diff --git a/RevokeMsgPatcher/Model/App.cs b/RevokeMsgPatcher/Model/App.cs index 151935e..3a9dabc 100644 --- a/RevokeMsgPatcher/Model/App.cs +++ b/RevokeMsgPatcher/Model/App.cs @@ -10,6 +10,11 @@ namespace RevokeMsgPatcher.Model { public string Name { get; set; } + /// + /// 主程序相对路径, 非必填, 用于主程序版本号的使用 + /// + public string MainAppRelativePath { get; set; } + public Dictionary FileTargetInfos { get; set; } public Dictionary> FileModifyInfos { get; set; } diff --git a/RevokeMsgPatcher/Model/ReplacePattern.cs b/RevokeMsgPatcher/Model/ReplacePattern.cs index 38810f5..a3eb232 100644 --- a/RevokeMsgPatcher/Model/ReplacePattern.cs +++ b/RevokeMsgPatcher/Model/ReplacePattern.cs @@ -8,6 +8,8 @@ namespace RevokeMsgPatcher.Model public byte[] Replace { get; set; } + public int Start { get; set; } + public string Category { get; set; } public ReplacePattern Clone() diff --git a/RevokeMsgPatcher/Modifier/DingTalkModifier.cs b/RevokeMsgPatcher/Modifier/DingTalkModifier.cs new file mode 100644 index 0000000..83c9ba0 --- /dev/null +++ b/RevokeMsgPatcher/Modifier/DingTalkModifier.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Win32; +using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Utils; + +namespace RevokeMsgPatcher.Modifier +{ + class DingTalkModifier : AppModifier + { + public DingTalkModifier(App config) + { + this.config = config; + } + + /// + /// 钉钉 + /// x64: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\钉钉 + /// x86: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\钉钉 + /// + /// + public override string FindInstallPath() + { + string installPath = FindDingTalkInstallPathFromRegistry(); + if (!IsAllFilesExist(installPath)) + { + foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"DingDing")) + { + if (IsAllFilesExist(defaultPath)) + { + return defaultPath; + } + } + } + else + { + return installPath; + } + return null; + } + + private string FindDingTalkInstallPathFromRegistry() + { + List registryPaths = new List(); + // 获取系统位数 + if (Environment.Is64BitProcess) + { + registryPaths.Add(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\钉钉"); + } + else + { + registryPaths.Add(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\钉钉"); + } + try + { + object uninstallExe = null; + foreach (string registryPath in registryPaths) + { + RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\钉钉"); + if (key == null) + { + continue; + } + uninstallExe = key.GetValue("UninstallString"); + key.Close(); + if (uninstallExe != null && !string.IsNullOrEmpty(uninstallExe.ToString())) + { + break; + } + } + // 再判断一次 + if (uninstallExe != null && !string.IsNullOrEmpty(uninstallExe.ToString())) + { + return uninstallExe.ToString().Replace("uninst.exe", ""); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + return null; + } + + public override string GetVersion() + { + throw new NotImplementedException(); + } + + /// + /// a.初始化修改器 + /// 使用主程序的版本 + /// + /// APP安装路径 + public new void InitEditors(string installPath) + { + string mainVersion = GetVersion(); + // 初始化文件修改器 + editors = new List(); + foreach (TargetInfo info in config.FileTargetInfos.Values) + { + FileHexEditor editor = new FileHexEditor(installPath, info, mainVersion); + editors.Add(editor); + } + + } + } +} diff --git a/RevokeMsgPatcher/Modifier/FileHexEditor.cs b/RevokeMsgPatcher/Modifier/FileHexEditor.cs index 6dbea11..79db8e8 100644 --- a/RevokeMsgPatcher/Modifier/FileHexEditor.cs +++ b/RevokeMsgPatcher/Modifier/FileHexEditor.cs @@ -32,6 +32,7 @@ namespace RevokeMsgPatcher.Modifier { get { + // 获取当前最新的备份文件版本号 return FileUtil.GetFileVersion(FileBakPath); } } @@ -66,7 +67,7 @@ namespace RevokeMsgPatcher.Modifier /// public List TargetChanges { get; set; } - public FileHexEditor(string installPath, TargetInfo target) + public FileHexEditor(string installPath, TargetInfo target, string mainAppVersion = null) { FileTargetInfo = target.Clone(); FileName = FileTargetInfo.Name; diff --git a/RevokeMsgPatcher/RevokeMsgPatcher.csproj b/RevokeMsgPatcher/RevokeMsgPatcher.csproj index 3601ce4..921d596 100644 --- a/RevokeMsgPatcher/RevokeMsgPatcher.csproj +++ b/RevokeMsgPatcher/RevokeMsgPatcher.csproj @@ -75,6 +75,7 @@ + diff --git a/RevokeMsgPatcher/Utils/FileUtil.cs b/RevokeMsgPatcher/Utils/FileUtil.cs index e7bb263..a0fc512 100644 --- a/RevokeMsgPatcher/Utils/FileUtil.cs +++ b/RevokeMsgPatcher/Utils/FileUtil.cs @@ -74,5 +74,15 @@ namespace RevokeMsgPatcher.Utils } } } + + public static byte[] ReadFileBytes(string path, int start) + { + using (FileStream fsSource = new FileStream(path, FileMode.Open, FileAccess.Read)) + { + byte[] bytes = new byte[fsSource.Length - start]; + fsSource.Read(bytes, start, (int)fsSource.Length); + return bytes; + } + } } }