Replace FD_OP with FD_OT to avoid macro collision
This commit is contained in:
20
decode.c
20
decode.c
@@ -229,7 +229,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr,
|
|||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += prefixes & PREFIX_REXR ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXR ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o2->type = FD_OP_REG;
|
out_o2->type = FD_OT_REG;
|
||||||
out_o2->reg = reg_idx;
|
out_o2->reg = reg_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr,
|
|||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
out_o1->type = FD_OP_REG;
|
out_o1->type = FD_OT_REG;
|
||||||
out_o1->reg = reg_idx;
|
out_o1->reg = reg_idx;
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr,
|
|||||||
instr->disp = 0;
|
instr->disp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_o1->type = FD_OP_MEM;
|
out_o1->type = FD_OT_MEM;
|
||||||
instr->idx_scale = scale;
|
instr->idx_scale = scale;
|
||||||
|
|
||||||
// If there was no SIB byte.
|
// If there was no SIB byte.
|
||||||
@@ -508,7 +508,7 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
|
|||||||
if (DESC_HAS_IMPLICIT(desc))
|
if (DESC_HAS_IMPLICIT(desc))
|
||||||
{
|
{
|
||||||
FdOp* operand = &instr->operands[DESC_IMPLICIT_IDX(desc)];
|
FdOp* operand = &instr->operands[DESC_IMPLICIT_IDX(desc)];
|
||||||
operand->type = FD_OP_REG;
|
operand->type = FD_OT_REG;
|
||||||
operand->reg = 0;
|
operand->reg = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,14 +539,14 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
|
|||||||
#if defined(ARCH_X86_64)
|
#if defined(ARCH_X86_64)
|
||||||
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
reg_idx += prefixes & PREFIX_REXB ? 8 : 0;
|
||||||
#endif
|
#endif
|
||||||
operand->type = FD_OP_REG;
|
operand->type = FD_OT_REG;
|
||||||
operand->reg = reg_idx;
|
operand->reg = reg_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UNLIKELY(DESC_HAS_VEXREG(desc)))
|
if (UNLIKELY(DESC_HAS_VEXREG(desc)))
|
||||||
{
|
{
|
||||||
FdOp* operand = &instr->operands[DESC_VEXREG_IDX(desc)];
|
FdOp* operand = &instr->operands[DESC_VEXREG_IDX(desc)];
|
||||||
operand->type = FD_OP_REG;
|
operand->type = FD_OT_REG;
|
||||||
operand->reg = vex_operand;
|
operand->reg = vex_operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,14 +554,14 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
|
|||||||
if (imm_control == 1)
|
if (imm_control == 1)
|
||||||
{
|
{
|
||||||
FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
||||||
operand->type = FD_OP_IMM;
|
operand->type = FD_OT_IMM;
|
||||||
operand->size = 1;
|
operand->size = 1;
|
||||||
instr->imm = 1;
|
instr->imm = 1;
|
||||||
}
|
}
|
||||||
else if (imm_control == 2)
|
else if (imm_control == 2)
|
||||||
{
|
{
|
||||||
FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)];
|
||||||
operand->type = FD_OP_MEM;
|
operand->type = FD_OT_MEM;
|
||||||
operand->reg = FD_REG_NONE;
|
operand->reg = FD_REG_NONE;
|
||||||
operand->size = op_size;
|
operand->size = op_size;
|
||||||
instr->idx_reg = FD_REG_NONE;
|
instr->idx_reg = FD_REG_NONE;
|
||||||
@@ -658,12 +658,12 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
|
|||||||
|
|
||||||
if (UNLIKELY(imm_control == 5))
|
if (UNLIKELY(imm_control == 5))
|
||||||
{
|
{
|
||||||
operand->type = FD_OP_REG;
|
operand->type = FD_OT_REG;
|
||||||
operand->reg = (instr->imm & 0xf0) >> 4;
|
operand->reg = (instr->imm & 0xf0) >> 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
operand->type = FD_OP_IMM;
|
operand->type = FD_OT_IMM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
fadec.h
22
fadec.h
@@ -43,10 +43,10 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FD_OP_NONE = 0,
|
FD_OT_NONE = 0,
|
||||||
FD_OP_REG = 1,
|
FD_OT_REG = 1,
|
||||||
FD_OP_IMM = 2,
|
FD_OT_IMM = 2,
|
||||||
FD_OP_MEM = 3,
|
FD_OT_MEM = 3,
|
||||||
} FdOpType;
|
} FdOpType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -144,12 +144,12 @@ void fd_format(const FdInstr* instr, char* buf, size_t len);
|
|||||||
* purpose register with an index in the range 4-7, it needs to be determined
|
* purpose register with an index in the range 4-7, it needs to be determined
|
||||||
* explicitly whether a high-byte register is accessed (using FD_OP_REG_HIGH).
|
* explicitly whether a high-byte register is accessed (using FD_OP_REG_HIGH).
|
||||||
* If that is the case, the index needs to be decreased by 4.
|
* If that is the case, the index needs to be decreased by 4.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_REG **/
|
* Only valid if FD_OP_TYPE == FD_OT_REG **/
|
||||||
#define FD_OP_REG(instr,idx) ((FdReg) (instr)->operands[idx].reg)
|
#define FD_OP_REG(instr,idx) ((FdReg) (instr)->operands[idx].reg)
|
||||||
/** Returns whether the accessed register is a actually high-byte register when
|
/** Returns whether the accessed register is a actually high-byte register when
|
||||||
* used on a general purpose instruction. In that case, the register index has
|
* used on a general purpose instruction. In that case, the register index has
|
||||||
* to be decreased by 4.
|
* to be decreased by 4.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_REG and the operand refers to a general
|
* Only valid if FD_OP_TYPE == FD_OT_REG and the operand refers to a general
|
||||||
* purpose register (depends on the instruction type) **/
|
* purpose register (depends on the instruction type) **/
|
||||||
#define FD_OP_REG_HIGH(instr,idx) ( \
|
#define FD_OP_REG_HIGH(instr,idx) ( \
|
||||||
(instr)->operands[idx].size == 1 && \
|
(instr)->operands[idx].size == 1 && \
|
||||||
@@ -160,23 +160,23 @@ void fd_format(const FdInstr* instr, char* buf, size_t len);
|
|||||||
* if the memory operand has no base register. This is the only case where the
|
* if the memory operand has no base register. This is the only case where the
|
||||||
* 64-bit register RIP can be returned, in which case the operand also has no
|
* 64-bit register RIP can be returned, in which case the operand also has no
|
||||||
* scaled index register.
|
* scaled index register.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_MEM **/
|
* Only valid if FD_OP_TYPE == FD_OT_MEM **/
|
||||||
#define FD_OP_BASE(instr,idx) ((FdReg) (instr)->operands[idx].reg)
|
#define FD_OP_BASE(instr,idx) ((FdReg) (instr)->operands[idx].reg)
|
||||||
/** Gets the index of the index register from a memory operand, or FD_REG_NONE,
|
/** Gets the index of the index register from a memory operand, or FD_REG_NONE,
|
||||||
* if the memory operand has no scaled index register.
|
* if the memory operand has no scaled index register.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_MEM **/
|
* Only valid if FD_OP_TYPE == FD_OT_MEM **/
|
||||||
#define FD_OP_INDEX(instr,idx) ((FdReg) (instr)->idx_reg)
|
#define FD_OP_INDEX(instr,idx) ((FdReg) (instr)->idx_reg)
|
||||||
/** Gets the scale of the index register from a memory operand when existent.
|
/** Gets the scale of the index register from a memory operand when existent.
|
||||||
* This does /not/ return the scale in an absolute value but returns the amount
|
* This does /not/ return the scale in an absolute value but returns the amount
|
||||||
* of bits the index register is shifted to the left (i.e. the value in in the
|
* of bits the index register is shifted to the left (i.e. the value in in the
|
||||||
* range 0-3). The actual scale can be computed easily using 1<<FD_OP_SCALE.
|
* range 0-3). The actual scale can be computed easily using 1<<FD_OP_SCALE.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_MEM and FD_OP_INDEX != FD_REG_NONE **/
|
* Only valid if FD_OP_TYPE == FD_OT_MEM and FD_OP_INDEX != FD_REG_NONE **/
|
||||||
#define FD_OP_SCALE(instr,idx) ((instr)->idx_scale)
|
#define FD_OP_SCALE(instr,idx) ((instr)->idx_scale)
|
||||||
/** Gets the sign-extended displacement of a memory operand.
|
/** Gets the sign-extended displacement of a memory operand.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_MEM **/
|
* Only valid if FD_OP_TYPE == FD_OT_MEM **/
|
||||||
#define FD_OP_DISP(instr,idx) ((instr)->disp)
|
#define FD_OP_DISP(instr,idx) ((instr)->disp)
|
||||||
/** Gets the (sign-extended) encoded constant for an immediate operand.
|
/** Gets the (sign-extended) encoded constant for an immediate operand.
|
||||||
* Only valid if FD_OP_TYPE == FD_OP_IMM **/
|
* Only valid if FD_OP_TYPE == FD_OT_IMM **/
|
||||||
#define FD_OP_IMM(instr,idx) ((instr)->imm)
|
#define FD_OP_IMM(instr,idx) ((instr)->imm)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
10
format.c
10
format.c
@@ -52,7 +52,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len)
|
|||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
FdOpType op_type = FD_OP_TYPE(instr, i);
|
FdOpType op_type = FD_OP_TYPE(instr, i);
|
||||||
if (op_type == FD_OP_NONE)
|
if (op_type == FD_OT_NONE)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const char* op_type_name = "reg\0imm\0mem" + op_type * 4 - 4;
|
const char* op_type_name = "reg\0imm\0mem" + op_type * 4 - 4;
|
||||||
@@ -64,13 +64,13 @@ fd_format(const FdInstr* instr, char* buffer, size_t len)
|
|||||||
bool has_base;
|
bool has_base;
|
||||||
bool has_idx;
|
bool has_idx;
|
||||||
bool has_disp;
|
bool has_disp;
|
||||||
case FD_OP_REG:
|
case FD_OT_REG:
|
||||||
if (FD_OP_REG_HIGH(instr, i))
|
if (FD_OP_REG_HIGH(instr, i))
|
||||||
FMT_CONCAT(buf, end, "r%uh", FD_OP_REG(instr, i) - 4);
|
FMT_CONCAT(buf, end, "r%uh", FD_OP_REG(instr, i) - 4);
|
||||||
else
|
else
|
||||||
FMT_CONCAT(buf, end, "r%u", FD_OP_REG(instr, i));
|
FMT_CONCAT(buf, end, "r%u", FD_OP_REG(instr, i));
|
||||||
break;
|
break;
|
||||||
case FD_OP_IMM:
|
case FD_OT_IMM:
|
||||||
immediate = FD_OP_IMM(instr, i);
|
immediate = FD_OP_IMM(instr, i);
|
||||||
if (FD_OP_SIZE(instr, i) == 1)
|
if (FD_OP_SIZE(instr, i) == 1)
|
||||||
immediate &= 0xff;
|
immediate &= 0xff;
|
||||||
@@ -80,7 +80,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len)
|
|||||||
immediate &= 0xffffffff;
|
immediate &= 0xffffffff;
|
||||||
FMT_CONCAT(buf, end, "0x%lx", immediate);
|
FMT_CONCAT(buf, end, "0x%lx", immediate);
|
||||||
break;
|
break;
|
||||||
case FD_OP_MEM:
|
case FD_OT_MEM:
|
||||||
has_base = FD_OP_BASE(instr, i) != FD_REG_NONE;
|
has_base = FD_OP_BASE(instr, i) != FD_REG_NONE;
|
||||||
has_idx = FD_OP_INDEX(instr, i) != FD_REG_NONE;
|
has_idx = FD_OP_INDEX(instr, i) != FD_REG_NONE;
|
||||||
has_disp = FD_OP_DISP(instr, i) != 0;
|
has_disp = FD_OP_DISP(instr, i) != 0;
|
||||||
@@ -102,7 +102,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len)
|
|||||||
else if (has_disp || (!has_base && !has_idx))
|
else if (has_disp || (!has_base && !has_idx))
|
||||||
FMT_CONCAT(buf, end, "0x%lx", FD_OP_DISP(instr, i));
|
FMT_CONCAT(buf, end, "0x%lx", FD_OP_DISP(instr, i));
|
||||||
break;
|
break;
|
||||||
case FD_OP_NONE:
|
case FD_OT_NONE:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user