Skip to content

Fix/libirecovery api compatibility - #66

Open
rarebyteforge wants to merge 4 commits into
tr4m0ryp:mainfrom
rarebyteforge:fix/libirecovery-api-compatibility
Open

Fix/libirecovery api compatibility#66
rarebyteforge wants to merge 4 commits into
tr4m0ryp:mainfrom
rarebyteforge:fix/libirecovery-api-compatibility

Conversation

@rarebyteforge

Copy link
Copy Markdown

Summary

Add compatibility layer to support both legacy and modern versions of libirecovery.

Problem

Modern libirecovery (2024+) introduced breaking API changes:

  • Renamed pid field to cpid in irecv_device_info struct
  • Removed IRECV_SEND_OPT_DFU_NOTIFY_FINISH constant

This caused compilation failures on systems with the updated libirecovery, while the codebase was previously only compatible with older versions.

Solution

Implement a centralized compatibility layer that:

  • Detects available API at build time via pkg-config
  • Provides macro irecv_get_device_id(info) to abstract device ID field access
  • Defines missing constants as safe fallbacks (e.g., IRECV_SEND_OPT_DFU_NOTIFY_FINISH → 0)
  • Includes comprehensive documentation for troubleshooting

Changes

  • NEW: include/compat/libirecovery_compat.h – Compatibility header with macros and inline functions
  • NEW: COMPATIBILITY.md – Detailed guide for both APIs, build configuration, and troubleshooting
  • MODIFIED: Makefile – Auto-detection of libirecovery features via grep on pkg-config headers
  • MODIFIED: src/bypass/path_a_ramdisk.c – Use compatibility layer for DFU notify flag
  • MODIFIED: src/bypass/path_b_identity.c – Use compatibility layer for device ID field

Compatibility

Works with:

  • Modern libirecovery (2024+): cpid field, no dfu_notify flag
  • Legacy libirecovery (pre-2024): pid field, dfu_notify flag available
  • Ubuntu 24.04 LTS, Arch Linux, and older Debian/Ubuntu systems

- Replace info->pid with info->cpid for new libirecovery versions
- Add #ifdef guards for HAVE_PID_FIELD to support older libirecovery
- Wrap IRECV_SEND_OPT_DFU_NOTIFY_FINISH in #ifdef for compatibility
- Fallback to irecv_send_file(client, path, 0) when flag is unavailable

Fixes compilation against modern Ubuntu/Arch with current libirecovery headers
Maintains backward compatibility with older libirecovery versions
Explains API differences between old and new libirecovery versions and how
tr4mpass handles both through the compatibility layer
Centralized version detection and API normalization for:
- PID vs CPID field differences between old and new libirecovery
- DFU notify finish flag availability

Provides single point of truth for compatibility handling
- path_b_identity.c: Replace direct info->pid with irecv_get_device_id() macro
- path_a_ramdisk.c: Use compatibility layer for DFU_NOTIFY_FINISH flag
- Both files now import compat/libirecovery_compat.h for API normalization
- Works transparently with both old (pid) and new (cpid) libirecovery versions
- Update Makefile with automatic API detection during build

All changes maintain the same functionality while being cleaner and more maintainable.
@rarebyteforge

rarebyteforge commented Jul 1, 2026

Copy link
Copy Markdown
Author

Merge Justification – Fix/libirecovery API Compatibility

This PR resolves critical build failures caused by breaking changes in modern libirecovery (2024+). Without these fixes, tr4mpass cannot be compiled on current Ubuntu or Arch systems.

Key Issues Addressed

  • struct irecv_device_info field rename (pidcpid).
  • Removal of IRECV_SEND_OPT_DFU_NOTIFY_FINISH constant.

Solution

  • Introduced a compatibility header (libirecovery_compat.h) that abstracts API differences:
    • irecv_get_device_id(info) macro for device ID access.
    • Safe fallback for missing constants (IRECV_SEND_OPT_DFU_NOTIFY_FINISH → 0).
  • Updated affected source files to use the compatibility layer.
  • Added COMPATIBILITY.md with guidance for developers.
  • Modified Makefile for auto‑detection of libirecovery features.

Benefits

  • Ensures clean builds on both legacy and modern libirecovery versions.
  • Tested successfully on Ubuntu 24.04 LTS, Arch Linux, and older Debian/Ubuntu releases.
  • Improves developer experience by removing the need for manual source edits or toggling flags.
  • Future‑proofs the codebase: any further libirecovery changes can be isolated in the compatibility header.

Recommendation
This PR should be merged promptly to restore build stability for all contributors and users. It eliminates recurring compilation errors and provides a maintainable path forward.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants