MiUnlockTool Documentation

repository·main·Indexed 23 days ago

https://github.com/offici5l/miunlocktool

A cross-platform Python-based utility (package name: miunlock, version 1.7.3) designed to retrieve encryptData(token) for Xiaomi devices to facilitate bootloader unlocking. It supports multiple platforms, SMS/Email verification, and automatic dataCenterZone configuration, providing an alternative to the official Windows-only MiFlashUnlock tool.

Tokens
3.5K
Snippets
8
Records
26
Agent score
76%

What's inside MiUnlockTool

  1. Compare MiUnlockTool with Official MiFlashUnlock

    main

    MiUnlockTool provides several advantages over the official Windows-only MiFlashUnlock tool:

    FeatureMiUnlockTool
    Supported platformsAll (Cross-platform)
    Save login session✅ Supported
    Verification methodsSMS / Email
    dataCenterZone configAutomatic / Manual

    Official MiFlashUnlock is limited to Windows and only supports SMS verification.

  2. Understand data wiping during bootloader unlocking

    main

    As a general rule, bootloader unlocking wipes all user data. Always back up your device before proceeding.

    The miunlock tool will explicitly notify you whether your data will be wiped or not before it proceeds with the operation.

    Exception: Legacy Devices

    The following device codenames are unlocked without clearing user data:

    gemini, ido, kate, kenzo, land, markw, meri, mido, nikel, omega, prada, rolex, santoni, venus, wt88047

  3. Understand the encryptData lifecycle and format

    main

    The encryptData is the deviceToken signed by Xiaomi's server.

    Workflow:

    1. The tool sends the deviceToken to Xiaomi's /api/v3/ahaUnlock endpoint.
    2. If the account meets requirements (including the waiting period), the server returns a JSON response containing the signed token as encryptData.
    3. The tool converts this encryptData string into raw bytes and saves it to a file.
    4. The file is sent to the device via fastboot stage.
    5. The device verifies the signature using an embedded public key to unlock the bootloader.

    Server Response Format:

    {
      "code": 0,
      "description": "私钥签名成功",
      "encryptData": "signed deviceToken",
      "uid": "Xiaomi account ID"
    }
  4. Run the MiUnlockTool CLI

    main

    Once your device is prepared and the MiUnlockTool is installed, execute the tool via the command line.

    After running the command, you will be prompted to choose a login method. You must sign in using the same Xiaomi account that you previously added in the Mi Unlock status section of your device settings. Follow the subsequent terminal prompts to complete the unlocking process.

    miunlock
  5. Set up a Python virtual environment

    main

    To avoid externally managed environment errors, create and activate a Python virtual environment. Replace anyname with your preferred environment name.

    1. Create the environment:

      python3 -m venv anyname
    2. Activate the environment based on your shell:

    • Windows (PowerShell):
      anyname/bin/Activate.ps1
    • Windows (CMD):
      anyname/bin/activate.bat
    • macOS/Linux (bash/zsh):
      source anyname/bin/activate
    • macOS/Linux (fish):
      source anyname/bin/activate.fish
    • macOS/Linux (tcsh):
      source anyname/bin/activate.csh

    Note: Activation is only for the current shell session. You must re-activate the environment whenever you open a new terminal to use the tool.

    python3 -m venv anyname
  6. Install MiUnlockTool on Android (Termux)

    main

    To use MiUnlockTool on Android, follow these steps:

    Prerequisites

    Install both the Termux app and the Termux API app from a single source (e.g., GitHub releases).

    Quick Installation

    Run the following command to automate the process:

    curl -sS https://raw.githubusercontent.com/MiForge/MiUnlockTool/main/.install | bash

    Step-by-step Installation

    1. Install Python3:
      pkg install python-pip
    2. **Install MiUnlockTool**:
     ```bash
    pip install miunlock

    Note on termux-fastboot: termux-fastboot is installed automatically the first time you run miunlock. To install it manually, use:

    curl -s https://raw.githubusercontent.com/nohajc/termux-adb/master/install.sh | bash
    curl -sS https://raw.githubusercontent.com/MiForge/MiUnlockTool/main/.install | bash
  7. Install Python for MiUnlockTool

    main

    Before installing MiUnlockTool, ensure Python is installed on your system. Use the command appropriate for your operating system:

    • Windows: Use winget install python or download the installer from Python's website (ensure you check "Add Python to PATH").
    • macOS: Use Homebrew with brew install --cask python or download the installer from Python's website.
    • Ubuntu/Debian: sudo apt install python3 python3-venv
    • Fedora: sudo dnf install python3
    • Arch Linux: sudo pacman -S python
    winget install python
  8. Unlock the bootloader using encryptData

    main

    Once you have obtained the encryptData file (the raw bytes of the signed token), follow these steps to unlock the device via fastboot:

    1. Stage the encrypted data file to the device: fastboot stage <encryptData_file>

    2. Execute the unlock command: fastboot oem unlock

    fastboot stage <encryptData_file>
    fastboot oem unlock
  9. Prepare your device for unlocking

    main

    To unlock your bootloader, you must register your account and device within the MIUI/HyperOS settings.

    1. Enable Developer Options by tapping 7 times on the MIUI version or Build number in your device settings.
    2. Navigate to: Settings → Additional settings → Developer options → Mi Unlock status.
    3. Tap "Add account and device".

    Note for HyperOS users: If your device is running HyperOS, you may also require permission from the Xiaomi Community.

  10. Retrieve the deviceToken via fastboot

    main

    The deviceToken is a value containing device-specific information (version, tokenversion, codename, cpuid, and a random RAND value) required for the unlocking process. You can retrieve it using one of the following fastboot commands depending on your device:

    • fastboot getvar token
    • fastboot oem get_token

    Note: The deviceToken changes every time the device reboots because a new RAND value is generated. This causes the encryptData (the signed token) to expire immediately after a reboot.

    fastboot getvar token
    # or
    fastboot oem get_token
  11. Prepare your Xiaomi device for bootloader unlocking

    main

    Before using the MiUnlockTool, you must enable developer options and register your account with Xiaomi's servers.

    Warning: Unlocking the bootloader will delete all data on your device, void your warranty, and remove security protections, potentially exposing the device to malware.

    1. Enable Developer Options: In your phone settings, tap the build number (MIUI Version / Build number) 7 times.
    2. Register Account: Navigate to SettingsAdditional settingsDeveloper optionsMi Unlock status.
    3. Add Account: Tap Add account and device and follow the on-screen instructions to successfully link your account.