Android Application

In this example project, we will utilize the Babel Obfuscator NuGet package to enable obfuscation in an Android application based on .NET 7. The Babel Obfuscator NuGet package can be easily integrated into a .NET project. It provides a convenient way to configure and apply obfuscation directly from Visual Studio or the command line.

To use this example project and follow the instructions provided, you need to have a site license for Babel Obfuscator (Ultimate, Server or Data Center editions). Additionally, the source code for the example project is available for download from the GitHub repository associated with the project.

git clone https://github.com/babelfornet/android-app-example.git

The example project "AndroidApp" is designed to demonstrate the obfuscation process of an Android application. The project contains the reference to the Babel Obfuscator NuGet package, which runs the obfuscation against the target assembly AndroidApp.dll during the build process.

In addition to using the Babel Obfuscator NuGet package to set up obfuscation in the AndroidApp project, some additional configuration has been added to the project file (AndroidApp.csproj) to enable other types of obfuscations.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ApplicationId>com.companyname.AndroidApp</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Babel.Obfuscator" Version="10.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  
  <PropertyGroup>
    <Use>tagassembly=true</Use>
    <StringEncryption>true</StringEncryption>
    <ControlFlowObfuscation>goto=on;if=on;switch=on;case=on;call=on;true</ControlFlowObfuscation>
    <DynamicProxy>all</DynamicProxy>
    <ResourceEncryption>true</ResourceEncryption>
    <VerboseLevel>3</VerboseLevel>
    <XmlRules>
      <Rules>
        <Rule name="rule1" feature="renaming" exclude="false">
          <Pattern>*</Pattern>
        </Rule>
	</Rules>
    </XmlRules>
  </PropertyGroup>
</Project>

For example, the project file includes settings for string encryption, which obfuscates string literals in the application's code to make it harder for attackers to reverse-engineer the app. Additionally, the configuration sets up a custom rule for renaming all public types, which increases the number of renamed types.

Once the app starts, it shows all the types inside the obfuscated assembly in the main view.

The view displays that most of the types have been renamed by Babel, showing that we are running the obfuscated application.

This example project demonstrates integrating the Babel Obfuscator NuGet package into an Android application and customising its obfuscation settings to achieve specific results. Through this example, users can gain insights into how Babel Obfuscator can help protect their Android applications by renaming types and methods, removing metadata, encrypting strings and adding control flow obfuscation to their code, enhancing the overall application security.

Last updated