Assembly obfuscation and reflection

I want to obfuscate my build files (* .dll, * .exe) using Dotfuscator . my question is: if I do this, can I still use the classes and types that are in these assemblies by their original names (I mean the names before obfuscation) and using the System.Reflection methods to work with them?

If you need more details, please tell me.

+7
source share
4 answers

Obfuscation - reflection, may cause some problems. Even if you accept the suggestion to use the option so as not to obfuscate the public method, some of the reflected code may call a private method. The problem is that obfuscation will change the name of some code that you may need to keep it the same.

If you know or can find a region that can be used with reflection, you can use

 [global::System.Reflection.Obfuscation(Exclude=true, Feature="renaming")] 

This will mean that the obfuscator will keep the name.

Performing obfuscation with reflection requires more testing, which is for sure, but still possible ...

+8
source

Read, for example, here http://msdn.microsoft.com/en-us/library/ms227298(v=vs.80).aspx There is a "library mode" to disable public member obfuscation. Another that you probably will not be able to access the methods. There is an attribute for controlling obfuscation at the level level: http://msdn.microsoft.com/en-us/library/ms227281(v=vs.80).aspx

+2
source

You can use System.Reflection on an obfuscation assembly, but since some of the obfuscation is to rename everything in the assembly into random and meaningless things, you cannot reflect the same names and identifiers as you do in non-obfuscation of the assembly. If you want to think about obfuscating the assembly, you will need to do it so that it does not depend on what names and types are named.

+1
source

You can create your own map to get new names from old ones. Mapper should write a sort table to disk / db with the following structure: Module (executable file), index, OriginalType, ObfuscatedType

Create a console application "Mapper" that works in two modes based on the argument: The application will receive the execution path as an argument

  • Assembly loading
  • GetTypes from loadedAssembly
  • PreObfuscation deletes all records and re-writes indexes and OriginalType values. PostObfuscation ObfuscatedType updates by index. Post-build events should be as follows:
    • Mapper.exe "target.exe" "Pre"
    • [Blackout]
    • Mapper.exe "target.exe" "Message"

Now you need a function for getObfuscatedName from OriginalName, and you're done.

Please note that this solution will not work with cropping, as the number of types will change and the indexes will no longer match between

 OriginalAssembly.GetTypes() 

and

 ObfuscatedAssembly.GetTypes() 
0
source

All Articles