Skip to content

Remove deprecated accessed_flags flags field from ZydisDecodedInstruction #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 48 additions & 151 deletions include/Zydis/DecoderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,197 +240,126 @@ typedef struct ZydisDecodedOperand_
/* ============================================================================================== */

/* ---------------------------------------------------------------------------------------------- */
/* R/E/FLAGS info */
/* CPU/FPU flags */
/* ---------------------------------------------------------------------------------------------- */

/**
* Defines the `ZydisCPUFlags` data-type.
* Defines the `ZydisAccessedFlagsMask` data-type.
*/
typedef ZyanU32 ZydisCPUFlags;

/**
* Defines the `ZydisCPUFlag` data-type.
*/
typedef ZyanU8 ZydisCPUFlag;
typedef ZyanU32 ZydisAccessedFlagsMask;

/**
* Carry flag.
*/
#define ZYDIS_CPUFLAG_CF 0
#define ZYDIS_CPUFLAG_CF (1ul << 0)
/**
* Parity flag.
*/
#define ZYDIS_CPUFLAG_PF 2
#define ZYDIS_CPUFLAG_PF (1ul << 2)
/**
* Adjust flag.
*/
#define ZYDIS_CPUFLAG_AF 4
#define ZYDIS_CPUFLAG_AF (1ul << 4)
/**
* Zero flag.
*/
#define ZYDIS_CPUFLAG_ZF 6
#define ZYDIS_CPUFLAG_ZF (1ul << 6)
/**
* Sign flag.
*/
#define ZYDIS_CPUFLAG_SF 7
#define ZYDIS_CPUFLAG_SF (1ul << 7)
/**
* Trap flag.
*/
#define ZYDIS_CPUFLAG_TF 8
#define ZYDIS_CPUFLAG_TF (1ul << 8)
/**
* Interrupt enable flag.
*/
#define ZYDIS_CPUFLAG_IF 9
#define ZYDIS_CPUFLAG_IF (1ul << 9)
/**
* Direction flag.
*/
#define ZYDIS_CPUFLAG_DF 10
#define ZYDIS_CPUFLAG_DF (1ul << 10)
/**
* Overflow flag.
*/
#define ZYDIS_CPUFLAG_OF 11
#define ZYDIS_CPUFLAG_OF (1ul << 11)
/**
* I/O privilege level flag.
*/
#define ZYDIS_CPUFLAG_IOPL 12
#define ZYDIS_CPUFLAG_IOPL (1ul << 12)
/**
* Nested task flag.
*/
#define ZYDIS_CPUFLAG_NT 14
#define ZYDIS_CPUFLAG_NT (1ul << 14)
/**
* Resume flag.
*/
#define ZYDIS_CPUFLAG_RF 16
#define ZYDIS_CPUFLAG_RF (1ul << 16)
/**
* Virtual 8086 mode flag.
*/
#define ZYDIS_CPUFLAG_VM 17
#define ZYDIS_CPUFLAG_VM (1ul << 17)
/**
* Alignment check.
*/
#define ZYDIS_CPUFLAG_AC 18
#define ZYDIS_CPUFLAG_AC (1ul << 18)
/**
* Virtual interrupt flag.
*/
#define ZYDIS_CPUFLAG_VIF 19
#define ZYDIS_CPUFLAG_VIF (1ul << 19)
/**
* Virtual interrupt pending.
*/
#define ZYDIS_CPUFLAG_VIP 20
#define ZYDIS_CPUFLAG_VIP (1ul << 20)
/**
* Able to use CPUID instruction.
*/
#define ZYDIS_CPUFLAG_ID 21

///////////////////////////////////////////////////////////////////////////////////////////////////

/**
* FPU condition-code flag 0.
*
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
*/
#define ZYDIS_CPUFLAG_C0 22
/**
* FPU condition-code flag 1.
*
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
*/
#define ZYDIS_CPUFLAG_C1 23
/**
* FPU condition-code flag 2.
*
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
*/
#define ZYDIS_CPUFLAG_C2 24
/**
* FPU condition-code flag 3.
*
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
*/
#define ZYDIS_CPUFLAG_C3 25

/**
* DEPRECATED. This define will be removed in the next major release.
*/
#define ZYDIS_CPUFLAG_MAX_VALUE ZYDIS_CPUFLAG_C3

///////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Defines the `ZydisFPUFlags` data-type.
*/
typedef ZyanU8 ZydisFPUFlags;
#define ZYDIS_CPUFLAG_ID (1ul << 21)

/**
* FPU condition-code flag 0.
*/
#define ZYDIS_FPUFLAG_C0 0x00 // (1 << 0)
#define ZYDIS_FPUFLAG_C0 (1ul << 0)
/**
* FPU condition-code flag 1.
*/
#define ZYDIS_FPUFLAG_C1 0x01 // (1 << 1)
#define ZYDIS_FPUFLAG_C1 (1ul << 1)
/**
* FPU condition-code flag 2.
*/
#define ZYDIS_FPUFLAG_C2 0x02 // (1 << 2)
#define ZYDIS_FPUFLAG_C2 (1ul << 2)
/**
* FPU condition-code flag 3.
*/
#define ZYDIS_FPUFLAG_C3 0x04 // (1 << 3)
#define ZYDIS_FPUFLAG_C3 (1ul << 3)

/**
* Defines the `ZydisCPUFlagAction` enum.
*
* DEPRECATED. This enum will be removed in the next major release.
/*
* Information about CPU/FPU flags accessed by the instruction.
*/
typedef enum ZydisCPUFlagAction_
typedef struct ZydisAccessedFlags_
{
/**
* The CPU flag is not touched by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_NONE,
/**
* The CPU flag is tested (read).
*/
ZYDIS_CPUFLAG_ACTION_TESTED,
/**
* The CPU flag is tested and modified afterwards (read-write).
*/
ZYDIS_CPUFLAG_ACTION_TESTED_MODIFIED,
/**
* The CPU flag is modified (write).
*/
ZYDIS_CPUFLAG_ACTION_MODIFIED,
/**
* The CPU flag is set to 0 (write).
/*
* As mask containing the flags `TESTED` by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_SET_0,
/**
* The CPU flag is set to 1 (write).
ZydisAccessedFlagsMask tested;
/*
* As mask containing the flags `MODIFIED` by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_SET_1,
/**
* The CPU flag is undefined (write).
ZydisAccessedFlagsMask modified;
/*
* As mask containing the flags `SET_0` by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_UNDEFINED,

/**
* Maximum value of this enum.
ZydisAccessedFlagsMask set_0;
/*
* As mask containing the flags `SET_1` by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_MAX_VALUE = ZYDIS_CPUFLAG_ACTION_UNDEFINED,
/**
* The minimum number of bits required to represent all values of this enum.
ZydisAccessedFlagsMask set_1;
/*
* As mask containing the flags `UNDEFINED` by the instruction.
*/
ZYDIS_CPUFLAG_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CPUFLAG_ACTION_MAX_VALUE)
} ZydisCPUFlagAction;
ZydisAccessedFlagsMask undefined;
} ZydisAccessedFlags;

/* ---------------------------------------------------------------------------------------------- */
/* Branch types */
Expand Down Expand Up @@ -803,48 +732,16 @@ typedef struct ZydisDecodedInstruction_
*/
ZydisInstructionAttributes attributes;
/**
* Information about accessed CPU flags.
*
* DEPRECATED. This field will be removed in the next major release. Please use the
* `cpu_flags_read`/`cpu_flags_written` or `fpu_flags_read`/`fpu_flags_written` fields
* instead.
*/
struct ZydisDecodedInstructionAccessedFlags_
{
/**
* The CPU-flag action.
*
* Use `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a specific
* action.
*/
ZydisCPUFlagAction action;
} accessed_flags[ZYDIS_CPUFLAG_MAX_VALUE + 1];
/**
* A mask containing the CPU flags read by the instruction.
* Information about CPU flags accessed by the instruction.
*
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
* The bits in the masks correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
* register.
*
* This mask includes the actions `TESTED` and `TESTED_MODIFIED`.
*/
ZydisCPUFlags cpu_flags_read;
/**
* A mask containing the CPU flags written by the instruction.
*
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
* register.
*
* This mask includes the actions `TESTED_MODIFIED`, `SET_0`, `SET_1` and `UNDEFINED`.
*/
ZydisCPUFlags cpu_flags_written;
/**
* A mask containing the FPU flags read by the instruction.
*/
ZydisFPUFlags fpu_flags_read;
const ZydisAccessedFlags* cpu_flags;
/**
* A mask containing the FPU flags written by the instruction.
* Information about FPU flags accessed by the instruction.
*/
ZydisFPUFlags fpu_flags_written;
const ZydisAccessedFlags* fpu_flags;
/**
* Extended info for `AVX` instructions.
*/
Expand Down
36 changes: 21 additions & 15 deletions include/Zydis/Internal/SharedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,19 +884,6 @@ typedef struct ZydisInstructionDefinitionMVEX_
} ZydisInstructionDefinitionMVEX;
#endif

/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */

typedef struct ZydisAccessedFlags_
{
ZydisCPUFlagAction action[ZYDIS_CPUFLAG_MAX_VALUE + 1];
ZyanU32 cpu_flags_read ZYAN_BITFIELD(22);
ZyanU32 cpu_flags_written ZYAN_BITFIELD(22);
ZyanU8 fpu_flags_read ZYAN_BITFIELD( 4);
ZyanU8 fpu_flags_written ZYAN_BITFIELD( 4);
} ZydisAccessedFlags;

/* ---------------------------------------------------------------------------------------------- */

#pragma pack(pop)
Expand All @@ -905,6 +892,24 @@ typedef struct ZydisAccessedFlags_
# pragma warning(pop)
#endif

/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU/FPU flags */
/* ---------------------------------------------------------------------------------------------- */

/*
* Contains information about the CPU/FPU flags accessed by an instruction.
*
* We don't want this struct to be packed! A pointer to the individual members will be used by the
* `ZydisDecodedInstruction` struct.
*/
typedef struct ZydisDefinitionAccessedFlags_
{
ZydisAccessedFlags cpu_flags;
ZydisAccessedFlags fpu_flags;
} ZydisDefinitionAccessedFlags;

/* ---------------------------------------------------------------------------------------------- */

/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
Expand Down Expand Up @@ -967,12 +972,13 @@ ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, Zydis
* Returns the the operand-definitions for the given instruction-`definition`.
*
* @param definition A pointer to the instruction-definition.
* @param flags A pointer to the variable that receives the `ZydisAccessedFlags` struct.
* @param flags A pointer to the variable that receives the `ZydisDefinitionAccessedFlags`
* struct.
*
* @return `ZYAN_TRUE`, if the instruction accesses any flags, or `ZYAN_FALSE`, if not.
*/
ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
const ZydisAccessedFlags** flags);
const ZydisDefinitionAccessedFlags** flags);
#endif

/* ---------------------------------------------------------------------------------------------- */
Expand Down
Loading