# fled-dev/mdmpatcher-enhanced architecture

> Architecture diagram of the GitHub repository fled-dev/mdmpatcher-enhanced, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fled-dev/mdmpatcher-enhanced
- Repository: https://github.com/fled-dev/mdmpatcher-enhanced

## Overview

1. **Project shape**
   - This is a **macOS desktop app** built in **Xcode** using **Swift + Cocoa/AppKit**, with a **Swift/C bridge** for lower-level device work.
   - The app is not a networked service; its architecture is centered on **local USB device interaction** and **filesystem-based patch/restore preparation**.

2. **Primary user-facing layer**
   - `AppDelegate.swift` and `ViewController.swift` form the main application flow.
   - The view controller owns the end-to-end workflow: detect a connected iOS device, display device metadata, enable the patch action, and surface errors/success notifications.
   - `ExtensionsShit.swift` appears to hold UI helper behavior, mainly for alerts and user feedback.

3. **USB/device discovery boundary**
   - `USBDetection.swift` is the monitoring layer that watches for USB events and filters for supported iOS devices.
   - This is the first architectural boundary: the app moves from “no device present” to “eligible device detected” before any patching logic is allowed to run.

4. **Low-level device communication**
   - `libidevicefunctions.c/.h`, `idevicebackup2.c/.h`, and `iDeviceInfoFunctions.swift` form the device-communication subsystem.
   - These pieces rely on the **libimobiledevice ecosystem** and associated libraries to talk to iPhone/iPad services over USB.
   - The app extracts device identity fields such as **UDID, model/product type, serial number, IMEI when available, and build version** to parameterize later file generation.

5. **Bridge between Swift and C**
   - `MDMPatcher-Bridging-Header.h` is the interop boundary that exposes C APIs to the Swift UI layer.
   - This separation is important: Swift handles UI/state, while C handles device sessions and restore mechanics.

6. **Patch payload preparation**
   - The repo contains bundled artifacts such as `extension1.pdf`, `extension2.pdf`, `libiMobileeDevice.dylib`, and “clean” plist/archive templates.
   - The architecture uses these as **template inputs** that are transformed per-device into a temporary working set.
   - `deobfuscation.swift` and the related C utilities likely support the decoding/decryption/byte-processing stages described in the README.

7. **File-processing and customization pipeline**
   - The patch flow is primarily **local file generation**:
     - decrypt or unpack bundled templates,
     - compute values from device metadata,
     - rewrite `Info.plist` and `Manifest.plist`,
     - prepare a backup-like directory structure.
   - This is the second major boundary: the app moves from live device inspection to **offline construction of restore inputs** on disk.

8. **Restore engine**
   - `idevicebackup2.c` is the restore orchestration layer.
   - It coordinates the final device-side action using the prepared backup structure and communicates over the same USB/libimobiledevice stack.
   - Architecturally, this is the execution phase that consumes the generated files and pushes them back to the connected device.

9. **Supporting system libraries and bundled binaries**
   - The repository vendors many native dependencies: `libimobiledevice`, `libusbmuxd`, `libplist`, `libirecovery`, `libcurl`, `libssl`, `libcrypto`, `libzip`, `libfragmentzip`, `libxpwntool`, and others.
   - These are not incidental; they are the runtime substrate for USB multiplexing, plist parsing, archive handling, and restore-related operations.
   - The app is effectively a thin Swift GUI over a substantial native toolchain.

10. **Data flow at a high level**
   - The main flow is:
     1. detect a supported iOS device,
     2. connect and read device metadata,
     3. generate a device-specific working set from bundled templates,
     4. invoke the restore engine over USB,
     5. clean up temp artifacts and reset UI state.
   - Errors can occur at any stage, and the app appears to funnel them back into the UI for user notification and retry.

11. **Repository packaging**
   - This repo includes both source and prebuilt binaries, which suggests the app depends on a curated native stack rather than fetching dependencies at build time.
   - The `.xcodeproj`, asset catalog, storyboard, and entitlements define a standard macOS app package, while the bundled dylibs/static archives define most of the non-UI functionality.

12. **Important architectural boundary for diagrams**
   - The most important split is between:
     - **macOS UI/state management** in Swift,
     - **native device/restore tooling** in C and bundled libraries,
     - **local template/file transformation** in between.
   - An accurate diagram should show the app as a controller over USB-connected iOS devices, with a file-generation step in the middle and a restore step at the end, rather than as a client-server or cloud architecture.

Main entry points: [`MDMPatcher/ViewController.swift`](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/ViewController.swift) (Main Flow), [`deobfuscation.swift`](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/deobfuscation.swift) (Decode Stage), [`MDMPatcher/idevicebackup2.c`](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/idevicebackup2.c) (Restore Engine), [`MDMPatcher/libidevicefunctions.c`](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/libidevicefunctions.c) (C Device API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["macOS UI"]
  node_app_delegate["App Delegate<br/>App lifecycle<br/>[AppDelegate.swift]"]
  node_view_controller["Main Flow<br/>UI controller"]
  node_alerts["UI Alerts<br/>UI helper"]
  node_packaging["App Package<br/>xcode project<br/>[project.pbxproj]"]
end

subgraph group_device["Device bridge"]
  node_usb_detection["USB Detection<br/>device monitor<br/>[USBDetection.swift]"]
  node_device_info["Device Info<br/>metadata reader"]
  node_lib_device_functions["C Device API<br/>usb/session bridge"]
  node_backup_restore["Restore Engine<br/>restore orchestrator<br/>[idevicebackup2.c]"]
  node_bridge_header["Bridge Header<br/>interop boundary"]
end

subgraph group_files["File pipeline"]
  node_templates[("Templates<br/>bundled inputs<br/>[clean_archive.zip]")]
  node_deobfuscation["Decode Stage<br/>file transform"]
  node_native_binary["Native Payload<br/>bundled dylib"]
  node_clean_info["Info Template<br/>plist template<br/>[clean_info.plist]"]
  node_clean_manifest["Manifest Template<br/>plist template"]
end

subgraph group_native["Native stack"]
  node_vendor_stack[("Vendor Stack<br/>native deps")]
end

node_packaging -->|"builds"| node_app_delegate
node_app_delegate -->|"starts"| node_view_controller
node_view_controller -->|"waits for device"| node_usb_detection
node_usb_detection -->|"selects target"| node_device_info
node_view_controller -->|"reports"| node_alerts
node_view_controller -->|"calls into C"| node_bridge_header
node_bridge_header -->|"exposes"| node_lib_device_functions
node_lib_device_functions -->|"uses"| node_vendor_stack
node_device_info -->|"reads via"| node_lib_device_functions
node_view_controller -->|"prepares payload"| node_deobfuscation
node_deobfuscation -->|"unpacks"| node_templates
node_deobfuscation -->|"writes"| node_clean_info
node_deobfuscation -->|"writes"| node_clean_manifest
node_templates -->|"feeds"| node_backup_restore
node_clean_info -->|"consumed by"| node_backup_restore
node_clean_manifest -->|"consumed by"| node_backup_restore
node_backup_restore -->|"executes on"| node_vendor_stack
node_native_binary -->|"supports"| node_deobfuscation
node_view_controller -->|"triggers"| node_backup_restore

click node_app_delegate "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/AppDelegate.swift"
click node_view_controller "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/ViewController.swift"
click node_alerts "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/ExtensionsShit.swift"
click node_usb_detection "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/USBDetection.swift"
click node_device_info "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/iDeviceInfoFunctions.swift"
click node_lib_device_functions "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/libidevicefunctions.c"
click node_backup_restore "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/idevicebackup2.c"
click node_bridge_header "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/MDMPatcher-Bridging-Header.h"
click node_templates "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_archive.zip"
click node_deobfuscation "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/deobfuscation.swift"
click node_native_binary "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/libiMobileeDevice.dylib"
click node_clean_info "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_info.plist"
click node_clean_manifest "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_manifest.plist"
click node_packaging "https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher Universal.xcodeproj/project.pbxproj"

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_app_delegate,node_view_controller,node_alerts,node_packaging toneBlue
class node_usb_detection,node_device_info,node_lib_device_functions,node_backup_restore,node_bridge_header toneAmber
class node_templates,node_deobfuscation,node_native_binary,node_clean_info,node_clean_manifest toneMint
class node_vendor_stack toneRose
```

## Components

### macOS UI

Swift/AppKit entry point, view state, and user feedback

- [App Delegate](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/AppDelegate.swift): App lifecycle · Launches the macOS app and hands control into the main UI flow · `MDMPatcher/AppDelegate.swift`
- [Main Flow](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/ViewController.swift): UI controller · Owns device state, patch action enablement, and user-facing success/error handling · `MDMPatcher/ViewController.swift`
- [UI Alerts](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/ExtensionsShit.swift): UI helper · Alert and feedback helpers used to surface outcomes to the user · `MDMPatcher/ExtensionsShit.swift`
- [App Package](https://github.com/fled-dev/mdmpatcher-enhanced/blob/HEAD/MDMPatcher%20Universal.xcodeproj/project.pbxproj): xcode project · Xcode project, storyboard, assets, and entitlements defining the macOS app bundle · `MDMPatcher Universal.xcodeproj/project.pbxproj`

### Device bridge

USB detection and libimobiledevice-backed device communication

- [USB Detection](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/USBDetection.swift): device monitor · Watches for USB events and filters for supported iOS devices · `MDMPatcher/USBDetection.swift`
- [Device Info](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/iDeviceInfoFunctions.swift): metadata reader · Reads UDID, product type, serial, IMEI, and build/version details · `MDMPatcher/iDeviceInfoFunctions.swift`
- [C Device API](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/libidevicefunctions.c): usb/session bridge · C-side device communication and lower-level libimobiledevice calls · `MDMPatcher/libidevicefunctions.c`
- [Restore Engine](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/idevicebackup2.c): restore orchestrator · Coordinates backup/restore-style execution against the connected device · `MDMPatcher/idevicebackup2.c`
- [Bridge Header](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/MDMPatcher-Bridging-Header.h): interop boundary · Exposes C APIs to the Swift layer · `MDMPatcher/MDMPatcher-Bridging-Header.h`

### File pipeline

Template decoding and per-device restore-package generation

- [Templates](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_archive.zip): bundled inputs · Clean plist/archive templates and packaged payload artifacts used as restore inputs · `MDMPatcher/clean_archive.zip`
- [Decode Stage](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/deobfuscation.swift): file transform · Byte-processing and decoding helpers used to unpack or normalize bundled payloads · `deobfuscation.swift`
- [Native Payload](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/libiMobileeDevice.dylib): bundled dylib · Prebuilt local binary used by the patching workflow · `MDMPatcher/libiMobileeDevice.dylib`
- [Info Template](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_info.plist): plist template · Device-specific Info.plist source for generated restore inputs · `MDMPatcher/clean_info.plist`
- [Manifest Template](https://github.com/fled-dev/mdmpatcher-enhanced/blob/main/MDMPatcher/clean_manifest.plist): plist template · Device-specific Manifest.plist source for generated restore inputs · `MDMPatcher/clean_manifest.plist`

### Native stack

Bundled system libraries and prebuilt binaries used by the C bridge

- **Vendor Stack**: native deps · Curated libimobiledevice, usbmuxd, plist, restore, archive, crypto, and ZIP dependencies

## Connections

- App Package → App Delegate: builds · Xcode builds the AppKit entry point and app bundle
- App Delegate → Main Flow: starts · Launch flow hands control to the main controller
- Main Flow → USB Detection: waits for device · The controller begins by listening for a supported USB-connected iOS device
- USB Detection → Device Info: selects target · Detected devices are filtered and then queried for identity metadata
- Main Flow → UI Alerts: reports · Success, errors, and prompts are surfaced through alert helpers
- Main Flow → Bridge Header: calls into C · Swift reaches the lower-level device and restore APIs through the bridge
- Bridge Header → C Device API: exposes · The bridging header makes the C device API available to Swift
- C Device API → Vendor Stack: uses · C device communication is implemented on top of bundled native libraries
- Device Info → C Device API: reads via · Metadata collection depends on the low-level USB/session layer
- Main Flow → Decode Stage: prepares payload · The main flow triggers local decoding and transformation work before restore
- Decode Stage → Templates: unpacks · Bundled artifacts are decoded or normalized into a device-specific working set
- Decode Stage → Info Template: writes · Info.plist content is rewritten from template data and device metadata
- Decode Stage → Manifest Template: writes · Manifest.plist content is rewritten for the target device
- Templates → Restore Engine: feeds · Prepared backup-like files are consumed by the restore engine
- Info Template → Restore Engine: consumed by · Generated Info.plist data is part of the restore input set
- Manifest Template → Restore Engine: consumed by · Generated Manifest.plist data is part of the restore input set
- Restore Engine → Vendor Stack: executes on · The restore phase runs over the same USB/libimobiledevice native substrate
- Native Payload → Decode Stage: supports · Bundled local binary participates in the patching or decoding pipeline
- Main Flow → Restore Engine: triggers · After preparation, the controller invokes the restore phase
