diff --git a/bdshemu/bdshemu.c b/bdshemu/bdshemu.c index 6285c44..3a6e1a5 100644 --- a/bdshemu/bdshemu.c +++ b/bdshemu/bdshemu.c @@ -1145,7 +1145,7 @@ ShemuGetOperandValue( case ND_REG_SSE: shemu_memcpy(Value->Value.Bytes, - &Context->SseRegisters[op->Info.Register.Reg * ND_MAX_REGISTER_SIZE], + &Context->SseRegisters[op->Info.Register.Reg], op->Size); break; @@ -1335,7 +1335,10 @@ ShemuSetOperandValue( break; case ND_REG_SSE: - shemu_memcpy(&Context->SseRegisters[op->Info.Register.Reg * ND_MAX_REGISTER_SIZE], + // Zero the register first. + nd_memzero(&Context->SseRegisters[op->Info.Register.Reg], ND_MAX_REGISTER_SIZE); + // Copy the value. + shemu_memcpy(&Context->SseRegisters[op->Info.Register.Reg], Value->Value.Bytes, op->Size); // Only log these when they're written. @@ -1935,16 +1938,21 @@ ShemuEmulate( case ND_INS_CMPXCHG: GET_OP(Context, 2, &src); GET_OP(Context, 0, &dst); + + res.Size = src.Size; + // Note: The accumulator is compared with the destination, not the other way around. + res.Value.Qwords[0] = src.Value.Qwords[0] - dst.Value.Qwords[0]; + + SET_FLAGS(Context, res, src, dst, FM_SUB); + if (src.Value.Qwords[0] == dst.Value.Qwords[0]) { GET_OP(Context, 1, &src); SET_OP(Context, 0, &src); - SET_FLAG(Context, NDR_RFLAG_ZF, 1); } else { SET_OP(Context, 2, &dst); - SET_FLAG(Context, NDR_RFLAG_ZF, 0); } break; diff --git a/bdshemu_test/bdshemu_test.zip b/bdshemu_test/bdshemu_test.zip index 8beccdf..a89035a 100644 Binary files a/bdshemu_test/bdshemu_test.zip and b/bdshemu_test/bdshemu_test.zip differ diff --git a/bindings/pybddisasm/setup.py b/bindings/pybddisasm/setup.py index b95a041..045c23d 100644 --- a/bindings/pybddisasm/setup.py +++ b/bindings/pybddisasm/setup.py @@ -12,7 +12,7 @@ from setuptools import find_packages, setup, Command, Extension, Distribution from codecs import open VERSION = (0, 1, 3) -LIBRARY_VERSION = (1, 34, 16) +LIBRARY_VERSION = (1, 34, 17) LIBRARY_INSTRUX_SIZE = 856 packages = ['pybddisasm'] diff --git a/inc/bdshemu.h b/inc/bdshemu.h index b1b6bf0..4c25c84 100644 --- a/inc/bdshemu.h +++ b/inc/bdshemu.h @@ -129,7 +129,7 @@ typedef struct _SHEMU_CONTEXT ND_UINT64 MmxRegisters[ND_MAX_MMX_REGS]; // SSE registers state. 32 x 64 bytes = 2048 bytes for the SSE registers. Can be provided on input, if needed. - ND_UINT8 SseRegisters[ND_MAX_SSE_REGS * ND_MAX_REGISTER_SIZE]; + ND_UINT8 SseRegisters[ND_MAX_SSE_REGS][ND_MAX_REGISTER_SIZE]; // General purpose registers write bitmap. After the first write, a register will be marked dirty in here. // Should be 0 on input. diff --git a/inc/version.h b/inc/version.h index 69c7d0d..aea37fc 100644 --- a/inc/version.h +++ b/inc/version.h @@ -7,6 +7,6 @@ #define DISASM_VERSION_MAJOR 1 #define DISASM_VERSION_MINOR 34 -#define DISASM_VERSION_REVISION 16 +#define DISASM_VERSION_REVISION 17 #endif // DISASM_VER_H