From 92594da9590d4792b48d90ac5e9022deb64a95c4 Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Wed, 18 Sep 2019 09:08:32 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E9=87=8D=E6=96=B0=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RevokeMsgPatcher/FormMain.Designer.cs | 89 ++++++++++++--------- RevokeMsgPatcher/FormMain.cs | 8 +- RevokeMsgPatcher/Model/App.cs | 4 +- RevokeMsgPatcher/Model/BinaryFile.cs | 5 +- RevokeMsgPatcher/Modifier/AppModifier.cs | 56 +++++++++++++ RevokeMsgPatcher/Modifier/FileHexEditor.cs | 12 +++ RevokeMsgPatcher/Modifier/QQModifier.cs | 12 +++ RevokeMsgPatcher/Modifier/TIMModifier.cs | 12 +++ RevokeMsgPatcher/Modifier/WechatModifier.cs | 37 +++++++++ RevokeMsgPatcher/RevokeMsgPatcher.csproj | 8 ++ RevokeMsgPatcher/Test.cs | 13 +++ RevokeMsgPatcher/Utils/HexEditUtil.cs | 12 +++ RevokeMsgPatcher/Utils/PathUtil.cs | 77 ++++++++++++++++++ 13 files changed, 304 insertions(+), 41 deletions(-) create mode 100644 RevokeMsgPatcher/Modifier/AppModifier.cs create mode 100644 RevokeMsgPatcher/Modifier/FileHexEditor.cs create mode 100644 RevokeMsgPatcher/Modifier/QQModifier.cs create mode 100644 RevokeMsgPatcher/Modifier/TIMModifier.cs create mode 100644 RevokeMsgPatcher/Modifier/WechatModifier.cs create mode 100644 RevokeMsgPatcher/Test.cs create mode 100644 RevokeMsgPatcher/Utils/HexEditUtil.cs create mode 100644 RevokeMsgPatcher/Utils/PathUtil.cs diff --git a/RevokeMsgPatcher/FormMain.Designer.cs b/RevokeMsgPatcher/FormMain.Designer.cs index 457ccab..dd11223 100644 --- a/RevokeMsgPatcher/FormMain.Designer.cs +++ b/RevokeMsgPatcher/FormMain.Designer.cs @@ -39,10 +39,9 @@ this.lblUpdatePachJson = new System.Windows.Forms.Label(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); - this.tabPage2 = new System.Windows.Forms.TabPage(); - this.tabPage3 = new System.Windows.Forms.TabPage(); - this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.tabPage2 = new System.Windows.Forms.TabPage(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); @@ -50,6 +49,7 @@ this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); + this.tabPage3 = new System.Windows.Forms.TabPage(); this.label8 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); @@ -57,6 +57,7 @@ this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); + this.btnTest = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); @@ -167,11 +168,29 @@ this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(483, 74); + this.tabPage1.Size = new System.Drawing.Size(483, 75); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "微信"; this.tabPage1.UseVisualStyleBackColor = true; // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(50, 44); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(35, 12); + this.label4.TabIndex = 10; + this.label4.Text = "0.0.1"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 44); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(41, 12); + this.label3.TabIndex = 9; + this.label3.Text = "版本:"; + // // tabPage2 // this.tabPage2.Controls.Add(this.label5); @@ -189,40 +208,6 @@ this.tabPage2.Text = "QQ"; this.tabPage2.UseVisualStyleBackColor = true; // - // tabPage3 - // - this.tabPage3.Controls.Add(this.label8); - this.tabPage3.Controls.Add(this.label9); - this.tabPage3.Controls.Add(this.textBox2); - this.tabPage3.Controls.Add(this.label10); - this.tabPage3.Controls.Add(this.button4); - this.tabPage3.Controls.Add(this.button5); - this.tabPage3.Controls.Add(this.button6); - this.tabPage3.Location = new System.Drawing.Point(4, 22); - this.tabPage3.Name = "tabPage3"; - this.tabPage3.Size = new System.Drawing.Size(483, 74); - this.tabPage3.TabIndex = 2; - this.tabPage3.Text = "TIM"; - this.tabPage3.UseVisualStyleBackColor = true; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 44); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(41, 12); - this.label3.TabIndex = 9; - this.label3.Text = "版本:"; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(50, 44); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(35, 12); - this.label4.TabIndex = 10; - this.label4.Text = "0.0.1"; - // // label5 // this.label5.AutoSize = true; @@ -286,6 +271,22 @@ this.button3.Text = "..."; this.button3.UseVisualStyleBackColor = true; // + // tabPage3 + // + this.tabPage3.Controls.Add(this.label8); + this.tabPage3.Controls.Add(this.label9); + this.tabPage3.Controls.Add(this.textBox2); + this.tabPage3.Controls.Add(this.label10); + this.tabPage3.Controls.Add(this.button4); + this.tabPage3.Controls.Add(this.button5); + this.tabPage3.Controls.Add(this.button6); + this.tabPage3.Location = new System.Drawing.Point(4, 22); + this.tabPage3.Name = "tabPage3"; + this.tabPage3.Size = new System.Drawing.Size(483, 75); + this.tabPage3.TabIndex = 2; + this.tabPage3.Text = "TIM"; + this.tabPage3.UseVisualStyleBackColor = true; + // // label8 // this.label8.AutoSize = true; @@ -349,11 +350,22 @@ this.button6.Text = "..."; this.button6.UseVisualStyleBackColor = true; // + // btnTest + // + this.btnTest.Location = new System.Drawing.Point(380, 13); + this.btnTest.Name = "btnTest"; + this.btnTest.Size = new System.Drawing.Size(62, 34); + this.btnTest.TabIndex = 11; + this.btnTest.Text = "Test!"; + this.btnTest.UseVisualStyleBackColor = true; + this.btnTest.Click += new System.EventHandler(this.btnTest_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(491, 138); + this.Controls.Add(this.btnTest); this.Controls.Add(this.tabControl1); this.Controls.Add(this.lblUpdatePachJson); this.Controls.Add(this.linkLabel1); @@ -404,6 +416,7 @@ private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button btnTest; } } diff --git a/RevokeMsgPatcher/FormMain.cs b/RevokeMsgPatcher/FormMain.cs index a7a9649..aba9a64 100644 --- a/RevokeMsgPatcher/FormMain.cs +++ b/RevokeMsgPatcher/FormMain.cs @@ -1,4 +1,5 @@ -using System; +using RevokeMsgPatcher.Utils; +using System; using System.IO; using System.Net; using System.Threading.Tasks; @@ -158,5 +159,10 @@ namespace RevokeMsgPatcher }); MessageBox.Show("当前所支持的微信版本:" + Environment.NewLine + versions); } + + private void btnTest_Click(object sender, EventArgs e) + { + PathUtil.DisplayAllProgram(); + } } } diff --git a/RevokeMsgPatcher/Model/App.cs b/RevokeMsgPatcher/Model/App.cs index 59ce918..29f6014 100644 --- a/RevokeMsgPatcher/Model/App.cs +++ b/RevokeMsgPatcher/Model/App.cs @@ -10,6 +10,8 @@ namespace RevokeMsgPatcher.Model { public string Name { get; set; } - public List Versions { get; set; } + public string[] ModifyFilePaths { get; set; } + + public List ModifyFileInfos { get; set; } } } diff --git a/RevokeMsgPatcher/Model/BinaryFile.cs b/RevokeMsgPatcher/Model/BinaryFile.cs index c3b7256..6243494 100644 --- a/RevokeMsgPatcher/Model/BinaryFile.cs +++ b/RevokeMsgPatcher/Model/BinaryFile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +9,9 @@ namespace RevokeMsgPatcher.Model { public class BinaryFile { - public string Name { get; set; } + //public string Name { get {return Path.GetFileName(RelativePath); } } + + public string RelativePath { get; set; } public string Version { get; set; } diff --git a/RevokeMsgPatcher/Modifier/AppModifier.cs b/RevokeMsgPatcher/Modifier/AppModifier.cs new file mode 100644 index 0000000..fa589cc --- /dev/null +++ b/RevokeMsgPatcher/Modifier/AppModifier.cs @@ -0,0 +1,56 @@ +using RevokeMsgPatcher.Model; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Modifier +{ + public abstract class AppModifier + { + private App config; + + private List editors; + + // 1. 获取安装目录 + // 2. 验证安装目录 通过 BinaryFiles + // 3. 判断所有 BinaryFiles 是否符合防撤回要求 + // 4. 备份所有 BinaryFiles // *.h.bak + // 5. 对每个 BinaryFile 中的 Changes 循环修改(修改前要测试它的读写性质,是否被程序占用等) + + // 获取版本号 + // 通过SHA1判断是否可以进行16进制编辑 先判断版本号 再判断SHA1 根据不同结果返回不同的提示 + + // ?多文件的备份回退 // 暂定有一个备份文件就点亮按钮 + + public abstract string FindInstallPath(); + + //public abstract bool ValidateInstallPath(); + + public abstract bool GetVersion(); + + public bool IsAllBinaryFilesExist(string installPath) + { + int success = 0; + foreach(string relativePath in config.ModifyFilePaths) + { + string filePath = Path.Combine(installPath, relativePath); + if(File.Exists(filePath)) + { + success++; + } + } + if(success == config.ModifyFilePaths.Length) + { + return true; + } + else + { + return false; + } + } + + } +} diff --git a/RevokeMsgPatcher/Modifier/FileHexEditor.cs b/RevokeMsgPatcher/Modifier/FileHexEditor.cs new file mode 100644 index 0000000..c3f4055 --- /dev/null +++ b/RevokeMsgPatcher/Modifier/FileHexEditor.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Modifier +{ + public class FileHexEditor + { + } +} diff --git a/RevokeMsgPatcher/Modifier/QQModifier.cs b/RevokeMsgPatcher/Modifier/QQModifier.cs new file mode 100644 index 0000000..5f41d86 --- /dev/null +++ b/RevokeMsgPatcher/Modifier/QQModifier.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Modifier +{ + class QQModifier + { + } +} diff --git a/RevokeMsgPatcher/Modifier/TIMModifier.cs b/RevokeMsgPatcher/Modifier/TIMModifier.cs new file mode 100644 index 0000000..800318e --- /dev/null +++ b/RevokeMsgPatcher/Modifier/TIMModifier.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Modifier +{ + class TIMModifier + { + } +} diff --git a/RevokeMsgPatcher/Modifier/WechatModifier.cs b/RevokeMsgPatcher/Modifier/WechatModifier.cs new file mode 100644 index 0000000..f5ee869 --- /dev/null +++ b/RevokeMsgPatcher/Modifier/WechatModifier.cs @@ -0,0 +1,37 @@ +using RevokeMsgPatcher.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Modifier +{ + class WechatModifier : AppModifier + { + public override string FindInstallPath() + { + string installPath = PathUtil.FindInstallPathFromRegistry("Wecaht"); + if(!IsAllBinaryFilesExist(installPath)) + { + foreach(string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\Wechat")) + { + if(IsAllBinaryFilesExist(defaultPath)) + { + return defaultPath; + } + } + } + else + { + return installPath; + } + return null; + } + + public override bool GetVersion() + { + throw new NotImplementedException(); + } + } +} diff --git a/RevokeMsgPatcher/RevokeMsgPatcher.csproj b/RevokeMsgPatcher/RevokeMsgPatcher.csproj index a142f2f..01435c2 100644 --- a/RevokeMsgPatcher/RevokeMsgPatcher.csproj +++ b/RevokeMsgPatcher/RevokeMsgPatcher.csproj @@ -60,10 +60,18 @@ + + + + + + + + FormMain.cs diff --git a/RevokeMsgPatcher/Test.cs b/RevokeMsgPatcher/Test.cs new file mode 100644 index 0000000..7de9ff4 --- /dev/null +++ b/RevokeMsgPatcher/Test.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher +{ + + class Test + { + } +} diff --git a/RevokeMsgPatcher/Utils/HexEditUtil.cs b/RevokeMsgPatcher/Utils/HexEditUtil.cs new file mode 100644 index 0000000..ab05ac8 --- /dev/null +++ b/RevokeMsgPatcher/Utils/HexEditUtil.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Utils +{ + class HexEditUtil + { + } +} diff --git a/RevokeMsgPatcher/Utils/PathUtil.cs b/RevokeMsgPatcher/Utils/PathUtil.cs new file mode 100644 index 0000000..5c8f44f --- /dev/null +++ b/RevokeMsgPatcher/Utils/PathUtil.cs @@ -0,0 +1,77 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Utils +{ + public class PathUtil + { + public static void DisplayAllProgram() + { + RegistryKey uninstallKey, programKey; + uninstallKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); + string[] programKeys = uninstallKey.GetSubKeyNames(); + foreach (string keyName in programKeys) + { + programKey = uninstallKey.OpenSubKey(keyName); + Console.WriteLine(keyName + " , " + programKey.GetValue("DisplayName") + " , " + programKey.GetValue("InstallLocation")); + programKey.Close(); + } + uninstallKey.Close(); + } + + /// + /// 从注册表中寻找安装路径 + /// + /// + /// 安装信息的注册表键名 + /// 微信:WeChat + /// QQ:{052CFB79-9D62-42E3-8A15-DE66C2C97C3E} + /// TIM:TIM + /// + /// 安装路径 + public static string FindInstallPathFromRegistry(string uninstallKeyName) + { + try + { + RegistryKey key = Registry.LocalMachine.OpenSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{uninstallKeyName}"); + object installLocation = key.GetValue("InstallLocation"); + key.Close(); + if (installLocation != null && !string.IsNullOrEmpty(installLocation.ToString())) + { + return installLocation.ToString(); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + return null; + } + + /// + /// 获取所有可能的默认安装路径 + /// + /// Tencent\* + /// + public static List GetDefaultInstallPaths(string relativePath) + { + List list = new List(); + // 从默认安装目录查找 + string[] drives = Environment.GetLogicalDrives(); //获取当前计算机逻辑磁盘名称列表 + foreach (string d in drives) + { + string path = Path.Combine(d, $@"Program Files (x86)\{relativePath}"); + if(Directory.Exists(path)) + { + list.Add(path); + } + } + return list; + } + } +}