forked from yck1509/ConfuserEx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAntiDumpProtection.cs
76 lines (60 loc) · 2.19 KB
/
AntiDumpProtection.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
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using Confuser.Core;
using Confuser.Core.Helpers;
using Confuser.Core.Services;
using Confuser.Renamer;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace Confuser.Protections {
[BeforeProtection("Ki.ControlFlow")]
internal class AntiDumpProtection : Protection {
public const string _Id = "anti dump";
public const string _FullId = "Ki.AntiDump";
public override string Name {
get { return "Anti Dump Protection"; }
}
public override string Description {
get { return "This protection prevents the assembly from being dumped from memory."; }
}
public override string Id {
get { return _Id; }
}
public override string FullId {
get { return _FullId; }
}
public override ProtectionPreset Preset {
get { return ProtectionPreset.Maximum; }
}
protected override void Initialize(ConfuserContext context) {
//
}
protected override void PopulatePipeline(ProtectionPipeline pipeline) {
pipeline.InsertPreStage(PipelineStage.ProcessModule, new AntiDumpPhase(this));
}
class AntiDumpPhase : ProtectionPhase {
public AntiDumpPhase(AntiDumpProtection parent)
: base(parent) { }
public override ProtectionTargets Targets {
get { return ProtectionTargets.Modules; }
}
public override string Name {
get { return "Anti-dump injection"; }
}
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) {
TypeDef rtType = context.Registry.GetService<IRuntimeService>().GetRuntimeType("Confuser.Runtime.AntiDump");
var marker = context.Registry.GetService<IMarkerService>();
var name = context.Registry.GetService<INameService>();
foreach (ModuleDef module in parameters.Targets.OfType<ModuleDef>()) {
IEnumerable<IDnlibDef> members = InjectHelper.Inject(rtType, module.GlobalType, module);
MethodDef cctor = module.GlobalType.FindStaticConstructor();
var init = (MethodDef)members.Single(method => method.Name == "Initialize");
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, init));
foreach (IDnlibDef member in members)
name.MarkHelper(member, marker, (Protection)Parent);
}
}
}
}
}