https://git.reactos.org/?p=reactos.git;a=commitdiff;h=eb4d13c823f1d444e877a…
commit eb4d13c823f1d444e877a704eb6a15ea541998c3
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Nov 3 22:45:51 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 3 22:45:51 2023 +0900
[IMM32][SDK] Implement CtfImm(Hide,Restore)ToolbarWnd (#5863)
- Add Imm32GetFn helper function.
- Implement CtfImmHideToolbarWnd and
CtfImmRestoreToolbarWnd functions.
- Add them to <imm32_undoc.h>.
CORE-19268
---
dll/win32/imm32/ctf.c | 178 ++++++++++++++++++++++++++++++++++----
dll/win32/imm32/imm32.spec | 2 +-
sdk/include/reactos/imm32_undoc.h | 2 +
3 files changed, 165 insertions(+), 17 deletions(-)
diff --git a/dll/win32/imm32/ctf.c b/dll/win32/imm32/ctf.c
index b403cb3ad59..78f9b09acb9 100644
--- a/dll/win32/imm32/ctf.c
+++ b/dll/win32/imm32/ctf.c
@@ -6,18 +6,127 @@
*/
#include "precomp.h"
+#include <msctf.h>
+#include <ctfutb.h>
WINE_DEFAULT_DEBUG_CHANNEL(imm);
-/*
- * NOTE: Microsoft CTF protocol has vulnerability.
- * If insecure, we don't follow the dangerous design.
- *
- *
https://www.zdnet.com/article/vulnerability-in-microsoft-ctf-protocol-goes-…
- *
https://googleprojectzero.blogspot.com/2019/08/down-rabbit-hole.html
+BOOL
+Imm32GetFn(
+ _Inout_opt_ FARPROC *ppfn,
+ _Inout_ HINSTANCE *phinstDLL,
+ _In_ LPCWSTR pszDllName,
+ _In_ LPCSTR pszFuncName)
+{
+ WCHAR szPath[MAX_PATH];
+
+ if (*ppfn)
+ return TRUE;
+
+ if (*phinstDLL == NULL)
+ {
+ Imm32GetSystemLibraryPath(szPath, _countof(szPath), pszDllName);
+ *phinstDLL = LoadLibraryExW(szPath, NULL, 0);
+ if (*phinstDLL == NULL)
+ return FALSE;
+ }
+
+ *ppfn = (FARPROC)GetProcAddress(*phinstDLL, pszFuncName);
+ return *ppfn != NULL;
+}
+
+#define IMM32_GET_FN(ppfn, phinstDLL, dll_name, func_name) \
+ Imm32GetFn((FARPROC*)(ppfn), (phinstDLL), (dll_name), #func_name)
+
+/***********************************************************************
+ * OLE32.DLL
*/
-/*
+HINSTANCE g_hOle32 = NULL;
+
+#define OLE32_FN(name) g_pfnOLE32_##name
+
+typedef HRESULT (WINAPI *FN_CoInitializeEx)(LPVOID, DWORD);
+typedef VOID (WINAPI *FN_CoUninitialize)(VOID);
+typedef HRESULT (WINAPI *FN_CoRegisterInitializeSpy)(IInitializeSpy*, ULARGE_INTEGER*);
+typedef HRESULT (WINAPI *FN_CoRevokeInitializeSpy)(ULARGE_INTEGER);
+
+FN_CoInitializeEx OLE32_FN(CoInitializeEx) = NULL;
+FN_CoUninitialize OLE32_FN(CoUninitialize) = NULL;
+FN_CoRegisterInitializeSpy OLE32_FN(CoRegisterInitializeSpy) = NULL;
+FN_CoRevokeInitializeSpy OLE32_FN(CoRevokeInitializeSpy) = NULL;
+
+#define Imm32GetOle32Fn(func_name) \
+ IMM32_GET_FN(&OLE32_FN(func_name), &g_hOle32, L"ole32.dll",
#func_name)
+
+HRESULT Imm32CoInitializeEx(VOID)
+{
+ if (!Imm32GetOle32Fn(CoInitializeEx))
+ return E_FAIL;
+
+ return OLE32_FN(CoInitializeEx)(NULL, COINIT_APARTMENTTHREADED);
+}
+
+VOID Imm32CoUninitialize(VOID)
+{
+ if (!Imm32GetOle32Fn(CoUninitialize))
+ return;
+
+ OLE32_FN(CoUninitialize)();
+}
+
+HRESULT Imm32CoRegisterInitializeSpy(IInitializeSpy* spy, ULARGE_INTEGER* cookie)
+{
+ if (!Imm32GetOle32Fn(CoRegisterInitializeSpy))
+ return E_FAIL;
+
+ return OLE32_FN(CoRegisterInitializeSpy)(spy, cookie);
+}
+
+HRESULT Imm32CoRevokeInitializeSpy(ULARGE_INTEGER cookie)
+{
+ if (!Imm32GetOle32Fn(CoRevokeInitializeSpy))
+ return E_FAIL;
+
+ return OLE32_FN(CoRevokeInitializeSpy)(cookie);
+}
+
+/***********************************************************************
+ * MSCTF.DLL
+ */
+
+HINSTANCE g_hMsctf = NULL;
+
+#define MSCTF_FN(name) g_pfnMSCTF_##name
+
+typedef HRESULT (WINAPI *FN_TF_CreateLangBarMgr)(ITfLangBarMgr**);
+typedef VOID (WINAPI *FN_TF_InvalidAssemblyListCacheIfExist)(VOID);
+
+FN_TF_CreateLangBarMgr MSCTF_FN(TF_CreateLangBarMgr) =
NULL;
+FN_TF_InvalidAssemblyListCacheIfExist MSCTF_FN(TF_InvalidAssemblyListCacheIfExist) =
NULL;
+
+#define Imm32GetMsctfFn(func_name) \
+ IMM32_GET_FN(&MSCTF_FN(func_name), &g_hMsctf, L"msctf.dll",
#func_name)
+
+HRESULT Imm32TF_CreateLangBarMgr(_Inout_ ITfLangBarMgr **ppBarMgr)
+{
+ if (!Imm32GetMsctfFn(TF_CreateLangBarMgr))
+ return E_FAIL;
+
+ return MSCTF_FN(TF_CreateLangBarMgr)(ppBarMgr);
+}
+
+VOID Imm32TF_InvalidAssemblyListCacheIfExist(VOID)
+{
+ if (!Imm32GetMsctfFn(TF_InvalidAssemblyListCacheIfExist))
+ return;
+
+ MSCTF_FN(TF_InvalidAssemblyListCacheIfExist)();
+}
+
+/***********************************************************************
+ * CTF IME support
+ *
* TSF stands for "Text Services Framework". "Cicero" is the code
name of TSF.
* CTF stands for "Cicero-aware Text Framework".
*
@@ -385,22 +494,59 @@ CtfImmTIMActivate(_In_ HKL hKL)
}
/***********************************************************************
- * CtfImmRestoreToolbarWnd(IMM32.@)
+ * CtfImmHideToolbarWnd(IMM32.@)
+ *
+ * Used with CtfImmRestoreToolbarWnd.
*/
-VOID WINAPI
-CtfImmRestoreToolbarWnd(_In_ DWORD dwStatus)
+DWORD WINAPI
+CtfImmHideToolbarWnd(VOID)
{
- FIXME("(0x%lx)\n", dwStatus);
+ ITfLangBarMgr *pBarMgr;
+ DWORD dwShowFlags = 0;
+ BOOL bShown;
+
+ TRACE("()\n");
+
+ if (FAILED(Imm32TF_CreateLangBarMgr(&pBarMgr)))
+ return dwShowFlags;
+
+ if (SUCCEEDED(pBarMgr->lpVtbl->GetShowFloatingStatus(pBarMgr,
&dwShowFlags)))
+ {
+ bShown = !(dwShowFlags & 0x800);
+ dwShowFlags &= 0xF;
+ if (bShown)
+ pBarMgr->lpVtbl->ShowFloating(pBarMgr, 8);
+ }
+
+ pBarMgr->lpVtbl->Release(pBarMgr);
+ return dwShowFlags;
}
/***********************************************************************
- * CtfImmHideToolbarWnd(IMM32.@)
+ * CtfImmRestoreToolbarWnd(IMM32.@)
+ *
+ * Used with CtfImmHideToolbarWnd.
*/
-DWORD WINAPI
-CtfImmHideToolbarWnd(VOID)
+VOID WINAPI
+CtfImmRestoreToolbarWnd(
+ _In_ LPVOID pUnused,
+ _In_ DWORD dwShowFlags)
{
- FIXME("()\n");
- return 0;
+ HRESULT hr;
+ ITfLangBarMgr *pBarMgr;
+
+ UNREFERENCED_PARAMETER(pUnused);
+
+ TRACE("(%p, 0x%X)\n", pUnused, dwShowFlags);
+
+ hr = Imm32TF_CreateLangBarMgr(&pBarMgr);
+ if (FAILED(hr))
+ return;
+
+ if (dwShowFlags)
+ pBarMgr->lpVtbl->ShowFloating(pBarMgr, dwShowFlags);
+
+ pBarMgr->lpVtbl->Release(pBarMgr);
}
BOOL Imm32InsideLoaderLock(VOID)
diff --git a/dll/win32/imm32/imm32.spec b/dll/win32/imm32/imm32.spec
index 89293195098..3a706be14b4 100644
--- a/dll/win32/imm32/imm32.spec
+++ b/dll/win32/imm32/imm32.spec
@@ -5,7 +5,7 @@
@ stdcall CtfImmIsCiceroStartedInThread()
@ stdcall CtfImmIsTextFrameServiceDisabled()
@ stdcall CtfImmTIMActivate(ptr)
-@ stdcall CtfImmRestoreToolbarWnd(long)
+@ stdcall CtfImmRestoreToolbarWnd(ptr long)
@ stdcall CtfImmHideToolbarWnd()
@ stdcall CtfImmDispatchDefImeMessage(ptr long ptr ptr)
@ stdcall CtfImmIsGuidMapEnable(ptr)
diff --git a/sdk/include/reactos/imm32_undoc.h b/sdk/include/reactos/imm32_undoc.h
index d2622dd8423..61904db0b13 100644
--- a/sdk/include/reactos/imm32_undoc.h
+++ b/sdk/include/reactos/imm32_undoc.h
@@ -27,6 +27,8 @@ HRESULT WINAPI CtfAImmDeactivate(_In_ BOOL bDestroy);
BOOL WINAPI CtfAImmIsIME(_In_ HKL hKL);
BOOL WINAPI CtfImmIsCiceroStartedInThread(VOID);
VOID WINAPI CtfImmSetAppCompatFlags(_In_ DWORD dwFlags);
+DWORD WINAPI CtfImmHideToolbarWnd(VOID);
+VOID WINAPI CtfImmRestoreToolbarWnd(_In_ LPVOID pUnused, _In_ DWORD dwShowFlags);
LRESULT WINAPI
CtfImmDispatchDefImeMessage(