mirror of
https://github.com/huiyadanli/RevokeMsgPatcher.git
synced 2025-05-24 06:26:06 +08:00
[+] 加入一些计时日志
This commit is contained in:
parent
409b377ab5
commit
56787bf95a
|
@ -1,6 +1,7 @@
|
||||||
using RevokeMsgPatcher.Model;
|
using RevokeMsgPatcher.Model;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
@ -11,8 +12,11 @@ namespace RevokeMsgPatcher.Matcher
|
||||||
// TODO 该逻辑需要优化!
|
// TODO 该逻辑需要优化!
|
||||||
public static List<Change> FindChanges(string path, List<ReplacePattern> replacePatterns)
|
public static List<Change> FindChanges(string path, List<ReplacePattern> replacePatterns)
|
||||||
{
|
{
|
||||||
|
Stopwatch sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
// 读取整个文件(dll)
|
// 读取整个文件(dll)
|
||||||
byte[] fileByteArray = File.ReadAllBytes(path);
|
byte[] fileByteArray = File.ReadAllBytes(path);
|
||||||
|
Console.WriteLine("读取文件耗时:{0}ms.", sw.Elapsed.TotalMilliseconds);
|
||||||
|
|
||||||
List<Change> changes = new List<Change>(); // 匹配且需要替换的地方
|
List<Change> changes = new List<Change>(); // 匹配且需要替换的地方
|
||||||
|
|
||||||
|
@ -22,6 +26,7 @@ namespace RevokeMsgPatcher.Matcher
|
||||||
{
|
{
|
||||||
// 所有的匹配点位
|
// 所有的匹配点位
|
||||||
int[] matchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Search);
|
int[] matchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Search);
|
||||||
|
Console.WriteLine("匹配{0}耗时:{1}ms.", pattern.Category, sw.Elapsed.TotalMilliseconds);
|
||||||
if (matchIndexs.Length >= 1)
|
if (matchIndexs.Length >= 1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < matchIndexs.Length; i++)
|
for (int i = 0; i < matchIndexs.Length; i++)
|
||||||
|
@ -85,19 +90,23 @@ namespace RevokeMsgPatcher.Matcher
|
||||||
|
|
||||||
public static SortedSet<string> FindReplacedFunction(string path, List<ReplacePattern> replacePatterns)
|
public static SortedSet<string> FindReplacedFunction(string path, List<ReplacePattern> replacePatterns)
|
||||||
{
|
{
|
||||||
|
Stopwatch sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
byte[] fileByteArray = File.ReadAllBytes(path);
|
byte[] fileByteArray = File.ReadAllBytes(path);
|
||||||
|
Console.WriteLine("读取文件耗时:{0}ms.", sw.Elapsed.TotalMilliseconds);
|
||||||
Tuple<bool, SortedSet<string>> res = IsAllReplaced(fileByteArray, replacePatterns);
|
Tuple<bool, SortedSet<string>> res = IsAllReplaced(fileByteArray, replacePatterns);
|
||||||
|
Console.WriteLine("匹配耗时:{0}ms.", sw.Elapsed.TotalMilliseconds);
|
||||||
return res.Item2;
|
return res.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Tuple<bool, SortedSet<string>> IsAllReplaced(byte[] fileByteArray, List<ReplacePattern> replacePatterns)
|
private static Tuple<bool, SortedSet<string>> IsAllReplaced(byte[] partByteArray, List<ReplacePattern> replacePatterns)
|
||||||
{
|
{
|
||||||
int matchNum = 0;
|
int matchNum = 0;
|
||||||
SortedSet<string> alreadyReplaced = new SortedSet<string>(); // 已经被替换特征的功能
|
SortedSet<string> alreadyReplaced = new SortedSet<string>(); // 已经被替换特征的功能
|
||||||
foreach (ReplacePattern pattern in replacePatterns)
|
foreach (ReplacePattern pattern in replacePatterns)
|
||||||
{
|
{
|
||||||
int[] searchMatchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Search);
|
int[] searchMatchIndexs = FuzzyMatcher.MatchAll(partByteArray, pattern.Search);
|
||||||
int[] replaceMatchIndexs = FuzzyMatcher.MatchAll(fileByteArray, pattern.Replace);
|
int[] replaceMatchIndexs = FuzzyMatcher.MatchAll(partByteArray, pattern.Replace);
|
||||||
// 查找串没有,但是替换串存在,也就是说明这个功能已经完全完成替换
|
// 查找串没有,但是替换串存在,也就是说明这个功能已经完全完成替换
|
||||||
if (searchMatchIndexs.Length == 0 && replaceMatchIndexs.Length > 0)
|
if (searchMatchIndexs.Length == 0 && replaceMatchIndexs.Length > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user