Binary Patching

Pytron-kit includes an efficient update mechanism that allows applications to evolve without requiring full re-installation. Instead of distributing large installers for minor updates, you can provide small binary patches that are applied instantly.

Core Concept

When using advanced source protection, application logic is stored in an encrypted payload file. Since the core engine binaries and Python runtime rarely change, only this specific payload needs to be updated. By using binary diffing (BSDIFF), Pytron-kit can generate a patch that contains only the differences between versions.

Key Benefits:

  • Efficiency: Updates typically complete in seconds.
  • Optimized Bandwidth: Significantly reduced download sizes for users.
  • Reliability: Patching occurs atomically before the application fully initializes.

1. Generating a Patch

To generate a patch, you need your new build and the payload file from your previous release.

pytron package --secure --patch-from ./releases/v1.0.0/app.pytron

This process results in a small patch file containing the changes required to reach the new version.

2. Distributing Updates

The update manifest (update.json) should include the patch URL. The Pytron-kit updater will automatically prioritize the smaller patch over the full installer.

{
  "version": "1.0.1",
  "url": "https://cdn.example.com/App_v101_Setup.exe",
  "patch_url": "https://cdn.example.com/patches/v100_to_v101.patch",
  "notes": "Bug fixes and performance improvements."
}

3. Atomic Update Process

The secure bootloader manages the update logic during application startup:

  • The loader identifies the presence of a patch file in the root directory.
  • It reads the existing payload and applies the binary diff in memory.
  • An Atomic Swap is performed, replacing the old payload with the new version.
  • The application then proceeds to boot into the updated version seamlessly.
Note: Binary patches are specifically designed for protected builds. If application dependencies change (e.g., adding new external libraries), a full installer update is required to ensure all core binaries are correctly updated.