From 79df790aec88ff5577a46e3390e261f801319eef Mon Sep 17 00:00:00 2001 From: js6pak Date: Fri, 15 Jan 2021 00:41:36 +0100 Subject: [PATCH] Reobfuscate type arrays in attributes --- .../Reactor.OxygenFilter.MSBuild.csproj | 2 +- Reactor.OxygenFilter.MSBuild/Reobfuscate.cs | 42 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj b/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj index eb07a96..be440d2 100644 --- a/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj +++ b/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj @@ -4,7 +4,7 @@ latest true - 0.2.1 + 0.2.2 git https://github.com/NuclearPowered/Reactor.OxygenFilter LGPL-3.0-or-later diff --git a/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs b/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs index ba45bb4..ae45ba4 100644 --- a/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs +++ b/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs @@ -99,29 +99,41 @@ namespace Reactor.OxygenFilter.MSBuild foreach (var type in moduleDefinition.GetAllTypes()) { + void ReobfuscateType(TypeReference t) + { + while (t != null) + { + var obfuscated = GetObfuscated(t.Resolve()); + + if (obfuscated != null) + { + toObfuscate[t] = obfuscated; + } + + t = t.DeclaringType; + } + } + foreach (var customAttribute in type.CustomAttributes) { TypeReference lastType = null; foreach (var argument in customAttribute.ConstructorArguments.ToList()) { - if (argument.Type.FullName == "System.Type") + if (argument.Type.FullName == "System.Type[]") + { + foreach (var nestedArgument in (CustomAttributeArgument[]) argument.Value) + { + if (nestedArgument.Type.FullName == "System.Type") + { + ReobfuscateType((TypeReference) nestedArgument.Value); + } + } + } + else if (argument.Type.FullName == "System.Type") { lastType = (TypeReference) argument.Value; - - var t = lastType; - - while (t != null) - { - var obfuscated = GetObfuscated(t.Resolve()); - - if (obfuscated != null) - { - toObfuscate[t] = obfuscated; - } - - t = t.DeclaringType; - } + ReobfuscateType(lastType); } else {