1

When I obfuscate this form, and "debug" it

public partial class Form1 : Form
{
  public void Form1()
  {
    InitializeComponents();
  }

  protected override void OnShown(EventArgs e)
  {
      base.OnShown(e);
      Console.WriteLine("Name: "+this.Name);
      Console.WriteLine("FullName: "+this.GetType().FullName);
  }
}

The output is like this:

Name: Form1
FullName: #Yab.#Zab


Question
Why is FullName obfuscated?
Form1 is public so I would expect SmartAssembly to ignore it.

Extra info
Form1 is public partial and so is the designer.cs

My SmartAssembly setup is like this:

    <ApplicationName />
    <Destination DestinationFileName=".\bin.obfuscated\MyProject.Form1.exe" />
    <Assemblies>
        <Assembly AssemblyName="MyProject.Form1, Culture=neutral, PublicKeyToken=omitted">
            <Merging>
                <ResourcesCompression Compress="0" />
                <MemberRefsProxy />
                <Pruning />
                <Obfuscation Obfuscate="1">
                  <Exclusions />
                </Obfuscation>
                <ControlFlow Obfuscate="1" />
            </Merging>
        </Assembly>
    </Assemblies>
    <Options>
      <Obfuscation FieldsNameMangling="2" NameMangling="1" />
      <ExceptionReporting />
      <FeatureUsageReporting Template="res:SmartUsageWithUIConsentFirstRun1033.dll" />
      <StrongNameSigning KeyFileName="PathToKeyFile" Sign="1" />
      <OtherProtections />
      <StringsEncoding />
      <OtherOptimizations />
      <Debugging />
    </Options>
leppie
  • 115,091
  • 17
  • 196
  • 297
Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
  • `partial` only has meaning for the compiler and the access modifier must be the same for all parts (that may or may not be on its own file). – Paulo Morgado Jun 09 '14 at 18:15
  • I disagree. I have seen many forms there the `Form1.designer.cs` part of the partial class - where private, even though the `Form1.cs` class was public. – Jens Kloster Jun 13 '14 at 12:00
  • either you've seen it wrong or the code failed to compile with "Partial declarations of 'Form1' have conflicting accessibility modifiers". ["All the parts must have the same accessibility, such as public, private, and so on."](http://msdn.microsoft.com/library/wa80x488.aspx "Partial Classes and Methods (C# Programming Guide)") – Paulo Morgado Jun 14 '14 at 00:33
  • @PauloMorgado - your point is well taken. I must have misread the code. – Jens Kloster Jun 15 '14 at 15:10

1 Answers1

2

Firstly, a public class isn't ignored by SmartAssembly in an application project (it will be ignored in a library project).

Secondly, the Name property of your form is a property set at runtime. In your case case, it may be initialized to "Form1" somewhere in your code, maybe in the designer.

This value can be changed anytime, example :

public Form1()
{
    InitializeComponent();
    this.Name = "foo";
}

So SmartAssembly cannot obfuscate this value, it would be wrong and would change the behavior of your code.

When SmartAssembly obfuscates your code, it only changes the names of the types, fields and methods. When your try to get the name of your type, it's logical to get the obfuscated name of your type.

Max
  • 1,810
  • 3
  • 26
  • 37
  • Do you have some documentation for your statements? They don't fit with my expirence working with SmartAssembly Obfuscation. – Jens Kloster Jun 13 '14 at 11:57
  • Which one? First point here (http://documentation.red-gate.com/display/SA6/Troubleshooting+name+mangling). I only speak about the name mangling here, because it seems to be point which interests you. The second point is more based on my experience, maybe I'm not totally clear in my explaination. – Max Jun 16 '14 at 08:04
  • 1
    I just needed the documentation - and your statements are correct :) thank you – Jens Kloster Jun 16 '14 at 10:53