From 1e71d8afc095e6649cb29b639db477c831b9566f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 9 Dec 2024 21:35:08 +0100 Subject: [PATCH] feat: Added `Disassemble selection` option to the Edit menu #1994 --- plugins/builtin/romfs/lang/en_US.json | 1 + .../source/content/views/view_disassembler.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index bc5f9d0549077..f92f92e3576a8 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -122,6 +122,7 @@ "hex.builtin.menu.file.clear_recent": "Clear", "hex.builtin.menu.file.close": "Close", "hex.builtin.menu.file.create_file": "New File...", + "hex.builtin.menu.edit.disassemble_range": "Disassemble selection", "hex.builtin.menu.file.export": "Export...", "hex.builtin.menu.file.export.as_language": "Text Formatted Bytes", "hex.builtin.menu.file.export.as_language.popup.export_error": "Failed to export bytes to the file!", diff --git a/plugins/disassembler/source/content/views/view_disassembler.cpp b/plugins/disassembler/source/content/views/view_disassembler.cpp index 2727df2f1edae..978ccaf101b8e 100644 --- a/plugins/disassembler/source/content/views/view_disassembler.cpp +++ b/plugins/disassembler/source/content/views/view_disassembler.cpp @@ -1,4 +1,5 @@ #include "content/views/view_disassembler.hpp" +#include "hex/api/content_registry.hpp" #include #include @@ -16,6 +17,18 @@ namespace hex::plugin::disasm { EventProviderDeleted::subscribe(this, [this](const auto*) { m_disassembly.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] { + ImGui::SetWindowFocus(this->getName().c_str()); + this->getWindowOpenState() = true; + + m_range = ui::RegionType::Region; + m_codeRegion = ImHexApi::HexEditor::getSelection()->getRegion(); + + this->disassemble(); + }, [this]{ + return ImHexApi::HexEditor::isSelectionValid() && !this->m_disassemblerTask.isRunning(); + }); } ViewDisassembler::~ViewDisassembler() {