# satyamisme/balong-usbdload architecture

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

- Interactive diagram: https://gitdiagram.com/satyamisme/balong-usbdload
- Repository: https://github.com/satyamisme/balong-usbdload

## Overview

Balong-usbdload is an emergency USB loader for Huawei Balong modems. The main workflow selects a loader and serial port, optionally patches the loader and bypasses secure boot, then sends the loader to the modem over its emergency serial interface. Separate utilities patch loader files, inspect or edit partition tables, and unpack or repack loader images. Edges follow the shown calls and README; where the main program’s control flow is unsampled, links are omitted or marked unverified.

Main entry points: [`balong-usbdload.c`](https://github.com/satyamisme/balong-usbdload/blob/master/balong-usbdload.c) (USB Loader), [`usbloader-packer.c`](https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-packer.c) (Image Packer), [`loader-patch.c`](https://github.com/satyamisme/balong-usbdload/blob/master/loader-patch.c) (Patch Utility), [`parts.c`](https://github.com/satyamisme/balong-usbdload/blob/master/parts.c) (Table Helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Emergency Boot"]
  node_main["USB Loader<br/>[balong-usbdload.c]"]
  node_serial["Serial Transport<br/>[balong-usbdload.c]"]
  node_exploit["Secuboot Bypass<br/>[exploit.c]"]
end

subgraph group_patch["Loader Patching"]
  node_patcher_cli["Patch Utility<br/>[loader-patch.c]"]
  node_patch_engine["Patch Engine<br/>[patcher.c]"]
end

subgraph group_ptable["Partition Tables"]
  node_ptable_core["Table Helpers<br/>[parts.c]"]
  node_ptable_editor["Table Editor<br/>[ptable-editor.c]"]
  node_ptable_injector["Table Injector<br/>[ptable-injector.c]"]
  node_ptable_list["Table Listing<br/>[ptable-list.c]"]
end

subgraph group_images["Loader Images"]
  node_packer["Image Packer<br/>[usbloader-packer.c]"]
  node_loader_image["USB Loader Image"]
  node_safe_image["Safe Loader Images<br/>[usblsafe-3372h.bin]"]
  node_components["Extracted Components<br/>[usbloader-packer.c]"]
end

node_user(("Operator"))
node_modem["Balong Modem"]

node_user -->|"selects loader"| node_main
node_main -->|"sends packets"| node_serial
node_serial -->|"transfers loader"| node_modem
node_main -->|"patches loader"| node_patch_engine
node_main -.->|"may invoke"| node_exploit
node_user -->|"requests patch"| node_patcher_cli
node_patcher_cli -->|"applies patches"| node_patch_engine
node_user -->|"edits table"| node_ptable_editor
node_ptable_editor -->|"uses table format"| node_ptable_core
node_user -->|"updates loader"| node_ptable_injector
node_ptable_injector -->|"finds and displays"| node_ptable_core
node_user -->|"lists table"| node_ptable_list
node_ptable_list -->|"uses table helpers"| node_ptable_core
node_user -->|"packs or unpacks"| node_packer
node_packer -->|"reads image"| node_loader_image
node_packer -->|"extracts blocks"| node_components
node_components -->|"repacked as image"| node_packer
node_patcher_cli -->|"creates patched copy"| node_safe_image

click node_main "https://github.com/satyamisme/balong-usbdload/blob/master/balong-usbdload.c"
click node_serial "https://github.com/satyamisme/balong-usbdload/blob/master/balong-usbdload.c"
click node_exploit "https://github.com/satyamisme/balong-usbdload/blob/master/exploit.c"
click node_patcher_cli "https://github.com/satyamisme/balong-usbdload/blob/master/loader-patch.c"
click node_patch_engine "https://github.com/satyamisme/balong-usbdload/blob/master/patcher.c"
click node_ptable_core "https://github.com/satyamisme/balong-usbdload/blob/master/parts.c"
click node_ptable_editor "https://github.com/satyamisme/balong-usbdload/blob/master/ptable-editor.c"
click node_ptable_injector "https://github.com/satyamisme/balong-usbdload/blob/master/ptable-injector.c"
click node_ptable_list "https://github.com/satyamisme/balong-usbdload/blob/master/ptable-list.c"
click node_packer "https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-packer.c"
click node_loader_image "https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-3372h.bin"
click node_safe_image "https://github.com/satyamisme/balong-usbdload/blob/master/usblsafe-3372h.bin"
click node_components "https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-packer.c"

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_main,node_serial,node_exploit toneBlue
class node_patcher_cli,node_patch_engine toneAmber
class node_ptable_core,node_ptable_editor,node_ptable_injector,node_ptable_list toneMint
class node_packer,node_loader_image,node_safe_image,node_components toneRose
class node_user,node_modem toneIndigo
```

## Components

### Emergency Boot

- [USB Loader](https://github.com/satyamisme/balong-usbdload/blob/master/balong-usbdload.c): `balong-usbdload.c`
- [Serial Transport](https://github.com/satyamisme/balong-usbdload/blob/master/balong-usbdload.c): `balong-usbdload.c`
- [Secuboot Bypass](https://github.com/satyamisme/balong-usbdload/blob/master/exploit.c): `exploit.c`

### Loader Patching

- [Patch Utility](https://github.com/satyamisme/balong-usbdload/blob/master/loader-patch.c): `loader-patch.c`
- [Patch Engine](https://github.com/satyamisme/balong-usbdload/blob/master/patcher.c): `patcher.c`

### Partition Tables

- [Table Helpers](https://github.com/satyamisme/balong-usbdload/blob/master/parts.c): `parts.c`
- [Table Editor](https://github.com/satyamisme/balong-usbdload/blob/master/ptable-editor.c): `ptable-editor.c`
- [Table Injector](https://github.com/satyamisme/balong-usbdload/blob/master/ptable-injector.c): `ptable-injector.c`
- [Table Listing](https://github.com/satyamisme/balong-usbdload/blob/master/ptable-list.c): `ptable-list.c`

### Loader Images

- [Image Packer](https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-packer.c): `usbloader-packer.c`
- [USB Loader Image](https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-3372h.bin): `usbloader-3372h.bin`
- [Safe Loader Images](https://github.com/satyamisme/balong-usbdload/blob/master/usblsafe-3372h.bin): `usblsafe-3372h.bin`
- [Extracted Components](https://github.com/satyamisme/balong-usbdload/blob/master/usbloader-packer.c): `usbloader-packer.c`

### Other components

- **Operator**
- **Balong Modem**

## Connections

- Operator → USB Loader: selects loader (evidence: `README.md`)
- USB Loader → Serial Transport: sends packets (evidence: `balong-usbdload.c`)
- Serial Transport → Balong Modem: transfers loader (evidence: `balong-usbdload.c`)
- USB Loader → Patch Engine: patches loader (evidence: `balong-usbdload.c`)
- USB Loader → Secuboot Bypass: may invoke
- Operator → Patch Utility: requests patch (evidence: `loader-patch.c`)
- Patch Utility → Patch Engine: applies patches (evidence: `loader-patch.c`)
- Operator → Table Editor: edits table (evidence: `ptable-editor.c`)
- Table Editor → Table Helpers: uses table format (evidence: `ptable-editor.c`)
- Operator → Table Injector: updates loader (evidence: `ptable-injector.c`)
- Table Injector → Table Helpers: finds and displays (evidence: `ptable-injector.c`)
- Operator → Table Listing: lists table (evidence: `ptable-list.c`)
- Table Listing → Table Helpers: uses table helpers (evidence: `ptable-list.c`)
- Operator → Image Packer: packs or unpacks (evidence: `README.md`)
- Image Packer → USB Loader Image: reads image (evidence: `usbloader-packer.c`)
- Image Packer → Extracted Components: extracts blocks (evidence: `usbloader-packer.c`)
- Extracted Components → Image Packer: repacked as image (evidence: `README.md`)
- Patch Utility → Safe Loader Images: creates patched copy (evidence: `README.md`)
