Skip to content

Commit

Permalink
x86: properly calculate absolute addresses for relative CALL & JMP - …
Browse files Browse the repository at this point in the history
…for AT&T syntax. thanks Perdo, again
  • Loading branch information
aquynh committed Oct 1, 2014
1 parent a92d2cb commit bff4fbd
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions arch/X86/X86ATTInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,19 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
if (imm < 0) {
unsigned int id = MCInst_getOpcode(MI);
if (id != X86_CALL64pcrel32 && id != X86_CALLpcrel16 && id != X86_CALLpcrel32) {
if (imm < -HEX_THRESHOLD)
SStream_concat(O, "-0x%"PRIx64, -imm);
else
SStream_concat(O, "-%"PRIu64, -imm);
SStream_concat(O, "0x%"PRIx64, imm);
} else {
// relative CALL. now caculate the absolute address
switch(MI->csh->mode) {
default: break; // never reach
case CS_MODE_16:
imm = 0x10000 + imm + 1 - MI->address;;
imm = 0x10000 + imm + 1;
break;
case CS_MODE_32:
imm = 0x100000000 + imm + 1 - MI->address;;
imm = 0x100000000 + imm + 1;
break;
case CS_MODE_64:
imm = 0xffffffffffffffff + imm + 1 - MI->address;
imm = 0xffffffffffffffff + imm + 1;
break;
}
SStream_concat(O, "0x%"PRIx64, imm);
Expand Down

0 comments on commit bff4fbd

Please sign in to comment.