Home - Forums-.NET - Spices.Net - Obfuscator Bug

Spices.Net

NET code security, tools to protect, obfuscate, tamper defense, code and data safety, recover, convert, optimize, explore, browse and analyze .Net software.

This forum related to following products: Spices.Net Suite, Spices.Net Obfuscator, Spices.Net Decompiler

Obfuscator Bug
Link Posted: 29-Dec-2005 03:30
Hi,

by obfuscating an application this code will fail to work if using string protection:

...
switch(strVar)
{
  case "/debug":
   _debugmode = true;
   break;
}

Every switch-construction with only one case will fail  

The next code works, but string protection is NOT DONE:

...
switch(strVar)
{
  case "/debug":
   _debugmode = true;
   break;
  case "/dummy":
   _debugmode = false;
   break;
}

Using Spice Obfuscator 4.5.6 CommandLine. I used .NET Reflector 4.1.95 to inspect this issue.

cu

Markus
Link Posted: 13-Jan-2006 09:09
If you look for the IL-code of this string switch code, you can find some il instruction for string interning (convert string to reference) to speed up string comparison (comparing by reference) in the switch, this trick of compiler does functioning of encryption on this portion of code incorrect. This problem related only for string switches.
To avoid this problem replace string swiches by usual if-else-elseif condition statements or you can use switches with string hashecode comparison:

switch(strVar.GetHashCode() )
{
  case "/debug".GetHashCode():
    _debugmode = true;
    break;
  case "/dummy".GetHashCode():
    _debugmode = false;
    break;
}
Link Posted: 13-Jan-2006 09:25
Ah - ok. Could you reproduce the behaviour with only one string case:

strVar = "/debug":
switch(strVar)
{
case "/debug":
_debugmode = true;
break;
}

With this construct the variable _debugmode is never set to true.

This is my main problem because I can't verify all my sources for a single case construct.

Thank you,

Markus
Link Posted: 13-Jan-2006 09:30
Yes, this problem related only string switches, it will be better if you'll use following code instead of string switch:
[c#]
if (strVar == "/debug")
  _debugmode = true;
else if (strVar == "/dummy")
  _debugmode = false;
Link Posted: 13-Jan-2006 09:43
Sorry,

I described in the first post 2 problems. The first (and main) problem ist that code like

strVar = "/debug":
switch(strVar)
{
case "/debug":
_debugmode = true;
break;
}

no longer works! Every program, library and control with only 1 string case no longer works proper! I understand, that string encryption can not be done on this construct, BUT it should work and that's NOT the case.

I develop since 2002 with .NET and have many projects - it is not possible to have a look at every switch and check if there is only one string case.

Thank you,

Markus
Link Posted: 13-Jan-2006 09:53
Can you send us (develop at 9rays.net, please zip) this code for analysis, probably problem not in the compiler.
Link Posted: 13-Jan-2006 10:43
Thanks for your assembly, I've tested this file on the latest Spices.Obfuscator.Net (both - GUI and console) and obfuscated assembly works correctly.
Link Posted: 13-Jan-2006 11:00
Sorry to tell you that the bug still occurs with 4.6.0 - I sent you the new obfuscated exe.

cu

Markus
Link Posted: 05-Feb-2006 22:04
Issue solved in version 4.6.3 - thank you very much !!!

cu

Markus