relinker: x86 decoder ignores the address of MOV moffs (A0-A3), desynchronising the scanner #1167

Closed
opened 2026-10-07 16:01:43 +00:00 by oguzhanozfe · 0 comments
oguzhanozfe commented 2026-10-07 16:01:43 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oguzhanozfe on 2026-10-07T16:01:43Z.


X64InstructionDecoder::Decode has no case for one-byte opcodes A0-A3 (MOV AL/eAX/rAX, moffs and MOV moffs, AL/eAX/rAX). These have no ModRM byte. In 64-bit mode they carry an 8-byte absolute address, or a 4-byte address with a 0x67 prefix (Intel SDM Vol. 2A §2.2.1.4, "Direct Memory-Offset MOVs"; the MOV table lists REX.W + A1 MOV RAX, moffs64). The decoder adds nothing for the address and returns only the prefix and opcode length. The 0x67 prefix is accepted but not recorded.

Bytes Expected Decode
A1 + 8-byte address 9 1
48 A1 + 8-byte address 10 2
48 A3 + 8-byte address 10 2
64 48 A1 + 8-byte address 11 3
67 A1 + 4-byte address 6 2

InstructionScanner sweeps linearly, so it then decodes the address bytes as instructions. For 48 A1 66 0F 78 C0 08 00 00 00 C3 (movabs rax, [0x8C0780F66]; ret), it returns [0,+2] [2,+6] [8,+2] [10,+1]. The [2,+6] entry is an EXTRQ located inside the address. With --to-intel, that EXTRQ would be rewritten, which corrupts the address.

Reproduced by compiling X64InstructionDecoder.cpp and InstructionScanner.cpp from main (def81199) with MSVC 14.50.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5747977625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1167). Originally posted by [oguzhanozfe](https://github.com/oguzhanozfe) on 2026-10-07T16:01:43Z. --- `X64InstructionDecoder::Decode` has no case for one-byte opcodes `A0`-`A3` (`MOV AL/eAX/rAX, moffs` and `MOV moffs, AL/eAX/rAX`). These have no ModRM byte. In 64-bit mode they carry an 8-byte absolute address, or a 4-byte address with a 0x67 prefix (Intel SDM Vol. 2A §2.2.1.4, "Direct Memory-Offset MOVs"; the MOV table lists `REX.W + A1 MOV RAX, moffs64`). The decoder adds nothing for the address and returns only the prefix and opcode length. The 0x67 prefix is accepted but not recorded. | Bytes | Expected | `Decode` | |---|---|---| | `A1` + 8-byte address | 9 | 1 | | `48 A1` + 8-byte address | 10 | 2 | | `48 A3` + 8-byte address | 10 | 2 | | `64 48 A1` + 8-byte address | 11 | 3 | | `67 A1` + 4-byte address | 6 | 2 | `InstructionScanner` sweeps linearly, so it then decodes the address bytes as instructions. For `48 A1 66 0F 78 C0 08 00 00 00 C3` (`movabs rax, [0x8C0780F66]; ret`), it returns `[0,+2] [2,+6] [8,+2] [10,+1]`. The `[2,+6]` entry is an EXTRQ located inside the address. With `--to-intel`, that EXTRQ would be rewritten, which corrupts the address. Reproduced by compiling `X64InstructionDecoder.cpp` and `InstructionScanner.cpp` from main (def81199) with MSVC 14.50.
Sign in to join this conversation.
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#1167
No description provided.