-
Notifications
You must be signed in to change notification settings - Fork 44
/
ConfuserExKillerTool.cs
54 lines (49 loc) · 2.24 KB
/
ConfuserExKillerTool.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.IO;
using System.Linq;
using System.Reflection;
using ConfuserExTools.AntiTamperKiller;
using ConfuserExTools.ConstantKiller;
using ConfuserExTools.ProxyKiller;
using dnlib.DotNet;
using dnlib.DotNet.Writer;
using Tool;
using Tool.Interface;
namespace ConfuserExTools.ConfuserExKiller {
public sealed class ConfuserExKillerTool : ITool<ConfuserExKillerSettings> {
public string Title => GetTitle();
public void Execute(ConfuserExKillerSettings settings) {
Logger.Initialize(false);
var reflModule = Assembly.LoadFile(settings.AssemblyPath).ManifestModule;
byte[] peImageOld = File.ReadAllBytes(settings.AssemblyPath);
byte[] peImage = AntiTamperKillerImpl.Execute(reflModule, peImageOld);
if (!peImage.SequenceEqual(peImageOld))
Logger.LogInfo($"AntiTamper已移除");
using (var module = ModuleDefMD.Load(peImage)) {
int count = ProxyKillerImpl.Execute(module, false, true);
Logger.LogInfo($"共 {count} 个代理方法被还原");
count = ConstantKillerImpl.Execute(module, reflModule);
Logger.LogInfo($"共 {count} 个常量被解密");
string newFilePath = PathInsertSuffix(settings.AssemblyPath, ".cexk");
Logger.LogInfo($"正在保存: {newFilePath}");
Logger.LogInfo();
module.Write(newFilePath, new ModuleWriterOptions(module) { Logger = DnlibLogger.Instance });
}
Logger.Flush();
}
private static string PathInsertSuffix(string path, string suffix) {
return Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + suffix + Path.GetExtension(path));
}
private static string GetTitle() {
string productName = GetAssemblyAttribute<AssemblyProductAttribute>().Product;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string copyright = GetAssemblyAttribute<AssemblyCopyrightAttribute>().Copyright.Substring(12);
int firstBlankIndex = copyright.IndexOf(' ');
string copyrightOwnerName = copyright.Substring(firstBlankIndex + 1);
string copyrightYear = copyright.Substring(0, firstBlankIndex);
return $"{productName} v{version} by {copyrightOwnerName} {copyrightYear}";
}
private static T GetAssemblyAttribute<T>() {
return (T)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(T), false)[0];
}
}
}