From 56787bf95aeba8f22785f43304a8e8c94b2a6b16 Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Sat, 30 Apr 2022 17:04:44 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E5=8A=A0=E5=85=A5=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RevokeMsgPatcher/Matcher/ModifyFinder.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/RevokeMsgPatcher/Matcher/ModifyFinder.cs b/RevokeMsgPatcher/Matcher/ModifyFinder.cs index 38eea5b..3090451 100644 --- a/RevokeMsgPatcher/Matcher/ModifyFinder.cs +++ b/RevokeMsgPatcher/Matcher/ModifyFinder.cs @@ -1,6 +1,7 @@ using RevokeMsgPatcher.Model; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; @@ -11,8 +12,11 @@ namespace RevokeMsgPatcher.Matcher // TODO 该逻辑需要优化! public static List FindChanges(string path, List replacePatterns) { + Stopwatch sw = new Stopwatch(); + sw.Start(); // 读取整个文件(dll) byte[] fileByteArray = File.ReadAllBytes(path); + Console.WriteLine("读取文件耗时:{0}ms.", sw.Elapsed.TotalMilliseconds); List changes = new List(); // 匹配且需要替换的地方 @@ -22,6 +26,7 @@ namespace RevokeMsgPatcher.Matcher { // 所有的匹配点位 int[] matchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Search); + Console.WriteLine("匹配{0}耗时:{1}ms.", pattern.Category, sw.Elapsed.TotalMilliseconds); if (matchIndexs.Length >= 1) { for (int i = 0; i < matchIndexs.Length; i++) @@ -85,19 +90,23 @@ namespace RevokeMsgPatcher.Matcher public static SortedSet FindReplacedFunction(string path, List replacePatterns) { + Stopwatch sw = new Stopwatch(); + sw.Start(); byte[] fileByteArray = File.ReadAllBytes(path); + Console.WriteLine("读取文件耗时:{0}ms.", sw.Elapsed.TotalMilliseconds); Tuple> res = IsAllReplaced(fileByteArray, replacePatterns); + Console.WriteLine("匹配耗时:{0}ms.", sw.Elapsed.TotalMilliseconds); return res.Item2; } - private static Tuple> IsAllReplaced(byte[] fileByteArray, List replacePatterns) + private static Tuple> IsAllReplaced(byte[] partByteArray, List replacePatterns) { int matchNum = 0; SortedSet alreadyReplaced = new SortedSet(); // 已经被替换特征的功能 foreach (ReplacePattern pattern in replacePatterns) { - int[] searchMatchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Search); - int[] replaceMatchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Replace); + int[] searchMatchIndexs = FuzzyMatcher.MatchAll(partByteArray, pattern.Search); + int[] replaceMatchIndexs = FuzzyMatcher.MatchAll(partByteArray, pattern.Replace); // 查找串没有,但是替换串存在,也就是说明这个功能已经完全完成替换 if (searchMatchIndexs.Length == 0 && replaceMatchIndexs.Length > 0) {