| Author |
Message |
CodeGuru
Joined: 22 Nov 2010 Posts: 7
|
Posted: Tue May 17, 2011 5:23 am Post subject: Obfuscating enum names when enum is .ToString()'d |
|
|
The bug I described here:
http://www.red-gate.com/MessageBoard/viewtopic.php?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: |
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. |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6346 Location: Red Gate Software
|
Posted: Wed May 18, 2011 9:36 am Post subject: |
|
|
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
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6346 Location: Red Gate Software
|
Posted: Wed May 18, 2011 1:28 pm Post subject: |
|
|
I'd also like to add I could not reproduce the problem with the given code using obfuscation and pruning.
| Code: |
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: |
[Flags]
enum Candy
{
JollyRancher = 0x01,
ReesesPieces = 0x02
} |
Hopefully this works for you. _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
CodeGuru
Joined: 22 Nov 2010 Posts: 7
|
Posted: Wed May 18, 2011 4:30 pm Post subject: Re: |
|
|
| 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. |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6346 Location: Red Gate Software
|
Posted: Fri May 20, 2011 5:36 pm Post subject: |
|
|
Did applying the "Flags" attribute fix the problem? _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group