SmartAssembly - 6.7
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 may not work with some types of assembly.

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.
- You may experience problems running an assembly that uses name mangling with a merged dependency containing WPF code, especially if that WPF code contains enums.
To resolve these problems, follow the steps in Troubleshooting after building.
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:
- Locate the
<Assembly>element for the assembly to which you want to apply the setting. - 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?
SmartAssembly
- Using Smartassembly to obfuscate a windows service
- Obfuscation not renaming identically-named methods in different classes
- Serialization exceptions occurring in obfuscated assemblies
- SmartAssembly skipping obfuscation of some classes in your assembly
- SmartAssembly is not merging or embedding all assembly dependencies
- Can I customize the path to the MDB database?
- System.InvalidOperationException when attempting to connect to local SmartAssembly database
- Protecting website code using SmartAssembly
- Visual Studio Deployment Projects including unprotected builds
- SmartAssembly MSBUILD tasks failing because of difference in log4net assembly
- SmartAssembly Error Reporting: This application has submitted too many reports
- The assembly is being merged, but the dependent assembly isn't
- ERR 2002: Server did not recognize the value of HTTP Header SOAPAction
- The error report is not associated with a valid project ID - SmartAssembly
- Application built with an evaluation edition of SmartAssembly
- How end users can change their participation in Feature Usage Reporting
- Log file for SmartAssembly
- Moving SmartAssembly to another computer
- 'Using JET databases is not possible in 64-bit applications' error when using MSBuild or TFS
- SmartAssembly stack trace is invalid when Method Parent Obfuscation is enabled
- Upgrading SmartAssembly version 4.x to version 5
- Upgrading SmartAssembly Standard to Professional
- Problems building WPF applications with SmartAssembly 6.7
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SmartAssembly
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs


Using SmartAssembly for obfuscation