https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0aa9d9fdb711702e4fb1099764b37357fc026a12

commit 0aa9d9fdb711702e4fb1099764b37357fc026a12
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Sun Aug 28 09:08:12 2022 +0900
Commit:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
CommitDate: Sun Aug 28 09:08:12 2022 +0900

    [USER32] Fix HKL keyboard list values (Retrial)
    
    CORE-18338
---
 win32ss/user/ntuser/kbdlayout.c     |  2 ++
 win32ss/user/user32/windows/input.c | 32 +++++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/win32ss/user/ntuser/kbdlayout.c b/win32ss/user/ntuser/kbdlayout.c
index 6a742b27377..83d89d9632a 100644
--- a/win32ss/user/ntuser/kbdlayout.c
+++ b/win32ss/user/ntuser/kbdlayout.c
@@ -999,6 +999,8 @@ cleanup:
  * NtUserLoadKeyboardLayoutEx
  *
  * Loads keyboard layout with given locale id
+ *
+ * NOTE: We adopt a different design from Microsoft's one for security reason.
  */
 HKL
 APIENTRY
diff --git a/win32ss/user/user32/windows/input.c 
b/win32ss/user/user32/windows/input.c
index 8d4d3ad8732..cad4930de28 100644
--- a/win32ss/user/user32/windows/input.c
+++ b/win32ss/user/user32/windows/input.c
@@ -640,6 +640,8 @@ LoadKeyboardLayoutA(LPCSTR pszKLID,
 
 /*
  * @unimplemented
+ *
+ * NOTE: We adopt a different design from Microsoft's one for security reason.
  */
 /* Win: LoadKeyboardLayoutWorker */
 HKL APIENTRY
@@ -654,12 +656,27 @@ IntLoadKeyboardLayout(
     UNICODE_STRING ustrKbdName;
     UNICODE_STRING ustrKLID;
     WCHAR wszRegKey[256] = L"SYSTEM\\CurrentControlSet\\Control\\Keyboard 
Layouts\\";
-    WCHAR wszLayoutId[10], wszNewKLID[10];
+    WCHAR wszLayoutId[10], wszNewKLID[10], szImeFileName[80];
     HKEY hKey;
     HKL hNewKL;
+    BOOL bIsIME;
 
-    /* LOWORD of dwhkl is Locale Identifier */
-    dwhkl = LOWORD(wcstoul(pwszKLID, NULL, 16));
+    dwhkl = wcstoul(pwszKLID, NULL, 16);
+    bIsIME = IS_IME_HKL(UlongToHandle(dwhkl));
+    if (bIsIME) /* IME? */
+    {
+        /* Check "IME File" value */
+        dwSize = sizeof(szImeFileName);
+        if (RegQueryValueExW(hKey, L"IME File", NULL, &dwType, 
(LPBYTE)szImeFileName,
+                             &dwSize) != ERROR_SUCCESS)
+        {
+            dwhkl = LOWORD(dwhkl);
+        }
+    }
+    else
+    {
+        dwhkl = LOWORD(dwhkl); /* LOWORD of dwhkl is language identifier */
+    }
 
     if (Flags & KLF_SUBSTITUTE_OK)
     {
@@ -692,10 +709,9 @@ IntLoadKeyboardLayout(
             /* If Layout Id is specified, use this value | f000 as HIWORD */
             /* FIXME: Microsoft Office expects this value to be something 
specific
              * for Japanese and Korean Windows with an IME the value is 0xe001
-             * We should probably check to see if an IME exists and if so then
-             * set this word properly.
              */
-            dwhkl |= (0xf000 | wcstol(wszLayoutId, NULL, 16)) << 16;
+            if (!bIsIME)
+                dwhkl |= (0xf000 | wcstol(wszLayoutId, NULL, 16)) << 16;
         }
 
         /* Close the key now */
@@ -713,9 +729,7 @@ IntLoadKeyboardLayout(
 
     ZeroMemory(&ustrKbdName, sizeof(ustrKbdName));
     RtlInitUnicodeString(&ustrKLID, pwszKLID);
-    hNewKL = NtUserLoadKeyboardLayoutEx(NULL, 0, &ustrKbdName,
-                                        NULL, &ustrKLID,
-                                        dwhkl, Flags);
+    hNewKL = NtUserLoadKeyboardLayoutEx(NULL, 0, &ustrKbdName, NULL, 
&ustrKLID, dwhkl, Flags);
     CliImmInitializeHotKeys(SETIMEHOTKEY_ADD, hNewKL);
     return hNewKL;
 }

Reply via email to