Reflection and Dynamic Class Loading

Reflection and dynamic class loading are extremely powerful tools in the .NET architecture. This level of runtime program customization prevents Dotfuscator from infallibly determining whether it is safe to rename all types loaded into a given program.

Consider the following (C#) code fragment:

public object GetNewType() { 
   Type type = Type.GetType( GetUserInputString(), true ); 
   object newInstance = Activator.CreateInstance( type ); 
   return newInstance; 
} 

This code loads a type by name and dynamically instantiates it. In addition, the name is coming from a string input by the user! (Or a runtime database, or another program, etc.)

There is obviously no way for Dotfuscator to predict which type names the user will enter. The solution is to exclude the names of all potentially loadable types (note that method and field renaming can still be performed). This is where manual user configuration (and some knowledge of the application being Dotfuscated) plays an important role.

Often the situation is less serious. Consider a slight variation:

public MyInterface GetNewType() { 
   Type type = Type.GetType( GetUserInputString(), true ); 
   object newInstance = Activator.CreateInstance( type ); 
   return newInstance as MyInterface; 
} 

Now it is immediately obvious that only a subset of types need to be excluded: those implementing MyInterface.

© 2002-2007 PreEmptive Solutions. All rights reserved.