Assembly Merging

In Babel Obfuscator, assembly merging can be performed in several ways, including using the babel tool from the command line, the MSBuild Babel task, or the user interface in the Babel Obfuscator application.

Merging From Command Line

Using the babel tool, you can merge assemblies by specifying the target assembly followed by the list of assembly files to be merged with the primary assembly as well as any other configuration options:

babel <primary assembly source> [<other assemblies>...] [options]

The Babel Obfuscator provides several options to configure assembly merging.

--[no]copyattrs [regex]

This option allows users to specify whether Babel should copy assembly-level attributes into the primary assembly. It is also possible to specify an optional regular expression to match the attribute's full name that should be merged. Users can enter multiple --copyattrs commands to specify several attribute filters. To disable copying assembly-level attributes, users can enter the --nocopyattrs command.

If assembly-level attributes are copied, users can use XML rules to filter the attributes to be copied or excluded using the CopyAttributes and NoCopyAttributes properties, which take a regular expression to match the assembly-level attribute full type name:

<Rule name="merge attributes" feature="merge" exclude="false">
  <Target>Assembly</Target>
  <Pattern>*</Pattern>
  <Properties>
    <NoCopyAttributes>.*TypeLibVersion</NoCopyAttributes>
  </Properties>
</Rule>

The CopyAttributes filter expression is used to selectively include assembly-level attributes in the merged assembly based on their fully qualified attribute type name. In other words, only the attributes that match the filter expression will be merged into the target assembly, while all others will be excluded.

On the other hand, the NoCopyAttributes filter expression is used to selectively exclude assembly-level attributes from the merged assembly based on their fully qualified attribute type name. This means that all attributes that match the filter expression will not be merged into the target assembly, while all others will be included.

--[no]internalize:

When enabled, it modifies the visibility of all the merged assembly types from public to internal.

Changing the type visibility can prevent merged types from being consumed outside the primary assembly, so this option should only be enabled if the merged types are intended to be used only by the primary assembly.

Merging From MSBuild Babel Task

To merge assmebies using the Babel task, you must define an additional ItemGroup element in the MSBuild project file. This ItemGroup contains all the assemblies you want to merge with the primary assembly. The Babel task will then use this ItemGroup to perform the merge during the build process.

Here is an example of how to define the ItemGroup element

<ItemGroup>
  <MergeAssembly Include="path/to/assembly1.dll"/>
  <MergeAssembly Include="path/to/assembly2.dll"/>
</ItemGroup>

In this example, path/to/assembly1.dll and path/to/assembly2.dll are the paths to the assemblies you want to merge with the primary assembly. You can include as many assemblies as you need in the ItemGroup.

Once you have defined the ItemGroup, you can pass it to the Babel task using the MergeAssemblies parameter:

<Babel MergeAssemblies="@(MergeAssembly)" Internalize="true" />

The Internalize attribute specifies whether to change the visibility of merged types from public to internal.

Merging From Babel UI

To merge assemblies using Babel UI, you can follow these steps:

  1. Open the Babel Obfuscator user interface and create a new project or open an existing one.

  2. Click + icon located to the left of the row corresponding to the primary assembly. This will reveal the Input Grid, where you can add the list of assemblies to be merged.

  3. In the Input Grid File column, Click ... to browse and select the assemblies you want to merge. Alternatively, you can drag and drop the list of assemblies in the Input Grid.

  4. Ensure the Action is set to Merge for every assembly added.

  5. You can configure the merging options, such as internalizing and copying attributes, by switching to the Settings panel.

Last updated