Skip to content

Commit

Permalink
x86: another attempt to fix capstone-engine#456
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Aug 19, 2015
1 parent 50d1205 commit f938424
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 8 additions & 7 deletions arch/X86/X86ATTInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions arch/X86/X86IntelInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f938424

Please sign in to comment.