-
Notifications
You must be signed in to change notification settings - Fork 21
/
Zydis.h
11884 lines (10861 loc) · 392 KB
/
Zydis.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DO NOT EDIT. This file is auto-generated by `amalgamate.py`.
//
// Header: Zydis/Zydis.h
//
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Master include file. Includes everything else.
*/
#ifndef ZYDIS_H
#define ZYDIS_H
//
// Header: Zycore/Defines.h
//
// Include stack:
// - Zydis/Zydis.h
//
/***************************************************************************************************
Zyan Core Library (Zycore-C)
Original Author : Florian Bernd, Joel Hoener
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* General helper and platform detection macros.
*/
#ifndef ZYCORE_DEFINES_H
#define ZYCORE_DEFINES_H
/* ============================================================================================== */
/* Meta macros */
/* ============================================================================================== */
/**
* Concatenates two values using the stringify operator (`##`).
*
* @param x The first value.
* @param y The second value.
*
* @return The combined string of the given values.
*/
#define ZYAN_MACRO_CONCAT(x, y) x ## y
/**
* Concatenates two values using the stringify operator (`##`) and expands the value to
* be used in another macro.
*
* @param x The first value.
* @param y The second value.
*
* @return The combined string of the given values.
*/
#define ZYAN_MACRO_CONCAT_EXPAND(x, y) ZYAN_MACRO_CONCAT(x, y)
/* ============================================================================================== */
/* Compiler detection */
/* ============================================================================================== */
#if defined(__clang__)
# define ZYAN_CLANG
# define ZYAN_GNUC
#elif defined(__ICC) || defined(__INTEL_COMPILER)
# define ZYAN_ICC
#elif defined(__GNUC__) || defined(__GNUG__)
# define ZYAN_GCC
# define ZYAN_GNUC
#elif defined(_MSC_VER)
# define ZYAN_MSVC
#elif defined(__BORLANDC__)
# define ZYAN_BORLAND
#else
# define ZYAN_UNKNOWN_COMPILER
#endif
/* ============================================================================================== */
/* Platform detection */
/* ============================================================================================== */
#if defined(_WIN32)
# define ZYAN_WINDOWS
#elif defined(__EMSCRIPTEN__)
# define ZYAN_EMSCRIPTEN
#elif defined(__wasi__) || defined(__WASI__)
// via: https://reviews.llvm.org/D57155
# define ZYAN_WASI
#elif defined(__APPLE__)
# define ZYAN_APPLE
# define ZYAN_POSIX
#elif defined(__linux)
# define ZYAN_LINUX
# define ZYAN_POSIX
#elif defined(__FreeBSD__)
# define ZYAN_FREEBSD
# define ZYAN_POSIX
#elif defined(sun) || defined(__sun)
# define ZYAN_SOLARIS
# define ZYAN_POSIX
#elif defined(__unix)
# define ZYAN_UNIX
# define ZYAN_POSIX
#elif defined(__posix)
# define ZYAN_POSIX
#else
# define ZYAN_UNKNOWN_PLATFORM
#endif
/* ============================================================================================== */
/* Kernel mode detection */
/* ============================================================================================== */
#if (defined(ZYAN_WINDOWS) && defined(_KERNEL_MODE)) || \
(defined(ZYAN_APPLE) && defined(KERNEL)) || \
(defined(ZYAN_LINUX) && defined(__KERNEL__)) || \
(defined(__FreeBSD_kernel__))
# define ZYAN_KERNEL
#else
# define ZYAN_USER
#endif
/* ============================================================================================== */
/* Architecture detection */
/* ============================================================================================== */
#if defined(_M_AMD64) || defined(__x86_64__)
# define ZYAN_X64
#elif defined(_M_IX86) || defined(__i386__)
# define ZYAN_X86
#elif defined(_M_ARM64) || defined(__aarch64__)
# define ZYAN_AARCH64
#elif defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || defined(__thumb__)
# define ZYAN_ARM
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__WASM__)
# define ZYAN_WASM
#elif defined(__powerpc64__)
# define ZYAN_PPC64
#elif defined(__powerpc__)
# define ZYAN_PPC
#elif defined(__riscv) && __riscv_xlen == 64
# define ZYAN_RISCV64
#else
# error "Unsupported architecture detected"
#endif
/* ============================================================================================== */
/* Debug/Release detection */
/* ============================================================================================== */
#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
# ifdef _DEBUG
# define ZYAN_DEBUG
# else
# define ZYAN_RELEASE
# endif
#elif defined(ZYAN_GNUC) || defined(ZYAN_ICC)
# ifdef NDEBUG
# define ZYAN_RELEASE
# else
# define ZYAN_DEBUG
# endif
#else
# define ZYAN_RELEASE
#endif
/* ============================================================================================== */
/* Deprecation hint */
/* ============================================================================================== */
#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
# define ZYAN_DEPRECATED __attribute__((__deprecated__))
#elif defined(ZYAN_MSVC)
# define ZYAN_DEPRECATED __declspec(deprecated)
#else
# define ZYAN_DEPRECATED
#endif
/* ============================================================================================== */
/* Generic DLL import/export helpers */
/* ============================================================================================== */
#if defined(ZYAN_MSVC)
# define ZYAN_DLLEXPORT __declspec(dllexport)
# define ZYAN_DLLIMPORT __declspec(dllimport)
#else
# define ZYAN_DLLEXPORT
# define ZYAN_DLLIMPORT
#endif
/* ============================================================================================== */
/* Zycore dll{export,import} */
/* ============================================================================================== */
// This is a cut-down version of what CMake's `GenerateExportHeader` would usually generate. To
// simplify builds without CMake, we define these things manually instead of relying on CMake
// to generate the header.
//
// For static builds, our CMakeList will define `ZYCORE_STATIC_BUILD`. For shared library builds,
// our CMake will define `ZYCORE_SHOULD_EXPORT` depending on whether the target is being imported or
// exported. If CMake isn't used, users can manually define these to fit their use-case.
// Backward compatibility: CMake would previously generate these variables names. However, because
// they have pretty cryptic names, we renamed them when we got rid of `GenerateExportHeader`. For
// backward compatibility for users that don't use CMake and previously manually defined these, we
// translate the old defines here and print a warning.
#if defined(ZYCORE_STATIC_DEFINE)
# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
# define ZYCORE_STATIC_BUILD
#endif
#if defined(Zycore_EXPORTS)
# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
# define ZYCORE_SHOULD_EXPORT
#endif
/**
* Symbol is exported in shared library builds.
*/
#if defined(ZYCORE_STATIC_BUILD)
# define ZYCORE_EXPORT
#else
# if defined(ZYCORE_SHOULD_EXPORT)
# define ZYCORE_EXPORT ZYAN_DLLEXPORT
# else
# define ZYCORE_EXPORT ZYAN_DLLIMPORT
# endif
#endif
/**
* Symbol is not exported and for internal use only.
*/
#define ZYCORE_NO_EXPORT
/* ============================================================================================== */
/* Misc compatibility macros */
/* ============================================================================================== */
#if defined(ZYAN_CLANG)
# define ZYAN_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
#else
# define ZYAN_NO_SANITIZE(what)
#endif
#if defined(ZYAN_MSVC) || defined(ZYAN_BORLAND)
# define ZYAN_INLINE __inline
#else
# define ZYAN_INLINE static inline
#endif
#if defined(ZYAN_MSVC)
# define ZYAN_NOINLINE __declspec(noinline)
#elif defined(ZYAN_GCC) || defined(ZYAN_CLANG)
# define ZYAN_NOINLINE __attribute__((noinline))
#else
# define ZYAN_NOINLINE
#endif
/* ============================================================================================== */
/* Debugging and optimization macros */
/* ============================================================================================== */
/**
* Runtime debug assertion.
*/
#if defined(ZYAN_NO_LIBC)
# define ZYAN_ASSERT(condition) (void)(condition)
#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
# include <wdm.h>
# define ZYAN_ASSERT(condition) NT_ASSERT(condition)
#else
# include <assert.h>
# define ZYAN_ASSERT(condition) assert(condition)
#endif
/**
* Compiler-time assertion.
*/
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
# define ZYAN_STATIC_ASSERT(x) _Static_assert(x, #x)
#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
(defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
(defined (_MSC_VER) && (_MSC_VER >= 1800))
# define ZYAN_STATIC_ASSERT(x) static_assert(x, #x)
#else
# define ZYAN_STATIC_ASSERT(x) \
typedef int ZYAN_MACRO_CONCAT_EXPAND(ZYAN_SASSERT_, __COUNTER__) [(x) ? 1 : -1]
#endif
/**
* Marks the current code path as unreachable.
*/
#if defined(ZYAN_RELEASE)
# if defined(ZYAN_CLANG) // GCC eagerly evals && RHS, we have to use nested ifs.
# if __has_builtin(__builtin_unreachable)
# define ZYAN_UNREACHABLE __builtin_unreachable()
# else
# define ZYAN_UNREACHABLE for(;;)
# endif
# elif defined(ZYAN_GCC) && ((__GNUC__ == 4 && __GNUC_MINOR__ > 4) || __GNUC__ > 4)
# define ZYAN_UNREACHABLE __builtin_unreachable()
# elif defined(ZYAN_ICC)
# ifdef ZYAN_WINDOWS
# include <stdlib.h> // "missing return statement" workaround
# define ZYAN_UNREACHABLE __assume(0); (void)abort()
# else
# define ZYAN_UNREACHABLE __builtin_unreachable()
# endif
# elif defined(ZYAN_MSVC)
# define ZYAN_UNREACHABLE __assume(0)
# else
# define ZYAN_UNREACHABLE for(;;)
# endif
#elif defined(ZYAN_NO_LIBC)
# define ZYAN_UNREACHABLE for(;;)
#elif defined(ZYAN_WINDOWS) && defined(ZYAN_KERNEL)
# define ZYAN_UNREACHABLE { __fastfail(0); for(;;){} }
#else
# include <stdlib.h>
# define ZYAN_UNREACHABLE { assert(0); abort(); }
#endif
/* ============================================================================================== */
/* Utils */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* General purpose */
/* ---------------------------------------------------------------------------------------------- */
/**
* Marks the specified parameter as unused.
*
* @param x The name of the unused parameter.
*/
#define ZYAN_UNUSED(x) (void)(x)
/**
* Intentional fallthrough.
*/
#if defined(ZYAN_GCC) && __GNUC__ >= 7
# define ZYAN_FALLTHROUGH ; __attribute__((__fallthrough__))
#else
# define ZYAN_FALLTHROUGH
#endif
/**
* Declares a bitfield.
*
* @param x The size (in bits) of the bitfield.
*/
#define ZYAN_BITFIELD(x) : x
/**
* Marks functions that require libc (cannot be used with `ZYAN_NO_LIBC`).
*/
#define ZYAN_REQUIRES_LIBC
/**
* Decorator for `printf`-style functions.
*
* @param format_index The 1-based index of the format string parameter.
* @param first_to_check The 1-based index of the format arguments parameter.
*/
#if defined(__RESHARPER__)
# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
[[gnu::format(printf, format_index, first_to_check)]]
#elif defined(ZYAN_GCC)
# define ZYAN_PRINTF_ATTR(format_index, first_to_check) \
__attribute__((format(printf, format_index, first_to_check)))
#else
# define ZYAN_PRINTF_ATTR(format_index, first_to_check)
#endif
/**
* Decorator for `wprintf`-style functions.
*
* @param format_index The 1-based index of the format string parameter.
* @param first_to_check The 1-based index of the format arguments parameter.
*/
#if defined(__RESHARPER__)
# define ZYAN_WPRINTF_ATTR(format_index, first_to_check) \
[[rscpp::format(wprintf, format_index, first_to_check)]]
#else
# define ZYAN_WPRINTF_ATTR(format_index, first_to_check)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Arrays */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the length (number of elements) of an array.
*
* @param a The name of the array.
*
* @return The number of elements of the given array.
*/
#define ZYAN_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
/* ---------------------------------------------------------------------------------------------- */
/* Arithmetic */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the smaller value of `a` or `b`.
*
* @param a The first value.
* @param b The second value.
*
* @return The smaller value of `a` or `b`.
*/
#define ZYAN_MIN(a, b) (((a) < (b)) ? (a) : (b))
/**
* Returns the bigger value of `a` or `b`.
*
* @param a The first value.
* @param b The second value.
*
* @return The bigger value of `a` or `b`.
*/
#define ZYAN_MAX(a, b) (((a) > (b)) ? (a) : (b))
/**
* Returns the absolute value of `a`.
*
* @param a The value.
*
* @return The absolute value of `a`.
*/
#define ZYAN_ABS(a) (((a) < 0) ? -(a) : (a))
/**
* Checks, if the given value is a power of 2.
*
* @param x The value.
*
* @return `ZYAN_TRUE`, if the given value is a power of 2 or `ZYAN_FALSE`, if not.
*
* Note that this macro always returns `ZYAN_TRUE` for `x == 0`.
*/
#define ZYAN_IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
/**
* Checks, if the given value is properly aligned.
*
* Note that this macro only works for powers of 2.
*/
#define ZYAN_IS_ALIGNED_TO(x, align) (((x) & ((align) - 1)) == 0)
/**
* Aligns the value to the nearest given alignment boundary (by rounding it up).
*
* @param x The value.
* @param align The desired alignment.
*
* @return The aligned value.
*
* Note that this macro only works for powers of 2.
*/
#define ZYAN_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1))
/**
* Aligns the value to the nearest given alignment boundary (by rounding it down).
*
* @param x The value.
* @param align The desired alignment.
*
* @return The aligned value.
*
* Note that this macro only works for powers of 2.
*/
#define ZYAN_ALIGN_DOWN(x, align) (((x) - 1) & ~((align) - 1))
/* ---------------------------------------------------------------------------------------------- */
/* Bit operations */
/* ---------------------------------------------------------------------------------------------- */
/*
* Checks, if the bit at index `b` is required to present the ordinal value `n`.
*
* @param n The ordinal value.
* @param b The bit index.
*
* @return `ZYAN_TRUE`, if the bit at index `b` is required to present the ordinal value `n` or
* `ZYAN_FALSE`, if not.
*
* Note that this macro always returns `ZYAN_FALSE` for `n == 0`.
*/
#define ZYAN_NEEDS_BIT(n, b) (((unsigned long)(n) >> (b)) > 0)
/*
* Returns the number of bits required to represent the ordinal value `n`.
*
* @param n The ordinal value.
*
* @return The number of bits required to represent the ordinal value `n`.
*
* Note that this macro returns `0` for `n == 0`.
*/
#define ZYAN_BITS_TO_REPRESENT(n) \
( \
ZYAN_NEEDS_BIT(n, 0) + ZYAN_NEEDS_BIT(n, 1) + \
ZYAN_NEEDS_BIT(n, 2) + ZYAN_NEEDS_BIT(n, 3) + \
ZYAN_NEEDS_BIT(n, 4) + ZYAN_NEEDS_BIT(n, 5) + \
ZYAN_NEEDS_BIT(n, 6) + ZYAN_NEEDS_BIT(n, 7) + \
ZYAN_NEEDS_BIT(n, 8) + ZYAN_NEEDS_BIT(n, 9) + \
ZYAN_NEEDS_BIT(n, 10) + ZYAN_NEEDS_BIT(n, 11) + \
ZYAN_NEEDS_BIT(n, 12) + ZYAN_NEEDS_BIT(n, 13) + \
ZYAN_NEEDS_BIT(n, 14) + ZYAN_NEEDS_BIT(n, 15) + \
ZYAN_NEEDS_BIT(n, 16) + ZYAN_NEEDS_BIT(n, 17) + \
ZYAN_NEEDS_BIT(n, 18) + ZYAN_NEEDS_BIT(n, 19) + \
ZYAN_NEEDS_BIT(n, 20) + ZYAN_NEEDS_BIT(n, 21) + \
ZYAN_NEEDS_BIT(n, 22) + ZYAN_NEEDS_BIT(n, 23) + \
ZYAN_NEEDS_BIT(n, 24) + ZYAN_NEEDS_BIT(n, 25) + \
ZYAN_NEEDS_BIT(n, 26) + ZYAN_NEEDS_BIT(n, 27) + \
ZYAN_NEEDS_BIT(n, 28) + ZYAN_NEEDS_BIT(n, 29) + \
ZYAN_NEEDS_BIT(n, 30) + ZYAN_NEEDS_BIT(n, 31) \
)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYCORE_DEFINES_H */
//
// Header: Zycore/Types.h
//
// Include stack:
// - Zydis/Zydis.h
//
/***************************************************************************************************
Zyan Core Library (Zyan-C)
Original Author : Florian Bernd, Joel Hoener
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Includes and defines some default data types.
*/
#ifndef ZYCORE_TYPES_H
#define ZYCORE_TYPES_H
/* ============================================================================================== */
/* Integer types */
/* ============================================================================================== */
#if defined(ZYAN_NO_LIBC) || \
(defined(ZYAN_MSVC) && defined(ZYAN_KERNEL)) // The WDK LibC lacks stdint.h.
// No LibC mode, use compiler built-in types / macros.
# if defined(ZYAN_MSVC) || defined(ZYAN_ICC)
typedef unsigned __int8 ZyanU8;
typedef unsigned __int16 ZyanU16;
typedef unsigned __int32 ZyanU32;
typedef unsigned __int64 ZyanU64;
typedef signed __int8 ZyanI8;
typedef signed __int16 ZyanI16;
typedef signed __int32 ZyanI32;
typedef signed __int64 ZyanI64;
# if _WIN64
typedef ZyanU64 ZyanUSize;
typedef ZyanI64 ZyanISize;
typedef ZyanU64 ZyanUPointer;
typedef ZyanI64 ZyanIPointer;
# else
typedef ZyanU32 ZyanUSize;
typedef ZyanI32 ZyanISize;
typedef ZyanU32 ZyanUPointer;
typedef ZyanI32 ZyanIPointer;
# endif
# elif defined(ZYAN_GNUC)
typedef __UINT8_TYPE__ ZyanU8;
typedef __UINT16_TYPE__ ZyanU16;
typedef __UINT32_TYPE__ ZyanU32;
typedef __UINT64_TYPE__ ZyanU64;
typedef __INT8_TYPE__ ZyanI8;
typedef __INT16_TYPE__ ZyanI16;
typedef __INT32_TYPE__ ZyanI32;
typedef __INT64_TYPE__ ZyanI64;
typedef __SIZE_TYPE__ ZyanUSize;
typedef __PTRDIFF_TYPE__ ZyanISize;
typedef __UINTPTR_TYPE__ ZyanUPointer;
typedef __INTPTR_TYPE__ ZyanIPointer;
# else
# error "Unsupported compiler for no-libc mode."
# endif
# if defined(ZYAN_MSVC)
# define ZYAN_INT8_MIN (-127i8 - 1)
# define ZYAN_INT16_MIN (-32767i16 - 1)
# define ZYAN_INT32_MIN (-2147483647i32 - 1)
# define ZYAN_INT64_MIN (-9223372036854775807i64 - 1)
# define ZYAN_INT8_MAX 127i8
# define ZYAN_INT16_MAX 32767i16
# define ZYAN_INT32_MAX 2147483647i32
# define ZYAN_INT64_MAX 9223372036854775807i64
# define ZYAN_UINT8_MAX 0xffui8
# define ZYAN_UINT16_MAX 0xffffui16
# define ZYAN_UINT32_MAX 0xffffffffui32
# define ZYAN_UINT64_MAX 0xffffffffffffffffui64
# else
# define ZYAN_INT8_MAX __INT8_MAX__
# define ZYAN_INT8_MIN (-ZYAN_INT8_MAX - 1)
# define ZYAN_INT16_MAX __INT16_MAX__
# define ZYAN_INT16_MIN (-ZYAN_INT16_MAX - 1)
# define ZYAN_INT32_MAX __INT32_MAX__
# define ZYAN_INT32_MIN (-ZYAN_INT32_MAX - 1)
# define ZYAN_INT64_MAX __INT64_MAX__
# define ZYAN_INT64_MIN (-ZYAN_INT64_MAX - 1)
# define ZYAN_UINT8_MAX __UINT8_MAX__
# define ZYAN_UINT16_MAX __UINT16_MAX__
# define ZYAN_UINT32_MAX __UINT32_MAX__
# define ZYAN_UINT64_MAX __UINT64_MAX__
# endif
#else
// If is LibC present, we use stdint types.
# include <stdint.h>
# include <stddef.h>
typedef uint8_t ZyanU8;
typedef uint16_t ZyanU16;
typedef uint32_t ZyanU32;
typedef uint64_t ZyanU64;
typedef int8_t ZyanI8;
typedef int16_t ZyanI16;
typedef int32_t ZyanI32;
typedef int64_t ZyanI64;
typedef size_t ZyanUSize;
typedef ptrdiff_t ZyanISize;
typedef uintptr_t ZyanUPointer;
typedef intptr_t ZyanIPointer;
# define ZYAN_INT8_MIN INT8_MIN
# define ZYAN_INT16_MIN INT16_MIN
# define ZYAN_INT32_MIN INT32_MIN
# define ZYAN_INT64_MIN INT64_MIN
# define ZYAN_INT8_MAX INT8_MAX
# define ZYAN_INT16_MAX INT16_MAX
# define ZYAN_INT32_MAX INT32_MAX
# define ZYAN_INT64_MAX INT64_MAX
# define ZYAN_UINT8_MAX UINT8_MAX
# define ZYAN_UINT16_MAX UINT16_MAX
# define ZYAN_UINT32_MAX UINT32_MAX
# define ZYAN_UINT64_MAX UINT64_MAX
#endif
// Verify size assumptions.
ZYAN_STATIC_ASSERT(sizeof(ZyanU8 ) == 1 );
ZYAN_STATIC_ASSERT(sizeof(ZyanU16 ) == 2 );
ZYAN_STATIC_ASSERT(sizeof(ZyanU32 ) == 4 );
ZYAN_STATIC_ASSERT(sizeof(ZyanU64 ) == 8 );
ZYAN_STATIC_ASSERT(sizeof(ZyanI8 ) == 1 );
ZYAN_STATIC_ASSERT(sizeof(ZyanI16 ) == 2 );
ZYAN_STATIC_ASSERT(sizeof(ZyanI32 ) == 4 );
ZYAN_STATIC_ASSERT(sizeof(ZyanI64 ) == 8 );
ZYAN_STATIC_ASSERT(sizeof(ZyanUSize ) == sizeof(void*)); // TODO: This one is incorrect!
ZYAN_STATIC_ASSERT(sizeof(ZyanISize ) == sizeof(void*)); // TODO: This one is incorrect!
ZYAN_STATIC_ASSERT(sizeof(ZyanUPointer) == sizeof(void*));
ZYAN_STATIC_ASSERT(sizeof(ZyanIPointer) == sizeof(void*));
// Verify signedness assumptions (relies on size checks above).
ZYAN_STATIC_ASSERT((ZyanI8 )-1 >> 1 < (ZyanI8 )((ZyanU8 )-1 >> 1));
ZYAN_STATIC_ASSERT((ZyanI16)-1 >> 1 < (ZyanI16)((ZyanU16)-1 >> 1));
ZYAN_STATIC_ASSERT((ZyanI32)-1 >> 1 < (ZyanI32)((ZyanU32)-1 >> 1));
ZYAN_STATIC_ASSERT((ZyanI64)-1 >> 1 < (ZyanI64)((ZyanU64)-1 >> 1));
/* ============================================================================================== */
/* Pointer */
/* ============================================================================================== */
/**
* Defines the `ZyanVoidPointer` data-type.
*/
typedef void* ZyanVoidPointer;
/**
* Defines the `ZyanConstVoidPointer` data-type.
*/
typedef const void* ZyanConstVoidPointer;
#define ZYAN_NULL ((void*)0)
/* ============================================================================================== */
/* Logic types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Boolean */
/* ---------------------------------------------------------------------------------------------- */
#define ZYAN_FALSE 0u
#define ZYAN_TRUE 1u
/**
* Defines the `ZyanBool` data-type.
*
* Represents a default boolean data-type where `0` is interpreted as `false` and all other values
* as `true`.
*/
typedef ZyanU8 ZyanBool;
/* ---------------------------------------------------------------------------------------------- */
/* Ternary */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanTernary` data-type.
*
* The `ZyanTernary` is a balanced ternary type that uses three truth values indicating `true`,
* `false` and an indeterminate third value.
*/
typedef ZyanI8 ZyanTernary;
#define ZYAN_TERNARY_FALSE (-1)
#define ZYAN_TERNARY_UNKNOWN 0x00
#define ZYAN_TERNARY_TRUE 0x01
/* ============================================================================================== */
/* String types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* C-style strings */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZyanCharPointer` data-type.
*
* This type is most often used to represent null-terminated strings aka. C-style strings.
*/
typedef char* ZyanCharPointer;
/**
* Defines the `ZyanConstCharPointer` data-type.
*
* This type is most often used to represent null-terminated strings aka. C-style strings.
*/
typedef const char* ZyanConstCharPointer;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#endif /* ZYCORE_TYPES_H */
#if !defined(ZYDIS_DISABLE_DECODER)
//
// Header: Zydis/Decoder.h
//
// Include stack:
// - Zydis/Zydis.h
//
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Functions for decoding instructions.
*/
#ifndef ZYDIS_DECODER_H
#define ZYDIS_DECODER_H
//
// Header: Zydis/DecoderTypes.h
//
// Include stack:
// - Zydis/Zydis.h
// - Zydis/Decoder.h
//
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Defines the basic `ZydisDecodedInstruction` and `ZydisDecodedOperand` structs.
*/
#ifndef ZYDIS_INSTRUCTIONINFO_H
#define ZYDIS_INSTRUCTIONINFO_H
//
// Header: Zydis/MetaInfo.h
//
// Include stack:
// - Zydis/Zydis.h
// - Zydis/Decoder.h
// - Zydis/DecoderTypes.h
//
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief
*/
#ifndef ZYDIS_METAINFO_H
#define ZYDIS_METAINFO_H
//
// Header: Zydis/Defines.h
//
// Include stack:
// - Zydis/Zydis.h
// - Zydis/Decoder.h
// - Zydis/DecoderTypes.h
// - Zydis/MetaInfo.h
//
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Joel Hoener
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* Import/export defines for MSVC builds.
*/
#ifndef ZYDIS_DEFINES_H
#define ZYDIS_DEFINES_H
// This is a cut-down version of what CMake's `GenerateExportHeader` would usually generate. To
// simplify builds without CMake, we define these things manually instead of relying on CMake
// to generate the header.
//