No longer expose PrefixSet in header
This commit is contained in:
46
decode.c
46
decode.c
@@ -70,6 +70,34 @@ static const uint8_t _decode_table64[] = {
|
|||||||
((size_t) ((uint8_t*) buf)[7] << 56))
|
((size_t) ((uint8_t*) buf)[7] << 56))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum PrefixSet
|
||||||
|
{
|
||||||
|
PREFIX_LOCK = INSTR_FLAG_LOCK,
|
||||||
|
PREFIX_REP = INSTR_FLAG_REP,
|
||||||
|
PREFIX_REPNZ = INSTR_FLAG_REPNZ,
|
||||||
|
PREFIX_REX = INSTR_FLAG_REX,
|
||||||
|
PREFIX_VEXL = INSTR_FLAG_VEXL,
|
||||||
|
PREFIX_SEG_FS = 1 << 8,
|
||||||
|
PREFIX_SEG_GS = 1 << 9,
|
||||||
|
PREFIX_SEG_CS = 1 << 10,
|
||||||
|
PREFIX_SEG_DS = 1 << 11,
|
||||||
|
PREFIX_SEG_ES = 1 << 12,
|
||||||
|
PREFIX_OPSZ = 1 << 13,
|
||||||
|
PREFIX_ADDRSZ = 1 << 14,
|
||||||
|
PREFIX_REXB = 1 << 15,
|
||||||
|
PREFIX_REXX = 1 << 16,
|
||||||
|
PREFIX_REXR = 1 << 17,
|
||||||
|
PREFIX_REXW = 1 << 18,
|
||||||
|
PREFIX_ESC_NONE = 0 << 19,
|
||||||
|
PREFIX_ESC_0F = 1 << 19,
|
||||||
|
PREFIX_ESC_0F38 = 2 << 19,
|
||||||
|
PREFIX_ESC_0F3A = 3 << 19,
|
||||||
|
PREFIX_ESC_MASK = 3 << 19,
|
||||||
|
PREFIX_VEX = 1 << 21,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum PrefixSet PrefixSet;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
decode_prefixes(const uint8_t* buffer, int len, DecodeMode mode,
|
decode_prefixes(const uint8_t* buffer, int len, DecodeMode mode,
|
||||||
@@ -171,7 +199,7 @@ out:
|
|||||||
static
|
static
|
||||||
int
|
int
|
||||||
decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
||||||
struct Operand* out_o1, struct Operand* out_o2)
|
PrefixSet prefixes, struct Operand* out_o1, struct Operand* out_o2)
|
||||||
{
|
{
|
||||||
int off = 0;
|
int off = 0;
|
||||||
|
|
||||||
@@ -190,7 +218,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
|||||||
{
|
{
|
||||||
uint8_t reg_idx = mod_reg;
|
uint8_t reg_idx = mod_reg;
|
||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += instr->prefixes & PREFIX_REXR ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXR ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o2->type = OT_REG;
|
out_o2->type = OT_REG;
|
||||||
out_o2->reg = reg_idx;
|
out_o2->reg = reg_idx;
|
||||||
@@ -200,7 +228,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
|||||||
{
|
{
|
||||||
uint8_t reg_idx = rm;
|
uint8_t reg_idx = rm;
|
||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += instr->prefixes & PREFIX_REXB ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o1->type = OT_REG;
|
out_o1->type = OT_REG;
|
||||||
out_o1->reg = reg_idx;
|
out_o1->reg = reg_idx;
|
||||||
@@ -222,7 +250,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
|||||||
scale = ((sib & 0xc0) >> 6) + 1;
|
scale = ((sib & 0xc0) >> 6) + 1;
|
||||||
idx = (sib & 0x38) >> 3;
|
idx = (sib & 0x38) >> 3;
|
||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
idx += instr->prefixes & PREFIX_REXX ? 8 : 0;
|
idx += prefixes & PREFIX_REXX ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
base = sib & 0x07;
|
base = sib & 0x07;
|
||||||
}
|
}
|
||||||
@@ -270,7 +298,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
|||||||
|
|
||||||
uint8_t reg_idx = rm;
|
uint8_t reg_idx = rm;
|
||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += instr->prefixes & PREFIX_REXB ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o1->reg = reg_idx;
|
out_o1->reg = reg_idx;
|
||||||
return off;
|
return off;
|
||||||
@@ -293,7 +321,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr,
|
|||||||
{
|
{
|
||||||
uint8_t reg_idx = base;
|
uint8_t reg_idx = base;
|
||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += instr->prefixes & PREFIX_REXB ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o1->reg = reg_idx;
|
out_o1->reg = reg_idx;
|
||||||
}
|
}
|
||||||
@@ -428,7 +456,9 @@ decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr)
|
|||||||
struct InstrDesc* desc = (struct InstrDesc*) table;
|
struct InstrDesc* desc = (struct InstrDesc*) table;
|
||||||
|
|
||||||
instr->type = desc->type;
|
instr->type = desc->type;
|
||||||
instr->prefixes = prefixes;
|
instr->flags = prefixes & 0x7f;
|
||||||
|
if (mode == DECODE_64)
|
||||||
|
instr->flags |= INSTR_FLAG_64;
|
||||||
instr->address = (uintptr_t) buffer;
|
instr->address = (uintptr_t) buffer;
|
||||||
|
|
||||||
if (prefixes & PREFIX_SEG_FS)
|
if (prefixes & PREFIX_SEG_FS)
|
||||||
@@ -508,7 +538,7 @@ decode(const uint8_t* buffer, int len, DecodeMode mode, Instr* instr)
|
|||||||
{
|
{
|
||||||
operand2 = &instr->operands[DESC_MODREG_IDX(desc)];
|
operand2 = &instr->operands[DESC_MODREG_IDX(desc)];
|
||||||
}
|
}
|
||||||
retval = decode_modrm(buffer + off, len - off, mode, instr,
|
retval = decode_modrm(buffer + off, len - off, mode, instr, prefixes,
|
||||||
operand1, operand2);
|
operand1, operand2);
|
||||||
|
|
||||||
if (UNLIKELY(retval < 0))
|
if (UNLIKELY(retval < 0))
|
||||||
|
|||||||
45
decode.h
45
decode.h
@@ -69,34 +69,16 @@ typedef uint8_t Reg;
|
|||||||
#define reg_is_none(reg) ((reg) == REG_NONE)
|
#define reg_is_none(reg) ((reg) == REG_NONE)
|
||||||
#define REG_NONE (0x3f)
|
#define REG_NONE (0x3f)
|
||||||
|
|
||||||
enum PrefixSet
|
enum
|
||||||
{
|
{
|
||||||
PREFIX_SEG_FS = 1 << 0,
|
INSTR_FLAG_LOCK = 1 << 0,
|
||||||
PREFIX_SEG_GS = 1 << 1,
|
INSTR_FLAG_REP = 1 << 1,
|
||||||
PREFIX_SEG_CS = 1 << 12,
|
INSTR_FLAG_REPNZ = 1 << 2,
|
||||||
PREFIX_SEG_DS = 1 << 17,
|
INSTR_FLAG_REX = 1 << 3,
|
||||||
PREFIX_SEG_ES = 1 << 18,
|
INSTR_FLAG_VEXL = 1 << 4,
|
||||||
PREFIX_OPSZ = 1 << 2,
|
INSTR_FLAG_64 = 1 << 7,
|
||||||
PREFIX_ADDRSZ = 1 << 3,
|
|
||||||
PREFIX_LOCK = 1 << 4,
|
|
||||||
PREFIX_REPNZ = 1 << 5,
|
|
||||||
PREFIX_REP = 1 << 6,
|
|
||||||
PREFIX_REX = 1 << 7,
|
|
||||||
PREFIX_REXB = 1 << 8,
|
|
||||||
PREFIX_REXX = 1 << 9,
|
|
||||||
PREFIX_REXR = 1 << 10,
|
|
||||||
PREFIX_REXW = 1 << 11,
|
|
||||||
PREFIX_ESC_NONE = 0 << 13,
|
|
||||||
PREFIX_ESC_0F = 1 << 13,
|
|
||||||
PREFIX_ESC_0F38 = 2 << 13,
|
|
||||||
PREFIX_ESC_0F3A = 3 << 13,
|
|
||||||
PREFIX_ESC_MASK = 3 << 13,
|
|
||||||
PREFIX_VEX = 1 << 15,
|
|
||||||
PREFIX_VEXL = 1 << 16,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum PrefixSet PrefixSet;
|
|
||||||
|
|
||||||
enum OperandType
|
enum OperandType
|
||||||
{
|
{
|
||||||
OT_NONE = 0,
|
OT_NONE = 0,
|
||||||
@@ -116,6 +98,7 @@ struct Instr
|
|||||||
{
|
{
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
struct Operand operands[4];
|
struct Operand operands[4];
|
||||||
|
uint8_t flags;
|
||||||
uint8_t segment;
|
uint8_t segment;
|
||||||
uint8_t op_size;
|
uint8_t op_size;
|
||||||
uint8_t addr_size;
|
uint8_t addr_size;
|
||||||
@@ -126,7 +109,6 @@ struct Instr
|
|||||||
uint8_t scale : 3;
|
uint8_t scale : 3;
|
||||||
uint8_t sreg : 5;
|
uint8_t sreg : 5;
|
||||||
|
|
||||||
PrefixSet prefixes;
|
|
||||||
size_t immediate;
|
size_t immediate;
|
||||||
intptr_t disp;
|
intptr_t disp;
|
||||||
|
|
||||||
@@ -139,11 +121,12 @@ typedef struct Instr Instr;
|
|||||||
#define INSTR_SEGMENT(instr) ((instr)->segment)
|
#define INSTR_SEGMENT(instr) ((instr)->segment)
|
||||||
#define INSTR_WIDTH(instr) ((instr)->op_size)
|
#define INSTR_WIDTH(instr) ((instr)->op_size)
|
||||||
#define INSTR_ADDRSZ(instr) ((instr)->addr_size)
|
#define INSTR_ADDRSZ(instr) ((instr)->addr_size)
|
||||||
#define INSTR_HAS_REP(instr) ((instr)->prefixes & PREFIX_REP)
|
#define INSTR_IS64(instr) ((instr)->flags & INSTR_FLAG_64)
|
||||||
#define INSTR_HAS_REPNZ(instr) ((instr)->prefixes & PREFIX_REPNZ)
|
#define INSTR_HAS_REP(instr) ((instr)->flags & INSTR_FLAG_REP)
|
||||||
#define INSTR_HAS_LOCK(instr) ((instr)->prefixes & PREFIX_LOCK)
|
#define INSTR_HAS_REPNZ(instr) ((instr)->flags & INSTR_FLAG_REPNZ)
|
||||||
#define INSTR_HAS_ADDRSZ(instr) ((instr)->prefixes & PREFIX_ADDRSZ)
|
#define INSTR_HAS_LOCK(instr) ((instr)->flags & INSTR_FLAG_LOCK)
|
||||||
#define INSTR_HAS_REX(instr) ((instr)->prefixes & PREFIX_REX)
|
#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, Instr* out_instr);
|
||||||
void instr_format(const Instr* instr, char buffer[128]);
|
void instr_format(const Instr* instr, char buffer[128]);
|
||||||
|
|||||||
Reference in New Issue
Block a user