diff --git a/plugins/builtin/include/content/providers/view_provider.hpp b/plugins/builtin/include/content/providers/view_provider.hpp new file mode 100644 index 000000000..3a6b194e4 --- /dev/null +++ b/plugins/builtin/include/content/providers/view_provider.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +namespace hex::plugin::builtin { + + class ViewProvider : public hex::prv::Provider { + public: + explicit ViewProvider() = default; + ~ViewProvider() override = default; + + [[nodiscard]] bool isAvailable() const override { return this->m_provider != nullptr; } + [[nodiscard]] bool isReadable() const override { return this->m_provider->isReadable(); } + [[nodiscard]] bool isWritable() const override { return this->m_provider->isWritable(); } + [[nodiscard]] bool isResizable() const override { return true; } + [[nodiscard]] bool isSavable() const override { return true; } + + void save() override { + this->m_provider->save(); + } + + [[nodiscard]] bool open() override { return true; } + void close() override { } + + void resize(size_t newSize) override { + this->m_size = newSize; + } + void insert(u64 offset, size_t size) override { + this->m_size += size; + this->m_provider->insert(offset + this->m_startAddress, size); + } + + void remove(u64 offset, size_t size) override { + this->m_size -= size; + this->m_provider->remove(offset + this->m_startAddress, size); + } + + void readRaw(u64 offset, void *buffer, size_t size) override { this->m_provider->read(offset + this->m_startAddress, buffer, size); } + void writeRaw(u64 offset, const void *buffer, size_t size) override { this->m_provider->write(offset + this->m_startAddress, buffer, size); } + [[nodiscard]] size_t getActualSize() const override { return this->m_size; } + + [[nodiscard]] std::string getName() const override { return hex::format("{} View", this->m_provider->getName()); } + [[nodiscard]] std::vector> getDataInformation() const override { return this->m_provider->getDataInformation(); } + + void loadSettings(const nlohmann::json &settings) override { hex::unused(settings); } + [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; } + + [[nodiscard]] std::string getTypeName() const override { + return "hex.builtin.provider.view"; + } + + void setProvider(u64 startAddress, size_t size, hex::prv::Provider *provider) { + this->m_startAddress = startAddress; + this->m_size = size; + this->m_provider = provider; + } + + [[nodiscard]] std::pair getRegionValidity(u64 address) const override { + address -= this->getBaseAddress(); + + if (address < this->getActualSize()) + return { Region { this->getBaseAddress() + address, this->getActualSize() - address }, true }; + else + return { Region::Invalid(), false }; + } + + private: + u64 m_startAddress = 0x00; + size_t m_size = 0x00; + prv::Provider *m_provider = nullptr; + }; + +} \ No newline at end of file diff --git a/plugins/builtin/source/content/providers.cpp b/plugins/builtin/source/content/providers.cpp index dafd03aaa..33f8704cc 100644 --- a/plugins/builtin/source/content/providers.cpp +++ b/plugins/builtin/source/content/providers.cpp @@ -7,6 +7,7 @@ #include "content/providers/intel_hex_provider.hpp" #include "content/providers/motorola_srec_provider.hpp" #include "content/providers/memory_file_provider.hpp" +#include "content/providers/view_provider.hpp" #include #include @@ -23,6 +24,7 @@ namespace hex::plugin::builtin { ContentRegistry::Provider::add(); ContentRegistry::Provider::add(); ContentRegistry::Provider::add(false); + ContentRegistry::Provider::add(false); ProjectFile::registerHandler({ .basePath = "providers", diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 0f9855fc3..1b757b35f 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -1034,6 +1035,15 @@ namespace hex::plugin::builtin { } } + + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.open_in_new_provider"_lang, nullptr, false, providerValid && provider->isResizable() && selection.has_value())) { + auto newProvider = ImHexApi::Provider::createProvider("hex.builtin.provider.view", true); + if (auto *viewProvider = dynamic_cast(newProvider); viewProvider != nullptr) { + viewProvider->setProvider(selection->getStartAddress(), selection->getSize(), selection->getProvider()); + if (viewProvider->open()) + EventManager::post(viewProvider); + } + } }); } diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index f2f4396b5..a8a24b6cd 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -355,6 +355,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "Einsetzen..." }, { "hex.builtin.view.hex_editor.menu.edit.remove", "Entfernen..." }, { "hex.builtin.view.hex_editor.menu.edit.jump_to", "Springen" }, + { "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Auswahlansicht öffnen..." }, { "hex.builtin.view.information.name", "Dateninformationen" }, { "hex.builtin.view.information.control", "Einstellungen" }, @@ -857,6 +858,7 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, { "hex.builtin.provider.mem_file", "RAM Datei" }, { "hex.builtin.provider.mem_file.unsaved", "Ungespeicherte Datei" }, + { "hex.builtin.provider.view", "Ansicht" }, { "hex.builtin.layouts.default", "Standard" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 584daeef4..2b26d69a0 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -45,7 +45,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, { "hex.builtin.welcome.tip_of_the_day", "Tip of the Day" }, - { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Restore lost data" }, @@ -358,6 +358,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "Insert..." }, { "hex.builtin.view.hex_editor.menu.edit.remove", "Remove..." }, { "hex.builtin.view.hex_editor.menu.edit.jump_to", "Jump to" }, + { "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "Data Information" }, { "hex.builtin.view.information.control", "Control" }, @@ -862,6 +863,7 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, { "hex.builtin.provider.mem_file", "Memory File" }, { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + { "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "Default" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 7a45b975d..94bd93c37 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Varie" }, { "hex.builtin.welcome.tip_of_the_day", "Consiglio del giorno" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Ripristina i dati persi" }, @@ -359,6 +359,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "Inserisci..." }, //{ "hex.builtin.view.hex_editor.menu.edit.remove", "Remove..." }, //{ "hex.builtin.view.hex_editor.menu.edit.jump_to", "Jump to" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "Informazione sui Dati" }, { "hex.builtin.view.information.control", "Controllo" }, @@ -865,6 +866,7 @@ namespace hex::plugin::builtin { // { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "Default" }, diff --git a/plugins/builtin/source/lang/ja_JP.cpp b/plugins/builtin/source/lang/ja_JP.cpp index ba600f9a1..1bfbdcc98 100644 --- a/plugins/builtin/source/lang/ja_JP.cpp +++ b/plugins/builtin/source/lang/ja_JP.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, //? { "hex.builtin.welcome.tip_of_the_day", "今日の豆知識" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "セッションの回復" }, @@ -360,6 +360,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "挿入…" }, //{ "hex.builtin.view.hex_editor.menu.edit.remove", "Remove..." }, //{ "hex.builtin.view.hex_editor.menu.edit.jump_to", "Jump to" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "データ解析" }, { "hex.builtin.view.information.control", "コントロール" }, @@ -864,6 +865,7 @@ namespace hex::plugin::builtin { // { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "標準" }, diff --git a/plugins/builtin/source/lang/ko_KR.cpp b/plugins/builtin/source/lang/ko_KR.cpp index 97ee20fad..3f03f6252 100644 --- a/plugins/builtin/source/lang/ko_KR.cpp +++ b/plugins/builtin/source/lang/ko_KR.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Various" }, { "hex.builtin.welcome.tip_of_the_day", "오늘의 팁" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "손상된 데이터 복구" }, @@ -357,6 +357,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "삽입..." }, { "hex.builtin.view.hex_editor.menu.edit.remove", "삭제..." }, //{ "hex.builtin.view.hex_editor.menu.edit.jump_to", "Jump to" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "데이터 정보" }, { "hex.builtin.view.information.control", "컨트롤" }, @@ -861,6 +862,7 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "기본 값" }, diff --git a/plugins/builtin/source/lang/pt_BR.cpp b/plugins/builtin/source/lang/pt_BR.cpp index 549ac9f74..43bce37ab 100644 --- a/plugins/builtin/source/lang/pt_BR.cpp +++ b/plugins/builtin/source/lang/pt_BR.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "Vários" }, { "hex.builtin.welcome.tip_of_the_day", "Dica do Dia" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "Restaurar dados perdidos" }, @@ -357,6 +357,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "Inserir..." }, //{ "hex.builtin.view.hex_editor.menu.edit.remove", "Remove..." }, //{ "hex.builtin.view.hex_editor.menu.edit.jump_to", "Jump to" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "Data Information" }, { "hex.builtin.view.information.control", "Controle" }, @@ -860,6 +861,7 @@ namespace hex::plugin::builtin { // { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "Default" }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index 2b23462b6..c187bb266 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "杂项" }, { "hex.builtin.welcome.tip_of_the_day", "每日提示" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "恢复崩溃数据" }, @@ -360,6 +360,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "插入..." }, { "hex.builtin.view.hex_editor.menu.edit.remove", "删除..." }, { "hex.builtin.view.hex_editor.menu.edit.jump_to", "转到" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "数据信息" }, { "hex.builtin.view.information.control", "控制" }, @@ -862,6 +863,7 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "默认" }, diff --git a/plugins/builtin/source/lang/zh_TW.cpp b/plugins/builtin/source/lang/zh_TW.cpp index dca4ab900..6c5fc2087 100644 --- a/plugins/builtin/source/lang/zh_TW.cpp +++ b/plugins/builtin/source/lang/zh_TW.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { { "hex.builtin.welcome.learn.plugins.link", "https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide" }, { "hex.builtin.welcome.header.various", "多樣" }, { "hex.builtin.welcome.tip_of_the_day", "今日提示" }, - // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup ?\n" + // { "hex.builtin.welcome.check_for_updates_text", "Do you want to automatically check for updates on startup?\n" // "Possible updates will be shown in the 'Update' tab of the welcome screen" }, { "hex.builtin.welcome.safety_backup.title", "復原遺失資料" }, @@ -357,6 +357,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.menu.edit.insert", "插入..." }, { "hex.builtin.view.hex_editor.menu.edit.remove", "移除..." }, { "hex.builtin.view.hex_editor.menu.edit.jump_to", "跳至" }, + //{ "hex.builtin.view.hex_editor.menu.edit.open_in_new_provider", "Open selection view..." }, { "hex.builtin.view.information.name", "資料資訊" }, { "hex.builtin.view.information.control", "控制" }, @@ -860,6 +861,7 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.motorola_srec.name", "Motorola SREC {0}" }, //{ "hex.builtin.provider.mem_file", "Memory File" }, // { "hex.builtin.provider.mem_file.unsaved", "Unsaved File" }, + //{ "hex.builtin.provider.view", "View" }, { "hex.builtin.layouts.default", "預設" },