Babel Obfuscator
HomeDocumentationShop
  • Introduction
    • General Features
  • Getting Started
    • Install
    • Product Activation
  • Command Line
    • Command Line Reference
      • Miscellaneous
      • Input Files
      • Output Files
      • Plugins
      • Merge and Embed
      • Renaming
      • Control Flow Obfuscation
      • Encryption and Protection
      • Code Generation
  • MSBuild Task
    • Babel Task Reference
    • Customizing Intellisense
  • NuGet Package
    • NuGet Pakage Reference
  • User Interface
    • Obfuscation
    • Tools
    • Custom Themes
  • Obfuscation Rules
    • XML Rules
      • Example Rules
    • Custom Attributes
    • Obfuscation Agent
  • Merge and Embed
    • Assembly Merging
    • Assembly Embedding
  • Symbols Renaming
    • XML Map Files
    • Cross Assembly Renaming
    • XAML Renaming
    • Decoding Stack Traces
  • String Encryption
    • Custom String Encryption
  • Control Flow Obfuscation
  • Code Encryption
    • External Code Files
    • Password Protected Code
    • Dynamic Code
  • Dynamic Proxy
  • Resource Encryption
  • Value And Array Encryption
  • Tampering Detection
  • Anti Debugging
  • Enhancing Code Security
  • Optimizations
    • Dead Code Removal
    • Metadata Optimizations
    • Code Optimizations
  • Appendix
  • Examples
    • Examples
    • General Samples
      • ClickOnce Deploy
      • Detecting Babel Obfuscation
      • Obfuscate .NET MAUI
      • Blazor Web App
    • Code Encryption
      • Feature Based Licenses
    • Cross Assembly Renaming
      • Publish .NET App
    • Build Servers
      • GitHub Actions
      • Unit Tests
    • Babel Obfuscator NuGet
      • Android Application
  • Plugins
    • Babel Obfuscator Plugins
    • Encrypt Plugin
      • Getting Started
      • Source Code
Powered by GitBook
On this page
  • Using NuGet Package
  • Linking Behavior for .NET MAUI iOS App

Was this helpful?

  1. Examples
  2. General Samples

Obfuscate .NET MAUI

Last updated 1 month ago

Was this helpful?

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 .

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

The Babel.Obfuscator NuGet package can be used on Windows, 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>

Linking Behavior for .NET MAUI iOS App

When building .NET MAUI app, a linker (ILLink) is used to minimize app size by removing unused code. It keeps only essential methods, properties, fields, events, structs, and classes.

The ILLink supports three modes for .NET MAUI apps on iOS and Mac Catalyst:

  • Don't link: All linker optimizations are disabled.

  • Link SDK assemblies only: Only SDK assemblies are optimized by removing unused types and members, leaving your assemblies unaltered.

  • Link all assemblies: This mode applies optimizations to minimize app size by modifying intermediate code.

An assembly obfuscated with Babel Obfuscator contains dynamic code and complex structures that ILLink fails to detect. As a result, aggressive optimizations like Link all assemblies can adversely affect the app’s functionality.

To avoid potential issues with ILLink when using obfuscated assemblies, it’s recommended to configure the ILLink mode to “Link SDK assemblies only”.

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

https://github.com/dotnet/maui-samples
here
TwoPaneView MAUI Sample Application