Obfuscation problem.

Obfuscation problem.

Old forum URL: forums.lhotka.net/forums/t/12054.aspx


sash_kr posted on Tuesday, July 02, 2013

CSLA.NET 4.5.30

 

After obfuscation my application doesn't work:

System.Reflection.AmbiguousMatchException: Ambiguous match found.
    at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
    at System.Type.GetProperty(String name)
    at Csla.Core.FieldManager.DefaultPropertyInfoFactory.GetFriendlyNameFromAttributes(Type type, String name)
    at Csla.Core.FieldManager.DefaultPropertyInfoFactory.Create[T](Type containingType, String name)
    at Csla.BusinessBase`1.RegisterProperty[P](Expression`1 propertyLambdaExpression)
    at ...cctor()

 

That's because obfuscator renaming  properties using the same name.

So, I propose  to add few methods to "IPropertyInfoFactory":

   Csla.PropertyInfo<T> Create<T>(Type containingType, PropertyInfo propertyInfo);

   ... etc.

 

And methods to "DefaultPropertyInfoFactory":

   private static string GetFriendlyNameFromAttributes(PropertyInfo propertyInfo )

   ... etc.

 

 

 

JonnyBee replied on Wednesday, July 03, 2013

Hi,

So obfuscating your business objects makes all the properties have the same name?
Which Obfuscator do you use?
This would likely break all your databinding or what - if the properties have the same name?

And is your suggestion to add System.Reflection.PropertyInfo as parameter to these method?

So my recommendation is to either:

1. NOT use PropertyInfoFactory and use other methods in the business object base classes to register PropertyInfo::

 protected static PropertyInfo<P> RegisterProperty<P>(Type objectType, PropertyInfo<P> info)

This will register a PropertyInfo that YOUR code has create itself.

2. Create your own PropertyInfoFactory.

The other solution is that you create your own PropertyInfoFactory as this is an extension point in CSLA where you can configure CSLA to use your OWN PropertyInfoFactory and do whatever is necessary for your application to work as you expect. You could even create your own new version of RegisterPropertNew and call other methods in YOUR PropertyInfoFactory that accepts a PropertyInfo as parameter.

RockfordLhotka replied on Wednesday, July 03, 2013

Most obfuscation programs have a way to mark certain properties/methods so they aren't renamed. There's no value in obfuscating the standard DataPortal_XYZ method names, so it is probably best to just prevent the tool from renaming those methods.

sash_kr replied on Wednesday, July 03, 2013

Thanks for reply.

I am new to CSLA. I'm learning CSLA and trying convert my existence project.

I always use obfuscation and love full obfuscation (cross-obfuscation) of private, protected and even public methods and properties. For now my obfuscation tool is "Spices.Net Obfuscator" (presented Gift by the developer for assistance improved their product Smile).

 "This would likely break all your databinding"  - I forgot about thisSad.  I didn't have the problems with databinding because of using DataTable. I should think about it.

 

Thanks!

 

By the way,  "Spices.Net Obfuscator"  has option "Use unique name" but unfortunately it works only on single class. Derived class properties could be renamed with the same names as in base class.

sash_kr replied on Wednesday, July 03, 2013

I've just found an interesting project - "Truss" (http://truss.codeplex.com/)

It seems it's custom realization of databinding which supports any UI technology and It's working with "Expression", not only with strings. So I could bind properties with same name Smile. But it has one disadvantage: no designer support. Any way, if you're obfuscating code you should do manual binding.

Copyright (c) Marimer LLC