diff options
| author | Rares <brotacoac@gmail.com> | 2026-11-23 17:55:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 09:55:03 -0600 |
| commit | d231919b88c9ee5aa4da75a4333dfd2da60b6aba (patch) | |
| tree | a1e7c964212de80a3735a8f33f657156fd5a16f4 | |
| parent | 8714c3503bc49b72f79909338684c41cb1282e84 (diff) | |
gdk_runtime_calls: REX.W overrides 0x66 prefix for immz in x86-64 decoder (#6853)
Squash-merged after diff review of PR #6853 - gdk_runtime_calls: REX.W overrides 0x66 prefix for immz in x86-64 decoder
| -rw-r--r-- | tests/test_gdk_runtime_calls.py | 4 | ||||
| -rw-r--r-- | tools/gdk_runtime_calls.py | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/tests/test_gdk_runtime_calls.py b/tests/test_gdk_runtime_calls.py index 9e1b7b869..603c505ea 100644 --- a/tests/test_gdk_runtime_calls.py +++ b/tests/test_gdk_runtime_calls.py | |||
| @@ -459,6 +459,10 @@ class DecoderTest(unittest.TestCase): | |||
| 459 | "48B80000000000000000": 10, # mov rax,imm64 | 459 | "48B80000000000000000": 10, # mov rax,imm64 |
| 460 | "F6C101": 3, # test cl,1 | 460 | "F6C101": 3, # test cl,1 |
| 461 | "F7C100000000": 6, # test ecx,imm32 | 461 | "F7C100000000": 6, # test ecx,imm32 |
| 462 | "66F7C10000": 5, # test cx,imm16 | ||
| 463 | "6648F7C100000000": 8, # test rcx,imm32 (REX.W overrides 66h) | ||
| 464 | "66C7C10000": 5, # mov cx,imm16 | ||
| 465 | "6648C7C100000000": 8, # mov rcx,imm32 (REX.W overrides 66h) | ||
| 462 | "4C8B11": 3, # mov r10,[rcx] | 466 | "4C8B11": 3, # mov r10,[rcx] |
| 463 | "0F8400000000": 6, # je rel32 | 467 | "0F8400000000": 6, # je rel32 |
| 464 | } | 468 | } |
diff --git a/tools/gdk_runtime_calls.py b/tools/gdk_runtime_calls.py index 6f986f66e..8e59912d0 100644 --- a/tools/gdk_runtime_calls.py +++ b/tools/gdk_runtime_calls.py | |||
| @@ -217,7 +217,7 @@ def decode(buf, off: int, base_rva: int) -> Insn | None: | |||
| 217 | if b in _M1_IMM8: | 217 | if b in _M1_IMM8: |
| 218 | imm = 1 | 218 | imm = 1 |
| 219 | elif b in _M1_IMMZ: | 219 | elif b in _M1_IMMZ: |
| 220 | imm = 2 if p66 else 4 | 220 | imm = 2 if (p66 and not (rex & 8)) else 4 |
| 221 | elif b in _M1_REL8: | 221 | elif b in _M1_REL8: |
| 222 | rel = 1 | 222 | rel = 1 |
| 223 | elif b in (0xE8, 0xE9): | 223 | elif b in (0xE8, 0xE9): |
| @@ -266,7 +266,7 @@ def decode(buf, off: int, base_rva: int) -> Insn | None: | |||
| 266 | disp = struct.unpack_from("<i", buf, p)[0] | 266 | disp = struct.unpack_from("<i", buf, p)[0] |
| 267 | p += dsize | 267 | p += dsize |
| 268 | if op in (0xF6, 0xF7) and reg & 7 in (0, 1): # test r/m, imm | 268 | if op in (0xF6, 0xF7) and reg & 7 in (0, 1): # test r/m, imm |
| 269 | imm = 1 if op == 0xF6 else (2 if p66 else 4) | 269 | imm = 1 if op == 0xF6 else (2 if (p66 and not (rex & 8)) else 4) |
| 270 | target = None | 270 | target = None |
| 271 | if rel: | 271 | if rel: |
| 272 | if p + rel > n: | 272 | if p + rel > n: |