Private field name is not mangled in merged assembly
iblazhko-tw
Posts: 6
I have following code in a dependency assembly:
Note the private field "implementation ".
This dependency is merged into main application and obfuscated:
After the obfuscation name of the private field "implementation" is not mangled:
https://www.dropbox.com/s/w64ibwonkf1nh0v/PrivateFieldNotMangled.png?dl=0
I would expect the name to be obfuscated, it is only used once as displayed in the snippet above, no access by reflection or anything like this.
Is there something I am missing from obfuscation configuration?
I was using SmartAssembly 6.9.0.114 for this test.
using AppDomainTest.Contracts; using AppDomainTest.Implementation2; using System; namespace AppDomainTest.Implementation3 { [Serializable] public class ServiceInAppDomain : ICalculatorService { private readonly ServiceEmbedded implementation = new ServiceEmbedded(); public double Add(double a, double b) { return implementation.Add(a, b); } } }
Note the private field "implementation ".
This dependency is merged into main application and obfuscated:
... <Options> ... <Obfuscation FieldsNameMangling="2" NameMangling="1" /> ... </Options> ... <Assembly AssemblyName="AppDomainTest.Implementation3, Culture=neutral, PublicKeyToken=null"> <Merging Merge="1"> <Obfuscation ExcludePublicMembers="0" Obfuscate="1" /> <ControlFlow Obfuscate="1" /> </Merging> </Assembly>
After the obfuscation name of the private field "implementation" is not mangled:
https://www.dropbox.com/s/w64ibwonkf1nh0v/PrivateFieldNotMangled.png?dl=0
I would expect the name to be obfuscated, it is only used once as displayed in the snippet above, no access by reflection or anything like this.
Is there something I am missing from obfuscation configuration?
I was using SmartAssembly 6.9.0.114 for this test.
Comments
According to the documentation here on serialization, it indicates that
It has further information on a way to get the obfuscation working in this instance.
I hope this helps!
Kind regards,
Alex
Have you visited our Help Center?
Thanks for the reply.
Yes, I see, that's make sense for private fields to not be obfuscated when the type is [Serializable].
How about private constants?
Consider this class:
Obfuscated version has "private const int State" unobfuscated. Any reasons why? It does not seem to have any effect on serialization.
If I apply [NonSerialized] attribute to the constant, its name gets mangled during obfuscation.
Thanks.
As stated before, the entire Class1 class is excluded from obfuscation, which includes the private constant. In the link it mentions you can work around this by implementing ISerializable on the class. Have a look at the documentation on serialization.
Kind regards,
Alex
Have you visited our Help Center?