VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2020-07-21 10:59:44 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2020-07-21 12:47:20 +0200
commitf9782fb3f6393b967d2997feff85d59c01a7db80 (patch)
treebe475906690b04857b551003c47b041e2b286553 /src/Common/Dlgcode.c
parent425e4e7d365795b820fa145403b2be372894c48b (diff)
downloadVeraCrypt-f9782fb3f6393b967d2997feff85d59c01a7db80.tar.gz
VeraCrypt-f9782fb3f6393b967d2997feff85d59c01a7db80.zip
Windows: Implement detection of Hibernate and Fast Startup and disable them if RAM encryption is activated.
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 0203a931..7a4f473e 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -14896,3 +14896,76 @@ void PasswordEditDropTarget::GotDrop(CLIPFORMAT format)
}
}
+
+/*
+ * Query the status of Hibernate and Fast Startup
+ */
+
+typedef BOOLEAN (WINAPI *GetPwrCapabilitiesFn)(
+ PSYSTEM_POWER_CAPABILITIES lpspc
+);
+
+BOOL GetHibernateStatus (BOOL& bHibernateEnabled, BOOL& bHiberbootEnabled)
+{
+ wchar_t szPowrProfPath[MAX_PATH] = {0};
+ HMODULE hPowrProf = NULL;
+ BOOL bResult = FALSE;
+
+ bHibernateEnabled = bHiberbootEnabled = FALSE;
+
+ if (GetSystemDirectory(szPowrProfPath, MAX_PATH))
+ StringCchCatW (szPowrProfPath, MAX_PATH, L"\\PowrProf.dll");
+ else
+ StringCchCopyW (szPowrProfPath, MAX_PATH, L"C:\\Windows\\System32\\PowrProf.dll");
+
+ hPowrProf = LoadLibrary (szPowrProfPath);
+ if (hPowrProf)
+ {
+ GetPwrCapabilitiesFn GetPwrCapabilitiesPtr = (GetPwrCapabilitiesFn) GetProcAddress (hPowrProf, "GetPwrCapabilities");
+ if ( GetPwrCapabilitiesPtr)
+ {
+ SYSTEM_POWER_CAPABILITIES spc;
+ BOOLEAN bRet = GetPwrCapabilitiesPtr (&spc);
+ if (bRet)
+ {
+ DWORD dwHibernateEnabled = 0;
+ DWORD dwHiberbootEnabled = 0;
+
+ if (spc.SystemS4)
+ {
+ dwHibernateEnabled = 1;
+ if(!ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Control\\Power", L"HibernateEnabled", &dwHibernateEnabled))
+ {
+ // starting from Windows 10 1809 (Build 17763), HibernateEnabledDefault is used when HibernateEnabled is absent
+ if (IsOSVersionAtLeast (WIN_10, 0) && CurrentOSBuildNumber >= 17763)
+ ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Control\\Power", L"HibernateEnabledDefault", &dwHibernateEnabled);
+ }
+ }
+
+ // check if Fast Startup / Hybrid Boot is enabled
+ if (IsOSVersionAtLeast (WIN_8, 0) && spc.spare2[0])
+ {
+ dwHiberbootEnabled = 1;
+ ReadLocalMachineRegistryDword (L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power", L"HiberbootEnabled", &dwHiberbootEnabled);
+ }
+
+ if (dwHibernateEnabled)
+ bHibernateEnabled = TRUE;
+ else
+ bHibernateEnabled = FALSE;
+
+ if (dwHiberbootEnabled)
+ bHiberbootEnabled = TRUE;
+ else
+ bHiberbootEnabled = FALSE;
+
+ bResult = TRUE;
+ }
+ }
+
+ FreeLibrary (hPowrProf);
+ }
+
+ return bResult;
+}
+