# Advanced Rules Editor

# Introduction

The Advanced Rules Editor provides a visual way to configure the same obfuscation and protection settings available via [assembly: Obfuscation(Feature="...")] attributes in your code (see here). Instead of writing assembly attributes by hand, you can use the GUI to:

  • Create Rules that specify which features (e.g., Renaming, ControlFlow, Virtualization, StringEncryption, etc.) to enable or disable.
  • Apply those Rules selectively to certain assemblies, namespaces, types, methods, fields, properties, or events.
  • Use Regular Expressions for matching names if you need advanced filtering.
  • Generate the corresponding [assembly: Obfuscation(Feature="...")] attributes from your visual settings, allowing you to include them directly in your project if you wish.

# 1. Accessing the Rules Editor

  1. In .NET Reactor, go to 2. Protection Settings -> Advanced Rules.
  2. Click on Add to create a new rule or select an existing rule to edit or clone.

# 2. Overview of the Rules Editor Interface

When you open the Rules Editor, you will see two main sections:

  1. Rules List (top section):

    • Displays all configured rules in a table, including columns for Rule Name, Rules Type, Assemblies, Namespaces, and Types.
    • You can quickly enable or disable a rule by checking or unchecking it in the Active column.
    • The Filter dropdown (at the top) allows you to filter which rules are currently displayed (e.g., show only renaming rules, show all rules, etc.).

  2. Rule Configuration (bottom section):

    • Here is where you specify the details of the selected rule.
    • Name and Comments fields let you describe your rule.
    • A Rules Type area (e.g., “Exclude Renaming” in the screenshot) indicates which obfuscation features are being turned on/off. You can toggle checkboxes (e.g., Type Names, Namespaces, Methods, Fields, Properties, etc.) or specify method/property names to include or exclude from renaming or from other features.
    • The Use Regular Expressions option allows the typed values (e.g., method or property names) to be interpreted as regex patterns.
    • The Where section lets you narrow down the rule to certain assemblies, namespaces, or specific types. You can also specify filters for Access Modifiers (e.g., public, private).

# 3. Adding or Editing a Rule

  1. Click “Add” to create a new rule and/or select a rule to bring up the detailed editor (the lower section).

  2. Rule Name: Provide a descriptive name (e.g., “PreventRenaming_MyCriticalTypes”).

  3. Comments: Add any notes you want to remember later (optional).

  4. Features Section:

    • Choose the type of rule you want to apply or exclude. For instance, “Exclude Renaming,” “Enable ControlFlow,” etc.
    • Depending on the selected rule type, you might see input fields and checkboxes for:
      • Type Names / Namespaces / Methods / Fields / Properties / Events
      • When checked, it means that category is included in the rule.
      • If the rule is an Exclude-type rule (e.g., “Exclude Renaming”), then those checked items will be excluded from renaming.
    • To specify a particular set of methods, properties, or events by name, enter them in the text box (comma-separated). You can also use the ... button to add the names to a list and define access modifiers.

    • Access Modifier filters (e.g., All Access Modifiers, +public, -internal) are also available. This lets you, for example, exclude only protected members from renaming while allowing private members to be renamed.

  5. Where (Filters):

    • Narrow down the rule by specifying:
      • Assemblies: If multiple assemblies are loaded in your project, you can select which ones get this rule. By default, “All Assemblies” is selected.
      • Namespace: Enter the namespace that this rule should target (e.g., My.Namespace).
      • Types: Enter specific types (e.g., MyType, MyType2+MySubClass). The plus sign denotes a nested type or sub-class. You can also leave the Namespace field empty and define full type names here.

  6. Use Regular Expressions:

    • If you check this box, all the name-based fields (methods, fields, properties, events, namespace, types) will be interpreted as regular expressions. This is equivalent to using rule regex: in the [Obfuscation(Feature="...")] syntax.

  7. Save your rule by clicking OK (or “Apply”) in the dialog. The new rule will be added to the list at the top.

# 4. Rule Priority and Conflicts

  • Typically, rules are processed top to bottom.
  • As a rule of thumb, place the more specific or narrower rules after the more general rules so that the narrower rule can take precedence.

# 5. Generating Assembly Attributes

You can easily convert your configured visual rules into assembly attributes:

  1. Right-click on a rule (or a selection of rules) and choose “Generate Assembly Attributes”. Alternatively you can use the corresponding menu items.
  2. The attributes are copied to the clipboard.

# 6. Tips & Best Practices

  • Use Comments: Document within the rule editor what each rule does, especially if you share the project with other developers.
  • Check Overlaps: Make sure that overlapping rules do not create unintended results.
  • Regular Expressions: Use them with caution—overly broad patterns can accidentally match more types/members than you intended.

# 7. Examples

# Example 1: Exclude Renaming for All Classes

All classes and their members in every assembly are excluded from renaming.



# Example 2: Exclude Renaming for Specific Types

Class names and members of MyNamespace.Type1 and MyNamespace.Type2 are excluded from renaming.



# Example 3: Exclude Renaming for Specific Types (Alternative Approach)

Same as Example 2, but without using the Namespace field.



# Example 4: Exclude Renaming for a Full Namespace

Everything in MyNamespace is excluded from renaming.



# Example 5: Exclude Renaming for Classes Ending with "Resource"

Any class whose name ends with “Resource” is excluded from renaming.



# Example 6: Exclude Renaming for Internal Classes Matching "Special" Under Namespaces Starting with "My"

All internal classes containing “Special” in their names, located in namespaces starting with “My” are excluded from renaming.



# Example 7: Exclude Renaming for Fields and Specific Methods in One Type

Fields and methods Method1/Method2 in MyNamespace.MyType1 are excluded from renaming. The type name itself, properties, and events in MyType1 remain subject to renaming.



# Example 8: Exclude Renaming for Internal Methods Starting with "Special" in One Class

Internal methods whose names begin with “Special” in MyNamespace.MyType1 are excluded from renaming.



# Example 9: Exclude Renaming for Classes Derived from a Specific Base Type

All classes that inherit from MyNamespace.MyBaseType are excluded from renaming.



# Example 10: Exclude Renaming for Classes decorated with a specific Attribute

Any class marked with [JsonObject] is excluded from renaming.



# Example 11: Exclude String Encryption for Methods Decorated with a specific Attribute

Methods marked with [JsonPropertyName] are excluded from string encryption.