Commit Graph

189 Commits

Author SHA1 Message Date
Adrià 2959dc5318
Merge pull request #1168 from oguzhanozfe/fix/decoder-moffs-length
fix(relinker): decode the 64-bit address of MOV moffs instructions
2026-10-08 10:39:59 +02:00
Adrià 8388121a4f
Merge pull request #1153 from ebarr24/codex/windows-gui-error-status
fix(relinker): preserve GUI startup failure status without stderr
2026-10-08 10:26:56 +02:00
Adrià 17440abe24
Merge pull request #1165 from oguzhanozfe/fix/linux-dynstr-runpath-size
fix(relinker): include the run path in the Linux DT_STRSZ
2026-10-08 10:25:19 +02:00
Adrià 61896dea23
Merge pull request #1163 from oguzhanozfe/fix/decoder-rexw-immediate-size
fix(relinker): let REX.W override 0x66 when sizing decoder immediates
2026-10-08 10:23:35 +02:00
Adrià f51eeff059
Merge pull request #1117 from TideOPL/fix/relinker-tls-unreached-code
fix(relinker): find Windows guest TLS accesses in code no root reaches
2026-10-08 09:54:40 +02:00
Adrià 66b8abd8e6
Merge pull request #1101 from eliasbruno124-dev/fix/relinker-windows-guest-filenames
fix(relinker): resolve Windows guest filename casing
2026-10-08 08:43:35 +02:00
Adrià 7a178e2276
Merge pull request #1089 from AaravMehta-07/fix/relinker-registry-json
fix(relinker): escape control characters in call registry JSON
2026-10-08 08:10:07 +02:00
Adrià Franch 4e69584edf test(relinker): pin RELA bounds check with malformed-ELF cases
Co-authored-by: Dextroid17 <noreply@github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-08 07:52:32 +02:00
Fynn Jannis Schulz 9ff9d4325c fix(relinker): share RELA entry bounds check with extractRelative 2026-10-08 07:52:23 +02:00
Fynn Jannis Schulz cfba9c09d2 fix(relinker): overflow-safe RELA entry bounds check 2026-10-08 07:52:23 +02:00
Dean 4a435af58a
Merge pull request #1103 from ctz23/test/windows-icon-distinct-output-20261007
test(relinker): use distinct executables in Windows icon tests
2026-10-08 18:28:01 +13:00
Hashaam Zafar 71b9cf3d0d test(relinker): run the Windows TLS cases on Linux x86-64
tls_function_coverage ran its execution cases only on Windows; on
Linux it checked bytes. windows_image_runner.py maps the relinked PE,
points GS at a TEB whose TLS slot holds a block copied from the
template, runs the TLS callbacks for process attach with the Windows
argument registers and calls the guest entry. convert() uses it on
Linux x86-64 and expects 42, as on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 11:52:14 -07:00
Ethan Barr 2ed81aebe4 fix(relinker): preserve GUI startup failure status without stderr 2026-10-07 09:38:56 -07:00
Oguzhan Ozdemir e8f73a5531 fix(relinker): decode the 64-bit address of MOV moffs instructions
A0-A3 (MOV AL/eAX/rAX to and from moffs) have no ModRM byte and carry an
8-byte absolute address in 64-bit mode, or 4 bytes with a 0x67 prefix.
The decoder added nothing for the address, so the linear scanner decoded
the address bytes as code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 19:00:37 +03:00
Oguzhan Ozdemir cf8b7315b6 fix(relinker): include the run path in the Linux DT_STRSZ
The Linux patcher appends the DT_RUNPATH string after the copied
.dynstr data but kept DT_STRSZ and the .dynstr section size at the size
of the copied data, so DT_RUNPATH pointed at the first byte past the
declared string table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 18:58:42 +03:00
ctz23 80120faf8e test(relinker): use distinct executables in Windows icon tests 2026-10-07 17:57:06 +02:00
eliasbruno124-dev ba3e75a100 fix(relinker): resolve Windows guest filename casing 2026-10-07 17:55:28 +02:00
Oguzhan Ozdemir d64c0605ea fix(relinker): let REX.W override 0x66 when sizing decoder immediates
In 64-bit mode REX.W takes precedence over the 0x66 operand-size prefix,
so the immediate of 81, C7, 69, 68, A9, the 05..3D accumulator forms and
the F7 TEST form stays imm32. The decoder only applied this to B8+r and
returned a length two bytes short for the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 18:51:56 +03:00
Adrià f71bf7fd40
Merge pull request #716 from merwie/feat/relinker-needed-modules-outside-module-dirs
feat(relinker): relink needed modules outside the module directories
2026-10-07 17:51:47 +02:00
Adrià Franch 9f3ac9a5bd test(relinker): register the --to-intel stub test next to the relinker tests
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-07 16:03:41 +02:00
Adrià Franch 14dc9b31ab test(relinker): add C++ end-to-end fixture and --to-intel Linux stub test
Add header-only support for end-to-end relinker tests: a minimal PS5
executable builder, a PT_LOAD mapper that applies segment permissions,
and a posix_spawn runner for the relinker binary. Every
core/relinker/tests/e2e/*.cpp becomes its own test, so new tests do not
touch CMake.

The first test relinks an executable with EXTRQ and INSERTQ sites using
--to-intel, maps the output and calls the patched code, which runs both
stubs from their Linux segment and returns through their branches.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-07 16:03:26 +02:00
TideOPL e6467c4dff fix(relinker): find Windows guest TLS accesses in code no root reaches
The Windows TLS rewriter only patches instructions that
CodeInstructionCollector finds: symbol and unwind function ranges, plus
the code their branches, relocated pointers and initializers reach. A
fixed-address executable (ET_SCE_EXEC) has no relocations for function
pointers held in data, such as vtables or a thread entry loaded with
LEA, and its unwind tables need not cover every function. TLS accesses
in that code stayed `mov reg, fs:[0]`, which reads address 0 on Windows.

PPSA16064 (Minecraft Dungeons II, Unreal Engine) has 3689 such loads in
its executable segment; 478 were left unpatched, and its worker threads
faulted on their first TLS access at start-up.

The collector now also sweeps each executable segment linearly from the
first address that int3 padding precedes on a 16-byte boundary, and adds
every FS-prefixed instruction with an absolute disp32 operand as a root.
The sweep resynchronizes at the next padded 16-byte boundary when an
instruction does not decode, crosses such a boundary or starts with two
zero bytes, so zero-filled or undecodable bytes are not read as code.
The rewriter's own checks still decide which forms it can patch.

With this, all 3689 loads in PPSA16064 are patched. New cases in
tls_function_coverage: a padded function nothing references is patched,
and the same load behind zero fill after padding is left unchanged.
2026-10-07 14:08:12 +01:00
Aarav 8ab22b0954 fix(relinker): escape control characters in call registry JSON 2026-10-07 16:05:40 +05:30
Dean 0e58c7034f
Merge pull request #837 from MathiasDevelopes/claude/relinker-shared-elf-constants
refactor(relinker): use the shared ELF constants
2026-10-07 15:24:05 +13:00
Dean c0eb929c09
Merge pull request #930 from ebarr24/fix/relinker-dynamic-segment-bounds
fix(relinker): reject malformed dynamic segments
2026-10-07 15:16:45 +13:00
Dean 293d1218e9
Merge pull request #684 from nicolasabosch/fix/windows-import-module-binding
fix(relinker): bind Windows imports to their declared modules
2026-10-07 15:16:03 +13:00
Arjen Singh 6ac3ad5d1d fix(relinker): quote literal autorun paths on POSIX 2026-10-06 16:18:01 -07:00
Nicolas Abosch b12ef2cf20 fix(relinker): fall back to unqualified lookup for unmatched import modules
A qualified import whose module name matches no DT_NEEDED entry now uses
the unqualified search order instead of failing with "Import module is
not a dependency". Restore the Linux rejection of duplicate exports
within one guest module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 16:48:10 -03:00
Ethan Barr cd0e534db3 fix(relinker): reject malformed dynamic segments 2026-10-06 10:42:19 -07:00
Claude 897d538649
refactor(relinker): use the shared ELF constants
The relinker redefined 61 ELF constants 93 times across seven files,
38 of them already in elfpatcher's ElfConstants.hpp. Add the missing
dynamic tags, relocation types and symbol constants to that header and
remove the local copies; every value is unchanged. strict_nid_filter_tests
compiles these sources and now gets the elfpatcher include directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MBXJqzgohLeVAeHsn4Jpm7
2026-10-06 08:26:50 +00:00
Dean 109a3281f8
Merge pull request #767 from 011010/feat/relinker-windows-tls-alu-reads
feat(relinker): support Windows guest TLS reads by ALU instructions
2026-10-06 16:35:21 +13:00
Nicolas Abosch e96e9c18cc fix(relinker): map module name aliases to declared dependencies 2026-10-05 22:47:35 -03:00
Nicolas Abosch bf0ee4019d fix(relinker): bind Windows imports to their declared modules 2026-10-05 22:43:25 -03:00
011010 7edf5d2ec2 fix(relinker): derive ZF from the subtraction in ALU execution tests
The cmp-equal execution case computed ZF from the untouched destination operand instead of the comparison result, so the self-check took the failure path and the Windows CI job failed with exit code 8. Derive ZF from the real subtraction for sub/cmp and from the real sum for add.
2026-10-05 19:39:50 -06:00
Dean bd8aa57775
Merge pull request #698 from merwie/fix/relinker-guest-absolute-symbols
fix(relinker): accept absolute symbols in guest modules
2026-10-06 13:19:30 +13:00
husari.orozco 31e9e67f54 fix(relinker): keep the original rax and rcx in ALU TLS reads
loadPointer overwrites rax and rcx, so a destination of rax or rcx
computed the operation against the thread pointer or the TLS index
instead of the original register. Restore the destination before the
operation for both, and include rcx in the byte-level cases, which
previously covered only rax, rbx, r8 and r13.

Add self-checking execution cases for rax, rcx and rbx destinations:
each verifies the result, the preservation of the other two registers
and the ZF and CF bits.
2026-10-05 17:50:50 -06:00
Nahuel Genchi 5fab03e4e5 fix(relinker): keep host prx references out of guest modules on Linux
On Linux every module resolves its references through one global scope,
and the guest modules are listed ahead of the host prx. When a title
bundles its own libc.prx, the host libc and the other host prx bound
their references to their own NIDs to the guest libc, so the host libc
built its standard streams on top of the guest _Stdout.

The exports of guest modules, and the guest and executable imports that
a guest module satisfies, now carry a #guest suffix. The title's imports
still reach the guest modules first, and a host prx only sees host
definitions, as on Windows. sceKernelDlsym also looks for the suffixed
name.
2026-10-05 19:58:39 -03:00
husari.orozco abdf673b1e feat(relinker): support Windows guest TLS reads by ALU instructions
Recognize the read-direction ALU forms (add, or, adc, sbb, and, sub, xor,
cmp) that read a qword from fs:[disp32], such as the stack canary check
`xor rbx, fs:[0x28]` emitted by stack-protected functions. They were
rejected as unsupported, which blocked titles relinked on Windows.

The stub loads the TLS value and applies the operation in place, keeping
the final operation as the last flag-setting instruction and preserving
the accumulator and counter. A destination of rax uses rdx as the value
scratch so the original accumulator survives.

Refs #217
2026-10-05 16:16:46 -06:00
Dean bc24783e5b
Merge pull request #733 from alfalfa-star/fix/relinker-duplicate-guest-exports
fix(relinker): allow duplicate Linux guest exports that no module imports
2026-10-06 10:34:07 +13:00
Dean 7580b9e44c
Merge pull request #679 from Celegans12/fix/relinker-windows-low-entropy-stacks
fix(relinker): keep Windows startup stacks below the guest arena
2026-10-06 07:57:17 +13:00
Dean cd8b6f3fcb
Merge pull request #662 from NumberGuan/codex/fix-autorun-exit-status
fix(relinker): decode autorun exit status for the host
2026-10-06 07:56:24 +13:00
alfalfa-star ee2b3be52f fix(relinker): allow duplicate Linux guest exports that no module imports
Guest modules a title opens with sceKernelLoadStartModule are looked up
through their own handle, so several modules may export the same name:
every Wwise plugin exports g_pAKPluginList. On Linux a duplicate now
fails only when the executable or a guest module imports it, as the
provider would be ambiguous. Windows keeps rejecting duplicates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 20:21:11 +02:00
Merijn d52a5f0169 feat(relinker): relink needed modules outside the module directories
Unity titles keep modules the executable needs in Media/Modules
(PPSA12544: Il2cppUserAssemblies.prx and PS5Util.prx), outside sce_module
and prx, so they were left as host libraries and startup failed to load
them. A DT_NEEDED module of the executable that is not in a module
directory is now searched for under the input directory and relinked like
the others; two ELF files with the name are ambiguous. Guest outputs keep
their directory relative to the input instead of only its last component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:41:59 +02:00
Merijn f524a27a8f fix(relinker): accept absolute symbols in guest modules
Guest modules may define symbols in SHN_ABS (0xfff1), for example the
151 library marker symbols of PPSA12544's Il2cppUserAssemblies.prx.
The reader no longer rejects them or checks their value as a mapped
address, relocations against them write the absolute value without a
base relocation, and they are not exported: a PE export is an RVA, so an
import of one fails at startup as an unresolved import. Other special
sections are still rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:37:35 +02:00
Celegans12 823c3caf4f fix(relinker): keep Windows startup stacks below the guest arena
The PE writer marked relocatable executables HIGH_ENTROPY_VA. Windows
then places the main thread stack, TEB, PEB and the loader threads'
stacks, which exist before libc reserves the guest arena from
0x2_0000_0000, anywhere in the first TiB. Nearly half the time they
land inside the arena and stay there as holes that fixed guest
mappings cannot use.

DllCharacteristics is now 0x140 (DYNAMIC_BASE, NX_COMPAT). The image
is still relocated and bottom-up allocations keep the 8-bit
randomization, but they start near the bottom of the address space,
far below the arena. DLL placement does not depend on this flag.

windows_address_space checks the flags and, on Windows, runs a
relinked guest that returns the high dword of its stack pointer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:51:50 +02:00
Tomás Ortellado 1fa44c7b5c fix(relinker): decode autorun exit status for the host 2026-10-05 09:23:47 -03:00
Tomás Ortellado 9f9e4e28b8 fix(relinker): reject invalid and overflowing alignment 2026-10-05 08:44:55 -03:00
Dean Galvin 7103f390cf fix(relinker): keep the host libc.prx needed on Linux when a title bundles its own
A title that ships sce_module/libc.prx makes addHost drop the host
libc.prx from the executable's dependencies. Every host prx needs it, but
their DT_RUNPATH is empty, so loading fails with "libc.prx: cannot open
shared object file".

Mirror the Windows rule from WindowsImportBuilder: when libSceLibcInternal.prx
is a host dependency and no host libc.prx remains, append libc.prx as the
last host dependency. The title's own imports still bind to the guest
modules first.

Refs #476
2026-10-05 20:36:29 +13:00
Nicolas Abosch 93efde8056 fix(relinker): merge function symbol alias extents 2026-10-05 01:50:14 -03:00
NumberGuan 75f407b926 fix(relinker): discover bundled modules in prx directories
Preserve each bundled module directory under app0 and resolve Linux dependencies across directories. Add integration coverage for both output formats and Windows startup. Refs #556; duplicate-export rejection remains unchanged.
2026-10-04 23:22:50 -03:00