When processing an input assembly, Dotfuscator recognizes a number of attributes that are used in Declarative Obfuscation. By using these attributes on your source code, you can configure many protection features inline with your application code. This page details these attributes
Referencing the Attributes
You can reference the obfuscation attributes either through the .NET Base Class Libraries or through a Dotfuscator Reference Assembly. The namespace of the attributes vary depending on which reference you use, but otherwise the attributes are identical.
Through the .NET Base Class Libraries
The obfuscation attributes are defined in both of the following .NET Base Class Libraries:
- mscorlib.dll for the original .NET Framework, as of version 2.0 (released in 2005)
- netstandard.dll for .NET Standard, as of version 2.0 (release forthcoming)
Most .NET projects reference one of these by default, so you usually do not need to add a new reference to your project.
The namespace of these attributes is System.Reflection.
Through a Dotfuscator Reference Assembly
If you are using an older framework or platform that does not have access to the obfuscation attributes in System.Reflection, Dotfuscator has an alternative assembly that can be referenced instead.
The assembly is named PreEmptive.ObfuscationAttributes.dll.
You can search for this assembly via the public nuget.org and add it as a dependency to your project.
The namespace of the attributes defined in this alternative assembly is PreEmptive.Dotfuscator.ObfuscationAttributes.
Attribute Listing
This section lists the attributes that Dotfuscator recognizes to configure its obfuscation behavior.
ObfuscationAttribute
Specifies how an assembly or code element should be obfuscated. Each use of the attribute specifies a protection transform and whether the annotated element should be excluded or included by that feature when Dotfuscator processes the compiled assembly. Practically speaking, in Dotfuscator Community, this means it can specify that the annotated type or member should be excluded from Renaming. Additional transforms are available in Dotfuscator Professional.
Also see the full ObfuscationAttribute documentation on Microsoft Docs.
Namespace: System.Reflection or PreEmptive.Dotfuscator.ObfuscationAttributes
Applies to: Assembly, type, or member
Multiple allowed on one code element: Yes
Requirements:
- For Dotfuscator to recognize uses of this attribute and obfuscate accordingly, the Honor obfuscation attributes input option for the input assembly that contains this attribute must be enabled, which it is by default.
- For Dotfuscator to remove uses of this attribute from the protected assembly, at least one of the following must be true:
- The Strip obfuscation attributes input option for the input assembly that contains this attribute must be enabled, which it is by default; or,
- The StripAfterObfuscation property of the attribute must be true, which it is by default.
Properties:
-
Feature: The name of the obfuscation transform to specify.
- Defaults to all, which is an alias of renaming.
- default: an alias of renaming.
- renaming: Use to specify Renaming exclusions.
-
Exclude: If true, Dotfuscator will exclude the annotated code element from the specified feature. If false, the code element will be included in the specified feature.
- Defaults to true.
- Use true for specifying renaming exclusions.
- Dotfuscator supports one value of the Exclude property for any given transform. Dotfuscator will ignore rules that have unsupported Exclude values. Therefore, the feature-specific values as specified above should be used.
-
ApplyToMembers: If annotating a type, indicates whether the attribute's obfuscation feature should be applied to all of the type's members and nested types.
- Defaults to true.
-
StripAfterObfuscation: If true, Dotfuscator will remove this attribute usage from the output assembly.
- Defaults to true.
- Dotfuscator will always strip all attribute usages from an input assembly, regardless of this property, when Strip obfuscation attributes setting input option is enabled, which it is by default.
ObfuscateAssemblyAttribute
Specifies whether or not an assembly is considered a library assembly or not. Use of this attribute overrides the Library mode input option.
Also see the full ObfuscateAssemblyAttribute documentation on Microsoft Docs.
Namespace: System.Reflection or PreEmptive.Dotfuscator.ObfuscationAttributes
Applies to: Assembly
Multiple allowed on one code element: No
Requirements:
- For Dotfuscator to recognize uses of this attribute and obfuscate accordingly, the Honor obfuscation attributes input option for the input assembly that contains this attribute must be enabled, which it is by default.
- For Dotfuscator to remove uses of this attribute from the protected assembly, at least one of the following must be true:
- The Strip obfuscation attributes input option for the input assembly that contains this attribute must be enabled, which it is by default; or,
- The StripAfterObfuscation property of the attribute must be true, which it is by default.
Properties:
-
AssemblyIsPrivate: If true, Dotfuscator will consider the assembly to be a non-library assembly, and therefore obfuscate more aggressively. If false, Dotfuscator will consider the assembly to be a library assembly, and therefore preserve the public contract of the assembly.
- Defaults to false.
-
StripAfterObfuscation: If true, Dotfuscator will remove this attribute usage from the output assembly.
- Defaults to true.
- Dotfuscator will always strip all attribute usages from an input assembly, regardless of this property, when Strip obfuscation attributes setting input option is enabled, which it is by default.