2020-12-05 17:32:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2022-02-08 19:22:52 +01:00
|
|
|
#include <capstone/capstone.h>
|
|
|
|
|
2020-12-05 17:32:30 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2022-02-08 19:22:52 +01:00
|
|
|
enum class Architecture : i32
|
|
|
|
{
|
2023-04-05 18:02:47 +02:00
|
|
|
ARM = CS_ARCH_ARM,
|
|
|
|
ARM64 = CS_ARCH_ARM64,
|
|
|
|
MIPS = CS_ARCH_MIPS,
|
|
|
|
X86 = CS_ARCH_X86,
|
|
|
|
PPC = CS_ARCH_PPC,
|
|
|
|
SPARC = CS_ARCH_SPARC,
|
|
|
|
SYSZ = CS_ARCH_SYSZ,
|
|
|
|
XCORE = CS_ARCH_XCORE,
|
|
|
|
M68K = CS_ARCH_M68K,
|
|
|
|
TMS320C64X = CS_ARCH_TMS320C64X,
|
|
|
|
M680X = CS_ARCH_M680X,
|
|
|
|
EVM = CS_ARCH_EVM,
|
2023-04-04 23:08:10 +02:00
|
|
|
|
|
|
|
#if CS_API_MAJOR >= 5
|
2023-05-20 13:37:45 +02:00
|
|
|
WASM = CS_ARCH_WASM,
|
2023-04-05 18:02:47 +02:00
|
|
|
RISCV = CS_ARCH_RISCV,
|
|
|
|
MOS65XX = CS_ARCH_MOS65XX,
|
|
|
|
BPF = CS_ARCH_BPF,
|
2023-08-26 12:21:44 +02:00
|
|
|
SH = CS_ARCH_SH,
|
|
|
|
TRICORE = CS_ARCH_TRICORE,
|
2023-03-23 16:45:00 +01:00
|
|
|
#endif
|
2020-12-05 17:32:30 +01:00
|
|
|
|
2023-08-26 12:21:44 +02:00
|
|
|
MAX = TRICORE,
|
2023-04-05 18:02:47 +02:00
|
|
|
MIN = ARM
|
2020-12-05 17:32:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Disassembler {
|
|
|
|
public:
|
2022-09-12 21:28:02 +02:00
|
|
|
constexpr static cs_arch toCapstoneArchitecture(Architecture architecture) {
|
2020-12-05 17:32:30 +01:00
|
|
|
return static_cast<cs_arch>(architecture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isSupported(Architecture architecture) {
|
2022-03-04 20:52:39 +01:00
|
|
|
return cs_support(toCapstoneArchitecture(architecture));
|
2020-12-05 17:32:30 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 18:02:47 +02:00
|
|
|
constexpr static auto ArchitectureNames = [](){
|
2023-08-26 12:21:44 +02:00
|
|
|
std::array<const char *, static_cast<u32>(Architecture::MAX) + 1> names = { };
|
2023-04-05 18:02:47 +02:00
|
|
|
|
|
|
|
names[CS_ARCH_ARM] = "ARM";
|
|
|
|
names[CS_ARCH_ARM64] = "AArch64";
|
|
|
|
names[CS_ARCH_MIPS] = "MIPS";
|
|
|
|
names[CS_ARCH_X86] = "Intel x86";
|
|
|
|
names[CS_ARCH_PPC] = "PowerPC";
|
|
|
|
names[CS_ARCH_SPARC] = "SPARC";
|
|
|
|
names[CS_ARCH_SYSZ] = "SystemZ";
|
|
|
|
names[CS_ARCH_XCORE] = "XCore";
|
|
|
|
names[CS_ARCH_M68K] = "Motorola 68K";
|
|
|
|
names[CS_ARCH_TMS320C64X] = "TMS320C64x";
|
|
|
|
names[CS_ARCH_M680X] = "M680X";
|
|
|
|
names[CS_ARCH_EVM] = "Ethereum Virtual Machine";
|
|
|
|
|
|
|
|
#if CS_API_MAJOR >= 5
|
2023-05-20 13:37:45 +02:00
|
|
|
names[CS_ARCH_WASM] = "WebAssembly";
|
2023-04-05 18:02:47 +02:00
|
|
|
names[CS_ARCH_RISCV] = "RISC-V";
|
|
|
|
names[CS_ARCH_MOS65XX] = "MOS Technology 65xx";
|
|
|
|
names[CS_ARCH_BPF] = "Berkeley Packet Filter";
|
2023-08-26 12:21:44 +02:00
|
|
|
names[CS_ARCH_SH] = "SuperH";
|
|
|
|
names[CS_ARCH_TRICORE] = "Tricore";
|
2023-04-05 18:02:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}();
|
2020-12-05 17:32:30 +01:00
|
|
|
|
2022-01-22 22:37:52 +01:00
|
|
|
static inline i32 getArchitectureSupportedCount() {
|
|
|
|
static i32 supportedCount = -1;
|
2020-12-05 17:32:30 +01:00
|
|
|
|
|
|
|
if (supportedCount != -1) {
|
|
|
|
return supportedCount;
|
|
|
|
}
|
|
|
|
|
2023-08-26 12:21:44 +02:00
|
|
|
for (supportedCount = static_cast<i32>(Architecture::MIN); supportedCount < static_cast<i32>(Architecture::MAX) + 1; supportedCount++) {
|
2020-12-05 17:32:30 +01:00
|
|
|
if (!cs_support(supportedCount)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedCount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|