VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2024-08-04 10:25:12 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2024-08-04 10:25:12 +0200
commitc8b9a73916b727d973cf51f1d7ebac3b9670d06b (patch)
tree82b156c8a0e19fccfa09ee84a0aef9692804c3d1 /src
parent71215f1a2541483ac82050fc3cb8af3a3e06cc24 (diff)
downloadVeraCrypt-c8b9a73916b727d973cf51f1d7ebac3b9670d06b.tar.gz
VeraCrypt-c8b9a73916b727d973cf51f1d7ebac3b9670d06b.zip
Windows: Fix rare cases being stuck in Secure Desktop after it is used for password entry
Cause seems to be IME as documented in KeePass project (https://keepass.info/help/kb/sec_desk.html#ime). We use the same approach as KeePass to disable IME in Secure Desktop. This commit also add few changes: - we switch to secure desktop only if SetThreadDesktop succeeds - we call SwitchDesktop to switch to original desktop only if we actually succeeded in displaying secure desktop
Diffstat (limited to 'src')
-rw-r--r--src/Common/Dlgcode.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index ce86c9da..488b050f 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -13921,20 +13921,33 @@ static unsigned int __stdcall SecureDesktopThread( LPVOID lpThreadParameter )
StringCbCopy(SecureDesktopName, sizeof (SecureDesktopName), pParam->szDesktopName);
pParam->hDesk = hSecureDesk;
- // wait for SwitchDesktop to succeed before using it for current thread
- while (true)
+ bNewDesktopSet = SetThreadDesktop (hSecureDesk);
+
+ if (bNewDesktopSet)
{
- if (SwitchDesktop (hSecureDesk))
+ // call ImmDisableIME from imm32.dll to disable IME since it can create issue with secure desktop
+ // cf: https://keepass.info/help/kb/sec_desk.html#ime
+ HMODULE hImmDll = LoadLibraryEx (L"imm32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (hImmDll)
{
- break;
+ typedef BOOL (WINAPI *ImmDisableIME_t)(DWORD);
+ ImmDisableIME_t ImmDisableIME = (ImmDisableIME_t) GetProcAddress (hImmDll, "ImmDisableIME");
+ if (ImmDisableIME)
+ {
+ ImmDisableIME (0);
+ }
}
- Sleep (SECUREDESKTOP_MONOTIR_PERIOD);
- }
- bNewDesktopSet = SetThreadDesktop (hSecureDesk);
+ // wait for SwitchDesktop to succeed before using it for current thread
+ while (true)
+ {
+ if (SwitchDesktop (hSecureDesk))
+ {
+ break;
+ }
+ Sleep (SECUREDESKTOP_MONOTIR_PERIOD);
+ }
- if (bNewDesktopSet)
- {
// create the thread that will ensure that VeraCrypt secure desktop has always user input
// this is done only if the stop event is created successfully
HANDLE hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -13964,6 +13977,12 @@ static unsigned int __stdcall SecureDesktopThread( LPVOID lpThreadParameter )
}
pParam->bDlgDisplayed = TRUE;
+
+ // free imm32.dll handle
+ if (hImmDll)
+ {
+ FreeLibrary (hImmDll);
+ }
}
else
{
@@ -14084,19 +14103,20 @@ INT_PTR SecureDesktopDialogBoxParam(
// dialog box was indeed displayed in Secure Desktop
retValue = param.retValue;
bSuccess = TRUE;
+
+ // switch back to the original desktop
+ while (!SwitchDesktop (hOriginalDesk))
+ {
+ Sleep (SECUREDESKTOP_MONOTIR_PERIOD);
+ }
+
+ SetThreadDesktop (hOriginalDesk);
}
- }
- if (param.hDesk)
- {
- while (!SwitchDesktop (hOriginalDesk))
+ if (param.hDesk)
{
- Sleep (SECUREDESKTOP_MONOTIR_PERIOD);
+ CloseDesktop (param.hDesk);
}
-
- SetThreadDesktop (hOriginalDesk);
-
- CloseDesktop (param.hDesk);
}
// get the new list of ctfmon.exe processes in order to find the ID of the