PreEmptive has evolved over the years to handle all different types of applications and scenarios. Reasonable defaults are designed to get any project up and running, and from there, we have full control over protection settings. Custom rules are one way to create simple, robust, flexible configurations—even with very complex applications.
In previous Support Corner articles, we learned about coding techniques that require a Rename exclusion to run properly after obfuscation. Sometimes, excluding just one class, method, field, or property is sufficient. But for larger, more complex applications this is usually not the case. Custom rules can help organize these exclusions into patterns for a more flexible and robust configuration. Rules can be created to exclude all descendants of a parent class or those that implement a particular interface. Rules can be created for types or members decorated with a custom attribute or with a certain access modifier. Regular expressions can also make custom rules based on the naming convention.
Consider the following example.
In “Protecting .NET applications that use the MVVM pattern,“ we learned that MVVM uses reflection to load properties of model classes:
Because of this, we had to exclude those properties from Rename obfuscation to avoid a runtime error:
Rather than checking individual checkboxes for each property, I can translate this into a custom rule. Each model class with an OnPropertyChanged method must implement INotifyPropertyChanged. Based on this, I will write a rule to exclude properties (.*) of any type (.*) that implements INotifyPropertChanged:
By making this modification, we can change or expand the use of the MVVM pattern without having to update obfuscation rules. I will also apply the other obfuscation transforms, String Encryption, Control Flow, Linking, and Tamper defense, to secure that section of code.
The full MVVM example modified to use Custom Rules can be downloaded here.
The original Support Corner article “Protecting .NET applications that use the MVVM pattern” is here.
If you have any feedback on this topic or other topics you would like us to discuss in the Support Corner, please contact us.