x86: recognize xrelease lock

This commit is contained in:
Nguyen Anh Quynh 2019-05-14 09:59:23 +08:00
parent d5dd80e979
commit eb25f46d6a
6 changed files with 16 additions and 8 deletions

View File

@ -33,7 +33,7 @@ void MCInst_Init(MCInst *inst)
inst->popcode_adjust = 0;
inst->assembly[0] = '\0';
inst->wasm_data.type = WASM_OP_INVALID;
inst->xAcquireRelease = false;
inst->xAcquireRelease = 0;
}
void MCInst_clear(MCInst *inst)

View File

@ -116,7 +116,7 @@ struct MCInst {
unsigned char evm_data[32]; // for EVM PUSH operand
cs_wasm_op wasm_data; // for WASM operand
MCRegisterInfo *MRI;
bool xAcquireRelease; // X86 xacquire/xrelease
uint8_t xAcquireRelease; // X86 xacquire/xrelease
};
void MCInst_Init(MCInst *inst);

View File

@ -470,10 +470,11 @@ static int readPrefixes(struct InternalInstruction* insn)
*/
if (((nextByte == 0xf0) ||
((nextByte & 0xfe) == 0x86 || (nextByte & 0xf8) == 0x90))) {
insn->xAcquireRelease = true;
insn->xAcquireRelease = byte;
if (!(byte == 0xf3 && nextByte == 0x90) && // PAUSE instruction support
!(byte == 0xf2 && nextByte == 0xf0))
!(byte == 0xf2 && nextByte == 0xf0) && // xacquire
!(byte == 0xf3 && nextByte == 0xf0)) // xrelease
break;
}
@ -485,7 +486,8 @@ static int readPrefixes(struct InternalInstruction* insn)
*/
if (byte == 0xf3 && (nextByte == 0x88 || nextByte == 0x89 ||
nextByte == 0xc6 || nextByte == 0xc7)) {
insn->xAcquireRelease = true;
insn->xAcquireRelease = byte;
if (nextByte != 0x90) // PAUSE instruction support
break;
}

View File

@ -586,8 +586,8 @@ typedef struct InternalInstruction {
uint8_t RC;
uint8_t numImmediatesConsumed;
/* true if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease */
bool xAcquireRelease;
/* 0xf2 or 0xf3 is xacquire or xrelease */
uint8_t xAcquireRelease;
// Address-size override
bool hasAdSize;

View File

@ -1835,8 +1835,10 @@ bool X86_lockrep(MCInst *MI, SStream *O)
break;
case 0xf0:
#ifndef CAPSTONE_DIET
if (MI->xAcquireRelease)
if (MI->xAcquireRelease == 0xf2)
SStream_concat(O, "xacquire|lock|");
else if (MI->xAcquireRelease == 0xf3)
SStream_concat(O, "xrelease|lock|");
else
SStream_concat(O, "lock|");
#endif

View File

@ -1,3 +1,7 @@
!# issue X86 xrelease
!# CS_ARCH_X86, CS_MODE_64, None
0xf3,0xf0,0x31,0x1f == xrelease lock xor dword ptr [rdi], ebx
!# issue 1477 X86 xacquire
!# CS_ARCH_X86, CS_MODE_64, None
0xf2,0xf0,0x31,0x1f == xacquire lock xor dword ptr [rdi], ebx