x86: properly calculate absolute addresses of relative CALL & JMP. thanks Pedro for valuable helps

test2
Nguyen Anh Quynh 10 years ago
parent df92a7f346
commit a92d2cba1d
  1. 12
      arch/X86/X86IntelInstPrinter.c

@ -503,21 +503,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);

Loading…
Cancel
Save