Dotfuscator User's Guide
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:

C# Code Fragment:
Copy Code
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!

There is no way for Dotfuscator to predict which type names the user will enter. The solution is to configure Dotfuscator 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 plays an important role.

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

C# Code Fragment Variation:
Copy Code
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.

 

 


© 2016 PreEmptive Solutions, LLC. All Rights Reserved.

www.preemptive.com