yck1509 / ConfuserEx

An open-source, free protector for .NET applications
http://yck1509.github.io/ConfuserEx/
Other
3.57k stars 1.63k forks source link

ObfuscationAttribute(Exclude = true, ApplyToMembers = true)] ApplyToMembers not work! #525

Open jzq740176597 opened 8 years ago

jzq740176597 commented 8 years ago

- [ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]

- class ShowSize_InEditor : EditorWindow

- {
       //[ObfuscationAttribute(Exclude = false, Feature = "-rename")]
        void OnGUI()
        {}
    }

latest ConfuserEx_bin 1.0 version.

I use GUI version ,and apply just Rename Protection. And the class attribute not exclude the member fucntion OnGUI() from name obfuscate. Worked only when uncomment the specific attribute above the OnGUI() function ? is Bug? Any hint?

thanks !

Regards!

abdeldjalil-fellah commented 7 years ago

I confirm this behavior! [ObfuscationAttribute(Exclude = true, ApplyToMembers = true)] does not work as expected, it does not exclude class members! I'm using the GUI

olegolegoleg commented 7 years ago

Same problem with ConfuserEx v1.0.0. Previous release v0.6.0 was working without any problem

It's looks like latest version just ignore "ApplyToMembers" attribute. Is it a bug?

-> Example, source code:

[ObfuscationAttribute(Exclude = false, ApplyToMembers = true, Feature = "-rename")]
public partial class image
{
    private string alttxtField;
    private string image1Field;
    private string numberField;

    public string alttext
    {
        get { return this.alttxtField; }
        set { this.alttxtField = value; }
    }

    public string image1
    {
        get { return this.image1Field; }
        set { this.image1Field = value; }
    }

    public string number
    {
        get { return this.numberField; }
        set { this.numberField = value; }
    }
}

-> Generates (extracted with JustDecompile):

public class image
{
    private string alttextField;
    private string image1Field;
    private string numberField;

    //(!) - Incorrect name below:
    public string u202a‪‪‎‭​‪‎‬‮‎‫‎‮​‌‍‫‍‏‌‪‏‎‎‎‮‮‮‮
    {
        get { return this.image1Field; }
        set { this.image1Field = value; }
    }

    //(!) - Incorrect name below:
    public string u206b‌‬‫‎‍‫‫‍‮​‎‮‬​‬‭‭​‮‪‌‍‌‌‪‭​‎‮
    {
        get { return this.alttextField; }
        set { this.alttextField = value; }
    }

    //(!) - Incorrect name below:   ‎‭​​‍‮‍‮‭‪‍‭‍‬‬‌‏‮​‭‍​​‮‮‪‫‍
    public string u206a‎‭​​‍‮‍‮‭‪‍‭‍‬‬‌‏‮​‭‍​​‮‮‪‫‍‭
    {
        get { return this.numberField; }
        set { this.numberField = value; }
    }

    public image()
    {
    }
}

————————————————————————— It costs me half of day to figure out. I was using v0.6.0, but it suddenly stopped to work with different exceptions. It was old version, so I upgrades to latest v1.0.0 and it generated executable without any problem, nice

However… I generally tested generated executable and sent to the client, he told me that it do not work. It was strange, because it passed out all tests. I tested it again on my side (not obfuscated, with debugger) – all works fine again!

After few hours – the problem was located in XML schema with 16 classes, all accessors (get/set) was renamed, even with “ignore” attribute (see code above).

Previous v0.6.0 with "Feature = "-rename"" attribute skips whole schema, but new v.1.0.0 partially rename it anyway. Latest version ignore "ApplyToMembers = true" attribute too. I compiled project few times with/without “ApplyToMembers” and results is same, always. —————————————————————————

My temporary solution: I was needed to fix it asap, so I manually added: [ObfuscationAttribute(Exclude = false, ApplyToMembers = true, Feature = "-rename")] above each accessor (get/set).

catester commented 7 years ago

This is ridiculous, someone needs to fix this ObfuscationAttribute logic, it's a mess now. I am having the same problem as @olegolegoleg, with v0.6.0 we could simply add this to a top of the class:

[Obfuscation(Exclude = false, Feature = "-rename", ApplyToMembers = true)]

and the class name AND the public property members were excluded from renaming. Now with v1.0.0, it doesn't work i.e. public members are RENAMED so ApplyToMembers = true does not work.

And someone suggested this, which doesn't work either:

[assembly: Obfuscation(Exclude = false, Feature = "namespace('Foo.Bar') and member-type('type'):-rename")]

By the way, this expression syntax sucks, why would I need to repeat namespaces and shit in Feature I am already applying the attribute to a specific class. I can understand it would be useful for assembly level attributes but at least support class level useful attributes.

I waited for 6 months before upgrading to v1.0.0, but I guess it will never be fixed so I will use @olegolegoleg's same solution and put a separate attribute to each public property/method of the class:

[Obfuscation(Exclude = false, Feature = "-rename")]