Skip to content

Commit 5580ced

Browse files
committed
Remove deprecated accessed_flags flags field from ZydisDecodedInstruction
1 parent 55dd08c commit 5580ced

21 files changed

+219
-363
lines changed

include/Zydis/DecoderTypes.h

+52-129
Original file line numberDiff line numberDiff line change
@@ -457,129 +457,82 @@ typedef ZyanU64 ZydisInstructionAttributes;
457457
#define ZYDIS_ATTRIB_HAS_NOTRACK 0x0000100000000000 // (1 << 44) // TODO: rebase
458458

459459
/* ---------------------------------------------------------------------------------------------- */
460-
/* R/E/FLAGS info */
460+
/* CPU/FPU flags */
461461
/* ---------------------------------------------------------------------------------------------- */
462462

463463
/**
464464
* Defines the `ZydisCPUFlags` data-type.
465465
*/
466466
typedef ZyanU32 ZydisCPUFlags;
467467

468-
/**
469-
* Defines the `ZydisCPUFlag` data-type.
470-
*/
471-
typedef ZyanU8 ZydisCPUFlag;
472-
473468
/**
474469
* Carry flag.
475470
*/
476-
#define ZYDIS_CPUFLAG_CF 0
471+
#define ZYDIS_CPUFLAG_CF (1ul << 0)
477472
/**
478473
* Parity flag.
479474
*/
480-
#define ZYDIS_CPUFLAG_PF 2
475+
#define ZYDIS_CPUFLAG_PF (1ul << 2)
481476
/**
482477
* Adjust flag.
483478
*/
484-
#define ZYDIS_CPUFLAG_AF 4
479+
#define ZYDIS_CPUFLAG_AF (1ul << 4)
485480
/**
486481
* Zero flag.
487482
*/
488-
#define ZYDIS_CPUFLAG_ZF 6
483+
#define ZYDIS_CPUFLAG_ZF (1ul << 6)
489484
/**
490485
* Sign flag.
491486
*/
492-
#define ZYDIS_CPUFLAG_SF 7
487+
#define ZYDIS_CPUFLAG_SF (1ul << 7)
493488
/**
494489
* Trap flag.
495490
*/
496-
#define ZYDIS_CPUFLAG_TF 8
491+
#define ZYDIS_CPUFLAG_TF (1ul << 8)
497492
/**
498493
* Interrupt enable flag.
499494
*/
500-
#define ZYDIS_CPUFLAG_IF 9
495+
#define ZYDIS_CPUFLAG_IF (1ul << 9)
501496
/**
502497
* Direction flag.
503498
*/
504-
#define ZYDIS_CPUFLAG_DF 10
499+
#define ZYDIS_CPUFLAG_DF (1ul << 10)
505500
/**
506501
* Overflow flag.
507502
*/
508-
#define ZYDIS_CPUFLAG_OF 11
503+
#define ZYDIS_CPUFLAG_OF (1ul << 11)
509504
/**
510505
* I/O privilege level flag.
511506
*/
512-
#define ZYDIS_CPUFLAG_IOPL 12
507+
#define ZYDIS_CPUFLAG_IOPL (1ul << 12)
513508
/**
514509
* Nested task flag.
515510
*/
516-
#define ZYDIS_CPUFLAG_NT 14
511+
#define ZYDIS_CPUFLAG_NT (1ul << 14)
517512
/**
518513
* Resume flag.
519514
*/
520-
#define ZYDIS_CPUFLAG_RF 16
515+
#define ZYDIS_CPUFLAG_RF (1ul << 16)
521516
/**
522517
* Virtual 8086 mode flag.
523518
*/
524-
#define ZYDIS_CPUFLAG_VM 17
519+
#define ZYDIS_CPUFLAG_VM (1ul << 17)
525520
/**
526521
* Alignment check.
527522
*/
528-
#define ZYDIS_CPUFLAG_AC 18
523+
#define ZYDIS_CPUFLAG_AC (1ul << 18)
529524
/**
530525
* Virtual interrupt flag.
531526
*/
532-
#define ZYDIS_CPUFLAG_VIF 19
527+
#define ZYDIS_CPUFLAG_VIF (1ul << 19)
533528
/**
534529
* Virtual interrupt pending.
535530
*/
536-
#define ZYDIS_CPUFLAG_VIP 20
531+
#define ZYDIS_CPUFLAG_VIP (1ul << 20)
537532
/**
538533
* Able to use CPUID instruction.
539534
*/
540-
#define ZYDIS_CPUFLAG_ID 21
541-
542-
///////////////////////////////////////////////////////////////////////////////////////////////////
543-
544-
/**
545-
* FPU condition-code flag 0.
546-
*
547-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
548-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
549-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
550-
*/
551-
#define ZYDIS_CPUFLAG_C0 22
552-
/**
553-
* FPU condition-code flag 1.
554-
*
555-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
556-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
557-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
558-
*/
559-
#define ZYDIS_CPUFLAG_C1 23
560-
/**
561-
* FPU condition-code flag 2.
562-
*
563-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
564-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
565-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
566-
*/
567-
#define ZYDIS_CPUFLAG_C2 24
568-
/**
569-
* FPU condition-code flag 3.
570-
*
571-
* DEPRECATED. This flag is not actually part of `FLAGS/EFLAGS/RFLAGS` and will be removed in the
572-
* next major release. Please refer to the `fpu_flags_read`/`fpu_flags_written` field instead and
573-
* use one of the `ZYDIS_FPUFLAG_XXX` masks to check for specific a flag.
574-
*/
575-
#define ZYDIS_CPUFLAG_C3 25
576-
577-
/**
578-
* DEPRECATED. This define will be removed in the next major release.
579-
*/
580-
#define ZYDIS_CPUFLAG_MAX_VALUE ZYDIS_CPUFLAG_C3
581-
582-
///////////////////////////////////////////////////////////////////////////////////////////////////
535+
#define ZYDIS_CPUFLAG_ID (1ul << 21)
583536

584537
/**
585538
* Defines the `ZydisFPUFlags` data-type.
@@ -589,65 +542,19 @@ typedef ZyanU8 ZydisFPUFlags;
589542
/**
590543
* FPU condition-code flag 0.
591544
*/
592-
#define ZYDIS_FPUFLAG_C0 0x00 // (1 << 0)
545+
#define ZYDIS_FPUFLAG_C0 (1 << 0)
593546
/**
594547
* FPU condition-code flag 1.
595548
*/
596-
#define ZYDIS_FPUFLAG_C1 0x01 // (1 << 1)
549+
#define ZYDIS_FPUFLAG_C1 (1 << 1)
597550
/**
598551
* FPU condition-code flag 2.
599552
*/
600-
#define ZYDIS_FPUFLAG_C2 0x02 // (1 << 2)
553+
#define ZYDIS_FPUFLAG_C2 (1 << 2)
601554
/**
602555
* FPU condition-code flag 3.
603556
*/
604-
#define ZYDIS_FPUFLAG_C3 0x04 // (1 << 3)
605-
606-
/**
607-
* Defines the `ZydisCPUFlagAction` enum.
608-
*
609-
* DEPRECATED. This enum will be removed in the next major release.
610-
*/
611-
typedef enum ZydisCPUFlagAction_
612-
{
613-
/**
614-
* The CPU flag is not touched by the instruction.
615-
*/
616-
ZYDIS_CPUFLAG_ACTION_NONE,
617-
/**
618-
* The CPU flag is tested (read).
619-
*/
620-
ZYDIS_CPUFLAG_ACTION_TESTED,
621-
/**
622-
* The CPU flag is tested and modified afterwards (read-write).
623-
*/
624-
ZYDIS_CPUFLAG_ACTION_TESTED_MODIFIED,
625-
/**
626-
* The CPU flag is modified (write).
627-
*/
628-
ZYDIS_CPUFLAG_ACTION_MODIFIED,
629-
/**
630-
* The CPU flag is set to 0 (write).
631-
*/
632-
ZYDIS_CPUFLAG_ACTION_SET_0,
633-
/**
634-
* The CPU flag is set to 1 (write).
635-
*/
636-
ZYDIS_CPUFLAG_ACTION_SET_1,
637-
/**
638-
* The CPU flag is undefined (write).
639-
*/
640-
ZYDIS_CPUFLAG_ACTION_UNDEFINED,
641-
642-
/**
643-
* Maximum value of this enum.
644-
*/
645-
ZYDIS_CPUFLAG_ACTION_MAX_VALUE = ZYDIS_CPUFLAG_ACTION_UNDEFINED,
646-
/**
647-
* The minimum number of bits required to represent all values of this enum.
648-
*/
649-
ZYDIS_CPUFLAG_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CPUFLAG_ACTION_MAX_VALUE)
650-
} ZydisCPUFlagAction;
557+
#define ZYDIS_FPUFLAG_C3 (1 << 3)
651558

652559
/* ---------------------------------------------------------------------------------------------- */
653560
/* Branch types */
@@ -1020,40 +927,56 @@ typedef struct ZydisDecodedInstruction_
1020927
*/
1021928
ZydisInstructionAttributes attributes;
1022929
/**
1023-
* Information about accessed CPU flags.
930+
* Information about CPU/FPU flags accessed by the instruction.
1024931
*
1025-
* DEPRECATED. This field will be removed in the next major release. Please use the
1026-
* `cpu_flags_read`/`cpu_flags_written` or `fpu_flags_read`/`fpu_flags_written` fields
1027-
* instead.
932+
* The bits in the masks correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
933+
* register.
1028934
*/
1029-
struct ZydisDecodedInstructionAccessedFlags_
935+
struct ZydisAccessedCPUFlags_
1030936
{
1031-
/**
1032-
* The CPU-flag action.
1033-
*
1034-
* Use `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a specific
1035-
* action.
937+
/*
938+
* As mask containing the CPU flags `TESTED` by the instruction.
939+
*/
940+
ZydisCPUFlags tested;
941+
/*
942+
* As mask containing the CPU flags `MODIFIED` by the instruction.
943+
*/
944+
ZydisCPUFlags modified;
945+
/*
946+
* As mask containing the CPU flags `SET_0` by the instruction.
947+
*/
948+
ZydisCPUFlags set_0;
949+
/*
950+
* As mask containing the CPU flags `SET_1` by the instruction.
1036951
*/
1037-
ZydisCPUFlagAction action;
1038-
} accessed_flags[ZYDIS_CPUFLAG_MAX_VALUE + 1];
952+
ZydisCPUFlags set_1;
953+
/*
954+
* As mask containing the CPU flags `SET_0` by the instruction.
955+
*/
956+
ZydisCPUFlags undefined;
957+
} cpu_flags;
1039958
/**
1040959
* A mask containing the CPU flags read by the instruction.
1041960
*
1042961
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
1043962
* register.
1044963
*
1045964
* This mask includes the actions `TESTED` and `TESTED_MODIFIED`.
965+
*
966+
* DEPRECATED. Use the masks inside of `cpu_flags` instead.
1046967
*/
1047-
ZydisCPUFlags cpu_flags_read;
968+
ZydisCPUFlags cpu_flags_read; // TODO: Remove in next version
1048969
/**
1049970
* A mask containing the CPU flags written by the instruction.
1050971
*
1051972
* The bits in this mask correspond to the actual bits in the `FLAGS/EFLAGS/RFLAGS`
1052973
* register.
1053974
*
1054975
* This mask includes the actions `TESTED_MODIFIED`, `SET_0`, `SET_1` and `UNDEFINED`.
976+
*
977+
* DEPRECATED. Use the masks inside of `cpu_flags` instead.
1055978
*/
1056-
ZydisCPUFlags cpu_flags_written;
979+
ZydisCPUFlags cpu_flags_written; // TODO: Remove in next version
1057980
/**
1058981
* A mask containing the FPU flags read by the instruction.
1059982
*/

include/Zydis/Internal/SharedData.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,15 @@ typedef struct ZydisInstructionDefinitionMVEX_
890890

891891
typedef struct ZydisAccessedFlags_
892892
{
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);
893+
ZyanU32 cpu_flags_read ZYAN_BITFIELD(22);
894+
ZyanU32 cpu_flags_written ZYAN_BITFIELD(22);
895+
ZyanU32 cpu_flags_tested ZYAN_BITFIELD(22);
896+
ZyanU32 cpu_flags_modified ZYAN_BITFIELD(22);
897+
ZyanU32 cpu_flags_set_0 ZYAN_BITFIELD(22);
898+
ZyanU32 cpu_flags_set_1 ZYAN_BITFIELD(22);
899+
ZyanU32 cpu_flags_undefined ZYAN_BITFIELD(22);
900+
ZyanU8 fpu_flags_read ZYAN_BITFIELD( 4);
901+
ZyanU8 fpu_flags_written ZYAN_BITFIELD( 4);
898902
} ZydisAccessedFlags;
899903

900904
/* ---------------------------------------------------------------------------------------------- */

include/Zydis/Utils.h

-45
Original file line numberDiff line numberDiff line change
@@ -199,51 +199,6 @@ ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction
199199
const ZydisDecodedOperand* operand, ZyanU64 runtime_address,
200200
const ZydisRegisterContext* register_context, ZyanU64* result_address);
201201

202-
/* ---------------------------------------------------------------------------------------------- */
203-
/* Accessed CPU flags */
204-
/* ---------------------------------------------------------------------------------------------- */
205-
206-
/**
207-
* Returns a mask of accessed CPU-flags matching the given `action`.
208-
*
209-
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
210-
* @param action The CPU-flag action.
211-
* @param flags Receives the flag mask.
212-
*
213-
* @return A zyan status code.
214-
*/
215-
ZYDIS_EXPORT ZyanStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction,
216-
ZydisCPUFlagAction action, ZydisCPUFlags* flags);
217-
218-
/**
219-
* Returns a mask of accessed CPU-flags that are read (tested) by the current instruction.
220-
*
221-
* DEPRECATED. This function will be removed in the next major release. Please refer to the
222-
* `cpu_flags_read` or `fpu_flags_read` fields of the `ZydisDecodedInstruction` instead.
223-
*
224-
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
225-
* @param flags Receives the flag mask.
226-
*
227-
* @return A zyan status code.
228-
*/
229-
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsRead(
230-
const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
231-
232-
/**
233-
* Returns a mask of accessed CPU-flags that are written (modified, undefined) by the current
234-
* instruction.
235-
*
236-
* DEPRECATED. This function will be removed in the next major release. Please refer to the
237-
* `cpu_flags_written` or `fpu_flags_written` fields of the `ZydisDecodedInstruction` instead.
238-
*
239-
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
240-
* @param flags Receives the flag mask.
241-
*
242-
* @return A zyan status code.
243-
*/
244-
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsWritten(
245-
const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
246-
247202
/* ---------------------------------------------------------------------------------------------- */
248203
/* Instruction segments */
249204
/* ---------------------------------------------------------------------------------------------- */

src/Decoder.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -4942,15 +4942,13 @@ static ZyanStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
49424942
if (ZydisGetAccessedFlags(definition, &flags))
49434943
{
49444944
instruction->attributes |= ZYDIS_ATTRIB_CPUFLAG_ACCESS;
4945-
ZYAN_ASSERT((ZYAN_ARRAY_LENGTH(instruction->accessed_flags) ==
4946-
ZYAN_ARRAY_LENGTH(flags->action )) &&
4947-
(sizeof (instruction->accessed_flags) ==
4948-
sizeof (flags->action )));
4949-
ZYAN_MEMCPY(&instruction->accessed_flags, &flags->action,
4950-
sizeof(flags->action));
4951-
49524945
instruction->cpu_flags_read = flags->cpu_flags_read;
49534946
instruction->cpu_flags_written = flags->cpu_flags_written;
4947+
instruction->cpu_flags.tested = flags->cpu_flags_tested;
4948+
instruction->cpu_flags.modified = flags->cpu_flags_modified;
4949+
instruction->cpu_flags.set_0 = flags->cpu_flags_set_0;
4950+
instruction->cpu_flags.set_1 = flags->cpu_flags_set_1;
4951+
instruction->cpu_flags.undefined = flags->cpu_flags_undefined;
49544952
instruction->fpu_flags_read = flags->fpu_flags_read;
49554953
instruction->fpu_flags_written = flags->fpu_flags_written;
49564954
}

0 commit comments

Comments
 (0)