2020-12-05 17:32:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-25 15:19:56 +01:00
|
|
|
#if __has_include(<capstone/capstone.h>)
|
2020-12-05 17:32:30 +01:00
|
|
|
#include <capstone/capstone.h>
|
2021-01-25 15:19:56 +01:00
|
|
|
#else
|
|
|
|
#include <capstone.h>
|
|
|
|
#endif
|
2020-12-05 17:32:30 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
enum class Architecture : s32 {
|
|
|
|
ARM,
|
|
|
|
ARM64,
|
|
|
|
MIPS,
|
|
|
|
X86,
|
|
|
|
PPC,
|
|
|
|
SPARC,
|
|
|
|
SYSZ,
|
|
|
|
XCORE,
|
|
|
|
M68K,
|
|
|
|
TMS320C64X,
|
|
|
|
M680X,
|
|
|
|
EVM,
|
2021-12-15 23:28:47 +01:00
|
|
|
MOS65XX,
|
|
|
|
WASM,
|
|
|
|
BPF,
|
|
|
|
RISCV,
|
2020-12-05 17:32:30 +01:00
|
|
|
|
|
|
|
MAX,
|
|
|
|
MIN = ARM
|
|
|
|
};
|
|
|
|
|
|
|
|
class Disassembler {
|
|
|
|
public:
|
|
|
|
static constexpr cs_arch toCapstoneArchictecture(Architecture architecture) {
|
|
|
|
return static_cast<cs_arch>(architecture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isSupported(Architecture architecture) {
|
|
|
|
return cs_support(toCapstoneArchictecture(architecture));
|
|
|
|
}
|
|
|
|
|
2021-12-15 23:28:47 +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
|
|
|
|
|
|
|
static inline s32 getArchitectureSupportedCount() {
|
|
|
|
static s32 supportedCount = -1;
|
|
|
|
|
|
|
|
if (supportedCount != -1) {
|
|
|
|
return supportedCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (supportedCount = static_cast<s32>(Architecture::MIN); supportedCount < static_cast<s32>(Architecture::MAX); supportedCount++) {
|
|
|
|
if (!cs_support(supportedCount)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedCount;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|