[-] 删除无用的旧代码

This commit is contained in:
huiyadanli 2019-10-06 11:19:26 +08:00
parent edc06cf769
commit 93f9f5b87b
7 changed files with 6 additions and 248 deletions

View File

@ -188,6 +188,7 @@ namespace RevokeMsgPatcher
{
EnableAllButton(false);
RadioButton radioButton = sender as RadioButton;
// 切换使用不同的防撤回对象
if (rbtWechat.Checked)
{
modifier = (WechatModifier)rbtWechat.Tag;

View File

@ -162,23 +162,23 @@ namespace RevokeMsgPatcher
{
Name = "IM.dll",
Version = "2.3.2.21173",
SHA1Before = "c6632339fbe675312a70ae4620e70699c258cd36",
SHA1After = "e9ddc5cc681950796fc8fe4c55f580428c890b51",
SHA1Before = "ecf3e69f3fb100ffe2fee095ffded591b9781024",
SHA1After = "0514d1304e7ac46b4d33386ec3313888f5ae7171",
Changes = new List<Change>
{
new Change
{
Position = 0x0005009F,
Position = 0x0004D78A,
Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 }
},
new Change
{
Position = 0x000502BC,
Position = 0x0004D9A7,
Content = new byte[] { 0xEB, 0x90, 0x90, 0x90, 0x90 }
},
new Change
{
Position = 0x0005046C,
Position = 0x0004DB57,
Content = new byte[] { 0xEB, 0x08, 0x90, 0x90, 0x90, 0x90 }
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RevokeMsgPatcher.Model
{
public class TargetFile
{
public string FileName { get; set; }
public string Version { get; set; }
public string SHA1Before { get; set; }
public string SHA1After { get; set; }
public long Position { get; set; }
public byte Content { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RevokeMsgPatcher.Model
{
public class Version
{
public string AppVersion { get; set; }
public List<ModifyInfo> Files { get; set; }
}
}

View File

@ -1,92 +0,0 @@
using RevokeMsgPatcher.Model;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Web.Script.Serialization;
using File = System.IO.File;
namespace RevokeMsgPatcher
{
public class Patcher
{
private string intallPath;
public string IntallPath
{
get { return intallPath; }
set
{
intallPath = value;
if (!string.IsNullOrEmpty(intallPath) && Util.IsWechatInstallPath(intallPath))
{
dllPath = Path.Combine(intallPath, "WeChatWin.dll");
bakPath = Path.Combine(intallPath, "WeChatWin.dll.h.bak");
}
else
{
intallPath = null;
dllPath = null;
bakPath = null;
}
}
}
private string dllPath;
private string bakPath;
public string DllPath { get => dllPath; }
public string BakPath { get => bakPath; }
private List<TargetFile> targetFiles;
private TargetFile currentFile;
public List<TargetFile> TargetFiles { get => targetFiles; }
public Patcher()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
targetFiles = serializer.Deserialize<List<TargetFile>>(Properties.Resources.PatchJson);
}
public void SetNewPatchJson(string json)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
targetFiles = serializer.Deserialize<List<TargetFile>>(json);
}
public string JudgeVersion()
{
string sha1 = Util.ComputeFileSHA1(dllPath);
Debug.WriteLine(sha1);
foreach (TargetFile t in targetFiles)
{
if (sha1 == t.SHA1After)
{
return "done";
}
if (sha1 == t.SHA1Before)
{
currentFile = t;
return t.Version;
}
}
return null;
}
public bool Patch()
{
if (currentFile != null)
{
File.Copy(dllPath, bakPath, true);
bool done = Util.EditHex(dllPath, currentFile.Position, currentFile.Content);
if (!done)
{
File.Copy(bakPath, dllPath, true);
}
return done;
}
return false;
}
}
}

View File

@ -59,21 +59,17 @@
<Compile Include="Model\Bag.cs" />
<Compile Include="Model\Change.cs" />
<Compile Include="Model\ModifyInfo.cs" />
<Compile Include="Model\TargetFile.cs" />
<Compile Include="Model\TargetInfo.cs" />
<Compile Include="Model\Version.cs" />
<Compile Include="Modifier\AppModifier.cs" />
<Compile Include="Modifier\FileHexEditor.cs" />
<Compile Include="Modifier\QQModifier.cs" />
<Compile Include="Modifier\TIMModifier.cs" />
<Compile Include="Modifier\WechatModifier.cs" />
<Compile Include="Patcher.cs" />
<Compile Include="Utils\FileUtil.cs" />
<Compile Include="Utils\PathUtil.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="JsonData.cs" />
<Compile Include="Util.cs" />
<EmbeddedResource Include="FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource>

View File

@ -1,109 +0,0 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace RevokeMsgPatcher
{
public class Util
{
/// <summary>
/// 自动查找安装路径
/// </summary>
/// <returns>安装路径</returns>
public static string AutoFindInstallPath()
{
// 微信的注册表路径
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\WeChat");
object installLocation = key.GetValue("InstallLocation");
key.Close();
if (installLocation == null || string.IsNullOrEmpty(installLocation.ToString()) || !IsWechatInstallPath(installLocation.ToString()))
{
// 从默认安装目录查找
string[] drives = Environment.GetLogicalDrives(); //获取当前计算机逻辑磁盘名称列表
foreach (string d in drives)
{
string assertPath = Path.Combine(d, @"Program Files (x86)\Tencent\WeChat");
if (IsWechatInstallPath(assertPath))
{
return assertPath;
}
}
}
else
{
return installLocation.ToString();
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
return null;
}
/// <summary>
/// 通过文件是否存在判断是否是安装目录
/// </summary>
/// <param name="path">安装目录</param>
/// <returns></returns>
public static bool IsWechatInstallPath(string path)
{
return File.Exists(Path.Combine(path, "WeChatWin.dll")) && File.Exists(Path.Combine(path, "WeChat.exe"));
}
/// <summary>
/// 获取文件版本
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string GetFileVersion(string path)
{
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(path);
return fileVersionInfo.FileVersion;
}
/// <summary>
/// 计算文件SHA1
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string ComputeFileSHA1(string s)
{
FileStream file = new FileStream(s, FileMode.Open);
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] retval = sha1.ComputeHash(file);
file.Close();
StringBuilder sc = new StringBuilder();
for (int i = 0; i < retval.Length; i++)
{
sc.Append(retval[i].ToString("x2"));
}
return sc.ToString();
}
/// <summary>
/// 修改文件指定位置的字节
/// </summary>
/// <param name="path">WeChatWin.dll 的路径</param>
/// <param name="position">偏移位置</param>
/// <param name="after">修改后的值</param>
/// <returns></returns>
public static bool EditHex(string path, long position, byte after)
{
using (var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite))
{
stream.Position = position;
stream.WriteByte(after);
}
return true;
}
}
}