fix(nid): preserve PE forwarders when repacking export names #6912
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6912"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-16T17:53:39Z.
What
Renaming PE exports can overwrite forwarded-export targets while
nid_patcherreports success. With GNU Binutils 2.42, an ordinary DLL exportinga=localandb=KERNEL32.GetCurrentProcessIdplaces a name before the forwarder string. On current main, patching leaves the forwarder RVA at0x304cbut changes its target fromKERNEL32.GetCurrentProcessIdtok3ozzWYBg, part of a replacement NID.Capture forwarded targets before repacking, deduplicate their storage and update every affected export-address entry, including unnamed exports. Preserve the DLL name, original name-to-ordinal associations and direct code/data exports. Update the directory size to cover the packed export strings while checking that every direct export remains outside that range: the PE export-address table format uses the directory bounds to distinguish direct exports from forwarders. Reclaim old string space and refuse before writing the file when new metadata would overlap exported data, change a direct export into a forwarder or exceed available space.
Tested
Linux x86_64, G++ 13.3, GNU Binutils 2.42; built the actual tool from all nine NID sources.
KERNEL32.GetCurrentProcessId, the DLL name, direct code RVA0x1000, every.textbyte and the correct sorted NID-to-ordinal mapping. GNUobjdumpdisplays both full NIDs without corrupt-offset warnings; the directory size grows from0x6bto0x7fwhile direct exports retain their classification. Native Windows loading was not run.test_pe_references.pygroup pass. Coverage includes PE32/PE32+, interleaved strings, named/ordinal/unnamed/shared forwarders, long-name space reclamation, external DLL metadata, direct-data preservation, directory growth and unchanged-file refusal when growth would overwrite exported data or reclassify a direct export. Main fails the forwarder and overlapping-growth regressions.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Baconzido on 2026-10-17T21:41:43Z.
macOS result for the NID Python groups. The description says native Windows loading was not run; this does not cover that either.
Apple M5 Pro (arm64), macOS 27.0.1, Python 3.14.7.
nid_patcheris not part of the relinker-only build, so I built it from the nine sources incore/libs/nid/srcwith AppleClang 21.0.0 (-std=c++20 -O1). Head1295a8001merged ontomain922dc8999(clean merge).test_pe_references.pywith the PR's patcher: 10/10 pass.main'sPeNidPatcher.cpp: 7 of 10 fail (test_directory_grows_to_include_repacked_names,test_directory_growth_cannot_reclassify_a_direct_export,test_name_growth_cannot_overwrite_direct_export_data, andtest_forwarder_targets_and_ordinals_survive_name_repackingfor bits 32/64 × dll_last False/True).test_elf_duplicates4/4,test_elf_layout3/3,test_gnu_hash6/6,test_native_paths3/3,test_shared_strings3/3,test_verneed6/6,test_macho_nidsandtest_symbol_versionspass.test_dynamic_strings.pytakes an ELF file as its argument rather than the patcher, so I did not count it.Not checked: native Windows loading of a repacked DLL, Windows host.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:13:27Z.
Windows run, covering the native loading the description lists as not run.
Radeon 860M (RDNA 3.5), Ryzen AI 7 350, Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.main6efb7261bwith #7432, #6912 and #6893 merged on top (no conflicts, disjoint files).nid_*tests pass, among themnid_pe_references.core/libs/libs/*.prxin this build was patched by this PR'snid_patcher. A title loaded them natively: VLC (PPSA85300 01.000.005), relinked with--windows, reachedrenderingat 39.7 FPS in a 30 s run throughtools/title_run.py(#7264).AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:16:01Z.
Read the diff against the PE export format: forwarder detection uses the directory bounds, direct exports are kept outside the grown range, and the patch refuses before writing when it would overlap exported data or reclassify a direct export. The new tests pin forwarder targets, ordinals and directory size; the macOS negative control (7/10 fail on main's patcher) and the Windows run cover what we can't run here; merged.