Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Copy obfuscation settings to compiler generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Nov 21, 2015
1 parent 9877d2c commit 551dd48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Confuser.Core/DnlibUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public static bool IsComImport(this TypeDef type) {
type.HasAttribute("System.Runtime.InteropServices.TypeLibTypeAttribute");
}

/// <summary>
/// Determines whether the specified type is compiler generated.
/// </summary>
/// <param name="type">The type.</param>
/// <returns><c>true</c> if specified type is compiler generated; otherwise, <c>false</c>.</returns>
public static bool IsCompilerGenerated(this TypeDef type) {
return type.HasAttribute("System.Runtime.CompilerServices.CompilerGeneratedAttribute");
}

/// <summary>
/// Determines whether the specified type is a delegate.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Confuser.Core/ObfAttrMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}

0 comments on commit 551dd48

Please sign in to comment.