From 542eb33aa6cea04d7dd7f5e7af0e7d9568f1fc7e Mon Sep 17 00:00:00 2001 From: clement rouault Date: Tue, 27 Apr 2021 21:32:49 +0200 Subject: [PATCH] Fix issue #19 about x86/x64 bad Test encoding --- tests/test_simple_x64.py | 4 ++++ tests/test_simple_x86.py | 5 +++++ windows/native_exec/simple_x64.py | 2 +- windows/native_exec/simple_x86.py | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_simple_x64.py b/tests/test_simple_x64.py index b83864d..4a75956 100644 --- a/tests/test_simple_x64.py +++ b/tests/test_simple_x64.py @@ -210,6 +210,10 @@ def test_assembler(): CheckInstr(x64.Test)('RCX', 'RCX') CheckInstr(x64.Test)(mem('[RDI + 0x100]'), 'RCX') + CheckInstr(x64.Test)('EAX', 0x11223344) + CheckInstr(x64.Test, immediat_accepted=-1)('RAX', 0xffffffff) + CheckInstr(x64.Test)('ECX', 0x42) + CheckInstr(x64.Test)('RCX', 0x42) assert x64.Test(mem('[RDI + 0x100]'), 'RCX').get_code() == x64.Test('RCX', mem('[RDI + 0x100]')).get_code() diff --git a/tests/test_simple_x86.py b/tests/test_simple_x86.py index aa773fa..d03554d 100644 --- a/tests/test_simple_x86.py +++ b/tests/test_simple_x86.py @@ -183,6 +183,8 @@ def test_assembler(): CheckInstr(Cmp, immediat_accepted=0xffffffff)('EAX', -1) CheckInstr(Cmp)('EAX', 0xffffffff) + + CheckInstr(And)('ECX', 'EBX') CheckInstr(And)('EAX', 0x11223344) CheckInstr(And)('EAX', mem('[EAX + 1]')) @@ -218,6 +220,9 @@ def test_assembler(): CheckInstr(x86.Test)('EAX', 'EAX') CheckInstr(x86.Test, expected_result="test edi, ecx")('ECX', 'EDI') CheckInstr(x86.Test)(mem('[ECX + 0x100]'), 'ECX') + CheckInstr(x86.Test)('EAX', 0x11223344) + CheckInstr(x86.Test, immediat_accepted=-1)('EAX', 0xffffffff) + CheckInstr(x86.Test)('ECX', 0x42) assert x86.Test(mem('[ECX + 0x100]'), 'ECX').get_code() == x86.Test('ECX', mem('[ECX + 0x100]')).get_code() diff --git a/windows/native_exec/simple_x64.py b/windows/native_exec/simple_x64.py index 632968d..04201c4 100644 --- a/windows/native_exec/simple_x64.py +++ b/windows/native_exec/simple_x64.py @@ -1021,7 +1021,7 @@ class Cmp(Instruction): class Test(Instruction): default_32_bits = True refuse_reverse = True - encoding = [(RawBits.from_int(8, 0xf7), Slash(7), AnyImm32()), + encoding = [(RawBits.from_int(8, 0xf7), Slash(0), AnyImm32()), (RawBits.from_int(8, 0x85), ModRM([ModRM_REG__REG, ModRM_REG64__MEM], has_direction_bit=False))] diff --git a/windows/native_exec/simple_x86.py b/windows/native_exec/simple_x86.py index a090ef9..e8bee2c 100644 --- a/windows/native_exec/simple_x86.py +++ b/windows/native_exec/simple_x86.py @@ -799,7 +799,7 @@ class Cmp(Instruction): class Test(Instruction): - encoding = [(RawBits.from_int(8, 0xf7), Slash(7), Imm32()), + encoding = [(RawBits.from_int(8, 0xf7), Slash(0), Imm32()), (RawBits.from_int(8, 0x85), ModRM([ModRM_REG__REG, ModRM_REG__MEM], has_direction_bit=False))]