views:

49

answers:

2

My employer uses Dotfuscator on all our .Net production software. Because of this, we are absolutely forbidden to use ANY built-in databinding or anything that reflects on property/function names - because dotfuscator changes them and therefore anything bound instantly and irredeemably breaks.

I keep rolling this logic over in my mind and it's starting to hurt. There must be a way of avoiding this deadlock, it's too wide-ranging and fundamental a problem to not have an obvious solution that has escaped us.

So, how does one do Reflection with Obfuscation? What's the trick? Presumably there must be commercial obfuscators which are intelligent enough to work around the problem. What are the options for our version (which is fairly stupid)?

A: 

It's the job of an obfuscator to break down relationships that are visible in the source code so that they are no longer apparent in the resulting executable code. Reflection relies on relationships such as “the property requested by this piece of code is the one defined by that piece of code”. So it's not surprising that obfuscation and reflection don't play well with each other.

Renaming properties is just degree zero of obfuscation. A nontrivial obfuscator will also do things like split a property in two, so that where the source code only mentions a property P, some of the runtime code will use P1, and some of the runtime code will use P2, and there will be enough assignments between them so that the properties have the right value when needed, but also parasitic assignments so that they won't have the right value when they're not needed. It's not just that P has been renamed: there no longer is a property P.

I don't know why you think that reflection plus obfuscation is “wide-ranging and fundamental”: both reflection and obfuscation are fairly rare in the grand scheme of programming, and there's no correlation between their use, so I don't think many people are trying to have both.

The lack of reflection to be just one item in the long list of things that obfuscation costs you. If the person who decided to use obfuscation is not a security maven, try to hammer it into them that obfuscation has a very high cost which they are sure to have underevaluated.

Gilles
I suppose I am being quite .Net-centric - which works for our business as we develop on .Net. The lead developer is absolutely insistent that we must obfuscate everything; he's difficult to persuade at the best of times and this opinion in particular is one he sticks to like a limpet. As I see it, binding is indispensible whenever you want to use an MVC architecture and this precludes its use. I feel we're shooting ourselves in the foot, but I recognise the arguments for obfuscation. It would take a change in business culture to accept the inevitability of others decompiling our applications.
Tom W
+1  A: 

We have made a number of improvements to Dotfuscator that should help alleviate issues related to databinding. Smart Obfuscation functionality was added in the 4.3.100 version in March 2008 to statically analyze assemblies and automatically exclude items from renaming/removal that are known to cause runtime errors. We have consistently expanded and enhanced this functionality and today's Dotfuscator works around standard data binding scenarios with usually no to minimal extra configuration.

Even if Smart Obfuscation does not catch every one of your scenarios it is very easy to define custom rules to exclude properties of certain types or inheritance hierarchies by using custom exclusion rules (including matching types by RegEx patterns). You can also decorate items with the System.Reflection.ObfuscationAttribute attribute to ensure that they will be excluded from renaming or removal when run through Dotfuscator.

If you are binding from XAML markup to types in codebehind the last few releases have supported renaming the XAML/BAML to match the code behind. This improves overall hardening and also eliminates an entire range of issues when symbols in the markup do not match the code definitions.

I would recommend working up a few simple proof of concept applications using databinding similar to what you want to use in your applications and running those through Dotfuscator to see how well it handles them. If you find any scenarios where Smart Obfuscation is not automatically excluding targets of data binding send them on to [email protected] . We're always looking for well defined scenarios to improve the product.

Joe Kuemerle
Thanks Joe, that's really helpful. I now feel a little sheepish for several reasons: i) I included a minor swipe at Dotfuscator in my initial post, which I regret; ii) we appear to be using a very old version (I forget which, but it doesn't do the things you've mentioned) and iii) although I'm complaining about it, it isn't my call, and I've been thus far unable to persuade my colleague in charge of this area to adopt anything new or change his tactics in any way.
Tom W
As an addendum; am I safe to presume that 4.3 Community Edition includes this functionality, and it isn't a pay-only feature? Persuading management to part with cash is never straightforward.
Tom W
Even without Smart Obfuscation you are able to create custom exclusion rules (including RegEx matches) from version 1.0 on. It is a bit of manual work but is certainly possible. Smart Obfuscation in the free version of Dotfuscator is available in version 5.0 that shipped with Visual Studio 2010.
Joe Kuemerle
Thank you for taking the time to provide such detailed answers - it's really reassuring that the people who build the tools we use every day are listening. Clearly SO is the place to be. The problem really stems from my colleagues' ignorance of the features available, and my trust in their abilities. The method you mention of using **ObfuscationAttribute** is more than adequate for our needs, but nobody knew about it.
Tom W