x86: fix selector part of farjmp/farcall instructions. bug reported by Ruslan Kabatsayev
diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c
index 7b140ba..0c4c03b 100644
--- a/arch/X86/X86ATTInstPrinter.c
+++ b/arch/X86/X86ATTInstPrinter.c
@@ -595,6 +595,26 @@
}
break;
+ case X86_INS_INT:
+ // do not print number in negative form
+ imm = imm & 0xff;
+ if (imm >= 0 && imm <= HEX_THRESHOLD)
+ SStream_concat(O, "$%u", imm);
+ else {
+ SStream_concat(O, "$0x%x", imm);
+ }
+ break;
+
+ case X86_INS_LCALL:
+ case X86_INS_LJMP:
+ // always print address in positive form
+ if (OpNo == 1) { // selector is ptr16
+ imm = imm & 0xffff;
+ opsize = 2;
+ }
+ SStream_concat(O, "$0x%"PRIx64, imm);
+ break;
+
case X86_INS_AND:
case X86_INS_OR:
case X86_INS_XOR:
@@ -771,9 +791,12 @@
if (MI->has_imm) {
// if op_count > 1, then this operand's size is taken from the destination op
if (MI->flat_insn->detail->x86.op_count > 1) {
- for (i = 0; i < MI->flat_insn->detail->x86.op_count; i++) {
- if (MI->flat_insn->detail->x86.operands[i].type == X86_OP_IMM)
- MI->flat_insn->detail->x86.operands[i].size = MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].size;
+ if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
+ for (i = 0; i < MI->flat_insn->detail->x86.op_count; i++) {
+ if (MI->flat_insn->detail->x86.operands[i].type == X86_OP_IMM)
+ MI->flat_insn->detail->x86.operands[i].size =
+ MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count - 1].size;
+ }
}
} else
MI->flat_insn->detail->x86.operands[0].size = MI->imm_size;
diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c
index 02cfe42..8932100 100644
--- a/arch/X86/X86IntelInstPrinter.c
+++ b/arch/X86/X86IntelInstPrinter.c
@@ -679,6 +679,19 @@
break;
+ case X86_INS_LCALL:
+ case X86_INS_LJMP:
+ // always print address in positive form
+ if (OpNo == 1) { // selector is ptr16
+ imm = imm & 0xffff;
+ opsize = 2;
+ }
+ if (imm > HEX_THRESHOLD)
+ SStream_concat(O, "0x%"PRIx64, imm);
+ else
+ SStream_concat(O, "%"PRIu64, imm);
+ break;
+
case X86_INS_AND:
case X86_INS_OR:
case X86_INS_XOR:
@@ -708,10 +721,15 @@
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
if (opsize > 0)
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
- else if (MI->flat_insn->detail->x86.op_count > 0)
- MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->flat_insn->detail->x86.operands[0].size;
- else
+ else if (MI->flat_insn->detail->x86.op_count > 0) {
+ if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
+ MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size =
+ MI->flat_insn->detail->x86.operands[0].size;
+ } else
+ MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
+ } else
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
+
MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
MI->flat_insn->detail->x86.op_count++;
}