Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Declarative Obfuscation

Ki edited this page Nov 1, 2016 · 1 revision

Since v0.4, ConfuserEx supports declarative obfuscation. You can use System.Reflection.ObfuscationAttribute to instruct ConfuserEx how to protect your application.

Currently, declarative obfuscation is only supported through the Command Line Interface(Confuser.CLI.exe), by either passing the files to protect as arguments, or simply drag-and-drop the files on Confuser.CLI.exe .

Item Hierarchy

Internally, ConfuserEx will construct a hierarchy tree for different items in order to determine how the attributes will be applied.

Module
  |
  ----- Namespace
           |
           ----- Type
                  |
                  |----- Nested Types
                  |         |
                  |         - ....
                  |------ Methods
                  |------ Fields
                  |------ Properties
                  |------ Events

This hierarchy will affect ApplyToMembers property.

Usage

The following code snippet demostrates all syntax of declarative obfuscation ConfuserEx currently supports:

[assembly: Obfuscation(Exclude = false, Feature = "generate debug symbol: true")]
[assembly: Obfuscation(Exclude = false, Feature = "random seed: Hello!")]
[assembly: Obfuscation(Exclude = false, Feature = "strong name key:C:\\key.pfx")]
[assembly: Obfuscation(Exclude = false, Feature = "strong name key password:hunter2")]

[assembly: Obfuscation(Exclude = false, Feature = "packer:compressor(key=dynamic)")]
[assembly: Obfuscation(Exclude = false, Feature = "preset(minimum);+ctrl flow;-anti debug;+rename(mode=letters,flatten=false);")]

[assembly: Obfuscation(Exclude = false, Feature = "namespace('Test'):-rename")]
[assembly: Obfuscation(Exclude = false, Feature = "namespace('LibraryA.Test'):+rename")]
[assembly: Obfuscation(Exclude = false, Feature = "external module:LibraryB.dll")]
namespace Test {

    [Obfuscation(Exclude = false, Feature = "constants")]
    class Program {
    
        public static void Main() {
            Console.WriteLine("Hi");
        }
    }
}