fix(relinker): reject input executables that are not x86-64 #3809

Merged
aayushmishraaa merged 1 commit from upstream-pr/3809 into main 2026-10-12 13:34:38 +00:00
aayushmishraaa commented 2026-10-11 16:57:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by aayushmishraaa on 2026-10-11T16:57:38Z.


What

ElfReader::ReadHeader validates the ELF identification bytes but not e_machine. An input executable whose e_machine is not x86-64 (62) is relinked to a Linux ELF that keeps the foreign machine value and exits 0; --macos and --windows fail later with Windows-specific messages from the patchers. Guest modules (GuestImageReader) and Windows images (WindowsLoadImage) already require e_machine == 62.

ReadHeader now throws Expected an x86-64 ELF after the identification check. test_elf_header.py covers e_machine 0, 3 and 183 in its four output modes (no output or registry written), and the header-only case sets e_machine so it still reaches No PT_DYNAMIC segment found.

Tested

macOS (Apple Silicon, AppleClang), relinker-only build: the extended elf_header test fails on current main (machine-0 relinks with exit 0) and passes with the change; all 105 relinker ctest tests pass; tools/check_conventions.py --base origin/main passes. Not tested with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820739793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3809). Originally posted by [aayushmishraaa](https://github.com/aayushmishraaa) on 2026-10-11T16:57:38Z. --- ### What `ElfReader::ReadHeader` validates the ELF identification bytes but not `e_machine`. An input executable whose `e_machine` is not x86-64 (62) is relinked to a Linux ELF that keeps the foreign machine value and exits 0; `--macos` and `--windows` fail later with Windows-specific messages from the patchers. Guest modules ([GuestImageReader](core/relinker/relinker/src/guest/GuestImageReader.cpp)) and Windows images ([WindowsLoadImage](core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp)) already require `e_machine == 62`. `ReadHeader` now throws `Expected an x86-64 ELF` after the identification check. `test_elf_header.py` covers `e_machine` 0, 3 and 183 in its four output modes (no output or registry written), and the `header-only` case sets `e_machine` so it still reaches `No PT_DYNAMIC segment found`. ### Tested macOS (Apple Silicon, AppleClang), relinker-only build: the extended `elf_header` test fails on current `main` (`machine-0` relinks with exit 0) and passes with the change; all 105 relinker ctest tests pass; `tools/check_conventions.py --base origin/main` passes. Not tested with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-12 11:45:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T11:45:48Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4441 core/relinker/relinker/src/parsing/ElfReader.cpp L88
core/relinker/relinker/tests/test_elf_header.py L19-21, L42
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123613822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3809#issuecomment-6123613822). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T11:45:48Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4441 | `core/relinker/relinker/src/parsing/ElfReader.cpp` [L88](https://github.com/boykopovar/AnyPS5/blob/a1a9c3db593ff0a03f3a337d6e70974a1032cb3c/core/relinker/relinker/src/parsing/ElfReader.cpp#L88)<br>`core/relinker/relinker/tests/test_elf_header.py` [L19-21](https://github.com/boykopovar/AnyPS5/blob/a1a9c3db593ff0a03f3a337d6e70974a1032cb3c/core/relinker/relinker/tests/test_elf_header.py#L19-L21), [L42](https://github.com/boykopovar/AnyPS5/blob/a1a9c3db593ff0a03f3a337d6e70974a1032cb3c/core/relinker/relinker/tests/test_elf_header.py#L42) | | |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3809
No description provided.