Obfuscating enum names when enum is .ToString()'d

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, melvyn.harbour, dom.smith

Obfuscating enum names when enum is .ToString()'d

Postby CodeGuru » Tue May 17, 2011 5:23 am

The bug I described here:
http://www.red-gate.com/MessageBoard/vi ... hp?t=12231

STILL exists in the latest version of 6.

Its pretty frustrating have to put my exe's through IDA just to make sure SmartAssembly is obfuscating all of my names.

Just to make it even more clear whats going on here.

Code: Select all
public class Test
{
   enum BitStateFlags
   {
      state1 = 1,
      state2 = 2,
   }

   void SomeFunction()
   {
      BitStateFlags flags = BitStateFlags.state1;

      MessageBox.Show(flags.ToString("X"));
   }
}


It's pretty obvious what you're trying to do. You detect if an enum is being printed out as a string. If it is, you're omitting it from obfuscation.

In this example though only the numerical value is being output though, not the actual enum name.

Also, you should have a policy of ALWAYS obfuscate unless the user EXPLICITLY chooses otherwise.

We should have confidence that SmartAssembly is obfuscating everything but your method to omit obfuscation on variables that you think we might want unobfuscated leaves us with zero confidence and full of doubt.
CodeGuru
 
Posts: 9
Joined: Mon Nov 22, 2010 5:29 pm

Postby Brian Donahue » Wed May 18, 2011 9:36 am

I'm sorry it looks like we had been totally unresponsive when dealing with this issue. I think the problem is that, behind the scenes, .NET uses Reflection voodoo to knock up a string representation of an enum, and SmartAssembly will usually blow the assembly metadata to bits as part of the obfuscation and I can see how this would be one side-effect.

If you want the string representation of this enum to be ("X"), maybe telling the enum to derive from the type long and using ((long)MyEnum).ToString("X")
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby Brian Donahue » Wed May 18, 2011 1:28 pm

I'd also like to add I could not reproduce the problem with the given code using obfuscation and pruning.
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Test t = new Test();
            t.GetCandy();
            Console.ReadLine();
        }
    }
    public class Test
    {
        enum Candy
        {
            JollyRancher = 0x01,
            ReesesPieces = 0x02
        }
        public void GetCandy()
        {
            Candy candy=Candy.JollyRancher;
            Console.WriteLine(candy.ToString());
        }
    }
}
However, from my miniscule understanding of the SmartAssembly code, I think you should be safe if you use the FlagsAttribute on the enum because there seems to be an exclusion in the SA obfuscation rules for that.
Code: Select all
        [Flags]
        enum Candy
        {
            JollyRancher = 0x01,
            ReesesPieces = 0x02
        }
Hopefully this works for you.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Re:

Postby CodeGuru » Wed May 18, 2011 4:30 pm

Brian Donahue wrote:If you want the string representation of this enum to be ("X"), maybe telling the enum to derive from the type long and using ((long)MyEnum).ToString("X")


That's exactly what I do to get SmartAssembly obfuscating the names properly.

I have not tried the [Flags] attribute as an alternative fix.

Thanks for the reply.
CodeGuru
 
Posts: 9
Joined: Mon Nov 22, 2010 5:29 pm

Postby Brian Donahue » Fri May 20, 2011 5:36 pm

Did applying the "Flags" attribute fix the problem?
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests

cron