yck1509 / ConfuserEx

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

Errors After Confusing Executable #87

Closed Abystus closed 9 years ago

Abystus commented 9 years ago

Project Settings:

Environment: Visual Studio 2013 Framework: 4.5 Platform: x86 OS: Windows 8.1

Problem Description:

The application starts up correctly and can access the database, but when attempting to enter certain screens I either receive an error, or the underlying code isn't functioning. I've tried with a few different settings, but all of them outside of the "None" preset cause these issues (also tried changing the inherit option as well). Below are two examples of what I'm experiencing:

Example 1:

This seems to occur when late binding is used on a custom control (possibly any control?). This is a modified check box which allows 'Y' and 'N' to be used instead of true or false.

error1

Error:

************** Exception Text **************
System.ArgumentException: Cannot bind to the property 'YesNo' on the target control.
Parameter name: PropertyName
   at System.Windows.Forms.Binding.CheckBinding()
   at System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent value)
   at System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)
   at System.Windows.Forms.ControlBindingsCollection.Add(String propertyName, Object dataSource, String dataMember, Boolean formattingEnabled, DataSourceUpdateMode updateMode, Object nullValue, String formatString, IFormatProvider formatInfo)
   at System.Windows.Forms.ControlBindingsCollection.Add(String propertyName, Object dataSource, String dataMember)
   at ????????????????????????????????????????.???????????????????????????????????????(ControlBindingsCollection , String , Object , String )
   at ????????????????????????????????????????.???????????????????????????????????????(Object , EventArgs )
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Underlying Code:

Problem Code:

            //Databindings
            chkActive.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "ACTIVE_USER");
            chkWritAdmin.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "WRIT_ADMIN");
            chkWritView.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "WRIT_VIEW");
            chkPaymentAdmin.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "PAYMENT_ADMIN");
            chkPaymentView.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "PAYMENT_VIEW");
            chkSalesAdmin.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "SALES_ADMIN");
            chkSalesView.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "SALES_VIEW");
            chkServicesAdmin.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "SERVICE_ADMIN");
            chkServicesView.DataBindings.Add("YesNo", dsPreferences.CLEAR_USERS, "SERVICE_VIEW");

Control Code:

   class CustomCheckbox : CheckBox
    {
        public string YesNo
        {
            get 
            {
                return Checked ? "Y" : "N";
            }
            set 
            {
                var changed = false;
                if (value == "Y")
                {
                    if (!Checked)
                        changed = true;

                    Checked = true;

                    if (changed)
                        OnPropertyChanged("YesNo");
                }
                else
                {
                    if (Checked)
                        changed = true;

                    Checked = false;

                    if (changed)
                        OnPropertyChanged("YesNo");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
        protected override void OnCheckedChanged(EventArgs e)
        {
            OnPropertyChanged("YesNo");
            base.OnCheckedChanged(e);
        }
    }

Example 2:

I cannot show a picture of this, but I can provide the code that is not working:

Underlying Code:

Problem Code:

        private void tvWritBreakdown_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SelectTabPage(tabBreakdown, tvWritBreakdown.SelectedNode.Text);
        }

        public void SelectTabPage(CustomControls.CustomTabControl tc, string text)
        {
            //Look for tabpage based on tab matching text
            var tab = tc.TabPages.Cast<TabPage>()
                      .FirstOrDefault(t => t.Tag == text);

            //If not null, select tabpage
            if (tab != null)
                tc.SelectedTab = tab;
        }

Control Code:

    public partial class CustomTabControl : TabControl
    {
        public CustomTabControl()
        {
            InitializeComponent();
        }

        private const int TCM_ADJUSTRECT = 0x1328;

        protected override void WndProc(ref Message m)
        {
            // Hide the tab headers at run-time
            if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
            {
                m.Result = (IntPtr)1;
                return;
            }

            // call the base class implementation
            base.WndProc(ref m);
        }
    }

This code will select the appropriate tab page in a tab control based on a matching Tag value to the selected tree view node text. Basically, it's a tree view which controls the tab control (custom tab control which hides its headers). The code does not move the tab pages after the application is confused (I'd assume that tab is always null). No error occurs. Possibly a problem handling LINQ syntax?

Build Setting Output:

 [INFO] ConfuserEx v0.2.3 Copyright (C) Ki 2014
 [INFO] Running on Microsoft Windows NT 6.2.9200.0, .NET Framework v4.0.30319.34014, 64 bits
[DEBUG] Discovering plugins...
 [INFO] Discovered 10 protections, 1 packers.
[DEBUG] Resolving component dependency...
 [INFO] Loading input modules...
 [INFO] Loading 'CMS.exe'...
 [INFO] Initializing...
[DEBUG] Building pipeline...
 [INFO] Resolving dependencies...
[DEBUG] Checking Strong Name...
[DEBUG] Creating global .cctors...
[DEBUG] Watermarking...
[DEBUG] Executing 'Name analysis' phase...
[DEBUG] Building VTables & identifier list...
[DEBUG] Analyzing...
 [INFO] Processing module 'CMS.exe'...
[DEBUG] Executing 'Invalid metadata addition' phase...
[DEBUG] Executing 'Renaming' phase...
[DEBUG] Renaming...
[DEBUG] Executing 'Anti-debug injection' phase...
[DEBUG] Executing 'Anti-dump injection' phase...
[DEBUG] Executing 'Anti-ILDasm marking' phase...
[DEBUG] Executing 'Encoding reference proxies' phase...
[DEBUG] Executing 'Constant encryption helpers injection' phase...
[DEBUG] Executing 'Resource encryption helpers injection' phase...
[DEBUG] Executing 'Constants encoding' phase...
[DEBUG] Executing 'Anti-tamper helpers injection' phase...
[DEBUG] Executing 'Control flow mangling' phase...
[DEBUG] Executing 'Post-renaming' phase...
[DEBUG] Executing 'Anti-tamper metadata preparation' phase...
[DEBUG] Executing 'Packer info extraction' phase...
 [INFO] Writing module 'CMS.exe'...
[DEBUG] Encrypting resources...
 [INFO] Finalizing...
[DEBUG] Saving to 'C:\CSS\OtherProjects\CMS\CMS\bin\Debug\Confused\CMS.exe'...
 [INFO] Done.
Finished at 11:20 AM, 0:02 elapsed.
yck1509 commented 9 years ago

You have to exclude the "YesNo" property from renaming manually since ConfuserEx does not recognize this late-binding situation at the moment. In your second example, it's most probably some late-binding failed. If you don't mind sharing your binaries privately, please contact me at confuser.net@gmail.com and I'll help you to solve the issue.