[PR #1483] x64_recomp: 0F 01 /r needs its ModRM byte (X64-RECOMP-GROUP7) #1513

Open
opened 2026-11-26 20:21:30 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1483
Author: @kett1m
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: x64-recomp-grp7


📝 Commits (1)

  • c1df54c x64_recomp: 0F 01 /r is a ModRM group, so the walk stops one byte late (X64-RECOMP-GROUP7)

📊 Changes

3 files changed (+59 additions, -5 deletions)

View changed files

📝 docs/mobile.md (+15 -4)
📝 tests/test_x64_recomp.py (+20 -0)
📝 tools/x64_recomp.py (+24 -1)

📄 Description

tools/x64_recomp.py's 0F table has no entry for opcode 0x01, so the whole
system-instruction group decoded as the unknown op0f_01 of two bytes. Every form of
0F 01 /r carries a ModRM byte: the memory forms are SGDT/SIDT/LGDT/LIDT/SMSW/LMSW/INVLPG, and
the register forms are whole ModRM bytes (MONITOR, MWAIT, XGETBV, XSETBV, CLZERO, MONITORX,
MWAITX, RDTSCP, SWAPGS, the VMX/SVM instructions). The walk stopped after the two opcode bytes,
so every instruction after it in the function was read at the wrong offset.

Measurement

A per-instruction differential against GNU objdump over the retail image's .text: objdump's
linear walk and the decoder's walk read the same bytes and the instruction lengths are compared
(objdump -d --start-address/--stop-address over the section, 26,674,180 objdump instructions).
The image is game_scarlett_master.exe, SHA-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993. REA measured the section
ranges with gnu.objdump section_headers, evidence
ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90: .text VMA
0x140001000, file 0x400, size 0x5f3f966; .pdata VMA 0x14abcf000, file 0x6e03a00.

The differential flags 16 0F 01 boundaries, all one byte short before the fix:

  • 10 clzero, RVAs 0x4e89a70 to 0x4e89bb4, in two neighbouring .pdata functions
    (0x4e899c0 and 0x4e89b80). The first sits at the head of the title's 64-byte zeroing loop
    (clzero; add $0x40,%rax; cmp %r10,%rax; jb back to it), so these run, they are not
    stray data.
  • 2 xgetbv, RVAs 0x21ae7b5 and 0x55e8e92.
  • 2 monitorx, RVAs 0x4fafbd7 and 0x4fafd21.
  • 2 mwaitx, RVAs 0x4fafc00 and 0x4fafd52.

Over the whole .pdata corpus (recomp_census.py's walk, 299,257 functions), the fix lets 9
functions decode further, 638 instructions in total, and 7 of them reach the end of the function
with no unknown instruction left.

Test

tests/test_x64_recomp.py::DecodeTests::test_group7_0f01_carries_modrm pins the register forms
(CLZERO, XGETBV, MONITORX, MWAITX, MONITOR, RDTSCP, SWAPGS, SMSW) at three bytes and the memory
forms (sgdt [rax], sgdt [rsp+0x10], invlpg [rsp+0x10]) at their full
ModRM/SIB/displacement length. Against the unfixed decoder it fails: 0f 01 fc decodes to size
2.

python -I tests/test_x64_recomp.py: 33 tests OK, 26 skipped (this host has no
qemu-system-aarch64). python -I tests/test_recomp_census.py: 11 tests OK.
python3 -m compileall -q make_game.py tools tests exits 0. python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md exits
0 with no output.

docs/mobile.md records the measurement and the evidence ID. The differential is local analysis
of the shipped file; nothing was executed. No game files, no GPU, nothing online. Tested on Linux
(openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores.

AI-assisted (DeepSeek V4.1 Flash).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1483 **Author:** [@kett1m](https://github.com/kett1m) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `x64-recomp-grp7` --- ### 📝 Commits (1) - [`c1df54c`](https://github.com/ubiquitarianism/leonida/commit/c1df54c119fad6d914b4eb95544606798426707a) x64_recomp: 0F 01 /r is a ModRM group, so the walk stops one byte late (X64-RECOMP-GROUP7) ### 📊 Changes **3 files changed** (+59 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/mobile.md` (+15 -4) 📝 `tests/test_x64_recomp.py` (+20 -0) 📝 `tools/x64_recomp.py` (+24 -1) </details> ### 📄 Description `tools/x64_recomp.py`'s `0F` table has no entry for opcode `0x01`, so the whole system-instruction group decoded as the unknown `op0f_01` of two bytes. Every form of `0F 01 /r` carries a ModRM byte: the memory forms are SGDT/SIDT/LGDT/LIDT/SMSW/LMSW/INVLPG, and the register forms are whole ModRM bytes (MONITOR, MWAIT, XGETBV, XSETBV, CLZERO, MONITORX, MWAITX, RDTSCP, SWAPGS, the VMX/SVM instructions). The walk stopped after the two opcode bytes, so every instruction after it in the function was read at the wrong offset. ## Measurement A per-instruction differential against GNU objdump over the retail image's `.text`: objdump's linear walk and the decoder's walk read the same bytes and the instruction lengths are compared (`objdump -d --start-address/--stop-address` over the section, 26,674,180 objdump instructions). The image is `game_scarlett_master.exe`, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`. REA measured the section ranges with `gnu.objdump` `section_headers`, evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90`: `.text` VMA `0x140001000`, file `0x400`, size `0x5f3f966`; `.pdata` VMA `0x14abcf000`, file `0x6e03a00`. The differential flags 16 `0F 01` boundaries, all one byte short before the fix: - 10 `clzero`, RVAs `0x4e89a70` to `0x4e89bb4`, in two neighbouring `.pdata` functions (`0x4e899c0` and `0x4e89b80`). The first sits at the head of the title's 64-byte zeroing loop (`clzero`; `add $0x40,%rax`; `cmp %r10,%rax`; `jb` back to it), so these run, they are not stray data. - 2 `xgetbv`, RVAs `0x21ae7b5` and `0x55e8e92`. - 2 `monitorx`, RVAs `0x4fafbd7` and `0x4fafd21`. - 2 `mwaitx`, RVAs `0x4fafc00` and `0x4fafd52`. Over the whole `.pdata` corpus (`recomp_census.py`'s walk, 299,257 functions), the fix lets 9 functions decode further, 638 instructions in total, and 7 of them reach the end of the function with no unknown instruction left. ## Test `tests/test_x64_recomp.py::DecodeTests::test_group7_0f01_carries_modrm` pins the register forms (CLZERO, XGETBV, MONITORX, MWAITX, MONITOR, RDTSCP, SWAPGS, SMSW) at three bytes and the memory forms (`sgdt [rax]`, `sgdt [rsp+0x10]`, `invlpg [rsp+0x10]`) at their full ModRM/SIB/displacement length. Against the unfixed decoder it fails: `0f 01 fc` decodes to size 2. `python -I tests/test_x64_recomp.py`: 33 tests OK, 26 skipped (this host has no qemu-system-aarch64). `python -I tests/test_recomp_census.py`: 11 tests OK. `python3 -m compileall -q make_game.py tools tests` exits 0. `python -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py docs/mobile.md` exits 0 with no output. `docs/mobile.md` records the measurement and the evidence ID. The differential is local analysis of the shipped file; nothing was executed. No game files, no GPU, nothing online. Tested on Linux (openSUSE Tumbleweed, Python 3.13.18, binutils 2.47), 12 cores. AI-assisted (DeepSeek V4.1 Flash). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1513
No description provided.