Automatic Handling of Windows Forms Data Binding

Many users of Eazfuscator.NET use Windows Forms technology to build application UI. Windows Forms provides a set of controls that allows to display data and interact with a user. Sometimes, the displayed data is not set to UI controls directly. A common practice is to use a data binding mechanism that allows to tie the object properties by name. To get property values by name, data binding uses Reflection API.

Consider a simple code that creates a list of products:

class Product  
{
   public int ID { get; set; }
   public string Title { get; set; }
   public string Description { get; set; }
}

// …

var products = new List<Product>  
{
   new Product { ID = 1, Title = "Juice", Description = "Juice description" },
   new Product { ID = 2, Title = "Tea", Description = "Tea description" },
   new Product { ID = 3, Title = "Coffee", Description = "Coffee description" }
};

Let’s display the products in the ComboBox control by title:

productsComboBox.DisplayMember = "Title";  
productsComboBox.DataSource = products;  

That’s how it all works:

ComboBox uses Reflection API in order to display products by Title

But what happens if we obfuscate such code? During obfuscation, the names of classes and their members change. When renamed, the Title property is no more available for binding by its old name:

The Title property is obfuscated and cannot be found by Reflection API anymore

Before now, the workaround was to manually exclude the Title property from renaming using the ObfuscationAttribute:

using System.Reflection;

class Product  
{
   public int ID { get; set; }

   [Obfuscation] // <-- the obfuscation attribute excludes Title property from renaming
   public string Title { get; set; }

   public string Description { get; set; }
}

It looks simple, but in a real application with a large amount of data displayed, this can turn into a nightmare. That’s why we added out of the box coverage for this scenario in Eazfuscator.NET 2018.4. It features support for Windows Forms binding semantics by automatically tracking corresponding properties and preserving them during obfuscation:

The Title property is preserved and the binding works fine

Of course, all the other class members get completely obfuscated to the maximum possible extent.

Try Eazfuscator.NET now

comments powered by Disqus