From cffd55bdda0b14407a139a86a690447e57c22c28 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 31 Mar 2023 22:20:00 +0200 Subject: [PATCH] fix: UTF-16BE search being broken --- plugins/builtin/source/content/views/view_find.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 0b9473d95..07753fd67 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -269,11 +269,11 @@ namespace hex::plugin::builtin { if (settings.type == UTF16LE) { // Check if second byte of UTF-16 encoded string is 0x00 if (countedCharacters % 2 == 1) - validChar = byte == 0x00; + validChar = byte == 0x00; } else if (settings.type == UTF16BE) { // Check if first byte of UTF-16 encoded string is 0x00 if (countedCharacters % 2 == 0) - validChar = byte == 0x00; + validChar = byte == 0x00; } task.update(progress); @@ -520,9 +520,6 @@ namespace hex::plugin::builtin { std::vector bytes(std::min(occurrence.region.getSize(), 128)); provider->read(occurrence.region.getStartAddress(), bytes.data(), bytes.size()); - if (occurrence.endian != std::endian::native) - std::reverse(bytes.begin(), bytes.end()); - std::string result; switch (this->m_decodeSettings.mode) { using enum SearchSettings::Mode; @@ -537,7 +534,7 @@ namespace hex::plugin::builtin { result = hex::encodeByteString(bytes); break; case UTF16: - for (size_t i = 0; i < bytes.size(); i += 2) + for (size_t i = occurrence.endian == std::endian::little ? 0 : 1; i < bytes.size(); i += 2) result += hex::encodeByteString({ bytes[i] }); break; case Unsigned: