ReactOS 0.4.17-dev-1421-g4623072
kbdlayout.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Win32k subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/user/ntuser/kbdlayout.c
5 * PURPOSE: Keyboard layout management
6 * COPYRIGHT: Copyright 2007 Saveliy Tretiakov
7 * Copyright 2008 Colin Finck
8 * Copyright 2011 Rafal Harabien
9 * Copyright 2022-2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
10 */
11
12#include <win32k.h>
13#include <immdev.h>
14
15// Was included only because of CP_ACP and required the
16// definition of SYSTEMTIME in ndk\rtltypes.h
17//#include <winnls.h>
18#define CP_ACP 0
19
20DBG_DEFAULT_CHANNEL(UserKbdLayout);
21
22PKL gspklBaseLayout = NULL; /* FIXME: Please move this to pWinSta->spklList */
27
28/* PRIVATE FUNCTIONS ******************************************************/
29
30/*
31 * Retrieves a PKL by an input locale identifier (HKL).
32 * @implemented
33 */
35{
36 PKL pFirstKL, pKL;
37
38 pFirstKL = pti->KeyboardLayout;
39 if (!pFirstKL)
40 return NULL;
41
42 pKL = pFirstKL;
43
44 /* hKL can have special value HKL_NEXT or HKL_PREV */
45 if (hKL == UlongToHandle(HKL_NEXT)) /* Looking forward */
46 {
47 do
48 {
49 pKL = pKL->pklNext;
50 if (!(pKL->dwKL_Flags & KL_UNLOAD))
51 return pKL;
52 } while (pKL != pFirstKL);
53 }
54 else if (hKL == UlongToHandle(HKL_PREV)) /* Looking backward */
55 {
56 do
57 {
58 pKL = pKL->pklPrev;
59 if (!(pKL->dwKL_Flags & KL_UNLOAD))
60 return pKL;
61 } while (pKL != pFirstKL);
62 }
63 else if (HIWORD(hKL)) /* hKL is a full input locale identifier */
64 {
65 /* No KL_UNLOAD check */
66 do
67 {
68 if (pKL->hkl == hKL)
69 return pKL;
70
71 pKL = pKL->pklNext;
72 } while (pKL != pFirstKL);
73 }
74 else /* Language only specified */
75 {
76 /* No KL_UNLOAD check */
77 do
78 {
79 if (LOWORD(pKL->hkl) == LOWORD(hKL)) /* Low word is language ID */
80 return pKL;
81
82 pKL = pKL->pklNext;
83 } while (pKL != pFirstKL);
84 }
85
86 return NULL;
87}
88
89/*
90 * A helper function for NtUserGetKeyboardLayoutList.
91 * @implemented
92 */
93static UINT APIENTRY
96 _In_ ULONG nBuff,
97 _Out_ HKL *pHklBuff)
98{
99 UINT ret = 0;
100 PKL pKL, pFirstKL;
101
102 pFirstKL = gspklBaseLayout; /* FIXME: Use pWinSta->spklList instead */
103 if (!pWinSta || !pFirstKL)
104 return 0;
105
106 pKL = pFirstKL;
107
108 if (nBuff == 0)
109 {
110 /* Count the effective PKLs */
111 do
112 {
113 if (!(pKL->dwKL_Flags & KL_UNLOAD))
114 ++ret;
115 pKL = pKL->pklNext;
116 } while (pKL != pFirstKL);
117 }
118 else
119 {
120 /* Copy the effective HKLs to pHklBuff */
121 do
122 {
123 if (!(pKL->dwKL_Flags & KL_UNLOAD))
124 {
125 *pHklBuff = pKL->hkl;
126 ++pHklBuff;
127 ++ret;
128 --nBuff;
129
130 if (nBuff == 0)
131 break;
132 }
133 pKL = pKL->pklNext;
134 } while (pKL != pFirstKL);
135 }
136
137 return ret;
138}
139
140#if 0 && DBG
141
142static VOID
143DumpKbdLayout(
144 IN PKBDTABLES pKbdTbl)
145{
146 PVK_TO_BIT pVkToBit;
147 PVK_TO_WCHAR_TABLE pVkToWchTbl;
148 PVSC_VK pVscVk;
149 ULONG i;
150
151 DbgPrint("Kbd layout: fLocaleFlags %x bMaxVSCtoVK %x\n",
152 pKbdTbl->fLocaleFlags, pKbdTbl->bMaxVSCtoVK);
153 DbgPrint("wMaxModBits %x\n",
154 pKbdTbl->pCharModifiers ? pKbdTbl->pCharModifiers->wMaxModBits
155 : 0);
156
157 if (pKbdTbl->pCharModifiers)
158 {
159 pVkToBit = pKbdTbl->pCharModifiers->pVkToBit;
160 if (pVkToBit)
161 {
162 for (; pVkToBit->Vk; ++pVkToBit)
163 {
164 DbgPrint("VkToBit %x -> %x\n", pVkToBit->Vk, pVkToBit->ModBits);
165 }
166 }
167
168 for (i = 0; i <= pKbdTbl->pCharModifiers->wMaxModBits; ++i)
169 {
170 DbgPrint("ModNumber %x -> %x\n", i, pKbdTbl->pCharModifiers->ModNumber[i]);
171 }
172 }
173
174 pVkToWchTbl = pKbdTbl->pVkToWcharTable;
175 if (pVkToWchTbl)
176 {
177 for (; pVkToWchTbl->pVkToWchars; ++pVkToWchTbl)
178 {
179 PVK_TO_WCHARS1 pVkToWch = pVkToWchTbl->pVkToWchars;
180
181 DbgPrint("pVkToWchTbl nModifications %x cbSize %x\n",
182 pVkToWchTbl->nModifications, pVkToWchTbl->cbSize);
183 if (pVkToWch)
184 {
185 while (pVkToWch->VirtualKey)
186 {
187 DbgPrint("pVkToWch VirtualKey %x Attributes %x wc { ",
188 pVkToWch->VirtualKey, pVkToWch->Attributes);
189 for (i = 0; i < pVkToWchTbl->nModifications; ++i)
190 {
191 DbgPrint("%x ", pVkToWch->wch[i]);
192 }
193 DbgPrint("}\n");
194 pVkToWch = (PVK_TO_WCHARS1)(((PBYTE)pVkToWch) + pVkToWchTbl->cbSize);
195 }
196 }
197 }
198 }
199
200// TODO: DeadKeys, KeyNames, KeyNamesExt, KeyNamesDead
201
202 DbgPrint("pusVSCtoVK: { ");
203 if (pKbdTbl->pusVSCtoVK)
204 {
205 for (i = 0; i < pKbdTbl->bMaxVSCtoVK; ++i)
206 {
207 DbgPrint("%x -> %x, ", i, pKbdTbl->pusVSCtoVK[i]);
208 }
209 }
210 DbgPrint("}\n");
211
212 DbgPrint("pVSCtoVK_E0: { ");
213 pVscVk = pKbdTbl->pVSCtoVK_E0;
214 if (pVscVk)
215 {
216 for (; pVscVk->Vsc; ++pVscVk)
217 {
218 DbgPrint("%x -> %x, ", pVscVk->Vsc, pVscVk->Vk);
219 }
220 }
221 DbgPrint("}\n");
222
223 DbgPrint("pVSCtoVK_E1: { ");
224 pVscVk = pKbdTbl->pVSCtoVK_E1;
225 if (pVscVk)
226 {
227 for (; pVscVk->Vsc; ++pVscVk)
228 {
229 DbgPrint("%x -> %x, ", pVscVk->Vsc, pVscVk->Vk);
230 }
231 }
232 DbgPrint("}\n");
233
234// TODO: Ligatures
235}
236
237#endif // DBG
238
239#define KBDIMG_TAG 'ibKU'
240#define KBDIMG_MAXSIZE (1 * 1024 * 1024)
241
242#ifndef RVA
243 #define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
244#endif
245
246/* Describes the .data section taken by KbdBuildImage. The buffer holds the .data section
247 * only, so the byte at offset 0 of the buffer is the byte at RVA offData of the file. */
248typedef struct _KBDIMAGE_INFO
249{
250 ULONG_PTR ImageBase; /* The base address the pointers in the layout tables are based on */
251 ULONG offData; /* RVA of the .data section in the file (not an offset in the buffer) */
252 ULONG cbData; /* Size of the .data section (= size of the buffer) */
254
270static PVOID
272 _In_ PVOID pvRaw,
273 _In_ SIZE_T cbRaw,
274 _Out_ PULONG pcbImage,
275 _Out_ PKBDIMAGE_INFO pInfo)
276{
277 static const UCHAR s_DataName[IMAGE_SIZEOF_SHORT_NAME] = ".data";
278 PIMAGE_DOS_HEADER pDos = pvRaw;
281 PBYTE pbRaw = pvRaw;
282 _SEH2_VOLATILE PBYTE pbImage = NULL;
283 ULONG cbImage, cbVirt, cbCopy, i;
284 SIZE_T offSec;
285 ULONG_PTR imageBase;
286
287 *pcbImage = 0;
288 RtlZeroMemory(pInfo, sizeof(*pInfo));
289
291 {
292 if (cbRaw < sizeof(IMAGE_DOS_HEADER) || pDos->e_magic != IMAGE_DOS_SIGNATURE ||
293 pDos->e_lfanew <= 0 || cbRaw < sizeof(IMAGE_NT_HEADERS) ||
294 (SIZE_T)pDos->e_lfanew > cbRaw - sizeof(IMAGE_NT_HEADERS) || (pDos->e_lfanew & 3))
295 {
296 _SEH2_YIELD(return NULL);
297 }
298
299 pNt = (PIMAGE_NT_HEADERS)(pbRaw + pDos->e_lfanew);
300 if (pNt->Signature != IMAGE_NT_SIGNATURE)
301 _SEH2_YIELD(return NULL);
302
303#ifdef _M_AMD64
306 {
307 imageBase = (ULONG_PTR)((PIMAGE_NT_HEADERS64)pNt)->OptionalHeader.ImageBase;
308 }
309#elif defined(_M_ARM64)
312 {
313 imageBase = (ULONG_PTR)((PIMAGE_NT_HEADERS64)pNt)->OptionalHeader.ImageBase;
314 }
315#elif defined(_M_ARM)
318 {
319 imageBase = ((PIMAGE_NT_HEADERS32)pNt)->OptionalHeader.ImageBase;
320 }
321#elif defined(_M_IX86)
324 {
325 imageBase = ((PIMAGE_NT_HEADERS32)pNt)->OptionalHeader.ImageBase;
326 }
327#else
328 #error Unsupported architecture.
329#endif
330 else
331 {
332 _SEH2_YIELD(return NULL);
333 }
334
335 cbImage = pNt->OptionalHeader.SizeOfImage;
336 if (!cbImage || cbImage > KBDIMG_MAXSIZE)
337 _SEH2_YIELD(return NULL);
338
339 /* Keep pSec aligned: IMAGE_FIRST_SECTION depends on SizeOfOptionalHeader */
340 if (pNt->FileHeader.SizeOfOptionalHeader & 3)
341 _SEH2_YIELD(return NULL);
342
343 /* The section headers must lie within the file (compare offsets, not pointers) */
344 pSec = IMAGE_FIRST_SECTION(pNt);
345 offSec = (SIZE_T)((PBYTE)pSec - pbRaw);
346 if (offSec > cbRaw ||
347 (cbRaw - offSec) / sizeof(IMAGE_SECTION_HEADER) < pNt->FileHeader.NumberOfSections)
348 {
349 _SEH2_YIELD(return NULL);
350 }
351
352 /* Find the .data section. Any other section is ignored. */
353 for (i = 0; i < pNt->FileHeader.NumberOfSections; ++i)
354 {
355 if (RtlEqualMemory(pSec[i].Name, s_DataName, sizeof(s_DataName)))
356 {
357 pData = &pSec[i];
358 break;
359 }
360 }
361 if (!pData)
362 {
363 ERR("No .data section\n");
364 _SEH2_YIELD(return NULL);
365 }
366
367 /* The part beyond SizeOfRawData (if any) is zero-filled, as the loader does */
368 cbVirt = pData->Misc.VirtualSize ? pData->Misc.VirtualSize : pData->SizeOfRawData;
369 cbCopy = min(pData->SizeOfRawData, cbVirt);
370 if (!cbVirt || pData->VirtualAddress > cbImage ||
371 cbVirt > cbImage - pData->VirtualAddress || pData->PointerToRawData > cbRaw ||
372 cbCopy > cbRaw - pData->PointerToRawData)
373 {
374 ERR("Invalid .data section\n");
375 _SEH2_YIELD(return NULL);
376 }
377
378 /* Retain the .data section only. The buffer starts at the beginning of .data,
379 * so an RVA must be converted to an offset by subtracting offData. */
380 pbImage = ExAllocatePoolZero(PagedPool, cbVirt, KBDIMG_TAG);
381 if (!pbImage)
382 _SEH2_YIELD(return NULL);
383 RtlCopyMemory(pbImage, pbRaw + pData->PointerToRawData, cbCopy);
384
385 pInfo->ImageBase = imageBase;
386 pInfo->offData = pData->VirtualAddress;
387 pInfo->cbData = cbVirt;
388 *pcbImage = cbVirt;
389 _SEH2_YIELD(return pbImage);
390 }
392 {
393 ERR("Exception in KbdBuildImage! Status: 0x%lx\n", _SEH2_GetExceptionCode());
394 }
395 _SEH2_END;
396
397 if (pbImage)
399 return NULL;
400}
401
402/* Loads the image of keyboard layout file. See also KbdUnloadImage below. */
403static PVOID
405 _In_ HANDLE hKernelFile,
406 _Out_ PULONG pcbImage,
407 _Out_ PKBDIMAGE_INFO pInfo)
408{
413 PVOID pvRaw, pvImage;
414 ULONG cbRaw;
415
416 *pcbImage = 0;
417 RtlZeroMemory(pInfo, sizeof(*pInfo));
418
419 if (!hKernelFile)
420 return NULL;
421
422 /* Get the file size */
423 Status = ZwQueryInformationFile(hKernelFile, &IoStatusBlock, &FileInfo,
425 if (!NT_SUCCESS(Status))
426 {
427 ERR("ZwQueryInformationFile failed: 0x%08X\n", Status);
428 return NULL;
429 }
430 if (FileInfo.EndOfFile.HighPart != 0 || FileInfo.EndOfFile.LowPart > KBDIMG_MAXSIZE)
431 {
432 ERR("Invalid file size (%I64u bytes)\n", FileInfo.EndOfFile.QuadPart);
433 return NULL;
434 }
435 cbRaw = FileInfo.EndOfFile.LowPart;
436 if (cbRaw < sizeof(IMAGE_DOS_HEADER)) /* Too small to be a PE file? */
437 {
438 ERR("Invalid file size (%lu bytes)\n", cbRaw);
439 return NULL;
440 }
441
442 /* Allocate raw image buffer */
444 if (!pvRaw)
445 return NULL;
446
447 /* Load the file content */
448 Offset.QuadPart = 0;
449 Status = ZwReadFile(hKernelFile, NULL, NULL, NULL, &IoStatusBlock,
450 pvRaw, cbRaw, &Offset, NULL);
451 if (!NT_SUCCESS(Status) || IoStatusBlock.Information != cbRaw)
452 {
453 ERR("ZwReadFile failed: 0x%08X (read %Iu of %lu)\n",
454 Status, IoStatusBlock.Information, cbRaw);
456 return NULL;
457 }
458
459 /* Take the .data section only (no relocation; see KbdRebaseTables) */
460 pvImage = KbdBuildImage(pvRaw, cbRaw, pcbImage, pInfo);
461 if (!pvImage)
462 ERR("KbdBuildImage failed\n");
463
465 return pvImage;
466}
467
468static __inline VOID
470 _In_opt_ PVOID pvImageBase)
471{
472 if (pvImageBase)
473 ExFreePoolWithTag(pvImageBase, KBDIMG_TAG);
474}
475
476/* Tells whether the RVA range [off, off + cb) lies within the .data section
477 * (without overflowing) */
478static __inline BOOL
480{
481 return (off >= pInfo->offData) && (cb <= pInfo->cbData) &&
482 ((off - pInfo->offData) <= (pInfo->cbData - cb));
483}
484
485/* Limits on the number of elements walked in each table. Tables and strings of a crafted layout
486 * may overlap each other, so these bound the work it can cause. They are far beyond what any
487 * real layout needs. */
488#define KBD_MAX_VKTOBIT 0x100
489#define KBD_MAX_WCHTABLES 0x20
490#define KBD_MAX_VKTOWCH 0x200
491#define KBD_MAX_KEYNAMES 0x200
492#define KBD_MAX_DEADNAMES 0x400
493#define KBD_MAX_DEADKEYS 0x10000
494#define KBD_MAX_VSCVK 0x100
495#define KBD_MAX_LIGATURES 0x10000
496#define KBD_MAX_NLS_ENTRIES 0x100
497#define KBD_MAX_NAME_CCH 128 /* including the terminating NUL */
498#define KBD_MAX_MOD_COLUMNS 10 /* the widest VK_TO_WCHARS<n> */
499#define KBD_MAX_LIGATURE_CCH 5 /* the widest LIGATURE<n> */
500
501/* The state of validation. All the checks are done on the copy in our buffer. */
502typedef struct _KBDVALIDATE
503{
504 PBYTE pbImage; /* The buffer (the .data section only) */
505 ULONG cbData; /* Size of the buffer */
506 ULONG_PTR ImageBase; /* The base address the pointers in the layout tables are based on */
507 ULONG offData; /* RVA of the .data section in the file */
508 PBYTE pbSlots; /* 1 bit per pointer-sized slot of the buffer that is already rebased */
510
511/* Tells whether [p, p + cb) lies within the buffer (without overflowing) and p is aligned */
512static BOOL
514 _In_ const KBDVALIDATE *pv,
515 _In_ const VOID *p,
516 _In_ SIZE_T cb,
517 _In_ SIZE_T cbAlign)
518{
519 ULONG_PTR off;
520
521 if ((ULONG_PTR)p < (ULONG_PTR)pv->pbImage)
522 return FALSE;
523
524 off = (ULONG_PTR)p - (ULONG_PTR)pv->pbImage;
525 if ((off & (cbAlign - 1)) || cb > pv->cbData || off > pv->cbData - cb)
526 return FALSE;
527
528 return TRUE;
529}
530
546static BOOL
549 _Inout_ PVOID *ppSlot,
550 _In_ SIZE_T cbMin,
551 _In_ SIZE_T cbAlign,
552 _In_ BOOL bRequired,
553 _In_ PCSTR pszName)
554{
555 ULONG_PTR va, rva, idx;
556
557 if (!KbdIsBufInRange(pv, ppSlot, sizeof(PVOID), sizeof(PVOID)))
558 {
559 ERR("Invalid slot of %s: 0x%p\n", pszName, ppSlot);
560 return FALSE;
561 }
562
563 idx = ((ULONG_PTR)ppSlot - (ULONG_PTR)pv->pbImage) / sizeof(PVOID);
564 if (pv->pbSlots[idx >> 3] & (1 << (idx & 7)))
565 {
566 ERR("%s overlaps another pointer\n", pszName);
567 return FALSE;
568 }
569 pv->pbSlots[idx >> 3] |= (1 << (idx & 7));
570
571 va = (ULONG_PTR)*ppSlot;
572 if (!va)
573 {
574 if (bRequired)
575 {
576 ERR("%s is NULL\n", pszName);
577 return FALSE;
578 }
579 return TRUE;
580 }
581
582 rva = va - pv->ImageBase;
583 if (va < pv->ImageBase || rva < pv->offData || (rva - pv->offData) >= pv->cbData)
584 {
585 ERR("Invalid %s: 0x%p\n", pszName, (PVOID)va);
586 return FALSE;
587 }
588
589 *ppSlot = pv->pbImage + (rva - pv->offData);
590 if (!KbdIsBufInRange(pv, *ppSlot, cbMin, cbAlign))
591 {
592 ERR("%s: No room for %Iu bytes at 0x%p\n", pszName, cbMin, (PVOID)va);
593 *ppSlot = NULL;
594 return FALSE;
595 }
596 return TRUE;
597}
598
599#define KBD_REBASE(pv, field, cbMin, cbAlign, bRequired) \
600 KbdRebaseSlot((pv), (PVOID*)&(field), (cbMin), (cbAlign), (bRequired), #field)
601
608static BOOL
610 _In_ const KBDVALIDATE *pv,
611 _In_ const VOID *pTable,
612 _In_ SIZE_T cbElem,
614 _In_ SIZE_T cbAlign,
615 _In_ ULONG cMax,
616 _Out_ PULONG pcElems,
617 _In_ PCSTR pszName)
618{
619 const BYTE *pb;
620 SIZE_T k;
621 ULONG i;
622
623 *pcElems = 0;
624
625 for (i = 0; i < cMax; ++i)
626 {
627 pb = (const BYTE *)pTable + i * cbElem;
628 if (!KbdIsBufInRange(pv, pb, cbElem, cbAlign))
629 {
630 ERR("%s: Element %lu is out of range\n", pszName, i);
631 return FALSE;
632 }
633
634 for (k = 0; k < cbKey; ++k)
635 {
636 if (pb[k])
637 break;
638 }
639 if (k == cbKey) /* The terminator */
640 {
641 *pcElems = i;
642 return TRUE;
643 }
644 }
645
646 ERR("%s: No terminator within %lu elements\n", pszName, cMax);
647 return FALSE;
648}
649
657static BOOL
659 _In_ const KBDVALIDATE *pv,
660 _In_ const WCHAR *pwsz)
661{
662 SIZE_T i, cchMax;
663
664 if (!KbdIsBufInRange(pv, pwsz, sizeof(WCHAR), TYPE_ALIGNMENT(WCHAR)))
665 return FALSE;
666
667 cchMax = (pv->pbImage + pv->cbData - (const BYTE *)pwsz) / sizeof(WCHAR);
669 for (i = 0; i < cchMax; ++i)
670 {
671 if (!pwsz[i])
672 return TRUE;
673 }
674
675 ERR("Unterminated string at 0x%p\n", pwsz);
676 return FALSE;
677}
678
686static BOOL
689 _Inout_ PKBDTABLES pTbl)
690{
691 PMODIFIERS pMod;
692 ULONG i, cVkToBit;
693 SIZE_T cbMod;
694
695 if (!KBD_REBASE(pv, pTbl->pCharModifiers, sizeof(MODIFIERS), TYPE_ALIGNMENT(MODIFIERS), TRUE))
696 return FALSE;
697 pMod = pTbl->pCharModifiers;
698
699 /* ModNumber[] is indexed by the modifier bits, up to wMaxModBits (inclusive) */
700 cbMod = FIELD_OFFSET(MODIFIERS, ModNumber) + ((SIZE_T)pMod->wMaxModBits + 1) * sizeof(BYTE);
701 if (pMod->wMaxModBits > 0xFF || !KbdIsBufInRange(pv, pMod, cbMod, TYPE_ALIGNMENT(MODIFIERS)))
702 {
703 ERR("Invalid wMaxModBits: 0x%X\n", pMod->wMaxModBits);
704 return FALSE;
705 }
706 for (i = 0; i <= pMod->wMaxModBits; ++i)
707 {
708 /* A column number must not exceed the widest VK_TO_WCHARS<n> */
709 if (pMod->ModNumber[i] != SHFT_INVALID && pMod->ModNumber[i] >= KBD_MAX_MOD_COLUMNS)
710 {
711 ERR("Invalid ModNumber[%lu]: 0x%X\n", i, pMod->ModNumber[i]);
712 return FALSE;
713 }
714 }
715
716 if (!KBD_REBASE(pv, pMod->pVkToBit, sizeof(VK_TO_BIT), TYPE_ALIGNMENT(VK_TO_BIT), TRUE) ||
717 !KbdMeasureTable(pv, pMod->pVkToBit, sizeof(VK_TO_BIT), sizeof(BYTE),
718 TYPE_ALIGNMENT(VK_TO_BIT), KBD_MAX_VKTOBIT, &cVkToBit, "pVkToBit"))
719 {
720 return FALSE;
721 }
722 return TRUE;
723}
724
734static BOOL
737 _Inout_ PKBDTABLES pTbl,
738 _Out_ PBOOL pbLigature,
739 _Out_ PBOOL pbDead)
740{
741 PVK_TO_WCHAR_TABLE pWchTbl;
742 const WCHAR *pwch;
743 SIZE_T cbEntry;
744 ULONG iTbl, cTbls, iVk, cVks, iMod;
745
746 *pbLigature = *pbDead = FALSE;
747
748 /* This table ends with an entry that has NULL pVkToWchars */
749 if (!KBD_REBASE(pv, pTbl->pVkToWcharTable, sizeof(VK_TO_WCHAR_TABLE),
751 !KbdMeasureTable(pv, pTbl->pVkToWcharTable, sizeof(VK_TO_WCHAR_TABLE), sizeof(PVOID),
753 "pVkToWcharTable"))
754 {
755 return FALSE;
756 }
757 if (cTbls == 0)
758 {
759 ERR("pVkToWcharTable is empty\n");
760 return FALSE;
761 }
762
763 for (iTbl = 0; iTbl < cTbls; ++iTbl)
764 {
765 pWchTbl = &pTbl->pVkToWcharTable[iTbl];
766
767 /* The stride must match the number of columns, or we would walk (and later
768 * index) the entries wrongly */
769 cbEntry = FIELD_OFFSET(VK_TO_WCHARS1, wch) + pWchTbl->nModifications * sizeof(WCHAR);
770 if (pWchTbl->nModifications < 1 || pWchTbl->nModifications > KBD_MAX_MOD_COLUMNS ||
771 pWchTbl->cbSize != cbEntry)
772 {
773 ERR("Invalid table: nModifications %u, cbSize %u\n",
774 pWchTbl->nModifications, pWchTbl->cbSize);
775 return FALSE;
776 }
777
778 /* The entries end with an entry that has VirtualKey == 0 */
779 if (!KBD_REBASE(pv, pWchTbl->pVkToWchars, cbEntry, TYPE_ALIGNMENT(VK_TO_WCHARS1), TRUE) ||
780 !KbdMeasureTable(pv, pWchTbl->pVkToWchars, cbEntry, sizeof(BYTE),
781 TYPE_ALIGNMENT(VK_TO_WCHARS1), KBD_MAX_VKTOWCH, &cVks,
782 "pVkToWchars"))
783 {
784 return FALSE;
785 }
786
787 for (iVk = 0; iVk < cVks; ++iVk)
788 {
789 pwch = (const WCHAR *)((PBYTE)pWchTbl->pVkToWchars + iVk * cbEntry +
790 FIELD_OFFSET(VK_TO_WCHARS1, wch));
791 for (iMod = 0; iMod < pWchTbl->nModifications; ++iMod)
792 {
793 if (pwch[iMod] == WCH_LGTR)
794 *pbLigature = TRUE;
795 else if (pwch[iMod] == WCH_DEAD)
796 *pbDead = TRUE;
797 }
798 }
799 }
800 return TRUE;
801}
802
811static BOOL
814 _Inout_ VSC_LPWSTR **ppNames,
815 _In_ PCSTR pszName)
816{
817 VSC_LPWSTR *pNames;
818 ULONG i, cNames;
819
820 if (!KbdRebaseSlot(pv, (PVOID*)ppNames, sizeof(VSC_LPWSTR), TYPE_ALIGNMENT(VSC_LPWSTR),
821 TRUE, pszName) ||
822 !KbdMeasureTable(pv, *ppNames, sizeof(VSC_LPWSTR), sizeof(BYTE),
823 TYPE_ALIGNMENT(VSC_LPWSTR), KBD_MAX_KEYNAMES, &cNames, pszName))
824 {
825 return FALSE;
826 }
827
828 pNames = *ppNames;
829 for (i = 0; i < cNames; ++i)
830 {
831 if (!KbdRebaseSlot(pv, (PVOID*)&pNames[i].pwsz, sizeof(WCHAR), TYPE_ALIGNMENT(WCHAR),
832 TRUE, pszName) ||
833 !KbdCheckWideString(pv, pNames[i].pwsz))
834 {
835 ERR("%s[%lu]: Invalid name\n", pszName, i);
836 return FALSE;
837 }
838 }
839 return TRUE;
840}
841
849static BOOL
852 _Inout_ PKBDTABLES pTbl)
853{
854 LPWSTR *ppwsz;
855 ULONG i, cNames;
856
857 if (!KBD_REBASE(pv, pTbl->pKeyNamesDead, sizeof(LPWSTR), TYPE_ALIGNMENT(LPWSTR), FALSE))
858 return FALSE;
859 if (!pTbl->pKeyNamesDead)
860 return TRUE;
861
862 if (!KbdMeasureTable(pv, pTbl->pKeyNamesDead, sizeof(LPWSTR), sizeof(LPWSTR),
863 TYPE_ALIGNMENT(LPWSTR), KBD_MAX_DEADNAMES, &cNames, "pKeyNamesDead"))
864 {
865 return FALSE;
866 }
867
868 ppwsz = pTbl->pKeyNamesDead;
869 for (i = 0; i < cNames; ++i)
870 {
871 if (!KbdRebaseSlot(pv, (PVOID*)&ppwsz[i], sizeof(WCHAR), TYPE_ALIGNMENT(WCHAR),
872 TRUE, "pKeyNamesDead[]") ||
873 !KbdCheckWideString(pv, ppwsz[i]))
874 {
875 ERR("pKeyNamesDead[%lu]: Invalid name\n", i);
876 return FALSE;
877 }
878 }
879 return TRUE;
880}
881
891static BOOL
894 _Inout_ PVSC_VK *ppVscVk,
895 _In_ PCSTR pszName)
896{
898
899 return KbdRebaseSlot(pv, (PVOID*)ppVscVk, sizeof(VSC_VK), TYPE_ALIGNMENT(VSC_VK), TRUE,
900 pszName) &&
901 KbdMeasureTable(pv, *ppVscVk, sizeof(VSC_VK), sizeof(BYTE), TYPE_ALIGNMENT(VSC_VK),
902 KBD_MAX_VSCVK, &cEntries, pszName);
903}
904
913static BOOL
916 _Inout_ PKBDTABLES pTbl)
917{
919
920 if (!KBD_REBASE(pv, pTbl->pDeadKey, sizeof(DEADKEY), TYPE_ALIGNMENT(DEADKEY), FALSE))
921 return FALSE;
922 if (!pTbl->pDeadKey)
923 return TRUE;
924
925 return KbdMeasureTable(pv, pTbl->pDeadKey, sizeof(DEADKEY), sizeof(DWORD),
927}
928
937static BOOL
940 _Inout_ PKBDTABLES pTbl)
941{
943 SIZE_T cbEntry;
944
945 if (!pTbl->pLigature) /* Not yet rebased, but we only test it for NULL here */
946 return KBD_REBASE(pv, pTbl->pLigature, 0, 1, FALSE);
947
948 cbEntry = FIELD_OFFSET(LIGATURE1, wch) + pTbl->nLgMaxd * sizeof(WCHAR);
949 if (pTbl->nLgMaxd < 1 || pTbl->nLgMaxd > KBD_MAX_LIGATURE_CCH || pTbl->cbLgEntry != cbEntry)
950 {
951 ERR("Invalid ligature stride: nLgMaxd %u, cbLgEntry %u\n",
952 pTbl->nLgMaxd, pTbl->cbLgEntry);
953 return FALSE;
954 }
955
956 return KBD_REBASE(pv, pTbl->pLigature, cbEntry, TYPE_ALIGNMENT(LIGATURE1), TRUE) &&
957 KbdMeasureTable(pv, pTbl->pLigature, cbEntry, sizeof(BYTE), TYPE_ALIGNMENT(LIGATURE1),
958 KBD_MAX_LIGATURES, &cEntries, "pLigature");
959}
960
969static BOOL
973{
974 PVK_F pVkToF;
975 ULONG i, j;
976
977 if (pNls->NumOfVkToF > KBD_MAX_NLS_ENTRIES ||
978 pNls->NumOfMouseVKey < 0 || pNls->NumOfMouseVKey > KBD_MAX_NLS_ENTRIES)
979 {
980 ERR("Invalid NLS counts: %lu, %d\n", pNls->NumOfVkToF, pNls->NumOfMouseVKey);
981 return FALSE;
982 }
983
984 /* A pointer is required only if its count is not zero */
985 if (!KBD_REBASE(pv, pNls->pVkToF, pNls->NumOfVkToF * sizeof(VK_F), TYPE_ALIGNMENT(VK_F),
986 pNls->NumOfVkToF != 0) ||
987 !KBD_REBASE(pv, pNls->pusMouseVKey, pNls->NumOfMouseVKey * sizeof(USHORT),
988 TYPE_ALIGNMENT(USHORT), pNls->NumOfMouseVKey != 0))
989 {
990 return FALSE;
991 }
992
993 /* The indexes in these entries select the functions and the arrays of 8 elements */
994 pVkToF = pNls->pVkToF;
995 for (i = 0; i < pNls->NumOfVkToF; ++i)
996 {
997 if (pVkToF[i].NLSFEProcType > KBDNLS_TYPE_TOGGLE ||
998 pVkToF[i].NLSFEProcCurrent >= RTL_NUMBER_OF(pVkToF[i].NLSFEProc))
999 {
1000 ERR("Invalid VK_F[%lu]\n", i);
1001 return FALSE;
1002 }
1003 for (j = 0; j < RTL_NUMBER_OF(pVkToF[i].NLSFEProc); ++j)
1004 {
1005 if (pVkToF[i].NLSFEProc[j].NLSFEProcIndex > KBDNLS_CONV_OR_NONCONV ||
1006 pVkToF[i].NLSFEProcAlt[j].NLSFEProcIndex > KBDNLS_CONV_OR_NONCONV)
1007 {
1008 ERR("Invalid VK_F[%lu] procedure\n", i);
1009 return FALSE;
1010 }
1011 }
1012 }
1013 return TRUE;
1014}
1015
1036static BOOL
1038 _In_ PBYTE pbImage,
1039 _In_ const KBDIMAGE_INFO *pInfo,
1040 _Inout_ PKBDTABLES pTbl,
1042{
1043 KBDVALIDATE v;
1044 BOOL bLigature, bDead, ret = FALSE;
1045
1046 v.pbImage = pbImage;
1047 v.cbData = pInfo->cbData;
1048 v.ImageBase = pInfo->ImageBase;
1049 v.offData = pInfo->offData;
1050 v.pbSlots = ExAllocatePoolZero(PagedPool, v.cbData / (sizeof(PVOID) * 8) + 1, KBDIMG_TAG);
1051 if (!v.pbSlots)
1052 return FALSE;
1053
1054 /* The root tables themselves */
1055 if (!KbdIsBufInRange(&v, pTbl, sizeof(*pTbl), TYPE_ALIGNMENT(KBDTABLES)) ||
1056 (pNls && !KbdIsBufInRange(&v, pNls, sizeof(*pNls), TYPE_ALIGNMENT(KBDNLSTABLES))))
1057 {
1058 ERR("Misplaced root tables\n");
1059 goto Quit;
1060 }
1061
1062 /* pusVSCtoVK is counted by bMaxVSCtoVK */
1063 if (pTbl->bMaxVSCtoVK == 0)
1064 {
1065 ERR("bMaxVSCtoVK is zero\n");
1066 goto Quit;
1067 }
1068
1069 if (!KbdCheckModifiers(&v, pTbl) ||
1070 !KbdCheckVkToWchars(&v, pTbl, &bLigature, &bDead) ||
1071 !KbdCheckKeyNames(&v, &pTbl->pKeyNames, "pKeyNames") ||
1072 !KbdCheckKeyNames(&v, &pTbl->pKeyNamesExt, "pKeyNamesExt") ||
1073 !KbdCheckDeadKeyNames(&v, pTbl) ||
1074 !KbdCheckDeadKeys(&v, pTbl) ||
1075 !KBD_REBASE(&v, pTbl->pusVSCtoVK, pTbl->bMaxVSCtoVK * sizeof(USHORT),
1077 !KbdCheckVscToVk(&v, &pTbl->pVSCtoVK_E0, "pVSCtoVK_E0") ||
1078 !KbdCheckVscToVk(&v, &pTbl->pVSCtoVK_E1, "pVSCtoVK_E1") ||
1079 !KbdCheckLigatures(&v, pTbl))
1080 {
1081 goto Quit;
1082 }
1083
1084 /* WCH_LGTR and WCH_DEAD refer to these tables */
1085 if ((bLigature && !pTbl->pLigature) || (bDead && !pTbl->pDeadKey))
1086 {
1087 ERR("The layout uses WCH_LGTR/WCH_DEAD without the table\n");
1088 goto Quit;
1089 }
1090
1091 if (pNls && !KbdCheckNls(&v, pNls))
1092 goto Quit;
1093
1094 ret = TRUE;
1095
1096Quit:
1097 ExFreePoolWithTag(v.pbSlots, KBDIMG_TAG);
1098 return ret;
1099}
1100
1101/* Loads keyboard layout DLL and gets address to KbdTables */
1102static BOOL
1104 _In_ HANDLE hKernelFile,
1105 _In_ ULONG offTable,
1106 _Out_ HANDLE *phModule,
1107 _Out_ PULONG pcbImage,
1108 _Out_ PKBDTABLES *ppKbdTables,
1109 _Out_ PKBDNLSTABLES *ppKbdNlsTables)
1110{
1111 PBYTE pbImage;
1112 ULONG cbImage, wMainOffset = LOWORD(offTable), wNlsOffset = HIWORD(offTable);
1115 PKBDTABLES pKbdTables;
1116 PKBDNLSTABLES pKbdNlsTables;
1117
1118 *phModule = NULL;
1119 *ppKbdTables = NULL;
1120 *ppKbdNlsTables = NULL;
1121
1122 if (!wMainOffset)
1123 return FALSE;
1124
1125 /* Load keyboard layout DLL */
1126 hModule = KbdLoadImage(hKernelFile, &cbImage, &info);
1127 if (!hModule)
1128 return FALSE;
1129
1130 /* offTable comes from user mode: the tables must lie entirely within the .data section */
1131 if (!KbdIsRangeInData(&info, wMainOffset, sizeof(**ppKbdTables)) ||
1132 (wNlsOffset && !KbdIsRangeInData(&info, wNlsOffset, sizeof(**ppKbdNlsTables))))
1133 {
1134 ERR("Table offset out of range: offTable 0x%08X, .data 0x%08lX+0x%08lX\n",
1135 offTable, info.offData, info.cbData);
1137 return FALSE;
1138 }
1139
1140 /* The buffer holds the .data section only: convert the RVAs to the offsets in the buffer */
1141 pbImage = (PBYTE)hModule;
1142 pKbdTables = (PKBDTABLES)RVA(wMainOffset - info.offData, pbImage);
1143 pKbdNlsTables = wNlsOffset ? (PKBDNLSTABLES)RVA(wNlsOffset - info.offData, pbImage) : NULL;
1144
1145 _SEH2_TRY
1146 {
1147 /* Adjust the pointers inside the tables using RVA (instead of the base relocations),
1148 and validate their targets */
1149 if (!KbdRebaseTables(pbImage, &info, pKbdTables, pKbdNlsTables))
1150 {
1151 ERR("Invalid pointer in the layout tables\n");
1153 _SEH2_YIELD(return FALSE);
1154 }
1155 }
1157 {
1158 ERR("Exception in UserLoadKbdDll! Status: 0x%lx\n", _SEH2_GetExceptionCode());
1160 _SEH2_YIELD(return FALSE);
1161 }
1162 _SEH2_END;
1163
1164 *phModule = hModule;
1165 *pcbImage = cbImage;
1166 *ppKbdTables = pKbdTables;
1167 *ppKbdNlsTables = pKbdNlsTables;
1168
1169#if 0 && DBG
1170 /* Dump keyboard layout */
1171 DumpKbdLayout(*ppKbdTables);
1172#endif
1173
1174 return TRUE;
1175}
1176
1177/* Loads keyboard layout DLL and creates KBDFILE object */
1178static PKBDFILE
1180 _In_ HANDLE hKernelFile,
1181 _In_ ULONG offTable,
1182 _In_ PCUNICODE_STRING pustrKLID)
1183{
1184 PKBDFILE pkf, pRet = NULL;
1185
1186 /* Create keyboard layout file object */
1188 if (!pkf)
1189 {
1190 ERR("Failed to create object!\n");
1191 return NULL;
1192 }
1193
1194 _swprintf(pkf->awchKF, L"%wZ", pustrKLID); /* Set keyboard layout name */
1195
1196 /* Load keyboard file now */
1197 if (!UserLoadKbdDll(hKernelFile, offTable, &pkf->hBase, &pkf->Size,
1198 &pkf->pKbdTbl, &pkf->pKbdNlsTbl))
1199 {
1200 ERR("Failed to load layout file!\n");
1201 goto cleanup;
1202 }
1203
1204 /* Update next field */
1205 pkf->pkfNext = gpkfList;
1206 gpkfList = pkf;
1207
1208 /* Return keyboard file */
1209 pRet = pkf;
1210
1211cleanup:
1212 if (pkf)
1213 UserDereferenceObject(pkf); // we dont need ptr anymore
1214 if (!pRet && pkf) /* If we have failed, destroy the created object */
1216 return pRet;
1217}
1218
1219/* Loads keyboard layout and creates KL object */
1220static PKL
1222 _In_ HANDLE hKernelFile,
1223 _In_ ULONG offTable,
1224 _In_ const UNICODE_STRING* pustrKLID,
1225 _In_ HKL hKL)
1226{
1227 LCID lCid;
1229 PKL pKl;
1230
1231 if (!hKernelFile || !offTable)
1232 {
1233 ERR("hKernelFile %p, offTable 0x%08X\n", hKernelFile, offTable);
1234 return NULL;
1235 }
1236
1237 // Retrieve the language identifier.
1238 // NOTE: Do this before creating any object, so that a failure here leaks nothing.
1239 if (!NT_SUCCESS(RtlUnicodeStringToInteger(pustrKLID, 16, (PULONG)&lCid)))
1240 {
1241 ERR("RtlUnicodeStringToInteger failed for '%wZ'\n", pustrKLID);
1242 return NULL;
1243 }
1244
1245 TRACE("Language Identifiers %wZ LCID 0x%x\n", pustrKLID, lCid);
1246
1247 /* Create keyboard layout object */
1249 if (!pKl)
1250 {
1251 ERR("Failed to create object!\n");
1252 return NULL;
1253 }
1254
1255 pKl->hkl = hKL;
1256 pKl->spkf = UserLoadKbdFile(hKernelFile, offTable, pustrKLID);
1257
1258 /* Dereference keyboard layout */
1260
1261 /* If we failed, remove KL object */
1262 if (!pKl->spkf)
1263 {
1264 ERR("UserLoadKbdFile(%wZ) failed!\n", pustrKLID);
1266 return NULL;
1267 }
1268
1269 if (co_IntGetCharsetInfo(lCid, &cs))
1270 {
1271 pKl->iBaseCharset = cs.ciCharset;
1272 pKl->dwFontSigs = cs.fs.fsCsb[0];
1273 pKl->CodePage = (USHORT)cs.ciACP;
1274 TRACE("Charset %u Font Sig %lu CodePage %u\n",
1275 pKl->iBaseCharset, pKl->dwFontSigs, pKl->CodePage);
1276 }
1277 else
1278 {
1280 pKl->dwFontSigs = FS_LATIN1;
1281 pKl->CodePage = CP_ACP;
1282 }
1283
1284 // Set initial system character set and font signature.
1285 if (gSystemFS == 0)
1286 {
1288 gSystemFS = pKl->dwFontSigs;
1289 }
1290
1291 return pKl;
1292}
1293
1294/*
1295 * UnloadKbdFile
1296 *
1297 * Destroys specified Keyboard File object
1298 */
1299static
1300VOID
1302{
1303 PKBDFILE *ppkfLink = &gpkfList;
1304 NT_ASSERT(pkf != NULL);
1305
1306 /* Find previous object */
1307 while (*ppkfLink)
1308 {
1309 if (*ppkfLink == pkf)
1310 break;
1311
1312 ppkfLink = &(*ppkfLink)->pkfNext;
1313 }
1314
1315 if (*ppkfLink == pkf)
1316 *ppkfLink = pkf->pkfNext;
1317
1318 KbdUnloadImage(pkf->hBase);
1320}
1321
1322/*
1323 * UserUnloadKbl
1324 *
1325 * Unloads specified Keyboard Layout if possible
1326 */
1327BOOL
1329{
1330 /* According to msdn, UnloadKeyboardLayout can fail
1331 if the keyboard layout identifier was preloaded. */
1332 if (pKl == gspklBaseLayout)
1333 {
1334 if (pKl->pklNext == pKl)
1335 {
1336 /* There is only one layout */
1337 return FALSE;
1338 }
1339
1340 /* Set next layout as default */
1341 gspklBaseLayout = pKl->pklNext;
1342 }
1343
1344 if (pKl->head.cLockObj > 1)
1345 {
1346 /* Layout is used by other threads */
1347 pKl->dwKL_Flags |= KL_UNLOAD;
1348 return FALSE;
1349 }
1350
1351 /* Unload the layout */
1352 pKl->pklPrev->pklNext = pKl->pklNext;
1353 pKl->pklNext->pklPrev = pKl->pklPrev;
1354 UnloadKbdFile(pKl->spkf);
1355 if (pKl->piiex)
1356 {
1358 }
1360 return TRUE;
1361}
1362
1363/*
1364 * W32kGetDefaultKeyLayout
1365 *
1366 * Returns default layout for new threads
1367 */
1368PKL
1370{
1371 PKL pKl = gspklBaseLayout;
1372
1373 if (!pKl)
1374 return NULL;
1375
1376 /* Return not unloaded layout */
1377 do
1378 {
1379 if (!(pKl->dwKL_Flags & KL_UNLOAD))
1380 return pKl;
1381
1382 pKl = pKl->pklPrev; /* Confirmed on Win2k */
1383 } while(pKl != gspklBaseLayout);
1384
1385 /* We have not found proper KL */
1386 return NULL;
1387}
1388
1389/*
1390 * UserHklToKbl
1391 *
1392 * Gets KL object from hkl value
1393 */
1394PKL
1395NTAPI
1397{
1398 PKL pKl = gspklBaseLayout;
1399
1400 if (!gspklBaseLayout)
1401 return NULL;
1402
1403 do
1404 {
1405 if (pKl->hkl == hKl)
1406 return pKl;
1407
1408 pKl = pKl->pklNext;
1409 } while (pKl != gspklBaseLayout);
1410
1411 return NULL;
1412}
1413
1417 _Inout_ PKL pNewKL)
1418{
1419 PKL pOldKL = gspklBaseLayout;
1420
1421 if ((pWinSta->Flags & WSS_NOIO) || pNewKL == pOldKL)
1422 return;
1423
1424 pNewKL->pklPrev->pklNext = pNewKL->pklNext;
1425 pNewKL->pklNext->pklPrev = pNewKL->pklPrev;
1426 pNewKL->pklNext = pOldKL;
1427 pNewKL->pklPrev = pOldKL->pklPrev;
1428 pOldKL->pklPrev->pklNext = pNewKL;
1429 pOldKL->pklPrev = pNewKL;
1430 gspklBaseLayout = pNewKL; /* Should we use UserAssignmentLock? */
1431}
1432
1433/*
1434 * UserSetDefaultInputLang
1435 *
1436 * Sets default keyboard layout for system. Called from UserSystemParametersInfo.
1437 */
1438BOOL
1439NTAPI
1441{
1442 PKL pKl;
1443
1444 pKl = UserHklToKbl(hKl);
1445 if (!pKl)
1446 return FALSE;
1447
1449 return TRUE;
1450}
1451
1454 _Inout_ PTHREADINFO pti,
1455 _Inout_ PKL pKL)
1456{
1457 PWND pImeWnd;
1458 HWND hImeWnd;
1460
1461 if (pti->KeyboardLayout == pKL)
1462 return;
1463
1464 pImeWnd = pti->spwndDefaultIme;
1465 if (pImeWnd)
1466 {
1467 UserRefObjectCo(pImeWnd, &Ref);
1468 hImeWnd = UserHMGetHandle(pImeWnd);
1470 UserDerefObjectCo(pImeWnd);
1471 }
1472 else
1473 {
1474 /* Remember old keyboard layout to switch back for Chinese IMEs */
1475 if (pti->KeyboardLayout)
1476 pti->hklPrev = pti->KeyboardLayout->hkl;
1477
1478 if (pti->spDefaultImc)
1479 {
1480 /* IME Activation is needed */
1481 pti->pClientInfo->CI_flags |= CI_IMMACTIVATE;
1482 }
1483 }
1484
1485 UserAssignmentLock((PVOID*)&(pti->KeyboardLayout), pKL);
1486 pti->pClientInfo->hKL = pKL->hkl;
1487 pti->pClientInfo->CodePage = pKL->CodePage;
1488}
1489
1491{
1492 PTHREADINFO ptiNode, ptiNext;
1493 PCLIENTINFO pClientInfo;
1494 BOOL bImmMode = IS_IMM_MODE();
1495
1496 for (ptiNode = ppi->ptiList; ptiNode; ptiNode = ptiNext)
1497 {
1498 IntReferenceThreadInfo(ptiNode);
1499 ptiNext = ptiNode->ptiSibling;
1500
1501 /* Skip this thread if its keyboard layout is already the correct one, or if it's dying */
1502 if (ptiNode->KeyboardLayout == pKL || (ptiNode->TIF_flags & TIF_INCLEANUP))
1503 {
1504 IntDereferenceThreadInfo(ptiNode);
1505 continue;
1506 }
1507
1508 if (bImmMode)
1509 {
1510 IntImmActivateLayout(ptiNode, pKL);
1511 }
1512 else
1513 {
1514 UserAssignmentLock((PVOID*)&ptiNode->KeyboardLayout, pKL);
1515 pClientInfo = ptiNode->pClientInfo;
1516 pClientInfo->CodePage = pKL->CodePage;
1517 pClientInfo->hKL = pKL->hkl;
1518 }
1519
1520 IntDereferenceThreadInfo(ptiNode);
1521 }
1522}
1523
1526 _Inout_ PKL pKL,
1528 _In_opt_ PWND pWnd)
1529{
1530 HKL hOldKL = NULL;
1531 PKL pOldKL;
1533 PWND pTargetWnd, pImeWnd;
1534 HWND hTargetWnd, hImeWnd;
1535 USER_REFERENCE_ENTRY Ref1, Ref2;
1537 BOOL bSetForProcess = !!(uFlags & KLF_SETFORPROCESS);
1538
1540 ClientInfo = pti->pClientInfo;
1541
1542 pOldKL = pti->KeyboardLayout;
1543 if (pOldKL)
1544 hOldKL = pOldKL->hkl;
1545
1546 if (uFlags & KLF_RESET)
1547 {
1548 FIXME("KLF_RESET\n");
1549 }
1550
1551 if (!bSetForProcess && pKL == pti->KeyboardLayout)
1552 {
1554 return hOldKL;
1555 }
1556
1557 pKL->wchDiacritic = UNICODE_NULL;
1558
1559 if (pOldKL)
1560 UserRefObjectCo(pOldKL, &Ref1);
1561
1562 if (pti->TIF_flags & TIF_CSRSSTHREAD)
1563 {
1565 ClientInfo->CodePage = pKL->CodePage;
1566 ClientInfo->hKL = pKL->hkl;
1567 }
1568 else if (bSetForProcess)
1569 {
1571 }
1572 else
1573 {
1574 if (IS_IMM_MODE())
1575 IntImmActivateLayout(pti, pKL);
1576 else
1578
1579 ClientInfo->CodePage = pKL->CodePage;
1580 ClientInfo->hKL = pKL->hkl;
1581 }
1582
1583 /* Send shell message if necessary */
1585 {
1586 /* Send the HKL if needed and remember it */
1587 if (ghKLSentToShell != pKL->hkl)
1588 {
1589 co_IntShellHookNotify(HSHELL_LANGUAGE, 0, (LPARAM)pKL->hkl);
1590 ghKLSentToShell = pKL->hkl;
1591 }
1592 }
1593
1594 if (pti->MessageQueue)
1595 {
1596 /* Determine the target window */
1597 pTargetWnd = pti->MessageQueue->spwndFocus;
1598 if (!pTargetWnd)
1599 {
1600 pTargetWnd = pti->MessageQueue->spwndActive;
1601 if (!pTargetWnd)
1602 pTargetWnd = pWnd;
1603 }
1604
1605 /* Send WM_INPUTLANGCHANGE message */
1606 if (pTargetWnd)
1607 {
1608 UserRefObjectCo(pTargetWnd, &Ref2);
1609 hTargetWnd = UserHMGetHandle(pTargetWnd);
1610 co_IntSendMessage(hTargetWnd, WM_INPUTLANGCHANGE, pKL->iBaseCharset, (LPARAM)pKL->hkl);
1611 UserDerefObjectCo(pTargetWnd);
1612 }
1613 }
1614
1615 // Refresh IME UI via WM_IME_SYSTEM:IMS_SENDNOTIFICATION messaging
1616 if (!(pti->TIF_flags & TIF_CSRSSTHREAD))
1617 {
1618 if (IS_IME_HKL(pKL->hkl) || (IS_CICERO_MODE() && !IS_16BIT_MODE()))
1619 {
1620 pImeWnd = pti->spwndDefaultIme;
1621 if (pImeWnd)
1622 {
1623 bSetForProcess &= !IS_16BIT_MODE();
1624 UserRefObjectCo(pImeWnd, &Ref2);
1625 hImeWnd = UserHMGetHandle(pImeWnd);
1626 co_IntSendMessage(hImeWnd, WM_IME_SYSTEM, IMS_SENDNOTIFICATION, bSetForProcess);
1627 UserDerefObjectCo(pImeWnd);
1628 }
1629 }
1630 }
1631
1632 if (pOldKL)
1633 UserDerefObjectCo(pOldKL);
1634
1636 return hOldKL;
1637}
1638
1642 _In_ HKL hKL,
1644 _In_opt_ PWND pWnd)
1645{
1646 PKL pKL;
1648
1649 pKL = IntHKLtoPKL(pti, hKL);
1650 if (!pKL)
1651 {
1652 ERR("Invalid HKL %p!\n", hKL);
1653 return NULL;
1654 }
1655
1656 if (uFlags & KLF_REORDER)
1657 IntReorderKeyboardLayouts(pWinSta, pKL);
1658
1659 return co_UserActivateKeyboardLayout(pKL, uFlags, pWnd);
1660}
1661
1662static BOOL APIENTRY
1665 _Inout_ PKL pKL,
1667{
1668 PKL pNextKL;
1669 USER_REFERENCE_ENTRY Ref1, Ref2;
1671
1672 if (pKL == gspklBaseLayout && !(dwFlags & UKL_NOACTIVATENEXT))
1673 return FALSE;
1674
1675 UserRefObjectCo(pKL, &Ref1); /* Add reference */
1676
1677 /* Regard as unloaded */
1679 pKL->dwKL_Flags |= KL_UNLOAD;
1680
1681 if (!(dwFlags & UKL_NOACTIVATENEXT) && pti->KeyboardLayout == pKL)
1682 {
1683 pNextKL = IntHKLtoPKL(pti, UlongToHandle(HKL_NEXT));
1684 if (pNextKL)
1685 {
1686 UserRefObjectCo(pNextKL, &Ref2); /* Add reference */
1688 UserDerefObjectCo(pNextKL); /* Release reference */
1689 }
1690 }
1691
1692 if (gspklBaseLayout == pKL && pKL != pKL->pklNext)
1693 {
1694 /* Set next layout as default (FIXME: Use UserAssignmentLock?) */
1695 gspklBaseLayout = pKL->pklNext;
1696 }
1697
1698 UserDerefObjectCo(pKL); /* Release reference */
1699
1700 if (ISITHOOKED(WH_SHELL))
1701 {
1702 co_IntShellHookNotify(HSHELL_LANGUAGE, 0, 0);
1704 }
1705
1706 return TRUE;
1707}
1708
1709static BOOL APIENTRY
1711{
1712 PKL pKL = IntHKLtoPKL(gptiCurrent, hKL);
1713 if (!pKL)
1714 {
1715 ERR("Invalid HKL %p!\n", hKL);
1716 return FALSE;
1717 }
1718 return co_IntUnloadKeyboardLayoutEx(pWinSta, pKL, 0);
1719}
1720
1723{
1724 PIMEINFOEX piiex;
1725
1726 if (!IS_IME_HKL(hKL) && !IS_CICERO_MODE())
1727 return NULL;
1728
1730 if (!piiex)
1731 return NULL;
1732
1733 if (!co_ClientImmLoadLayout(hKL, piiex))
1734 {
1736 return NULL;
1737 }
1738
1739 return piiex;
1740}
1741
1745 _In_ HANDLE hKernelFile,
1746 _In_opt_ HKL hOldKL,
1747 _In_ ULONG offTable,
1748 _In_ PUNICODE_STRING puszSafeKLID,
1749 _In_ HKL hNewKL,
1750 _In_ UINT Flags)
1751{
1752 PKL pOldKL, pNewKL;
1753
1754 if (hNewKL == NULL || (pWinSta->Flags & WSS_NOIO))
1755 return NULL;
1756
1757 /* If hOldKL is specified, unload it and load new layput as default */
1758 if (hOldKL && hOldKL != hNewKL)
1759 {
1760 pOldKL = UserHklToKbl(hOldKL);
1761 if (pOldKL)
1762 UserUnloadKbl(pOldKL);
1763 }
1764
1765 /* FIXME: It seems KLF_RESET is only supported for WINLOGON */
1766
1767 /* Let's see if layout was already loaded. */
1768 pNewKL = UserHklToKbl(hNewKL);
1769 if (!pNewKL)
1770 {
1771 /* It wasn't, so load it. */
1772 pNewKL = co_UserLoadKbdLayout(hKernelFile, offTable, puszSafeKLID, hNewKL);
1773 if (!pNewKL)
1774 return NULL;
1775
1776 if (gspklBaseLayout)
1777 {
1778 /* Find last not unloaded layout */
1779 PKL pLastKL = gspklBaseLayout->pklPrev;
1780 while (pLastKL != gspklBaseLayout && (pLastKL->dwKL_Flags & KL_UNLOAD))
1781 pLastKL = pLastKL->pklPrev;
1782
1783 /* Add new layout to the list */
1784 pNewKL->pklNext = pLastKL->pklNext;
1785 pNewKL->pklPrev = pLastKL;
1786 pNewKL->pklNext->pklPrev = pNewKL;
1787 pNewKL->pklPrev->pklNext = pNewKL;
1788 }
1789 else
1790 {
1791 /* This is the first layout */
1792 pNewKL->pklNext = pNewKL;
1793 pNewKL->pklPrev = pNewKL;
1794 gspklBaseLayout = pNewKL;
1795 }
1796
1797 pNewKL->piiex = co_UserImmLoadLayout(hNewKL);
1798 }
1799
1800 /* If this layout was prepared to unload, undo it */
1801 pNewKL->dwKL_Flags &= ~KL_UNLOAD;
1802
1803 /* Reorder if necessary */
1804 if (Flags & KLF_REORDER)
1805 IntReorderKeyboardLayouts(pWinSta, pNewKL);
1806
1807 /* Activate this layout in current thread */
1808 if (Flags & KLF_ACTIVATE)
1810
1811 /* Send shell message */
1812 if (!(Flags & KLF_NOTELLSHELL))
1813 co_IntShellHookNotify(HSHELL_LANGUAGE, 0, (LPARAM)hNewKL);
1814
1815 /* FIXME: KLF_REPLACELANG */
1816
1817 return hNewKL;
1818}
1819
1820typedef struct tagKBDFILE_NAME
1821{
1825
1826/* Gets the full NT path of a file or directory handle. */
1828{
1829 ULONG cbReturned;
1830 return ZwQueryObject(hObject, ObjectNameInformation, pName, sizeof(*pName), &cbReturned);
1831}
1832
1833static BOOL FASTCALL
1835 _In_ PCUNICODE_STRING pustrParent,
1836 _In_ PCUNICODE_STRING pustrDir)
1837{
1841 HANDLE hDir;
1843
1844 /* Get the canonical name of the directory */
1850 if (!NT_SUCCESS(Status))
1851 {
1852 ERR("ZwOpenFile(%wZ) failed, Status 0x%08lx\n", pustrDir, Status);
1853 return FALSE;
1854 }
1855
1856 Status = IntQueryHandleName(hDir, &Name);
1857 ZwClose(hDir);
1858 if (!NT_SUCCESS(Status))
1859 {
1860 ERR("IntQueryHandleName(%p) failed, Status 0x%08lx\n", hDir, Status);
1861 return FALSE;
1862 }
1863
1864 if (!RtlEqualUnicodeString(pustrParent, &Name.Info.Name, TRUE))
1865 return FALSE;
1866
1867 return TRUE;
1868}
1869
1891{
1892 static const UNICODE_STRING ustrDir = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32");
1894 UNICODE_STRING ustrParent;
1895 PFILE_OBJECT pFileObject = NULL;
1896 HANDLE hKernelFile = NULL;
1898
1899 if (!hFile)
1900 return NULL;
1901
1902 /* Resolve the user handle exactly once and pin the file object */
1904 (PVOID*)&pFileObject, NULL);
1905 if (!NT_SUCCESS(Status))
1906 {
1907 ERR("ObReferenceObjectByHandle(%p) failed, Status 0x%08lx\n", hFile, Status);
1908 return NULL;
1909 }
1910
1911 if (!(pFileObject->Flags & FO_SYNCHRONOUS_IO))
1912 {
1913 ERR("Not a synchronous file: %p\n", hFile);
1914 ObDereferenceObject(pFileObject);
1915 return NULL;
1916 }
1917
1918 /* Duplicate the handle for kernel-mode, which user mode cannot close or swap */
1921 *IoFileObjectType, KernelMode, &hKernelFile);
1922 ObDereferenceObject(pFileObject);
1923 if (!NT_SUCCESS(Status))
1924 {
1925 ERR("ObOpenObjectByPointer(%p) failed, Status 0x%08lx\n", hFile, Status);
1926 return NULL;
1927 }
1928
1929 /* Get the canonical name of the file */
1930 Status = IntQueryHandleName(hKernelFile, &Name);
1931 if (!NT_SUCCESS(Status))
1932 {
1933 ERR("IntQueryHandleName(%p) failed, Status 0x%08lx\n", hFile, Status);
1934 goto Failure;
1935 }
1936
1937 /* Strip the filename of the file */
1938 ustrParent = Name.Info.Name;
1939 while (ustrParent.Length > 0)
1940 {
1941 ustrParent.Length -= sizeof(WCHAR);
1942 if (ustrParent.Buffer[ustrParent.Length / sizeof(WCHAR)] == L'\\')
1943 break;
1944 }
1945
1946 if (!IntEqualDir(&ustrParent, &ustrDir))
1947 {
1948 ERR("Not in system32: %wZ\n", &Name.Info.Name);
1949 goto Failure;
1950 }
1951
1952 return hKernelFile; /* Success */
1953
1954Failure:
1955 ZwClose(hKernelFile);
1956 return NULL;
1957}
1958
1959/* EXPORTS *******************************************************************/
1960
1961/*
1962 * UserGetKeyboardLayout
1963 *
1964 * Returns hkl of given thread keyboard layout
1965 */
1969{
1970 PTHREADINFO pti;
1971 PLIST_ENTRY ListEntry;
1972 PKL pKl;
1973
1975
1976 if (!dwThreadId)
1977 {
1978 pKl = pti->KeyboardLayout;
1979 return pKl ? pKl->hkl : NULL;
1980 }
1981
1982 ListEntry = pti->rpdesk->PtiList.Flink;
1983
1984 //
1985 // Search the Desktop Thread list for related Desktop active Threads.
1986 //
1987 while(ListEntry != &pti->rpdesk->PtiList)
1988 {
1989 pti = CONTAINING_RECORD(ListEntry, THREADINFO, PtiLink);
1990
1991 if (PsGetThreadId(pti->pEThread) == UlongToHandle(dwThreadId))
1992 {
1993 pKl = pti->KeyboardLayout;
1994 return pKl ? pKl->hkl : NULL;
1995 }
1996
1997 ListEntry = ListEntry->Flink;
1998 }
1999
2000 return NULL;
2001}
2002
2003/*
2004 * NtUserGetKeyboardLayoutList
2005 *
2006 * Returns list of loaded keyboard layouts in system
2007 */
2008UINT
2011 ULONG nBuff,
2012 HKL *pHklBuff)
2013{
2014 UINT ret = 0;
2015 PWINSTATION_OBJECT pWinSta;
2016
2017 if (!pHklBuff)
2018 nBuff = 0;
2019
2021
2022 if (nBuff > MAXULONG / sizeof(HKL))
2023 {
2025 goto Quit;
2026 }
2027
2028 _SEH2_TRY
2029 {
2030 ProbeForWrite(pHklBuff, nBuff * sizeof(HKL), 1);
2031 }
2033 {
2035 _SEH2_YIELD(goto Quit);
2036 }
2037 _SEH2_END;
2038
2040
2041 _SEH2_TRY
2042 {
2043 ret = IntGetKeyboardLayoutList(pWinSta, nBuff, pHklBuff);
2044 }
2046 {
2048 _SEH2_YIELD(goto Quit);
2049 }
2050 _SEH2_END;
2051
2052Quit:
2053 UserLeave();
2054 return ret;
2055}
2056
2057/*
2058 * NtUserGetKeyboardLayoutName
2059 *
2060 * Returns KLID of current thread keyboard layout
2061 */
2062BOOL
2065 _Inout_ PUNICODE_STRING pustrName)
2066{
2067 BOOL bRet = FALSE;
2068 PKL pKl;
2069 PTHREADINFO pti;
2070 UNICODE_STRING ustrNameSafe;
2072
2074
2076 pKl = pti->KeyboardLayout;
2077
2078 if (!pKl)
2079 goto cleanup;
2080
2081 _SEH2_TRY
2082 {
2083 ProbeForWriteUnicodeString(pustrName);
2084 ustrNameSafe = *pustrName;
2085
2086 ProbeForWrite(ustrNameSafe.Buffer, ustrNameSafe.MaximumLength, 1);
2087
2088 if (IS_IME_HKL(pKl->hkl))
2089 {
2090 Status = RtlIntegerToUnicodeString(HandleToUlong(pKl->hkl), 16, &ustrNameSafe);
2091 }
2092 else
2093 {
2094 if (ustrNameSafe.MaximumLength < KL_NAMELENGTH * sizeof(WCHAR))
2095 {
2097 _SEH2_YIELD(goto cleanup);
2098 }
2099
2100 /* FIXME: Do not use awchKF */
2101 ustrNameSafe.Length = 0;
2102 Status = RtlAppendUnicodeToString(&ustrNameSafe, pKl->spkf->awchKF);
2103 }
2104
2105 if (NT_SUCCESS(Status))
2106 {
2107 *pustrName = ustrNameSafe;
2108 bRet = TRUE;
2109 }
2110 }
2112 {
2114 }
2115 _SEH2_END;
2116
2117cleanup:
2118 UserLeave();
2119 return bRet;
2120}
2121
2122/*
2123 * NtUserLoadKeyboardLayoutEx
2124 *
2125 * Loads keyboard layout with given locale id
2126 */
2127HKL
2128NTAPI
2131 _In_ ULONG offTable,
2133 _In_opt_ HKL hOldKL,
2134 _In_ PUNICODE_STRING puszKLID,
2135 _In_ ULONG dwNewKL,
2136 _In_ UINT Flags)
2137{
2138 HKL hRetKL = NULL;
2140 UNICODE_STRING uszSafeKLID;
2141 PWINSTATION_OBJECT pWinSta;
2142 HANDLE hKernelFile = NULL; /* Local kernel handle duplicated from hFile */
2143 HANDLE ahKernelAuxFile[KBDTABLE_MULTI_MAX] = { NULL }; /* Ditto, for the aux files */
2144 KBDTABLE_MULTI_EX multi;
2145 ULONG iTable;
2146
2149 KLF_RESET|KLF_SHIFTLOCK))
2150 {
2151 ERR("Invalid flags: %x\n", Flags);
2153 return NULL;
2154 }
2155
2156 RtlInitEmptyUnicodeString(&uszSafeKLID, Buffer, sizeof(Buffer));
2157 RtlZeroMemory(&multi, sizeof(multi));
2158
2159 /* Read from paramters */
2160 _SEH2_TRY
2161 {
2162 ProbeForRead(puszKLID, sizeof(*puszKLID), 1);
2163 ProbeForRead(puszKLID->Buffer, sizeof(puszKLID->Length), 1); /* FIXME */
2164 RtlCopyUnicodeString(&uszSafeKLID, puszKLID);
2165 if (pMulti)
2166 {
2167 ProbeForRead(pMulti, sizeof(*pMulti), 1);
2168 multi = *pMulti;
2169 }
2170 }
2172 {
2174 _SEH2_YIELD(return NULL);
2175 }
2176 _SEH2_END;
2177
2179
2180 /* Validate data */
2181 if (!hFile || !offTable || multi.Multi.nTables > KBDTABLE_MULTI_MAX)
2182 {
2183 ERR("hFile:%p, nTables:%u, offTable:0x%08X\n", hFile, multi.Multi.nTables, offTable);
2185 goto Quit;
2186 }
2187
2188 /* Verify file handles. The handles passed in belong to user32, which closes them itself.
2189 * We only work with (and close) our own kernel handles made by the verification. */
2190 hKernelFile = IntVerifyKeyboardFileHandle(hFile);
2191 if (!hKernelFile)
2192 goto Quit;
2193 for (iTable = 0; iTable < multi.Multi.nTables; ++iTable) /* nTables < MAX is checked above */
2194 {
2195 HANDLE hAuxFile = multi.AuxEntries[iTable].hFile;
2196 /* user32 tolerates a failed aux file by storing NULL */
2197 if (!hAuxFile)
2198 continue;
2199
2200 ahKernelAuxFile[iTable] = IntVerifyKeyboardFileHandle(hAuxFile);
2201 if (!ahKernelAuxFile[iTable])
2202 goto Quit;
2203 }
2204
2205 /* Load it now */
2207 hRetKL = co_IntLoadKeyboardLayoutEx(pWinSta, hKernelFile, hOldKL, offTable, &uszSafeKLID,
2208 UlongToHandle(dwNewKL), Flags);
2209Quit:
2210 /* Close our kernel handles. Never use the (unvalidated) user-supplied nTables here. */
2211 if (hKernelFile)
2212 ZwClose(hKernelFile);
2213 for (iTable = 0; iTable < RTL_NUMBER_OF(ahKernelAuxFile); ++iTable)
2214 {
2215 if (ahKernelAuxFile[iTable])
2216 ZwClose(ahKernelAuxFile[iTable]);
2217 }
2218
2219 UserLeave();
2220 return hRetKL;
2221}
2222
2223/*
2224 * NtUserActivateKeyboardLayout
2225 *
2226 * Activates specified layout for thread or process
2227 */
2228HKL
2229NTAPI
2231 HKL hKL,
2232 ULONG Flags)
2233{
2234 PWINSTATION_OBJECT pWinSta;
2235 HKL hOldKL;
2236
2238
2239 /* FIXME */
2240
2242 hOldKL = co_IntActivateKeyboardLayout(pWinSta, hKL, Flags, NULL);
2243 UserLeave();
2244
2245 return hOldKL;
2246}
2247
2248/*
2249 * NtUserUnloadKeyboardLayout
2250 *
2251 * Unloads keyboard layout with specified hkl value
2252 */
2253BOOL
2256 HKL hKl)
2257{
2258 BOOL ret;
2259 PWINSTATION_OBJECT pWinSta;
2260
2262
2264 ret = IntUnloadKeyboardLayout(pWinSta, hKl);
2265
2266 UserLeave();
2267 return ret;
2268}
2269
2270/* EOF */
@ ObjectNameInformation
Definition: DriverTester.h:55
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
UINT cchMax
#define __inline
Definition: _wctype.cpp:15
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
#define UlongToHandle(ul)
Definition: basetsd.h:91
#define HandleToUlong(h)
Definition: basetsd.h:73
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
RtlInitEmptyUnicodeString(SymbolicLinkName, NULL, 0)
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
LPWSTR Name
Definition: desk.c:124
PTHREADINFO gptiForeground
Definition: focus.c:15
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
unsigned int idx
Definition: utils.c:40
#define APIENTRY
Definition: api.h:79
UINT uFlags
Definition: api.c:59
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
HMODULE hModule
Definition: animate.c:44
#define IMAGE_FILE_MACHINE_ARMNT
Definition: compat.h:127
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define MAX_PATH
Definition: compat.h:34
#define IMAGE_FILE_MACHINE_ARM64
Definition: compat.h:129
#define FILE_SHARE_READ
Definition: compat.h:136
static void cleanup(void)
Definition: main.c:1335
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
static const uint32_t k[]
Definition: sha256.c:24
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
DWORD dwThreadId
Definition: fdebug.c:31
struct _IMAGE_NT_HEADERS * PIMAGE_NT_HEADERS32
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:24
const GLdouble * v
Definition: gl.h:2040
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define DbgPrint
Definition: hal.h:12
unsigned int UINT
Definition: sysinfo.c:13
#define ISITHOOKED(HookId)
Definition: hook.h:6
ZwClose(Handle)
#define cs
Definition: i386-dis.c:442
#define IS_IME_HKL(hKL)
Definition: imm32_undoc.h:21
#define IMS_ACTIVATELAYOUT
Definition: imm32_undoc.h:60
#define WM_IME_SYSTEM
Definition: imm32_undoc.h:32
#define IMS_SENDNOTIFICATION
Definition: imm32_undoc.h:66
#define TIF_CSRSSTHREAD
Definition: ntuser.h:293
#define TIF_INCLEANUP
Definition: ntuser.h:290
#define UserHMGetHandle(obj)
Definition: ntuser.h:257
struct _THREADINFO * GetW32ThreadInfo(VOID)
Definition: misc.c:806
#define CI_IMMACTIVATE
Definition: ntuser.h:334
#define IS_IMM_MODE()
Definition: ntuser.h:1243
@ TYPE_KBDFILE
Definition: ntuser.h:59
@ TYPE_KBDLAYOUT
Definition: ntuser.h:58
#define IS_16BIT_MODE()
Definition: ntuser.h:1245
#define IS_CICERO_MODE()
Definition: ntuser.h:1244
CLIENT_DATA ClientInfo
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define WCH_DEAD
Definition: kbd.h:170
struct _KBDTABLES * PKBDTABLES
#define WCH_LGTR
Definition: kbd.h:171
struct tagKbdNlsLayer * PKBDNLSTABLES
#define KBDNLS_TYPE_TOGGLE
Definition: kbd.h:212
#define KBDTABLE_MULTI_MAX
Definition: kbd.h:199
#define SHFT_INVALID
Definition: kbd.h:74
#define KBDNLS_CONV_OR_NONCONV
Definition: kbd.h:233
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
LONG_PTR LPARAM
Definition: minwindef.h:175
BOOL * PBOOL
Definition: minwindef.h:137
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
static LPSTR pName
Definition: security.c:86
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define min(a, b)
Definition: monoChain.cc:55
UINT_PTR HKL
Definition: msctf.idl:125
_In_ HANDLE hFile
Definition: mswsock.h:90
#define KernelMode
Definition: asm.h:38
#define UserMode
Definition: asm.h:39
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define _Inout_
Definition: no_sal2.h:162
#define _Inout_opt_
Definition: no_sal2.h:216
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define FASTCALL
Definition: nt_native.h:50
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define TYPE_ALIGNMENT(t)
Definition: ntbasedef.h:117
#define UNICODE_NULL
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:377
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: ntimage.h:378
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:428
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:729
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:829
PWINSTATION_OBJECT FASTCALL IntGetProcessWindowStation(HWINSTA *phWinSta OPTIONAL)
Definition: winsta.c:422
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:241
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2769
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:44
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:28
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:493
#define LOWORD(l)
Definition: pedump.c:82
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
unsigned short USHORT
Definition: pedump.c:61
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define KLF_SETFORPROCESS
Definition: winuser.h:117
#define KL_NAMELENGTH
Definition: winuser.h:122
#define KLF_REPLACELANG
Definition: winuser.h:115
#define KLF_ACTIVATE
Definition: winuser.h:111
#define HKL_PREV
Definition: winuser.h:110
#define KLF_REORDER
Definition: winuser.h:114
#define WH_SHELL
Definition: winuser.h:40
#define HKL_NEXT
Definition: winuser.h:109
#define KLF_SUBSTITUTE_OK
Definition: winuser.h:112
#define KLF_NOTELLSHELL
Definition: winuser.h:116
#define KLF_UNLOADPREVIOUS
Definition: winuser.h:113
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_VOLATILE
Definition: pseh2_64.h:208
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
DWORD LCID
Definition: nls.h:13
#define ProbeForWriteUnicodeString(Ptr)
Definition: probe.h:48
#define FileStandardInformation
Definition: propsheet.cpp:61
#define TRACE(s)
Definition: solgame.cpp:4
USHORT CodePage
Definition: ntuser.h:368
HKL hKL
Definition: ntuser.h:367
Definition: kbd.h:111
DWORD cLockObj
Definition: ntuser.h:209
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
ULONG_PTR ImageBase
Definition: kbdlayout.c:250
PBYTE pbSlots
Definition: kbdlayout.c:508
ULONG offData
Definition: kbdlayout.c:507
PBYTE pbImage
Definition: kbdlayout.c:504
ULONG_PTR ImageBase
Definition: kbdlayout.c:506
ULONG cbData
Definition: kbdlayout.c:505
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: kbd.h:81
WORD wMaxModBits
Definition: kbd.h:83
BYTE ModNumber[]
Definition: kbd.h:84
PTHREADINFO ptiList
Definition: win32.h:260
PPROCESSINFO ppi
Definition: win32.h:89
PTHREADINFO ptiSibling
Definition: win32.h:117
struct _CLIENTINFO * pClientInfo
Definition: win32.h:95
struct tagKL * KeyboardLayout
Definition: win32.h:91
FLONG TIF_flags
Definition: win32.h:96
struct _DESKTOP * rpdesk
Definition: win32.h:93
struct _WND * spwndDefaultIme
Definition: win32.h:132
struct _USER_MESSAGE_QUEUE * MessageQueue
Definition: win32.h:90
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: object.h:4
Definition: kbd.h:76
BYTE ModBits
Definition: kbd.h:78
BYTE Vk
Definition: kbd.h:77
BYTE nModifications
Definition: kbd.h:107
Definition: kbd.h:127
USHORT Vk
Definition: kbd.h:129
BYTE Vsc
Definition: kbd.h:128
Definition: ntuser.h:722
OBJECT_NAME_INFORMATION Info
Definition: kbdlayout.c:1822
PKBDTABLES pKbdTbl
Definition: input.h:12
PKBDNLSTABLES pKbdNlsTbl
Definition: input.h:14
ULONG Size
Definition: input.h:13
HANDLE hBase
Definition: input.h:11
struct tagKBDFILE * pkfNext
Definition: input.h:9
WCHAR awchKF[20]
Definition: input.h:10
HANDLE hFile
Definition: ntuser.h:114
KBDTABLE_MULTI_AUX_ENTRY AuxEntries[KBDTABLE_MULTI_MAX]
Definition: ntuser.h:124
KBDTABLE_MULTI Multi
Definition: ntuser.h:122
UINT nTables
Definition: kbd.h:203
Definition: input.h:18
DWORD dwKL_Flags
Definition: input.h:22
USHORT CodePage
Definition: input.h:27
PIMEINFOEX piiex
Definition: input.h:29
DWORD dwFontSigs
Definition: input.h:25
PKBDFILE spkf
Definition: input.h:24
HEAD head
Definition: input.h:19
HKL hkl
Definition: input.h:23
struct tagKL * pklNext
Definition: input.h:20
UINT iBaseCharset
Definition: input.h:26
struct tagKL * pklPrev
Definition: input.h:21
PCBYTE SIZE_T cbKey
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint16_t * LPWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const char * PCSTR
Definition: typedefs.h:52
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
#define UKL_NOACTIVATENEXT
Definition: undocuser.h:186
#define KL_UNLOAD
Definition: undocuser.h:183
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:175
#define IntReferenceThreadInfo(pti)
Definition: win32.h:170
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:30
BOOL APIENTRY co_IntGetCharsetInfo(LCID Locale, PCHARSETINFO pCs)
Definition: callback.c:1040
BOOL APIENTRY co_ClientImmLoadLayout(_In_ HKL hKL, _Inout_ PIMEINFOEX pImeInfoEx)
Definition: callback.c:1276
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1712
UINT APIENTRY NtUserGetKeyboardLayoutList(ULONG nBuff, HKL *pHklBuff)
Definition: kbdlayout.c:2010
static BOOL KbdIsBufInRange(_In_ const KBDVALIDATE *pv, _In_ const VOID *p, _In_ SIZE_T cb, _In_ SIZE_T cbAlign)
Definition: kbdlayout.c:513
static BOOL KbdCheckKeyNames(_In_ PKBDVALIDATE pv, _Inout_ VSC_LPWSTR **ppNames, _In_ PCSTR pszName)
Verifies and rebases the key name. This table ends with an entry that has vsc == 0.
Definition: kbdlayout.c:812
static BOOL APIENTRY co_IntUnloadKeyboardLayoutEx(_Inout_ PWINSTATION_OBJECT pWinSta, _Inout_ PKL pKL, _In_ DWORD dwFlags)
Definition: kbdlayout.c:1663
static UINT APIENTRY IntGetKeyboardLayoutList(_Inout_ PWINSTATION_OBJECT pWinSta, _In_ ULONG nBuff, _Out_ HKL *pHklBuff)
Definition: kbdlayout.c:94
static BOOL KbdCheckDeadKeys(_In_ PKBDVALIDATE pv, _Inout_ PKBDTABLES pTbl)
Verifies and rebases the dead keys (optional). This table ends with an entry that has dwBoth == 0.
Definition: kbdlayout.c:914
#define RVA(m, b)
Definition: kbdlayout.c:243
struct _KBDVALIDATE KBDVALIDATE
HKL NTAPI NtUserActivateKeyboardLayout(HKL hKL, ULONG Flags)
Definition: kbdlayout.c:2230
#define KBD_MAX_NLS_ENTRIES
Definition: kbdlayout.c:496
VOID FASTCALL IntReorderKeyboardLayouts(_Inout_ PWINSTATION_OBJECT pWinSta, _Inout_ PKL pNewKL)
Definition: kbdlayout.c:1415
VOID APIENTRY IntImmActivateLayout(_Inout_ PTHREADINFO pti, _Inout_ PKL pKL)
Definition: kbdlayout.c:1453
static BOOL KbdCheckNls(_In_ PKBDVALIDATE pv, _Inout_ PKBDNLSTABLES pNls)
Verifies and rebases the NLS (national language support; for Far-East) tables. These tables are count...
Definition: kbdlayout.c:970
DWORD gSystemFS
Definition: kbdlayout.c:24
PKL gspklBaseLayout
Definition: kbdlayout.c:22
static BOOL UserLoadKbdDll(_In_ HANDLE hKernelFile, _In_ ULONG offTable, _Out_ HANDLE *phModule, _Out_ PULONG pcbImage, _Out_ PKBDTABLES *ppKbdTables, _Out_ PKBDNLSTABLES *ppKbdNlsTables)
Definition: kbdlayout.c:1103
static BOOL KbdCheckWideString(_In_ const KBDVALIDATE *pv, _In_ const WCHAR *pwsz)
Verifies a wide string is terminated within the layout data (and is not unreasonably long).
Definition: kbdlayout.c:658
#define KBD_MAX_WCHTABLES
Definition: kbdlayout.c:489
static BOOL KbdRebaseSlot(_In_ PKBDVALIDATE pv, _Inout_ PVOID *ppSlot, _In_ SIZE_T cbMin, _In_ SIZE_T cbAlign, _In_ BOOL bRequired, _In_ PCSTR pszName)
Converts a pointer slot of the layout tables from a virtual address (relative to ImageBase) to a poin...
Definition: kbdlayout.c:547
static BOOL KbdCheckVkToWchars(_In_ PKBDVALIDATE pv, _Inout_ PKBDTABLES pTbl, _Out_ PBOOL pbLigature, _Out_ PBOOL pbDead)
Verifies and rebases the VK_TO_WCHAR_TABLE structure in the layout data.
Definition: kbdlayout.c:735
static BOOL APIENTRY IntUnloadKeyboardLayout(_Inout_ PWINSTATION_OBJECT pWinSta, _In_ HKL hKL)
Definition: kbdlayout.c:1710
struct tagKBDFILE_NAME KBDFILE_NAME
static BOOL KbdCheckDeadKeyNames(_In_ PKBDVALIDATE pv, _Inout_ PKBDTABLES pTbl)
Verifies and rebases the dead key names (optional). This array of strings ends with NULL.
Definition: kbdlayout.c:850
#define KBD_MAX_VKTOBIT
Definition: kbdlayout.c:488
PKL NTAPI UserHklToKbl(HKL hKl)
Definition: kbdlayout.c:1396
static BOOL KbdCheckLigatures(_In_ PKBDVALIDATE pv, _Inout_ PKBDTABLES pTbl)
Verifies and rebases the ligatures (optional). This table ends with an entry that has VirtualKey == 0...
Definition: kbdlayout.c:938
UINT gSystemCPCharSet
Definition: kbdlayout.c:25
#define KBDIMG_TAG
Definition: kbdlayout.c:239
#define CP_ACP
Definition: kbdlayout.c:18
static BOOL KbdMeasureTable(_In_ const KBDVALIDATE *pv, _In_ const VOID *pTable, _In_ SIZE_T cbElem, _In_ SIZE_T cbKey, _In_ SIZE_T cbAlign, _In_ ULONG cMax, _Out_ PULONG pcElems, _In_ PCSTR pszName)
Measures a table that ends with a terminating element, verifying every element (the terminator includ...
Definition: kbdlayout.c:609
PKL FASTCALL IntHKLtoPKL(_Inout_ PTHREADINFO pti, _In_ HKL hKL)
Definition: kbdlayout.c:34
#define KBD_MAX_NAME_CCH
Definition: kbdlayout.c:497
#define KBD_MAX_KEYNAMES
Definition: kbdlayout.c:491
HKL APIENTRY co_UserActivateKeyboardLayout(_Inout_ PKL pKL, _In_ ULONG uFlags, _In_opt_ PWND pWnd)
Definition: kbdlayout.c:1525
static BOOL KbdCheckVscToVk(_In_ PKBDVALIDATE pv, _Inout_ PVSC_VK *ppVscVk, _In_ PCSTR pszName)
Verifies and rebases the VSC -> VK table for the E0/E1 prefixes. They end with an entry that has Vsc ...
Definition: kbdlayout.c:892
static PVOID KbdLoadImage(_In_ HANDLE hKernelFile, _Out_ PULONG pcbImage, _Out_ PKBDIMAGE_INFO pInfo)
Definition: kbdlayout.c:404
HKL NTAPI NtUserLoadKeyboardLayoutEx(_In_ HANDLE hFile, _In_ ULONG offTable, _In_opt_ PKBDTABLE_MULTI_EX pMulti, _In_opt_ HKL hOldKL, _In_ PUNICODE_STRING puszKLID, _In_ ULONG dwNewKL, _In_ UINT Flags)
Definition: kbdlayout.c:2129
BOOL UserUnloadKbl(PKL pKl)
Definition: kbdlayout.c:1328
PKBDFILE gpkfList
Definition: kbdlayout.c:23
struct tagKBDFILE_NAME * PKBDFILE_NAME
PIMEINFOEX FASTCALL co_UserImmLoadLayout(_In_ HKL hKL)
Invokes imm32!ImmLoadLayout and returns PIMEINFOEX.
Definition: kbdlayout.c:1722
#define KBD_MAX_LIGATURES
Definition: kbdlayout.c:495
static BOOL FASTCALL IntEqualDir(_In_ PCUNICODE_STRING pustrParent, _In_ PCUNICODE_STRING pustrDir)
Definition: kbdlayout.c:1834
HKL ghKLSentToShell
Definition: kbdlayout.c:26
#define KBD_MAX_DEADNAMES
Definition: kbdlayout.c:492
static VOID UnloadKbdFile(_In_ PKBDFILE pkf)
Definition: kbdlayout.c:1301
static BOOL KbdCheckModifiers(_In_ PKBDVALIDATE pv, _Inout_ PKBDTABLES pTbl)
Verifies and rebases the modifiers in the main tables of the layout data.
Definition: kbdlayout.c:687
#define KBDIMG_MAXSIZE
Definition: kbdlayout.c:240
HKL APIENTRY co_IntActivateKeyboardLayout(_Inout_ PWINSTATION_OBJECT pWinSta, _In_ HKL hKL, _In_ ULONG uFlags, _In_opt_ PWND pWnd)
Definition: kbdlayout.c:1640
HKL APIENTRY co_IntLoadKeyboardLayoutEx(_Inout_ PWINSTATION_OBJECT pWinSta, _In_ HANDLE hKernelFile, _In_opt_ HKL hOldKL, _In_ ULONG offTable, _In_ PUNICODE_STRING puszSafeKLID, _In_ HKL hNewKL, _In_ UINT Flags)
Definition: kbdlayout.c:1743
BOOL APIENTRY NtUserUnloadKeyboardLayout(HKL hKl)
Definition: kbdlayout.c:2255
BOOL APIENTRY NtUserGetKeyboardLayoutName(_Inout_ PUNICODE_STRING pustrName)
Definition: kbdlayout.c:2064
#define KBD_MAX_VSCVK
Definition: kbdlayout.c:494
static PVOID KbdBuildImage(_In_ PVOID pvRaw, _In_ SIZE_T cbRaw, _Out_ PULONG pcbImage, _Out_ PKBDIMAGE_INFO pInfo)
Build the image of the keyboard layout file without executing it, due to security reasons.
Definition: kbdlayout.c:271
#define KBD_MAX_LIGATURE_CCH
Definition: kbdlayout.c:499
#define KBD_MAX_DEADKEYS
Definition: kbdlayout.c:493
HKL FASTCALL UserGetKeyboardLayout(DWORD dwThreadId)
Definition: kbdlayout.c:1967
struct _KBDVALIDATE * PKBDVALIDATE
#define KBD_REBASE(pv, field, cbMin, cbAlign, bRequired)
Definition: kbdlayout.c:599
static VOID co_IntSetKeyboardLayoutForProcess(PPROCESSINFO ppi, PKL pKL)
Definition: kbdlayout.c:1490
#define KBD_MAX_MOD_COLUMNS
Definition: kbdlayout.c:498
struct _KBDIMAGE_INFO * PKBDIMAGE_INFO
struct _KBDIMAGE_INFO KBDIMAGE_INFO
static PKBDFILE UserLoadKbdFile(_In_ HANDLE hKernelFile, _In_ ULONG offTable, _In_ PCUNICODE_STRING pustrKLID)
Definition: kbdlayout.c:1179
PKL W32kGetDefaultKeyLayout(VOID)
Definition: kbdlayout.c:1369
HANDLE FASTCALL IntVerifyKeyboardFileHandle(HANDLE hFile)
Validates that the given user-mode handle corresponds to an opened file in SystemRoot\system32.
Definition: kbdlayout.c:1890
static PKL co_UserLoadKbdLayout(_In_ HANDLE hKernelFile, _In_ ULONG offTable, _In_ const UNICODE_STRING *pustrKLID, _In_ HKL hKL)
Definition: kbdlayout.c:1221
static BOOL KbdRebaseTables(_In_ PBYTE pbImage, _In_ const KBDIMAGE_INFO *pInfo, _Inout_ PKBDTABLES pTbl, _Inout_opt_ PKBDNLSTABLES pNls)
Adjusts the pointers inside the layout tables, and validates the whole layout.
Definition: kbdlayout.c:1037
static NTSTATUS IntQueryHandleName(HANDLE hObject, PKBDFILE_NAME pName)
Definition: kbdlayout.c:1827
#define KBD_MAX_VKTOWCH
Definition: kbdlayout.c:490
BOOL NTAPI UserSetDefaultInputLang(HKL hKl)
Definition: kbdlayout.c:1440
static __inline VOID KbdUnloadImage(_In_opt_ PVOID pvImageBase)
Definition: kbdlayout.c:469
static __inline BOOL KbdIsRangeInData(_In_ const KBDIMAGE_INFO *pInfo, _In_ ULONG_PTR off, _In_ SIZE_T cb)
Definition: kbdlayout.c:479
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1497
BOOL FASTCALL UserMarkObjectDestroy(PVOID Object)
Definition: object.c:624
PVOID FASTCALL UserAssignmentLock(PVOID *ppvObj, PVOID pvNew)
Definition: object.c:861
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:647
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:740
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
Definition: object.c:572
#define USERTAG_IME
Definition: tags.h:240
#define WSS_NOIO
Definition: winsta.h:9
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:21
#define ERROR_INVALID_FLAGS
Definition: winerror.h:907
_In_ UINT _In_ UINT cEntries
Definition: wingdi.h:4067
#define ANSI_CHARSET
Definition: wingdi.h:383
#define FS_LATIN1
Definition: wingdi.h:560
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
#define ObDereferenceObject
Definition: obfuncs.h:203
#define NT_ASSERT
Definition: rtlfuncs.h:3334
unsigned char BYTE
Definition: xxhash.c:193