# patrislav1/unisoc-unlock architecture

> Architecture diagram of the GitHub repository patrislav1/unisoc-unlock, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/patrislav1/unisoc-unlock
- Repository: https://github.com/patrislav1/unisoc-unlock

## Overview

unisoc-unlock is a Python tool for locking or unlocking a Unisoc/Spreadtrum Android bootloader. The user selects a command; the tool connects to the device in fastboot mode, requests and extracts its identifier token, signs the token with the bundled key, downloads the signature, then issues the lock or unlock command. The bundled fastboot implementation handles protocol messages over USB, with shared device discovery and transport code. The README also documents platform support and on-device confirmation. Some fastboot implementation details are unsampled, so the graph limits those connections to relationships visible in excerpts or documented behavior.

Main entry points: [`src/unisoc_unlock/bundled_adb/fastboot.py`](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/fastboot.py) (Fastboot commands), [`src/unisoc_unlock/cli.py`](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py) (Bootloader command), [`src/unisoc_unlock/bundled_adb/common.py`](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/common.py) (USB transport), [`src/unisoc_unlock/bundled_adb/usb_exceptions.py`](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/usb_exceptions.py) (USB exceptions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Unlock workflow"]
  node_cli["CLI command<br/>[cli.py]"]
  node_bootloader_cmd["Bootloader command<br/>[cli.py]"]
  node_token_parse["Token extraction<br/>[cli.py]"]
  node_token_sign["Token signing<br/>[cli.py]"]
  node_module_entry["Module entry<br/>[__main__.py]"]
end

subgraph group_fastboot["Fastboot protocol"]
  node_fastboot_commands["Fastboot commands<br/>[fastboot.py]"]
  node_fastboot_protocol["Fastboot protocol<br/>[fastboot.py]"]
end

subgraph group_transport["Device transport"]
  node_usb_transport["USB transport<br/>[common.py]"]
end

subgraph group_support["Errors and key"]
  node_signing_key["Bundled signing key<br/>[rsa4096_vbmeta.pem]"]
  node_usb_errors["USB exceptions<br/>[usb_exceptions.py]"]
end

node_user(("User"))
node_device["Unisoc device"]

node_user -->|"selects command"| node_cli
node_module_entry -->|"calls main"| node_cli
node_cli -->|"dispatches command"| node_bootloader_cmd
node_bootloader_cmd -->|"connects and requests token"| node_fastboot_commands
node_fastboot_commands -->|"passes response callback"| node_token_parse
node_bootloader_cmd -->|"signs extracted token"| node_token_sign
node_token_sign -->|"loads key"| node_signing_key
node_bootloader_cmd -->|"downloads signature and sends lock command"| node_fastboot_commands
node_fastboot_commands -->|"dispatches commands"| node_fastboot_protocol
node_fastboot_protocol -->|"reads and writes packets"| node_usb_transport
node_fastboot_commands -->|"discovers devices"| node_usb_transport
node_usb_transport -->|"communicates over USB"| node_device
node_fastboot_protocol -->|"exchanges fastboot messages"| node_device
node_fastboot_commands -->|"raises device errors"| node_usb_errors
node_usb_transport -->|"wraps USB failures"| node_usb_errors
node_device -->|"requests confirmation"| node_user

click node_cli "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py"
click node_bootloader_cmd "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py"
click node_token_parse "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py"
click node_token_sign "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py"
click node_signing_key "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/rsa4096_vbmeta.pem"
click node_fastboot_commands "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/fastboot.py"
click node_fastboot_protocol "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/fastboot.py"
click node_usb_transport "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/common.py"
click node_usb_errors "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/usb_exceptions.py"
click node_module_entry "https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/__main__.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_bootloader_cmd,node_token_parse,node_token_sign,node_module_entry,node_user toneBlue
class node_fastboot_commands,node_fastboot_protocol toneAmber
class node_usb_transport toneMint
class node_signing_key,node_usb_errors toneRose
class node_device toneIndigo
```

## Components

### Unlock workflow

- [CLI command](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py): `src/unisoc_unlock/cli.py`
- [Bootloader command](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py): `src/unisoc_unlock/cli.py`
- [Token extraction](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py): `src/unisoc_unlock/cli.py`
- [Token signing](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/cli.py): `src/unisoc_unlock/cli.py`
- [Module entry](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/__main__.py): `src/unisoc_unlock/__main__.py`

### Fastboot protocol

- [Fastboot commands](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/fastboot.py): `src/unisoc_unlock/bundled_adb/fastboot.py`
- [Fastboot protocol](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/fastboot.py): `src/unisoc_unlock/bundled_adb/fastboot.py`

### Device transport

- [USB transport](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/common.py): `src/unisoc_unlock/bundled_adb/common.py`

### Errors and key

- [Bundled signing key](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/rsa4096_vbmeta.pem): `src/unisoc_unlock/rsa4096_vbmeta.pem`
- [USB exceptions](https://github.com/patrislav1/unisoc-unlock/blob/main/src/unisoc_unlock/bundled_adb/usb_exceptions.py): `src/unisoc_unlock/bundled_adb/usb_exceptions.py`

### Other components

- **User**
- **Unisoc device**

## Connections

- User → CLI command: selects command (evidence: `README.md`)
- Module entry → CLI command: calls main (evidence: `src/unisoc_unlock/__main__.py`)
- CLI command → Bootloader command: dispatches command (evidence: `src/unisoc_unlock/cli.py`)
- Bootloader command → Fastboot commands: connects and requests token (evidence: `src/unisoc_unlock/cli.py`)
- Fastboot commands → Token extraction: passes response callback (evidence: `src/unisoc_unlock/cli.py`)
- Bootloader command → Token signing: signs extracted token (evidence: `src/unisoc_unlock/cli.py`)
- Token signing → Bundled signing key: loads key (evidence: `src/unisoc_unlock/cli.py`)
- Bootloader command → Fastboot commands: downloads signature and sends lock command (evidence: `src/unisoc_unlock/cli.py`)
- Fastboot commands → Fastboot protocol: dispatches commands (evidence: `src/unisoc_unlock/bundled_adb/fastboot.py`)
- Fastboot protocol → USB transport: reads and writes packets (evidence: `src/unisoc_unlock/bundled_adb/fastboot.py`)
- Fastboot commands → USB transport: discovers devices (evidence: `src/unisoc_unlock/bundled_adb/fastboot.py`)
- USB transport → Unisoc device: communicates over USB (evidence: `README.md`)
- Fastboot protocol → Unisoc device: exchanges fastboot messages (evidence: `src/unisoc_unlock/bundled_adb/fastboot.py`)
- Fastboot commands → USB exceptions: raises device errors (evidence: `src/unisoc_unlock/bundled_adb/fastboot.py`)
- USB transport → USB exceptions: wraps USB failures (evidence: `src/unisoc_unlock/bundled_adb/common.py`)
- Unisoc device → User: requests confirmation (evidence: `README.md`)
