Skip to content

Commit 445b933

Browse files
committed
Fixing watermarking, disable hardening by default
1 parent a920205 commit 445b933

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

Confuser.Core/ConfuserEngine.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,16 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token)
8888
try {
8989
// Enable watermarking by default
9090
context.Project.Rules.Insert(0, new Rule {
91-
new SettingItem<Protection>(WatermarkingProtection._Id),
92-
new SettingItem<Protection>("harden")
91+
new SettingItem<Protection>(WatermarkingProtection._Id)
9392
});
9493

9594
var asmResolver = new AssemblyResolver();
9695
asmResolver.EnableTypeDefCache = true;
9796
asmResolver.DefaultModuleContext = new ModuleContext(asmResolver);
9897
context.Resolver = asmResolver;
99-
context.BaseDirectory = Path.Combine(Environment.CurrentDirectory, parameters.Project.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
100-
context.OutputDirectory = Path.Combine(parameters.Project.BaseDirectory, parameters.Project.OutputDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
101-
foreach (string probePath in parameters.Project.ProbePaths)
98+
context.BaseDirectory = Path.Combine(Environment.CurrentDirectory, context.Project.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
99+
context.OutputDirectory = Path.Combine(context.Project.BaseDirectory, context.Project.OutputDirectory.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
100+
foreach (string probePath in context.Project.ProbePaths)
102101
asmResolver.PostSearchPaths.Insert(0, Path.Combine(context.BaseDirectory, probePath));
103102

104103
context.CheckCancellation();
@@ -128,7 +127,7 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token)
128127
throw new ConfuserException(ex);
129128
}
130129

131-
components.Insert(0, new CoreComponent(parameters, marker));
130+
components.Insert(0, new CoreComponent(context, marker));
132131
foreach (Protection prot in prots)
133132
components.Add(prot);
134133
foreach (Packer packer in packers)
@@ -139,7 +138,7 @@ static void RunInternal(ConfuserParameters parameters, CancellationToken token)
139138
// 4. Load modules
140139
context.Logger.Info("Loading input modules...");
141140
marker.Initalize(prots, packers);
142-
MarkerResult markings = marker.MarkProject(parameters.Project, context);
141+
MarkerResult markings = marker.MarkProject(context.Project, context);
143142
context.Modules = new ModuleSorter(markings.Modules).Sort().ToList().AsReadOnly();
144143
foreach (var module in context.Modules)
145144
module.EnableTypeDefFindCache = false;

Confuser.Core/CoreComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class CoreComponent : ConfuserComponent {
3838
public const string _APIStoreId = "Confuser.APIStore";
3939

4040
readonly Marker marker;
41-
readonly ConfuserParameters parameters;
41+
readonly ConfuserContext _context;
4242

4343
/// <summary>
4444
/// Initializes a new instance of the <see cref="CoreComponent" /> class.
4545
/// </summary>
4646
/// <param name="parameters">The parameters.</param>
4747
/// <param name="marker">The marker.</param>
48-
internal CoreComponent(ConfuserParameters parameters, Marker marker) {
49-
this.parameters = parameters;
48+
internal CoreComponent(ConfuserContext context, Marker marker) {
49+
_context = context;
5050
this.marker = marker;
5151
}
5252

@@ -72,7 +72,7 @@ public override string FullId {
7272

7373
/// <inheritdoc />
7474
protected internal override void Initialize(ConfuserContext context) {
75-
context.Registry.RegisterService(_RandomServiceId, typeof(IRandomService), new RandomService(parameters.Project.Seed));
75+
context.Registry.RegisterService(_RandomServiceId, typeof(IRandomService), new RandomService(_context.Project.Seed));
7676
context.Registry.RegisterService(_MarkerServiceId, typeof(IMarkerService), new MarkerService(context, marker));
7777
context.Registry.RegisterService(_TraceServiceId, typeof(ITraceService), new TraceService());
7878
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService());

Confuser.Core/WatermarkingProtection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected internal override void Initialize(ConfuserContext context) { }
2626

2727
/// <inheritdoc />
2828
protected internal override void PopulatePipeline(ProtectionPipeline pipeline) =>
29-
pipeline.InsertPreStage(PipelineStage.BeginModule, new WatermarkingPhase(this));
29+
pipeline.InsertPostStage(PipelineStage.EndModule, new WatermarkingPhase(this));
3030

3131
/// <inheritdoc />
3232
public override ProtectionPreset Preset => ProtectionPreset.None;
@@ -52,7 +52,7 @@ protected internal override void Execute(ConfuserContext context, ProtectionPara
5252
if (attrType == null) {
5353
attrType = new TypeDefUser("", "ConfusedByAttribute", attrRef);
5454
module.Types.Add(attrType);
55-
marker.Mark(attrType, null);
55+
marker.Mark(attrType, Parent);
5656
}
5757

5858
var ctor = attrType.FindInstanceConstructors()
@@ -70,7 +70,7 @@ protected internal override void Execute(ConfuserContext context, ProtectionPara
7070
MethodSig.CreateInstance(module.CorLibTypes.Void), attrRef)));
7171
ctor.Body.Instructions.Add(OpCodes.Ret.ToInstruction());
7272
attrType.Methods.Add(ctor);
73-
marker.Mark(ctor, null);
73+
marker.Mark(ctor, Parent);
7474
}
7575

7676
var attr = new CustomAttribute(ctor);

Confuser.Protections/HardeningProtection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ protected override void PopulatePipeline(ProtectionPipeline pipeline) =>
2424
pipeline.InsertPreStage(PipelineStage.OptimizeMethods, new HardeningPhase(this));
2525

2626
/// <inheritdoc />
27-
public override ProtectionPreset Preset => ProtectionPreset.None;
27+
public override ProtectionPreset Preset => ProtectionPreset.Minimum;
2828
}
2929
}

Confuser.Renamer/AnalyzePhase.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
171171
else if (type.IsRuntimeSpecialName || type.IsGlobalModuleType) {
172172
service.SetCanRename(type, false);
173173
}
174-
else if (type.FullName == "ConfusedByAttribute") {
175-
// Courtesy
176-
service.SetCanRename(type, false);
177-
}
178174

179175
if (parameters.GetParameter(context, type, "forceRen", false))
180176
return;

0 commit comments

Comments
 (0)