diff --git a/RevokeMsgPatcher/FormMain.Designer.cs b/RevokeMsgPatcher/FormMain.Designer.cs index dd11223..b39c9e9 100644 --- a/RevokeMsgPatcher/FormMain.Designer.cs +++ b/RevokeMsgPatcher/FormMain.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); - this.label2 = new System.Windows.Forms.Label(); + this.lblPathTag = new System.Windows.Forms.Label(); this.btnPatch = new System.Windows.Forms.Button(); this.txtPath = new System.Windows.Forms.TextBox(); this.btnChoosePath = new System.Windows.Forms.Button(); @@ -37,45 +37,27 @@ this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.btnRestore = new System.Windows.Forms.Button(); this.lblUpdatePachJson = new System.Windows.Forms.Label(); - this.tabControl1 = new System.Windows.Forms.TabControl(); - this.tabPage1 = new System.Windows.Forms.TabPage(); - this.label4 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.tabPage2 = new System.Windows.Forms.TabPage(); + this.lblVersion = new System.Windows.Forms.Label(); + this.lblVersionTag = new System.Windows.Forms.Label(); + this.rbtWechat = new System.Windows.Forms.RadioButton(); + this.rbtQQ = new System.Windows.Forms.RadioButton(); + this.rbtTIM = new System.Windows.Forms.RadioButton(); this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.label7 = new System.Windows.Forms.Label(); - 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(); - this.label10 = new System.Windows.Forms.Label(); - 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(); - this.tabPage3.SuspendLayout(); + this.panelMask = new System.Windows.Forms.Panel(); this.SuspendLayout(); // - // label2 + // lblPathTag // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(6, 17); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(41, 12); - this.label2.TabIndex = 1; - this.label2.Text = "路径:"; + this.lblPathTag.AutoSize = true; + this.lblPathTag.Location = new System.Drawing.Point(12, 34); + this.lblPathTag.Name = "lblPathTag"; + this.lblPathTag.Size = new System.Drawing.Size(65, 12); + this.lblPathTag.TabIndex = 1; + this.lblPathTag.Text = "应用路径:"; // // btnPatch // - this.btnPatch.Location = new System.Drawing.Point(366, 39); + this.btnPatch.Location = new System.Drawing.Point(372, 56); this.btnPatch.Name = "btnPatch"; this.btnPatch.Size = new System.Drawing.Size(102, 23); this.btnPatch.TabIndex = 3; @@ -85,16 +67,15 @@ // // txtPath // - this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtPath.Location = new System.Drawing.Point(52, 12); + this.txtPath.Location = new System.Drawing.Point(82, 29); this.txtPath.Name = "txtPath"; - this.txtPath.Size = new System.Drawing.Size(376, 21); + this.txtPath.Size = new System.Drawing.Size(352, 21); this.txtPath.TabIndex = 4; + this.txtPath.TextChanged += new System.EventHandler(this.txtPath_TextChanged); // // btnChoosePath // - this.btnChoosePath.Location = new System.Drawing.Point(434, 12); + this.btnChoosePath.Location = new System.Drawing.Point(440, 27); this.btnChoosePath.Name = "btnChoosePath"; this.btnChoosePath.Size = new System.Drawing.Size(34, 23); this.btnChoosePath.TabIndex = 5; @@ -105,7 +86,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(7, 13); + this.label1.Location = new System.Drawing.Point(12, 87); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(101, 12); this.label1.TabIndex = 6; @@ -114,7 +95,7 @@ // linkLabel1 // this.linkLabel1.AutoSize = true; - this.linkLabel1.Location = new System.Drawing.Point(102, 13); + this.linkLabel1.Location = new System.Drawing.Point(119, 87); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(41, 12); this.linkLabel1.TabIndex = 7; @@ -124,7 +105,7 @@ // // btnRestore // - this.btnRestore.Location = new System.Drawing.Point(258, 39); + this.btnRestore.Location = new System.Drawing.Point(264, 56); this.btnRestore.Name = "btnRestore"; this.btnRestore.Size = new System.Drawing.Size(102, 23); this.btnRestore.TabIndex = 8; @@ -134,240 +115,103 @@ // // lblUpdatePachJson // - this.lblUpdatePachJson.AutoSize = true; this.lblUpdatePachJson.Cursor = System.Windows.Forms.Cursors.Hand; - this.lblUpdatePachJson.Location = new System.Drawing.Point(196, 13); + this.lblUpdatePachJson.Location = new System.Drawing.Point(312, 89); this.lblUpdatePachJson.Name = "lblUpdatePachJson"; - this.lblUpdatePachJson.Size = new System.Drawing.Size(131, 12); + this.lblUpdatePachJson.Size = new System.Drawing.Size(162, 12); this.lblUpdatePachJson.TabIndex = 9; - this.lblUpdatePachJson.Text = "获取最新补丁信息中..."; + this.lblUpdatePachJson.Text = "[ 获取最新补丁信息中... ]"; + this.lblUpdatePachJson.TextAlign = System.Drawing.ContentAlignment.TopRight; this.lblUpdatePachJson.Click += new System.EventHandler(this.lblUpdatePachJson_Click); // - // tabControl1 + // lblVersion // - this.tabControl1.Controls.Add(this.tabPage1); - this.tabControl1.Controls.Add(this.tabPage2); - this.tabControl1.Controls.Add(this.tabPage3); - this.tabControl1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.tabControl1.Location = new System.Drawing.Point(0, 37); - this.tabControl1.Multiline = true; - this.tabControl1.Name = "tabControl1"; - this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(491, 101); - this.tabControl1.TabIndex = 10; + this.lblVersion.AutoSize = true; + this.lblVersion.Location = new System.Drawing.Point(83, 61); + this.lblVersion.Name = "lblVersion"; + this.lblVersion.Size = new System.Drawing.Size(35, 12); + this.lblVersion.TabIndex = 10; + this.lblVersion.Text = "0.0.1"; // - // tabPage1 + // lblVersionTag // - this.tabPage1.Controls.Add(this.label4); - this.tabPage1.Controls.Add(this.label3); - this.tabPage1.Controls.Add(this.txtPath); - this.tabPage1.Controls.Add(this.label2); - this.tabPage1.Controls.Add(this.btnRestore); - this.tabPage1.Controls.Add(this.btnPatch); - this.tabPage1.Controls.Add(this.btnChoosePath); - 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, 75); - this.tabPage1.TabIndex = 0; - this.tabPage1.Text = "微信"; - this.tabPage1.UseVisualStyleBackColor = true; + this.lblVersionTag.AutoSize = true; + this.lblVersionTag.Location = new System.Drawing.Point(12, 61); + this.lblVersionTag.Name = "lblVersionTag"; + this.lblVersionTag.Size = new System.Drawing.Size(65, 12); + this.lblVersionTag.TabIndex = 9; + this.lblVersionTag.Text = "当前版本:"; // - // label4 + // rbtWechat // - 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"; + this.rbtWechat.AutoSize = true; + this.rbtWechat.Checked = true; + this.rbtWechat.Location = new System.Drawing.Point(82, 7); + this.rbtWechat.Name = "rbtWechat"; + this.rbtWechat.Size = new System.Drawing.Size(47, 16); + this.rbtWechat.TabIndex = 12; + this.rbtWechat.TabStop = true; + this.rbtWechat.Text = "微信"; + this.rbtWechat.UseVisualStyleBackColor = true; + this.rbtWechat.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged); // - // label3 + // rbtQQ // - 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 = "版本:"; + this.rbtQQ.AutoSize = true; + this.rbtQQ.Location = new System.Drawing.Point(140, 7); + this.rbtQQ.Name = "rbtQQ"; + this.rbtQQ.Size = new System.Drawing.Size(35, 16); + this.rbtQQ.TabIndex = 13; + this.rbtQQ.Text = "QQ"; + this.rbtQQ.UseVisualStyleBackColor = true; + this.rbtQQ.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged); // - // tabPage2 + // rbtTIM // - this.tabPage2.Controls.Add(this.label5); - this.tabPage2.Controls.Add(this.label6); - this.tabPage2.Controls.Add(this.textBox1); - this.tabPage2.Controls.Add(this.label7); - this.tabPage2.Controls.Add(this.button1); - this.tabPage2.Controls.Add(this.button2); - this.tabPage2.Controls.Add(this.button3); - this.tabPage2.Location = new System.Drawing.Point(4, 22); - this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(483, 75); - this.tabPage2.TabIndex = 1; - this.tabPage2.Text = "QQ"; - this.tabPage2.UseVisualStyleBackColor = true; + this.rbtTIM.AutoSize = true; + this.rbtTIM.Location = new System.Drawing.Point(186, 7); + this.rbtTIM.Name = "rbtTIM"; + this.rbtTIM.Size = new System.Drawing.Size(41, 16); + this.rbtTIM.TabIndex = 14; + this.rbtTIM.Text = "TIM"; + this.rbtTIM.UseVisualStyleBackColor = true; + this.rbtTIM.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged); // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(50, 44); + this.label5.Location = new System.Drawing.Point(12, 9); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(35, 12); - this.label5.TabIndex = 17; - this.label5.Text = "0.0.1"; + this.label5.Size = new System.Drawing.Size(65, 12); + this.label5.TabIndex = 16; + this.label5.Text = "选择应用:"; // - // label6 + // panelMask // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(6, 44); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(41, 12); - this.label6.TabIndex = 16; - this.label6.Text = "版本:"; - // - // textBox1 - // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.Location = new System.Drawing.Point(52, 12); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(376, 21); - this.textBox1.TabIndex = 13; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(6, 17); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(41, 12); - this.label7.TabIndex = 11; - this.label7.Text = "路径:"; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(258, 39); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(102, 23); - this.button1.TabIndex = 15; - this.button1.Text = "备份还原"; - this.button1.UseVisualStyleBackColor = true; - // - // button2 - // - this.button2.Location = new System.Drawing.Point(366, 39); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(102, 23); - this.button2.TabIndex = 12; - this.button2.Text = "点我防撤回!"; - this.button2.UseVisualStyleBackColor = true; - // - // button3 - // - this.button3.Location = new System.Drawing.Point(434, 12); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(34, 23); - this.button3.TabIndex = 14; - 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; - this.label8.Location = new System.Drawing.Point(50, 44); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(35, 12); - this.label8.TabIndex = 17; - this.label8.Text = "0.0.1"; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(6, 44); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(41, 12); - this.label9.TabIndex = 16; - this.label9.Text = "版本:"; - // - // textBox2 - // - this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox2.Location = new System.Drawing.Point(52, 12); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(376, 21); - this.textBox2.TabIndex = 13; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(6, 17); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(41, 12); - this.label10.TabIndex = 11; - this.label10.Text = "路径:"; - // - // button4 - // - this.button4.Location = new System.Drawing.Point(258, 39); - this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(102, 23); - this.button4.TabIndex = 15; - this.button4.Text = "备份还原"; - this.button4.UseVisualStyleBackColor = true; - // - // button5 - // - this.button5.Location = new System.Drawing.Point(366, 39); - this.button5.Name = "button5"; - this.button5.Size = new System.Drawing.Size(102, 23); - this.button5.TabIndex = 12; - this.button5.Text = "点我防撤回!"; - this.button5.UseVisualStyleBackColor = true; - // - // button6 - // - this.button6.Location = new System.Drawing.Point(434, 12); - this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(34, 23); - this.button6.TabIndex = 14; - 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); + this.panelMask.Location = new System.Drawing.Point(140, 127); + this.panelMask.Name = "panelMask"; + this.panelMask.Size = new System.Drawing.Size(157, 58); + this.panelMask.TabIndex = 17; + this.panelMask.Visible = false; // // 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.ClientSize = new System.Drawing.Size(490, 110); this.Controls.Add(this.lblUpdatePachJson); + this.Controls.Add(this.panelMask); + this.Controls.Add(this.lblVersion); + this.Controls.Add(this.lblVersionTag); + this.Controls.Add(this.label5); + this.Controls.Add(this.txtPath); + this.Controls.Add(this.rbtTIM); + this.Controls.Add(this.lblPathTag); + this.Controls.Add(this.rbtQQ); + this.Controls.Add(this.btnRestore); + this.Controls.Add(this.rbtWechat); + this.Controls.Add(this.btnPatch); + this.Controls.Add(this.btnChoosePath); this.Controls.Add(this.linkLabel1); this.Controls.Add(this.label1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -375,20 +219,13 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "微信/QQ/TIM防撤回补丁"; this.Load += new System.EventHandler(this.FormMain_Load); - this.tabControl1.ResumeLayout(false); - this.tabPage1.ResumeLayout(false); - this.tabPage1.PerformLayout(); - this.tabPage2.ResumeLayout(false); - this.tabPage2.PerformLayout(); - this.tabPage3.ResumeLayout(false); - this.tabPage3.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label lblPathTag; private System.Windows.Forms.Button btnPatch; private System.Windows.Forms.TextBox txtPath; private System.Windows.Forms.Button btnChoosePath; @@ -396,27 +233,13 @@ private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.Button btnRestore; private System.Windows.Forms.Label lblUpdatePachJson; - private System.Windows.Forms.TabControl tabControl1; - private System.Windows.Forms.TabPage tabPage1; - private System.Windows.Forms.TabPage tabPage2; - private System.Windows.Forms.TabPage tabPage3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label lblVersion; + private System.Windows.Forms.Label lblVersionTag; + private System.Windows.Forms.RadioButton rbtWechat; + private System.Windows.Forms.RadioButton rbtQQ; + private System.Windows.Forms.RadioButton rbtTIM; private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button button2; - private System.Windows.Forms.Button button3; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.TextBox textBox2; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.Button button4; - private System.Windows.Forms.Button button5; - private System.Windows.Forms.Button button6; - private System.Windows.Forms.Button btnTest; + private System.Windows.Forms.Panel panelMask; } } diff --git a/RevokeMsgPatcher/FormMain.cs b/RevokeMsgPatcher/FormMain.cs index 4637eac..b0ff41d 100644 --- a/RevokeMsgPatcher/FormMain.cs +++ b/RevokeMsgPatcher/FormMain.cs @@ -1,6 +1,8 @@ -using RevokeMsgPatcher.Modifier; +using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Modifier; using RevokeMsgPatcher.Utils; using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; @@ -10,7 +12,24 @@ namespace RevokeMsgPatcher { public partial class FormMain : Form { - WechatModifier wechatModifier = new WechatModifier(); + AppModifier modifier = null; + + public void InitModifier() + { + Bag bag = new JsonData().Bag(); + + WechatModifier wechatModifier = new WechatModifier(bag.Apps["Wechat"]); + QQModifier qqModifier = new QQModifier(bag.Apps["QQ"]); + TIMModifier timModifier = new TIMModifier(bag.Apps["TIM"]); + + rbtWechat.Tag = wechatModifier; + rbtQQ.Tag = qqModifier; + rbtTIM.Tag = timModifier; + + // 默认微信 + rbtWechat.Enabled = true; + modifier = wechatModifier; + } public FormMain() { @@ -24,67 +43,86 @@ namespace RevokeMsgPatcher } this.Text += currentVersion; + InitModifier(); + InitControls(); + + } + + private void InitControls() + { // 自动获取应用安装路径 - txtPath.Text = wechatModifier.FindInstallPath(); + txtPath.Text = modifier.FindInstallPath(); + lblVersion.Text = modifier.GetVersion(); // 显示是否能够备份还原 if (!string.IsNullOrEmpty(txtPath.Text)) { - wechatModifier.InitEditors(txtPath.Text); - btnRestore.Enabled = wechatModifier.BackupExists(); + modifier.InitEditors(txtPath.Text); + btnRestore.Enabled = modifier.BackupExists(); } - } private void btnPatch_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(txtPath.Text) || !wechatModifier.IsAllFilesExist(txtPath.Text)) + if (!modifier.IsAllFilesExist(txtPath.Text)) { - MessageBox.Show("请选择微信安装路径!"); + MessageBox.Show("请选择正确的安装路径!"); return; } + EnableAllButton(false); // a.重新初始化编辑器 - wechatModifier.InitEditors(txtPath.Text); - btnPatch.Enabled = false; + modifier.InitEditors(txtPath.Text); // b.计算SHA1,验证文件完整性,寻找对应的补丁信息 try { - wechatModifier.ValidateAndFindModifyInfo(); + modifier.ValidateAndFindModifyInfo(); } catch (Exception ex) { MessageBox.Show(ex.Message); + EnableAllButton(true); + btnRestore.Enabled = modifier.BackupExists(); + return; } // c.打补丁 try { - wechatModifier.Patch(); + modifier.Patch(); + MessageBox.Show("补丁安装成功!"); + EnableAllButton(true); + btnRestore.Enabled = modifier.BackupExists(); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(ex.Message + " 请以管理员权限启动本程序,并确认微信处于关闭状态。"); + EnableAllButton(true); + btnRestore.Enabled = modifier.BackupExists(); } - btnPatch.Enabled = true; } private void txtPath_TextChanged(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(txtPath.Text)) + if (modifier.IsAllFilesExist(txtPath.Text)) { - wechatModifier.InitEditors(txtPath.Text); - btnRestore.Enabled = wechatModifier.BackupExists(); + modifier.InitEditors(txtPath.Text); + btnRestore.Enabled = modifier.BackupExists(); + } + else + { + btnPatch.Enabled = false; + btnRestore.Enabled = false; } } private void btnChoosePath_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); - dialog.Description = "请选择微信安装路径"; + dialog.Description = "请选择安装路径"; if (dialog.ShowDialog() == DialogResult.OK) { - if (string.IsNullOrEmpty(dialog.SelectedPath) || !wechatModifier.IsAllFilesExist(dialog.SelectedPath)) + if (string.IsNullOrEmpty(dialog.SelectedPath) || !modifier.IsAllFilesExist(dialog.SelectedPath)) { - MessageBox.Show("无法找到微信关键文件,请选择正确的微信安装路径!"); + MessageBox.Show("无法找到此应用的关键文件,请选择正确的安装路径!"); } else { @@ -95,17 +133,19 @@ namespace RevokeMsgPatcher private void btnRestore_Click(object sender, EventArgs e) { - btnRestore.Enabled = false; + EnableAllButton(false); try { - wechatModifier.Restore(); + modifier.Restore(); + MessageBox.Show("还原成功!"); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(ex.Message); } - btnRestore.Enabled = wechatModifier.BackupExists(); + EnableAllButton(true); + btnRestore.Enabled = modifier.BackupExists(); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -122,16 +162,16 @@ namespace RevokeMsgPatcher }); t.Start(); string json = await t; - if(string.IsNullOrEmpty(json)) + if (string.IsNullOrEmpty(json)) { - lblUpdatePachJson.Text = "获取失败"; + lblUpdatePachJson.Text = "[ 获取失败 ]"; - } else + } + else { //patcher.SetNewPatchJson(json); - lblUpdatePachJson.Text = "获取成功"; + lblUpdatePachJson.Text = "[ 获取成功 ]"; } - } private void lblUpdatePachJson_Click(object sender, EventArgs e) @@ -144,9 +184,42 @@ namespace RevokeMsgPatcher MessageBox.Show("当前所支持的微信版本:" + Environment.NewLine + versions); } - private void btnTest_Click(object sender, EventArgs e) + private void radioButtons_CheckedChanged(object sender, EventArgs e) { - PathUtil.DisplayAllProgram(); + EnableAllButton(false); + RadioButton radioButton = sender as RadioButton; + if (rbtWechat.Checked) + { + modifier = (WechatModifier)rbtWechat.Tag; + } + else if (rbtQQ.Checked) + { + modifier = (QQModifier)rbtQQ.Tag; + } + else if (rbtTIM.Checked) + { + modifier = (TIMModifier)rbtTIM.Tag; + } + txtPath.Text = modifier.FindInstallPath(); + lblVersion.Text = modifier.GetVersion(); + EnableAllButton(true); + // 显示是否能够备份还原 + if (!string.IsNullOrEmpty(txtPath.Text)) + { + modifier.InitEditors(txtPath.Text); + btnRestore.Enabled = modifier.BackupExists(); + } + } + + private void EnableAllButton(bool state) + { + foreach (Control c in this.Controls) + { + if (c is Button) + { + c.Enabled = state; + } + } } } } diff --git a/RevokeMsgPatcher/JsonData.cs b/RevokeMsgPatcher/JsonData.cs new file mode 100644 index 0000000..f21817d --- /dev/null +++ b/RevokeMsgPatcher/JsonData.cs @@ -0,0 +1,192 @@ +using RevokeMsgPatcher.Model; +using System.Collections.Generic; +using System.Web.Script.Serialization; + +namespace RevokeMsgPatcher +{ + + public class JsonData + { + + public Bag Bag() + { + return new Bag + { + Apps = AppConfig(), + LatestVersion = "0.5", + Notice = "公告" + }; + } + + public string BagJson() + { + JavaScriptSerializer serializer = new JavaScriptSerializer(); + return serializer.Serialize(Bag()); + } + + public Dictionary AppConfig() + { + return new Dictionary + { + { "Wechat" , Wechat() }, + { "QQ" , QQ() }, + { "TIM" , TIM() } + }; + } + + public string AppConfigJson() + { + JavaScriptSerializer serializer = new JavaScriptSerializer(); + return serializer.Serialize(AppConfig()); + } + + public App Wechat() + { + return new App + { + Name = "Wechat", + FileTargetInfos = new Dictionary + { + { + "WeChatWin.dll", + new TargetInfo + { + Name = "WeChatWin.dll", + RelativePath = "WeChatWin.dll" + } + } + }, + FileModifyInfos = new Dictionary> + { + { + "WeChatWin.dll", + new List + { + new ModifyInfo { + Name="WeChatWin.dll", + Version="2.7.1.65", + SHA1Before="8346b97d264725da924d240c6eb77df3e693385e", + SHA1After="42bab2c9c79ef4f2088c00ea6d817973e14a5e6e", + Changes = new List + { + new Change + { + Position =2495545, + Content =new byte[] { 235} + } + } + }, + new ModifyInfo {Name="WeChatWin.dll",Version="2.7.1.59",SHA1Before="df954d403edaca89cd5394927a325a0023e93281",SHA1After="6aa22460c91bb5c5e2f0ec1af99b8a5f6d4318c0",Changes = new List { new Change {Position=2496073,Content=new byte[] { 235} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.7.1.43",SHA1Before="39cd9e09e1a3eac09e6808749bff525c9e3216ce",SHA1After="7b829f1ff0217e346a80f9510fdd7634ddd49445",Changes = new List { new Change {Position=2494169,Content=new byte[] { 235} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.7.0.70",SHA1Before="3b0601864aff3c1d792f812ad1ca05f02aa761e3",SHA1After="1e8734d32b0a8c12758e30f99c77f729991fb071",Changes = new List { new Change {Position=2475657,Content=new byte[] { 235} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.7.0.65",SHA1Before="063c2e05a0df1bdb8987c2d978d93499bd2052ba",SHA1After="5ed4c09a4f18643b967f063a824d7e65d0567f8a",Changes = new List { new Change {Position=2475449,Content=new byte[] { 117} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.8.68",SHA1Before="2e9417f4276b12fe32ca7b4fee49272a4a2af334",SHA1After="699602ee3cbb9ae5714f6e6ebc658c875a6c66e6",Changes = new List { new Change {Position=2454006,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.8.65",SHA1Before="e01f6855a96c12c30808960903ed199a33e4952c",SHA1After="d9120569cfd0433aebea107d7b90805cbbac7518",Changes = new List { new Change {Position=2454265,Content=new byte[] { 117} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.8.52",SHA1Before="88131302f664df6a657c9ca49d152da536fe5729",SHA1After="8d1454b73831644181e962c1fa0ea4e2da4124a3",Changes = new List { new Change {Position=2453049,Content=new byte[] { 117} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.8.51",SHA1Before="d0a5517b1292a751501b00b4b1f0702db2d9fc30",SHA1After="53e7b1525d49bf2c3250a8131ff0ba2510779b78",Changes = new List { new Change {Position=2452614,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.8.37",SHA1Before="7e01f8b04a158a4a50bc5a6e67c2fb8b02233170",SHA1After="a1895004415fe9bcd7e690bd6e482b833b515599",Changes = new List { new Change {Position=2452614,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.7.57",SHA1Before="80a91aaf941bcb1c24a7d672838ac73e9ebb2e40",SHA1After="a0d3f9a45a835f97aef7fe0872387d8cfb5c25a4",Changes = new List { new Change {Position=2433413,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.7.40",SHA1Before="04bd0cb28df6630b518f42a3f9c2caa4a9359fbc",SHA1After="13c91cf1d4609959771fd137b9a86a5ca365e1b6",Changes = new List { new Change {Position=2432934,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.7.32",SHA1Before="a02519c1007ee6723947c262c720d63c619f633e",SHA1After="f3007471ca8734c29783c25f0bb49949a783a44",Changes = new List { new Change {Position=2432806,Content=new byte[] { 116} } } },new ModifyInfo {Name="WeChatWin.dll",Version="2.6.6.28",SHA1Before="0b19cb17a62c3ea0efce0fb675a1d3b17845cba3",SHA1After="260948656725446b818ea668273ceff02ddfb44d",Changes = new List { new Change {Position=2401678,Content=new byte[] { 116} } } } + } + } + } + }; + } + + public App QQ() + { + return new App + { + Name = "QQ", + FileTargetInfos = new Dictionary + { + { + "IM.dll", + new TargetInfo + { + Name = "IM.dll", + RelativePath = @"Bin\IM.dll" + } + } + }, + FileModifyInfos = new Dictionary> + { + { + "IM.dll", + new List + { + new ModifyInfo + { + Name = "IM.dll", + Version = "9.1.7.25980", + SHA1Before = "c6632339fbe675312a70ae4620e70699c258cd36", + SHA1After = "e9ddc5cc681950796fc8fe4c55f580428c890b51", + Changes = new List + { + new Change + { + Position = 0x0005009F, + Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 } + }, + new Change + { + Position = 0x000502BC, + Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 } + }, + new Change + { + Position = 0x0005046C, + Content = new byte[] { 0xEB, 0x08, 0x90, 0x90, 0x90, 0x90 } + } + } + } + } + } + } + }; + } + + public App TIM() + { + return new App + { + Name = "TIM", + FileTargetInfos = new Dictionary + { + { + "IM.dll", + new TargetInfo + { + Name = "IM.dll", + RelativePath = @"Bin\IM.dll" + } + } + }, + FileModifyInfos = new Dictionary> + { + { + "IM.dll", + new List + { + new ModifyInfo + { + Name = "IM.dll", + Version = "2.3.2.21173", + SHA1Before = "c6632339fbe675312a70ae4620e70699c258cd36", + SHA1After = "e9ddc5cc681950796fc8fe4c55f580428c890b51", + Changes = new List + { + new Change + { + Position = 0x0005009F, + Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 } + }, + new Change + { + Position = 0x000502BC, + Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 } + }, + new Change + { + Position = 0x0005046C, + Content = new byte[] { 0xEB, 0x08, 0x90, 0x90, 0x90, 0x90 } + } + } + } + } + } + } + }; + } + } +} diff --git a/RevokeMsgPatcher/Model/Bag.cs b/RevokeMsgPatcher/Model/Bag.cs new file mode 100644 index 0000000..c84dd6a --- /dev/null +++ b/RevokeMsgPatcher/Model/Bag.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RevokeMsgPatcher.Model +{ + public class Bag + { + public Dictionary Apps { get; set; } + + public string LatestVersion { get; set; } + + public string Notice { get; set; } + } +} diff --git a/RevokeMsgPatcher/Modifier/AppModifier.cs b/RevokeMsgPatcher/Modifier/AppModifier.cs index 90bd629..c720960 100644 --- a/RevokeMsgPatcher/Modifier/AppModifier.cs +++ b/RevokeMsgPatcher/Modifier/AppModifier.cs @@ -19,10 +19,16 @@ namespace RevokeMsgPatcher.Modifier { protected App config; + public App Config { set { config = value; } } + protected List editors; public string InstallPath { get; set; } + /// + /// 自动搜索应用安装路径 + /// + /// 应用安装路径 public abstract string FindInstallPath(); //public abstract bool ValidateAndInitialize(string installPath); @@ -40,7 +46,7 @@ namespace RevokeMsgPatcher.Modifier /// public bool IsAllFilesExist(string installPath) { - if(string.IsNullOrEmpty(installPath)) + if (string.IsNullOrEmpty(installPath)) { return false; } @@ -107,27 +113,28 @@ namespace RevokeMsgPatcher.Modifier matchingVersion = modifyInfo; } } - // 补丁前SHA1匹配上,肯定是正确的dll - if (matchingSHA1Before != null) - { - editor.FileModifyInfo = modifyInfo.Clone(); - continue; - } - // 补丁后SHA1匹配上,肯定已经打过补丁 - if (matchingSHA1After != null) - { - throw new Exception($"你已经安装过此补丁,文件路径:{editor.FilePath}"); - } - // 全部不匹配,说明不支持 - if (matchingSHA1Before == null && matchingSHA1After == null && matchingVersion == null) - { - throw new Exception($"不支持此版本:{editor.FileVersion},文件路径:{editor.FilePath}"); - } - // SHA1不匹配,版本匹配,可能dll已经被其他补丁程序修改过 - if ((matchingSHA1Before == null && matchingSHA1After == null) && matchingVersion != null) - { - throw new Exception($"程序支持此版本:{editor.FileVersion}。但是文件校验不通过,请确认是否使用过其他补丁程序。文件路径:{editor.FilePath}"); - } + } + + // 补丁前SHA1匹配上,肯定是正确的dll + if (matchingSHA1Before != null) + { + editor.FileModifyInfo = matchingSHA1Before; + continue; + } + // 补丁后SHA1匹配上,肯定已经打过补丁 + if (matchingSHA1After != null) + { + throw new Exception($"你已经安装过此补丁,文件路径:{editor.FilePath}"); + } + // 全部不匹配,说明不支持 + if (matchingSHA1Before == null && matchingSHA1After == null && matchingVersion == null) + { + throw new Exception($"不支持此版本:{editor.FileVersion},文件路径:{editor.FilePath}"); + } + // SHA1不匹配,版本匹配,可能dll已经被其他补丁程序修改过 + if ((matchingSHA1Before == null && matchingSHA1After == null) && matchingVersion != null) + { + throw new Exception($"程序支持此版本:{editor.FileVersion}。但是文件校验不通过,请确认是否使用过其他补丁程序。文件路径:{editor.FilePath}"); } } } @@ -152,13 +159,27 @@ namespace RevokeMsgPatcher.Modifier editor.Backup(); } // 打补丁! - foreach (FileHexEditor editor in editors) + List done = new List(); // 已经打上补丁的 + try { - bool success = editor.Patch(); - if (!success) + foreach (FileHexEditor editor in editors) + { + bool success = editor.Patch(); + if (!success) + { + editor.Restore(); + } + done.Add(editor); + } + } + catch (Exception ex) + { + // 恢复所有已经打上补丁的文件 + foreach (FileHexEditor editor in done) { editor.Restore(); } + throw ex; } return true; } @@ -167,7 +188,7 @@ namespace RevokeMsgPatcher.Modifier { foreach (FileHexEditor editor in editors) { - if(!File.Exists(editor.FileBakPath)) + if (!File.Exists(editor.FileBakPath)) { return false; } diff --git a/RevokeMsgPatcher/Modifier/FileHexEditor.cs b/RevokeMsgPatcher/Modifier/FileHexEditor.cs index 82cc995..d4ecb16 100644 --- a/RevokeMsgPatcher/Modifier/FileHexEditor.cs +++ b/RevokeMsgPatcher/Modifier/FileHexEditor.cs @@ -62,6 +62,7 @@ namespace RevokeMsgPatcher.Modifier public bool Patch() { + FileUtil.EditMultiHex(FilePath, FileModifyInfo.Changes); return true; } diff --git a/RevokeMsgPatcher/Modifier/QQModifier.cs b/RevokeMsgPatcher/Modifier/QQModifier.cs index 5f41d86..fccf67c 100644 --- a/RevokeMsgPatcher/Modifier/QQModifier.cs +++ b/RevokeMsgPatcher/Modifier/QQModifier.cs @@ -1,12 +1,56 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Utils; namespace RevokeMsgPatcher.Modifier { - class QQModifier + class QQModifier : AppModifier { + public QQModifier(App config) + { + this.config = config; + } + + /// + /// 自动寻找获取微信安装路径 + /// + /// + public override string FindInstallPath() + { + string installPath = PathUtil.FindInstallPathFromRegistry("{052CFB79-9D62-42E3-8A15-DE66C2C97C3E} "); + if (!IsAllFilesExist(installPath)) + { + foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\QQ")) + { + if (IsAllFilesExist(defaultPath)) + { + return defaultPath; + } + } + } + else + { + return installPath; + } + return null; + } + + /// + /// 获取整个APP的当前版本 + /// + /// + public override string GetVersion() + { + if (editors != null && editors.Count > 0) + { + foreach (FileHexEditor editor in editors) + { + if (editor.FileName == "IM.dll") + { + return editor.FileVersion; + } + } + } + return ""; + } } } diff --git a/RevokeMsgPatcher/Modifier/TIMModifier.cs b/RevokeMsgPatcher/Modifier/TIMModifier.cs index 800318e..37938b8 100644 --- a/RevokeMsgPatcher/Modifier/TIMModifier.cs +++ b/RevokeMsgPatcher/Modifier/TIMModifier.cs @@ -1,12 +1,56 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Utils; namespace RevokeMsgPatcher.Modifier { - class TIMModifier + class TIMModifier : AppModifier { + + public TIMModifier(App config) + { + this.config = config; + } + /// + /// 自动寻找获取微信安装路径 + /// + /// + public override string FindInstallPath() + { + string installPath = PathUtil.FindInstallPathFromRegistry("TIM"); + if (!IsAllFilesExist(installPath)) + { + foreach (string defaultPath in PathUtil.GetDefaultInstallPaths(@"Tencent\TIM")) + { + if (IsAllFilesExist(defaultPath)) + { + return defaultPath; + } + } + } + else + { + return installPath; + } + return null; + } + + /// + /// 获取整个APP的当前版本 + /// + /// + public override string GetVersion() + { + if (editors != null && editors.Count > 0) + { + foreach (FileHexEditor editor in editors) + { + if (editor.FileName == "IM.dll") + { + return editor.FileVersion; + } + } + } + return ""; + } } } diff --git a/RevokeMsgPatcher/Modifier/WechatModifier.cs b/RevokeMsgPatcher/Modifier/WechatModifier.cs index eb9d278..ace78e8 100644 --- a/RevokeMsgPatcher/Modifier/WechatModifier.cs +++ b/RevokeMsgPatcher/Modifier/WechatModifier.cs @@ -1,14 +1,16 @@ -using RevokeMsgPatcher.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using RevokeMsgPatcher.Model; +using RevokeMsgPatcher.Utils; namespace RevokeMsgPatcher.Modifier { class WechatModifier : AppModifier { + + public WechatModifier(App config) + { + this.config = config; + } + /// /// 自动寻找获取微信安装路径 /// diff --git a/RevokeMsgPatcher/RevokeMsgPatcher.csproj b/RevokeMsgPatcher/RevokeMsgPatcher.csproj index 1129655..78cdd0e 100644 --- a/RevokeMsgPatcher/RevokeMsgPatcher.csproj +++ b/RevokeMsgPatcher/RevokeMsgPatcher.csproj @@ -56,6 +56,7 @@ FormMain.cs + @@ -71,9 +72,8 @@ - + - FormMain.cs diff --git a/RevokeMsgPatcher/Test.cs b/RevokeMsgPatcher/Test.cs deleted file mode 100644 index 7de9ff4..0000000 --- a/RevokeMsgPatcher/Test.cs +++ /dev/null @@ -1,13 +0,0 @@ -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/FileUtil.cs b/RevokeMsgPatcher/Utils/FileUtil.cs index e844c59..e7bb263 100644 --- a/RevokeMsgPatcher/Utils/FileUtil.cs +++ b/RevokeMsgPatcher/Utils/FileUtil.cs @@ -1,4 +1,6 @@ -using System.Diagnostics; +using RevokeMsgPatcher.Model; +using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Security.Cryptography; using System.Text; @@ -41,7 +43,7 @@ namespace RevokeMsgPatcher.Utils /// /// 修改文件指定位置的字节 /// - /// WeChatWin.dll 的路径 + /// 文件对象的路径 /// 偏移位置 /// 修改后的值 /// @@ -55,5 +57,22 @@ namespace RevokeMsgPatcher.Utils return true; } + + /// + /// 修改文件多个指定位置的多个字节 + /// + /// 文件对象的路径 + /// 需要修改的位置和内容 + public static void EditMultiHex(string path, List changes) + { + using (var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) + { + foreach (Change change in changes) + { + stream.Seek(change.Position, SeekOrigin.Begin); + stream.Write(change.Content, 0, change.Content.Length); + } + } + } } } diff --git a/RevokeMsgPatcher/Utils/HexEditUtil.cs b/RevokeMsgPatcher/Utils/HexEditUtil.cs deleted file mode 100644 index ab05ac8..0000000 --- a/RevokeMsgPatcher/Utils/HexEditUtil.cs +++ /dev/null @@ -1,12 +0,0 @@ -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 index 5c8f44f..61c547c 100644 --- a/RevokeMsgPatcher/Utils/PathUtil.cs +++ b/RevokeMsgPatcher/Utils/PathUtil.cs @@ -39,6 +39,10 @@ namespace RevokeMsgPatcher.Utils try { RegistryKey key = Registry.LocalMachine.OpenSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{uninstallKeyName}"); + if (key == null) + { + return null; + } object installLocation = key.GetValue("InstallLocation"); key.Close(); if (installLocation != null && !string.IsNullOrEmpty(installLocation.ToString())) @@ -66,7 +70,7 @@ namespace RevokeMsgPatcher.Utils foreach (string d in drives) { string path = Path.Combine(d, $@"Program Files (x86)\{relativePath}"); - if(Directory.Exists(path)) + if (Directory.Exists(path)) { list.Add(path); }