Babel Obfuscator
HomeDocumentationShop
  • Introduction
    • General Features
  • Getting Started
    • Install
    • Product Activation
  • Command Line
    • Command Line Reference
      • Miscellaneous
      • Input Files
      • Output Files
      • Plugins
      • Merge and Embed
      • Renaming
      • Control Flow Obfuscation
      • Encryption and Protection
      • Code Generation
  • MSBuild Task
    • Babel Task Reference
    • Customizing Intellisense
  • NuGet Package
    • NuGet Pakage Reference
  • User Interface
    • Obfuscation
    • Tools
    • Custom Themes
  • Obfuscation Rules
    • XML Rules
      • Example Rules
    • Custom Attributes
    • Obfuscation Agent
  • Merge and Embed
    • Assembly Merging
    • Assembly Embedding
  • Symbols Renaming
    • XML Map Files
    • Cross Assembly Renaming
    • XAML Renaming
    • Decoding Stack Traces
  • String Encryption
    • Custom String Encryption
  • Control Flow Obfuscation
  • Code Encryption
    • External Code Files
    • Password Protected Code
    • Dynamic Code
  • Dynamic Proxy
  • Resource Encryption
  • Value And Array Encryption
  • Tampering Detection
  • Anti Debugging
  • Enhancing Code Security
  • Optimizations
    • Dead Code Removal
    • Metadata Optimizations
    • Code Optimizations
  • Appendix
  • Examples
    • Examples
    • General Samples
      • ClickOnce Deploy
      • Detecting Babel Obfuscation
      • Obfuscate .NET MAUI
      • Blazor Web App
    • Code Encryption
      • Feature Based Licenses
    • Cross Assembly Renaming
      • Publish .NET App
    • Build Servers
      • GitHub Actions
      • Unit Tests
    • Babel Obfuscator NuGet
      • Android Application
  • Plugins
    • Babel Obfuscator Plugins
    • Encrypt Plugin
      • Getting Started
      • Source Code
Powered by GitBook
On this page
  • The ObfuscateAssembly Attribute
  • The Obfuscation Attribute
  • Extended Feature Syntax

Was this helpful?

  1. Obfuscation Rules

Custom Attributes

Last updated 1 year ago

Was this helpful?

Babel supports declarative obfuscation using the custom attributes and provided by the .NET Framework and .NET.

The ObfuscateAssembly Attribute

The System.Reflection.ObfuscateAssemblyAttribute, is an assembly-level attribute that instructs Babel Obfuscator to use obfuscation rules reserved for private assemblies.

A private assembly is an assembly that will not be used as a library: no other software components will use the assembly. Babel fully obfuscates private assemblies, which will rename all public symbols.

[assembly: ObfuscateAssembly(true)]

The Boolean constructor argument assemblyIsPrivate=true tells Babel that the assembly is used within the scope of one application and the public interface can be safely renamed.

The Obfuscation Attribute

The System.Reflection.ObfuscationAttribute attribute can be used on assembly members like types, methods, events, properties and fields to configure the action taken for a specific obfuscation feature.

The Obfuscation attribute has the following properties:

Feature

The Feature property maps a string value to a specific obfuscator feature or a list of features. The default value for the Feature property is “all”.

Babel uses “all” to map the complete set of available features. and “default” to map the renaming feature.

Please refer to the obfuscation to know more.

Exclude

Indicates whether the obfuscation feature should be excluded for the associated member.

ApplyToMembers

Specifies whether the action taken by the obfuscator for the associated type should be applied to all its members.

StripAfterObfuscation

Specifies whether the attribute should be removed after processing.

The following code example shows how ObfuscationAttribute can be used to target a method to enable code encryption:

[Obfuscation(Feature="msil encryption", Exclude=false)]
public string DoSomething()
{

Extended Feature Syntax

Babel Obfuscator supports an extended syntax for feature strings that will allow setting feature properties as a list of key-value pairs after the name of each feature.

[Obfuscation(Feature="msil encryption:source=opt;cache=true", Exclude=false)]#

The extended Feature syntax will allow setting the ObfuscationAttribute at the assembly level to configure features for the entire assembly:

Renaming

[assembly: Obfuscation(Feature="renaming:flatten namespaces=ACME.Test.*", Exclude=false)]
[assembly: Obfuscation(Feature="renaming:flattenNamespaces=ACME.Data.*", Exclude=false)]
[assembly: Obfuscation(Feature="renaming:internalize=true;rename parameters=true", Exclude=false)]
[assembly: Obfuscation(Feature="renaming:overloaded=true;unicode=false", Exclude=false)]
[assembly: Obfuscation(Feature="renaming:name length=5;name prefix=Acme_", Exclude=false)]

Obfuscation Agent

Disable the obfuscation Agent for Serializable types and Reflected enum tasks.

[assembly: Obfuscation(Feature="agent:tasknamelist=Serializable types,Reflected enums", Exclude=true)]

Value Encryption

Encrypts values and arrays of methods having several instructions between 10 and 100.

[assembly: Obfuscation(Feature="value encryption:min instruction count=10; max instruction count=100", Exclude=false)]

The Obfuscation attribute alone is not sufficient to activate the chosen feature. The attribute can only function if the feature is globally enabled in the configuration.

Other Examples

Do not obfuscate compiler-generated code.

[assembly: Obfuscation(Feature="all:compilergenerated=true", Exclude=true)]

System.Reflection.ObfuscationAttribute
System.Reflection.ObfuscateAssemblyAttribute
feature table