8000 amd64, x86: Decode MOVZX/MOVSX Ew,Gw with a 66 prefix by NopeCharon · Pull Request #108 · angr/vex · GitHub
[go: up one dir, main page]

Skip to content

amd64, x86: Decode MOVZX/MOVSX Ew,Gw with a 66 prefix - #108

Open
NopeCharon wants to merge 1 commit into
angr:masterfrom
NopeCharon:fix/amd64-movzx-movsx-16bit
Open

NopeCharon wants to merge 1 commit into
angr:masterfrom
NopeCharon:fix/amd64-movzx-movsx-16bit

Conversation

@NopeCharon
Copy link
Copy Markdown

Fixes angr/pyvex#536.

With a 66 operand-size prefix, 0F B7 (MOVZX) and 0F BF (MOVSX) have a 16-bit destination and a 16-bit source, so they are plain 16-bit moves (movzww/movsww): the low 16 bits of the destination get the source and the rest of the register is left alone. The amd64 front end only accepted 32- and 64-bit destinations for these opcodes, so every encoding from the issue lifted to an empty Ijk_NoDecode block:

  • 66 0f b7 c0 (movzx ax, ax)
  • 66 0f bf c0 (movsx ax, ax)
  • 66 45 0f b7 5c 27 6a (movzx r11w, word ptr [r15 + 0x6a])

The x86 front end already accepts movsww (Valgrind bug 250799). Its dis_movx_E_G copies the source straight into the destination when the two sizes match. This change does the same in the amd64 dis_movx_E_G, because doScalarWidening has no same-size case, and accepts sz == 2 for both opcodes. REX.W still takes precedence over 66, and the F2/F3 forms are still rejected.

On x86, 0F B7 also accepts the 66 form now, so both front ends decode the same encodings.

Checked through pyvex built against this branch:

  • 66 0f b7 c0 lifts to t0 = 64to16(GET:I64(rax)); PUT(ax) = t0, and the memory form from the issue lifts to LDle:I16(r15 + 0x6a) written to r11w. Both are 4 and 7 bytes long and end in Ijk_Boring.
  • 66 0f bf c0 on amd64, and 66 0f b7 c1 and 66 0f bf 01 on x86, decode as 16-bit moves.
  • 0f b7 c0, 66 48 0f b7 c0 (REX.W wins) and f3 0f b7 c0 (still Ijk_NoDecode) behave as before.
  • The pyvex test suite passes.

With an operand-size prefix, 0F B7 (MOVZX) and 0F BF (MOVSX) have a
16-bit destination and a 16-bit source, so they are plain 16-bit moves:
the low 16 bits of the destination receive the source and the rest of
the register is left alone. Assemblers spell them movzww/movsww and
CPUs execute them, but the amd64 front end only accepted 32- and 64-bit
destinations for these opcodes, so `66 0F B7 C0` (movzx ax, ax),
`66 0F BF C0` (movsx ax, ax) and `66 45 0F B7 5C 27 6A`
(movzx r11w, word ptr [r15+0x6a]) lifted to an empty Ijk_NoDecode
block.

The x86 front end already accepts the movsww form (Valgrind bug
250799) and handles it in dis_movx_E_G by copying the source straight
into the destination when the sizes match. Do the same in the amd64
dis_movx_E_G, where doScalarWidening has no same-size case, and accept
sz == 2 for both opcodes. REX.W still takes precedence over 66, and F2/F3
forms are rejected as before.

On x86, accept the movzww form too, so both front ends decode the same
set of encodings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pyvex fails to decode some Mov instructions with 66 prefix

1 participant

0