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

Disable type name rename when marked with SerializableAttribute #493

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fjch1997
Copy link

#58

This way serialized data is fully compatible with unobfuscated version

@wmjordan
Copy link

wmjordan commented Nov 6, 2016

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);
}

@fjch1997
Copy link
Author

fjch1997 commented Nov 9, 2016

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.

@wmjordan
Copy link

wmjordan commented Nov 10, 2016

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.

@fjch1997
Copy link
Author

Probably better disabling renaming for the entire class using Confuser's attribute. This is not worth the effort.

@wmjordan
Copy link

@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.

@fjch1997
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants