This repository was archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObfuscationEngine.cs
64 lines (54 loc) · 2.27 KB
/
ObfuscationEngine.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
55
56
57
58
59
60
61
62
63
64
using dnlib.DotNet;
using dnlib.DotNet.Writer;
using ExmapleObfuscator.Interfaces;
using ExmapleObfuscator.Protections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExmapleObfuscator
{
public class ObfuscationEngine : IObfuscationEngine
{
bool isStringsEnabled;
List<IProtection> protections = new List<IProtection>();
ModuleDefMD mod;
/// <summary>
/// Настройка защит перед началом работы
/// </summary>
public void CreateConfig()
{
isStringsEnabled = GetAnswer("Шифруем строки?");
if (isStringsEnabled)
protections.Add(new StringsEncryption());
}
/// <summary>
/// Выполнение всех защит в порядке их добавления
/// </summary>
/// <param name="path">Путь до исполняемого файла или DLL</param>
public void Run(string path)
{
mod = ModuleDefMD.Load(path);
foreach (IProtection protection in protections)
protection.Run(mod);
mod.Name = "owefoweufniweuf";
mod.Assembly.Name = "oebnorbwornbown";
var options = new ModuleWriterOptions(mod);
options.MetadataOptions.Flags = MetadataFlags.PreserveRids;
options.Logger = DummyLogger.NoThrowInstance;
mod.Write("test." + path.Substring(path.Length - 3, 3), options);
}
private static bool GetAnswer(string text)
{
Console.WriteLine(text);
Console.Write("Нажмите пробел, чтобы подтвердить, или любую клавишу для отмены: ");
var res = ' ' == Console.ReadKey().KeyChar;
Console.WriteLine();
return res;
}
private static void ResetColor() => Console.ForegroundColor = ConsoleColor.White;
private static void SetWarningColor() => Console.ForegroundColor = ConsoleColor.DarkYellow;
private static void SetInfoColor() => Console.ForegroundColor = ConsoleColor.Cyan;
}
}