Skip to main content

Using Eazfuscator.NET for Restricted Target Platforms

Article ID: KB100032Published: September 21, 2014

Synopsis

Eazfuscator.NET may inject additional code into protected assemblies during obfuscation. The injected code belongs to a so called Eazfuscator.NET Runtime module. It is used to support such features as string encryption, assembly embedding, and others during run time. At the same time, some system suppliers may impose restrictions on what .NET types and APIs are available in their environments. For example, a particular embedded system supplier may limit .NET API surface available on their devices due to computational or security constraints.

Eazfuscator.NET automatically detects the target platform and shapes its runtime module to meet the platform API requirements. However, there is a large diversity of target platforms based on .NET: various embedded systems, hobby projects atop .NET Micro Framework, in-house .NET platform implementations, etc. That is why Eazfuscator.NET may require additional knowledge about a particular target platform.

Here is a sample error dump that you may get while trying to deploy the assembly obfuscated with Eazfuscator.NET to a restricted target platform:

Error 1    Invalid Reference 'System.Windows.Forms.dll'
Error 2 'System.Reflection.Assembly' referenced in [1]::[1]() is not allowed in Crestron's sandbox.
Error 3 'System.Reflection.AssemblyName' referenced in [1]::[1]() is not allowed in Crestron's sandbox.
Error 4 'System.Windows.Forms.DialogResult' referenced in [1]::[1]() is not allowed in Crestron's sandbox.
Error 5 'System.Reflection.MethodBase' referenced in  ::.cctor() is not allowed in Crestron's sandbox.
Error 6 'System.IO.Stream' referenced in  ::[1](System.Int32) is not allowed in Crestron's sandbox.

The solution to this problem is to provide a custom Eazfuscator.NET configuration for the particular .NET target platform.

Target Platform API Configuration

Eazfuscator.NET is configured by obfuscation attributes in your source code. If your target platform does not implement a particular .NET API then you can instruct Eazfuscator.NET to avoid using it:

using System.Reflection;

[assembly: Obfuscation(Feature = "platform api: [type name 1], [type name 2], ..., [type name N]", Exclude = true)]

Eazfuscator.NET will then fall back to a more simple and generic talk with a .NET platform. In this way, Eazfuscator.NET will be able to produce obfuscated assemblies that can be successfully consumed by your target platform. Type name masks are also supported:

[assembly: Obfuscation(Feature = "platform api: System.Reflection.*, System.IO.Stream, System.Windows.Forms.*", Exclude = true)]

For example, System.Reflection.* mask matches all types defined in System.Reflection namespace; they will not be used by Eazfuscator.NET runtime code.

Instructions

Please follow the instructions below to apply a corresponding configuration to your project:

  1. Locate the project of interest in Solution Explorer window of Microsoft Visual Studio:

    Project in Solution Explorer

  2. Add a new ObfuscationSettings.cs (or .vb) file to your project or use the existing one if you already have it:

    ObfuscationSettings.cs file

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

    using System.Reflection;

    [assembly: Obfuscation(Feature = "platform api: System.Reflection.*, System.IO.Stream, System.Windows.Forms.*", Exclude = true)]

    Please ensure that the excluded platform API matches your particular target platform. The given example is a typical configuration for Crestron's sandbox.

Applicability

This article applies to:

  • Eazfuscator.NET 4.6 or higher. Earlier versions do not support platform api directive