Babel 1.1.0.0This new release of babel introduce rule files. Rule files are XML files that contains information to guide the process of obfuscation. The rule file consist of a list of rules defined by XML element <Rule></Rule>. This list is enclosed by the element <Rules></Rules> that is also the root document element. <Rules version="1.0">
<Rule>
</Rule>
<Rule>
</Rule>
...
</Rules> The Rules element attribute version is used to define the current rules schema version and must be "1.0". If a rule file is provided to babel, this file is processed during type obfuscation and all symbols (classes, methods, properties, fields...) name are checked against each rule in the order they are declared into the file. If a symbol match a rule the symbol obfuscation action is taken by the boolean attribute obfuscate of the Rule element: <Rule name="my rule" obfuscate="false">
</Rule> The Rule element has another attribute, name, that is used to name the rule. The name and obfuscate attributes are mandatory as specified by the XSD schema. Any Rule element has five other child elements: Access, Target, Pattern, HasAttribute, Description. The first three attributes are mandatory, whereas the last two are optional. Access: Specify the symbol visibility for this rule. Admitted values are: All or any combination of Public, Protected, Internal, Private.
Target: Specify which kind of symbol should be checked. Admitted values are: All or any combination of
Classes, Delegates, Structures, Interfaces, Enums, Events,
Methods, Properties, Fields, StaticFields
Pattern: any wildcar expression or regular expression, the boolean attribute isRegEx states if the pattern is a regular expression. If a regular expression is used, remember to enclose the regular expression definition string in a CDATA section, ex: <![CDATA[^Properties.*]]> The optional elements are: HasAttribute: specify a list of fully qualified type attributes. If the target has at least one of these attribute the rule match. This element may have the boolean attribute onEnclosingType. If this attribute is set to "true" the attribute presence is checked on the target symbol enclosing type. Otherwise if it is set to "false" the attribute presence is checked on the target symbol. Description: any useful rule description The following example show the content of SafeRules.xml file: <Rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<Rule name="Properties types" obfuscate="false">
<Access>All</Access>
<Target>All</Target>
<Pattern isRegEx="false">*Properties*</Pattern>
<Description>Do not obfuscate all Properties namespace types.</Description>
</Rule>
<Rule name="Serializable types" obfuscate="false">
<Access>All</Access>
<Target>Fields, StaticFields</Target>
<Pattern><![CDATA[*]]></Pattern>
<HasAttribute onEnclosingType="true">System.SerializableAttribute</HasAttribute>
<Description>Do not obfuscate fields of Serializable types.</Description>
</Rule>
</Rules>This file is distributed with Babel 1.1.0.0 package. The first rules tells babel to do not obfuscate any symbol inside the Properties namespace or whatever symbol contains Properties in his fully qualified name. This rule is required by winform application that put all the application resource access into the Properties namespace. The second rule tells babel to do not obfuscate fields of types that are declared as serializable. Using this file for all windows form application is a good starting point. Examples1. Say you want to obfuscate all the enum types into the namespace Foo but not that one into any other child namespace, so you can write a rule file like this: <Rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<Rule name="Do not obfuscate enum in Foo" obfuscate="false">
<Access>All</Access>
<Target>Enums, StaticFields</Target>
<Pattern isRegEx="true"><![CDATA[Foo\.[^.]+$]]></Pattern>
<Description>Do not obfuscate Foo enum types.</Description>
</Rule>
</Rules>We use a regular expression pattern match for all the enum types with name that match Foo. but not Foo.Baz. So if you have an enum type named State into Foo namespace that one won't be obfuscated but if you have another enum, say Colors into namespace Foo.Baz that one will be obfuscated. Note that into <Target> element we have also included StaticFields because enums values are StaticFields. Rule file schema definitionFollow the XSD schema that babel use to validate any rule xml file. <?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Rules" type="RulesType" />
<xs:complexType name="RuleType">
<xs:all>
<xs:element minOccurs="1" name="Access" type="xs:string" />
<xs:element minOccurs="1" name="Target" type="xs:string" />
<xs:element minOccurs="1" name="Pattern" type="PatternType" />
<xs:element minOccurs="0" name="HasAttribute" type="HasAttributeType" />
<xs:element minOccurs="0" name="Description" type="xs:string" />
</xs:all>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="obfuscate" type="xs:boolean" use="required" />
</xs:complexType>
<xs:complexType name="PatternType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="false" name="isRegEx" type="xs:boolean" use="optional" />
<xs:attribute default="false" name="ignoreCase" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="HasAttributeType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="false" name="onEnclosingType" type="xs:boolean" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="RulesType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Rule">
<xs:complexType>
<xs:complexContent mixed="false">
<xs:extension base="RuleType" />
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute fixed="1.0" name="version" type="xs:string" use="required" />
</xs:complexType>
</xs:schema>
|
How to obfuscate local variables ?
The name of a local variable is not available at runtime because their names are not compiled into the assembly's metadata.