diff --git a/decode.c b/decode.c index 92a9eac..28dd995 100644 --- a/decode.c +++ b/decode.c @@ -358,7 +358,8 @@ struct InstrDesc #define DESC_IMM_BYTE(desc) (((desc)->immediate >> 7) & 1) int -decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr) +decode(const uint8_t* buffer, int len, DecodeMode mode, uintptr_t address, + Instr* instr) { const uint8_t* decode_table = NULL; @@ -453,7 +454,7 @@ decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr) instr->flags = prefixes & 0x7f; if (mode == DECODE_64) instr->flags |= INSTR_FLAG_64; - instr->address = (uintptr_t) buffer; + instr->address = address; uint8_t op_size = 0; if (desc->gp_size_8) @@ -630,7 +631,7 @@ decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr) if (imm_control == 4) { - instr->immediate += (uintptr_t) buffer + off; + instr->immediate += instr->address + off; } struct Operand* operand = &instr->operands[DESC_IMM_IDX(desc)]; diff --git a/decode.h b/decode.h index 910928b..d92e749 100644 --- a/decode.h +++ b/decode.h @@ -131,7 +131,8 @@ typedef struct Instr Instr; #define INSTR_HAS_REX(instr) ((instr)->flags & INSTR_FLAG_REX) #define INSTR_HAS_VEXL(instr) ((instr)->flags & INSTR_FLAG_VEXL) -int decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* out_instr); +int decode(const uint8_t* buffer, int len, DecodeMode mode, uintptr_t address, + Instr* out_instr); void instr_format(const Instr* instr, char buffer[128]); #endif diff --git a/tests/driver.c b/tests/driver.c index 1132ff0..8c922d4 100644 --- a/tests/driver.c +++ b/tests/driver.c @@ -72,7 +72,8 @@ main(int argc, char** argv) while (current_off != length) { size_t remaining = length - current_off; - int retval = decode(code + current_off, remaining, mode, &instr); + int retval = decode(code + current_off, remaining, mode, 0x1234000, + &instr); if (retval < 0) goto fail; current_off += retval;