SmartAssembly - 6.6

SmartAssembly

Obfuscating code - SmartAssembly

About name mangling

Name mangling changes the name of your classes and methods to unreadable characters, making your code harder to understand. SmartAssembly automatically detects non-obfuscatable code or metadata.

Using name mangling

Name mangling makes your code harder to understand by changing the names of types, methods and fields.

To use name mangling, in the Project Settings window, go to Obfuscation or click the icon in the toolbar.

Select the assemblies that you want to obfuscate.

Types/methods name mangling

ASCII characters

Renames types and methods using ASCII characters. For example, the type FullScreenSplash is obfuscated to #dc.

Unicode unprintable characters

Renames types and methods using Unicode unprintable characters. For example, the type FullScreenSplash is obfuscated to U+1D11E (which is unprintable).

Unicode unprintable characters and advanced renaming algorithm

Renames types and methods using Unicode unprintable characters and renames multiple items with the same name. For example, the types FullScreenSplash and FontStyle are both obfuscated to U+017D.

Note that when you obfuscate an assembly using ASCII characters name mangling, SmartAssembly automatically uses incremental obfuscation. This enables you to decode a stack trace, even if the stack-trace covers several obfuscated assemblies.

Fields name mangling

One-to-one renaming scheme

Changes all fields in all classes so that they have different names. A field's name is unique within an assembly.

Obfuscated in the same style as the selected Types/methods name mangling.

Standard renaming

Alters the field name so that is unique within a class, however the same name is often used within other classes in the assembly. For example, #a: string, #b: boolean, #c: string, #d: boolean.

Obfuscated in the same style as the selected Types/methods name mangling.

Advanced renaming

Alters the field name, however it not unique within a class and is reused. Fields of a different type will have the same name. For example, #a: string, #a: boolean, #b: string, #b: boolean.

Obfuscated in the same style as the selected Types/methods name mangling.

When name mangling is enabled, the colored bars under the toolbar icon and to the left of the feature options are green. If it is disabled, the bars are orange.

Method parent obfuscation

Method parent obfuscation moves methods to other types in the assembly, making it hard to discover which classes they are part of.

Please note that method parent obfuscation is a new feature in SmartAssembly 6.6. We do not expect it to work with Silverlight or Windows Phone applications, and we cannot guarantee that it will work on other types of assembly. If you have any feedback on this new feature, please add your comments to the SmartAssembly forum.

Name mangling example:

The following example shows code before and after name mangling:

Before:

public ClientLicence GetLicence(ItemType type);

public bool IsFileInProject(string fileName);

public void ResolveAssemblyReferences();

public void Save();

private void SetMemento(Properties memento);

public void Start(bool withDebugging);

private void StartBuild(ProjectBuildOptions buildOptions, IBuildFeedbackSink feedbackSink);

After:

It is not possible to display unprintable characters. For the purpose of this example, unprintable characters are represented by an asterisk (*).

public ‑.‑ *(‑.‑);

public bool *(string);

public void *();

public void *();

private void *(‑.‑);

public void *(bool);

private void *(‑.‑,‑.‑);

Troubleshooting name mangling

SmartAssembly usually detects that a member cannot be obfuscated by name mangling. However, in some cases, you need to manually exclude the member from the obfuscation. You can do this in your SmartAssembly project or by using custom attributes.

  • If you use the Unicode unprintable characters and advanced renaming algorithm option for name mangling, consider using Unicode unprintable characters instead, especially if your class/interface inheritance is complex or if you use generics.
  • If you are using Linq, you must exclude any classes using the System.Data.Linq.Mapping.Table attribute from obfuscation and pruning (this also applies if they are used as a dependency).

    Depending on the specific application you many need to exclude other classes.

Excluding public members from name mangling

Executable files

By default, SmartAssembly obfuscates all members of executable files, including public members.

To override this behavior, manually edit the SmartAssembly project file (*.saproj) in an XML editor as follows.

  1. Locate the <Assembly> element for the assembly to which you want to apply the setting.
  2. Add the KeepPublicMembersAccessible="1" attribute to the <Merging> element, as in the example below.

<Assembly AssemblyName="...">
  <Merging KeepPublicMembersAccessible="1">
    <!-- Settings for the assembly -->
  </Merging>
</Assembly>

Note that the ExcludePublicMembers attribute on the <Obfuscation> element was replaced by KeepPublicMembersAccessible in SmartAssembly 6.7. Because the new attribute is set on the <Merging> element, the assembly's public members are neither pruned nor obfuscated.

DLL files

SmartAssembly does not obfuscate public members of DLL files, because the DLL would be unusable.

Excluding items from name mangling

If you do not want to obfuscate some members, select the assembly to obfuscate, and navigate to the items that you want to exclude from obfuscation. Items you exclude from obfuscation will not be obfuscated in the resulting assembly.

You can also use the [DoNotObfuscate] and [DoNotObfuscateType] attributes to exclude items from name mangling. For information, see Using custom attributes.

Was this article helpful?

Search support
Forums
Visit the SmartAssembly forum.

SmartAssembly

all products