diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index 0cc96fb6f..df44d6cfb 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -2,11 +2,15 @@ #include #include +#include +#include #include #include #include #include +#include +#include #include @@ -127,6 +131,27 @@ namespace hex::plugin::builtin { return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; }); + ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 0, [](auto buffer, auto endian, auto style) { + Region currSelection = { 0 }; + EventManager::post(currSelection); + + constexpr static auto MaxStringLength = 32; + + std::string stringBuffer(std::min(MaxStringLength, currSelection.size), 0x00); + SharedData::currentProvider->read(currSelection.address, stringBuffer.data(), stringBuffer.size()); + if (currSelection.size > MaxStringLength) + stringBuffer += "..."; + + for (auto &c : stringBuffer) + if (c < 0x20 || c == '\n' || c == '\r') + c = ' '; + + + auto value = hex::format("\"{0}\"", stringBuffer); + + return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; + }); + #if defined(OS_WINDOWS) && defined(ARCH_64_BIT) ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(__time32_t), [](auto buffer, auto endian, auto style) { diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 2ed45ded5..6d9a9b531 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -319,6 +319,7 @@ namespace hex::plugin::builtin { { "hex.builtin.inspector.ascii", "ASCII Zeichen" }, { "hex.builtin.inspector.wide", "Wide Zeichen" }, { "hex.builtin.inspector.utf8", "UTF-8 code point" }, + { "hex.builtin.inspector.string", "String" }, { "hex.builtin.inspector.time32", "__time32_t" }, { "hex.builtin.inspector.time64", "__time64_t" }, { "hex.builtin.inspector.time", "time_t" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 3ce90c7f4..5d871a4ff 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -319,6 +319,7 @@ namespace hex::plugin::builtin { { "hex.builtin.inspector.ascii", "ASCII Character" }, { "hex.builtin.inspector.wide", "Wide Character" }, { "hex.builtin.inspector.utf8", "UTF-8 code point" }, + { "hex.builtin.inspector.string", "String" }, { "hex.builtin.inspector.time32", "__time32_t" }, { "hex.builtin.inspector.time64", "__time64_t" }, { "hex.builtin.inspector.time", "time_t" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index ee9d6e6da..73e4017bb 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -318,6 +318,7 @@ namespace hex::plugin::builtin { { "hex.builtin.inspector.ascii", "ASCII Character" }, { "hex.builtin.inspector.wide", "Wide Character" }, { "hex.builtin.inspector.utf8", "UTF-8 code point" }, + { "hex.builtin.inspector.string", "String" }, { "hex.builtin.inspector.time32", "__time32_t" }, { "hex.builtin.inspector.time64", "__time64_t" }, { "hex.builtin.inspector.time", "time_t" }, diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index ea12a583d..7aadbe77a 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -208,7 +208,10 @@ namespace hex { }); EventManager::subscribe(this, [this](auto ®ion) { - region = Region { this->m_memoryEditor.DataPreviewAddr, (this->m_memoryEditor.DataPreviewAddrEnd - this->m_memoryEditor.DataPreviewAddr) + 1 }; + u64 address = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + size_t size = std::abs(s64(this->m_memoryEditor.DataPreviewAddrEnd) - s64(this->m_memoryEditor.DataPreviewAddr)) + 1; + + region = Region { address, size }; }); }