1
0
mirror of synced 2024-11-15 03:27:40 +01:00
ImHex/lib/libimhex/include/hex/helpers/disassembler.hpp
StarrFox 25ddaa08dc
build: Fix building with capstone < 5 (#1323)
<!--
Please provide as much information as possible about what your PR aims
to do.
PRs with no description will most likely be closed until more
information is provided.
If you're planing on changing fundamental behaviour or add big new
features, please open a GitHub Issue first before starting to work on
it.
If it's not something big and you still want to contact us about it,
feel free to do so !
-->

### Problem description
<!-- Describe the bug that you fixed/feature request that you
implemented, or link to an existing issue describing it -->
This might fix building with capstone 4 as discussed in
https://discord.com/channels/789833418631675954/1155669027306340393/1155669027306340393

### Implementation description
<!-- Explain what you did to correct the problem -->
moves the max definition inside the if statement that checks for
capstone 5
2023-09-25 21:52:28 +02:00

94 lines
2.9 KiB
C++

#pragma once
#include <hex.hpp>
#include <capstone/capstone.h>
namespace hex {
enum class Architecture : i32
{
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,
#if CS_API_MAJOR >= 5
WASM = CS_ARCH_WASM,
RISCV = CS_ARCH_RISCV,
MOS65XX = CS_ARCH_MOS65XX,
BPF = CS_ARCH_BPF,
SH = CS_ARCH_SH,
TRICORE = CS_ARCH_TRICORE,
MAX = TRICORE,
# else
MAX = EVM,
#endif
MIN = ARM
};
class Disassembler {
public:
constexpr static cs_arch toCapstoneArchitecture(Architecture architecture) {
return static_cast<cs_arch>(architecture);
}
static inline bool isSupported(Architecture architecture) {
return cs_support(toCapstoneArchitecture(architecture));
}
constexpr static auto ArchitectureNames = [](){
std::array<const char *, static_cast<u32>(Architecture::MAX) + 1> names = { };
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
names[CS_ARCH_WASM] = "WebAssembly";
names[CS_ARCH_RISCV] = "RISC-V";
names[CS_ARCH_MOS65XX] = "MOS Technology 65xx";
names[CS_ARCH_BPF] = "Berkeley Packet Filter";
names[CS_ARCH_SH] = "SuperH";
names[CS_ARCH_TRICORE] = "Tricore";
#endif
return names;
}();
static inline i32 getArchitectureSupportedCount() {
static i32 supportedCount = -1;
if (supportedCount != -1) {
return supportedCount;
}
for (supportedCount = static_cast<i32>(Architecture::MIN); supportedCount < static_cast<i32>(Architecture::MAX) + 1; supportedCount++) {
if (!cs_support(supportedCount)) {
break;
}
}
return supportedCount;
}
};
}