xref: /reactos/dll/win32/imm32/ctf.c (revision 372a445a)
1 /*
2  * PROJECT:     ReactOS IMM32
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Implementing the IMM32 Cicero-aware Text Framework (CTF)
5  * COPYRIGHT:   Copyright 2022 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
10 WINE_DEFAULT_DEBUG_CHANNEL(imm);
11 
12 /*
13  * NOTE: Microsoft CTF protocol has vulnerability.
14  *       If insecure, we don't follow the dangerous design.
15  *
16  * https://www.zdnet.com/article/vulnerability-in-microsoft-ctf-protocol-goes-back-to-windows-xp/
17  * https://googleprojectzero.blogspot.com/2019/08/down-rabbit-hole.html
18  */
19 
20 // Win: LoadCtfIme
21 HMODULE APIENTRY Imm32LoadCtfIme(VOID)
22 {
23     FIXME("()\n");
24     return NULL;
25 }
26 
27 // Win: Internal_CtfImeDestroyInputContext
28 HRESULT APIENTRY Imm32CtfImeDestroyInputContext(HIMC hIMC)
29 {
30     if (!Imm32LoadCtfIme())
31         return E_FAIL;
32 #if 1
33     FIXME("(%p)\n", hIMC);
34     return E_NOTIMPL;
35 #else
36     return g_pfnCtfImeDestroyInputContext(hIMC);
37 #endif
38 }
39 
40 // Win: CtfImmTIMDestroyInputContext
41 HRESULT APIENTRY CtfImmTIMDestroyInputContext(HIMC hIMC)
42 {
43     if (!Imm32IsCiceroMode() || (GetWin32ClientInfo()->dwCompatFlags2 & 2))
44         return E_NOINTERFACE;
45 
46     return Imm32CtfImeDestroyInputContext(hIMC);
47 }
48 
49 // Win: CtfImmTIMCreateInputContext
50 HRESULT APIENTRY CtfImmTIMCreateInputContext(HIMC hIMC)
51 {
52     TRACE("(%p)\n", hIMC);
53     return E_NOTIMPL;
54 }
55 
56 /***********************************************************************
57  *		CtfImmIsCiceroEnabled (IMM32.@)
58  */
59 BOOL WINAPI CtfImmIsCiceroEnabled(VOID)
60 {
61     return Imm32IsCiceroMode();
62 }
63 
64 /***********************************************************************
65  *		CtfImmIsTextFrameServiceDisabled(IMM32.@)
66  */
67 BOOL WINAPI CtfImmIsTextFrameServiceDisabled(VOID)
68 {
69     return !!(GetWin32ClientInfo()->CI_flags & CI_TFSDISABLED);
70 }
71 
72 /***********************************************************************
73  *		CtfImmTIMActivate(IMM32.@)
74  */
75 HRESULT WINAPI CtfImmTIMActivate(HKL hKL)
76 {
77     FIXME("(%p)\n", hKL);
78     return E_NOTIMPL;
79 }
80 
81 /***********************************************************************
82  *		CtfImmRestoreToolbarWnd(IMM32.@)
83  */
84 VOID WINAPI CtfImmRestoreToolbarWnd(DWORD dwStatus)
85 {
86     FIXME("(0x%lx)\n", dwStatus);
87 }
88 
89 /***********************************************************************
90  *		CtfImmHideToolbarWnd(IMM32.@)
91  */
92 DWORD WINAPI CtfImmHideToolbarWnd(VOID)
93 {
94     FIXME("()\n");
95     return 0;
96 }
97 
98 /***********************************************************************
99  *		CtfImmDispatchDefImeMessage(IMM32.@)
100  */
101 LRESULT WINAPI CtfImmDispatchDefImeMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
102 {
103     FIXME("(%p, %u, %p, %p)\n", hWnd, uMsg, wParam, lParam);
104     return 0;
105 }
106 
107 /***********************************************************************
108  *		CtfImmIsGuidMapEnable(IMM32.@)
109  */
110 BOOL WINAPI CtfImmIsGuidMapEnable(HIMC hIMC)
111 {
112     DWORD dwThreadId;
113     HKL hKL;
114     PIMEDPI pImeDpi;
115     BOOL ret = FALSE;
116 
117     TRACE("(%p)\n", hIMC);
118 
119     if (!Imm32IsCiceroMode() || Imm32Is16BitMode())
120         return ret;
121 
122     dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
123     hKL = GetKeyboardLayout(dwThreadId);
124 
125     if (IS_IME_HKL(hKL))
126         return ret;
127 
128     pImeDpi = Imm32FindOrLoadImeDpi(hKL);
129     if (!pImeDpi)
130         return ret;
131 
132     if (pImeDpi->CtfImeIsGuidMapEnable)
133         ret = pImeDpi->CtfImeIsGuidMapEnable(hIMC);
134 
135     ImmUnlockImeDpi(pImeDpi);
136     return ret;
137 }
138 
139 /***********************************************************************
140  *		CtfImmGetGuidAtom(IMM32.@)
141  */
142 HRESULT WINAPI CtfImmGetGuidAtom(HIMC hIMC, DWORD dwUnknown, LPDWORD pdwGuidAtom)
143 {
144     HRESULT hr = E_FAIL;
145     PIMEDPI pImeDpi;
146     DWORD dwThreadId;
147     HKL hKL;
148 
149     TRACE("(%p, 0xlX, %p)\n", hIMC, dwUnknown, pdwGuidAtom);
150 
151     *pdwGuidAtom = 0;
152 
153     if (!Imm32IsCiceroMode() || Imm32Is16BitMode())
154         return hr;
155 
156     dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
157     hKL = GetKeyboardLayout(dwThreadId);
158     if (IS_IME_HKL(hKL))
159         return S_OK;
160 
161     pImeDpi = Imm32FindOrLoadImeDpi(hKL);
162     if (!pImeDpi)
163         return hr;
164 
165     if (pImeDpi->CtfImeGetGuidAtom)
166         hr = pImeDpi->CtfImeGetGuidAtom(hIMC, dwUnknown, pdwGuidAtom);
167 
168     ImmUnlockImeDpi(pImeDpi);
169     return hr;
170 }
171