Fix #382 - Refactor 16bit addressing issue to fix rel32 calculation

This commit is contained in:
pancake 2013-11-30 03:28:19 +01:00
parent f0a45a556a
commit 239203d8d9
4 changed files with 10 additions and 29 deletions

View File

@ -95,8 +95,7 @@ gen_operand(struct ud* u, struct ud_operand* op)
break;
case UD_OP_JIMM:
//ud_syn_print_addr(u, ud_syn_rel_target(u, op));
ud_syn_print_addr(u, ud_syn_rel_target(u, op, u->dis_mode!=64? 1: 0));
ud_syn_print_addr(u, ud_syn_rel_target(u, op));
break;
case UD_OP_PTR:

View File

@ -94,8 +94,7 @@ static void gen_operand(struct ud* u, struct ud_operand* op, int syn_cast)
case UD_OP_JIMM:
//ud_syn_print_addr(u, ud_syn_rel_target(u, op));
ud_syn_print_addr(u, ud_syn_rel_target(u, op, u->dis_mode!=64? 1: 0));
ud_syn_print_addr(u, ud_syn_rel_target(u, op));
break;
case UD_OP_PTR:

View File

@ -88,40 +88,23 @@ const char* ud_reg_tab[] =
};
#if 0
uint64_t
ud_syn_rel_target(struct ud *u, struct ud_operand *opr)
{
const uint64_t trunc_mask = 0xffffffffffffffffull >> (64 - u->opr_mode);
uint64_t trunc_mask = 0xffffffffffffffffull >> (64 - u->opr_mode);
switch (opr->size) {
case 8 : return (u->pc + opr->lval.sbyte) & trunc_mask;
case 16: return (u->pc + opr->lval.sword) & trunc_mask;
case 16: {
int delta = (opr->lval.sword & trunc_mask);
if ((u->pc + delta)>0xffff)
return (u->pc & 0xf0000) + (u->pc+delta&0xffff);
return (u->pc + delta);
}
case 32: return (u->pc + opr->lval.sdword) & trunc_mask;
default: UD_ASSERT(!"invalid relative offset size.");
return 0ull;
}
}
#endif
uint64_t
ud_syn_rel_target(struct ud *u, struct ud_operand *opr, int mask)
{
uint64_t trunc_mask = 0xffffffffffffffffull;
if (mask) trunc_mask >>= (64 - u->opr_mode);
switch (opr->size) {
case 8 : return (u->pc + (opr->lval.sbyte & trunc_mask));
case 16: {
int delta = (opr->lval.sword & trunc_mask);
if ((u->pc + delta)>0xffff) {
return (u->pc & 0xf0000) + (u->pc+delta&0xffff);
}
return (u->pc + delta);
}
case 32: return (u->pc + (opr->lval.sdword & trunc_mask));
default: UD_ASSERT(!"invalid relative offset size.");
}
return 0LL;
}
/*

View File

@ -33,7 +33,7 @@
extern const char* ud_reg_tab[];
uint64_t ud_syn_rel_target(struct ud*, struct ud_operand*, int n);
uint64_t ud_syn_rel_target(struct ud*, struct ud_operand*);
#ifdef __GNUC__
int ud_asmprintf(struct ud *u, const char *fmt, ...)