From ebf0c66d23d9c80b877c23c46ca41bb7847330d5 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Sun, 28 Apr 2024 21:38:33 +0100 Subject: [PATCH] Show extended scan preview for strings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Scan preview for strings will be unbounded; their length will be determined solely by the null character. Bonus: Non-printable characters in scanned or watched strings will be replaced with the � character (the unrepresentable character). Fixes #79. --- Source/Common/MemoryCommon.cpp | 19 +++++++++++++++---- Source/MemoryScanner/MemoryScanner.cpp | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/Common/MemoryCommon.cpp b/Source/Common/MemoryCommon.cpp index 7e40ff04..321ef3ca 100644 --- a/Source/Common/MemoryCommon.cpp +++ b/Source/Common/MemoryCommon.cpp @@ -1,6 +1,7 @@ #include "MemoryCommon.h" #include +#include #include #include #include @@ -624,13 +625,23 @@ std::string formatMemoryToString(const char* memory, const MemType type, const s } case Common::MemType::type_string: { - int actualLength = 0; - for (actualLength; actualLength < length; ++actualLength) + std::string text; + for (std::string::size_type i{0}; i < length; ++i) { - if (*(memory + actualLength) == 0x00) + const char c{memory[i]}; + if (c == '\0') break; + + if (std::isprint(c)) + { + text.push_back(c); + } + else + { + text += "�"; + } } - return std::string(memory, actualLength); + return text; } case Common::MemType::type_byteArray: { diff --git a/Source/MemoryScanner/MemoryScanner.cpp b/Source/MemoryScanner/MemoryScanner.cpp index c7816ca2..c3f7f45c 100644 --- a/Source/MemoryScanner/MemoryScanner.cpp +++ b/Source/MemoryScanner/MemoryScanner.cpp @@ -501,7 +501,8 @@ std::string MemScanner::getFormattedScannedValueAt(const int index) const bool aramAccessible = DolphinComm::DolphinAccessor::isARAMAccessible(); u32 offset = Common::dolphinAddrToOffset(m_resultsConsoleAddr.at(index), aramAccessible); u32 ramIndex = Common::offsetToCacheIndex(offset, aramAccessible); - return Common::formatMemoryToString(&m_scanRAMCache[ramIndex], m_memType, m_memSize, m_memBase, + const size_t length{m_memType == Common::MemType::type_string ? ~0ULL : m_memSize}; + return Common::formatMemoryToString(&m_scanRAMCache[ramIndex], m_memType, length, m_memBase, !m_memIsSigned, Common::shouldBeBSwappedForType(m_memType)); }