From a17159217268f3dcd9bdec52e6ff1c4792f1818d Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 16 May 2025 10:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20RemoveObfuzAttributesPass.?= =?UTF-8?q?cs=EF=BC=8C=E5=9C=A8=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=B8=85=E7=90=86=E6=8E=89=E6=89=80=E6=9C=89?= =?UTF-8?q?=20[ObfuzIgnore]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CleanUp/RemoveObfuzAttributesPass.cs | 70 +++++++++++++++++++ Editor/Obfuscator.cs | 1 + 2 files changed, 71 insertions(+) create mode 100644 Editor/ObfusPasses/CleanUp/RemoveObfuzAttributesPass.cs diff --git a/Editor/ObfusPasses/CleanUp/RemoveObfuzAttributesPass.cs b/Editor/ObfusPasses/CleanUp/RemoveObfuzAttributesPass.cs new file mode 100644 index 0000000..e1b02e9 --- /dev/null +++ b/Editor/ObfusPasses/CleanUp/RemoveObfuzAttributesPass.cs @@ -0,0 +1,70 @@ +using dnlib.DotNet; +using dnlib.DotNet.Emit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Obfuz.ObfusPasses.CleanUp +{ + public class RemoveObfuzAttributesPass : ObfuscationPassBase + { + public override ObfuscationPassType Type => ObfuscationPassType.None; + + public override void Start() + { + } + + public override void Stop() + { + + } + + + private void RemoveObfuzAttributes(IHasCustomAttribute provider) + { + CustomAttributeCollection customAttributes = provider.CustomAttributes; + if (customAttributes.Count == 0) + return; + var toRemove = new List(); + customAttributes.RemoveAll("Obfuz.ObfuzIgnoreAttribute"); + } + + public override void Process() + { + var ctx = ObfuscationPassContext.Current; + foreach (ModuleDef mod in ctx.toObfuscatedModules) + { + RemoveObfuzAttributes(mod); + foreach (TypeDef type in mod.GetTypes()) + { + RemoveObfuzAttributes(type); + foreach (FieldDef field in type.Fields) + { + RemoveObfuzAttributes(field); + } + foreach (MethodDef method in type.Methods) + { + RemoveObfuzAttributes(method); + foreach (Parameter param in method.Parameters) + { + if (param.ParamDef != null) + { + RemoveObfuzAttributes(param.ParamDef); + } + } + } + foreach (PropertyDef property in type.Properties) + { + RemoveObfuzAttributes(property); + } + foreach (EventDef eventDef in type.Events) + { + RemoveObfuzAttributes(eventDef); + } + } + } + } + } +} diff --git a/Editor/Obfuscator.cs b/Editor/Obfuscator.cs index c0e0975..15ee177 100644 --- a/Editor/Obfuscator.cs +++ b/Editor/Obfuscator.cs @@ -69,6 +69,7 @@ namespace Obfuz } } _pipeline1.AddPass(new CleanUpInstructionPass()); + _pipeline2.AddPass(new RemoveObfuzAttributesPass()); } public static void SaveKey(byte[] secret, string secretOutputPath)