From ed025a7a5e4fd615b937ec3db6bf553a6e39303e Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:19:38 +0000 Subject: [PATCH] Unicode fixes & sizeof asserts. --- UnleashedRecomp/kernel/imports.cpp | 27 ++++++++------------------- UnleashedRecomp/kernel/xdm.h | 6 ++++++ UnleashedRecomp/stdafx.h | 1 - 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/UnleashedRecomp/kernel/imports.cpp b/UnleashedRecomp/kernel/imports.cpp index d810721a..552bdc3d 100644 --- a/UnleashedRecomp/kernel/imports.cpp +++ b/UnleashedRecomp/kernel/imports.cpp @@ -520,9 +520,9 @@ void XexGetModuleSection() LOG_UTILITY("!!! STUB !!!"); } -uint32_t RtlUnicodeToMultiByteN(char* MultiByteString, uint32_t MaxBytesInMultiByteString, be* BytesInMultiByteString, const wchar_t* UnicodeString, uint32_t BytesInUnicodeString) +uint32_t RtlUnicodeToMultiByteN(char* MultiByteString, uint32_t MaxBytesInMultiByteString, be* BytesInMultiByteString, const be* UnicodeString, uint32_t BytesInUnicodeString) { - const auto reqSize = BytesInUnicodeString / sizeof(wchar_t); + const auto reqSize = BytesInUnicodeString / sizeof(uint16_t); if (BytesInMultiByteString) *BytesInMultiByteString = reqSize; @@ -532,7 +532,7 @@ uint32_t RtlUnicodeToMultiByteN(char* MultiByteString, uint32_t MaxBytesInMultiB for (size_t i = 0; i < reqSize; i++) { - const auto c = ByteSwap(UnicodeString[i]); + const auto c = UnicodeString[i].get(); MultiByteString[i] = c < 256 ? c : '?'; } @@ -1254,26 +1254,15 @@ void NtQueryFullAttributesFile() LOG_UTILITY("!!! STUB !!!"); } -uint32_t RtlMultiByteToUnicodeN(wchar_t* UnicodeString, uint32_t MaxBytesInUnicodeString, be* BytesInUnicodeString, const char* MultiByteString, uint32_t BytesInMultiByteString) +uint32_t RtlMultiByteToUnicodeN(be* UnicodeString, uint32_t MaxBytesInUnicodeString, be* BytesInUnicodeString, const char* MultiByteString, uint32_t BytesInMultiByteString) { - std::wstring_convert> converter; + uint32_t length = std::min(MaxBytesInUnicodeString / 2, BytesInMultiByteString); - std::wstring wideString = converter.from_bytes( - MultiByteString, MultiByteString + (BytesInMultiByteString - 1) - ); - - uint32_t bytesRequired = static_cast((wideString.size() + 1) * sizeof(wchar_t)); - - uint32_t bytesToCopy = (bytesRequired > MaxBytesInUnicodeString) - ? MaxBytesInUnicodeString - : bytesRequired; - - memcpy(UnicodeString, wideString.data(), bytesToCopy); - for (size_t i = 0; i < bytesToCopy / 2; i++) - UnicodeString[i] = ByteSwap(UnicodeString[i]); + for (size_t i = 0; i < length; i++) + UnicodeString[i] = MultiByteString[i]; if (BytesInUnicodeString != nullptr) - *BytesInUnicodeString = bytesToCopy; + *BytesInUnicodeString = length * 2; return STATUS_SUCCESS; } diff --git a/UnleashedRecomp/kernel/xdm.h b/UnleashedRecomp/kernel/xdm.h index 1b55d787..5569952e 100644 --- a/UnleashedRecomp/kernel/xdm.h +++ b/UnleashedRecomp/kernel/xdm.h @@ -53,12 +53,16 @@ typedef union _LARGE_INTEGER { int64_t QuadPart; } LARGE_INTEGER; +static_assert(sizeof(LARGE_INTEGER) == 8); + typedef struct _FILETIME { uint32_t dwLowDateTime; uint32_t dwHighDateTime; } FILETIME; +static_assert(sizeof(FILETIME) == 8); + typedef struct _WIN32_FIND_DATAA { uint32_t dwFileAttributes; @@ -73,6 +77,8 @@ typedef struct _WIN32_FIND_DATAA char cAlternateFileName[14]; } WIN32_FIND_DATAA; +static_assert(sizeof(WIN32_FIND_DATAA) == 320); + #endif struct KernelObject diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 28096160..a0b541ca 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -46,7 +46,6 @@ using Microsoft::WRL::ComPtr; #include #include #include -#include #include #include "framework.h"