From 5459687e215a85aac7855cf39d148e76fde79ca0 Mon Sep 17 00:00:00 2001 From: yck1509 Date: Sun, 22 Jun 2014 22:31:55 +0800 Subject: [PATCH] Add Name property to ProtectionPhase --- Confuser.Core/ProtectionPhase.cs | 6 ++++++ Confuser.Core/ProtectionPipeline.cs | 2 ++ Confuser.Protections/AntiDebugProtection.cs | 4 ++++ Confuser.Protections/AntiDumpProtection.cs | 4 ++++ Confuser.Protections/AntiILDasmProtection.cs | 4 ++++ Confuser.Protections/AntiTamper/AntiTamperProtection.cs | 8 ++++++++ Confuser.Protections/Compress/ExtractPhase.cs | 4 ++++ Confuser.Protections/Compress/StubProtection.cs | 4 ++++ Confuser.Protections/Constants/EncodePhase.cs | 4 ++++ Confuser.Protections/Constants/InjectPhase.cs | 4 ++++ Confuser.Protections/ControlFlow/ControlFlowPhase.cs | 4 ++++ Confuser.Protections/InvalidMetadataProtection.cs | 4 ++++ .../ReferenceProxy/ReferenceProxyPhase.cs | 4 ++++ Confuser.Protections/Resources/InjectPhase.cs | 4 ++++ Confuser.Renamer/AnalyzePhase.cs | 4 ++++ Confuser.Renamer/PostRenamePhase.cs | 4 ++++ Confuser.Renamer/RenamePhase.cs | 4 ++++ ConfuserEx/Skin.cs | 8 ++++++-- 18 files changed, 78 insertions(+), 2 deletions(-) diff --git a/Confuser.Core/ProtectionPhase.cs b/Confuser.Core/ProtectionPhase.cs index 9c89e3c..d358481 100644 --- a/Confuser.Core/ProtectionPhase.cs +++ b/Confuser.Core/ProtectionPhase.cs @@ -23,6 +23,12 @@ /// The protection targets. public abstract ProtectionTargets Targets { get; } + /// + /// Gets the name of the phase. + /// + /// The name of phase. + public abstract string Name { get; } + /// /// Gets a value indicating whether this phase process all targets, not just the targets that requires the component. /// diff --git a/Confuser.Core/ProtectionPipeline.cs b/Confuser.Core/ProtectionPipeline.cs index f77ba2e..125e4d0 100644 --- a/Confuser.Core/ProtectionPipeline.cs +++ b/Confuser.Core/ProtectionPipeline.cs @@ -120,12 +120,14 @@ namespace Confuser.Core { /// The working context. internal void ExecuteStage(PipelineStage stage, Action func, Func> targets, ConfuserContext context) { foreach (ProtectionPhase pre in preStage[stage]) { + context.Logger.DebugFormat("Executing '{0}' phase...", pre.Name); pre.Execute(context, new ProtectionParameters(pre.Parent, Filter(context, targets(), pre))); context.CheckCancellation(); } func(context); context.CheckCancellation(); foreach (ProtectionPhase post in postStage[stage]) { + context.Logger.DebugFormat("Executing '{0}' phase...", post.Name); post.Execute(context, new ProtectionParameters(post.Parent, Filter(context, targets(), post))); context.CheckCancellation(); } diff --git a/Confuser.Protections/AntiDebugProtection.cs b/Confuser.Protections/AntiDebugProtection.cs index a3b1c50..5becf45 100644 --- a/Confuser.Protections/AntiDebugProtection.cs +++ b/Confuser.Protections/AntiDebugProtection.cs @@ -49,6 +49,10 @@ namespace Confuser.Protections { get { return ProtectionTargets.Modules; } } + public override string Name { + get { return "Anti-debug injection"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var rt = context.Registry.GetService(); var marker = context.Registry.GetService(); diff --git a/Confuser.Protections/AntiDumpProtection.cs b/Confuser.Protections/AntiDumpProtection.cs index 9c828b0..eaf3710 100644 --- a/Confuser.Protections/AntiDumpProtection.cs +++ b/Confuser.Protections/AntiDumpProtection.cs @@ -49,6 +49,10 @@ namespace Confuser.Protections { 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().GetRuntimeType("Confuser.Runtime.AntiDump"); diff --git a/Confuser.Protections/AntiILDasmProtection.cs b/Confuser.Protections/AntiILDasmProtection.cs index 2a9b33f..dd270c4 100644 --- a/Confuser.Protections/AntiILDasmProtection.cs +++ b/Confuser.Protections/AntiILDasmProtection.cs @@ -43,6 +43,10 @@ namespace Confuser.Protections { get { return ProtectionTargets.Modules; } } + public override string Name { + get { return "Anti-ILDasm marking"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { foreach (ModuleDef module in parameters.Targets.OfType()) { TypeRef attrRef = module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "SuppressIldasmAttribute"); diff --git a/Confuser.Protections/AntiTamper/AntiTamperProtection.cs b/Confuser.Protections/AntiTamper/AntiTamperProtection.cs index 207c019..f731831 100644 --- a/Confuser.Protections/AntiTamper/AntiTamperProtection.cs +++ b/Confuser.Protections/AntiTamper/AntiTamperProtection.cs @@ -53,6 +53,10 @@ namespace Confuser.Protections { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Anti-tamper helpers injection"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (!parameters.Targets.Any()) return; @@ -82,6 +86,10 @@ namespace Confuser.Protections { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Anti-tamper metadata preparation"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (!parameters.Targets.Any()) return; diff --git a/Confuser.Protections/Compress/ExtractPhase.cs b/Confuser.Protections/Compress/ExtractPhase.cs index 03a9c59..4472a34 100644 --- a/Confuser.Protections/Compress/ExtractPhase.cs +++ b/Confuser.Protections/Compress/ExtractPhase.cs @@ -14,6 +14,10 @@ namespace Confuser.Protections.Compress { get { return ProtectionTargets.Modules; } } + public override string Name { + get { return "Packer info extraction"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (context.Packer == null) return; diff --git a/Confuser.Protections/Compress/StubProtection.cs b/Confuser.Protections/Compress/StubProtection.cs index aa1e23e..cdaaeb1 100644 --- a/Confuser.Protections/Compress/StubProtection.cs +++ b/Confuser.Protections/Compress/StubProtection.cs @@ -49,6 +49,10 @@ namespace Confuser.Protections.Compress { get { return ProtectionTargets.Modules; } } + public override string Name { + get { return "Packer info encoding"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { context.CurrentModuleWriterListener.OnWriterEvent += (sender, e) => { if (e.WriterEvent == ModuleWriterEvent.MDBeginCreateTables) { diff --git a/Confuser.Protections/Constants/EncodePhase.cs b/Confuser.Protections/Constants/EncodePhase.cs index 204b10c..48c2117 100644 --- a/Confuser.Protections/Constants/EncodePhase.cs +++ b/Confuser.Protections/Constants/EncodePhase.cs @@ -20,6 +20,10 @@ namespace Confuser.Protections.Constants { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Constants encoding"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var moduleCtx = context.Annotations.Get(context.CurrentModule, ConstantProtection.ContextKey); if (!parameters.Targets.Any() || moduleCtx == null) diff --git a/Confuser.Protections/Constants/InjectPhase.cs b/Confuser.Protections/Constants/InjectPhase.cs index 888118c..c451dc4 100644 --- a/Confuser.Protections/Constants/InjectPhase.cs +++ b/Confuser.Protections/Constants/InjectPhase.cs @@ -18,6 +18,10 @@ namespace Confuser.Protections.Constants { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Constant encryption helpers injection"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (parameters.Targets.Any()) { var compression = context.Registry.GetService(); diff --git a/Confuser.Protections/ControlFlow/ControlFlowPhase.cs b/Confuser.Protections/ControlFlow/ControlFlowPhase.cs index d82355d..5649a3a 100644 --- a/Confuser.Protections/ControlFlow/ControlFlowPhase.cs +++ b/Confuser.Protections/ControlFlow/ControlFlowPhase.cs @@ -20,6 +20,10 @@ namespace Confuser.Protections.ControlFlow { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Control flow mangling"; } + } + private static CFContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RandomGenerator random, bool disableOpti) { var ret = new CFContext(); ret.Type = parameters.GetParameter(context, method, "type", CFType.Switch); diff --git a/Confuser.Protections/InvalidMetadataProtection.cs b/Confuser.Protections/InvalidMetadataProtection.cs index 3c2fe60..5182ab3 100644 --- a/Confuser.Protections/InvalidMetadataProtection.cs +++ b/Confuser.Protections/InvalidMetadataProtection.cs @@ -49,6 +49,10 @@ namespace Confuser.Protections { get { return ProtectionTargets.Modules; } } + public override string Name { + get { return "Invalid metadata addition"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (parameters.Targets.Contains(context.CurrentModule)) { random = context.Registry.GetService().GetRandomGenerator(_FullId); diff --git a/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs b/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs index d241253..fb0ff69 100644 --- a/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs +++ b/Confuser.Protections/ReferenceProxy/ReferenceProxyPhase.cs @@ -16,6 +16,10 @@ namespace Confuser.Protections.ReferenceProxy { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Encoding reference proxies"; } + } + private static RPContext ParseParameters(MethodDef method, ConfuserContext context, ProtectionParameters parameters, RPStore store) { var ret = new RPContext(); ret.Mode = parameters.GetParameter(context, method, "mode", Mode.Mild); diff --git a/Confuser.Protections/Resources/InjectPhase.cs b/Confuser.Protections/Resources/InjectPhase.cs index 03d262a..f4e1bc7 100644 --- a/Confuser.Protections/Resources/InjectPhase.cs +++ b/Confuser.Protections/Resources/InjectPhase.cs @@ -19,6 +19,10 @@ namespace Confuser.Protections.Resources { get { return ProtectionTargets.Methods; } } + public override string Name { + get { return "Resource encryption helpers injection"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { if (parameters.Targets.Any()) { var compression = context.Registry.GetService(); diff --git a/Confuser.Renamer/AnalyzePhase.cs b/Confuser.Renamer/AnalyzePhase.cs index c9bfef9..f27018e 100644 --- a/Confuser.Renamer/AnalyzePhase.cs +++ b/Confuser.Renamer/AnalyzePhase.cs @@ -15,6 +15,10 @@ namespace Confuser.Renamer { get { return ProtectionTargets.AllDefinitions; } } + public override string Name { + get { return "Name analysis"; } + } + private void ParseParameters(IDnlibDef def, ConfuserContext context, NameService service, ProtectionParameters parameters) { var mode = parameters.GetParameter(context, def, "mode", null); if (mode != null) diff --git a/Confuser.Renamer/PostRenamePhase.cs b/Confuser.Renamer/PostRenamePhase.cs index d26d09f..814f46f 100644 --- a/Confuser.Renamer/PostRenamePhase.cs +++ b/Confuser.Renamer/PostRenamePhase.cs @@ -14,6 +14,10 @@ namespace Confuser.Renamer { get { return ProtectionTargets.AllDefinitions; } } + public override string Name { + get { return "Post-renaming"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var service = (NameService)context.Registry.GetService(); diff --git a/Confuser.Renamer/RenamePhase.cs b/Confuser.Renamer/RenamePhase.cs index 0455236..ea643d1 100644 --- a/Confuser.Renamer/RenamePhase.cs +++ b/Confuser.Renamer/RenamePhase.cs @@ -12,6 +12,10 @@ namespace Confuser.Renamer { get { return ProtectionTargets.AllDefinitions; } } + public override string Name { + get { return "Renaming"; } + } + protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var service = (NameService)context.Registry.GetService(); diff --git a/ConfuserEx/Skin.cs b/ConfuserEx/Skin.cs index be3c9f7..8729f07 100644 --- a/ConfuserEx/Skin.cs +++ b/ConfuserEx/Skin.cs @@ -32,8 +32,12 @@ namespace ConfuserEx { public static void OnRTBDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs dpe) { var rtb = (RichTextBox)d; - rtb.Document = (FlowDocument)dpe.NewValue; - rtb.TextChanged += (sender, e) => rtb.ScrollToEnd(); + if (dpe.NewValue != null) { + rtb.Document = (FlowDocument)dpe.NewValue; + rtb.TextChanged += (sender, e) => rtb.ScrollToEnd(); + } + else + rtb.Document = new FlowDocument(); } public static FlowDocument GetRTBDocument(DependencyObject obj) {