fix(nid): preserve PE export forwarders when repacking names #2268

Closed
SzymonLeja wants to merge 1 commit from upstream-pr/2268 into main
SzymonLeja commented 2026-10-09 14:03:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SzymonLeja on 2026-10-09T14:03:42Z.


What

Fix the Windows PE NID patcher corrupting valid forwarded exports while repacking
renamed export strings.

The patcher now:

  • Detects forwarder strings through export address table RVAs.
  • Validates forwarder bounds.
  • Preserves forwarder strings while allocating renamed exports.
  • Expands the export data-directory and section metadata when required.
  • Rejects layouts without enough safe space.
  • Adds PE32 and PE32+ regression coverage.

Tested

  • cmake --build build --target libs (passed)
  • nid_patcher_pe_forwarders (passed)
  • patched_libraries (passed)
  • tools/check_conventions.py --base origin/main (passed)
  • tools/check_test_registration.py build: 444 executables, no new exceptions (passed)
  • git diff --check (passed)
  • Reproduced the original corruption with a MinGW-generated forwarded DLL.
  • Verified the patched DLL with objdump -p.
  • Verified both NID exports resolve to the matching KERNEL32 addresses using LoadLibrary and GetProcAddress.

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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: None
  • AI-assisted: Yes

 #2170  and  #2247  touch the same CMake test-registration block, but neither implements or is required by this PE forwarder fix.  Depends on: None .

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801505624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2268). Originally posted by [SzymonLeja](https://github.com/SzymonLeja) on 2026-10-09T14:03:42Z. --- ### What Fix the Windows PE NID patcher corrupting valid forwarded exports while repacking renamed export strings. The patcher now: - Detects forwarder strings through export address table RVAs. - Validates forwarder bounds. - Preserves forwarder strings while allocating renamed exports. - Expands the export data-directory and section metadata when required. - Rejects layouts without enough safe space. - Adds PE32 and PE32+ regression coverage. ### Tested - `cmake --build build --target libs` (passed) - `nid_patcher_pe_forwarders` (passed) - `patched_libraries` (passed) - `tools/check_conventions.py --base origin/main` (passed) - `tools/check_test_registration.py build`: 444 executables, no new exceptions (passed) - `git diff --check` (passed) - Reproduced the original corruption with a MinGW-generated forwarded DLL. - Verified the patched DLL with `objdump -p`. - Verified both NID exports resolve to the matching KERNEL32 addresses using `LoadLibrary` and `GetProcAddress`. ### 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`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code added - [x] Generic behaviour, not specific to one title - [x] Depends on: None - [x] AI-assisted: Yes  #2170  and  #2247  touch the same CMake test-registration block, but neither implements or is required by this PE forwarder fix.  Depends on: None .
github-actions[bot] commented 2026-10-09 14:34:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T14:34:43Z.


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
#2170 core/libs/CMakeLists.txt L133
#2247 core/libs/CMakeLists.txt L133
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083047469 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2268#issuecomment-6083047469). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T14:34:43Z. --- <!-- 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 | |---|---|---|---| | #2170 | `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/CMakeLists.txt#L133) | | | | #2247 | `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/CMakeLists.txt#L133) | | |
SzymonLeja commented 2026-10-09 16:39:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SzymonLeja on 2026-10-09T16:39:17Z.


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
#2170 core/libs/CMakeLists.txt L133
#2247 core/libs/CMakeLists.txt L133

 #2170  and  #2247  touch the same CMake test-registration block, but neither implements or is required by this PE forwarder fix.  Depends on: None .

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085141742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2268#issuecomment-6085141742). Originally posted by [SzymonLeja](https://github.com/SzymonLeja) on 2026-10-09T16:39:17Z. --- > 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 > #2170 `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/d70b89989473ba1f6ae13e44e079e67f1f8a44b0/core/libs/CMakeLists.txt#L133) > #2247 `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/d70b89989473ba1f6ae13e44e079e67f1f8a44b0/core/libs/CMakeLists.txt#L133)  #2170  and  #2247  touch the same CMake test-registration block, but neither implements or is required by this PE forwarder fix.  Depends on: None .
oneandonlydean commented 2026-10-09 20:10:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:10:58Z.


Closing: none of our libraries has a forwarded export and PE32 isn't built, so nothing reaches this path today. Please reopen if a library gains a forwarder.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088456666 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2268#issuecomment-6088456666). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:58Z. --- Closing: none of our libraries has a forwarded export and PE32 isn't built, so nothing reaches this path today. Please reopen if a library gains a forwarder.

Pull request closed

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!2268
No description provided.