.NET MAUI - Root/Jail Broken Detection

.NET MAUI Banner

Introduction

Building a secure .NET MAUI app is essential. Rooted/jailbroken devices bypass security measures, leaving them vulnerable. This can impact your app's data and functionality. Let's explore the risks and how to implement root/jailbreak detection in your .NET MAUI app.

Quick Links

  • Project Setup
  • Install Plugin
  • Implementation
  • Download Code

Project Setup in Visual Studio

  • Launch Visual Studio 2022, and in the start window, click Create a new project to create a new project.
    Create a new project in Visual Studio
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
    Visual Studio in new project
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button.Configure new project in Visual Studio
  • In the Additional information window, click the Create button:
    Additional information
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app
    Android Emulator

Install Plugin

  • Open your Nuget Package Manager and search "banditoth.MAUI.JailbreakDetector" and install the latest version in your project.
    Install plugins

Implementation

  • Open MainPage.xaml file and update the UI as per your requirement. In this sample, I have added a button to check whether the device is rooted or not.
  • You can dependency inject the jailbreak detector instance by resolving an instance of IJailbreakDetector. Store the instance in a private readonly field in your class, or use it directly.
    IJailbreakDetectorConfiguration jailbreakDetectorConfiguration = new JailbreakSettings();
    jailbreakDetectorConfiguration.MaximumPossibilityPercentage = 20;
    jailbreakDetectorConfiguration.MaximumWarningCount = 1;
    jailbreakDetectorConfiguration.CanThrowException = true;
    
    IJailbreakDetector jailbreakDetector = new JailberakDetectorService(jailbreakDetectorConfiguration);
  • Use the following code to check whether the device is rooted or not.
    if (jailbreakDetector.IsSupported())
    {
    	var isRooted = await jailbreakDetector.IsRootedOrJailbrokenAsync();
    	if (isRooted)
    	{
    		await DisplayAlert("ANDROIDMADS - .NET MAUI", "DEVICE IS ROOTED", "OK");
    	}
    	else
    	{
    		await DisplayAlert("ANDROIDMADS - .NET MAUI", "DEVICE IS NOT ROOTED", "OK");
    	}
    }

Download Code

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.


Similar Articles