4.5. Advanced Symbol Renaming Options
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
-
Open obfuscatable project inside the IDE
-
Add new source file to the project and call it
ObfuscationSettings.cs
(for C#) orObfuscationSettings.vb
(for Visual Basic .NET). You may prefer to use another name instead ofObfuscationSettings.cs
orObfuscationSettings.vb
-
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)>
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.
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)]
Of course, you are free to choose any namespace in a pattern.