2

Im looking to how i can exclude a line of code in my project, but all i found is how to exclude a complete namespace, can you help me ?

JuulFan
  • 21
  • 7

1 Answers1

2

.NET has an attribute called ObfuscationAttribute, which has an Exclude property.

The documentation for Exclude says:

Gets or sets a Boolean value indicating whether the obfuscation tool should exclude the type or member from obfuscation.

You should be able to add [Obfuscation(Exclude = true)] to the member(s) you want to exclude. If the obfuscator tool you're using properly respect this attribute (ConfuserEx should be respecting this AFAIK), it should get the work done.

Youssef13
  • 3,836
  • 3
  • 24
  • 41
  • Thanks for you answer, i dont know how to use this [Obfuscation(Exclude = true)], where to add it ? i just want to exclude a line of code, actually in the file Program.cs – JuulFan Sep 14 '20 at 21:41
  • @JuulFan Extract this one line of code into a method, and put `[Obfuscation(Exclude = true)]` just above the method. – Youssef13 Sep 14 '20 at 21:43
  • And obviously, don't forget `using System.Reflection;` – Youssef13 Sep 14 '20 at 21:43
  • i did it it doesnt work :( [System.Reflection.Obfuscation(Exclude = true)] static void notObsfuscate() { – JuulFan Sep 14 '20 at 21:46
  • You need to explain more on *how* it doesn't work. Did you get a compile-error? can you show it? did it compile successfully but ConfuserEx didn't exclude it? – Youssef13 Sep 14 '20 at 21:48
  • Also i just add the next code to AssemblyInfo.cs and it works, but im worry about what exactly do this code -> [assembly: Obfuscation(Exclude = false, Feature = "packer:compressor")] – JuulFan Sep 14 '20 at 21:48
  • @JuulFan I think it should disable a feature called "packer:compressor" for the entire assembly, not only for the one line you want to exclude. – Youssef13 Sep 14 '20 at 21:53
  • Yes, back to the problem, the solution that you post sounds good, just need to make it works, i did what you post, and doesnt work, and if i compile without using confuserex then works, but then when i compile and use confuserex it doesnt work. – JuulFan Sep 14 '20 at 21:56