forked from mkaring/ConfuserEx
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConfuserContext.cs
More file actions
205 lines (178 loc) · 7.06 KB
/
Copy pathConfuserContext.cs
File metadata and controls
205 lines (178 loc) · 7.06 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.Collections.Generic;
using System.Threading;
using Confuser.Core.Project;
using dnlib.DotNet;
using dnlib.DotNet.Writer;
using Microsoft.Extensions.Logging;
namespace Confuser.Core {
/// <summary>
/// Context providing information on the current protection process.
/// </summary>
public class ConfuserContext {
readonly Annotations annotations = new Annotations();
readonly ServiceRegistry registry = new ServiceRegistry();
internal CancellationToken token;
/// <summary>
/// Gets the logger used for logging events.
/// </summary>
/// <value>The logger.</value>
public Microsoft.Extensions.Logging.ILogger Logger { get; internal set; }
/// <summary>
/// Gets the progress reporter used for reporting protection progress.
/// </summary>
/// <value>The progress reporter.</value>
public IProgressReporter ProgressReporter { get; internal set; }
/// <summary>
/// Gets the project being processed.
/// </summary>
/// <value>The project.</value>
public ConfuserProject Project { get; internal set; }
internal bool PackerInitiated { get; set; }
/// <summary>
/// Gets the annotation storage.
/// </summary>
/// <value>The annotation storage.</value>
public Annotations Annotations {
get { return annotations; }
}
/// <summary>
/// Gets the service registry.
/// </summary>
/// <value>The service registry.</value>
public ServiceRegistry Registry {
get { return registry; }
}
/// <summary>
/// Gets the assembly resolver.
/// </summary>
/// <value>The assembly resolver.</value>
public IAssemblyResolver Resolver => InternalResolver;
/// <summary>
/// Gets the assembly resolver.
/// </summary>
/// <value>The assembly resolver.</value>
internal ConfuserAssemblyResolver InternalResolver { get; set; }
/// <summary>
/// Gets the modules being protected.
/// </summary>
/// <value>The modules being protected.</value>
public IList<ModuleDefMD> Modules { get; internal set; }
/// <summary>
/// Gets the external modules.
/// </summary>
/// <value>The external modules.</value>
public IList<byte[]> ExternalModules { get; internal set; }
/// <summary>
/// Gets the base directory.
/// </summary>
/// <value>The base directory.</value>
public string BaseDirectory { get; internal set; }
/// <summary>
/// Gets the output directory.
/// </summary>
/// <value>The output directory.</value>
public string OutputDirectory { get; internal set; }
/// <summary>
/// Gets the packer.
/// </summary>
/// <value>The packer.</value>
public Packer Packer { get; internal set; }
/// <summary>
/// Gets the current processing pipeline.
/// </summary>
/// <value>The processing pipeline.</value>
public ProtectionPipeline Pipeline { get; internal set; }
/// <summary>
/// Gets the <c>byte[]</c> of modules after protected, or null if module is not protected yet.
/// </summary>
/// <value>The list of <c>byte[]</c> of protected modules.</value>
public IList<byte[]> OutputModules { get; internal set; }
/// <summary>
/// Gets the <c>byte[]</c> of module debug symbols after protected, or null if module is not protected yet.
/// </summary>
/// <value>The list of <c>byte[]</c> of module debug symbols.</value>
public IList<byte[]> OutputSymbols { get; internal set; }
/// <summary>
/// Gets the relative output paths of module, or null if module is not protected yet.
/// </summary>
/// <value>The relative output paths of protected modules.</value>
public IList<string> OutputPaths { get; internal set; }
/// <summary>
/// Gets the current module index.
/// </summary>
/// <value>The current module index.</value>
public int CurrentModuleIndex { get; internal set; }
/// <summary>
/// Gets the current module.
/// </summary>
/// <value>The current module.</value>
public ModuleDefMD CurrentModule {
get { return CurrentModuleIndex == -1 ? null : Modules[CurrentModuleIndex]; }
}
/// <summary>
/// Gets the writer options of the current module.
/// </summary>
/// <value>The writer options.</value>
public ModuleWriterOptionsBase CurrentModuleWriterOptions { get; internal set; }
/// <summary>
/// Gets output <c>byte[]</c> of the current module
/// </summary>
/// <value>The output <c>byte[]</c>.</value>
public byte[] CurrentModuleOutput { get; internal set; }
/// <summary>
/// Gets output <c>byte[]</c> debug symbol of the current module
/// </summary>
/// <value>The output <c>byte[]</c> debug symbol.</value>
public byte[] CurrentModuleSymbol { get; internal set; }
/// <summary>
/// Gets the token used to indicate cancellation
/// </summary>
public CancellationToken CancellationToken { get { return token; } }
/// <summary>
/// Throws a System.OperationCanceledException if protection process has been canceled.
/// </summary>
/// <exception cref="OperationCanceledException">
/// The protection process is canceled.
/// </exception>
public void CheckCancellation() {
token.ThrowIfCancellationRequested();
}
/// <summary>
/// Requests the current module to be written as mix-mode module, and return the native writer options.
/// </summary>
/// <returns>The native writer options.</returns>
public NativeModuleWriterOptions RequestNative(bool optimizeImageSize) {
if (CurrentModule == null)
return null;
if (CurrentModuleWriterOptions == null)
CurrentModuleWriterOptions = new NativeModuleWriterOptions(CurrentModule, optimizeImageSize);
// Clone the current options to the new options
var newOptions = new NativeModuleWriterOptions(CurrentModule, optimizeImageSize) {
AddCheckSum = CurrentModuleWriterOptions.AddCheckSum,
AddMvidSection = CurrentModuleWriterOptions.AddMvidSection,
Cor20HeaderOptions = CurrentModuleWriterOptions.Cor20HeaderOptions,
GetPdbContentId = CurrentModuleWriterOptions.GetPdbContentId,
Logger = CurrentModuleWriterOptions.Logger,
MetadataLogger = CurrentModuleWriterOptions.MetadataLogger,
MetadataOptions = CurrentModuleWriterOptions.MetadataOptions,
ModuleKind = CurrentModuleWriterOptions.ModuleKind,
NoWin32Resources = CurrentModuleWriterOptions.NoWin32Resources,
PdbChecksumAlgorithm = CurrentModuleWriterOptions.PdbChecksumAlgorithm,
PdbFileName = CurrentModuleWriterOptions.PdbFileName,
PdbFileNameInDebugDirectory = CurrentModuleWriterOptions.PdbFileNameInDebugDirectory,
PdbOptions = CurrentModuleWriterOptions.PdbOptions,
PdbStream = CurrentModuleWriterOptions.PdbStream,
PEHeadersOptions = CurrentModuleWriterOptions.PEHeadersOptions,
ShareMethodBodies = CurrentModuleWriterOptions.ShareMethodBodies,
DelaySign = CurrentModuleWriterOptions.DelaySign,
StrongNameKey = CurrentModuleWriterOptions.StrongNameKey,
StrongNamePublicKey = CurrentModuleWriterOptions.StrongNamePublicKey,
Win32Resources = CurrentModuleWriterOptions.Win32Resources,
WritePdb = CurrentModuleWriterOptions.WritePdb,
};
CurrentModuleWriterOptions = newOptions;
return newOptions;
}
}
}