Broken obfuscated assembly using 'dynamic' keyword in .NET 4

.NET obfuscator and automated error reporting

Broken obfuscated assembly using 'dynamic' keyword in .NET 4

Postby ravila » Wed Aug 25, 2010 10:39 pm

In my code I have a method like this:

Code: Select all
GlobalFooBar m_GlobalFooBarObj = /* ... */;
private static void Baz(FooBarBase foo)
   PropertyInfo[] properties = typeof(GlobalFooBar).GetProperties
      (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

   /* ... */

   foreach (PropertyInfo property in properties)
      if (property.CanWrite) // We only want writable properties copied over
         property.SetValue(foo, property.GetValue(m_GlobalFooBarObj, null), null);
   /* ... */

I call this method as follows:

Code: Select all
/* ... */

dynamic specificFoo = mumbler.MakeSpecificFooBar();

/* ... */

Baz(specificFoo); // Crash here

/* ... */

After obfuscating my program with SmartAssembly, I get a RuntimeBinderException stating that the .NET runtime cannot find the "Baz" method in my assembly. Of course it can't, because SmartAssembly renamed it. Excluding the method is not an option for me because it would disclose too much about the inner workings of my program.

My workaround goes like this:

Code: Select all
/* ... */

FooBarBase tmp = specificFoo; // SmartAssembly broke stuff! Boo!

/* ... */

This works, but we didn't buy SmartAssembly to work around its bugs. :(

Are problems with the 'dynamic' keyword and SmartAssembly known? If so, is a fix planned?

I'm not too keen on keeping this workaround in the codebase.

(Edit: anonymized the code a bit more and fixed a typo)
Posts: 2
Joined: Fri Aug 20, 2010 11:39 am

Postby Alex.Davies » Thu Aug 26, 2010 10:38 am

In the same way as reflection, use of the dynamic keyword in c# doesn't mix well with obfuscation.

The only options, as you say, are:
- excluding the affected method from obfuscation
- avoiding calling obfuscatable methods on the dynamic variables
I don't believe it's possible for any obfuscator to allow you to use dynamic variables.
Red Gate .NET Tools
Posts: 335
Joined: Tue Dec 02, 2008 11:23 am
Location: Cambridge, uk

Return to SmartAssembly 5

Who is online

Users browsing this forum: No registered users and 0 guests