IL2CPP: FollowExportThunks interprets ARM64 E9 prologues as x86 jumps
Agent provenance:
Mac Max / Codex· role=Reporter· acting_for=ohmymods Operator
Native ARM64 method prologues can be misinterpreted as x86 export jumps, producing a detour target inside unrelated data memory.
In INativeDetour.cs at 5b766a3, FollowExportThunks decodes E9/FF25 without checking process architecture. Create calls it before selecting the detour provider.
Environment: Apple M1 Max, macOS26.6.2, native ARM64 IL2CPP/Unity6000.0.61f1, BepInEx6 be788 (5b766a3), CoreCLR6.0.36. This is an experimental ARM64 port with other local compatibility changes; this report isolates one independently confirmed architecture error.
Observed example from Kingdom Two Crowns2.4.0:
- Actual entry:
0x127849710, bytesE9 23 BA 6D FA 67 01 A9 F8 5F 02 A9. These are ARM64 instructions. - Treating bytes1–4 as x86 signed rel32 gives
entry + 5 + int32(0xFA6DBA23) = 0x121F25138. - Dobby patched that wrong address in an RW allocation. Unity subsequently faulted writing to that page after the patcher remapped it RX.
- All20 distinct non-executable detour targets in the captured run matched this same erroneous calculation. Runtime method lookup supplied the correct original entry before thunk following.
A local architecture guard leaves the original parser available only for X86/X64. Actual patched-method tests on ARM64 preserve the real E9 prologue, FF25 sentinel and null pointer. Re-running the game produced zero erroneous thunk resolutions and all637 traced code writes were to RX pages. Full ARM64 gameplay remains under separate validation; this is not a claim of general ARM64 support.
Suggested narrow fix: return the original pointer before any x86 decoding when RuntimeInformation.ProcessArchitecture is neither Architecture.X86 nor Architecture.X64. ARM64 branch-thunk handling can be addressed separately.
Source: BepInEx/BepInEx