13

I cannot get my obfuscated application running on mono. Unobfuscated works on mono. When I use the .net framework on win7 it starts without issue in both variants.

This is the exception I get:

Unhandled Exception: System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object at .‮‮‎‫‎âªâ€­â€‹â€ªâ€«âªâ¬â€Žâªâ¯â€«â­â€Œâ€‹â€­â¯â€­â«â¯â¬â€­â€­â«â€Œâ€®â­â«â€­â€ªâ€«â­â€¬â€«â€ªâ€ªâ€® () <0x40884310 + 0x00874> in :0 at ..cctor () <0x40884100 + 0x00017> in :0 --- End of inner exception stack trace --- at Vintagestory.Server.Program.Main (System.String[] args) <0x408814c0 + 0x002bb> in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for '' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object at .‮‮‎‫‎âªâ€­â€‹â€ªâ€«âªâ¬â€Žâªâ¯â€«â­â€Œâ€‹â€­â¯â€­â«â¯â¬â€­â€­â«â€Œâ€®â­â«â€­â€ªâ€«â­â€¬â€«â€ªâ€ªâ€® () <0x40884310 + 0x00874> in :0 at ..cctor () <0x40884100 + 0x00017> in :0 --- End of inner exception stack trace --- at Vintagestory.Server.Program.Main (System.String[] args) <0x408814c0 + 0x002bb> in :0

The exception seems to happen at a point when it has to load additional code from an external library thats also obfuscated in the same process.

How can I even go about and debug/fix this?

Update: Seems to also happen on Windows Mono

Update2: Here is also a github issue entry of the bug with some more detail: https://github.com/yck1509/ConfuserEx/issues/535

Tyron
  • 1,938
  • 11
  • 30
  • I have not used ConfuserEx or mono - maybe they use something that just isn't supported on linux - I guess this is the constructor that throws the exception, but none of the code you took picture of shows anything that can throw a NullReferenceException. I don't think you have a simple way of debugging it since this is basically the point of obfuscation, so you probably have to dig in and make sense of the code. Maybe paste the entire code of the constructor, and I could try and help you. – gilmishal Aug 31 '16 at 12:36
  • Thank you for your response, i've added a pastebin to the entire source code. One more thing i could try is disable individual protections and see which causes. – Tyron Aug 31 '16 at 14:10
  • Seems like a case where classical `Trace.WriteLine` debugging would help. Print debug messages after each statement of the static initializer to narrow down the location of the issue (also move any initialization of static fields to the static initializer). – Dirk Vollmar Sep 30 '16 at 09:49
  • 1
    I remember using `ConfuserEx` for my `WPF` application. I too got problems with it, but only on Windows (no `Mono`). Just as you assumed, I disabled all protections and then started enabling them one by one. And it helped. You may try the same thing. – Gabrielius Sep 30 '16 at 10:13
  • Hm ok thanks for the suggestions, I'll test those out in a few days. – Tyron Oct 01 '16 at 16:28
  • @Tyron Could you try to run it on the x32 platform please. Is result the same? – Alexandr Nikitin Oct 02 '16 at 11:35
  • Thanks for the suggestion. Compiling as x86 app did not help unfortunately. – Tyron Oct 03 '16 at 17:40

2 Answers2

8

I used the Maximum Obfuscation Level for a single C# Class that was not even used but part of an external library that was required, that seemed to be the problem.

When I reduce the obfuscation level down to "Aggressive" it works. Not ideal but will do for now.

Tyron
  • 1,938
  • 11
  • 30
0

I also set the "anti debug" and "anti tamper" protection action remove. And It work's for me.

<protection id="anti debug" action="remove"/>
<protection id="anti tamper" action="remove"/>
Tonay
  • 27
  • 1