# rgerganov/gen5fw architecture

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

- Interactive diagram: https://gitdiagram.com/rgerganov/gen5fw
- Repository: https://github.com/rgerganov/gen5fw

## Overview

##### Project type and purpose
- This is a command-line firmware-patching toolkit (not a web app or microservice).
- Its goal is to take an official Gen5 Navigation firmware package, crack/unzip it, apply custom patches (e.g., enable ADB), re-pack and encrypt it, and produce a USB-deployable update for Hyundai/KIA/Genesis head units.

##### File structure
- Top level:
- gen5.py         – main Python3 tool (encrypts firmware artifacts)
- checksum.py     – helper for computing checksums on files
- dos_date.mjs    – Node script (fixes DOS timestamps?)
- partition.dat   – binary data file used by gen5.py
- requirements.txt– Python dependencies
- pics/           – images for README only
- zip_password_calculator/:
- zip_password_calculator.mjs – Node tool to crack the update_package.zip password
- zip_password_calculator.sh  – shell wrapper for the above
- build.prop.TEST             – sample config
- README.md explains the overall patch & deploy pipeline and external tool requirements (Android sparse utils, unzip, img2simg).

##### README for additional insights
- The process is linear:
a. Download ‘update_package.zip’ via official updater
b. Crack its password (zip_password_calculator) → obtain update.zip + otacerts.zip
c. Unzip update.zip → firmware blobs + system.ext4
d. Mount system.ext4 → apply patch
e. Umount + convert ext4 to sparse image (img2simg)
f. Run gen5.py encrypt → produce seven encrypted files + file_info
g. Copy to FAT32 USB → use head-unit recovery mode to flash

##### Detail guidance
- Every major artifact (update_package.zip, update.zip, system.ext4, system.img, encrypted files).
- Manual patch as a sub-step inside the “Mount & Patch” component.
- Don’t clutter: keep each step visually distinct but show handoff of output as input to the next.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Source
    ExternalFirmware["Firmware Updater App"]:::external
    ExternalFirmware --> USB1

    USB1["USB Drive (FAT32)"]:::external
    USB1 --> zipSH

    %% Zip Password Cracker Module
    subgraph "Zip Password Cracker Module"
        zipModule["zip_password_cracker"]:::script
        zipSH["zip_password_calculator.sh"]:::script
        zipMJS["zip_password_calculator.mjs"]:::script
        buildProp["build.prop.TEST"]:::script
        zipSH --> zipMJS
        zipMJS --> zipModule
    end
    USB1 --> zipModule
    zipModule --> update_zip
    zipModule --> otacerts

    update_zip["update.zip"]:::external
    otacerts["otacerts.zip"]:::external

    %% Unzip & Mount
    update_zip --> unzipSub
    unzipSub["Unzip (unzip)"]:::external
    unzipSub --> blobs
    unzipSub --> systemEXT

    blobs["Firmware Blobs"]:::script
    systemEXT["system.ext4"]:::script

    systemEXT --> mount
    mount["Mount & Manual Patch"]:::script
    mount --> systemEXT_Patched

    systemEXT_Patched["system.ext4 (patched)"]:::script

    %% Sparse Conversion
    systemEXT_Patched --> sparseTool
    sparseTool["img2simg"]:::external
    sparseTool --> systemIMG

    systemIMG["system.img"]:::script

    %% Encryption & Packaging
    blobs --> packageStep
    systemIMG --> packageStep
    packageStep["gen5.py Encrypt"]:::script
    packageStep --> outputDir

    outputDir["security_force/ (Encrypted bundle)"]:::script
    outputDir --> USB2

    USB2["USB Drive (FAT32)"]:::external
    USB2 --> HeadUnit

    HeadUnit["Car Head Unit (Recovery)"]:::head

    %% Ancillary Tools
    dosDate["dos_date.mjs"]:::script
    checksumN["checksum.py"]:::script
    gen5["gen5.py"]:::script
    partitionDat["partition.dat"]:::script
    README["README.md"]:::script
    requirements["requirements.txt"]:::script
    pics["pics/"]:::script

    %% Click Events
    click gen5 "https://github.com/rgerganov/gen5fw/blob/master/gen5.py"
    click checksumN "https://github.com/rgerganov/gen5fw/blob/master/checksum.py"
    click partitionDat "https://github.com/rgerganov/gen5fw/blob/master/partition.dat"
    click dosDate "https://github.com/rgerganov/gen5fw/blob/master/dos_date.mjs"
    click zipModule "https://github.com/rgerganov/gen5fw/tree/master/zip_password_calculator/"
    click zipMJS "https://github.com/rgerganov/gen5fw/blob/master/zip_password_calculator/zip_password_calculator.mjs"
    click zipSH "https://github.com/rgerganov/gen5fw/blob/master/zip_password_calculator/zip_password_calculator.sh"
    click buildProp "https://github.com/rgerganov/gen5fw/blob/master/zip_password_calculator/build.prop.TEST"
    click README "https://github.com/rgerganov/gen5fw/blob/master/README.md"
    click requirements "https://github.com/rgerganov/gen5fw/blob/master/requirements.txt"
    click pics "https://github.com/rgerganov/gen5fw/tree/master/pics/"

    %% Styles
    classDef script fill:#D1E8FF,stroke:#0366D6,color:#0366D6
    classDef external fill:#D1FFD1,stroke:#228B22,color:#228B22
    classDef head fill:#FFD1A9,stroke:#D2691E,color:#D2691E
```
