Skip to content

Instantly share code, notes, and snippets.

@Starmania
Last active November 8, 2024 10:46
Show Gist options
  • Save Starmania/32520c56792e4f596cb7d51cab076f67 to your computer and use it in GitHub Desktop.
Save Starmania/32520c56792e4f596cb7d51cab076f67 to your computer and use it in GitHub Desktop.

Preface

Genymotion recently moved root access behind a paywall, making it a premium feature. However, if you're using Genymotion for Android development, testing, or educational purposes, having root access can be essential. Root access allows developers to access deeper functionality, test root-only features, and explore Android's internals without restrictions.

The good news is that with a bit of work, you can still enable root on a Genymotion emulator if you have access to its disk image and platform keys. This guide walks you through the process of adding a custom system app, RootToggle, which will allow you to switch root access on and off without needing Genymotion's paid root access feature.

This Gist details the steps to compile, sign, and install RootToggle as a system app in a Genymotion emulator by directly modifying the emulator's disk image IN LINUX (use a virtual machine on Windows to do that).


Contents

  • RootToggle.apk: The signed APK for RootToggle
  • RootToggle Source Files: Source code for the RootToggle app
  • Setup Instructions: Guide to add RootToggle to the system partition in Genymotion

1. Compile the RootToggle App

If you prefer to compile the APK from source, follow these steps:

  1. Get the source: Download source.zip

  2. Build the APK: Open the project in Android Studio and build the APK, or use the Gradle command line.

    ./gradlew assembleRelease
  3. Locate the Unsigned APK: After building, the unsigned APK will be in the app/build/outputs/apk/release directory.

2.Get the Platform Keys

You will need platform.pk8 and platform.x509.pem keys for the emulator. If for some reason this repo doesn't exist anymore, you could get it here.

git clone https://github.com/Genymobile/genymotion_platform_vendor_genymotion_security_public
cp genymotion_platform_vendor_genymotion_security_public/release-keys/platform* .

3. Sign the APK with. Sign the APK with Platform Keys

Run the following command to sign the APK:

/path/to/build-tools/<version>/apksigner sign \
  --key platform.pk8 \
  --cert platform.x509.pem \
  --out RootToggle-signed.apk \
  app/build/outputs/apk/release/app-release-unsigned.apk

The signed APK is now ready to be installed as a system app.

4. Install RootToggle as a System App

Using QEMU and qemu-nbd, we’ll add the signed APK to the Genymotion emulator’s system partition.

Step-by-Step Commands

  1. Load the NBD (Network Block Device) Module:

    sudo modprobe nbd
  2. Attach the QCOW2 Disk Image:

    sudo qemu-nbd --connect=/dev/nbd0 ~/.Genymobile/Genymotion/deployed/Google\ Pixel\ 7\ Pro/system.qcow2
  3. Identify the System Partition:

    Run fdisk -l to confirm the correct partition (usually /dev/nbd0p4 for large partitions).

  4. Mount the System Partition:

    sudo mkdir -p /mnt/android_system
    sudo mount /dev/nbd0p4 /mnt/android_system
  5. Create the App Directory:

    sudo mkdir -p /mnt/android_system/system/priv-app/RootToggle
  6. Copy the Signed APK:

    sudo cp RootToggle-signed.apk /mnt/android_system/system/priv-app/RootToggle/RootToggle.apk
  7. Set the Correct Permissions:

    sudo chmod 644 /mnt/android_system/system/priv-app/RootToggle/RootToggle.apk
  8. Unmount and Disconnect:

    sudo umount /mnt/android_system
    sudo qemu-nbd --disconnect /dev/nbd0

5. Start the Emulator

Start your Genymotion emulator as usual. The RootToggle app should now be installed as a system app with the necessary permissions to modify persist.sys.root_access.

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment