1 #pragma once
2 
3 #if __has_include(<capstone/capstone.h>)
4 #include <capstone/capstone.h>
5 #else
6 #include <capstone.h>
7 #endif
8 #include <hex.hpp>
9 
10 namespace hex {
11 
12     enum class Architecture : s32 {
13         ARM,
14         ARM64,
15         MIPS,
16         X86,
17         PPC,
18         SPARC,
19         SYSZ,
20         XCORE,
21         M68K,
22         TMS320C64X,
23         M680X,
24         EVM,
25 
26         MAX,
27         MIN = ARM
28     };
29 
30     class Disassembler {
31     public:
toCapstoneArchictecture(Architecture architecture)32         static constexpr cs_arch toCapstoneArchictecture(Architecture architecture) {
33             return static_cast<cs_arch>(architecture);
34         }
35 
isSupported(Architecture architecture)36         static inline bool isSupported(Architecture architecture) {
37             return cs_support(toCapstoneArchictecture(architecture));
38         }
39 
40         constexpr static const char * const ArchitectureNames[] = { "ARM32", "ARM64", "MIPS", "x86", "PowerPC", "Sparc", "SystemZ", "XCore", "68K", "TMS320C64x", "680X", "Ethereum" };
41 
getArchitectureSupportedCount()42         static inline s32 getArchitectureSupportedCount() {
43             static s32 supportedCount = -1;
44 
45             if (supportedCount != -1) {
46                 return supportedCount;
47             }
48 
49             for (supportedCount = static_cast<s32>(Architecture::MIN); supportedCount < static_cast<s32>(Architecture::MAX); supportedCount++) {
50                 if (!cs_support(supportedCount)) {
51                     break;
52                 }
53             }
54 
55             return supportedCount;
56         }
57     };
58 }
59