Yano rules allow you to customize the obfuscation process in a very flexible manner. You should not need the rules if you don't use reflection, data binding and any communication technology based on serialization (.NET Remoting, WCF).
Rules are expressed in XML using a special easy-to-follow syntax. A rule indicates some special settings for a set of rule matching elements.
Yano installs with some out-of-the-box rules for various cases and frameworks that you can use or modify to fit your specific needs.
Here is how you can exclude all public static properties from being renamed:
<rule name="Exclude all public static properties (accessed through reflection)"> <renaming enabled="false" /> <apply-to-property specifiers="public static" /> </rule>
Each rule has an optional and unique name. The "renaming" node indicates that renaming should be disabled, while "apply-to-property" matches all public static properties.
Here are more examples that should clarify what you can do with rules.
<rule name="Enabling .NET Remoting"> <renaming cls-compliant="true" /> <apply-to-type> <having-type named="System.MarshalByRefObject" /> </apply-to-type> </rule>
For best obfuscation Yano renames metadata elements in CLI-compliant mode, which breaks .NET Remoting. The above example shows how to enable CLS-compliant renaming for classed derived from MarshalByRefObject. This is enough to enable .NET Remoting. Note that you have to obfuscate both client and server side assemblies in a single project to get this working.
The following example illustrates how you can target a specific element to change its processing settings.
<rule name="Exclude a resource from encryption"> <resource-encryption enabled="false" /> <apply-to-resource named="Yano.Core.Resources.Yano.xsd" /> </rule>
This is how you could obfuscate Fluent assembly:
<rule name="Use assembly renaming level, disable pruning and resource encryption for Fluent assembly"> <renaming level="assembly" /> <resource-encryption enabled="false" /> <pruning enabled="false" /> <apply-to-assembly named="Fluent" /> </rule>
Paint.NET uses reflection to dynamically access control properties and bind them to UI. Those properties are marked with PropertyControlPropertyAttribute. Here is how you can target them to disable renaming:
<rule name="Disable renaming properties with PaintDotNet.IndirectUI.PropertyControlPropertyAttribute"> <renaming enabled="false" /> <apply-to-property> <having-attribute named="PaintDotNet.IndirectUI.PropertyControlPropertyAttribute" /> </apply-to-property> </rule>
Specifiers are a powerfull technique to filter out elements and easily target the ones you want. The next example shows how to preserve the names of interfaces defined in ICSharpCode.TextEditor namespace. Note that their members (i.e. methods) are not excluded from renaming by the rule.
<rule name="Disable renaming interfaces defined in ICSharpCode.TextEditor namespace"> <renaming enabled="false" /> <apply-to-type members="false" named="ICSharpCode.TextEditor.*" specifiers="interface" /> </rule>
The following rule is part of a project that obfuscates a complex ERP system. ERP's extension points are methods that have a single parameter of IActionContext type. The ERP engine invokes these methods after searching them by their full name (Namespace.Type.Method) via reflection. Therefore the rule also disables renaming for method's containing type and namespaces.
<rule name="Disable renaming and pruning methods having a single parameter of IActionContext type"> <renaming enabled="false" /> <pruning enabled="false" /> <apply-to-method container="true"> <having-signature parameters-count="1"> <with-parameter index="0"> <having-type named="*.IActionContext" /> </with-parameter> </having-signature> <defined-in-type specifiers="non-interface non-delegate" /> </apply-to-method> </rule>
The installer installs an XML schema file (Yano.xsd) which you can use in any XML editor to obtain autocompletion and easily edit Yano project and rules files.
It is automatically deployed into Visual Studio (2005-2010) schema folder to get IntelliSense support inside the built-in XML Editor.