Still working on my obfuscation program based on modifying ILAsm files. (Ref. Which C# method names should not be obfuscated? )
In looking at the ILAsm code, I get the impression that the .property statements aren't used for anything, at least not for program execution. Am I right in thinking they are only there to provide metadata for Visual Studio? And if so, is it OK to simply remove them when the ILAsm code will only be used to produce production modules that will never be used with Visual Studio?
You're correct that the fact something is declared as a property does not affect program execution. As the book Inside Microsoft .NET IL Assembler states in its introduction to the chapter concerning properties, the JIT compiler and execution engine are completely unaware of properties, and no IL instructions make any reference to the property concept.
Note that Visual Studio is not the only consumer of metadata. If you strip
.property
and reassemble, you'll have the getter and setter methods, but it obviously isn't a property any more. The most obvious example of where this becomes a problem : what if an instance of an object gets handed off to another method which uses reflection to invoke each property on the class? The properties would not be found and run-time behavior has changed as a result of the proposed obfuscation method.Of course, scenarios such as reflection and serialization are a common gotcha with obfuscation tools, as was discussed in your previous question. So, what I'm saying is, it is problematic, but its problematic in a similar set of scenarios as those discussed in your other thread -- particularly those scenarios where metadata is being consumed or serialization is being performed at run-time.
The latest edition of the book I mentioned above has a different name: Expert .NET 2.0 IL Assembler; it may be a useful reference to you. Compiling for the .NET Common Language Runtime may also be valuable.