Skip to content

Commit 7d6ee06

Browse files
authored
Remove legacy code and general cleanup (#262)
1 parent 162ef4e commit 7d6ee06

25 files changed

+406
-557
lines changed

include/Zydis/DecoderTypes.h

+48-151
Original file line numberDiff line numberDiff line change
@@ -240,197 +240,126 @@ typedef struct ZydisDecodedOperand_
240240
/* ============================================================================================== */
241241

242242
/* ---------------------------------------------------------------------------------------------- */
243-
/* R/E/FLAGS info */
243+
/* CPU/FPU flags */
244244
/* ---------------------------------------------------------------------------------------------- */
245245

246246
/**
247-
* Defines the `ZydisCPUFlags` data-type.
247+
* Defines the `ZydisAccessedFlagsMask` data-type.
248248
*/
249-
typedef ZyanU32 ZydisCPUFlags;
250-
251-
/**
252-
* Defines the `ZydisCPUFlag` data-type.
253-
*/
254-
typedef ZyanU8 ZydisCPUFlag;
249+
typedef ZyanU32 ZydisAccessedFlagsMask;
255250

256251
/**
257252
* Carry flag.
258253
*/
259-
#define ZYDIS_CPUFLAG_CF 0
254+
#define ZYDIS_CPUFLAG_CF (1ul << 0)
260255
/**
261256
* Parity flag.
262257
*/
263-
#define ZYDIS_CPUFLAG_PF 2
258+
#define ZYDIS_CPUFLAG_PF (1ul << 2)
264259
/**
265260
* Adjust flag.
266261
*/
267-
#define ZYDIS_CPUFLAG_AF 4
262+
#define ZYDIS_CPUFLAG_AF (1ul << 4)
268263
/**
269264
* Zero flag.
270265
*/
271-
#define ZYDIS_CPUFLAG_ZF 6
266+
#define ZYDIS_CPUFLAG_ZF (1ul << 6)
272267
/**
273268
* Sign flag.
274269
*/
275-
#define ZYDIS_CPUFLAG_SF 7
270+
#define ZYDIS_CPUFLAG_SF (1ul << 7)
276271
/**
277272
* Trap flag.
278273
*/
279-
#define ZYDIS_CPUFLAG_TF 8
274+
#define ZYDIS_CPUFLAG_TF (1ul << 8)
280275
/**
281276
* Interrupt enable flag.
282277
*/
283-
#define ZYDIS_CPUFLAG_IF 9
278+
#define ZYDIS_CPUFLAG_IF (1ul << 9)
284279
/**
285280
* Direction flag.
286281
*/
287-
#define ZYDIS_CPUFLAG_DF 10
282+
#define ZYDIS_CPUFLAG_DF (1ul << 10)
288283
/**
289284
* Overflow flag.
290285
*/
291-
#define ZYDIS_CPUFLAG_OF 11
286+
#define ZYDIS_CPUFLAG_OF (1ul << 11)
292287
/**
293288
* I/O privilege level flag.
294289
*/
295-
#define ZYDIS_CPUFLAG_IOPL 12
290+
#define ZYDIS_CPUFLAG_IOPL (1ul << 12)
296291
/**
297292
* Nested task flag.
298293
*/
299-
#define ZYDIS_CPUFLAG_NT 14
294+
#define ZYDIS_CPUFLAG_NT (1ul << 14)
300295
/**
301296
* Resume flag.
302297
*/
303-
#define ZYDIS_CPUFLAG_RF 16
298+
#define ZYDIS_CPUFLAG_RF (1ul << 16)
304299
/**
305300
* Virtual 8086 mode flag.
306301
*/
307-
#define ZYDIS_CPUFLAG_VM 17
302+
#define ZYDIS_CPUFLAG_VM (1ul << 17)
308303
/**
309304
* Alignment check.
310305
*/
311-
#define ZYDIS_CPUFLAG_AC 18
306+
#define ZYDIS_CPUFLAG_AC (1ul << 18)
312307
/**
313308
* Virtual interrupt flag.
314309
*/
315-
#define ZYDIS_CPUFLAG_VIF 19
310+
#define ZYDIS_CPUFLAG_VIF (1ul << 19)
316311
/**
317312
* Virtual interrupt pending.
318313
*/
319-
#define ZYDIS_CPUFLAG_VIP 20
314+
#define ZYDIS_CPUFLAG_VIP (1ul << 20)
320315
/**
321316
* Able to use CPUID instruction.
322317
*/
323-
#define ZYDIS_CPUFLAG_ID 21
324-
325-
///////////////////////////////////////////////////////////////////////////////////////////////////
326-
327-
/**
328-
* FPU condition-code flag 0.
329-
*
330-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
331-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
332-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
333-
*/
334-
#define ZYDIS_CPUFLAG_C0 22
335-
/**
336-
* FPU condition-code flag 1.
337-
*
338-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
339-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
340-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
341-
*/
342-
#define ZYDIS_CPUFLAG_C1 23
343-
/**
344-
* FPU condition-code flag 2.
345-
*
346-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
347-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
348-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
349-
*/
350-
#define ZYDIS_CPUFLAG_C2 24
351-
/**
352-
* FPU condition-code flag 3.
353-
*
354-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
355-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
356-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
357-
*/
358-
#define ZYDIS_CPUFLAG_C3 25
359-
360-
/**
361-
* DEPRECATED. This define will be removed in the next major release.
362-
*/
363-
#define ZYDIS_CPUFLAG_MAX_VALUE ZYDIS_CPUFLAG_C3
364-
365-
///////////////////////////////////////////////////////////////////////////////////////////////////
366-
367-
/**
368-
* Defines the `ZydisFPUFlags` data-type.
369-
*/
370-
typedef ZyanU8 ZydisFPUFlags;
318+
#define ZYDIS_CPUFLAG_ID (1ul << 21)
371319

372320
/**
373321
* FPU condition-code flag 0.
374322
*/
375-
#define ZYDIS_FPUFLAG_C0 0x00 // (1 << 0)
323+
#define ZYDIS_FPUFLAG_C0 (1ul << 0)
376324
/**
377325
* FPU condition-code flag 1.
378326
*/
379-
#define ZYDIS_FPUFLAG_C1 0x01 // (1 << 1)
327+
#define ZYDIS_FPUFLAG_C1 (1ul << 1)
380328
/**
381329
* FPU condition-code flag 2.
382330
*/
383-
#define ZYDIS_FPUFLAG_C2 0x02 // (1 << 2)
331+
#define ZYDIS_FPUFLAG_C2 (1ul << 2)
384332
/**
385333
* FPU condition-code flag 3.
386334
*/
387-
#define ZYDIS_FPUFLAG_C3 0x04 // (1 << 3)
335+
#define ZYDIS_FPUFLAG_C3 (1ul << 3)
388336

389-
/**
390-
* Defines the `ZydisCPUFlagAction` enum.
391-
*
392-
* DEPRECATED. This enum will be removed in the next major release.
337+
/*
338+
* Information about CPU/FPU flags accessed by the instruction.
393339
*/
394-
typedef enum ZydisCPUFlagAction_
340+
typedef struct ZydisAccessedFlags_
395341
{
396-
/**
397-
* The CPU flag is not touched by the instruction.
398-
*/
399-
ZYDIS_CPUFLAG_ACTION_NONE,
400-
/**
401-
* The CPU flag is tested (read).
402-
*/
403-
ZYDIS_CPUFLAG_ACTION_TESTED,
404-
/**
405-
* The CPU flag is tested and modified afterwards (read-write).
406-
*/
407-
ZYDIS_CPUFLAG_ACTION_TESTED_MODIFIED,
408-
/**
409-
* The CPU flag is modified (write).
410-
*/
411-
ZYDIS_CPUFLAG_ACTION_MODIFIED,
412-
/**
413-
* The CPU flag is set to 0 (write).
342+
/*
343+
* As mask containing the flags `TESTED` by the instruction.
414344
*/
415-
ZYDIS_CPUFLAG_ACTION_SET_0,
416-
/**
417-
* The CPU flag is set to 1 (write).
345+
ZydisAccessedFlagsMask tested;
346+
/*
347+
* As mask containing the flags `MODIFIED` by the instruction.
418348
*/
419-
ZYDIS_CPUFLAG_ACTION_SET_1,
420-
/**
421-
* The CPU flag is undefined (write).
349+
ZydisAccessedFlagsMask modified;
350+
/*
351+
* As mask containing the flags `SET_0` by the instruction.
422352
*/
423-
ZYDIS_CPUFLAG_ACTION_UNDEFINED,
424-
425-
/**
426-
* Maximum value of this enum.
353+
ZydisAccessedFlagsMask set_0;
354+
/*
355+
* As mask containing the flags `SET_1` by the instruction.
427356
*/
428-
ZYDIS_CPUFLAG_ACTION_MAX_VALUE = ZYDIS_CPUFLAG_ACTION_UNDEFINED,
429-
/**
430-
* The minimum number of bits required to represent all values of this enum.
357+
ZydisAccessedFlagsMask set_1;
358+
/*
359+
* As mask containing the flags `UNDEFINED` by the instruction.
431360
*/
432-
ZYDIS_CPUFLAG_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CPUFLAG_ACTION_MAX_VALUE)
433-
} ZydisCPUFlagAction;
361+
ZydisAccessedFlagsMask undefined;
362+
} ZydisAccessedFlags;
434363

435364
/* ---------------------------------------------------------------------------------------------- */
436365
/* Branch types */
@@ -803,48 +732,16 @@ typedef struct ZydisDecodedInstruction_
803732
*/
804733
ZydisInstructionAttributes attributes;
805734
/**
806-
* Information about accessed CPU flags.
807-
*
808-
* DEPRECATED. This field will be removed in the next major release. Please use the
809-
* `cpu_flags_read`/`cpu_flags_written` or `fpu_flags_read`/`fpu_flags_written` fields
810-
* instead.
811-
*/
812-
struct ZydisDecodedInstructionAccessedFlags_
813-
{
814-
/**
815-
* The CPU-flag action.
816-
*
817-
* Use `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a specific
818-
* action.
819-
*/
820-
ZydisCPUFlagAction action;
821-
} accessed_flags[ZYDIS_CPUFLAG_MAX_VALUE + 1];
822-
/**
823-
* A mask containing the CPU flags read by the instruction.
735+
* Information about CPU flags accessed by the instruction.
824736
*
825-
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
737+
* The bits in the masks correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
826738
* register.
827-
*
828-
* This mask includes the actions `TESTED` and `TESTED_MODIFIED`.
829-
*/
830-
ZydisCPUFlags cpu_flags_read;
831-
/**
832-
* A mask containing the CPU flags written by the instruction.
833-
*
834-
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
835-
* register.
836-
*
837-
* This mask includes the actions `TESTED_MODIFIED`, `SET_0`, `SET_1` and `UNDEFINED`.
838-
*/
839-
ZydisCPUFlags cpu_flags_written;
840-
/**
841-
* A mask containing the FPU flags read by the instruction.
842739
*/
843-
ZydisFPUFlags fpu_flags_read;
740+
const ZydisAccessedFlags* cpu_flags;
844741
/**
845-
* A mask containing the FPU flags written by the instruction.
742+
* Information about FPU flags accessed by the instruction.
846743
*/
847-
ZydisFPUFlags fpu_flags_written;
744+
const ZydisAccessedFlags* fpu_flags;
848745
/**
849746
* Extended info for `AVX` instructions.
850747
*/

include/Zydis/Internal/SharedData.h

+21-15
Original file line numberDiff line numberDiff line change
@@ -884,19 +884,6 @@ typedef struct ZydisInstructionDefinitionMVEX_
884884
} ZydisInstructionDefinitionMVEX;
885885
#endif
886886

887-
/* ---------------------------------------------------------------------------------------------- */
888-
/* Accessed CPU flags */
889-
/* ---------------------------------------------------------------------------------------------- */
890-
891-
typedef struct ZydisAccessedFlags_
892-
{
893-
ZydisCPUFlagAction action[ZYDIS_CPUFLAG_MAX_VALUE + 1];
894-
ZyanU32 cpu_flags_read ZYAN_BITFIELD(22);
895-
ZyanU32 cpu_flags_written ZYAN_BITFIELD(22);
896-
ZyanU8 fpu_flags_read ZYAN_BITFIELD( 4);
897-
ZyanU8 fpu_flags_written ZYAN_BITFIELD( 4);
898-
} ZydisAccessedFlags;
899-
900887
/* ---------------------------------------------------------------------------------------------- */
901888

902889
#pragma pack(pop)
@@ -905,6 +892,24 @@ typedef struct ZydisAccessedFlags_
905892
# pragma warning(pop)
906893
#endif
907894

895+
/* ---------------------------------------------------------------------------------------------- */
896+
/* Accessed CPU/FPU flags */
897+
/* ---------------------------------------------------------------------------------------------- */
898+
899+
/*
900+
* Contains information about the CPU/FPU flags accessed by an instruction.
901+
*
902+
* We don't want this struct to be packed! A pointer to the individual members will be used by the
903+
* `ZydisDecodedInstruction` struct.
904+
*/
905+
typedef struct ZydisDefinitionAccessedFlags_
906+
{
907+
ZydisAccessedFlags cpu_flags;
908+
ZydisAccessedFlags fpu_flags;
909+
} ZydisDefinitionAccessedFlags;
910+
911+
/* ---------------------------------------------------------------------------------------------- */
912+
908913
/* ============================================================================================== */
909914
/* Functions */
910915
/* ============================================================================================== */
@@ -967,12 +972,13 @@ ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, Zydis
967972
* Returns the the operand-definitions for the given instruction-`definition`.
968973
*
969974
* @param definition A pointer to the instruction-definition.
970-
* @param flags A pointer to the variable that receives the `ZydisAccessedFlags` struct.
975+
* @param flags A pointer to the variable that receives the `ZydisDefinitionAccessedFlags`
976+
* struct.
971977
*
972978
* @return `ZYAN_TRUE`, if the instruction accesses any flags, or `ZYAN_FALSE`, if not.
973979
*/
974980
ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
975-
const ZydisAccessedFlags** flags);
981+
const ZydisDefinitionAccessedFlags** flags);
976982
#endif
977983

978984
/* ---------------------------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)