Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.
Open
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
64 changes: 62 additions & 2 deletions Confuser.Renamer/AnalyzePhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
service.SetCanRename(type, false);
}

/*
* Can't rename Classes/Types that will be serialized
*/
if(type != null) {
if (type.IsSerializable) {
service.SetCanRename(type, false);
}

if (type.DeclaringType != null) {
if (type.DeclaringType.IsSerializable) {
service.SetCanRename(type, false);
}
}
}

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

Expand Down Expand Up @@ -200,9 +215,30 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (parameters.GetParameter(context, field, "forceRen", false))
return;

else if (field.DeclaringType.IsSerializable && !field.IsNotSerialized)
/*
* System.Xml.Serialization.XmlSerializer
*
* XmlSerializer by default serializes fields marked with [NonSerialized]
* This is a work-around that causes all fields in a class marked [Serializable]
* to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
*
* If we have a way to detect which serializer method the code is going to use
* for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
* we'll have a more accurate way to achieve this.
*/
else if (field.DeclaringType.IsSerializable) // && !field.IsNotSerialized)
service.SetCanRename(field, false);

else if (field.DeclaringType.IsSerializable && (field.CustomAttributes.IsDefined("XmlIgnore")
|| field.CustomAttributes.IsDefined("XmlIgnoreAttribute")
|| field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore")
|| field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute")
|| field.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute"))) // Can't seem to detect CustomAttribute
service.SetCanRename(field, true);
/*
* End of XmlSerializer work-around
*/

else if (field.IsLiteral && field.DeclaringType.IsEnum &&
!parameters.GetParameter(context, field, "renEnum", false))
service.SetCanRename(field, false);
Expand All @@ -219,7 +255,31 @@ void Analyze(NameService service, ConfuserContext context, ProtectionParameters
else if (parameters.GetParameter(context, property, "forceRen", false))
return;

else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
/*
* System.Xml.Serialization.XmlSerializer
*
* XmlSerializer by default serializes fields marked with [NonSerialized]
* This is a work-around that causes all fields in a class marked [Serializable]
* to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
*
* If we have a way to detect which serializer method the code is going to use
* for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
* we'll have a more accurate way to achieve this.
*/
else if (property.DeclaringType.IsSerializable) // && !field.IsNotSerialized)
service.SetCanRename(property, false);

else if (property.DeclaringType.IsSerializable && (property.CustomAttributes.IsDefined("XmlIgnore")
|| property.CustomAttributes.IsDefined("XmlIgnoreAttribute")
|| property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore")
|| property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute")
|| property.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute"))) // Can't seem to detect CustomAttribute
service.SetCanRename(property, true);
/*
* End of XmlSerializer work-around
*/

else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
service.SetCanRename(property, false);

else if (property.DeclaringType.Name.String.Contains("AnonymousType"))
Expand Down