yck1509 / ConfuserEx

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

How to exclude public API from obfuscation? #457

Open whitetown opened 8 years ago

whitetown commented 8 years ago

I have the following structure of the application. It is much complex in reality.

namespase Reader
{
    static class ReaderProgram
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ReaderForm());
            //ReaderForm uses some internal functions
        }
    }

    public class ReaderAPI
    {
        public Encoding e;

        public void DoSomething(String filename)
        {
            //ReaderAPI uses some internal functions
        }
    }
}

I would like to protect ReaderProgram but allows the user to use ReaderAPI:

ReaderAPI api = new ReaderAPI()
api.e = ...
api.DoSomething("filename.txt");

Could you help me with Obfuscation attributes, please?

yck1509 commented 8 years ago

Hi, You can try to set the renPublic parameter of name protection to false.

whitetown commented 8 years ago

Unfortunately I get the following error:

System.IO.FileNotFoundException: Could not load file or assembly 'koi' or one of its dependencies. The system cannot find the file specified. File name: 'koi' ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) at testAPI.Form1.button1_Click(Object sender, EventArgs e)

I have tried to insert the following directives:

[assembly: Obfuscation(Exclude = false, Feature = "namespace('Reader'):-rename")] namespace Reader

[ObfuscationAttribute(Exclude = false, Feature = "-rename")]
public class ReaderAPI

I have no idea what is 'koi'. I have tried both confuser.exe and confuser.cli.exe

finally I have tried to switch off the option [ ] compressor in this case I can use API but I also see that a whole .exe is unprotected. I could decompile it.