1 /*************************************************************************************************** 2 3 Zyan Disassembler Library (Zydis) 4 5 Original Author : Florian Bernd 6 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 25 ***************************************************************************************************/ 26 27 #ifndef ZYDIS_INTERNAL_SHAREDDATA_H 28 #define ZYDIS_INTERNAL_SHAREDDATA_H 29 30 #include <Zycore/Defines.h> 31 #include <Zydis/Mnemonic.h> 32 #include <Zydis/Register.h> 33 #include <Zydis/SharedTypes.h> 34 #include <Zydis/DecoderTypes.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* ============================================================================================== */ 41 /* Enums and types */ 42 /* ============================================================================================== */ 43 44 // MSVC does not like types other than (un-)signed int for bit-fields 45 #ifdef ZYAN_MSVC 46 # pragma warning(push) 47 # pragma warning(disable:4214) 48 #endif 49 50 #pragma pack(push, 1) 51 52 /* ---------------------------------------------------------------------------------------------- */ 53 /* Operand definition */ 54 /* ---------------------------------------------------------------------------------------------- */ 55 56 /** 57 * Defines the `ZydisSemanticOperandType` enum. 58 */ 59 typedef enum ZydisSemanticOperandType_ 60 { 61 ZYDIS_SEMANTIC_OPTYPE_UNUSED, 62 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_REG, 63 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_MEM, 64 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_IMM1, 65 ZYDIS_SEMANTIC_OPTYPE_GPR8, 66 ZYDIS_SEMANTIC_OPTYPE_GPR16, 67 ZYDIS_SEMANTIC_OPTYPE_GPR32, 68 ZYDIS_SEMANTIC_OPTYPE_GPR64, 69 ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64, 70 ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64, 71 ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32, 72 ZYDIS_SEMANTIC_OPTYPE_GPR_ASZ, 73 ZYDIS_SEMANTIC_OPTYPE_FPR, 74 ZYDIS_SEMANTIC_OPTYPE_MMX, 75 ZYDIS_SEMANTIC_OPTYPE_XMM, 76 ZYDIS_SEMANTIC_OPTYPE_YMM, 77 ZYDIS_SEMANTIC_OPTYPE_ZMM, 78 ZYDIS_SEMANTIC_OPTYPE_TMM, 79 ZYDIS_SEMANTIC_OPTYPE_BND, 80 ZYDIS_SEMANTIC_OPTYPE_SREG, 81 ZYDIS_SEMANTIC_OPTYPE_CR, 82 ZYDIS_SEMANTIC_OPTYPE_DR, 83 ZYDIS_SEMANTIC_OPTYPE_MASK, 84 ZYDIS_SEMANTIC_OPTYPE_MEM, 85 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBX, 86 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBY, 87 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ, 88 ZYDIS_SEMANTIC_OPTYPE_IMM, 89 ZYDIS_SEMANTIC_OPTYPE_REL, 90 ZYDIS_SEMANTIC_OPTYPE_PTR, 91 ZYDIS_SEMANTIC_OPTYPE_AGEN, 92 ZYDIS_SEMANTIC_OPTYPE_MOFFS, 93 ZYDIS_SEMANTIC_OPTYPE_MIB, 94 95 /** 96 * Maximum value of this enum. 97 */ 98 ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE = ZYDIS_SEMANTIC_OPTYPE_MIB, 99 /** 100 * The minimum number of bits required to represent all values of this enum. 101 */ 102 ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE) 103 } ZydisSemanticOperandType; 104 105 /* ---------------------------------------------------------------------------------------------- */ 106 107 /** 108 * Defines the `ZydisInternalElementType` enum. 109 */ 110 typedef enum ZydisInternalElementType_ 111 { 112 ZYDIS_IELEMENT_TYPE_INVALID, 113 ZYDIS_IELEMENT_TYPE_VARIABLE, 114 ZYDIS_IELEMENT_TYPE_STRUCT, 115 ZYDIS_IELEMENT_TYPE_INT, 116 ZYDIS_IELEMENT_TYPE_UINT, 117 ZYDIS_IELEMENT_TYPE_INT1, 118 ZYDIS_IELEMENT_TYPE_INT8, 119 ZYDIS_IELEMENT_TYPE_INT8X4, 120 ZYDIS_IELEMENT_TYPE_INT16, 121 ZYDIS_IELEMENT_TYPE_INT16X2, 122 ZYDIS_IELEMENT_TYPE_INT32, 123 ZYDIS_IELEMENT_TYPE_INT64, 124 ZYDIS_IELEMENT_TYPE_UINT8, 125 ZYDIS_IELEMENT_TYPE_UINT8X4, 126 ZYDIS_IELEMENT_TYPE_UINT16, 127 ZYDIS_IELEMENT_TYPE_UINT16X2, 128 ZYDIS_IELEMENT_TYPE_UINT32, 129 ZYDIS_IELEMENT_TYPE_UINT64, 130 ZYDIS_IELEMENT_TYPE_UINT128, 131 ZYDIS_IELEMENT_TYPE_UINT256, 132 ZYDIS_IELEMENT_TYPE_FLOAT16, 133 ZYDIS_IELEMENT_TYPE_FLOAT16X2, 134 ZYDIS_IELEMENT_TYPE_FLOAT32, 135 ZYDIS_IELEMENT_TYPE_FLOAT64, 136 ZYDIS_IELEMENT_TYPE_FLOAT80, 137 ZYDIS_IELEMENT_TYPE_BFLOAT16X2, 138 ZYDIS_IELEMENT_TYPE_BCD80, 139 ZYDIS_IELEMENT_TYPE_CC3, 140 ZYDIS_IELEMENT_TYPE_CC5, 141 142 /** 143 * Maximum value of this enum. 144 */ 145 ZYDIS_IELEMENT_TYPE_MAX_VALUE = ZYDIS_IELEMENT_TYPE_CC5, 146 /** 147 * The minimum number of bits required to represent all values of this enum. 148 */ 149 ZYDIS_IELEMENT_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_TYPE_MAX_VALUE) 150 } ZydisInternalElementType; 151 152 /* ---------------------------------------------------------------------------------------------- */ 153 154 /** 155 * Defines the `ZydisImplicitRegisterType` enum. 156 */ 157 typedef enum ZydisImplicitRegisterType_ 158 { 159 // TODO: Rename OSZ|ASZ|SSZ_ 160 ZYDIS_IMPLREG_TYPE_STATIC, 161 ZYDIS_IMPLREG_TYPE_GPR_OSZ, 162 ZYDIS_IMPLREG_TYPE_GPR_ASZ, 163 ZYDIS_IMPLREG_TYPE_IP_ASZ, 164 ZYDIS_IMPLREG_TYPE_IP_SSZ, 165 ZYDIS_IMPLREG_TYPE_GPR_SSZ, 166 ZYDIS_IMPLREG_TYPE_FLAGS_SSZ, 167 168 /** 169 * Maximum value of this enum. 170 */ 171 ZYDIS_IMPLREG_TYPE_MAX_VALUE = ZYDIS_IMPLREG_TYPE_FLAGS_SSZ, 172 /** 173 * The minimum number of bits required to represent all values of this enum. 174 */ 175 ZYDIS_IMPLREG_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLREG_TYPE_MAX_VALUE) 176 } ZydisImplicitRegisterType; 177 178 /* ---------------------------------------------------------------------------------------------- */ 179 180 /** 181 * Defines the `ZydisImplicitMemBase` enum. 182 */ 183 typedef enum ZydisImplicitMemBase_ 184 { 185 // TODO: Rename OSZ|ASZ|SSZ_ 186 ZYDIS_IMPLMEM_BASE_AGPR_REG, 187 ZYDIS_IMPLMEM_BASE_AGPR_RM, 188 ZYDIS_IMPLMEM_BASE_AAX, 189 ZYDIS_IMPLMEM_BASE_ADX, 190 ZYDIS_IMPLMEM_BASE_ABX, 191 ZYDIS_IMPLMEM_BASE_ASI, 192 ZYDIS_IMPLMEM_BASE_ADI, 193 ZYDIS_IMPLMEM_BASE_SSP, 194 ZYDIS_IMPLMEM_BASE_SBP, 195 196 /** 197 * Maximum value of this enum. 198 */ 199 ZYDIS_IMPLMEM_BASE_MAX_VALUE = ZYDIS_IMPLMEM_BASE_SBP, 200 /** 201 * The minimum number of bits required to represent all values of this enum. 202 */ 203 ZYDIS_IMPLMEM_BASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLMEM_BASE_MAX_VALUE) 204 } ZydisImplicitMemBase; 205 206 /* ---------------------------------------------------------------------------------------------- */ 207 208 // MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct 209 // enum types 210 ZYAN_STATIC_ASSERT(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS <= 8); 211 ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS <= 8); 212 ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ACTION_REQUIRED_BITS <= 8); 213 ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS <= 8); 214 ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS <= 8); 215 ZYAN_STATIC_ASSERT(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS <= 8); 216 ZYAN_STATIC_ASSERT(ZYDIS_REGISTER_REQUIRED_BITS <= 16); 217 ZYAN_STATIC_ASSERT(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS <= 8); 218 219 /** 220 * Defines the `ZydisOperandDefinition` struct. 221 */ 222 typedef struct ZydisOperandDefinition_ 223 { 224 ZyanU8 type ZYAN_BITFIELD(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS); 225 ZyanU8 visibility ZYAN_BITFIELD(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS); 226 ZyanU8 actions ZYAN_BITFIELD(ZYDIS_OPERAND_ACTION_REQUIRED_BITS); 227 ZyanU16 size[3]; 228 ZyanU8 element_type ZYAN_BITFIELD(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS); 229 union 230 { 231 ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS); 232 struct 233 { 234 ZyanU8 type ZYAN_BITFIELD(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS); 235 union 236 { 237 ZyanU16 reg ZYAN_BITFIELD(ZYDIS_REGISTER_REQUIRED_BITS); 238 ZyanU8 id ZYAN_BITFIELD(6); 239 } reg; 240 } reg; 241 struct 242 { 243 ZyanU8 seg ZYAN_BITFIELD(3); 244 ZyanU8 base ZYAN_BITFIELD(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS); 245 } mem; 246 } op; 247 ZyanBool is_multisource4 ZYAN_BITFIELD(1); 248 ZyanBool ignore_seg_override ZYAN_BITFIELD(1); 249 } ZydisOperandDefinition; 250 251 /* ---------------------------------------------------------------------------------------------- */ 252 /* Instruction definition */ 253 /* ---------------------------------------------------------------------------------------------- */ 254 255 /** 256 * Defines the `ZydisReadWriteAction` enum. 257 */ 258 typedef enum ZydisReadWriteAction_ 259 { 260 ZYDIS_RW_ACTION_NONE, 261 ZYDIS_RW_ACTION_READ, 262 ZYDIS_RW_ACTION_WRITE, 263 ZYDIS_RW_ACTION_READWRITE, 264 265 /** 266 * Maximum value of this enum. 267 */ 268 ZYDIS_RW_ACTION_MAX_VALUE = ZYDIS_RW_ACTION_READWRITE, 269 /** 270 * The minimum number of bits required to represent all values of this enum. 271 */ 272 ZYDIS_RW_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_RW_ACTION_MAX_VALUE) 273 } ZydisReadWriteAction; 274 275 /* ---------------------------------------------------------------------------------------------- */ 276 277 /** 278 * Defines the `ZydisInternalVectorLength` enum. 279 */ 280 typedef enum ZydisInternalVectorLength_ 281 { 282 ZYDIS_IVECTOR_LENGTH_DEFAULT, 283 ZYDIS_IVECTOR_LENGTH_FIXED_128, 284 ZYDIS_IVECTOR_LENGTH_FIXED_256, 285 ZYDIS_IVECTOR_LENGTH_FIXED_512, 286 287 /** 288 * Maximum value of this enum. 289 */ 290 ZYDIS_IVECTOR_LENGTH_MAX_VALUE = ZYDIS_IVECTOR_LENGTH_FIXED_512, 291 /** 292 * The minimum number of bits required to represent all values of this enum. 293 */ 294 ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IVECTOR_LENGTH_MAX_VALUE) 295 } ZydisInternalVectorLength; 296 297 /* ---------------------------------------------------------------------------------------------- */ 298 299 /** 300 * Defines the `ZydisInternalElementSize` enum. 301 */ 302 typedef enum ZydisInternalElementSize_ 303 { 304 ZYDIS_IELEMENT_SIZE_INVALID, 305 ZYDIS_IELEMENT_SIZE_8, 306 ZYDIS_IELEMENT_SIZE_16, 307 ZYDIS_IELEMENT_SIZE_32, 308 ZYDIS_IELEMENT_SIZE_64, 309 ZYDIS_IELEMENT_SIZE_128, 310 311 /** 312 * Maximum value of this enum. 313 */ 314 ZYDIS_IELEMENT_SIZE_MAX_VALUE = ZYDIS_IELEMENT_SIZE_128, 315 /** 316 * The minimum number of bits required to represent all values of this enum. 317 */ 318 ZYDIS_IELEMENT_SIZE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_SIZE_MAX_VALUE) 319 } ZydisInternalElementSize; 320 321 /* ---------------------------------------------------------------------------------------------- */ 322 323 /** 324 * Defines the `ZydisEVEXFunctionality` enum. 325 */ 326 typedef enum ZydisEVEXFunctionality_ 327 { 328 ZYDIS_EVEX_FUNC_INVALID, 329 /** 330 * `EVEX.b` enables broadcast functionality. 331 */ 332 ZYDIS_EVEX_FUNC_BC, 333 /** 334 * `EVEX.b` enables embedded-rounding functionality. 335 */ 336 ZYDIS_EVEX_FUNC_RC, 337 /** 338 * `EVEX.b` enables sae functionality. 339 */ 340 ZYDIS_EVEX_FUNC_SAE, 341 342 /** 343 * Maximum value of this enum. 344 */ 345 ZYDIS_EVEX_FUNC_MAX_VALUE = ZYDIS_EVEX_FUNC_SAE, 346 /** 347 * The minimum number of bits required to represent all values of this enum. 348 */ 349 ZYDIS_EVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_FUNC_MAX_VALUE) 350 } ZydisEVEXFunctionality; 351 352 /* ---------------------------------------------------------------------------------------------- */ 353 354 /** 355 * Defines the `ZydisEVEXTupleType` enum. 356 */ 357 typedef enum ZydisEVEXTupleType_ 358 { 359 ZYDIS_TUPLETYPE_INVALID, 360 /** 361 * Full Vector 362 */ 363 ZYDIS_TUPLETYPE_FV, 364 /** 365 * Half Vector 366 */ 367 ZYDIS_TUPLETYPE_HV, 368 /** 369 * Full Vector Mem 370 */ 371 ZYDIS_TUPLETYPE_FVM, 372 /** 373 * Tuple1 Scalar 374 */ 375 ZYDIS_TUPLETYPE_T1S, 376 /** 377 * Tuple1 Fixed 378 */ 379 ZYDIS_TUPLETYPE_T1F, 380 /** 381 * Tuple1 4x32 382 */ 383 ZYDIS_TUPLETYPE_T1_4X, 384 /** 385 * Gather / Scatter 386 */ 387 ZYDIS_TUPLETYPE_GSCAT, 388 /** 389 * Tuple2 390 */ 391 ZYDIS_TUPLETYPE_T2, 392 /** 393 * Tuple4 394 */ 395 ZYDIS_TUPLETYPE_T4, 396 /** 397 * Tuple8 398 */ 399 ZYDIS_TUPLETYPE_T8, 400 /** 401 * Half Mem 402 */ 403 ZYDIS_TUPLETYPE_HVM, 404 /** 405 * QuarterMem 406 */ 407 ZYDIS_TUPLETYPE_QVM, 408 /** 409 * OctMem 410 */ 411 ZYDIS_TUPLETYPE_OVM, 412 /** 413 * Mem128 414 */ 415 ZYDIS_TUPLETYPE_M128, 416 /** 417 * MOVDDUP 418 */ 419 ZYDIS_TUPLETYPE_DUP, 420 /** 421 * Quarter of the vector-length. 422 */ 423 ZYDIS_TUPLETYPE_QUARTER, 424 425 /** 426 * Maximum value of this enum. 427 */ 428 ZYDIS_TUPLETYPE_MAX_VALUE = ZYDIS_TUPLETYPE_QUARTER, 429 /** 430 * The minimum number of bits required to represent all values of this enum. 431 */ 432 ZYDIS_TUPLETYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_TUPLETYPE_MAX_VALUE) 433 } ZydisEVEXTupleType; 434 435 /* ---------------------------------------------------------------------------------------------- */ 436 437 /** 438 * Defines the `ZydisMVEXFunctionality` enum. 439 */ 440 typedef enum ZydisMVEXFunctionality_ 441 { 442 /** 443 * The `MVEX.SSS` value is ignored. 444 */ 445 ZYDIS_MVEX_FUNC_IGNORED, 446 /** 447 * `MVEX.SSS` must be `000b`. 448 */ 449 ZYDIS_MVEX_FUNC_INVALID, 450 /** 451 * `MVEX.SSS` controls embedded-rounding functionality. 452 */ 453 ZYDIS_MVEX_FUNC_RC, 454 /** 455 * `MVEX.SSS` controls sae functionality. 456 */ 457 ZYDIS_MVEX_FUNC_SAE, 458 /** 459 * No special operation (32bit float elements). 460 */ 461 ZYDIS_MVEX_FUNC_F_32, 462 /** 463 * No special operation (32bit uint elements). 464 */ 465 ZYDIS_MVEX_FUNC_I_32, 466 /** 467 * No special operation (64bit float elements). 468 */ 469 ZYDIS_MVEX_FUNC_F_64, 470 /** 471 * No special operation (64bit uint elements). 472 */ 473 ZYDIS_MVEX_FUNC_I_64, 474 /** 475 * Sf32(reg) or Si32(reg). 476 */ 477 ZYDIS_MVEX_FUNC_SWIZZLE_32, 478 /** 479 * Sf64(reg) or Si64(reg). 480 */ 481 ZYDIS_MVEX_FUNC_SWIZZLE_64, 482 /** 483 * Sf32(mem). 484 */ 485 ZYDIS_MVEX_FUNC_SF_32, 486 /** 487 * Sf32(mem) broadcast only. 488 */ 489 ZYDIS_MVEX_FUNC_SF_32_BCST, 490 /** 491 * Sf32(mem) broadcast 4to16 only. 492 */ 493 ZYDIS_MVEX_FUNC_SF_32_BCST_4TO16, 494 /** 495 * Sf64(mem). 496 */ 497 ZYDIS_MVEX_FUNC_SF_64, 498 /** 499 * Si32(mem). 500 */ 501 ZYDIS_MVEX_FUNC_SI_32, 502 /** 503 * Si32(mem) broadcast only. 504 */ 505 ZYDIS_MVEX_FUNC_SI_32_BCST, 506 /** 507 * Si32(mem) broadcast 4to16 only. 508 */ 509 ZYDIS_MVEX_FUNC_SI_32_BCST_4TO16, 510 /** 511 * Si64(mem). 512 */ 513 ZYDIS_MVEX_FUNC_SI_64, 514 /** 515 * Uf32. 516 */ 517 ZYDIS_MVEX_FUNC_UF_32, 518 /** 519 * Uf64. 520 */ 521 ZYDIS_MVEX_FUNC_UF_64, 522 /** 523 * Ui32. 524 */ 525 ZYDIS_MVEX_FUNC_UI_32, 526 /** 527 * Ui64. 528 */ 529 ZYDIS_MVEX_FUNC_UI_64, 530 /** 531 * Df32. 532 */ 533 ZYDIS_MVEX_FUNC_DF_32, 534 /** 535 * Df64. 536 */ 537 ZYDIS_MVEX_FUNC_DF_64, 538 /** 539 * Di32. 540 */ 541 ZYDIS_MVEX_FUNC_DI_32, 542 /** 543 * Di64. 544 */ 545 ZYDIS_MVEX_FUNC_DI_64, 546 547 /** 548 * Maximum value of this enum. 549 */ 550 ZYDIS_MVEX_FUNC_MAX_VALUE = ZYDIS_MVEX_FUNC_DI_64, 551 /** 552 * The minimum number of bits required to represent all values of this enum. 553 */ 554 ZYDIS_MVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_FUNC_MAX_VALUE) 555 } ZydisMVEXFunctionality; 556 557 /* ---------------------------------------------------------------------------------------------- */ 558 559 /** 560 * Defines the `ZydisVEXStaticBroadcast` enum. 561 */ 562 typedef enum ZydisVEXStaticBroadcast 563 { 564 ZYDIS_VEX_STATIC_BROADCAST_NONE, 565 ZYDIS_VEX_STATIC_BROADCAST_1_TO_2, 566 ZYDIS_VEX_STATIC_BROADCAST_1_TO_4, 567 ZYDIS_VEX_STATIC_BROADCAST_1_TO_8, 568 ZYDIS_VEX_STATIC_BROADCAST_1_TO_16, 569 ZYDIS_VEX_STATIC_BROADCAST_1_TO_32, 570 ZYDIS_VEX_STATIC_BROADCAST_2_TO_4, 571 572 /** 573 * Maximum value of this enum. 574 */ 575 ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_VEX_STATIC_BROADCAST_2_TO_4, 576 /** 577 * The minimum number of bits required to represent all values of this enum. 578 */ 579 ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS = 580 ZYAN_BITS_TO_REPRESENT(ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE) 581 } ZydisVEXStaticBroadcast; 582 583 /* ---------------------------------------------------------------------------------------------- */ 584 585 /** 586 * Defines the `ZydisEVEXStaticBroadcast` enum. 587 */ 588 typedef enum ZydisEVEXStaticBroadcast_ 589 { 590 ZYDIS_EVEX_STATIC_BROADCAST_NONE, 591 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_2, 592 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_4, 593 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_8, 594 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_16, 595 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_32, 596 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_64, 597 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_4, 598 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_8, 599 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_16, 600 ZYDIS_EVEX_STATIC_BROADCAST_4_TO_8, 601 ZYDIS_EVEX_STATIC_BROADCAST_4_TO_16, 602 ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16, 603 604 /** 605 * Maximum value of this enum. 606 */ 607 ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16, 608 /** 609 * The minimum number of bits required to represent all values of this enum. 610 */ 611 ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS = 612 ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE) 613 } ZydisEVEXStaticBroadcast; 614 615 /* ---------------------------------------------------------------------------------------------- */ 616 617 /** 618 * Defines the `ZydisMVEXStaticBroadcast` enum. 619 */ 620 typedef enum ZydisMVEXStaticBroadcast_ 621 { 622 ZYDIS_MVEX_STATIC_BROADCAST_NONE, 623 ZYDIS_MVEX_STATIC_BROADCAST_1_TO_8, 624 ZYDIS_MVEX_STATIC_BROADCAST_1_TO_16, 625 ZYDIS_MVEX_STATIC_BROADCAST_4_TO_8, 626 ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16, 627 628 /** 629 * Maximum value of this enum. 630 */ 631 ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16, 632 /** 633 * The minimum number of bits required to represent all values of this enum. 634 */ 635 ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS = 636 ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE) 637 } ZydisMVEXStaticBroadcast; 638 639 /* ---------------------------------------------------------------------------------------------- */ 640 641 /** 642 * Defines the `ZydisMaskPolicy` enum. 643 */ 644 typedef enum ZydisMaskPolicy_ 645 { 646 ZYDIS_MASK_POLICY_INVALID, 647 /** 648 * The instruction accepts mask-registers other than the default-mask (K0), but 649 * does not require them. 650 */ 651 ZYDIS_MASK_POLICY_ALLOWED, 652 /** 653 * The instruction requires a mask-register other than the default-mask (K0). 654 */ 655 ZYDIS_MASK_POLICY_REQUIRED, 656 /** 657 * The instruction does not allow a mask-register other than the default-mask (K0). 658 */ 659 ZYDIS_MASK_POLICY_FORBIDDEN, 660 661 /** 662 * Maximum value of this enum. 663 */ 664 ZYDIS_MASK_POLICY_MAX_VALUE = ZYDIS_MASK_POLICY_FORBIDDEN, 665 /** 666 * The minimum number of bits required to represent all values of this enum. 667 */ 668 ZYDIS_MASK_POLICY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_POLICY_MAX_VALUE) 669 } ZydisMaskPolicy; 670 671 /* ---------------------------------------------------------------------------------------------- */ 672 673 /** 674 * Defines the `ZydisMaskOverride` enum. 675 */ 676 typedef enum ZydisMaskOverride_ 677 { 678 ZYDIS_MASK_OVERRIDE_DEFAULT, 679 ZYDIS_MASK_OVERRIDE_ZEROING, 680 ZYDIS_MASK_OVERRIDE_CONTROL, 681 682 /** 683 * Maximum value of this enum. 684 */ 685 ZYDIS_MASK_OVERRIDE_MAX_VALUE = ZYDIS_MASK_OVERRIDE_CONTROL, 686 /** 687 * The minimum number of bits required to represent all values of this enum. 688 */ 689 ZYDIS_MASK_OVERRIDE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_OVERRIDE_MAX_VALUE) 690 } ZydisMaskOverride; 691 692 /* ---------------------------------------------------------------------------------------------- */ 693 694 #define ZYDIS_OPDEF_REQUIRED_BITS \ 695 ZYAN_MAX(ZYDIS_REGKIND_REQUIRED_BITS, ZYDIS_MEMOP_TYPE_REQUIRED_BITS + 1) + 1 696 697 #define ZYDIS_OPDEF_GET_REG(operand_definition) \ 698 ((operand_definition) & ((1 << ZYDIS_REGKIND_REQUIRED_BITS ) - 1)) 699 700 #define ZYDIS_OPDEF_GET_MEM(operand_definition) \ 701 ((operand_definition) & ((1 << ZYDIS_MEMOP_TYPE_REQUIRED_BITS) - 1)) 702 703 #define ZYDIS_OPDEF_GET_REG_HIGH_BIT(operand_definition) \ 704 (((operand_definition) >> ZYDIS_REGKIND_REQUIRED_BITS ) & 0x01) 705 706 #define ZYDIS_OPDEF_GET_MEM_HIGH_BIT(operand_definition) \ 707 (((operand_definition) >> ZYDIS_MEMOP_TYPE_REQUIRED_BITS) & 0x01) 708 709 // MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct 710 // enum types 711 ZYAN_STATIC_ASSERT(ZYDIS_MNEMONIC_REQUIRED_BITS <= 16); 712 ZYAN_STATIC_ASSERT(ZYDIS_CATEGORY_REQUIRED_BITS <= 8); 713 ZYAN_STATIC_ASSERT(ZYDIS_ISA_SET_REQUIRED_BITS <= 8); 714 ZYAN_STATIC_ASSERT(ZYDIS_ISA_EXT_REQUIRED_BITS <= 8); 715 ZYAN_STATIC_ASSERT(ZYDIS_BRANCH_TYPE_REQUIRED_BITS <= 8); 716 ZYAN_STATIC_ASSERT(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS <= 8); 717 ZYAN_STATIC_ASSERT(ZYDIS_OPDEF_REQUIRED_BITS <= 8); 718 ZYAN_STATIC_ASSERT(ZYDIS_RW_ACTION_REQUIRED_BITS <= 8); 719 720 #ifndef ZYDIS_MINIMAL_MODE 721 # define ZYDIS_INSTRUCTION_DEFINITION_BASE \ 722 ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \ 723 ZyanU8 operand_count ZYAN_BITFIELD( 4); \ 724 ZyanU8 operand_count_visible ZYAN_BITFIELD( 3); \ 725 ZyanU16 operand_reference ZYAN_BITFIELD(15); \ 726 ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \ 727 ZyanU8 address_size_map ZYAN_BITFIELD( 2); \ 728 ZyanU8 flags_reference ZYAN_BITFIELD( 7); \ 729 ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \ 730 ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \ 731 ZyanU8 category ZYAN_BITFIELD(ZYDIS_CATEGORY_REQUIRED_BITS); \ 732 ZyanU8 isa_set ZYAN_BITFIELD(ZYDIS_ISA_SET_REQUIRED_BITS); \ 733 ZyanU8 isa_ext ZYAN_BITFIELD(ZYDIS_ISA_EXT_REQUIRED_BITS); \ 734 ZyanU8 branch_type ZYAN_BITFIELD(ZYDIS_BRANCH_TYPE_REQUIRED_BITS); \ 735 ZyanU8 exception_class ZYAN_BITFIELD(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS); \ 736 ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \ 737 ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \ 738 ZyanU8 cpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \ 739 ZyanU8 fpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \ 740 ZyanU8 xmm_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \ 741 ZyanBool accepts_segment ZYAN_BITFIELD( 1) 742 #else 743 # define ZYDIS_INSTRUCTION_DEFINITION_BASE \ 744 ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \ 745 ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \ 746 ZyanU8 address_size_map ZYAN_BITFIELD( 2); \ 747 ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \ 748 ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \ 749 ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \ 750 ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS) 751 #endif 752 753 #define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR \ 754 ZYDIS_INSTRUCTION_DEFINITION_BASE; \ 755 ZyanU8 op_ndsndd ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS) 756 757 #define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL \ 758 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR; \ 759 ZyanBool is_gather ZYAN_BITFIELD( 1); \ 760 ZyanBool no_source_dest_match ZYAN_BITFIELD( 1); \ 761 ZyanBool no_source_source_match ZYAN_BITFIELD( 1) // TODO: Could be moved to VEX 762 763 /** 764 * Defines the `ZydisInstructionDefinition` struct. 765 */ 766 typedef struct ZydisInstructionDefinition_ 767 { 768 ZYDIS_INSTRUCTION_DEFINITION_BASE; 769 } ZydisInstructionDefinition; 770 771 /** 772 * Defines the `ZydisInstructionDefinitionLEGACY` struct. 773 */ 774 typedef struct ZydisInstructionDefinitionLEGACY_ 775 { 776 ZYDIS_INSTRUCTION_DEFINITION_BASE; 777 #ifndef ZYDIS_MINIMAL_MODE 778 ZyanBool is_privileged ZYAN_BITFIELD( 1); 779 #endif 780 ZyanBool accepts_LOCK ZYAN_BITFIELD( 1); 781 #ifndef ZYDIS_MINIMAL_MODE 782 ZyanBool accepts_REP ZYAN_BITFIELD( 1); 783 ZyanBool accepts_REPEREPZ ZYAN_BITFIELD( 1); 784 ZyanBool accepts_REPNEREPNZ ZYAN_BITFIELD( 1); 785 ZyanBool accepts_BOUND ZYAN_BITFIELD( 1); 786 ZyanBool accepts_XACQUIRE ZYAN_BITFIELD( 1); 787 ZyanBool accepts_XRELEASE ZYAN_BITFIELD( 1); 788 ZyanBool accepts_NOTRACK ZYAN_BITFIELD( 1); 789 ZyanBool accepts_hle_without_lock ZYAN_BITFIELD( 1); 790 ZyanBool accepts_branch_hints ZYAN_BITFIELD( 1); 791 #endif 792 } ZydisInstructionDefinitionLEGACY; 793 794 /** 795 * Defines the `ZydisInstructionDefinition3DNOW` struct. 796 */ 797 typedef struct ZydisInstructionDefinition3DNOW_ 798 { 799 ZYDIS_INSTRUCTION_DEFINITION_BASE; 800 } ZydisInstructionDefinition3DNOW; 801 802 /** 803 * Defines the `ZydisInstructionDefinitionXOP` struct. 804 */ 805 typedef struct ZydisInstructionDefinitionXOP_ 806 { 807 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR; 808 } ZydisInstructionDefinitionXOP; 809 810 // MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct 811 // enum types 812 ZYAN_STATIC_ASSERT(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS <= 8); 813 814 /** 815 * Defines the `ZydisInstructionDefinitionVEX` struct. 816 */ 817 typedef struct ZydisInstructionDefinitionVEX_ 818 { 819 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL; 820 #ifndef ZYDIS_MINIMAL_MODE 821 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS); 822 #endif 823 } ZydisInstructionDefinitionVEX; 824 825 #ifndef ZYDIS_DISABLE_AVX512 826 827 // MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct 828 // enum types 829 ZYAN_STATIC_ASSERT(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS <= 8); 830 ZYAN_STATIC_ASSERT(ZYDIS_TUPLETYPE_REQUIRED_BITS <= 8); 831 ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS <= 8); 832 ZYAN_STATIC_ASSERT(ZYDIS_EVEX_FUNC_REQUIRED_BITS <= 8); 833 ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8); 834 ZYAN_STATIC_ASSERT(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS <= 8); 835 ZYAN_STATIC_ASSERT(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8); 836 837 /** 838 * Defines the `ZydisInstructionDefinitionEVEX` struct. 839 */ 840 typedef struct ZydisInstructionDefinitionEVEX_ 841 { 842 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL; 843 #ifndef ZYDIS_MINIMAL_MODE 844 ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS); 845 ZyanU8 tuple_type ZYAN_BITFIELD(ZYDIS_TUPLETYPE_REQUIRED_BITS); 846 ZyanU8 element_size ZYAN_BITFIELD(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS); 847 ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_EVEX_FUNC_REQUIRED_BITS); 848 #endif 849 ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS); 850 ZyanBool accepts_zero_mask ZYAN_BITFIELD( 1); 851 #ifndef ZYDIS_MINIMAL_MODE 852 ZyanU8 mask_override ZYAN_BITFIELD(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS); 853 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS); 854 #endif 855 } ZydisInstructionDefinitionEVEX; 856 #endif 857 858 #ifndef ZYDIS_DISABLE_KNC 859 860 // MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct 861 // enum types 862 ZYAN_STATIC_ASSERT(ZYDIS_MVEX_FUNC_REQUIRED_BITS <= 8); 863 ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8); 864 ZYAN_STATIC_ASSERT(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8); 865 866 /** 867 * Defines the `ZydisInstructionDefinitionMVEX` struct. 868 */ 869 typedef struct ZydisInstructionDefinitionMVEX_ 870 { 871 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL; 872 ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_MVEX_FUNC_REQUIRED_BITS); 873 ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS); 874 #ifndef ZYDIS_MINIMAL_MODE 875 ZyanBool has_element_granularity ZYAN_BITFIELD( 1); 876 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS); 877 #endif 878 } ZydisInstructionDefinitionMVEX; 879 #endif 880 881 /* ---------------------------------------------------------------------------------------------- */ 882 883 #pragma pack(pop) 884 885 #ifdef ZYAN_MSVC 886 # pragma warning(pop) 887 #endif 888 889 /* ---------------------------------------------------------------------------------------------- */ 890 /* Accessed CPU/FPU flags */ 891 /* ---------------------------------------------------------------------------------------------- */ 892 893 /* 894 * Contains information about the CPU/FPU flags accessed by an instruction. 895 * 896 * We don't want this struct to be packed! A pointer to the individual members will be used by the 897 * `ZydisDecodedInstruction` struct. 898 */ 899 typedef struct ZydisDefinitionAccessedFlags_ 900 { 901 ZydisAccessedFlags cpu_flags; 902 ZydisAccessedFlags fpu_flags; 903 } ZydisDefinitionAccessedFlags; 904 905 /* ---------------------------------------------------------------------------------------------- */ 906 907 /* ============================================================================================== */ 908 /* Functions */ 909 /* ============================================================================================== */ 910 911 /* ---------------------------------------------------------------------------------------------- */ 912 /* Instruction definition */ 913 /* ---------------------------------------------------------------------------------------------- */ 914 915 /** 916 * Returns the instruction-definition with the given `encoding` and `id`. 917 * 918 * @param encoding The instruction-encoding. 919 * @param id The definition-id. 920 * @param definition A pointer to the variable that receives a pointer to the instruction- 921 * definition. 922 */ 923 ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding, 924 ZyanU16 id, const ZydisInstructionDefinition** definition); 925 926 /* ---------------------------------------------------------------------------------------------- */ 927 /* Operand definition */ 928 /* ---------------------------------------------------------------------------------------------- */ 929 930 #ifndef ZYDIS_MINIMAL_MODE 931 /** 932 * Returns the the operand-definitions for the given instruction-`definition`. 933 * 934 * @param definition A pointer to the instruction-definition. 935 * 936 * @return A pointer to the first operand definition of the instruction, or `ZYAN_NULL`. 937 */ 938 ZYDIS_NO_EXPORT const ZydisOperandDefinition* ZydisGetOperandDefinitions( 939 const ZydisInstructionDefinition* definition); 940 #endif 941 942 /* ---------------------------------------------------------------------------------------------- */ 943 /* Element info */ 944 /* ---------------------------------------------------------------------------------------------- */ 945 946 #ifndef ZYDIS_MINIMAL_MODE 947 /** 948 * Returns the actual type and size of an internal element-type. 949 * 950 * @param element The internal element type. 951 * @param type The actual element type. 952 * @param size The element size. 953 */ 954 ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type, 955 ZydisElementSize* size); 956 #endif 957 958 /* ---------------------------------------------------------------------------------------------- */ 959 /* Accessed CPU flags */ 960 /* ---------------------------------------------------------------------------------------------- */ 961 962 #ifndef ZYDIS_MINIMAL_MODE 963 /** 964 * Returns the the operand-definitions for the given instruction-`definition`. 965 * 966 * @param definition A pointer to the instruction-definition. 967 * @param flags A pointer to the variable that receives the `ZydisDefinitionAccessedFlags` 968 * struct. 969 * 970 * @return `ZYAN_TRUE`, if the instruction accesses any flags, or `ZYAN_FALSE`, if not. 971 */ 972 ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition, 973 const ZydisDefinitionAccessedFlags** flags); 974 #endif 975 976 /* ---------------------------------------------------------------------------------------------- */ 977 978 /* ============================================================================================== */ 979 980 #ifdef __cplusplus 981 } 982 #endif 983 984 #endif /* ZYDIS_INTERNAL_SHAREDDATA_H */ 985