Specify address via parameter
This allows to decode instructions where the address of the buffer is not the address of the instruction.
This commit is contained in:
7
decode.c
7
decode.c
@@ -358,7 +358,8 @@ struct InstrDesc
|
|||||||
#define DESC_IMM_BYTE(desc) (((desc)->immediate >> 7) & 1)
|
#define DESC_IMM_BYTE(desc) (((desc)->immediate >> 7) & 1)
|
||||||
|
|
||||||
int
|
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;
|
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;
|
instr->flags = prefixes & 0x7f;
|
||||||
if (mode == DECODE_64)
|
if (mode == DECODE_64)
|
||||||
instr->flags |= INSTR_FLAG_64;
|
instr->flags |= INSTR_FLAG_64;
|
||||||
instr->address = (uintptr_t) buffer;
|
instr->address = address;
|
||||||
|
|
||||||
uint8_t op_size = 0;
|
uint8_t op_size = 0;
|
||||||
if (desc->gp_size_8)
|
if (desc->gp_size_8)
|
||||||
@@ -630,7 +631,7 @@ decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr)
|
|||||||
|
|
||||||
if (imm_control == 4)
|
if (imm_control == 4)
|
||||||
{
|
{
|
||||||
instr->immediate += (uintptr_t) buffer + off;
|
instr->immediate += instr->address + off;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Operand* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
struct Operand* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
||||||
|
|||||||
3
decode.h
3
decode.h
@@ -131,7 +131,8 @@ typedef struct Instr Instr;
|
|||||||
#define INSTR_HAS_REX(instr) ((instr)->flags & INSTR_FLAG_REX)
|
#define INSTR_HAS_REX(instr) ((instr)->flags & INSTR_FLAG_REX)
|
||||||
#define INSTR_HAS_VEXL(instr) ((instr)->flags & INSTR_FLAG_VEXL)
|
#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]);
|
void instr_format(const Instr* instr, char buffer[128]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ main(int argc, char** argv)
|
|||||||
while (current_off != length)
|
while (current_off != length)
|
||||||
{
|
{
|
||||||
size_t remaining = length - current_off;
|
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)
|
if (retval < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
current_off += retval;
|
current_off += retval;
|
||||||
|
|||||||
Reference in New Issue
Block a user