1
0
mirror of synced 2024-11-24 15:50:16 +01:00

ui: Added strings to data inspector

This commit is contained in:
WerWolv 2021-09-01 02:01:50 +02:00
parent 82cb7917e4
commit 19c367b540
5 changed files with 32 additions and 1 deletions

View File

@ -2,11 +2,15 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/shared_data.hpp>
#include <hex/api/event.hpp>
#include <cstring>
#include <ctime>
#include <codecvt>
#include <locale>
#include <string>
#include <vector>
#include <imgui_internal.h>
@ -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<QuerySelection>(currSelection);
constexpr static auto MaxStringLength = 32;
std::string stringBuffer(std::min<ssize_t>(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) {

View File

@ -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" },

View File

@ -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" },

View File

@ -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" },

View File

@ -208,7 +208,10 @@ namespace hex {
});
EventManager::subscribe<QuerySelection>(this, [this](auto &region) {
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 };
});
}