x86: fix immediate operand of AND/OR/XOR instructions. bug reported by @yegord
diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c
index 1470b92..989fb05 100644
--- a/arch/X86/X86ATTInstPrinter.c
+++ b/arch/X86/X86ATTInstPrinter.c
@@ -588,6 +588,19 @@
SStream_concat(O, "$-%"PRIu64, -imm);
}
break;
+
+ case X86_INS_AND:
+ case X86_INS_OR:
+ case X86_INS_XOR:
+ // do not print number in negative form
+ if (imm >= 0 && imm <= HEX_THRESHOLD)
+ SStream_concat(O, "$%u", imm);
+ else {
+ imm = arch_masks[MI->op1_size? MI->op1_size : MI->imm_size] & imm;
+ SStream_concat(O, "$0x%"PRIx64, imm);
+ }
+ break;
+
case X86_INS_RET:
// RET imm16
if (imm >= 0 && imm <= HEX_THRESHOLD)
@@ -607,12 +620,14 @@
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
MI->has_imm = true;
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
+
if (opsize > 0)
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
else if (MI->op1_size > 0)
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->op1_size;
else
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
+
MI->flat_insn->detail->x86.op_count++;
}
}
diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c
index 3a4d1be..85373b1 100644
--- a/arch/X86/X86IntelInstPrinter.c
+++ b/arch/X86/X86IntelInstPrinter.c
@@ -679,8 +679,10 @@
// do not print number in negative form
if (imm >= 0 && imm <= HEX_THRESHOLD)
SStream_concat(O, "%u", imm);
- else
- SStream_concat(O, "0x%"PRIx64, arch_masks[MI->op1_size? MI->op1_size : MI->imm_size] & imm);
+ else {
+ imm = arch_masks[MI->op1_size? MI->op1_size : MI->imm_size] & imm;
+ SStream_concat(O, "0x%"PRIx64, imm);
+ }
break;
case X86_INS_RET:
// RET imm16