diff --git a/native_exec/simple_x86.py b/native_exec/simple_x86.py index a1db2b6..ac2292f 100644 --- a/native_exec/simple_x86.py +++ b/native_exec/simple_x86.py @@ -538,7 +538,7 @@ class Jz(JmpType): class Jnz(JmpType): encoding = [(RawBits.from_int(8, 0x75), JmpImm8(2)), (RawBits.from_int(16, 0x0f85), JmpImm32(6))] - + class Jbe(JmpType): encoding = [(RawBits.from_int(8, 0x76), JmpImm8(2)), (RawBits.from_int(16, 0x0f86), JmpImm32(6))] @@ -574,6 +574,12 @@ class Mov(Instruction): encoding = [(RawBits.from_int(8, 0x89), ModRM([ModRM_REG__REG, ModRM_REG__MEM])), (RawBits.from_int(5, 0xb8 >> 3), X86RegisterSelector(), Imm32())] +class Movsb(Instruction): + encoding = [(RawBits.from_int(8, 0xa4),)] + +class Movsd(Instruction): + encoding = [(RawBits.from_int(8, 0xa5),)] + class Lea(Instruction): encoding = [(RawBits.from_int(8, 0x8d), ModRM([ModRM_REG__MEM], accept_reverse=False, has_direction_bit=False))] diff --git a/native_exec/test_simple_x86.py b/native_exec/test_simple_x86.py index 4006cae..90f87e7 100644 --- a/native_exec/test_simple_x86.py +++ b/native_exec/test_simple_x86.py @@ -9,8 +9,9 @@ def disas(x): class TestInstr(object): - def __init__(self, instr_to_test): + def __init__(self, instr_to_test, expected_result=None): self.instr_to_test = instr_to_test + self.expected_result = expected_result def __call__(self, *args): res = bytes(self.instr_to_test(*args).get_code()) @@ -31,6 +32,12 @@ class TestInstr(object): return True def compare_args(self, args, capres): + if self.expected_result is not None: + result = "{0} {1}".format(capres.mnemonic, capres.op_str) + if result != self.expected_result: + raise AssertionError("Bad expected result expect <{0}> got <{1}>".format(self.expected_result, result)) + return + capres_op = list(capres.operands) if len(args) != len(capres_op): raise AssertionError("Expected {0} operands got {1}".format(len(args), len(capres_op))) @@ -105,5 +112,8 @@ TestInstr(Call)('EAX') TestInstr(Call)(mem('[EAX + ECX * 8]')) TestInstr(Cpuid)() +TestInstr(Movsb, expected_result='movsb byte ptr es:[edi], byte ptr [esi]')() +TestInstr(Movsd, expected_result='movsd dword ptr es:[edi], dword ptr [esi]')() + TestInstr(Xchg)('EAX', 'ESP') assert Xchg('EAX', 'ECX').get_code() == Xchg('ECX', 'EAX').get_code()