Skip to main content
Version: 2023.4

4.7. Code Control Flow Obfuscation

Code control flow obfuscation allows making IL code more entangled. Decompilers often crash on such code so that the code may be considered as much better protected.

By default, the code control flow obfuscation feature is not used during the obfuscation of the assembly.

To enable the code control flow obfuscation feature, you should apply a specially formed attribute to your assembly. To do that, you can use the instructions below.

Instructions on enabling control flow obfuscation

  1. Open obfuscatable project inside the IDE

  2. Add new source file to the project and call it ObfuscationSettings.cs (for C#) or ObfuscationSettings.vb (for Visual Basic .NET). You may prefer to use another name instead of ObfuscationSettings.cs or ObfuscationSettings.vb

  3. Fill ObfuscationSettings.cs with the following content (C#):

    using System;
    using System.Reflection;

    [assembly: Obfuscation(Feature = "code control flow obfuscation", Exclude = false)]

    For Visual Basic .NET, fill ObfuscationSettings.vb with the following content:

    Imports System
    Imports System.Reflection

    <Assembly: Obfuscation(Feature:="code control flow obfuscation", Exclude:=False)>

Applying Control Flow Obfuscation to Selected Methods

You can enable control flow obfuscation on individual or multiple methods, or override the global setting.

Examples are provided below.

Example 4.26. Enable control flow obfuscation for a specified method

using System;
using System.Reflection;

class YourClass
{
[Obfuscation(Feature = "code control flow obfuscation", Exclude = false)]
void YourMethod()
{
...
}
}

Example 4.27. Enable control flow obfuscation for all methods of a class

using System;
using System.Reflection;

[Obfuscation(Feature = "apply to member * when method or constructor: code control flow obfuscation", Exclude = false)]
class YourClass
{
...
}

Example 4.28. Disable control flow obfuscation on a class level by overriding the global setting

using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "code control flow obfuscation", Exclude = false)]

[Obfuscation(Feature = "apply to member * when method or constructor: code control flow obfuscation", Exclude = true)]
class YourClass
{
...
}