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

don't rename explicitly implemented interface members #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 53 additions & 35 deletions Confuser.Core/DnlibUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,65 +269,83 @@ static void FindTypeRefsInternal(TypeSig typeSig, IList<ITypeDefOrRef> ret) {
/// </summary>
/// <param name="property">The property.</param>
/// <returns><c>true</c> if the specified property is public; otherwise, <c>false</c>.</returns>
public static bool IsPublic(this PropertyDef property) {
if (property.GetMethod != null && property.GetMethod.IsPublic)
return true;

if (property.SetMethod != null && property.SetMethod.IsPublic)
return true;

return property.OtherMethods.Any(method => method.IsPublic);
public static bool IsPublic (this PropertyDef property)
{
return property.AllMethods ().Any (method => method.IsPublic);
}

/// <summary>
/// Determines whether the specified property is static.
/// </summary>
/// <param name="property">The property.</param>
/// <returns><c>true</c> if the specified property is static; otherwise, <c>false</c>.</returns>
public static bool IsStatic(this PropertyDef property) {
if (property.GetMethod != null && property.GetMethod.IsStatic)
return true;

if (property.SetMethod != null && property.SetMethod.IsStatic)
return true;

return property.OtherMethods.Any(method => method.IsStatic);
public static bool IsStatic (this PropertyDef property)
{
return property.AllMethods ().Any (method => method.IsStatic);
}

/// <summary>
/// Determines whether the specified event is public.
/// </summary>
/// <param name="evt">The event.</param>
/// <returns><c>true</c> if the specified event is public; otherwise, <c>false</c>.</returns>
public static bool IsPublic(this EventDef evt) {
if (evt.AddMethod != null && evt.AddMethod.IsPublic)
return true;

if (evt.RemoveMethod != null && evt.RemoveMethod.IsPublic)
return true;

if (evt.InvokeMethod != null && evt.InvokeMethod.IsPublic)
return true;

return evt.OtherMethods.Any(method => method.IsPublic);
public static bool IsPublic (this EventDef evt)
{
return evt.AllMethods ().Any (method => method.IsPublic);
}

/// <summary>
/// Determines whether the specified event is static.
/// </summary>
/// <param name="evt">The event.</param>
/// <returns><c>true</c> if the specified event is static; otherwise, <c>false</c>.</returns>
public static bool IsStatic(this EventDef evt) {
if (evt.AddMethod != null && evt.AddMethod.IsStatic)
return true;
public static bool IsStatic (this EventDef evt)
{
return evt.AllMethods ().Any (method => method.IsStatic);
}

/// <summary>
/// Determines whether the specified method is an explictly implemented interface member.
/// </summary>
/// <param name="method">The method.</param>
/// <returns><c>true</c> if the specified method is an explictly implemented interface member; otherwise, <c>false</c>.</returns>
public static bool IsExplicitlyImplementedInterfaceMember (this MethodDef method)
{
return method.IsFinal && method.IsPrivate;
}

if (evt.RemoveMethod != null && evt.RemoveMethod.IsStatic)
return true;
/// <summary>
/// Determines whether the specified property is an explictly implemented interface member.
/// </summary>
/// <param name="property">The method.</param>
/// <returns><c>true</c> if the specified property is an explictly implemented interface member; otherwise, <c>false</c>.</returns>
public static bool IsExplicitlyImplementedInterfaceMember (this PropertyDef property)
{
return property.AllMethods ().Any (IsExplicitlyImplementedInterfaceMember);
}

if (evt.InvokeMethod != null && evt.InvokeMethod.IsStatic)
return true;
/// <summary>
/// Determines whether the specified event is an explictly implemented interface member.
/// </summary>
/// <param name="evt">The event.</param>
/// <returns><c>true</c> if the specified eve is an explictly implemented interface member; otherwise, <c>false</c>.</returns>
public static bool IsExplicitlyImplementedInterfaceMember (this EventDef evt)
{
return evt.AllMethods ().Any (IsExplicitlyImplementedInterfaceMember);
}

private static IEnumerable<MethodDef> AllMethods (this EventDef evt)
{
return new [] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod }
.Concat (evt.OtherMethods)
.Where (m => m != null);
}

return evt.OtherMethods.Any(method => method.IsStatic);
private static IEnumerable<MethodDef> AllMethods (this PropertyDef property)
{
return new [] { property.GetMethod, property.SetMethod }
.Concat (property.OtherMethods)
.Where (m => m != null);
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions Confuser.Renamer/AnalyzePhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (method.IsRuntimeSpecialName)
service.SetCanRename(method, false);

else if (method.IsExplicitlyImplementedInterfaceMember())
service.SetCanRename(method, false);

else if (parameters.GetParameter(context, method, "forceRen", false))
return;

Expand Down Expand Up @@ -216,6 +219,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (property.IsRuntimeSpecialName)
service.SetCanRename(property, false);

else if (property.IsExplicitlyImplementedInterfaceMember())
service.SetCanRename(property, false);

else if (parameters.GetParameter(context, property, "forceRen", false))
return;

Expand All @@ -233,6 +239,9 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters

else if (evt.IsRuntimeSpecialName)
service.SetCanRename(evt, false);

else if (evt.IsExplicitlyImplementedInterfaceMember())
service.SetCanRename (evt, false);
}
}
}