x86: do not print memory offset in negative form. bug reported by Le Dinh Long

_v3_old
Nguyen Anh Quynh 11 years ago
parent 6baf084480
commit e3ecb0a82f
  1. 11
      arch/X86/X86ATTInstPrinter.c
  2. 11
      arch/X86/X86IntelInstPrinter.c
  3. 10
      arch/X86/X86Mapping.c
  4. 2
      arch/X86/X86Mapping.h

@ -210,10 +210,7 @@ static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
if (MI->csh->detail)
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].mem.disp = imm;
if (imm < 0) {
if (imm < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "-%"PRIu64, -imm);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & imm);
} else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
@ -373,7 +370,7 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
else
SStream_concat(O, "%s$%"PRIu64"%s", markup("<imm:"), imm, markup(">"));
} else {
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), ((1 << 8*MI->x86_imm_size) - 1) & imm, markup(">"));
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), arch_masks[MI->x86_imm_size] & imm, markup(">"));
}
if (MI->csh->detail) {
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].type = X86_OP_IMM;
@ -393,7 +390,7 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
// Print X86 immediates as signed values.
int64_t imm = MCOperand_getImm(Op);
if (imm < 0) {
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), ((1 << 8*MI->x86_imm_size) - 1) & imm, markup(">"));
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), arch_masks[MI->x86_imm_size] & imm, markup(">"));
} else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "%s$0x%"PRIx64"%s", markup("<imm:"), imm, markup(">"));
@ -432,7 +429,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) {
SStream_concat(O, "0x%"PRIx64, ((1L << (8*MI->csh->mode)) - 1) & DispVal);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & DispVal);
} else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);

@ -214,10 +214,7 @@ static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
if (MI->csh->detail)
MI->flat_insn.x86.operands[MI->flat_insn.x86.op_count].mem.disp = imm;
if (imm < 0) {
if (imm < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "-%"PRIu64, -imm);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & imm);
} else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
@ -416,7 +413,7 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
else
SStream_concat(O, "%"PRIu64, imm);
} else {
SStream_concat(O, "0x%"PRIx64, ((1 << 8*MI->x86_imm_size) - 1) & imm);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->x86_imm_size] & imm);
}
if (MI->csh->detail) {
@ -436,7 +433,7 @@ static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
} else if (MCOperand_isImm(Op)) {
int64_t imm = MCOperand_getImm(Op);
if (imm < 0) {
SStream_concat(O, "0x%"PRIx64, ((1 << 8*MI->x86_imm_size) - 1) & imm);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->x86_imm_size] & imm);
} else {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
@ -497,7 +494,7 @@ static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
}
if (DispVal < 0) {
SStream_concat(O, "0x%"PRIx64, ((1L << (8*MI->csh->mode)) - 1) & DispVal);
SStream_concat(O, "0x%"PRIx64, arch_masks[MI->csh->mode] & DispVal);
} else {
if (DispVal > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, DispVal);

@ -9,6 +9,16 @@
#include "../../utils.h"
#include "../../include/x86.h"
uint64_t arch_masks[9] = {
0, 0xff,
0xffff,
0,
0xffffffff,
0, 0, 0,
0xffffffffffffffff
};
static x86_reg sib_base_map[] = {
X86_REG_INVALID,
#define ENTRY(x) X86_REG_##x,

@ -44,4 +44,6 @@ void X86_insn_combine(cs_struct *h, cs_insn *insn, cs_insn *prev);
// this is to handle instructions embedding accumulate registers into AsmStrs[]
x86_reg X86_insn_reg(unsigned int id);
extern uint64_t arch_masks[9];
#endif

Loading…
Cancel
Save