Skip to content

fix: support signing unsigned Mach-O binaries without LC_CODE_SIGNATURE#44

Open
messense wants to merge 2 commits intonichmor:mainfrom
messense:codesign-macho-without-sign
Open

fix: support signing unsigned Mach-O binaries without LC_CODE_SIGNATURE#44
messense wants to merge 2 commits intonichmor:mainfrom
messense:codesign-macho-without-sign

Conversation

@messense
Copy link
Copy Markdown

@messense messense commented Apr 2, 2026

Add support for ad-hoc signing Mach-O binaries that don't have an existing LC_CODE_SIGNATURE load command (unsigned binaries).

Changes:

  • Add write_u32/write_u64 helpers that respect binary endianness (ctx.le) instead of hardcoded .to_le_bytes()
  • Extract InsertCodeSigParams struct and insert_code_signature_command_into_buffer() as shared helper for inserting LC_CODE_SIGNATURE into header padding
  • Update generate_adhoc_signature() to parse binary context for endianness
  • Update adhoc_sign() to detect missing LC_CODE_SIGNATURE and insert it
  • Update adhoc_sign_file() to use shared helper for LC_CODE_SIGNATURE insertion

This is for PyO3/maturin#3114 (https://github.com/PyO3/maturin/actions/runs/23901410353/job/69698993401)

Add support for ad-hoc signing Mach-O binaries that don't have an existing
LC_CODE_SIGNATURE load command (unsigned binaries).

Changes:
- Add write_u32/write_u64 helpers that respect binary endianness (ctx.le)
  instead of hardcoded .to_le_bytes()
- Extract InsertCodeSigParams struct and insert_code_signature_command_into_buffer()
  as shared helper for inserting LC_CODE_SIGNATURE into header padding
- Update generate_adhoc_signature() to parse binary context for endianness
- Update adhoc_sign() to detect missing LC_CODE_SIGNATURE and insert it
- Update adhoc_sign_file() to use shared helper for LC_CODE_SIGNATURE insertion
- Add test_sign_unsigned_binary test case
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