Obfuscate .NET MAUI

Babel Obfuscator can obfuscate a .NET MAUI (Multi-platform App UI) application by processing the compiled assembly file (e.g., a DLL or EXE) with its obfuscation engine. The obfuscation process will modify the compiled assembly to make the code harder to understand and reverse engineer while still preserving the functionality of the application.

When obfuscating a .NET MAUI application with Babel Obfuscator, it is recommended to use the latest version of the obfuscator and to follow best practices for obfuscation, such as obfuscating all code and resources, keeping important names intact using exclusions, and testing the obfuscated application to ensure it still functions correctly.

We will use the TwoPaneView sample MAUI application available for download at GitHub https://github.com/dotnet/maui-samples.

git clone https://github.com/dotnet/maui-samples

These sample applications are designed to showcase various features of the MAUI framework and are a good starting point for building custom MAUI applications.

  1. Firstly, clone the project's repository from GitHub and save it on your local machine.

  2. Once the repository is saved on your machine, navigate to the folder named 7.0 in the repository.

  3. Inside the 7.0 folder, go to UserInterface/Views/TwoPaneView.

  4. Open the solution TwoPaneViewSample.sln file in this folder.

  5. Once the solution is opened in Visual Studio, you need to double-click the solution project TwoPaneViewSample node, which can be found in the Solution Explorer window.

  6. This will open the project file inside the Visual Studio editor.

  7. To configure the Babel task for this project, you can append the required MSBuild instructions to the project file. These instructions will tell the Babel Obfuscator how to obfuscate the project's code.

<UsingTask TaskName="Babel" AssemblyName="Babel.Build, Version=10.0.0.0, Culture=neutral, PublicKeyToken=138d17b5bd621ab7" />

<Target Name="Obfuscate" AfterTargets="Compile">
   <ItemGroup>
      <_BabelSearchDirectories Include="@(ReferencePathWithRefAssemblies->'%(rootdir)%(directory)')" Condition="'%(Extension)' == '.dll'" />
      <BabelSearchDirectories Include="@(_BabelSearchDirectories->Distinct())" />
   </ItemGroup>

   <Babel InputFile="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" OutputFile="$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)" SearchDirectories="@(BabelSearchDirectories)" GenerateDebug="true" ObfuscateTypes="true" ObfuscateEvents="true" ObfuscateMethods="true" ObfuscateProperties="true"  ObfuscateFields="true" ObfuscateXaml="true" VirtualFunctions="true" UnicodeNormalization="false" FlattenNamespaces="true" StringEncryption="hash"  ResourceEncryption="true" ControlFLowObfuscation="if=on;switch=on;case=on;call=on" ControlFLowIterations="3" />
   
</Target>

The @BabelSearchDirectories item group in the context of Babel Obfuscator is used to define a list of directories that the obfuscation process will search in order to resolve any assembly references used in the project.

This list is generated by extracting search directories from the list of assemblies referenced by the project. The Babel Obfuscator looks at the metadata of the referenced assemblies to determine the location of their dependencies and then adds those directories to the @BabelSearchDirectories list. By doing this, the obfuscator can find all the necessary files it needs to obfuscate the project's code successfully.

Now you can compile and run the obfuscated .NET MAUI application.

Using NuGet Package (MAC & Linux)

The Babel.Obfuscator NuGet package can be used on MAX OS and Linux for those who have the Ultimate, Server or Data Center edition. This provides a more straightforward configuration process, allowing users to add only Babel-related obfuscation settings without the burden of configuring other related build items. Using the NuGet package, users can avoid the Babel task and simplify the configuration process for their projects.

  1. Add the Babel.Obfuscator.nupkg to TwoPaneViewSample project.

  2. Set the following properties inside the TwoPaneViewSample project file:

<PropertyGroup>
   <StringEncryption>hash</StringEncryption>
   <ResourceEncryption>true</ResourceEncryption>
   <ObfuscateXaml>true</ObfuscateXaml>
   <ControlFlowObfuscation>if=on;switch=on;case=on;call=on</ControlFlowObfuscation>
   <ControlFlowIterations>3</ControlFlowIterations>
</PropertyGroup>

The sample project with Babel task instructions already included is available for download here.

Last updated