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
|
|
|
|
{
|
2020-12-05 17:32:30 +01:00
|
|
|
ARM,
|
|
|
|
ARM64,
|
|
|
|
MIPS,
|
|
|
|
X86,
|
|
|
|
PPC,
|
|
|
|
SPARC,
|
|
|
|
SYSZ,
|
|
|
|
XCORE,
|
|
|
|
M68K,
|
|
|
|
TMS320C64X,
|
|
|
|
M680X,
|
|
|
|
EVM,
|
2021-12-15 23:28:47 +01:00
|
|
|
WASM,
|
2023-03-23 16:45:00 +01:00
|
|
|
#if defined(CS_MODE_RISCV32)
|
|
|
|
RISCV,
|
|
|
|
#endif
|
|
|
|
#if defined(CS_MODE_MOS65XX_6502)
|
|
|
|
MOS65XX,
|
|
|
|
#endif
|
|
|
|
#if defined(CS_MODE_BPF_CLASSIC)
|
2021-12-15 23:28:47 +01:00
|
|
|
BPF,
|
2023-03-23 16:45:00 +01:00
|
|
|
#endif
|
2020-12-05 17:32:30 +01:00
|
|
|
|
|
|
|
MAX,
|
|
|
|
MIN = ARM
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
constexpr static const char *const ArchitectureNames[] = { "ARM32", "ARM64", "MIPS", "x86", "PowerPC", "Sparc", "SystemZ", "XCore", "68K", "TMS320C64x", "680X", "Ethereum", "MOS65XX", "WebAssembly", "Berkeley Packet Filter", "RISC-V" };
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:37:52 +01:00
|
|
|
for (supportedCount = static_cast<i32>(Architecture::MIN); supportedCount < static_cast<i32>(Architecture::MAX); supportedCount++) {
|
2020-12-05 17:32:30 +01:00
|
|
|
if (!cs_support(supportedCount)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedCount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|