build: Refactor ContentRegistry into multiple separate files

This commit is contained in:
WerWolv
2025-08-14 21:22:03 +02:00
parent d920718b44
commit fbde2942de
141 changed files with 2337 additions and 2007 deletions

View File

@@ -1,4 +1,4 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/content_registry/disassemblers.hpp>
#include <content/helpers/disassembler.hpp>
#include <hex/helpers/fmt.hpp>
@@ -7,7 +7,7 @@
namespace hex::plugin::disasm {
class CapstoneArchitecture : public ContentRegistry::Disassembler::Architecture {
class CapstoneArchitecture : public ContentRegistry::Disassemblers::Architecture {
public:
explicit CapstoneArchitecture(BuiltinArchitecture architecture, cs_mode mode = cs_mode(0))
: Architecture(CapstoneDisassembler::ArchitectureNames[u32(architecture)]),
@@ -51,7 +51,7 @@ namespace hex::plugin::disasm {
ImGui::NewLine();
}
std::optional<ContentRegistry::Disassembler::Instruction> disassemble(u64 imageBaseAddress, u64 instructionLoadAddress, u64 instructionDataAddress, std::span<const u8> code) override {
std::optional<ContentRegistry::Disassemblers::Instruction> disassemble(u64 imageBaseAddress, u64 instructionLoadAddress, u64 instructionDataAddress, std::span<const u8> code) override {
auto ptr = code.data();
auto size = code.size_bytes();
@@ -59,7 +59,7 @@ namespace hex::plugin::disasm {
return std::nullopt;
}
ContentRegistry::Disassembler::Instruction disassembly = { };
ContentRegistry::Disassemblers::Instruction disassembly = { };
disassembly.address = m_instruction->address;
disassembly.offset = instructionDataAddress - imageBaseAddress;
disassembly.size = m_instruction->size;
@@ -440,26 +440,26 @@ namespace hex::plugin::disasm {
#endif
void registerCapstoneArchitectures() {
ContentRegistry::Disassembler::add<ArchitectureARM>();
ContentRegistry::Disassembler::add<ArchitectureARM64>();
ContentRegistry::Disassembler::add<ArchitectureMIPS>();
ContentRegistry::Disassembler::add<ArchitectureX86>();
ContentRegistry::Disassembler::add<ArchitecturePowerPC>();
ContentRegistry::Disassembler::add<ArchitectureSPARC>();
ContentRegistry::Disassembler::add<ArchitectureSystemZ>();
ContentRegistry::Disassembler::add<ArchitectureXCore>();
ContentRegistry::Disassembler::add<ArchitectureM68K>();
ContentRegistry::Disassembler::add<ArchitectureTMS320C64X>();
ContentRegistry::Disassembler::add<ArchitectureM680X>();
ContentRegistry::Disassembler::add<ArchitectureEVM>();
ContentRegistry::Disassemblers::add<ArchitectureARM>();
ContentRegistry::Disassemblers::add<ArchitectureARM64>();
ContentRegistry::Disassemblers::add<ArchitectureMIPS>();
ContentRegistry::Disassemblers::add<ArchitectureX86>();
ContentRegistry::Disassemblers::add<ArchitecturePowerPC>();
ContentRegistry::Disassemblers::add<ArchitectureSPARC>();
ContentRegistry::Disassemblers::add<ArchitectureSystemZ>();
ContentRegistry::Disassemblers::add<ArchitectureXCore>();
ContentRegistry::Disassemblers::add<ArchitectureM68K>();
ContentRegistry::Disassemblers::add<ArchitectureTMS320C64X>();
ContentRegistry::Disassemblers::add<ArchitectureM680X>();
ContentRegistry::Disassemblers::add<ArchitectureEVM>();
#if CS_API_MAJOR >= 5
ContentRegistry::Disassembler::add<ArchitectureWASM>();
ContentRegistry::Disassembler::add<ArchitectureRISCV>();
ContentRegistry::Disassembler::add<ArchitectureMOS65XX>();
ContentRegistry::Disassembler::add<ArchitectureBPF>();
ContentRegistry::Disassembler::add<ArchitectureSuperH>();
ContentRegistry::Disassembler::add<ArchitectureTricore>();
ContentRegistry::Disassemblers::add<ArchitectureWASM>();
ContentRegistry::Disassemblers::add<ArchitectureRISCV>();
ContentRegistry::Disassemblers::add<ArchitectureMOS65XX>();
ContentRegistry::Disassemblers::add<ArchitectureBPF>();
ContentRegistry::Disassemblers::add<ArchitectureSuperH>();
ContentRegistry::Disassemblers::add<ArchitectureTricore>();
#endif
}

View File

@@ -1,4 +1,4 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/content_registry/disassemblers.hpp>
#include <hex/helpers/default_paths.hpp>
#include <disasm/disasm.hpp>
@@ -8,7 +8,7 @@
namespace hex::plugin::disasm {
class CustomArchitecture : public ContentRegistry::Disassembler::Architecture {
class CustomArchitecture : public ContentRegistry::Disassemblers::Architecture {
public:
CustomArchitecture(std::string name, std::fs::path path) : Architecture(std::move(name)), m_path(std::move(path)) {}
@@ -26,7 +26,7 @@ namespace hex::plugin::disasm {
}
std::optional<ContentRegistry::Disassembler::Instruction> disassemble(u64 imageBaseAddress, u64 instructionLoadAddress, u64 instructionDataAddress, std::span<const u8> code) override {
std::optional<ContentRegistry::Disassemblers::Instruction> disassemble(u64 imageBaseAddress, u64 instructionLoadAddress, u64 instructionDataAddress, std::span<const u8> code) override {
std::ignore = imageBaseAddress;
std::ignore = instructionDataAddress;
std::ignore = instructionLoadAddress;
@@ -39,7 +39,7 @@ namespace hex::plugin::disasm {
const auto &instruction = instructions.front();
ContentRegistry::Disassembler::Instruction disassembly = { };
ContentRegistry::Disassemblers::Instruction disassembly = { };
disassembly.address = instructionDataAddress;
disassembly.offset = instructionDataAddress - imageBaseAddress;
disassembly.size = instruction.bytes.size();
@@ -69,7 +69,7 @@ namespace hex::plugin::disasm {
try {
auto spec = ::disasm::spec::Loader::load(entry.path(), { entry.path().parent_path() });
ContentRegistry::Disassembler::add<CustomArchitecture>(spec.getName(), entry.path());
ContentRegistry::Disassemblers::add<CustomArchitecture>(spec.getName(), entry.path());
} catch (const std::exception &e) {
log::error("Failed to load disassembler config '{}': {}", wolv::util::toUTF8String(entry.path()), e.what());
}

View File

@@ -1,4 +1,4 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/content_registry/pattern_language.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/utils.hpp>

View File

@@ -1,5 +1,6 @@
#include <content/views/view_disassembler.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/content_registry/user_interface.hpp>
#include <hex/api/content_registry/views.hpp>
#include <hex/api/imhex_api/hex_editor.hpp>
#include <hex/providers/provider.hpp>
@@ -21,7 +22,7 @@ namespace hex::plugin::disasm {
m_disassembly.get(provider).clear();
});
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.menu.edit.disassemble_range" }, ICON_VS_DEBUG_LINE_BY_LINE, 3100, CTRLCMD + SHIFT + Keys::D, [this] {
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.menu.edit.disassemble_range" }, ICON_VS_DEBUG_LINE_BY_LINE, 3100, CTRLCMD + SHIFT + Keys::D, [this] {
ImGui::SetWindowFocus(this->getName().c_str());
this->getWindowOpenState() = true;
@@ -121,7 +122,7 @@ namespace hex::plugin::disasm {
}
// As disassembly code can be quite long, we prefer writing each disassembled instruction to file
for (const ContentRegistry::Disassembler::Instruction& instruction : m_disassembly.get(provider)) {
for (const ContentRegistry::Disassemblers::Instruction& instruction : m_disassembly.get(provider)) {
// We test for a "bugged" case that should never happen - the instruction should always have a mnemonic
if (instruction.mnemonic.empty())
continue;
@@ -172,7 +173,7 @@ namespace hex::plugin::disasm {
ImGuiExt::Header("hex.ui.common.settings"_lang);
// Draw architecture selector
const auto &architectures = ContentRegistry::Disassembler::impl::getArchitectures();
const auto &architectures = ContentRegistry::Disassemblers::impl::getArchitectures();
if (architectures.empty()) {
ImGuiExt::TextSpinner("hex.disassembler.view.disassembler.arch"_lang);
} else {

View File

@@ -1,6 +1,7 @@
#include <hex/plugin.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/content_registry/views.hpp>
#include <hex/api/content_registry/pattern_language.hpp>
#include <hex/helpers/logger.hpp>
#include <pl/api.hpp>