From 6baf0844805bdf126eb1ef79b4dbb93d19a31784 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 78a4b22f..dc7c8532 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.c @@ -432,10 +432,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 e08aff13..92a8950a 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -446,7 +446,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)); @@ -493,18 +493,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);