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.
These sample applications are designed to showcase various features of the MAUI framework and are a good starting point for building custom MAUI applications.
Firstly, clone the project's repository from GitHub and save it on your local machine.
Once the repository is saved on your machine, navigate to the folder named 7.0 in the repository.
Inside the 7.0 folder, go to UserInterface/Views/TwoPaneView.
Open the solution TwoPaneViewSample.sln file in this folder.
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.
This will open the project file inside the Visual Studio editor.
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.
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.
Add the Babel.Obfuscator.nupkg to TwoPaneViewSample project.
Set the following properties inside the TwoPaneViewSample project file:
The sample project with Babel task instructions already included is available for download here.
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”.
Last updated