Cross Assembly Renaming

During the obfuscation process, Babel Obfuscator renames all the symbols that are not externally visible to the assembly, which includes private and internal symbols. This means that Babel will change the names of fields, methods, classes, and other code elements that are not meant to be accessed outside of the assembly.

Babel will not rename symbols externally visible to the assembly, such as public symbols. This is because public symbols are meant to be accessed by other assemblies, and renaming them would break the application's functionality. Therefore, Babel only renames the symbols not meant to be accessed by other assemblies, ensuring that the application still works as intended.

However, Babel provides the ability to obfuscate both public and internal members across multiple assemblies. This is accomplished by fixing the names of the obfuscated symbols referenced in each assembly using XML map files.

This is because when an assembly is obfuscated, the names of its symbols are changed. Thus, any reference to these symbols made by another assembly must be updated to reflect the new names. By specifying these input and output XML map files, Babel Obfuscator can use them to fix cross-name references between all participating assemblies. This ensures that the obfuscated code works correctly and does not break due to incorrect symbol names.

It is important to keep map files private and not deploy them with the obfuscated application under any circumstances, as they can be used to reverse engineer the obfuscation and compromise the security of the application.

Setup From MSBuild Task

To configure cross-assembly renaming with MSBuild, it is necessary to specify the input and output XML map files for each assembly involved in the obfuscation project. Each obfuscated assembly must generate an XML map file, which will then be provided as input to all other obfuscated assemblies that reference this target assembly.

Here's an example of how to configure cross-assembly renaming between one main assembly and two referenced assemblies arranged according to the following scheme.

  • MainAssembly.dll

    1. Library1.dll

    2. Library2.dll

  • Library1.dll

    1. Library2.dll

Main Assembly Project

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <Reference Include="path\to\referenced\Library1.dll" />
    <Reference Include="path\to\referenced\Library2.dll" />
  </ItemGroup>

  <Target Name="Obfuscate" AfterTargets="CoreCompile">
    <ItemGroup>
      <MapInFile Include="path\to\referenced\Library1.dll.map.xml" />
      <MapInFile Include="path\to\referenced\Library2.dll.map.xml" />
    </ItemGroup>
    <Babel Input="$(TargetPath)" MapInFiles="@(MapInFile)" />
  </Target>
</Project>

As the MainAssembly project references the two libraries, Library1 and Library2, which have been obfuscated in their public interface, the Babel task needs to be configured to load the two XML mapping files generated for each library.

Library1 Assembly Project

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <Reference Include="path\to\referenced\Library2.dll" />
  </ItemGroup>
  <PropertyGroup>
    <GenerateMapOutFile>true</GenerateMapOutFile>
  </PropertyGroup>

  <Target Name="Obfuscate" AfterTargets="CoreCompile">
    <ItemGroup>
      <MapInFile Include="path\to\referenced\Library2.dll.map.xml" />
    </ItemGroup>
    <Babel Input="$(TargetPath)" MapInFiles="@(MapInFile)" GenerateMapOutFile="$(GenerateMapOutFile)" />
  </Target>
</Project>

It is worth noticing that as Library1 references Library2, the obfuscation project, besides generating the XML map file with GenerateMapOutFile=true, must also reference the mapping file generated for Library2.

Library2 Assembly Project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GenerateMapOutFile>true</GenerateMapOutFile>
  </PropertyGroup>

  <Target Name="Obfuscate" AfterTargets="CoreCompile">
    <Babel Input="$(TargetPath)" GenerateMapOutFile="$(GenerateMapOutFile)" />
  </Target>
</Project>

This ensures that any cross-referencing between Library1 and Library2 is handled correctly during the obfuscation process. Without referencing the XML map file generated for Library2, the obfuscation process for Library1 may not correctly handle cross-referencing between the two libraries, leading to potential issues at runtime. Therefore, it is essential to ensure that all necessary XML map files are generated and referenced correctly when configuring cross-assembly renaming.

Setup From Babel UI

In cases where the application to be configured for cross-assembly obfuscation comprises multiple components, selecting the appropriate obfuscation order can be a challenging task. However, the Babel Obfuscator provides a user-friendly interface that simplifies the process of setting up cross-assembly obfuscation.

To utilize this feature, drag and drop all the assemblies you wish to cross-obfuscate into the Input Grid. Then, right-click in the Input Grid and select "Setup Public Obfuscation" from the drop-down menu. This will enable the Babel Obfuscator to automatically generate an appropriate obfuscation order for the selected assemblies and set up the correct XML mapping files for every assembly in the obfuscation project with minimal effort on your part.

To exclude an assembly from public obfuscation, you can easily do so using the Babel Obfuscator UI. Right-click on the Input Grid column header and select the "Column Chooser" from the drop-down menu, which will open the Customization dialog.

Drag and drop the "Rename Public" field into the Input Grid. Now you can uncheck the "Rename Public" checkbox for each assembly that should not have the public interface mangled. By unchecking this field, Babel will remove the obfuscation rule created to rename all public symbols exposed by the third-party assembly, effectively excluding it from the public obfuscation process.

Last updated