From 803fa0cba9416a73425bc44cc886a1826ca06d70 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Wed, 28 Aug 2019 09:20:10 +0300 Subject: [PATCH] [Kernel] Fix TranslateUnicodeString endian and size --- src/xenia/kernel/util/shim_utils.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/xenia/kernel/util/shim_utils.h b/src/xenia/kernel/util/shim_utils.h index f4bf06a5f..60e7525c5 100644 --- a/src/xenia/kernel/util/shim_utils.h +++ b/src/xenia/kernel/util/shim_utils.h @@ -103,12 +103,22 @@ inline std::string TranslateAnsiStringAddress(const Memory* memory, inline std::wstring TranslateUnicodeString( const Memory* memory, const X_UNICODE_STRING* unicode_string) { - if (!unicode_string || !unicode_string->length) { + if (!unicode_string) { return L""; } - return std::wstring( - memory->TranslateVirtual(unicode_string->pointer), - unicode_string->length); + uint16_t length = unicode_string->length; + if (!length) { + return L""; + } + const xe::be* guest_string = + memory->TranslateVirtual*>( + unicode_string->pointer); + std::wstring translated_string; + translated_string.reserve(length); + for (uint16_t i = 0; i < length; ++i) { + translated_string += wchar_t(uint16_t(guest_string[i])); + } + return translated_string; } } // namespace util