1
0
mirror of synced 2024-11-12 02:00:52 +01:00

feat: Added wide string to data inspector

This commit is contained in:
WerWolv 2022-09-28 16:10:40 +02:00
parent 0552084673
commit b450f4797e
10 changed files with 50 additions and 2 deletions

@ -1 +1 @@
Subproject commit df5f35b49d99ab91786edeb04c077d88e057c1ba
Subproject commit 65fca44f38f61bbaafd6241ac6f17b8f0c1b7369

View File

@ -396,13 +396,14 @@ namespace hex::plugin::builtin {
}
);
constexpr static auto MaxStringLength = 32;
ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1,
[](auto buffer, auto endian, auto style) {
hex::unused(buffer, endian, style);
auto currSelection = ImHexApi::HexEditor::getSelection();
constexpr static auto MaxStringLength = 32;
std::string value, copyValue;
@ -430,6 +431,45 @@ namespace hex::plugin::builtin {
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.string16", 2,
[](auto buffer, auto endian, auto style) {
hex::unused(buffer, endian, style);
auto currSelection = ImHexApi::HexEditor::getSelection();
std::string value, copyValue;
if (currSelection.has_value()) {
std::u16string stringBuffer(std::min<size_t>(currSelection->size, 0x1000), 0x00);
ImHexApi::Provider::get()->read(currSelection->address, stringBuffer.data(), stringBuffer.size());
for (auto &c : stringBuffer)
c = hex::changeEndianess(c, endian);
auto it = std::remove_if(buffer.begin(), buffer.end(),
[](auto c) { return c == 0x00; });
buffer.erase(it, buffer.end());
value = copyValue = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>("Invalid").to_bytes(stringBuffer.data());
if (value.size() > MaxStringLength) {
value.resize(MaxStringLength);
value += "...";
}
} else {
value = "";
copyValue = "";
}
return [value, copyValue] { ImGui::TextFormatted("L\"{0}\"", value.c_str()); return copyValue; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
return hex::decodeByteString(value);
}
);
#if defined(OS_WINDOWS) && defined(ARCH_64_BIT)
ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(u32), [](auto buffer, auto endian, auto style) {

View File

@ -495,6 +495,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Zeichen" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -501,6 +501,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -500,6 +500,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -503,6 +503,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -500,6 +500,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -498,6 +498,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "String" },
{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -501,6 +501,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "宽字符" },
{ "hex.builtin.inspector.utf8", "UTF-8 码位" },
{ "hex.builtin.inspector.string", "字符串" },
//{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },

View File

@ -499,6 +499,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.wide", "框字元" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
{ "hex.builtin.inspector.string", "字串" },
//{ "hex.builtin.inspector.string16", "Wide String" },
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },