How to avoid reflection errors when compiling C# assemblies using VMProtect?

Issues related to VMProtect
Post Reply
a7B9k3L2m8
Posts: 4
Joined: Fri Oct 11, 2024 10:00 am

How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by a7B9k3L2m8 »

Hi everyone, I'm having trouble protecting a C# assembly with VMProtect. The program uses some reflection techniques, and errors occur when it is run after protection. I tried adding the [global::System.Reflection.Obfuscation(Exclude=true, Feature="renaming")] attribute in some places, and this did solve some of the problems.

But I'm not sure if this is a universal solution for all cases, or if there is a simpler, more general approach that can be applied to a larger range of code. Does anyone have any experience or suggestions? Thank you very much!
Admin
Site Admin
Posts: 2686
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by Admin »

Send us an example (original EXE + VMP files) that shows your problem.
a7B9k3L2m8
Posts: 4
Joined: Fri Oct 11, 2024 10:00 am

Re: How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by a7B9k3L2m8 »

Hello, I am sorry for not replying to your message in time. I have been busy recently. Regarding the example you requested, I currently need some time to prepare. I will try to organize it within the next few days, but since I am also taking care of some other things, there is still a small probability that I may not be able to send it within a few days.
a7B9k3L2m8
Posts: 4
Joined: Fri Oct 11, 2024 10:00 am

Re: How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by a7B9k3L2m8 »

Hello, I have put the example you requested in the attachments, please check it.
Attachments
Test.zip
(533.38 KiB) Downloaded 597 times
Admin
Site Admin
Posts: 2686
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by Admin »

Just add ObfuscationAttribute before each class that you want to exclude from renaming:

Code: Select all

[Obfuscation(Exclude=true, Feature="renaming"]
class MyClass {
...
P.S. [assembly::Obfuscation(Exclude=true, Feature="renaming"] excludes ALL classes from renaming even when "Strip Debug Information" is ON.
a7B9k3L2m8
Posts: 4
Joined: Fri Oct 11, 2024 10:00 am

Re: How to avoid reflection errors when compiling C# assemblies using VMProtect?

Post by a7B9k3L2m8 »

So, when applying reflection to assemblies, namespaces, classes, properties, fields, methods, etc., can we ensure that they will not be affected by renaming obfuscation by using the corresponding Obfuscation attribute provided by C#? I want to know the general rules.
Post Reply