Make sure all flags are set for CMPXCHG (this was left intentionally incomplete).

Make sure we clear upper bits of the 256/512 bit SSE register.
pull/78/head
BITDEFENDER\vlutas 2 years ago
parent 6dda2c122c
commit bf81c647e3

@ -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;

Binary file not shown.

@ -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']

@ -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.

@ -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

Loading…
Cancel
Save