[Kernel] Fix TranslateUnicodeString endian and size

This commit is contained in:
Triang3l 2019-08-28 09:20:10 +03:00
parent 0ad1bd9ab4
commit 803fa0cba9
1 changed files with 14 additions and 4 deletions

View File

@ -103,12 +103,22 @@ inline std::string TranslateAnsiStringAddress(const Memory* memory,
inline std::wstring TranslateUnicodeString( inline std::wstring TranslateUnicodeString(
const Memory* memory, const X_UNICODE_STRING* unicode_string) { const Memory* memory, const X_UNICODE_STRING* unicode_string) {
if (!unicode_string || !unicode_string->length) { if (!unicode_string) {
return L""; return L"";
} }
return std::wstring( uint16_t length = unicode_string->length;
memory->TranslateVirtual<const wchar_t*>(unicode_string->pointer), if (!length) {
unicode_string->length); return L"";
}
const xe::be<uint16_t>* guest_string =
memory->TranslateVirtual<const xe::be<uint16_t>*>(
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 } // namespace util