From f93842434932c211ef5683769997490dcf3f3260 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Wed, 19 Aug 2015 09:34:56 +0800 Subject: [PATCH] x86: another attempt to fix #456 --- arch/X86/X86ATTInstPrinter.c | 15 ++++++++------- arch/X86/X86IntelInstPrinter.c | 16 +++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c index 2e93e081c1..7f53cf86c0 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.c @@ -461,21 +461,22 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) imm = imm & 0xffffffff; } - // CALL/JMP rel16 is special - if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) + if (MI->csh->mode == CS_MODE_16 && + (MI->Opcode != X86_JMP_4 && MI->Opcode != X86_CALLpcrel32)) imm = imm & 0xffff; - if (MI->csh->mode == CS_MODE_16 && MI->Opcode == X86_JMP_4) + // Hack: X86 16bit with opcode X86_JMP_4 + if (MI->csh->mode == CS_MODE_16 && + (MI->Opcode == X86_JMP_4 && MI->x86_prefix[2] != 0x66)) imm = imm & 0xffff; + // CALL/JMP rel16 is special + if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) + imm = imm & 0xffff; if (imm < 0) { SStream_concat(O, "0x%"PRIx64, imm); } else { - // handle 16bit segment bound - if (MI->csh->mode == CS_MODE_16 && imm > 0x100000) - imm -= 0x10000; - if (imm > HEX_THRESHOLD) SStream_concat(O, "0x%"PRIx64, imm); else diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c index 0d7ae7b007..001feb9cfb 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -543,20 +543,22 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) imm = imm & 0xffffffff; } - // CALL/JMP rel16 is special - if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) + if (MI->csh->mode == CS_MODE_16 && + (MI->Opcode != X86_JMP_4 && MI->Opcode != X86_CALLpcrel32)) imm = imm & 0xffff; - if (MI->csh->mode == CS_MODE_16 && MI->Opcode == X86_JMP_4) + // Hack: X86 16bit with opcode X86_JMP_4 + if (MI->csh->mode == CS_MODE_16 && + (MI->Opcode == X86_JMP_4 && MI->x86_prefix[2] != 0x66)) + imm = imm & 0xffff; + + // CALL/JMP rel16 is special + if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) imm = imm & 0xffff; if (imm < 0) { SStream_concat(O, "0x%"PRIx64, imm); } else { - // handle 16bit segment bound - if (MI->csh->mode == CS_MODE_16 && imm > 0x100000) - imm -= 0x10000; - if (imm > HEX_THRESHOLD) SStream_concat(O, "0x%"PRIx64, imm); else