Skip to content

Commit

Permalink
feat: Added wide string to data inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Sep 28, 2022
1 parent 0552084 commit b450f47
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/external/pattern_language
42 changes: 41 additions & 1 deletion plugins/builtin/source/content/data_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/de_DE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/en_US.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/it_IT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/ja_JP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/ko_KR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/pt_BR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/zh_CN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/lang/zh_TW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down

0 comments on commit b450f47

Please sign in to comment.