diff --git a/Confuser.Core/DnlibUtils.cs b/Confuser.Core/DnlibUtils.cs index 448cee43a..f3d3c5c12 100644 --- a/Confuser.Core/DnlibUtils.cs +++ b/Confuser.Core/DnlibUtils.cs @@ -102,6 +102,15 @@ public static bool IsComImport(this TypeDef type) { type.HasAttribute("System.Runtime.InteropServices.TypeLibTypeAttribute"); } + /// + /// Determines whether the specified type is compiler generated. + /// + /// The type. + /// true if specified type is compiler generated; otherwise, false. + public static bool IsCompilerGenerated(this TypeDef type) { + return type.HasAttribute("System.Runtime.CompilerServices.CompilerGeneratedAttribute"); + } + /// /// Determines whether the specified type is a delegate. /// diff --git a/Confuser.Core/ObfAttrMarker.cs b/Confuser.Core/ObfAttrMarker.cs index ebb72ca2e..c06da5bfd 100644 --- a/Confuser.Core/ObfAttrMarker.cs +++ b/Confuser.Core/ObfAttrMarker.cs @@ -486,7 +486,23 @@ void ProcessTypeMembers(TypeDef type, Rules rules, ProtectionSettingsStack stack void ProcessMember(IDnlibDef member, Rules rules, ProtectionSettingsStack stack) { stack.Push(ProcessAttributes(ReadObfuscationAttributes(member))); ApplySettings(member, rules, stack.GetInfos()); + ProcessBody(member as MethodDef, rules, stack); stack.Pop(); } + + void ProcessBody(MethodDef method, Rules rules, ProtectionSettingsStack stack) { + if (method == null || method.Body == null) + return; + + var declType = method.DeclaringType; + foreach (var instr in method.Body.Instructions) + if (instr.Operand is MethodDef) { + var cgType = ((MethodDef)instr.Operand).DeclaringType; + if (cgType.DeclaringType == declType && cgType.IsCompilerGenerated()) { + ApplySettings(cgType, rules, stack.GetInfos()); + ProcessTypeMembers(cgType, rules, stack); + } + } + } } } \ No newline at end of file