ConfuserEx
ConfuserEx copied to clipboard
Disable type name rename when marked with SerializableAttribute
#58
This way serialized data is fully compatible with unobfuscated version
Thank you very much for this patch. However, it applies to the type only. The properties of the type will still be renamed.
We shall add the following line into the void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, PropertyDef property) method in the same code file.
else if (property.DeclaringType.IsSerializable) {
service.SetCanRename(property, false);
}
SerializableAttribute doesn't care about properties, it cares about fields only.
My understanding is SerializableAttribute is only for .NET Framework's rule on (de)serialization, which will not call constructors and will only serialize fileds (private and public). This is also the behavior of BinaryFormatter and SoapFormatter. All classes that come with the framework and marked as Serializable follows this rule. Many third party serializer, including Newtonsoft.Json, can also be set to follow this rule.
If the author of the class want it to be Json serialized or something, there is no need to use SerializableAttribute. Instead, apply DataMemberAttribute or the serializer specific ones.
Thank you for the explanation.
Currently I am working with Dapper, which maps property names to database fields.
We do need some mechanisms to prevent properties from being renamed.
The DataMemberAttribute might not be suitable for this purpose.
Probably better disabling renaming for the entire class using Confuser's attribute. This is not worth the effort.
@fjch1997 Using "Confuser's attribute" would have the project referencing Confuser, which is not the way to go I am afraid.
Did you mean ObfuscatorAttribute actually? I agree using ObfuscatorAttribute instead will be a better approach.
The problem is that the support for ObfuscatorAttribute of Confuser is too limited at this moment.
It's been a while since I had to use Confuser so I'm forgetting all the details. But yes, I mean ObfuscatorAttribute. Confuser doesn't have its own attributes. Actually you can set parameters to ObfuscatorAttribute to instruct ConfuserEx to only disable rename for a class and everything. I know this is not properly documented but it is supported. So overall it's quite powerful. I can't tell you how to use it since I don't even remember myself. But you can take a look at the samples and source code.