Skip to main content
Version: 2023.3

4.5. Advanced Symbol Renaming Options

4.5.1. Symbol Renaming with Printable Characters

The symbol renaming algorithm uses unprintable Unicode characters by default. But sometimes, it may be beneficial to use printable ASCII characters instead. To do that, follow the instructions below.

Alternatively, you may prefer to use symbol encryption for the very same purpose.

Instructions on enabling printable characters for symbol renaming

  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 = "rename symbol names with printable characters", Exclude = false)]

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

    Imports System
    Imports System.Reflection

    <Assembly: Obfuscation(Feature:="rename symbol names with printable characters", Exclude:=False)>
Note

Please note that printable characters in symbol names can be controlled at the assembly level only. For example, it is impossible to use printable characters for some specific class or method; it is possible to do this just for a whole assembly.

4.5.2. Type Renaming Patterns

Eazfuscator.NET removes the namespaces of renamed types by default. This can lead to some issues when badly written code tries to get a renamed type's namespace via reflection.

For example, let's see what kind of flawed code can suffer from the absence of namespaces.

Example 4.22.  Example code that fails with NullReferenceException when the given type has no namespace

bool IsSystemDataType(Type type)
{
if (type != null && type.Namespace.StartsWith("System.Data"))
return true;
return false;
}

As you can see in the sample above, the method can fail with NullReferenceException when type.Namespace property returns null, indicating that the given type has no namespace. This issue can be easily fixed if you have access to the source code, but sometimes the flawed code comes from elsewhere.

To workaround possible problems, a custom type renaming pattern can be defined for an assembly, for a type or a group of types. The examples below show the possible definitions.

Example 4.23. Add 'b' namespace to all renamed types in assembly

using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "type renaming pattern 'b'.*", Exclude = false)]

Example 4.24. Add 'b' namespace to a class

using System;
using System.Reflection;

namespace App
{
[Obfuscation(Feature = "type renaming pattern 'b'.*", Exclude = false)]
class Class1
{
...
}
}

Example 4.25. Add 'b' namespace to a group of renamed classes. All classes with 'Impl' name ending are affected

using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "apply to type *Impl: type renaming pattern 'b'.*", Exclude = false)]
Tip

Of course, you are free to choose any namespace in a pattern.