Search code examples
c#.netobfuscationeazfuscator

Disable "Constant Literals Pruning" in Eazfuscator.NET


I would like to disable "Constant Literals Pruning" in Eazfuscator.NET (assembly level). How is this possible?

Background: We use enums in a custom attribute constructor. The type of constructor parameter is object, because the attribute class is in an assembly that doesn’t reference the assembly containing the enum.

Before obfuscation:

[MyAttribute(MyEnum.Value3)]
public class MyClass
{

}

After obfuscation (decompiled):

[MyAttribute(2)]
public class MyAttribute : Attribute
{

}

In the constructor of the attribute I cast the value to Enum. This generates an exception in the obfuscated assembly, but not in the unobfuscated variant:

public class MyAttribute : Attribute
{
    public MyAttribute(object value)
    {
       var x = (Enum) value;    // this throws an InvalidCastException after obfuscation
    }
}

Solution

  • This is how you can disable stripping/pruning of the enum literals with Eazfuscator.NET:

    [Obfuscation(Feature = "enum values pruning", Exclude = true)]
    enum SampleEnum
    {
        None,
        Digit1,
        Digit2
    }