Files
sp00nz 21d9ce75b8 Lift switch tables whose displacement is not slot 0
MSVC's CRT memcpy/memmove dispatch unaligned lead and trail bytes as

    and  eax, 3              ; 1..3 on this path, never 0
    jmp  [eax*4 + LeadUpVec - 4]

    sub  ecx, 4              ; -4..-1 when fewer than 4 dwords remain
    jmp  [ecx*4 + TrailUpVec + 16]

Reading forward from the displacement finds the jmp's own bytes in the
first form and the code after the table in the second, so both were
lifted as unresolvable indirect tail jumps. At runtime the target is
not a function, the ICALL is skipped, and memcpy returns without
copying whenever the destination is unaligned.

The emitted switch compares the loaded value against its arms instead
of indexing, so only the set of arms matters. When slot 0 is not an arm,
the lifter now also tries the slots after it and the slots below it,
and CFG recovery's census tries skipping slot 0. A census entry stays
authoritative: the lifter never rediscovers arms recovery rejected.

Surfaced in Burnout 3: its memcpy's jump-table arms were reached as
indirect targets, and feeding them back as seeds split memcpy and sent
XAPI down its dashboard-update path. Any title linking the MSVC CRT
has these two jumps (Half-Life 2 still carries one such ITAIL).

tools/recomp/test_switch_table_offset_index.py covers both forms; it
fails without the change. pytest tools/: 562 -> 564 passed, 17 skipped
before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 04:11:43 -07:00
..
2026-09-27 00:55:21 -07:00