diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-18 00:56:17 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-20 02:05:45 +0100 |
commit | 8e8e273e11ee4198a369f0e5745b1544a70a5809 (patch) | |
tree | 8ee0011d2e9e8ad5be05056421df44ff26ff0c2e /src/Setup | |
parent | 6452fb3693a87a4585dde2ce3c2070e38fc2a071 (diff) | |
download | VeraCrypt-8e8e273e11ee4198a369f0e5745b1544a70a5809.tar.gz VeraCrypt-8e8e273e11ee4198a369f0e5745b1544a70a5809.zip |
Windows: Correctly remove driver file veracrypt.sys during uninstall on Windows 64-bit. Implement deleting locked files after machine reboot.
Diffstat (limited to 'src/Setup')
-rw-r--r-- | src/Setup/Setup.c | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index 02a361c5..7c382986 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -88,8 +88,19 @@ void localcleanup (void) CloseAppSetupMutex ();
}
+BOOL ForceDeleteFile (LPCWSTR szFileName)
+{
+ if (!DeleteFile (szFileName))
+ {
+ /* delete the renamed file when the machine reboots */
+ return MoveFileEx (szFileName, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
+ }
+ else
+ return TRUE;
+}
+
BOOL StatDeleteFile (wchar_t *lpszFile, BOOL bCheckForOldFile)
{
struct __stat64 st;
@@ -99,13 +110,15 @@ BOOL StatDeleteFile (wchar_t *lpszFile, BOOL bCheckForOldFile) StringCbCopyW (szOldPath, sizeof(szOldPath), lpszFile);
StringCbCatW (szOldPath, sizeof(szOldPath), VC_FILENAME_RENAMED_SUFFIX);
if (_wstat64 (szOldPath, &st) == 0)
- DeleteFile (szOldPath);
+ {
+ ForceDeleteFile (szOldPath);
+ }
}
if (_wstat64 (lpszFile, &st) == 0)
- return DeleteFile (lpszFile);
+ return ForceDeleteFile (lpszFile);
else
return TRUE;
}
@@ -674,9 +687,9 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) StringCbCatW (szDestDir, MAX_PATH, L"\\");
for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
{
- BOOL bResult;
+ BOOL bResult, driver64 = FALSE;
wchar_t szDir[TC_MAX_PATH];
if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0)
{
@@ -702,8 +715,11 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) if (*szFiles[i] == L'A')
StringCbCopyW (szDir, sizeof(szDir), szDestDir);
else if (*szFiles[i] == L'D')
{
+ if (Is64BitOs ())
+ driver64 = TRUE;
+
GetSystemDirectory (szDir, ARRAYSIZE (szDir));
x = wcslen (szDir);
if (szDir[x - 1] != L'\\')
@@ -738,17 +754,14 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) bResult = TCCopyFile (mp, szTmp);
}
else
{
- BOOL driver64 = FALSE;
-
StringCchCopyNW (curFileName, ARRAYSIZE(curFileName), szFiles[i] + 1, wcslen (szFiles[i]) - 1);
curFileName [wcslen (szFiles[i]) - 1] = 0;
if (Is64BitOs ()
&& wcscmp (szFiles[i], L"Dveracrypt.sys") == 0)
{
- driver64 = TRUE;
StringCbCopyNW (curFileName, sizeof(curFileName), FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER));
}
if (Is64BitOs ()
@@ -891,15 +904,15 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) // delete files from legacy path
if (FileExists (favoritesLegacyFile.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
- DeleteFile (favoritesLegacyFile.c_str());
+ ForceDeleteFile (favoritesLegacyFile.c_str());
}
if (FileExists (serviceLegacyPath.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
- DeleteFile (serviceLegacyPath.c_str());
+ ForceDeleteFile (serviceLegacyPath.c_str());
}
EnableWow64FsRedirection (TRUE);
}
@@ -907,9 +920,14 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) }
}
else
{
+ if (driver64)
+ EnableWow64FsRedirection (FALSE);
bResult = StatDeleteFile (szTmp, TRUE);
+ if (driver64)
+ EnableWow64FsRedirection (TRUE);
+
if (bResult && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0)
{
if (Is64BitOs ())
EnableWow64FsRedirection (FALSE);
@@ -922,29 +940,29 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) // delete all files related to system favorites service
if (FileExists (favoritesFile.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) favoritesFile.c_str());
- DeleteFile (favoritesFile.c_str());
+ ForceDeleteFile (favoritesFile.c_str());
}
if (FileExists (servicePath.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) servicePath.c_str());
- DeleteFile (servicePath.c_str());
+ ForceDeleteFile (servicePath.c_str());
}
if (Is64BitOs ())
{
if (FileExists (favoritesLegacyFile.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
- DeleteFile (favoritesLegacyFile.c_str());
+ ForceDeleteFile (favoritesLegacyFile.c_str());
}
if (FileExists (serviceLegacyPath.c_str()))
{
RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
- DeleteFile (serviceLegacyPath.c_str());
+ ForceDeleteFile (serviceLegacyPath.c_str());
}
EnableWow64FsRedirection (TRUE);
}
@@ -1731,9 +1749,9 @@ BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir) if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk");
- DeleteFile (szTmp2);
+ StatDeleteFile (szTmp2, FALSE);
// Start menu group
RemoveMessage ((HWND) hwndDlg, szLinkDir);
if (StatRemoveDirectory (szLinkDir) == FALSE)
@@ -1853,9 +1871,9 @@ BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL if (CreateLink (szTmp3, L"appwiz.cpl", szTmp2, szTmp, 0) != S_OK)
goto error;
StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk");
- DeleteFile (szTmp2);
+ StatDeleteFile (szTmp2, FALSE);
}
if (bDesktopIcon)
{
@@ -2158,9 +2176,9 @@ void DoInstall (void *arg) UpdateProgressBarProc(61);
GetWindowsDirectory (path, ARRAYSIZE (path));
StringCbCatW (path, sizeof (path), L"\\VeraCrypt Setup.exe");
- DeleteFile (path);
+ StatDeleteFile (path, FALSE);
if (UpdateProgressBarProc(63) && UnloadDriver && DoServiceUninstall (hwndDlg, L"veracrypt") == FALSE)
{
bOK = FALSE;
|