Obfuscator

This extension applies obfuscation to your assemblies.

Image

Subscribed hooks

Assembly creation

This extension modifies assembly stream in assembly creation hook.

Options

Naming Strategy

StrategyDescription
Non PrintableUse non-printable control characters for names
GuidUse GUID for names

Filtering Strategy

StrategyDescription
AutomaticUse default strategy
CustomUse a config file for advanced control

Automatic

The automatic strategy for obfuscation processes the following types and members:

  • Non-public types
    • Except those derived from UnityEngine.Object.
    • Except those marked with the System.Reflection.ObfuscationAttribute(Exclude = true) attribute.
  • Members of non-public types, or private members of public types
    • Except those marked with UnityEngine.SerializeField, UnityEngine.PropertyAttribute, or System.Reflection.ObfuscationAttribute(Exclude = true) attributes.
    • Except those with abstract, override or virtual modifiers
    • Except those with Unity-specific method names (e.g. Awake, Update) within types derived from UnityEngine.Object
    • Except those public fields within types marked with the System.Serializable attribute.

Overloads are treated as a single method (they'll have the same name after obfuscation).

Custom

To generate a custom config template file, follow these steps:

  1. Switch to "Automatic".
  2. Click the refresh icon button in the "Preview Config" section.
  3. If processing succeeds, click the save icon button to export the config.

You can make changes to the config file and switch back to "Custom" to use the modified config file.

An exmaple config file:

<obfuscation>
  <type name="MyNamespace.MyHelperClass" exclude="true">
    <member name="MyStaticMethod" />
  </type>
  <type name="MyNamespace.MyInternalClass">
    <member name="_myPrivateField" />
  </type>
  <type name="MyNamespace.MyPublicClass" exclude="true" />
</obfuscation>

In a config file, only listed types and members will be obfuscated. If a type or member has an attribute exclude set to true, the type or member itself will be excluded from obfuscation, but not their members. You need to explicitly set the attribute for each member you want to exclude, or simply remove them from the list.

You can also use System.Reflection.ObfuscationAttribute with the Exclude property:

using System.Reflection;

// this class name won't be obfuscated
[Obfuscation] // it's the same as [Obfuscation(Exclude = true)]
internal class MyHelper
{
}

Please note that the default value for the Exclude property is true, which excludes it from being obfuscated. Though it might look confusing when arguments are ommitted.

Project config

Example decoded json config in project file:

{
  "namingStrategy": 0,
  "filteringStrategy": 1,
  "configFile": "obfuscation.xml"
}
Previous
Visibility Changer