From aac1a37a3ff3ed09e7c2eeaa0c7fc564dd26f3e8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 11 Oct 2021 20:59:14 +0200 Subject: [PATCH] patterns: Limit number of characters displayed in a string pattern --- .../hex/pattern_language/pattern_data.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index a7be3654c..a993c4b90 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -624,10 +624,12 @@ namespace hex::pl { } void createEntry(prv::Provider* &provider) override { - std::string buffer(this->getSize(), 0x00); - provider->read(this->getOffset(), buffer.data(), this->getSize()); + auto size = std::min(this->getSize(), 0x7F); + std::string buffer(size, 0x00); - this->createDefaultEntry(hex::format("\"{0}\"", makeDisplayable(buffer.data(), this->getSize()).c_str()), buffer); + provider->read(this->getOffset(), buffer.data(), size); + + this->createDefaultEntry(hex::format("\"{0}\" {1}", makeDisplayable(buffer.data(), this->getSize()), size > this->getSize() ? "(truncated)" : ""), buffer); } [[nodiscard]] std::string getFormattedName() const override { @@ -647,15 +649,17 @@ namespace hex::pl { } void createEntry(prv::Provider* &provider) override { - std::u16string buffer(this->getSize(), 0x00); - provider->read(this->getOffset(), buffer.data(), this->getSize()); + auto size = std::min(this->getSize(), 0x100); + + std::u16string buffer(size, 0x00); + provider->read(this->getOffset(), buffer.data(), size); for (auto &c : buffer) c = hex::changeEndianess(c, 2, this->getEndian()); auto utf8String = std::wstring_convert, char16_t>{}.to_bytes(buffer); - this->createDefaultEntry(hex::format("\"{0}\"", utf8String), utf8String); + this->createDefaultEntry(hex::format("\"{0}\" {1}", utf8String, size > this->getSize() ? "(truncated)" : ""), utf8String); } [[nodiscard]] std::string getFormattedName() const override {