Red Gate forums :: View topic - Broken obfuscated assembly using 'dynamic' keyword in .NET 4
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 5
SmartAssembly 5 forum

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

Search in SmartAssembly 5 forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
ravila



Joined: 20 Aug 2010
Posts: 2

PostPosted: Wed Aug 25, 2010 11:39 pm    Post subject: Broken obfuscated assembly using 'dynamic' keyword in .NET 4 Reply with quote

In my code I have a method like this:

Code:
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:
/* ... */

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:
/* ... */

FooBarBase tmp = specificFoo; // SmartAssembly broke stuff! Boo!
Baz(tmp);

/* ... */



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

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)
Back to top
View user's profile Send private message
Alex.Davies



Joined: 02 Dec 2008
Posts: 335
Location: Cambridge, uk

PostPosted: Thu Aug 26, 2010 11:38 am    Post subject: Reply with quote

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.
_________________
Alex
Developer,
Red Gate .NET Tools
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group