From 125f504174d287f8cc2f6e3e01d6e4803a5c4203 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Sat, 29 Mar 2014 12:02:21 +0800 Subject: [PATCH] x86: print offset value in memory reference instruction properly when offset is negative. bug reported by Le Dinh Long --- arch/X86/X86ATTInstPrinter.c | 5 +---- arch/X86/X86IntelInstPrinter.c | 15 ++++----------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c index f0843913..f50ff4bb 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.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); diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c index 90e539d9..8fcd6517 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -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);