Assemblies Embedding

Eazfuscator.NET

Assemblies Embedding

Introduction

What's the point for embedding when we have merging (or vice versa)?

Instructions

To enable assemblies embedding you should apply specially formed attribute(s) to your assembly. In order to do that you can use the instructions below.
  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. using System;
    using System.Reflection;
    
    [assembly: Obfuscation(Feature = "embed XXXXXX.dll", Exclude = false)]
    Imports System
    Imports System.Reflection
    
    <Assembly: Obfuscation(Feature:="embed XXXXXX.dll", Exclude:=False)> 
    
    [Note]Note
    [Important]Important
    [Tip]Tip
    [assembly: Obfuscation(Feature = @"embed $(InputDir)\Lib\AssemblyToEmbed.dll", Exclude = false)]
    [Tip]Tip
    [assembly: Obfuscation(Feature = "embed Assembly1.dll", Exclude = false)]
    [assembly: Obfuscation(Feature = "embed AnotherAssembly2.dll", Exclude = false)]
    

Tuning

[assembly: Obfuscation(Feature = "embed [flags] XXXXXX.dll", Exclude = false)]
Flag Description
no_compress Disables the compression
no_encrypt Disables the encryption
no_satellites Disables automatic embedding of satellite assemblies
load_from_file Instructs Eazfuscator.NET to load the embedded assembly from file instead of memory during the obfuscated assembly run-time. This can be used to preserve a meaningful value of Location property from System.Reflection.Assembly type.
immediate_load Instructs Eazfuscator.NET to load the embedded assembly immediately on a module start. This may be required to satisfy the technologies that rely on a custom assembly resolution mechanism. An example of such technology is WPF which uses XmlnsDefinitionAttribute to locate the assemblies at runtime. Please note that Eazfuscator.NET automatically detects the most of affected technologies and applies the flag automatically when required.
using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "embed [no_compress no_encrypt] XXXXXX.dll", Exclude = false)]
using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "embed [no_encrypt] XXXXXX.dll", Exclude = false)]
using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "embed XXXXXX.dll", Exclude = false)]
using System;
using System.Reflection;

[assembly: Obfuscation(Feature = "embed satellites", Exclude = false)]

Troubleshooting

While assembly embedding is the most non-intrusive way to link the assembly, some rare issues may occur. Possible issues are described in this chapter together with corresponding solutions to avoid them.

Possible Issue #1: Location Property of System.Reflection.Assembly Class

using System;

class Program
{
    static string GetEulaPath()
    {
        var assembly = typeof(Program).Assembly;
        // string location = assembly.Location; // Please do not use this. This is a flawed approach
        string location = new Uri(assembly.EscapedCodeBase).LocalPath; // <-- Use this instead
        return Path.Combine(Path.GetDirectoryName(location), "EULA.rtf");
    }
}

Possible Issue #2: Custom Assembly Loading