x86: print offset value in memory reference instruction properly when offset is negative. bug reported by Le Dinh Long

v2
Nguyen Anh Quynh 11 years ago
parent e51cf36636
commit 125f504174
  1. 5
      arch/X86/X86ATTInstPrinter.c
  2. 15
      arch/X86/X86IntelInstPrinter.c

@ -435,10 +435,7 @@ static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].mem.disp = DispVal;
if (DispVal || (!MCOperand_getReg(IndexReg) && !MCOperand_getReg(BaseReg))) {
if (DispVal < 0) {
if (DispVal < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -DispVal);
else
SStream_concat(O, "-%"PRIu64, -DispVal);
SStream_concat(O, "0x%"PRIx64, ((1L << (8*MI->csh->mode)) - 1) & DispVal);
} else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);

@ -449,7 +449,7 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
}
}
static void printMemReference(MCInst *MI, unsigned Op, SStream *O) // qqq
static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
{
MCOperand *BaseReg = MCInst_getOperand(MI, Op);
uint64_t ScaleVal = MCOperand_getImm(MCInst_getOperand(MI, Op+1));
@ -496,18 +496,11 @@ static void printMemReference(MCInst *MI, unsigned Op, SStream *O) // qqq
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].mem.disp = DispVal;
if (DispVal || (!MCOperand_getReg(IndexReg) && !MCOperand_getReg(BaseReg))) {
if (NeedPlus) {
if (DispVal > 0)
SStream_concat(O, " + ");
else {
SStream_concat(O, " - ");
DispVal = -DispVal;
}
SStream_concat(O, " + ");
}
if (DispVal < 0) {
if (DispVal < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -DispVal);
else
SStream_concat(O, "-%"PRIu64, -DispVal);
SStream_concat(O, "0x%"PRIx64, ((1L << (8*MI->csh->mode)) - 1) & DispVal);
} else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);

Loading…
Cancel
Save