What is the best method to find a class/property in c# through reflection after obfuscation has been done?

StackOverflow https://stackoverflow.com/questions/7973128

Question

Here's an example of the code which will be used for the reflection:

var i = typeof(Program).Assembly.CreateInstance("test.Program");

After the software is obfuscated, the code will obviously stop working.

I'm trying to find a way around it by searching for properties of a class, which do not change after obfuscation has been done. I've tried that with type.GUID, but when I run the debug version, I get one GUID, and in the release after the obfuscation is completed, the guid is changed.

I'm using Eazfuscator.NET for obfuscation.

I would like to avoid using attributes to mark class/method if possible.

Any ideas on what would work?

Was it helpful?

Solution

don't want the obfuscator to defeat the attackers. Just make the job of understanding the code more difficult. And I want this as a part of advanced piracy protection

After obfuscation; zip, encrypt and do whatever you want with your assembly. Then create another wrapper project and add your assembly as a resource into that project. Attach to AppDomain.CurrentDomain.AssemblyResolve event (in your new project) and whenever an unresolved assembly event occurs, read your resource(decrypt,unzip etc.) and return the actual assembly.

You may also try to obfuscate your final wrapper application.

How secure? At least, you can make life more harder for attackers.

OTHER TIPS

I'm sure there are ways to iterate over all types and find the one you're looking for, but the things that come to mind would all produce the least maintainable code ever.

Some obfuscators (we use DeepSea, I don't know Eazfuscator) allow preventing obfuscation of specific classes, allowing reflection on those. In DeepSea's case, this is indicated by attributes but those won't/shouldn't (I never checked :o) make it to the final assembly.

If you regard reflection as "an outside process looking at your assembly" and obfuscating "preventing outside processes from looking at your assembly" you're really stopping yourself from doing what you want to do.

I don't have exact answer, but ILSpy's source might help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top