fix(relinker): add icons to generated Windows executables #350

Merged
QDarkRex merged 2 commits from upstream-pr/350 into main 2026-10-04 04:50:37 +00:00
QDarkRex commented 2026-10-02 11:35:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T11:35:53Z.


What

Embed sce_sys/icon0.png beside the input executable as a PNG RT_ICON with an RT_GROUP_ICON in a read-only .rsrc section. Preserve the PNG bytes, including images larger than 256x256. Missing icons leave resource directory 2 empty. Invalid PNG signatures, IHDR fields, chunk bounds or CRCs fail with the icon path in a RelinkerException.
Use only the C++20 standard library. No new flags or dependencies. Remove the resolved executable-icon technical debt entry. Based on e1654a97.
A malformed icon0.png fails the relink rather than being skipped; removing the file relinks without an icon.

Tested

Windows 11 Home Single Language, build 26200; MinGW-w64 GCC 15.2, Release: all 16 relinker tests pass. The new test fails against unpatched e1654a97 with missing icon resources. It checks the resource tree, group metadata, unchanged PNG bytes, missing icons and 11 malformed files. Windows runs also extract icons and execute the relinked fixtures; non-Windows runs check relinking and resource bytes.
Manual Windows check: Explorer displays generated icons from 32x32, 256x256, 512x512 and 1024x1024 PNGs. A relinked window fixture loads group resource 1 from its executable and displays the 512x512 icon in the title bar and taskbar. Screenshot: the relinked window fixture showing the embedded 512x512 icon in its title bar. No game binaries tested.
Linux: Ubuntu 24.04, GCC 13.3, Release: all 16 relinker tests pass; the new test fails against unpatched e1654a97. llvm-readobj --coff-resources parses the generated resource tree (ICON and GROUP_ICON, ID 1, language 0) and the PNG is embedded byte-for-byte. Without icon0.png, the output is byte-identical to unpatched e1654a97.

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
    S1
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4715947543 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350). Originally posted by [QDarkRex](https://github.com/QDarkRex) on 2026-10-02T11:35:53Z. --- ### What Embed `sce_sys/icon0.png` beside the input executable as a PNG `RT_ICON` with an `RT_GROUP_ICON` in a read-only `.rsrc` section. Preserve the PNG bytes, including images larger than 256x256. Missing icons leave resource directory 2 empty. Invalid PNG signatures, IHDR fields, chunk bounds or CRCs fail with the icon path in a `RelinkerException`. Use only the C++20 standard library. No new flags or dependencies. Remove the resolved executable-icon technical debt entry. Based on `e1654a97`. A malformed `icon0.png` fails the relink rather than being skipped; removing the file relinks without an icon. ### Tested Windows 11 Home Single Language, build 26200; MinGW-w64 GCC 15.2, Release: all 16 relinker tests pass. The new test fails against unpatched `e1654a97` with missing icon resources. It checks the resource tree, group metadata, unchanged PNG bytes, missing icons and 11 malformed files. Windows runs also extract icons and execute the relinked fixtures; non-Windows runs check relinking and resource bytes. Manual Windows check: Explorer displays generated icons from 32x32, 256x256, 512x512 and 1024x1024 PNGs. A relinked window fixture loads group resource 1 from its executable and displays the 512x512 icon in the title bar and taskbar. Screenshot: the relinked window fixture showing the embedded 512x512 icon in its title bar. No game binaries tested. Linux: Ubuntu 24.04, GCC 13.3, Release: all 16 relinker tests pass; the new test fails against unpatched `e1654a97`. `llvm-readobj --coff-resources` parses the generated resource tree (ICON and GROUP_ICON, ID 1, language 0) and the PNG is embedded byte-for-byte. Without `icon0.png`, the output is byte-identical to unpatched `e1654a97`. ### Checklist - [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 <img width="941" height="367" alt="S1" src="https://github.com/user-attachments/assets/c2149542-69f7-4c36-af89-47e4ceb18125" />
adriadam10 commented 2026-10-02 11:39:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T11:39:51Z.


Nice work. ELF has no icon resource, so I'll open a separate PR for the Linux side: next to the output it writes a freedesktop .desktop entry pointing at a copy of sce_sys/icon0.png (title taken from sce_sys/param.json). It won't touch the files or lines changed here, so the two PRs don't conflict.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5951570782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5951570782). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T11:39:51Z. --- Nice work. ELF has no icon resource, so I'll open a separate PR for the Linux side: next to the output it writes a freedesktop `.desktop` entry pointing at a copy of `sce_sys/icon0.png` (title taken from `sce_sys/param.json`). It won't touch the files or lines changed here, so the two PRs don't conflict.
QDarkRex commented 2026-10-02 11:43:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T11:43:34Z.


Thanks! A .desktop entry sounds like the right equivalent for Linux. Since it reads the same file, the PNG validation in WindowsIconResourceBuilder.cpp could be shared if useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5951639456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5951639456). Originally posted by [QDarkRex](https://github.com/QDarkRex) on 2026-10-02T11:43:34Z. --- Thanks! A .desktop entry sounds like the right equivalent for Linux. Since it reads the same file, the PNG validation in WindowsIconResourceBuilder.cpp could be shared if useful.
adriadam10 commented 2026-10-02 11:48:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T11:48:45Z.


Thanks! Opened #353. It keeps a minimal signature/IHDR check so the two PRs stay independent and conflict-free; once this one lands I'll follow up moving validatePng to a shared place and use it from both sides.

One note on the test: CONTRIBUTING says Python is optional and that without it some relinker tests aren't registered, so test_windows_icon.py may silently not run. In #353 I wrote it as a C++ test that calls the writer directly (elfpatcher/tests/LinuxDesktopEntryTests.cpp, like file_writer_tests) so it always runs with ctest. A C++ test over WindowsIconResourceBuilder would get the same guarantee here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5951726683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5951726683). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T11:48:45Z. --- Thanks! Opened #353. It keeps a minimal signature/IHDR check so the two PRs stay independent and conflict-free; once this one lands I'll follow up moving `validatePng` to a shared place and use it from both sides. One note on the test: CONTRIBUTING says Python is optional and that without it some relinker tests aren't registered, so `test_windows_icon.py` may silently not run. In #353 I wrote it as a C++ test that calls the writer directly (`elfpatcher/tests/LinuxDesktopEntryTests.cpp`, like `file_writer_tests`) so it always runs with ctest. A C++ test over `WindowsIconResourceBuilder` would get the same guarantee here.
adriadam10 commented 2026-10-02 11:55:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T11:55:02Z.


The red Linux check isn't caused by this PR: the relinker tests all pass, including windows_icon. The failure is agc_driver_vopc_compare on lavapipe (thread 1 compare 39 is 0, expected 1). That's a shader test from my #259. The same failure, with the same thread and compare, shows up in unrelated PRs that ran at about the same time (pr/savedata-delete-dir-name, fix/kernel-nooverwrite-win, fix/tlou-runtime-funcs). Other runs on the same base e1654a97 (main, #353) pass with the same image and Mesa. I'm looking into it on my side; a CI re-run should get this one green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5951815475 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5951815475). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T11:55:02Z. --- The red Linux check isn't caused by this PR: the relinker tests all pass, including `windows_icon`. The failure is `agc_driver_vopc_compare` on lavapipe (`thread 1 compare 39 is 0, expected 1`). That's a shader test from my #259. The same failure, with the same thread and compare, shows up in unrelated PRs that ran at about the same time (`pr/savedata-delete-dir-name`, `fix/kernel-nooverwrite-win`, `fix/tlou-runtime-funcs`). Other runs on the same base `e1654a97` (main, #353) pass with the same image and Mesa. I'm looking into it on my side; a CI re-run should get this one green.
QDarkRex commented 2026-10-02 13:54:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T13:54:34Z.


Added elfpatcher/tests/WindowsIconResourceTests.cpp, registered without the Python condition so it always runs with ctest. It checks the empty and missing icon cases, the .rsrc tree entries and the unchanged PNG bytes, and that a malformed PNG fails with its path. test_windows_icon.py stays for the end-to-end check through the relinker.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5953945464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5953945464). Originally posted by [QDarkRex](https://github.com/QDarkRex) on 2026-10-02T13:54:34Z. --- Added elfpatcher/tests/WindowsIconResourceTests.cpp, registered without the Python condition so it always runs with ctest. It checks the empty and missing icon cases, the .rsrc tree entries and the unchanged PNG bytes, and that a malformed PNG fails with its path. test_windows_icon.py stays for the end-to-end check through the relinker.
QDarkRex commented 2026-10-02 14:23:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-02T14:23:07Z.


Thanks for looking into the agc_driver_vopc_compare failure! In case it helps narrow it down: it now shows up on main too. The push build of 313de1c (merge of #289) fails with the same thread 1 compare 39 is 0, expected 1, and so does feat/sync-on-address. Happy to run anything on my side if that's useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5954561918 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5954561918). Originally posted by [QDarkRex](https://github.com/QDarkRex) on 2026-10-02T14:23:07Z. --- Thanks for looking into the `agc_driver_vopc_compare` failure! In case it helps narrow it down: it now shows up on main too. The push build of 313de1c (merge of #289) fails with the same `thread 1 compare 39 is 0, expected 1`, and so does `feat/sync-on-address`. Happy to run anything on my side if that's useful.
oneandonlydean commented 2026-10-04 01:43:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T01:43:57Z.


This now conflicts with main: #430 added its TechnicalDebt line in the same place. Could you rebase? Otherwise it looks good to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5975493313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5975493313). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T01:43:57Z. --- This now conflicts with main: #430 added its TechnicalDebt line in the same place. Could you rebase? Otherwise it looks good to merge.
QDarkRex commented 2026-10-04 03:38:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-10-04T03:38:33Z.


Rebased onto main (33a2f90). The only conflict was the TechnicalDebt line: the icon entry is removed and #430's --to-intel wording is kept as is. Relinker tests pass on Windows (MinGW 15.2) and Linux (GCC 13), including windows_icon and windows_icon_resource. Thanks for the review!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5976224104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/350#issuecomment-5976224104). Originally posted by [QDarkRex](https://github.com/QDarkRex) on 2026-10-04T03:38:33Z. --- Rebased onto main (33a2f90). The only conflict was the TechnicalDebt line: the icon entry is removed and #430's `--to-intel` wording is kept as is. Relinker tests pass on Windows (MinGW 15.2) and Linux (GCC 13), including `windows_icon` and `windows_icon_resource`. Thanks for the review!
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!350
No description provided.