VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Setup
diff options
context:
space:
mode:
authorDavid Foerster <david.foerster@informatik.hu-berlin.de>2016-05-10 20:20:14 +0200
committerDavid Foerster <david.foerster@informatik.hu-berlin.de>2016-05-10 20:20:14 +0200
commitfc37cc4a02ed13d1a73b941a9f80975600fd1b99 (patch)
treead9e5ac81111402b5c47dc06944cc5243824c4b5 /src/Setup
parent98b04198c6ea5bc07cca50956809068adf1fea82 (diff)
downloadVeraCrypt-fc37cc4a02ed13d1a73b941a9f80975600fd1b99.tar.gz
VeraCrypt-fc37cc4a02ed13d1a73b941a9f80975600fd1b99.zip
Normalize all line terminators
Diffstat (limited to 'src/Setup')
-rw-r--r--src/Setup/ComSetup.cpp206
-rw-r--r--src/Setup/ComSetup.h24
-rw-r--r--src/Setup/ComSetup.rgs182
-rw-r--r--src/Setup/Dir.c220
-rw-r--r--src/Setup/Dir.h46
-rw-r--r--src/Setup/Resource.h128
-rw-r--r--src/Setup/SelfExtract.c1576
-rw-r--r--src/Setup/SelfExtract.h86
-rw-r--r--src/Setup/Setup.c5264
-rw-r--r--src/Setup/Setup.h380
-rw-r--r--src/Setup/Setup.manifest64
-rw-r--r--src/Setup/Setup.rc654
-rw-r--r--src/Setup/Setup.vcproj968
-rw-r--r--src/Setup/Wizard.c2390
-rw-r--r--src/Setup/Wizard.h62
15 files changed, 6125 insertions, 6125 deletions
diff --git a/src/Setup/ComSetup.cpp b/src/Setup/ComSetup.cpp
index 5e45f8e3..24e5262f 100644
--- a/src/Setup/ComSetup.cpp
+++ b/src/Setup/ComSetup.cpp
@@ -1,103 +1,103 @@
-/*
- Derived from source code of TrueCrypt 7.1a, which is
- Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
- by the TrueCrypt License 3.0.
-
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages.
-*/
-
-#define TC_MAIN_COM_VERSION_MAJOR 2
-#define TC_MAIN_COM_VERSION_MINOR 7
-
-#define TC_FORMAT_COM_VERSION_MAJOR 2
-#define TC_FORMAT_COM_VERSION_MINOR 5
-
-#include <atlbase.h>
-#include <comdef.h>
-#include <statreg.h>
-#include <windows.h>
-#include "ComSetup.h"
-#include "Dlgcode.h"
-#include "Resource.h"
-#include "../Mount/MainCom_i.c"
-#include "../Format/FormatCom_i.c"
-
-
-extern "C" BOOL RegisterComServers (wchar_t *modulePath)
-{
- BOOL ret = TRUE;
- wchar_t mainModule[1024], formatModule[1024];
- CComPtr<ITypeLib> tl, tl2;
-
- wsprintfW (mainModule, L"%sVeraCrypt.exe", modulePath);
- wsprintfW (formatModule, L"%sVeraCrypt Format.exe", modulePath);
-
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32);
- // unregister older versions that may still exist
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-3, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-2, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-1, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-1, 0, SYS_WIN32);
-
- wchar_t setupModule[MAX_PATH];
- GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
-
- CRegObject ro;
- HRESULT r;
-
- if (!SUCCEEDED (r = ro.FinalConstruct ())
- || !SUCCEEDED (r = ro.AddReplacement (L"MAIN_MODULE", mainModule))
- || !SUCCEEDED (r = ro.AddReplacement (L"FORMAT_MODULE", formatModule))
- || !SUCCEEDED (r = ro.ResourceRegister (setupModule, IDR_COMREG, L"REGISTRY"))
- || !SUCCEEDED (r = LoadTypeLib (mainModule, &tl))
- || !SUCCEEDED (r = RegisterTypeLib (tl, mainModule, 0))
- || !SUCCEEDED (r = LoadTypeLib (formatModule, &tl2))
- || !SUCCEEDED (r = RegisterTypeLib (tl2, formatModule, 0)))
- {
- MessageBox (MainDlg, _com_error (r).ErrorMessage(), _T(TC_APP_NAME), MB_ICONERROR);
- ret = FALSE;
- }
-
- ro.FinalRelease ();
- return ret;
-}
-
-
-extern "C" BOOL UnregisterComServers (wchar_t *modulePath)
-{
- BOOL ret;
-
- if (UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
- return FALSE;
- if (UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
- return FALSE;
-
- // unregister older versions that may still exist
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-3, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-2, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-1, 0, SYS_WIN32);
- UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-1, 0, SYS_WIN32);
-
- wchar_t module[1024];
- CRegObject ro;
- ro.FinalConstruct ();
-
- wsprintfW (module, L"%sVeraCrypt.exe", modulePath);
- ro.AddReplacement (L"MAIN_MODULE", module);
-
- wsprintfW (module, L"%sVeraCrypt Format.exe", modulePath);
- ro.AddReplacement (L"FORMAT_MODULE", module);
-
- wchar_t setupModule[MAX_PATH];
- GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
-
- ret = ro.ResourceUnregister (setupModule, IDR_COMREG, L"REGISTRY") == S_OK;
-
- ro.FinalRelease ();
- return ret;
-}
+/*
+ Derived from source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
+ by the TrueCrypt License 3.0.
+
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages.
+*/
+
+#define TC_MAIN_COM_VERSION_MAJOR 2
+#define TC_MAIN_COM_VERSION_MINOR 7
+
+#define TC_FORMAT_COM_VERSION_MAJOR 2
+#define TC_FORMAT_COM_VERSION_MINOR 5
+
+#include <atlbase.h>
+#include <comdef.h>
+#include <statreg.h>
+#include <windows.h>
+#include "ComSetup.h"
+#include "Dlgcode.h"
+#include "Resource.h"
+#include "../Mount/MainCom_i.c"
+#include "../Format/FormatCom_i.c"
+
+
+extern "C" BOOL RegisterComServers (wchar_t *modulePath)
+{
+ BOOL ret = TRUE;
+ wchar_t mainModule[1024], formatModule[1024];
+ CComPtr<ITypeLib> tl, tl2;
+
+ wsprintfW (mainModule, L"%sVeraCrypt.exe", modulePath);
+ wsprintfW (formatModule, L"%sVeraCrypt Format.exe", modulePath);
+
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32);
+ // unregister older versions that may still exist
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-3, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-2, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-1, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-1, 0, SYS_WIN32);
+
+ wchar_t setupModule[MAX_PATH];
+ GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
+
+ CRegObject ro;
+ HRESULT r;
+
+ if (!SUCCEEDED (r = ro.FinalConstruct ())
+ || !SUCCEEDED (r = ro.AddReplacement (L"MAIN_MODULE", mainModule))
+ || !SUCCEEDED (r = ro.AddReplacement (L"FORMAT_MODULE", formatModule))
+ || !SUCCEEDED (r = ro.ResourceRegister (setupModule, IDR_COMREG, L"REGISTRY"))
+ || !SUCCEEDED (r = LoadTypeLib (mainModule, &tl))
+ || !SUCCEEDED (r = RegisterTypeLib (tl, mainModule, 0))
+ || !SUCCEEDED (r = LoadTypeLib (formatModule, &tl2))
+ || !SUCCEEDED (r = RegisterTypeLib (tl2, formatModule, 0)))
+ {
+ MessageBox (MainDlg, _com_error (r).ErrorMessage(), _T(TC_APP_NAME), MB_ICONERROR);
+ ret = FALSE;
+ }
+
+ ro.FinalRelease ();
+ return ret;
+}
+
+
+extern "C" BOOL UnregisterComServers (wchar_t *modulePath)
+{
+ BOOL ret;
+
+ if (UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
+ return FALSE;
+ if (UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR, 0, SYS_WIN32) != S_OK)
+ return FALSE;
+
+ // unregister older versions that may still exist
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-3, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-2, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptMainCom, TC_MAIN_COM_VERSION_MAJOR, TC_MAIN_COM_VERSION_MINOR-1, 0, SYS_WIN32);
+ UnRegisterTypeLib (LIBID_TrueCryptFormatCom, TC_FORMAT_COM_VERSION_MAJOR, TC_FORMAT_COM_VERSION_MINOR-1, 0, SYS_WIN32);
+
+ wchar_t module[1024];
+ CRegObject ro;
+ ro.FinalConstruct ();
+
+ wsprintfW (module, L"%sVeraCrypt.exe", modulePath);
+ ro.AddReplacement (L"MAIN_MODULE", module);
+
+ wsprintfW (module, L"%sVeraCrypt Format.exe", modulePath);
+ ro.AddReplacement (L"FORMAT_MODULE", module);
+
+ wchar_t setupModule[MAX_PATH];
+ GetModuleFileNameW (NULL, setupModule, sizeof (setupModule) / sizeof (setupModule[0]));
+
+ ret = ro.ResourceUnregister (setupModule, IDR_COMREG, L"REGISTRY") == S_OK;
+
+ ro.FinalRelease ();
+ return ret;
+}
diff --git a/src/Setup/ComSetup.h b/src/Setup/ComSetup.h
index 0e3bbd5f..56e30139 100644
--- a/src/Setup/ComSetup.h
+++ b/src/Setup/ComSetup.h
@@ -8,15 +8,15 @@
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-BOOL RegisterComServers (wchar_t *modulePath);
-BOOL UnregisterComServers (wchar_t *modulePath);
-
-#ifdef __cplusplus
-}
-#endif
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+BOOL RegisterComServers (wchar_t *modulePath);
+BOOL UnregisterComServers (wchar_t *modulePath);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/Setup/ComSetup.rgs b/src/Setup/ComSetup.rgs
index 19ee8be7..ed927913 100644
--- a/src/Setup/ComSetup.rgs
+++ b/src/Setup/ComSetup.rgs
@@ -1,92 +1,92 @@
-HKCR
-{
- ForceRemove VeraCrypt.1 = s 'VeraCrypt class'
- {
- CLSID = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
- }
-
- ForceRemove VeraCrypt = s 'VeraCrypt class'
- {
- CLSID = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
- CurVer = s 'VeraCrypt.1'
- }
-
- NoRemove CLSID
- {
- ForceRemove {FE8B3B95-C80C-41f7-830F-FBA271C26F7E} = s 'VeraCrypt class'
- {
- ProgID = s 'VeraCrypt.1'
- VersionIndependentProgID = s 'VeraCrypt'
- LocalServer32 = s '"%MAIN_MODULE%"'
-
- TypeLib = s '{9ACF6176-5FC4-4690-A025-B3306A50EB6A}'
-
- Elevation
- {
- val Enabled = d 1
- val IconReference = s '@%MAIN_MODULE%,-501'
- }
-
- val AppId = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
- val LocalizedString = s '@%MAIN_MODULE%,-110'
- }
- }
-
- NoRemove AppId
- {
- ForceRemove {FE8B3B95-C80C-41f7-830F-FBA271C26F7E} = s 'VeraCrypt class'
- {
- val AccessPermission = b 010004803000000040000000000000001400000002001c000100000000001400070000000101000000000005040000000102000000000005200000002002000001020000000000052000000020020000
- }
-
- ForceRemove VeraCrypt.exe
- {
- val AppId = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
- }
- }
-
- ForceRemove VeraCryptFormat.1 = s 'VeraCryptFormat class'
- {
- CLSID = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
- }
-
- ForceRemove VeraCryptFormat = s 'VeraCryptFormat class'
- {
- CLSID = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
- CurVer = s 'VeraCryptFormat.1'
- }
-
- NoRemove CLSID
- {
- ForceRemove {A96D3797-9F31-49f4-A0CE-9657392CF789} = s 'VeraCryptFormat class'
- {
- ProgID = s 'VeraCryptFormat.1'
- VersionIndependentProgID = s 'VeraCryptFormat'
- LocalServer32 = s '"%FORMAT_MODULE%"'
-
- TypeLib = s '{56327DDA-F1A7-4e13-B128-520D129BDEF6}'
-
- Elevation
- {
- val Enabled = d 1
- val IconReference = s '@%FORMAT_MODULE%,-501'
- }
-
- val AppId = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
- val LocalizedString = s '@%FORMAT_MODULE%,-112'
- }
- }
-
- NoRemove AppId
- {
- ForceRemove {A96D3797-9F31-49f4-A0CE-9657392CF789} = s 'VeraCryptFormat class'
- {
- val AccessPermission = b 010004803000000040000000000000001400000002001c000100000000001400070000000101000000000005040000000102000000000005200000002002000001020000000000052000000020020000
- }
-
- ForceRemove 'VeraCrypt Format.exe'
- {
- val AppId = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
- }
- }
+HKCR
+{
+ ForceRemove VeraCrypt.1 = s 'VeraCrypt class'
+ {
+ CLSID = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
+ }
+
+ ForceRemove VeraCrypt = s 'VeraCrypt class'
+ {
+ CLSID = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
+ CurVer = s 'VeraCrypt.1'
+ }
+
+ NoRemove CLSID
+ {
+ ForceRemove {FE8B3B95-C80C-41f7-830F-FBA271C26F7E} = s 'VeraCrypt class'
+ {
+ ProgID = s 'VeraCrypt.1'
+ VersionIndependentProgID = s 'VeraCrypt'
+ LocalServer32 = s '"%MAIN_MODULE%"'
+
+ TypeLib = s '{9ACF6176-5FC4-4690-A025-B3306A50EB6A}'
+
+ Elevation
+ {
+ val Enabled = d 1
+ val IconReference = s '@%MAIN_MODULE%,-501'
+ }
+
+ val AppId = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
+ val LocalizedString = s '@%MAIN_MODULE%,-110'
+ }
+ }
+
+ NoRemove AppId
+ {
+ ForceRemove {FE8B3B95-C80C-41f7-830F-FBA271C26F7E} = s 'VeraCrypt class'
+ {
+ val AccessPermission = b 010004803000000040000000000000001400000002001c000100000000001400070000000101000000000005040000000102000000000005200000002002000001020000000000052000000020020000
+ }
+
+ ForceRemove VeraCrypt.exe
+ {
+ val AppId = s '{FE8B3B95-C80C-41f7-830F-FBA271C26F7E}'
+ }
+ }
+
+ ForceRemove VeraCryptFormat.1 = s 'VeraCryptFormat class'
+ {
+ CLSID = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
+ }
+
+ ForceRemove VeraCryptFormat = s 'VeraCryptFormat class'
+ {
+ CLSID = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
+ CurVer = s 'VeraCryptFormat.1'
+ }
+
+ NoRemove CLSID
+ {
+ ForceRemove {A96D3797-9F31-49f4-A0CE-9657392CF789} = s 'VeraCryptFormat class'
+ {
+ ProgID = s 'VeraCryptFormat.1'
+ VersionIndependentProgID = s 'VeraCryptFormat'
+ LocalServer32 = s '"%FORMAT_MODULE%"'
+
+ TypeLib = s '{56327DDA-F1A7-4e13-B128-520D129BDEF6}'
+
+ Elevation
+ {
+ val Enabled = d 1
+ val IconReference = s '@%FORMAT_MODULE%,-501'
+ }
+
+ val AppId = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
+ val LocalizedString = s '@%FORMAT_MODULE%,-112'
+ }
+ }
+
+ NoRemove AppId
+ {
+ ForceRemove {A96D3797-9F31-49f4-A0CE-9657392CF789} = s 'VeraCryptFormat class'
+ {
+ val AccessPermission = b 010004803000000040000000000000001400000002001c000100000000001400070000000101000000000005040000000102000000000005200000002002000001020000000000052000000020020000
+ }
+
+ ForceRemove 'VeraCrypt Format.exe'
+ {
+ val AppId = s '{A96D3797-9F31-49f4-A0CE-9657392CF789}'
+ }
+ }
} \ No newline at end of file
diff --git a/src/Setup/Dir.c b/src/Setup/Dir.c
index c4bab5d6..342ff748 100644
--- a/src/Setup/Dir.c
+++ b/src/Setup/Dir.c
@@ -1,110 +1,110 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#include "Tcdefs.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <direct.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <Strsafe.h>
-
-#include "Dir.h"
-
-/* create full directory tree. returns 0 for success, -1 if failure */
-int
-mkfulldir (wchar_t *oriPath, BOOL bCheckonly)
-{
- struct _stat st;
- wchar_t *uniq_file;
- wchar_t path [TC_MAX_PATH];
-
- StringCbCopyW (path, TC_MAX_PATH, oriPath);
-
- if (wcslen (path) == 3 && path[1] == L':')
- goto is_root; /* keep final slash in root if present */
-
- /* strip final forward or backslash if we have one! */
- uniq_file = wcsrchr (path, L'\\');
- if (uniq_file && uniq_file[1] == L'\0')
- uniq_file[0] = L'\0';
- else
- {
- uniq_file = wcsrchr (path, L'/');
- if (uniq_file && uniq_file[1] == L'\0')
- uniq_file[0] = L'\0';
- }
-
- is_root:
- if (bCheckonly)
- return _wstat (path, &st);
-
- if (_wstat (path, &st))
- return mkfulldir_internal (path);
- else
- return 0;
-}
-
-
-int
-mkfulldir_internal (wchar_t *path)
-{
- wchar_t *token;
- struct _stat st;
- static wchar_t tokpath[_MAX_PATH];
- static wchar_t trail[_MAX_PATH];
-
- StringCbCopyW (tokpath, _MAX_PATH, path);
- trail[0] = L'\0';
-
- token = wcstok (tokpath, L"\\/");
-
- if (tokpath[0] == L'\\' && tokpath[1] == L'\\')
- { /* unc */
- trail[0] = tokpath[0];
- trail[1] = tokpath[1];
- trail[2] = L'\0';
- if (token)
- {
- StringCbCatW (trail, _MAX_PATH, token);
- StringCbCatW (trail, _MAX_PATH, L"\\");
- token = wcstok (NULL, L"\\/");
- if (token)
- { /* get share name */
- StringCbCatW (trail, _MAX_PATH, token);
- StringCbCatW (trail, _MAX_PATH, L"\\");
- }
- token = wcstok (NULL, L"\\/");
- }
- }
-
- if (tokpath[1] == L':')
- { /* drive letter */
- StringCbCatW (trail, _MAX_PATH, tokpath);
- StringCbCatW (trail, _MAX_PATH, L"\\");
- token = wcstok (NULL, L"\\/");
- }
-
- while (token != NULL)
- {
- int x;
- StringCbCatW (trail, _MAX_PATH, token);
- x = _wmkdir (trail);
- StringCbCatW (trail, _MAX_PATH, L"\\");
- token = wcstok (NULL, L"\\/");
- }
-
- return _wstat (path, &st);
-}
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#include "Tcdefs.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <direct.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <Strsafe.h>
+
+#include "Dir.h"
+
+/* create full directory tree. returns 0 for success, -1 if failure */
+int
+mkfulldir (wchar_t *oriPath, BOOL bCheckonly)
+{
+ struct _stat st;
+ wchar_t *uniq_file;
+ wchar_t path [TC_MAX_PATH];
+
+ StringCbCopyW (path, TC_MAX_PATH, oriPath);
+
+ if (wcslen (path) == 3 && path[1] == L':')
+ goto is_root; /* keep final slash in root if present */
+
+ /* strip final forward or backslash if we have one! */
+ uniq_file = wcsrchr (path, L'\\');
+ if (uniq_file && uniq_file[1] == L'\0')
+ uniq_file[0] = L'\0';
+ else
+ {
+ uniq_file = wcsrchr (path, L'/');
+ if (uniq_file && uniq_file[1] == L'\0')
+ uniq_file[0] = L'\0';
+ }
+
+ is_root:
+ if (bCheckonly)
+ return _wstat (path, &st);
+
+ if (_wstat (path, &st))
+ return mkfulldir_internal (path);
+ else
+ return 0;
+}
+
+
+int
+mkfulldir_internal (wchar_t *path)
+{
+ wchar_t *token;
+ struct _stat st;
+ static wchar_t tokpath[_MAX_PATH];
+ static wchar_t trail[_MAX_PATH];
+
+ StringCbCopyW (tokpath, _MAX_PATH, path);
+ trail[0] = L'\0';
+
+ token = wcstok (tokpath, L"\\/");
+
+ if (tokpath[0] == L'\\' && tokpath[1] == L'\\')
+ { /* unc */
+ trail[0] = tokpath[0];
+ trail[1] = tokpath[1];
+ trail[2] = L'\0';
+ if (token)
+ {
+ StringCbCatW (trail, _MAX_PATH, token);
+ StringCbCatW (trail, _MAX_PATH, L"\\");
+ token = wcstok (NULL, L"\\/");
+ if (token)
+ { /* get share name */
+ StringCbCatW (trail, _MAX_PATH, token);
+ StringCbCatW (trail, _MAX_PATH, L"\\");
+ }
+ token = wcstok (NULL, L"\\/");
+ }
+ }
+
+ if (tokpath[1] == L':')
+ { /* drive letter */
+ StringCbCatW (trail, _MAX_PATH, tokpath);
+ StringCbCatW (trail, _MAX_PATH, L"\\");
+ token = wcstok (NULL, L"\\/");
+ }
+
+ while (token != NULL)
+ {
+ int x;
+ StringCbCatW (trail, _MAX_PATH, token);
+ x = _wmkdir (trail);
+ StringCbCatW (trail, _MAX_PATH, L"\\");
+ token = wcstok (NULL, L"\\/");
+ }
+
+ return _wstat (path, &st);
+}
diff --git a/src/Setup/Dir.h b/src/Setup/Dir.h
index 42707a38..2126bb42 100644
--- a/src/Setup/Dir.h
+++ b/src/Setup/Dir.h
@@ -1,23 +1,23 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int mkfulldir ( wchar_t *path , BOOL bCheckonly );
-int mkfulldir_internal ( wchar_t *path );
-
-#ifdef __cplusplus
-}
-#endif
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int mkfulldir ( wchar_t *path , BOOL bCheckonly );
+int mkfulldir_internal ( wchar_t *path );
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/Setup/Resource.h b/src/Setup/Resource.h
index 2baaefe0..bbbd4766 100644
--- a/src/Setup/Resource.h
+++ b/src/Setup/Resource.h
@@ -1,64 +1,64 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by Setup.rc
-//
-#define IDR_COMREG 10
-#define IDD_INSTALL 101
-#define IDD_INSTALL_OPTIONS_PAGE_DLG 102
-#define IDD_UNINSTALL 103
-#define IDI_SETUP 104
-#define IDR_SETUP_RSRC_HEADER 105
-#define IDD_EXTRACTION_OPTIONS_PAGE_DLG 106
-#define IDB_SETUP_WIZARD 107
-#define IDD_INTRO_PAGE_DLG 108
-#define IDB_SETUP_WIZARD_BKG 109
-#define IDD_INFO_PAGE_DLG 110
-#define IDD_INSTL_DLG 111
-#define IDD_WIZARD_MODE_PAGE_DLG 112
-#define IDD_PROGRESS_PAGE_DLG 113
-#define IDD_DONATIONS_PAGE_DLG 114
-#define IDC_DESTINATION 1000
-#define IDC_BOX_TITLE 1001
-#define IDC_BROWSE 1002
-#define IDC_BOX_INFO 1003
-#define IDC_LICENSE 1004
-#define IDC_BOX_HELP 1005
-#define IDC_LICENSE_TEXT 1006
-#define IDC_BOX_HELP2 1007
-#define IDC_FILE_TYPE 1008
-#define IDT_UNINSTALL_DIR 1009
-#define IDC_PROG_GROUP 1010
-#define IDC_SYSTEM_RESTORE 1011
-#define IDC_DESKTOP_ICON 1012
-#define IDC_ALL_USERS 1013
-#define IDT_INSTALL_DESTINATION 1014
-#define IDC_UNINSTALL 1015
-#define IDC_PROGRESS_BAR 1016
-#define IDC_LOG_WINDOW 1017
-#define IDC_SETUP_WIZARD_BKG 1018
-#define IDC_SETUP_WIZARD_GFX_AREA 1019
-#define IDC_HR 1020
-#define IDC_OPEN_CONTAINING_FOLDER 1021
-#define IDC_AGREE 1022
-#define IDC_HR_BOTTOM 1023
-#define IDC_WIZARD_MODE_INSTALL 1024
-#define IDC_WIZARD_MODE_EXTRACT_ONLY 1025
-#define IDC_NEXT 1026
-#define IDC_PREV 1027
-#define IDT_EXTRACT_DESTINATION 1028
-#define IDC_POS_BOX 1029
-#define IDC_BITMAP_SETUP_WIZARD 1030
-#define IDC_MAIN_CONTENT_CANVAS 1031
-#define IDC_DONATE 1032
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NO_MFC 1
-#define _APS_NEXT_RESOURCE_VALUE 115
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1033
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by Setup.rc
+//
+#define IDR_COMREG 10
+#define IDD_INSTALL 101
+#define IDD_INSTALL_OPTIONS_PAGE_DLG 102
+#define IDD_UNINSTALL 103
+#define IDI_SETUP 104
+#define IDR_SETUP_RSRC_HEADER 105
+#define IDD_EXTRACTION_OPTIONS_PAGE_DLG 106
+#define IDB_SETUP_WIZARD 107
+#define IDD_INTRO_PAGE_DLG 108
+#define IDB_SETUP_WIZARD_BKG 109
+#define IDD_INFO_PAGE_DLG 110
+#define IDD_INSTL_DLG 111
+#define IDD_WIZARD_MODE_PAGE_DLG 112
+#define IDD_PROGRESS_PAGE_DLG 113
+#define IDD_DONATIONS_PAGE_DLG 114
+#define IDC_DESTINATION 1000
+#define IDC_BOX_TITLE 1001
+#define IDC_BROWSE 1002
+#define IDC_BOX_INFO 1003
+#define IDC_LICENSE 1004
+#define IDC_BOX_HELP 1005
+#define IDC_LICENSE_TEXT 1006
+#define IDC_BOX_HELP2 1007
+#define IDC_FILE_TYPE 1008
+#define IDT_UNINSTALL_DIR 1009
+#define IDC_PROG_GROUP 1010
+#define IDC_SYSTEM_RESTORE 1011
+#define IDC_DESKTOP_ICON 1012
+#define IDC_ALL_USERS 1013
+#define IDT_INSTALL_DESTINATION 1014
+#define IDC_UNINSTALL 1015
+#define IDC_PROGRESS_BAR 1016
+#define IDC_LOG_WINDOW 1017
+#define IDC_SETUP_WIZARD_BKG 1018
+#define IDC_SETUP_WIZARD_GFX_AREA 1019
+#define IDC_HR 1020
+#define IDC_OPEN_CONTAINING_FOLDER 1021
+#define IDC_AGREE 1022
+#define IDC_HR_BOTTOM 1023
+#define IDC_WIZARD_MODE_INSTALL 1024
+#define IDC_WIZARD_MODE_EXTRACT_ONLY 1025
+#define IDC_NEXT 1026
+#define IDC_PREV 1027
+#define IDT_EXTRACT_DESTINATION 1028
+#define IDC_POS_BOX 1029
+#define IDC_BITMAP_SETUP_WIZARD 1030
+#define IDC_MAIN_CONTENT_CANVAS 1031
+#define IDC_DONATE 1032
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NO_MFC 1
+#define _APS_NEXT_RESOURCE_VALUE 115
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1033
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c
index 42326efc..e427e44c 100644
--- a/src/Setup/SelfExtract.c
+++ b/src/Setup/SelfExtract.c
@@ -1,788 +1,788 @@
-/*
- Derived from source code of TrueCrypt 7.1a, which is
- Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
- by the TrueCrypt License 3.0.
-
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages.
-*/
-
-#include "Tcdefs.h"
-
-#include "Inflate.h"
-#include "SelfExtract.h"
-#include "Wizard.h"
-#include "Setup.h"
-#include "Crc.h"
-#include "Endian.h"
-#include "Dlgcode.h"
-#include "Dir.h"
-#include "Language.h"
-#include "Resource.h"
-#include <tchar.h>
-#include <Strsafe.h>
-
-#ifndef SRC_POS
-#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
-#endif
-
-#define OutputPackageFile L"VeraCrypt Setup " _T(VERSION_STRING) L".exe"
-
-#define MAG_START_MARKER "TCINSTRT"
-#define MAG_END_MARKER_OBFUSCATED "T/C/I/N/S/C/R/C"
-#define PIPE_BUFFER_LEN (4 * BYTES_PER_KB)
-
-unsigned char MagEndMarker [sizeof (MAG_END_MARKER_OBFUSCATED)];
-wchar_t DestExtractPath [TC_MAX_PATH];
-DECOMPRESSED_FILE Decompressed_Files [NBR_COMPRESSED_FILES];
-
-volatile char *PipeWriteBuf = NULL;
-volatile HANDLE hChildStdinWrite = INVALID_HANDLE_VALUE;
-unsigned char *DecompressedData = NULL;
-
-
-
-void SelfExtractStartupInit (void)
-{
- DeobfuscateMagEndMarker ();
-}
-
-
-// The end marker must be included in the self-extracting exe only once, not twice (used e.g.
-// by IsSelfExtractingPackage()) and that's why MAG_END_MARKER_OBFUSCATED is obfuscated and
-// needs to be deobfuscated using this function at startup.
-static void DeobfuscateMagEndMarker (void)
-{
- int i;
-
- for (i = 0; i < sizeof (MAG_END_MARKER_OBFUSCATED); i += 2)
- MagEndMarker [i/2] = MAG_END_MARKER_OBFUSCATED [i];
-
- MagEndMarker [i/2] = 0;
-}
-
-
-static void PkgError (wchar_t *msg)
-{
- MessageBox (NULL, msg, L"VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
-}
-
-
-static void PkgWarning (wchar_t *msg)
-{
- MessageBox (NULL, msg, L"VeraCrypt", MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
-}
-
-
-static void PkgInfo (wchar_t *msg)
-{
- MessageBox (NULL, msg, L"VeraCrypt", MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
-}
-
-
-// Returns 0 if decompression fails or, if successful, returns the size of the decompressed data
-static int DecompressBuffer (char *out, char *in, int len)
-{
- return (DecompressDeflatedData (out, in, len)); // Inflate
-}
-
-
-static void __cdecl PipeWriteThread (void *len)
-{
- int sendBufSize = PIPE_BUFFER_LEN, bytesSent = 0;
- int bytesToSend = *((int *) len), bytesSentTotal = 0;
-
- if (PipeWriteBuf == NULL || (HANDLE) hChildStdinWrite == INVALID_HANDLE_VALUE)
- {
- PkgError (L"Failed sending data to the STDIN pipe");
- return;
- }
-
- while (bytesToSend > 0)
- {
- if (bytesToSend < PIPE_BUFFER_LEN)
- sendBufSize = bytesToSend;
-
- if (!WriteFile ((HANDLE) hChildStdinWrite, (char *) PipeWriteBuf + bytesSentTotal, sendBufSize, &bytesSent, NULL)
- || bytesSent == 0
- || bytesSent != sendBufSize)
- {
- PkgError (L"Failed sending data to the STDIN pipe");
- return;
- }
-
- bytesToSend -= bytesSent;
- bytesSentTotal += bytesSent;
- }
-
- // Closing the pipe causes the child process to stop reading from it
-
- if (!CloseHandle (hChildStdinWrite))
- {
- PkgError (L"Cannot close pipe");
- return;
- }
-}
-
-
-// Returns 0 if compression fails or, if successful, the size of the compressed data
-static int CompressBuffer (char *out, char *in, int len)
-{
- SECURITY_ATTRIBUTES securityAttrib;
- DWORD bytesReceived = 0;
- HANDLE hChildStdoutWrite = INVALID_HANDLE_VALUE;
- HANDLE hChildStdoutRead = INVALID_HANDLE_VALUE;
- HANDLE hChildStdinRead = INVALID_HANDLE_VALUE;
- STARTUPINFO startupInfo;
- PROCESS_INFORMATION procInfo;
- char pipeBuffer [PIPE_BUFFER_LEN];
- int res_len = 0;
- BOOL bGzipHeaderRead = FALSE;
- wchar_t szGzipCmd[64];
-
- ZeroMemory (&startupInfo, sizeof (startupInfo));
- ZeroMemory (&procInfo, sizeof (procInfo));
-
- // Pipe handle inheritance
- securityAttrib.bInheritHandle = TRUE;
- securityAttrib.nLength = sizeof (securityAttrib);
- securityAttrib.lpSecurityDescriptor = NULL;
-
- if (!CreatePipe (&hChildStdoutRead, &hChildStdoutWrite, &securityAttrib, 0))
- {
- PkgError (L"Cannot create STDOUT pipe.");
- return 0;
- }
- SetHandleInformation (hChildStdoutRead, HANDLE_FLAG_INHERIT, 0);
-
- if (!CreatePipe (&hChildStdinRead, &((HANDLE) hChildStdinWrite), &securityAttrib, 0))
- {
- PkgError (L"Cannot create STDIN pipe.");
- CloseHandle(hChildStdoutWrite);
- CloseHandle(hChildStdoutRead);
- return 0;
- }
- SetHandleInformation (hChildStdinWrite, HANDLE_FLAG_INHERIT, 0);
-
- // Create a child process that will compress the data
-
- startupInfo.wShowWindow = SW_HIDE;
- startupInfo.hStdInput = hChildStdinRead;
- startupInfo.hStdOutput = hChildStdoutWrite;
- startupInfo.cb = sizeof (startupInfo);
- startupInfo.hStdError = hChildStdoutWrite;
- startupInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
-
- StringCchCopyW (szGzipCmd, ARRAYSIZE (szGzipCmd), L"gzip --best");
- if (!CreateProcess (NULL, szGzipCmd, NULL, NULL, TRUE, 0, NULL, NULL, &startupInfo, &procInfo))
- {
- PkgError (L"Error: Cannot run gzip.\n\nBefore you can create a self-extracting VeraCrypt package, you need to have the open-source 'gzip' compression tool placed in any directory in the search path for executable files (for example, in 'C:\\Windows\\').\n\nNote: gzip can be freely downloaded e.g. from www.gzip.org");
- CloseHandle(hChildStdoutWrite);
- CloseHandle(hChildStdoutRead);
- CloseHandle(hChildStdinRead);
- CloseHandle(hChildStdinWrite);
- return 0;
- }
-
- CloseHandle (procInfo.hProcess);
- CloseHandle (procInfo.hThread);
-
- // Start sending the uncompressed data to the pipe (STDIN)
- PipeWriteBuf = in;
- _beginthread (PipeWriteThread, PIPE_BUFFER_LEN * 2, (void *) &len);
-
- if (!CloseHandle (hChildStdoutWrite))
- {
- PkgError (L"Cannot close STDOUT write");
- CloseHandle(hChildStdoutRead);
- CloseHandle(hChildStdinRead);
- return 0;
- }
-
- bGzipHeaderRead = FALSE;
-
- // Read the compressed data from the pipe (sent by the child process to STDOUT)
- while (TRUE)
- {
- if (!ReadFile (hChildStdoutRead, pipeBuffer, bGzipHeaderRead ? PIPE_BUFFER_LEN : 10, &bytesReceived, NULL))
- break;
-
- if (bGzipHeaderRead)
- {
- memcpy (out + res_len, pipeBuffer, bytesReceived);
- res_len += bytesReceived;
- }
- else
- bGzipHeaderRead = TRUE; // Skip the 10-byte gzip header
- }
-
- CloseHandle(hChildStdoutRead);
- CloseHandle(hChildStdinRead);
- return res_len - 8; // A gzip stream ends with a CRC-32 hash and a 32-bit size (those 8 bytes need to be chopped off)
-}
-
-
-// Clears all bytes that change when an exe file is digitally signed, except the data that are appended.
-// If those bytes weren't cleared, CRC-32 checks would fail after signing.
-static void WipeSignatureAreas (char *buffer)
-{
- // Clear bytes 0x130-0x1ff
- memset (buffer + 0x130, 0, 0x200 - 0x130);
-}
-
-
-BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir)
-{
- int i, x;
- wchar_t inputFile [TC_MAX_PATH];
- wchar_t outputFile [TC_MAX_PATH];
- wchar_t szTmpFilePath [TC_MAX_PATH];
- unsigned char szTmp32bit [4] = {0};
- unsigned char *szTmp32bitPtr = szTmp32bit;
- unsigned char *buffer = NULL, *compressedBuffer = NULL;
- unsigned char *bufIndex = NULL;
- wchar_t tmpStr [2048];
- int bufLen = 0, compressedDataLen = 0, uncompressedDataLen = 0;
-
- x = wcslen (szDestDir);
- if (x < 2)
- goto err;
-
- if (szDestDir[x - 1] != L'\\')
- StringCbCatW (szDestDir, MAX_PATH, L"\\");
-
- GetModuleFileName (NULL, inputFile, ARRAYSIZE (inputFile));
-
- StringCchCopyW (outputFile, ARRAYSIZE(outputFile), szDestDir);
- StringCchCatW (outputFile, ARRAYSIZE(outputFile), OutputPackageFile);
-
- // Clone 'VeraCrypt Setup.exe' to create the base of the new self-extracting archive
-
- if (!TCCopyFile (inputFile, outputFile))
- {
- handleWin32Error (hwndDlg, SRC_POS);
- PkgError (L"Cannot copy 'VeraCrypt Setup.exe' to the package");
- goto err;
- }
-
- // Determine the buffer size needed for all the files and meta data and check if all required files exist
-
- bufLen = 0;
-
- for (i = 0; i < sizeof (szCompressedFiles) / sizeof (szCompressedFiles[0]); i++)
- {
- StringCbPrintfW (szTmpFilePath, sizeof(szTmpFilePath), L"%s%s", szDestDir, szCompressedFiles[i]);
-
- if (!FileExists (szTmpFilePath))
- {
- wchar_t tmpstr [1000];
-
- StringCbPrintfW (tmpstr, sizeof(tmpstr), L"File not found:\n\n'%s'", szTmpFilePath);
- if (_wremove (outputFile))
- StringCbCatW (tmpstr, sizeof(tmpstr), L"\nFailed also to delete package file");
- PkgError (tmpstr);
- goto err;
- }
-
- bufLen += (int) GetFileSize64 (szTmpFilePath);
-
- bufLen += 2; // 16-bit filename length
- bufLen += (wcslen(szCompressedFiles[i]) * sizeof (wchar_t)); // Filename
- bufLen += 4; // CRC-32
- bufLen += 4; // 32-bit file length
- }
-
- buffer = malloc (bufLen + 524288); // + 512K reserve
- if (buffer == NULL)
- {
- PkgError (L"Cannot allocate memory for uncompressed data");
- if (_wremove (outputFile))
- PkgError (L"Cannot allocate memory for uncompressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot allocate memory for uncompressed data");
- goto err;
- }
-
-
- // Write the start marker
- if (!SaveBufferToFile (MAG_START_MARKER, outputFile, strlen (MAG_START_MARKER), TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write the start marker\nFailed also to delete package file");
- else
- PkgError (L"Cannot write the start marker");
- goto err;
- }
-
-
- bufIndex = buffer;
-
- // Copy all required files and their meta data to the buffer
- for (i = 0; i < sizeof (szCompressedFiles) / sizeof (szCompressedFiles[0]); i++)
- {
- DWORD tmpFileSize;
- unsigned char *tmpBuffer;
-
- StringCbPrintfW (szTmpFilePath, sizeof(szTmpFilePath), L"%s%s", szDestDir, szCompressedFiles[i]);
-
- tmpBuffer = LoadFile (szTmpFilePath, &tmpFileSize);
-
- if (tmpBuffer == NULL)
- {
- wchar_t tmpstr [1000];
-
- StringCbPrintfW (tmpstr, sizeof(tmpstr), L"Cannot load file \n'%s'", szTmpFilePath);
- if (_wremove (outputFile))
- StringCbCatW (tmpstr, sizeof(tmpstr), L"\nFailed also to delete package file");
- PkgError (tmpstr);
- goto err;
- }
-
- // Copy the filename length to the main buffer
- mputWord (bufIndex, (WORD) wcslen(szCompressedFiles[i]));
-
- // Copy the filename to the main buffer
- wmemcpy ((wchar_t*)bufIndex, szCompressedFiles[i], wcslen(szCompressedFiles[i]));
- bufIndex += (wcslen(szCompressedFiles[i]) * sizeof (wchar_t));
-
- // Compute CRC-32 hash of the uncompressed file and copy it to the main buffer
- mputLong (bufIndex, GetCrc32 (tmpBuffer, tmpFileSize));
-
- // Copy the file length to the main buffer
- mputLong (bufIndex, (unsigned __int32) tmpFileSize);
-
- // Copy the file contents to the main buffer
- memcpy (bufIndex, tmpBuffer, tmpFileSize);
- bufIndex += tmpFileSize;
-
- free (tmpBuffer);
- }
-
- // Calculate the total size of the uncompressed data
- uncompressedDataLen = (int) (bufIndex - buffer);
-
- // Write total size of the uncompressed data
- szTmp32bitPtr = szTmp32bit;
- mputLong (szTmp32bitPtr, (unsigned __int32) uncompressedDataLen);
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write the total size of the uncompressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot write the total size of the uncompressed data");
- goto err;
- }
-
- // Compress all the files and meta data in the buffer to create a solid archive
-
- // Test to make Coverity happy. It will always be false
- if (uncompressedDataLen >= (INT_MAX - 524288))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot allocate memory for compressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot allocate memory for compressed data");
- goto err;
- }
-
- compressedBuffer = malloc (uncompressedDataLen + 524288); // + 512K reserve
- if (compressedBuffer == NULL)
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot allocate memory for compressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot allocate memory for compressed data");
- goto err;
- }
-
- compressedDataLen = CompressBuffer (compressedBuffer, buffer, uncompressedDataLen);
- if (compressedDataLen <= 0)
- {
- if (_wremove (outputFile))
- PkgError (L"Failed to compress the data.\nFailed also to delete package file");
- else
- PkgError (L"Failed to compress the data");
- goto err;
- }
-
- free (buffer);
- buffer = NULL;
-
- // Write the total size of the compressed data
- szTmp32bitPtr = szTmp32bit;
- mputLong (szTmp32bitPtr, (unsigned __int32) compressedDataLen);
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write the total size of the compressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot write the total size of the compressed data");
- goto err;
- }
-
- // Write the compressed data
- if (!SaveBufferToFile (compressedBuffer, outputFile, compressedDataLen, TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write compressed data to the package.\nFailed also to delete package file");
- else
- PkgError (L"Cannot write compressed data to the package");
- goto err;
- }
-
- // Write the end marker
- if (!SaveBufferToFile (MagEndMarker, outputFile, strlen (MagEndMarker), TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write the end marker.\nFailed also to delete package file");
- else
- PkgError (L"Cannot write the end marker");
- goto err;
- }
-
- free (compressedBuffer);
- compressedBuffer = NULL;
-
- // Compute and write CRC-32 hash of the entire package
- {
- DWORD tmpFileSize;
- char *tmpBuffer;
-
- tmpBuffer = LoadFile (outputFile, &tmpFileSize);
-
- if (tmpBuffer == NULL)
- {
- handleWin32Error (hwndDlg, SRC_POS);
- if (_wremove (outputFile))
- PkgError (L"Cannot load the package to compute CRC.\nFailed also to delete package file");
- else
- PkgError (L"Cannot load the package to compute CRC");
- goto err;
- }
-
- // Zero all bytes that change when the exe is digitally signed (except appended blocks).
- WipeSignatureAreas (tmpBuffer);
-
- szTmp32bitPtr = szTmp32bit;
- mputLong (szTmp32bitPtr, GetCrc32 (tmpBuffer, tmpFileSize));
- free (tmpBuffer);
-
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
- {
- if (_wremove (outputFile))
- PkgError (L"Cannot write the total size of the compressed data.\nFailed also to delete package file");
- else
- PkgError (L"Cannot write the total size of the compressed data");
- goto err;
- }
- }
-
- StringCbPrintfW (tmpStr, sizeof(tmpStr), L"Self-extracting package successfully created (%s)", outputFile);
- PkgInfo (tmpStr);
- return TRUE;
-
-err:
- if (buffer)
- free (buffer);
- if (compressedBuffer)
- free (compressedBuffer);
-
- return FALSE;
-}
-
-
-// Verifies the CRC-32 of the whole self-extracting package (except the digital signature areas, if present)
-BOOL VerifyPackageIntegrity (void)
-{
- int fileDataEndPos = 0;
- int fileDataStartPos = 0;
- unsigned __int32 crc = 0;
- unsigned char *tmpBuffer;
- int tmpFileSize;
- wchar_t path [TC_MAX_PATH];
-
- GetModuleFileName (NULL, path, ARRAYSIZE (path));
-
- fileDataEndPos = (int) FindStringInFile (path, MagEndMarker, strlen (MagEndMarker));
- if (fileDataEndPos < 0)
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- return FALSE;
- }
- fileDataEndPos--;
-
- fileDataStartPos = (int) FindStringInFile (path, MAG_START_MARKER, strlen (MAG_START_MARKER));
- if (fileDataStartPos < 0)
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- return FALSE;
- }
- fileDataStartPos += strlen (MAG_START_MARKER);
-
-
- if (!LoadInt32 (path, &crc, fileDataEndPos + strlen (MagEndMarker) + 1))
- {
- Error ("CANT_VERIFY_PACKAGE_INTEGRITY", NULL);
- return FALSE;
- }
-
- // Compute the CRC-32 hash of the whole file (except the digital signature area, if present)
- tmpBuffer = LoadFile (path, &tmpFileSize);
-
- if (tmpBuffer == NULL)
- {
- Error ("CANT_VERIFY_PACKAGE_INTEGRITY", NULL);
- return FALSE;
- }
-
- // Zero all bytes that change when an exe is digitally signed (except appended blocks).
- WipeSignatureAreas (tmpBuffer);
-
- if (crc != GetCrc32 (tmpBuffer, fileDataEndPos + 1 + strlen (MagEndMarker)))
- {
- free (tmpBuffer);
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- return FALSE;
- }
-
- free (tmpBuffer);
-
- return TRUE;
-}
-
-
-// Determines whether we are a self-extracting package
-BOOL IsSelfExtractingPackage (void)
-{
- wchar_t path [TC_MAX_PATH];
-
- GetModuleFileName (NULL, path, ARRAYSIZE (path));
-
- return (FindStringInFile (path, MagEndMarker, strlen (MagEndMarker)) != -1);
-}
-
-
-static void FreeAllFileBuffers (void)
-{
- int fileNo;
-
- if (DecompressedData != NULL)
- {
- free (DecompressedData);
- DecompressedData = NULL;
- }
-
- for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
- {
- Decompressed_Files[fileNo].fileName = NULL;
- Decompressed_Files[fileNo].fileContent = NULL;
- Decompressed_Files[fileNo].fileNameLength = 0;
- Decompressed_Files[fileNo].fileLength = 0;
- Decompressed_Files[fileNo].crc = 0;
- }
-}
-
-
-// Assumes that VerifyPackageIntegrity() has been used. Returns TRUE, if successful (otherwise FALSE).
-// Creates a table of pointers to buffers containing the following objects for each file:
-// filename size, filename (not null-terminated!), file size, file CRC-32, uncompressed file contents.
-// For details, see the definition of the DECOMPRESSED_FILE structure.
-BOOL SelfExtractInMemory (wchar_t *path)
-{
- int filePos = 0, fileNo = 0;
- int fileDataEndPos = 0;
- int fileDataStartPos = 0;
- int uncompressedLen = 0;
- int compressedLen = 0;
- unsigned char *compressedData = NULL;
- unsigned char *bufPos = NULL, *bufEndPos = NULL;
-
- FreeAllFileBuffers();
-
- fileDataEndPos = (int) FindStringInFile (path, MagEndMarker, strlen (MagEndMarker));
- if (fileDataEndPos < 0)
- {
- Error ("CANNOT_READ_FROM_PACKAGE", NULL);
- return FALSE;
- }
-
- fileDataEndPos--;
-
- fileDataStartPos = (int) FindStringInFile (path, MAG_START_MARKER, strlen (MAG_START_MARKER));
- if (fileDataStartPos < 0)
- {
- Error ("CANNOT_READ_FROM_PACKAGE", NULL);
- return FALSE;
- }
-
- fileDataStartPos += strlen (MAG_START_MARKER);
-
- filePos = fileDataStartPos;
-
- // Read the stored total size of the uncompressed data
- if (!LoadInt32 (path, &uncompressedLen, filePos))
- {
- Error ("CANNOT_READ_FROM_PACKAGE", NULL);
- return FALSE;
- }
-
- filePos += 4;
-
- // Read the stored total size of the compressed data
- if (!LoadInt32 (path, &compressedLen, filePos))
- {
- Error ("CANNOT_READ_FROM_PACKAGE", NULL);
- return FALSE;
- }
-
- filePos += 4;
-
- if (compressedLen != fileDataEndPos - fileDataStartPos - 8 + 1)
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- }
-
- DecompressedData = malloc (uncompressedLen + 524288); // + 512K reserve
- if (DecompressedData == NULL)
- {
- Error ("ERR_MEM_ALLOC", NULL);
- return FALSE;
- }
-
- bufPos = DecompressedData;
- bufEndPos = bufPos + uncompressedLen - 1;
-
- compressedData = LoadFileBlock (path, filePos, compressedLen);
-
- if (compressedData == NULL)
- {
- free (DecompressedData);
- DecompressedData = NULL;
-
- Error ("CANNOT_READ_FROM_PACKAGE", NULL);
- return FALSE;
- }
-
- // Decompress the data
- if (DecompressBuffer (DecompressedData, compressedData, compressedLen) != uncompressedLen)
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- goto sem_end;
- }
-
- while (bufPos <= bufEndPos && fileNo < NBR_COMPRESSED_FILES)
- {
- // Filename length
- Decompressed_Files[fileNo].fileNameLength = mgetWord (bufPos);
-
- // Filename
- Decompressed_Files[fileNo].fileName = (wchar_t*) bufPos;
- bufPos += (Decompressed_Files[fileNo].fileNameLength * sizeof (wchar_t));
-
- // CRC-32 of the file
- Decompressed_Files[fileNo].crc = mgetLong (bufPos);
-
- // File length
- Decompressed_Files[fileNo].fileLength = mgetLong (bufPos);
-
- // File content
- Decompressed_Files[fileNo].fileContent = bufPos;
- bufPos += Decompressed_Files[fileNo].fileLength;
-
- // Verify CRC-32 of the file (to verify that it didn't get corrupted while creating the solid archive).
- if (Decompressed_Files[fileNo].crc
- != GetCrc32 (Decompressed_Files[fileNo].fileContent, Decompressed_Files[fileNo].fileLength))
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- goto sem_end;
- }
-
- fileNo++;
- }
-
- if (fileNo < NBR_COMPRESSED_FILES)
- {
- Error ("DIST_PACKAGE_CORRUPTED", NULL);
- goto sem_end;
- }
-
- free (compressedData);
- return TRUE;
-
-sem_end:
- FreeAllFileBuffers();
- free (compressedData);
- return FALSE;
-}
-
-
-void __cdecl ExtractAllFilesThread (void *hwndDlg)
-{
- int fileNo;
- BOOL bSuccess = FALSE;
- wchar_t packageFile [TC_MAX_PATH];
-
- InvalidateRect (GetDlgItem (GetParent (hwndDlg), IDD_INSTL_DLG), NULL, TRUE);
-
- ClearLogWindow (hwndDlg);
-
- GetModuleFileName (NULL, packageFile, ARRAYSIZE (packageFile));
-
- if (!(bSuccess = SelfExtractInMemory (packageFile)))
- goto eaf_end;
-
- if (mkfulldir (DestExtractPath, TRUE) != 0)
- {
- if (mkfulldir (DestExtractPath, FALSE) != 0)
- {
- wchar_t szTmp[TC_MAX_PATH];
-
- handleWin32Error (hwndDlg, SRC_POS);
- StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), DestExtractPath);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
- bSuccess = FALSE;
- goto eaf_end;
- }
- }
-
- for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
- {
- wchar_t fileName [TC_MAX_PATH] = {0};
- wchar_t filePath [TC_MAX_PATH] = {0};
-
- // Filename
- StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);
- StringCchCopyW (filePath, ARRAYSIZE(filePath), DestExtractPath);
- StringCchCatW (filePath, ARRAYSIZE(filePath), fileName);
-
- StatusMessageParam (hwndDlg, "EXTRACTING_VERB", filePath);
-
- // Write the file
- if (!SaveBufferToFile (
- Decompressed_Files[fileNo].fileContent,
- filePath,
- Decompressed_Files[fileNo].fileLength,
- FALSE, FALSE))
- {
- wchar_t szTmp[512];
-
- StringCbPrintfW (szTmp, sizeof (szTmp), GetString ("CANNOT_WRITE_FILE_X"), filePath);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
- bSuccess = FALSE;
- goto eaf_end;
- }
- UpdateProgressBarProc ((int) (100 * ((float) fileNo / NBR_COMPRESSED_FILES)));
- }
-
-eaf_end:
- FreeAllFileBuffers();
-
- if (bSuccess)
- PostMessage (MainDlg, TC_APPMSG_EXTRACTION_SUCCESS, 0, 0);
- else
- PostMessage (MainDlg, TC_APPMSG_EXTRACTION_FAILURE, 0, 0);
-}
-
+/*
+ Derived from source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
+ by the TrueCrypt License 3.0.
+
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages.
+*/
+
+#include "Tcdefs.h"
+
+#include "Inflate.h"
+#include "SelfExtract.h"
+#include "Wizard.h"
+#include "Setup.h"
+#include "Crc.h"
+#include "Endian.h"
+#include "Dlgcode.h"
+#include "Dir.h"
+#include "Language.h"
+#include "Resource.h"
+#include <tchar.h>
+#include <Strsafe.h>
+
+#ifndef SRC_POS
+#define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
+#endif
+
+#define OutputPackageFile L"VeraCrypt Setup " _T(VERSION_STRING) L".exe"
+
+#define MAG_START_MARKER "TCINSTRT"
+#define MAG_END_MARKER_OBFUSCATED "T/C/I/N/S/C/R/C"
+#define PIPE_BUFFER_LEN (4 * BYTES_PER_KB)
+
+unsigned char MagEndMarker [sizeof (MAG_END_MARKER_OBFUSCATED)];
+wchar_t DestExtractPath [TC_MAX_PATH];
+DECOMPRESSED_FILE Decompressed_Files [NBR_COMPRESSED_FILES];
+
+volatile char *PipeWriteBuf = NULL;
+volatile HANDLE hChildStdinWrite = INVALID_HANDLE_VALUE;
+unsigned char *DecompressedData = NULL;
+
+
+
+void SelfExtractStartupInit (void)
+{
+ DeobfuscateMagEndMarker ();
+}
+
+
+// The end marker must be included in the self-extracting exe only once, not twice (used e.g.
+// by IsSelfExtractingPackage()) and that's why MAG_END_MARKER_OBFUSCATED is obfuscated and
+// needs to be deobfuscated using this function at startup.
+static void DeobfuscateMagEndMarker (void)
+{
+ int i;
+
+ for (i = 0; i < sizeof (MAG_END_MARKER_OBFUSCATED); i += 2)
+ MagEndMarker [i/2] = MAG_END_MARKER_OBFUSCATED [i];
+
+ MagEndMarker [i/2] = 0;
+}
+
+
+static void PkgError (wchar_t *msg)
+{
+ MessageBox (NULL, msg, L"VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
+}
+
+
+static void PkgWarning (wchar_t *msg)
+{
+ MessageBox (NULL, msg, L"VeraCrypt", MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
+}
+
+
+static void PkgInfo (wchar_t *msg)
+{
+ MessageBox (NULL, msg, L"VeraCrypt", MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
+}
+
+
+// Returns 0 if decompression fails or, if successful, returns the size of the decompressed data
+static int DecompressBuffer (char *out, char *in, int len)
+{
+ return (DecompressDeflatedData (out, in, len)); // Inflate
+}
+
+
+static void __cdecl PipeWriteThread (void *len)
+{
+ int sendBufSize = PIPE_BUFFER_LEN, bytesSent = 0;
+ int bytesToSend = *((int *) len), bytesSentTotal = 0;
+
+ if (PipeWriteBuf == NULL || (HANDLE) hChildStdinWrite == INVALID_HANDLE_VALUE)
+ {
+ PkgError (L"Failed sending data to the STDIN pipe");
+ return;
+ }
+
+ while (bytesToSend > 0)
+ {
+ if (bytesToSend < PIPE_BUFFER_LEN)
+ sendBufSize = bytesToSend;
+
+ if (!WriteFile ((HANDLE) hChildStdinWrite, (char *) PipeWriteBuf + bytesSentTotal, sendBufSize, &bytesSent, NULL)
+ || bytesSent == 0
+ || bytesSent != sendBufSize)
+ {
+ PkgError (L"Failed sending data to the STDIN pipe");
+ return;
+ }
+
+ bytesToSend -= bytesSent;
+ bytesSentTotal += bytesSent;
+ }
+
+ // Closing the pipe causes the child process to stop reading from it
+
+ if (!CloseHandle (hChildStdinWrite))
+ {
+ PkgError (L"Cannot close pipe");
+ return;
+ }
+}
+
+
+// Returns 0 if compression fails or, if successful, the size of the compressed data
+static int CompressBuffer (char *out, char *in, int len)
+{
+ SECURITY_ATTRIBUTES securityAttrib;
+ DWORD bytesReceived = 0;
+ HANDLE hChildStdoutWrite = INVALID_HANDLE_VALUE;
+ HANDLE hChildStdoutRead = INVALID_HANDLE_VALUE;
+ HANDLE hChildStdinRead = INVALID_HANDLE_VALUE;
+ STARTUPINFO startupInfo;
+ PROCESS_INFORMATION procInfo;
+ char pipeBuffer [PIPE_BUFFER_LEN];
+ int res_len = 0;
+ BOOL bGzipHeaderRead = FALSE;
+ wchar_t szGzipCmd[64];
+
+ ZeroMemory (&startupInfo, sizeof (startupInfo));
+ ZeroMemory (&procInfo, sizeof (procInfo));
+
+ // Pipe handle inheritance
+ securityAttrib.bInheritHandle = TRUE;
+ securityAttrib.nLength = sizeof (securityAttrib);
+ securityAttrib.lpSecurityDescriptor = NULL;
+
+ if (!CreatePipe (&hChildStdoutRead, &hChildStdoutWrite, &securityAttrib, 0))
+ {
+ PkgError (L"Cannot create STDOUT pipe.");
+ return 0;
+ }
+ SetHandleInformation (hChildStdoutRead, HANDLE_FLAG_INHERIT, 0);
+
+ if (!CreatePipe (&hChildStdinRead, &((HANDLE) hChildStdinWrite), &securityAttrib, 0))
+ {
+ PkgError (L"Cannot create STDIN pipe.");
+ CloseHandle(hChildStdoutWrite);
+ CloseHandle(hChildStdoutRead);
+ return 0;
+ }
+ SetHandleInformation (hChildStdinWrite, HANDLE_FLAG_INHERIT, 0);
+
+ // Create a child process that will compress the data
+
+ startupInfo.wShowWindow = SW_HIDE;
+ startupInfo.hStdInput = hChildStdinRead;
+ startupInfo.hStdOutput = hChildStdoutWrite;
+ startupInfo.cb = sizeof (startupInfo);
+ startupInfo.hStdError = hChildStdoutWrite;
+ startupInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+
+ StringCchCopyW (szGzipCmd, ARRAYSIZE (szGzipCmd), L"gzip --best");
+ if (!CreateProcess (NULL, szGzipCmd, NULL, NULL, TRUE, 0, NULL, NULL, &startupInfo, &procInfo))
+ {
+ PkgError (L"Error: Cannot run gzip.\n\nBefore you can create a self-extracting VeraCrypt package, you need to have the open-source 'gzip' compression tool placed in any directory in the search path for executable files (for example, in 'C:\\Windows\\').\n\nNote: gzip can be freely downloaded e.g. from www.gzip.org");
+ CloseHandle(hChildStdoutWrite);
+ CloseHandle(hChildStdoutRead);
+ CloseHandle(hChildStdinRead);
+ CloseHandle(hChildStdinWrite);
+ return 0;
+ }
+
+ CloseHandle (procInfo.hProcess);
+ CloseHandle (procInfo.hThread);
+
+ // Start sending the uncompressed data to the pipe (STDIN)
+ PipeWriteBuf = in;
+ _beginthread (PipeWriteThread, PIPE_BUFFER_LEN * 2, (void *) &len);
+
+ if (!CloseHandle (hChildStdoutWrite))
+ {
+ PkgError (L"Cannot close STDOUT write");
+ CloseHandle(hChildStdoutRead);
+ CloseHandle(hChildStdinRead);
+ return 0;
+ }
+
+ bGzipHeaderRead = FALSE;
+
+ // Read the compressed data from the pipe (sent by the child process to STDOUT)
+ while (TRUE)
+ {
+ if (!ReadFile (hChildStdoutRead, pipeBuffer, bGzipHeaderRead ? PIPE_BUFFER_LEN : 10, &bytesReceived, NULL))
+ break;
+
+ if (bGzipHeaderRead)
+ {
+ memcpy (out + res_len, pipeBuffer, bytesReceived);
+ res_len += bytesReceived;
+ }
+ else
+ bGzipHeaderRead = TRUE; // Skip the 10-byte gzip header
+ }
+
+ CloseHandle(hChildStdoutRead);
+ CloseHandle(hChildStdinRead);
+ return res_len - 8; // A gzip stream ends with a CRC-32 hash and a 32-bit size (those 8 bytes need to be chopped off)
+}
+
+
+// Clears all bytes that change when an exe file is digitally signed, except the data that are appended.
+// If those bytes weren't cleared, CRC-32 checks would fail after signing.
+static void WipeSignatureAreas (char *buffer)
+{
+ // Clear bytes 0x130-0x1ff
+ memset (buffer + 0x130, 0, 0x200 - 0x130);
+}
+
+
+BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir)
+{
+ int i, x;
+ wchar_t inputFile [TC_MAX_PATH];
+ wchar_t outputFile [TC_MAX_PATH];
+ wchar_t szTmpFilePath [TC_MAX_PATH];
+ unsigned char szTmp32bit [4] = {0};
+ unsigned char *szTmp32bitPtr = szTmp32bit;
+ unsigned char *buffer = NULL, *compressedBuffer = NULL;
+ unsigned char *bufIndex = NULL;
+ wchar_t tmpStr [2048];
+ int bufLen = 0, compressedDataLen = 0, uncompressedDataLen = 0;
+
+ x = wcslen (szDestDir);
+ if (x < 2)
+ goto err;
+
+ if (szDestDir[x - 1] != L'\\')
+ StringCbCatW (szDestDir, MAX_PATH, L"\\");
+
+ GetModuleFileName (NULL, inputFile, ARRAYSIZE (inputFile));
+
+ StringCchCopyW (outputFile, ARRAYSIZE(outputFile), szDestDir);
+ StringCchCatW (outputFile, ARRAYSIZE(outputFile), OutputPackageFile);
+
+ // Clone 'VeraCrypt Setup.exe' to create the base of the new self-extracting archive
+
+ if (!TCCopyFile (inputFile, outputFile))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ PkgError (L"Cannot copy 'VeraCrypt Setup.exe' to the package");
+ goto err;
+ }
+
+ // Determine the buffer size needed for all the files and meta data and check if all required files exist
+
+ bufLen = 0;
+
+ for (i = 0; i < sizeof (szCompressedFiles) / sizeof (szCompressedFiles[0]); i++)
+ {
+ StringCbPrintfW (szTmpFilePath, sizeof(szTmpFilePath), L"%s%s", szDestDir, szCompressedFiles[i]);
+
+ if (!FileExists (szTmpFilePath))
+ {
+ wchar_t tmpstr [1000];
+
+ StringCbPrintfW (tmpstr, sizeof(tmpstr), L"File not found:\n\n'%s'", szTmpFilePath);
+ if (_wremove (outputFile))
+ StringCbCatW (tmpstr, sizeof(tmpstr), L"\nFailed also to delete package file");
+ PkgError (tmpstr);
+ goto err;
+ }
+
+ bufLen += (int) GetFileSize64 (szTmpFilePath);
+
+ bufLen += 2; // 16-bit filename length
+ bufLen += (wcslen(szCompressedFiles[i]) * sizeof (wchar_t)); // Filename
+ bufLen += 4; // CRC-32
+ bufLen += 4; // 32-bit file length
+ }
+
+ buffer = malloc (bufLen + 524288); // + 512K reserve
+ if (buffer == NULL)
+ {
+ PkgError (L"Cannot allocate memory for uncompressed data");
+ if (_wremove (outputFile))
+ PkgError (L"Cannot allocate memory for uncompressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot allocate memory for uncompressed data");
+ goto err;
+ }
+
+
+ // Write the start marker
+ if (!SaveBufferToFile (MAG_START_MARKER, outputFile, strlen (MAG_START_MARKER), TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write the start marker\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write the start marker");
+ goto err;
+ }
+
+
+ bufIndex = buffer;
+
+ // Copy all required files and their meta data to the buffer
+ for (i = 0; i < sizeof (szCompressedFiles) / sizeof (szCompressedFiles[0]); i++)
+ {
+ DWORD tmpFileSize;
+ unsigned char *tmpBuffer;
+
+ StringCbPrintfW (szTmpFilePath, sizeof(szTmpFilePath), L"%s%s", szDestDir, szCompressedFiles[i]);
+
+ tmpBuffer = LoadFile (szTmpFilePath, &tmpFileSize);
+
+ if (tmpBuffer == NULL)
+ {
+ wchar_t tmpstr [1000];
+
+ StringCbPrintfW (tmpstr, sizeof(tmpstr), L"Cannot load file \n'%s'", szTmpFilePath);
+ if (_wremove (outputFile))
+ StringCbCatW (tmpstr, sizeof(tmpstr), L"\nFailed also to delete package file");
+ PkgError (tmpstr);
+ goto err;
+ }
+
+ // Copy the filename length to the main buffer
+ mputWord (bufIndex, (WORD) wcslen(szCompressedFiles[i]));
+
+ // Copy the filename to the main buffer
+ wmemcpy ((wchar_t*)bufIndex, szCompressedFiles[i], wcslen(szCompressedFiles[i]));
+ bufIndex += (wcslen(szCompressedFiles[i]) * sizeof (wchar_t));
+
+ // Compute CRC-32 hash of the uncompressed file and copy it to the main buffer
+ mputLong (bufIndex, GetCrc32 (tmpBuffer, tmpFileSize));
+
+ // Copy the file length to the main buffer
+ mputLong (bufIndex, (unsigned __int32) tmpFileSize);
+
+ // Copy the file contents to the main buffer
+ memcpy (bufIndex, tmpBuffer, tmpFileSize);
+ bufIndex += tmpFileSize;
+
+ free (tmpBuffer);
+ }
+
+ // Calculate the total size of the uncompressed data
+ uncompressedDataLen = (int) (bufIndex - buffer);
+
+ // Write total size of the uncompressed data
+ szTmp32bitPtr = szTmp32bit;
+ mputLong (szTmp32bitPtr, (unsigned __int32) uncompressedDataLen);
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write the total size of the uncompressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write the total size of the uncompressed data");
+ goto err;
+ }
+
+ // Compress all the files and meta data in the buffer to create a solid archive
+
+ // Test to make Coverity happy. It will always be false
+ if (uncompressedDataLen >= (INT_MAX - 524288))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot allocate memory for compressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot allocate memory for compressed data");
+ goto err;
+ }
+
+ compressedBuffer = malloc (uncompressedDataLen + 524288); // + 512K reserve
+ if (compressedBuffer == NULL)
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot allocate memory for compressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot allocate memory for compressed data");
+ goto err;
+ }
+
+ compressedDataLen = CompressBuffer (compressedBuffer, buffer, uncompressedDataLen);
+ if (compressedDataLen <= 0)
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Failed to compress the data.\nFailed also to delete package file");
+ else
+ PkgError (L"Failed to compress the data");
+ goto err;
+ }
+
+ free (buffer);
+ buffer = NULL;
+
+ // Write the total size of the compressed data
+ szTmp32bitPtr = szTmp32bit;
+ mputLong (szTmp32bitPtr, (unsigned __int32) compressedDataLen);
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write the total size of the compressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write the total size of the compressed data");
+ goto err;
+ }
+
+ // Write the compressed data
+ if (!SaveBufferToFile (compressedBuffer, outputFile, compressedDataLen, TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write compressed data to the package.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write compressed data to the package");
+ goto err;
+ }
+
+ // Write the end marker
+ if (!SaveBufferToFile (MagEndMarker, outputFile, strlen (MagEndMarker), TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write the end marker.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write the end marker");
+ goto err;
+ }
+
+ free (compressedBuffer);
+ compressedBuffer = NULL;
+
+ // Compute and write CRC-32 hash of the entire package
+ {
+ DWORD tmpFileSize;
+ char *tmpBuffer;
+
+ tmpBuffer = LoadFile (outputFile, &tmpFileSize);
+
+ if (tmpBuffer == NULL)
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ if (_wremove (outputFile))
+ PkgError (L"Cannot load the package to compute CRC.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot load the package to compute CRC");
+ goto err;
+ }
+
+ // Zero all bytes that change when the exe is digitally signed (except appended blocks).
+ WipeSignatureAreas (tmpBuffer);
+
+ szTmp32bitPtr = szTmp32bit;
+ mputLong (szTmp32bitPtr, GetCrc32 (tmpBuffer, tmpFileSize));
+ free (tmpBuffer);
+
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot write the total size of the compressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot write the total size of the compressed data");
+ goto err;
+ }
+ }
+
+ StringCbPrintfW (tmpStr, sizeof(tmpStr), L"Self-extracting package successfully created (%s)", outputFile);
+ PkgInfo (tmpStr);
+ return TRUE;
+
+err:
+ if (buffer)
+ free (buffer);
+ if (compressedBuffer)
+ free (compressedBuffer);
+
+ return FALSE;
+}
+
+
+// Verifies the CRC-32 of the whole self-extracting package (except the digital signature areas, if present)
+BOOL VerifyPackageIntegrity (void)
+{
+ int fileDataEndPos = 0;
+ int fileDataStartPos = 0;
+ unsigned __int32 crc = 0;
+ unsigned char *tmpBuffer;
+ int tmpFileSize;
+ wchar_t path [TC_MAX_PATH];
+
+ GetModuleFileName (NULL, path, ARRAYSIZE (path));
+
+ fileDataEndPos = (int) FindStringInFile (path, MagEndMarker, strlen (MagEndMarker));
+ if (fileDataEndPos < 0)
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ return FALSE;
+ }
+ fileDataEndPos--;
+
+ fileDataStartPos = (int) FindStringInFile (path, MAG_START_MARKER, strlen (MAG_START_MARKER));
+ if (fileDataStartPos < 0)
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ return FALSE;
+ }
+ fileDataStartPos += strlen (MAG_START_MARKER);
+
+
+ if (!LoadInt32 (path, &crc, fileDataEndPos + strlen (MagEndMarker) + 1))
+ {
+ Error ("CANT_VERIFY_PACKAGE_INTEGRITY", NULL);
+ return FALSE;
+ }
+
+ // Compute the CRC-32 hash of the whole file (except the digital signature area, if present)
+ tmpBuffer = LoadFile (path, &tmpFileSize);
+
+ if (tmpBuffer == NULL)
+ {
+ Error ("CANT_VERIFY_PACKAGE_INTEGRITY", NULL);
+ return FALSE;
+ }
+
+ // Zero all bytes that change when an exe is digitally signed (except appended blocks).
+ WipeSignatureAreas (tmpBuffer);
+
+ if (crc != GetCrc32 (tmpBuffer, fileDataEndPos + 1 + strlen (MagEndMarker)))
+ {
+ free (tmpBuffer);
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ return FALSE;
+ }
+
+ free (tmpBuffer);
+
+ return TRUE;
+}
+
+
+// Determines whether we are a self-extracting package
+BOOL IsSelfExtractingPackage (void)
+{
+ wchar_t path [TC_MAX_PATH];
+
+ GetModuleFileName (NULL, path, ARRAYSIZE (path));
+
+ return (FindStringInFile (path, MagEndMarker, strlen (MagEndMarker)) != -1);
+}
+
+
+static void FreeAllFileBuffers (void)
+{
+ int fileNo;
+
+ if (DecompressedData != NULL)
+ {
+ free (DecompressedData);
+ DecompressedData = NULL;
+ }
+
+ for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
+ {
+ Decompressed_Files[fileNo].fileName = NULL;
+ Decompressed_Files[fileNo].fileContent = NULL;
+ Decompressed_Files[fileNo].fileNameLength = 0;
+ Decompressed_Files[fileNo].fileLength = 0;
+ Decompressed_Files[fileNo].crc = 0;
+ }
+}
+
+
+// Assumes that VerifyPackageIntegrity() has been used. Returns TRUE, if successful (otherwise FALSE).
+// Creates a table of pointers to buffers containing the following objects for each file:
+// filename size, filename (not null-terminated!), file size, file CRC-32, uncompressed file contents.
+// For details, see the definition of the DECOMPRESSED_FILE structure.
+BOOL SelfExtractInMemory (wchar_t *path)
+{
+ int filePos = 0, fileNo = 0;
+ int fileDataEndPos = 0;
+ int fileDataStartPos = 0;
+ int uncompressedLen = 0;
+ int compressedLen = 0;
+ unsigned char *compressedData = NULL;
+ unsigned char *bufPos = NULL, *bufEndPos = NULL;
+
+ FreeAllFileBuffers();
+
+ fileDataEndPos = (int) FindStringInFile (path, MagEndMarker, strlen (MagEndMarker));
+ if (fileDataEndPos < 0)
+ {
+ Error ("CANNOT_READ_FROM_PACKAGE", NULL);
+ return FALSE;
+ }
+
+ fileDataEndPos--;
+
+ fileDataStartPos = (int) FindStringInFile (path, MAG_START_MARKER, strlen (MAG_START_MARKER));
+ if (fileDataStartPos < 0)
+ {
+ Error ("CANNOT_READ_FROM_PACKAGE", NULL);
+ return FALSE;
+ }
+
+ fileDataStartPos += strlen (MAG_START_MARKER);
+
+ filePos = fileDataStartPos;
+
+ // Read the stored total size of the uncompressed data
+ if (!LoadInt32 (path, &uncompressedLen, filePos))
+ {
+ Error ("CANNOT_READ_FROM_PACKAGE", NULL);
+ return FALSE;
+ }
+
+ filePos += 4;
+
+ // Read the stored total size of the compressed data
+ if (!LoadInt32 (path, &compressedLen, filePos))
+ {
+ Error ("CANNOT_READ_FROM_PACKAGE", NULL);
+ return FALSE;
+ }
+
+ filePos += 4;
+
+ if (compressedLen != fileDataEndPos - fileDataStartPos - 8 + 1)
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ }
+
+ DecompressedData = malloc (uncompressedLen + 524288); // + 512K reserve
+ if (DecompressedData == NULL)
+ {
+ Error ("ERR_MEM_ALLOC", NULL);
+ return FALSE;
+ }
+
+ bufPos = DecompressedData;
+ bufEndPos = bufPos + uncompressedLen - 1;
+
+ compressedData = LoadFileBlock (path, filePos, compressedLen);
+
+ if (compressedData == NULL)
+ {
+ free (DecompressedData);
+ DecompressedData = NULL;
+
+ Error ("CANNOT_READ_FROM_PACKAGE", NULL);
+ return FALSE;
+ }
+
+ // Decompress the data
+ if (DecompressBuffer (DecompressedData, compressedData, compressedLen) != uncompressedLen)
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ goto sem_end;
+ }
+
+ while (bufPos <= bufEndPos && fileNo < NBR_COMPRESSED_FILES)
+ {
+ // Filename length
+ Decompressed_Files[fileNo].fileNameLength = mgetWord (bufPos);
+
+ // Filename
+ Decompressed_Files[fileNo].fileName = (wchar_t*) bufPos;
+ bufPos += (Decompressed_Files[fileNo].fileNameLength * sizeof (wchar_t));
+
+ // CRC-32 of the file
+ Decompressed_Files[fileNo].crc = mgetLong (bufPos);
+
+ // File length
+ Decompressed_Files[fileNo].fileLength = mgetLong (bufPos);
+
+ // File content
+ Decompressed_Files[fileNo].fileContent = bufPos;
+ bufPos += Decompressed_Files[fileNo].fileLength;
+
+ // Verify CRC-32 of the file (to verify that it didn't get corrupted while creating the solid archive).
+ if (Decompressed_Files[fileNo].crc
+ != GetCrc32 (Decompressed_Files[fileNo].fileContent, Decompressed_Files[fileNo].fileLength))
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ goto sem_end;
+ }
+
+ fileNo++;
+ }
+
+ if (fileNo < NBR_COMPRESSED_FILES)
+ {
+ Error ("DIST_PACKAGE_CORRUPTED", NULL);
+ goto sem_end;
+ }
+
+ free (compressedData);
+ return TRUE;
+
+sem_end:
+ FreeAllFileBuffers();
+ free (compressedData);
+ return FALSE;
+}
+
+
+void __cdecl ExtractAllFilesThread (void *hwndDlg)
+{
+ int fileNo;
+ BOOL bSuccess = FALSE;
+ wchar_t packageFile [TC_MAX_PATH];
+
+ InvalidateRect (GetDlgItem (GetParent (hwndDlg), IDD_INSTL_DLG), NULL, TRUE);
+
+ ClearLogWindow (hwndDlg);
+
+ GetModuleFileName (NULL, packageFile, ARRAYSIZE (packageFile));
+
+ if (!(bSuccess = SelfExtractInMemory (packageFile)))
+ goto eaf_end;
+
+ if (mkfulldir (DestExtractPath, TRUE) != 0)
+ {
+ if (mkfulldir (DestExtractPath, FALSE) != 0)
+ {
+ wchar_t szTmp[TC_MAX_PATH];
+
+ handleWin32Error (hwndDlg, SRC_POS);
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), DestExtractPath);
+ MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
+ bSuccess = FALSE;
+ goto eaf_end;
+ }
+ }
+
+ for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
+ {
+ wchar_t fileName [TC_MAX_PATH] = {0};
+ wchar_t filePath [TC_MAX_PATH] = {0};
+
+ // Filename
+ StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);
+ StringCchCopyW (filePath, ARRAYSIZE(filePath), DestExtractPath);
+ StringCchCatW (filePath, ARRAYSIZE(filePath), fileName);
+
+ StatusMessageParam (hwndDlg, "EXTRACTING_VERB", filePath);
+
+ // Write the file
+ if (!SaveBufferToFile (
+ Decompressed_Files[fileNo].fileContent,
+ filePath,
+ Decompressed_Files[fileNo].fileLength,
+ FALSE, FALSE))
+ {
+ wchar_t szTmp[512];
+
+ StringCbPrintfW (szTmp, sizeof (szTmp), GetString ("CANNOT_WRITE_FILE_X"), filePath);
+ MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
+ bSuccess = FALSE;
+ goto eaf_end;
+ }
+ UpdateProgressBarProc ((int) (100 * ((float) fileNo / NBR_COMPRESSED_FILES)));
+ }
+
+eaf_end:
+ FreeAllFileBuffers();
+
+ if (bSuccess)
+ PostMessage (MainDlg, TC_APPMSG_EXTRACTION_SUCCESS, 0, 0);
+ else
+ PostMessage (MainDlg, TC_APPMSG_EXTRACTION_FAILURE, 0, 0);
+}
+
diff --git a/src/Setup/SelfExtract.h b/src/Setup/SelfExtract.h
index a93f4901..529b24d7 100644
--- a/src/Setup/SelfExtract.h
+++ b/src/Setup/SelfExtract.h
@@ -1,43 +1,43 @@
-/*
- Derived from source code of TrueCrypt 7.1a, which is
- Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
- by the TrueCrypt License 3.0.
-
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages.
-*/
-
-#include "Setup.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct
-{
- // WARNING: file name is NOT null-terminated (use fileNameLength).
- wchar_t *fileName;
- int fileNameLength;
- uint32 crc;
- __int32 fileLength;
- unsigned char *fileContent;
-} DECOMPRESSED_FILE;
-
-extern DECOMPRESSED_FILE Decompressed_Files [NBR_COMPRESSED_FILES];
-
-void SelfExtractStartupInit (void);
-BOOL SelfExtractInMemory (wchar_t *path);
-void __cdecl ExtractAllFilesThread (void *hwndDlg);
-BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir);
-BOOL VerifyPackageIntegrity (void);
-BOOL IsSelfExtractingPackage (void);
-static void DeobfuscateMagEndMarker (void);
-
-extern wchar_t DestExtractPath [TC_MAX_PATH];
-
-#ifdef __cplusplus
-}
-#endif
+/*
+ Derived from source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
+ by the TrueCrypt License 3.0.
+
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages.
+*/
+
+#include "Setup.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+ // WARNING: file name is NOT null-terminated (use fileNameLength).
+ wchar_t *fileName;
+ int fileNameLength;
+ uint32 crc;
+ __int32 fileLength;
+ unsigned char *fileContent;
+} DECOMPRESSED_FILE;
+
+extern DECOMPRESSED_FILE Decompressed_Files [NBR_COMPRESSED_FILES];
+
+void SelfExtractStartupInit (void);
+BOOL SelfExtractInMemory (wchar_t *path);
+void __cdecl ExtractAllFilesThread (void *hwndDlg);
+BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir);
+BOOL VerifyPackageIntegrity (void);
+BOOL IsSelfExtractingPackage (void);
+static void DeobfuscateMagEndMarker (void);
+
+extern wchar_t DestExtractPath [TC_MAX_PATH];
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c
index 7c382986..899c1583 100644
--- a/src/Setup/Setup.c
+++ b/src/Setup/Setup.c
@@ -1,2632 +1,2632 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#include "Tcdefs.h"
-#include <SrRestorePtApi.h>
-#include <io.h>
-#include <propkey.h>
-#include <propvarutil.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <tchar.h>
-
-#include "Apidrvr.h"
-#include "BootEncryption.h"
-#include "Boot/Windows/BootCommon.h"
-#include "Combo.h"
-#include "ComSetup.h"
-#include "Dlgcode.h"
-#include "Language.h"
-#include "Registry.h"
-#include "Resource.h"
-
-#include "Dir.h"
-#include "Setup.h"
-#include "SelfExtract.h"
-#include "Wizard.h"
-
-#include "../Common/Resource.h"
-
-using namespace VeraCrypt;
-
-#pragma warning( disable : 4201 )
-#pragma warning( disable : 4115 )
-
-#include <shlobj.h>
-
-#pragma warning( default : 4201 )
-#pragma warning( default : 4115 )
-
-#include <Strsafe.h>
-
-wchar_t InstallationPath[TC_MAX_PATH];
-wchar_t SetupFilesDir[TC_MAX_PATH];
-wchar_t UninstallBatch[MAX_PATH];
-
-BOOL bUninstall = FALSE;
-BOOL bRestartRequired = FALSE;
-BOOL bMakePackage = FALSE;
-BOOL bDone = FALSE;
-BOOL Rollback = FALSE;
-BOOL bUpgrade = FALSE;
-BOOL bDowngrade = FALSE;
-BOOL SystemEncryptionUpdate = FALSE;
-BOOL PortableMode = FALSE;
-BOOL bRepairMode = FALSE;
-BOOL bReinstallMode = FALSE;
-BOOL bChangeMode = FALSE;
-BOOL bDevm = FALSE;
-BOOL bPossiblyFirstTimeInstall = FALSE;
-BOOL bUninstallInProgress = FALSE;
-BOOL UnloadDriver = TRUE;
-
-BOOL bSystemRestore = TRUE;
-BOOL bDisableSwapFiles = FALSE;
-BOOL bForAllUsers = TRUE;
-BOOL bRegisterFileExt = TRUE;
-BOOL bAddToStartMenu = TRUE;
-BOOL bDesktopIcon = TRUE;
-
-BOOL bDesktopIconStatusDetermined = FALSE;
-
-HMODULE volatile SystemRestoreDll = 0;
-
-void localcleanup (void)
-{
- localcleanupwiz ();
- cleanup ();
-
- 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;
-
- if (bCheckForOldFile)
- {
- wchar_t szOldPath[MAX_PATH + 1];
- StringCbCopyW (szOldPath, sizeof(szOldPath), lpszFile);
- StringCbCatW (szOldPath, sizeof(szOldPath), VC_FILENAME_RENAMED_SUFFIX);
-
- if (_wstat64 (szOldPath, &st) == 0)
- {
- ForceDeleteFile (szOldPath);
- }
- }
-
- if (_wstat64 (lpszFile, &st) == 0)
- return ForceDeleteFile (lpszFile);
- else
- return TRUE;
-}
-
-BOOL StatRemoveDirectory (wchar_t *lpszDir)
-{
- struct __stat64 st;
-
- if (_wstat64 (lpszDir, &st) == 0)
- {
- BOOL bStatus = RemoveDirectory (lpszDir);
- if (!bStatus)
- {
- /* force removal of the non empty directory */
- wchar_t szOpPath[TC_MAX_PATH + 1] = {0};
- SHFILEOPSTRUCTW op;
-
- StringCchCopyW(szOpPath, ARRAYSIZE(szOpPath)-1, lpszDir);
- ZeroMemory(&op, sizeof(op));
- op.wFunc = FO_DELETE;
- op.pFrom = szOpPath;
- op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR;
-
- if ((0 == SHFileOperation(&op)) && (!op.fAnyOperationsAborted))
- bStatus = TRUE;
- }
- return bStatus;
- }
- else
- return TRUE;
-}
-
-
-/* Recursively set the given OWNER security descriptor to the key and its subkeys */
-static void RecursiveSetOwner (HKEY hKey, PSECURITY_DESCRIPTOR pSD)
-{
- LSTATUS status = 0;
- DWORD dwIndex = 0, dwMaxNameLen = 0, dwNameLen = 0, numberSubKeys = 0;
- HKEY hSubKey;
-
- if ( (ERROR_SUCCESS == status) && (ERROR_SUCCESS == RegQueryInfoKey(hKey, NULL, NULL, NULL, &numberSubKeys, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
- && (numberSubKeys >= 1)
- )
- {
- dwMaxNameLen++;
- wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
- while (true)
- {
- dwNameLen = dwMaxNameLen;
- status = RegEnumKeyExW (hKey, dwIndex++, szNameValue, &dwNameLen, NULL, NULL, NULL, NULL);
- if (status == ERROR_SUCCESS)
- {
- status = RegOpenKeyExW (hKey, szNameValue, 0, WRITE_OWNER | KEY_READ , &hSubKey);
- if (ERROR_SUCCESS == status)
- {
- RecursiveSetOwner (hSubKey, pSD);
- RegCloseKey(hSubKey);
- }
- }
- else
- break;
- }
- delete [] szNameValue;
- }
-
- RegSetKeySecurity (hKey, OWNER_SECURITY_INFORMATION, pSD);
-}
-
-/* Recursively set the given DACL security descriptor to the key and its subkeys */
-static void RecursiveSetDACL (HKEY hKey, const wchar_t* SubKeyName, PSECURITY_DESCRIPTOR pSD)
-{
- HKEY hSubKey;
- DWORD dwIndex = 0, dwMaxNameLen = 0, dwNameLen = 0, numberSubKeys = 0;
- LSTATUS status = RegOpenKeyExW(hKey, SubKeyName, 0, WRITE_DAC | KEY_READ /*| ACCESS_SYSTEM_SECURITY*/, &hSubKey);
- if (status == ERROR_SUCCESS)
- {
- status = RegSetKeySecurity (hSubKey, DACL_SECURITY_INFORMATION, pSD);
- if (status == ERROR_SUCCESS)
- {
- RegCloseKey(hSubKey);
- status = RegOpenKeyExW(hKey, SubKeyName, 0, WRITE_DAC | KEY_READ , &hSubKey);
- }
-
- if ( (ERROR_SUCCESS == status)
- && (ERROR_SUCCESS == RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &numberSubKeys, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
- && (numberSubKeys >= 1)
- )
- {
- dwMaxNameLen++;
- wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
- while (true)
- {
- dwNameLen = dwMaxNameLen;
- status = RegEnumKeyExW (hSubKey, dwIndex++, szNameValue, &dwNameLen, NULL, NULL, NULL, NULL);
- if (status == ERROR_SUCCESS)
- {
- RecursiveSetDACL (hSubKey, szNameValue, pSD);
- }
- else
- break;
- }
- delete [] szNameValue;
- }
- }
-}
-
-/* Correct the key permissions to allow its deletion */
-static void AllowKeyAccess(HKEY Key,const wchar_t* SubKeyName)
-{
- LSTATUS RegResult;
- HKEY SvcKey = NULL;
- DWORD dwLength = 0;
- HANDLE Token = NULL;
- PTOKEN_USER pTokenUser = NULL;
- std::string sNewSD;
-
- RegResult = RegOpenKeyExW(Key, SubKeyName, 0, WRITE_OWNER | KEY_READ, &SvcKey);
- if (RegResult==ERROR_SUCCESS)
- {
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token))
- {
- if (!GetTokenInformation(Token, TokenUser, pTokenUser, 0, &dwLength))
- {
- if (GetLastError() ==ERROR_INSUFFICIENT_BUFFER)
- {
- pTokenUser = (PTOKEN_USER) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
- if (pTokenUser)
- {
- if (GetTokenInformation(Token, TokenUser, pTokenUser, dwLength, &dwLength))
- {
- SECURITY_DESCRIPTOR SecDesc;
- if ( InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION)
- && SetSecurityDescriptorDacl(&SecDesc, TRUE, NULL, FALSE) // NULL DACL: full access to everyone
- && SetSecurityDescriptorOwner(&SecDesc, pTokenUser->User.Sid, FALSE)
- )
- {
- RecursiveSetOwner(SvcKey, &SecDesc);
- }
- }
-
- }
- }
- }
- }
- RegCloseKey(SvcKey);
- }
-
- if (pTokenUser)
- {
- PSID pSid = pTokenUser->User.Sid;
- DWORD dwAclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + ::GetLengthSid(pSid) - sizeof(DWORD);
- PACL pDacl = (PACL) new BYTE[dwAclSize];
- if (pDacl)
- {
- if (TRUE == ::InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
- {
- if (TRUE == AddAccessAllowedAceEx(pDacl, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, WRITE_DAC | KEY_ALL_ACCESS, pSid))
- {
- SECURITY_DESCRIPTOR SecDesc;
- if (TRUE == ::InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
- {
- if (TRUE == ::SetSecurityDescriptorDacl(&SecDesc, TRUE, pDacl, FALSE))
- {
- RecursiveSetDACL (Key, SubKeyName, &SecDesc);
- }
- }
- }
- }
- delete [] pDacl;
- }
- }
-
- if (pTokenUser)
- HeapFree(GetProcessHeap(), 0, pTokenUser);
- if (Token)
- CloseHandle(Token);
-}
-
-void SearchAndDeleteRegistrySubString (HKEY hKey, const wchar_t *subKey, const wchar_t *str, BOOL bEnumSubKeys, const wchar_t* enumMatchSubStr)
-{
- HKEY hSubKey = 0;
- LSTATUS status = 0;
- DWORD dwIndex = 0, dwType, dwValueNameLen, dwDataLen;
- std::list<std::wstring> subKeysList;
- size_t subStringLength = str? wcslen(str) : 0;
-
- if (bEnumSubKeys)
- {
- DWORD dwMaxNameLen = 0;
- if (ERROR_SUCCESS == RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
- {
- dwMaxNameLen++;
- wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
- dwIndex = 0;
- while (true)
- {
- dwValueNameLen = dwMaxNameLen;
- status = RegEnumKeyExW (hKey, dwIndex++, szNameValue, &dwValueNameLen, NULL, NULL, NULL, NULL);
- if (status == ERROR_SUCCESS)
- {
- if (enumMatchSubStr && !wcsstr(szNameValue, enumMatchSubStr))
- continue;
- std::wstring entryName = szNameValue;
- entryName += L"\\";
- entryName += subKey;
- entryName += L"\\";
- subKeysList.push_back(entryName);
- }
- else
- break;
- }
- delete [] szNameValue;
- }
- }
- else
- {
- subKeysList.push_back(subKey);
- }
-
- for (std::list<std::wstring>::iterator ItSubKey = subKeysList.begin(); ItSubKey != subKeysList.end(); ItSubKey++)
- {
- // if the string to search for is empty, delete the sub key, otherwise, look for matching value and delete them
- if (subStringLength == 0)
- {
- if (ERROR_ACCESS_DENIED == DeleteRegistryKey (hKey, ItSubKey->c_str()))
- {
- // grant permission to delete
- AllowKeyAccess (hKey, ItSubKey->c_str());
-
- // try again
- DeleteRegistryKey (hKey, ItSubKey->c_str());
- }
- }
- else
- {
- if (RegOpenKeyExW (hKey, ItSubKey->c_str(), 0, KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
- {
- DWORD dwMaxNameLen = 0, dwMaxDataLen = 0;
- if (ERROR_SUCCESS == RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwMaxNameLen, &dwMaxDataLen, NULL, NULL))
- {
- dwMaxNameLen++;
- wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
- LPBYTE pbData = new BYTE[dwMaxDataLen];
-
- std::list<std::wstring> foundEntries;
- dwIndex = 0;
- do
- {
- dwValueNameLen = dwMaxNameLen;
- dwDataLen = dwMaxDataLen;
- status = RegEnumValueW(hSubKey, dwIndex++, szNameValue, &dwValueNameLen, NULL, &dwType, pbData, &dwDataLen);
- if (status == ERROR_SUCCESS)
- {
- if ( (wcslen(szNameValue) >= subStringLength && wcsstr(szNameValue, str))
- || (dwType == REG_SZ && wcslen((wchar_t*) pbData) >= subStringLength && wcsstr((wchar_t*) pbData, str))
- )
- {
- foundEntries.push_back(szNameValue);
- }
- }
- } while ((status == ERROR_SUCCESS) || (status == ERROR_MORE_DATA)); // we ignore ERROR_MORE_DATA errors since
- // we are sure to use the correct sizes
-
- // delete the entries
- if (!foundEntries.empty())
- {
- for (std::list<std::wstring>::iterator It = foundEntries.begin();
- It != foundEntries.end(); It++)
- {
- RegDeleteValueW (hSubKey, It->c_str());
- }
- }
-
- delete [] szNameValue;
- delete [] pbData;
- }
-
-
- RegCloseKey (hSubKey);
- }
- }
- }
-}
-
-/* Set the given privilege of the current process */
-BOOL SetPrivilege(LPTSTR szPrivilegeName, BOOL bEnable)
-{
- TOKEN_PRIVILEGES tp;
- LUID luid;
- HANDLE hProcessToken;
- BOOL bStatus = FALSE;
-
- if ( OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
- &hProcessToken) )
- {
- if ( LookupPrivilegeValue(
- NULL,
- szPrivilegeName,
- &luid ) )
- {
-
- tp.PrivilegeCount = 1;
- tp.Privileges[0].Luid = luid;
- tp.Privileges[0].Attributes = bEnable? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED;
-
- // Enable the privilege
- bStatus = AdjustTokenPrivileges(
- hProcessToken,
- FALSE,
- &tp,
- sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES) NULL,
- (PDWORD) NULL);
- }
-
- CloseHandle(hProcessToken);
- }
-
- return bStatus;
-}
-
-/*
- * Creates a VT_LPWSTR propvariant.
- * we use our own implementation to use SHStrDupW function pointer
- * that we retreive ourselves to avoid dll hijacking attacks
- */
-inline HRESULT VCInitPropVariantFromString(__in PCWSTR psz, __out PROPVARIANT *ppropvar)
-{
- ppropvar->vt = VT_LPWSTR;
- HRESULT hr = VCStrDupW(psz, &ppropvar->pwszVal);
- if (FAILED(hr))
- {
- PropVariantInit(ppropvar);
- }
- return hr;
-}
-
-HRESULT CreateLink (wchar_t *lpszPathObj, wchar_t *lpszArguments,
- wchar_t *lpszPathLink, const wchar_t* iconFile, int iconIndex)
-{
- HRESULT hres;
- IShellLink *psl;
-
- /* Get a pointer to the IShellLink interface. */
- hres = CoCreateInstance (CLSID_ShellLink, NULL,
- CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
- if (SUCCEEDED (hres))
- {
- IPersistFile *ppf;
-
- /* Set the path to the shortcut target, and add the
- description. */
- psl->SetPath (lpszPathObj);
- psl->SetArguments (lpszArguments);
- if (iconFile)
- {
- psl->SetIconLocation (iconFile, iconIndex);
- }
-
- // Application ID
- if (_tcsstr (lpszPathObj, _T(TC_APP_NAME) _T(".exe")))
- {
- IPropertyStore *propStore;
-
- if (SUCCEEDED (psl->QueryInterface (IID_PPV_ARGS (&propStore))))
- {
- PROPVARIANT propVariant;
- if (SUCCEEDED (VCInitPropVariantFromString (TC_APPLICATION_ID, &propVariant)))
- {
- if (SUCCEEDED (propStore->SetValue (PKEY_AppUserModel_ID, propVariant)))
- propStore->Commit();
-
- PropVariantClear (&propVariant);
- }
-
- propStore->Release();
- }
- }
-
- /* Query IShellLink for the IPersistFile interface for saving
- the shortcut in persistent storage. */
- hres = psl->QueryInterface (IID_IPersistFile,
- (void **) &ppf);
-
- if (SUCCEEDED (hres))
- {
- /* Save the link by calling IPersistFile::Save. */
- hres = ppf->Save (lpszPathLink, TRUE);
- ppf->Release ();
- }
- psl->Release ();
- }
- return hres;
-}
-
-BOOL IsSystemRestoreEnabled ()
-{
- BOOL bEnabled = FALSE;
- HKEY hKey;
- DWORD dwValue = 0, cbValue = sizeof (DWORD);
- wchar_t szRegPath[MAX_PATH];
- GetRestorePointRegKeyName (szRegPath, sizeof (szRegPath));
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, szRegPath, 0, KEY_READ | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)
- {
- if (IsOSAtLeast (WIN_VISTA))
- {
- if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"RPSessionInterval", NULL, NULL, (LPBYTE) &dwValue, &cbValue))
- && (dwValue == 1)
- )
- {
- bEnabled = TRUE;
- }
- }
- else
- {
- if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"DisableSR", NULL, NULL, (LPBYTE) &dwValue, &cbValue))
- && (dwValue == 0)
- )
- {
- bEnabled = TRUE;
- }
- }
-
-
- RegCloseKey (hKey);
- }
-
- return bEnabled;
-}
-
-void GetProgramPath (HWND hwndDlg, wchar_t *path)
-{
- ITEMIDLIST *i;
- HRESULT res;
-
- if (bForAllUsers)
- res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
- else
- res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
-
- SHGetPathFromIDList (i, path);
-}
-
-void StatusMessage (HWND hwndDlg, char *stringId)
-{
- if (Rollback)
- return;
-
- SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) GetString (stringId));
-
- SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
- SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
-}
-
-void StatusMessageParam (HWND hwndDlg, char *stringId, wchar_t *param)
-{
- wchar_t szTmp[1024];
-
- if (Rollback)
- return;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s %s", GetString (stringId), param);
- SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) szTmp);
-
- SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
- SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
-}
-
-void ClearLogWindow (HWND hwndDlg)
-{
- SendMessage (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_RESETCONTENT, 0, 0);
-}
-
-void RegMessage (HWND hwndDlg, wchar_t *txt)
-{
- StatusMessageParam (hwndDlg, "ADDING_REG", txt);
-}
-
-void CopyMessage (HWND hwndDlg, wchar_t *txt)
-{
- StatusMessageParam (hwndDlg, "INSTALLING", txt);
-}
-
-void RemoveMessage (HWND hwndDlg, wchar_t *txt)
-{
- if (!Rollback)
- StatusMessageParam (hwndDlg, "REMOVING", txt);
-}
-
-void IconMessage (HWND hwndDlg, wchar_t *txt)
-{
- StatusMessageParam (hwndDlg, "ADDING_ICON", txt);
-}
-
-void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr)
-{
- LONG driverVersion = VERSION_NUM;
- int status = 0;
-
- if (hDriver == INVALID_HANDLE_VALUE)
- status = DriverAttach();
-
- if ((status == 0) && (hDriver != INVALID_HANDLE_VALUE))
- {
- DWORD dwResult;
- BOOL bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
-
- if (!bResult)
- bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
-
-
- bUpgrade = (bResult && driverVersion <= VERSION_NUM);
- bDowngrade = (bResult && driverVersion > VERSION_NUM);
- bReinstallMode = (bResult && driverVersion == VERSION_NUM);
-
- PortableMode = DeviceIoControl (hDriver, TC_IOCTL_GET_PORTABLE_MODE_STATUS, NULL, 0, NULL, 0, &dwResult, NULL);
-
- if (bCloseDriverHandle)
- {
- CloseHandle (hDriver);
- hDriver = INVALID_HANDLE_VALUE;
- }
- }
-
- *driverVersionPtr = driverVersion;
-}
-
-
-static BOOL IsFileInUse (const wstring &filePath)
-{
- HANDLE useTestHandle = CreateFile (filePath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
-
- if (useTestHandle != INVALID_HANDLE_VALUE)
- CloseHandle (useTestHandle);
- else if (GetLastError() == ERROR_SHARING_VIOLATION)
- return TRUE;
-
- return FALSE;
-}
-
-
-BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir)
-{
- /* WARNING: Note that, despite its name, this function is used during UNinstallation as well. */
-
- wchar_t szTmp[TC_MAX_PATH];
- BOOL bOK = TRUE;
- int i, x, fileNo;
- wchar_t curFileName [TC_MAX_PATH] = {0};
-
- if (!bUninstall && !bDevm)
- {
- // Self-extract all files to memory
-
- GetModuleFileName (NULL, szTmp, ARRAYSIZE (szTmp));
-
- if (!SelfExtractInMemory (szTmp))
- return FALSE;
- }
-
- x = wcslen (szDestDir);
- if (x < 2)
- return FALSE;
-
- if (szDestDir[x - 1] != L'\\')
- StringCbCatW (szDestDir, MAX_PATH, L"\\");
-
- for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
- {
- BOOL bResult, driver64 = FALSE;
- wchar_t szDir[TC_MAX_PATH];
-
- if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0)
- {
- if (bUninstall)
- continue; // Prevent 'access denied' error
-
- if (bRepairMode)
- continue; // Destination = target
- }
-
- // skip files that don't apply to the current architecture
- if ( (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x64.exe") == 0))
- || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x64.exe") == 0))
- || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x64.exe") == 0))
- || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0))
- || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0))
- || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0))
- )
- {
- continue;
- }
-
- 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'\\')
- StringCbCatW (szDir, sizeof(szDir), L"\\");
-
- StringCbCatW (szDir, sizeof(szDir), L"Drivers\\");
- }
- else if (*szFiles[i] == L'W')
- GetWindowsDirectory (szDir, ARRAYSIZE (szDir));
-
- if (*szFiles[i] == L'I')
- continue;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, szFiles[i] + 1);
-
- if (bUninstall == FALSE)
- CopyMessage (hwndDlg, szTmp);
- else
- RemoveMessage (hwndDlg, szTmp);
-
- if (bUninstall == FALSE)
- {
- SetCurrentDirectory (SetupFilesDir);
-
- if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0)
- {
- // Copy ourselves (the distribution package) to the destination location as 'VeraCrypt Setup.exe'
-
- wchar_t mp[MAX_PATH];
-
- GetModuleFileName (NULL, mp, ARRAYSIZE (mp));
- bResult = TCCopyFile (mp, szTmp);
- }
- else
- {
- 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)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-x64.exe", sizeof (L"VeraCrypt-x64.exe"));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt.exe", sizeof (L"VeraCrypt.exe"));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCryptExpander.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander-x64.exe", sizeof (L"VeraCryptExpander-x64.exe"));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander.exe", sizeof (L"VeraCryptExpander.exe"));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCrypt Format.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format-x64.exe", sizeof (L"VeraCrypt Format-x64.exe"));
- }
-
- if (Is64BitOs ()
- && wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0)
- {
- StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format.exe", sizeof (L"VeraCrypt Format.exe"));
- }
-
- if (!bDevm)
- {
- bResult = FALSE;
-
- // Find the correct decompressed file in memory
- for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
- {
- // Write the file (stored in memory) directly to the destination location
- // (there will be no temporary files).
- if (wmemcmp (
- curFileName,
- Decompressed_Files[fileNo].fileName,
- min (wcslen (curFileName), (size_t) Decompressed_Files[fileNo].fileNameLength)) == 0)
- {
- // Dump filter driver cannot be installed to SysWOW64 directory
- if (driver64 && !EnableWow64FsRedirection (FALSE))
- {
- handleWin32Error (hwndDlg, SRC_POS);
- bResult = FALSE;
- goto err;
- }
-
- bResult = SaveBufferToFile (
- (char *) Decompressed_Files[fileNo].fileContent,
- szTmp,
- Decompressed_Files[fileNo].fileLength,
- FALSE,
- TRUE);
-
- if (driver64)
- {
- if (!EnableWow64FsRedirection (TRUE))
- {
- handleWin32Error (hwndDlg, SRC_POS);
- bResult = FALSE;
- goto err;
- }
-
- if (!bResult)
- goto err;
-
- }
-
- break;
- }
- }
- }
- else
- {
- if (driver64)
- EnableWow64FsRedirection (FALSE);
-
- bResult = TCCopyFile (curFileName, szTmp);
-
- if (driver64)
- EnableWow64FsRedirection (TRUE);
- }
-
- if (bResult && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0)
- {
- if (Is64BitOs ())
- EnableWow64FsRedirection (FALSE);
-
- wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
- wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true);
- wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false);
- wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true);
-
- if ( FileExists (servicePath.c_str())
- || (Is64BitOs () && FileExists (serviceLegacyPath.c_str()))
- )
- {
- CopyMessage (hwndDlg, (wchar_t *) servicePath.c_str());
- bResult = CopyFile (szTmp, servicePath.c_str(), FALSE);
- }
-
- if (bResult && Is64BitOs ()
- && FileExists (favoritesLegacyFile.c_str())
- && !FileExists (favoritesFile.c_str()))
- {
- // copy the favorites XML file to the native system directory
- bResult = CopyFile (favoritesLegacyFile.c_str(), favoritesFile.c_str(), FALSE);
- }
-
- if (bResult && Is64BitOs () && FileExists (favoritesFile.c_str()) && FileExists (servicePath.c_str()))
- {
- // Update the path of the service
- BootEncryption BootEncObj (hwndDlg);
-
- try
- {
- if (BootEncObj.GetDriverServiceStartType() == SERVICE_BOOT_START)
- {
- BootEncObj.UpdateSystemFavoritesService ();
- }
- }
- catch (...) {}
- }
-
- if (Is64BitOs ())
- {
- // delete files from legacy path
- if (FileExists (favoritesLegacyFile.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
- ForceDeleteFile (favoritesLegacyFile.c_str());
- }
-
- if (FileExists (serviceLegacyPath.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
- ForceDeleteFile (serviceLegacyPath.c_str());
- }
-
- EnableWow64FsRedirection (TRUE);
- }
- }
- }
- }
- 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);
-
- wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
- wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true);
- wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false);
- wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true);
-
- // delete all files related to system favorites service
- if (FileExists (favoritesFile.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) favoritesFile.c_str());
- ForceDeleteFile (favoritesFile.c_str());
- }
-
- if (FileExists (servicePath.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) servicePath.c_str());
- ForceDeleteFile (servicePath.c_str());
- }
-
- if (Is64BitOs ())
- {
- if (FileExists (favoritesLegacyFile.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
- ForceDeleteFile (favoritesLegacyFile.c_str());
- }
-
- if (FileExists (serviceLegacyPath.c_str()))
- {
- RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
- ForceDeleteFile (serviceLegacyPath.c_str());
- }
-
- EnableWow64FsRedirection (TRUE);
- }
- }
- }
-
-err:
- if (bResult == FALSE)
- {
- LPVOID lpMsgBuf;
- DWORD dwError = GetLastError ();
- wchar_t szTmp2[700];
- wchar_t szErrorValue[16];
- wchar_t* pszDesc;
-
- FormatMessage (
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
- (wchar_t *) &lpMsgBuf,
- 0,
- NULL
- );
-
- if (lpMsgBuf)
- pszDesc = (wchar_t*) lpMsgBuf;
- else
- {
- StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"0x%.8X", dwError);
- pszDesc = szErrorValue;
- }
-
- if (bUninstall == FALSE)
- StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("INSTALL_OF_FAILED"), szTmp, pszDesc);
- else
- StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("UNINSTALL_OF_FAILED"), szTmp, pszDesc);
-
- if (lpMsgBuf) LocalFree (lpMsgBuf);
-
- if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
- return FALSE;
- }
- }
-
- // Language pack
- if (bUninstall == FALSE)
- {
- WIN32_FIND_DATA f;
- HANDLE h;
-
- SetCurrentDirectory (SetupFilesDir);
- h = FindFirstFile (L"Language.*.xml", &f);
-
- if (h != INVALID_HANDLE_VALUE)
- {
- wchar_t d[MAX_PATH*2];
- StringCbPrintfW (d, sizeof(d), L"%s%s", szDestDir, f.cFileName);
- CopyMessage (hwndDlg, d);
- TCCopyFile (f.cFileName, d);
- FindClose (h);
- }
-
- SetCurrentDirectory (SetupFilesDir);
- SetCurrentDirectory (L"Setup files");
- h = FindFirstFile (L"VeraCrypt User Guide.*.pdf", &f);
- if (h != INVALID_HANDLE_VALUE)
- {
- wchar_t d[MAX_PATH*2];
- StringCbPrintfW (d, sizeof(d), L"%s%s", szDestDir, f.cFileName);
- CopyMessage (hwndDlg, d);
- TCCopyFile (f.cFileName, d);
- FindClose (h);
- }
- SetCurrentDirectory (SetupFilesDir);
- }
-
- return bOK;
-}
-
-BOOL DoRegInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bInstallType)
-{
- wchar_t szDir[TC_MAX_PATH], *key;
- wchar_t szTmp[TC_MAX_PATH*4];
- HKEY hkey = 0;
- BOOL bSlash, bOK = FALSE;
- DWORD dw;
- int x;
-
- if (SystemEncryptionUpdate)
- {
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt",
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_32KEY, NULL, &hkey, &dw) == ERROR_SUCCESS)
- {
- StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING));
- RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t));
-
- StringCbCopyW (szTmp, sizeof(szTmp), _T(TC_HOMEPAGE));
- RegSetValueEx (hkey, L"URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t));
-
- RegCloseKey (hkey);
- }
-
- return TRUE;
- }
-
- StringCbCopyW (szDir, sizeof(szDir), szDestDir);
- x = wcslen (szDestDir);
- if (szDestDir[x - 1] == L'\\')
- bSlash = TRUE;
- else
- bSlash = FALSE;
-
- if (bSlash == FALSE)
- StringCbCatW (szDir, sizeof(szDir), L"\\");
-
- if (bInstallType)
- {
-
- key = L"Software\\Classes\\VeraCryptVolume";
- RegMessage (hwndDlg, key);
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- key,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCrypt Volume");
- if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%ws", TC_APPLICATION_ID);
- if (RegSetValueEx (hkey, L"AppUserModelID", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- RegCloseKey (hkey);
- hkey = 0;
-
- key = L"Software\\Classes\\VeraCryptVolume\\DefaultIcon";
- RegMessage (hwndDlg, key);
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- key,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%sVeraCrypt.exe,1", szDir);
- if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- RegCloseKey (hkey);
- hkey = 0;
-
- key = L"Software\\Classes\\VeraCryptVolume\\Shell\\open\\command";
- RegMessage (hwndDlg, key);
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- key,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt.exe\" /v \"%%1\"", szDir );
- if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- RegCloseKey (hkey);
- hkey = 0;
-
- key = L"Software\\Classes\\.hc";
- BOOL typeClassChanged = TRUE;
- wchar_t typeClass[256];
- DWORD typeClassSize = sizeof (typeClass);
-
- if (ReadLocalMachineRegistryString (key, L"", typeClass, &typeClassSize) && typeClassSize > 0 && wcscmp (typeClass, L"VeraCryptVolume") == 0)
- typeClassChanged = FALSE;
-
- RegMessage (hwndDlg, key);
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- key,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCryptVolume");
- if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- RegCloseKey (hkey);
- hkey = 0;
-
- if (typeClassChanged)
- SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
- }
-
- key = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt";
- RegMessage (hwndDlg, key);
- if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- key,
- 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_32KEY, NULL, &hkey, &dw) != ERROR_SUCCESS)
- goto error;
-
- /* IMPORTANT: IF YOU CHANGE THIS IN ANY WAY, REVISE AND UPDATE SetInstallationPath() ACCORDINGLY! */
- StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\" /u", szDir);
- if (RegSetValueEx (hkey, L"UninstallString", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\" /c", szDir);
- if (RegSetValueEx (hkey, L"ModifyPath", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\"", szDir);
- if (RegSetValueEx (hkey, L"DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING));
- if (RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCrypt");
- if (RegSetValueEx (hkey, L"DisplayName", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), L"IDRIX");
- if (RegSetValueEx (hkey, L"Publisher", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- StringCbCopyW (szTmp, sizeof(szTmp), _T(TC_HOMEPAGE));
- if (RegSetValueEx (hkey, L"URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
- goto error;
-
- bOK = TRUE;
-
-error:
- if (hkey != 0)
- RegCloseKey (hkey);
-
- if (bOK == FALSE)
- {
- handleWin32Error (hwndDlg, SRC_POS);
- Error ("REG_INSTALL_FAILED", hwndDlg);
- }
-
- // Register COM servers for UAC
- if (IsOSAtLeast (WIN_VISTA))
- {
- if (!RegisterComServers (szDir))
- {
- Error ("COM_REG_FAILED", hwndDlg);
- return FALSE;
- }
- }
-
- return bOK;
-}
-
-BOOL DoApplicationDataUninstall (HWND hwndDlg)
-{
- wchar_t path[MAX_PATH];
- wchar_t path2[MAX_PATH];
- BOOL bOK = TRUE;
-
- StatusMessage (hwndDlg, "REMOVING_APPDATA");
-
- SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
- StringCbCatW (path, sizeof(path), L"\\VeraCrypt\\");
-
- // Delete favorite volumes file
- StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_FAVORITE_VOLUMES);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- // Delete keyfile defaults
- StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_DEFAULT_KEYFILES);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- // Delete history file
- StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_HISTORY);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- // Delete configuration file
- StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_CONFIGURATION);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- // Delete system encryption configuration file
- StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
- StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
- RemoveMessage (hwndDlg, path);
- if (!StatRemoveDirectory (path))
- {
- handleWin32Error (hwndDlg, SRC_POS);
- bOK = FALSE;
- }
-
- // remove VeraCrypt under common appdata
- if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
- {
- StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
-
- // Delete original bootloader
- StringCbPrintfW (path2, sizeof(path2), L"%s\\%s", path, TC_SYS_BOOT_LOADER_BACKUP_NAME);
- RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2, FALSE);
-
- // remove VeraCrypt folder
- RemoveMessage (hwndDlg, path);
- StatRemoveDirectory (path);
- }
-
-
- return bOK;
-}
-
-BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
-{
- wchar_t regk [64];
- typedef LSTATUS (WINAPI *RegDeleteKeyExWFn) (HKEY hKey,LPCWSTR lpSubKey,REGSAM samDesired,WORD Reserved);
- RegDeleteKeyExWFn RegDeleteKeyExWPtr = NULL;
- HMODULE hAdvapiDll = LoadLibrary (L"Advapi32.dll");
- if (hAdvapiDll)
- {
- RegDeleteKeyExWPtr = (RegDeleteKeyExWFn) GetProcAddress(hAdvapiDll, "RegDeleteKeyExW");
- }
-
- // Unregister COM servers
- if (!bRemoveDeprecated && IsOSAtLeast (WIN_VISTA))
- {
- if (!UnregisterComServers (InstallationPath))
- StatusMessage (hwndDlg, "COM_DEREG_FAILED");
- }
-
- if (!bRemoveDeprecated)
- StatusMessage (hwndDlg, "REMOVING_REG");
-
- if (RegDeleteKeyExWPtr)
- {
- RegDeleteKeyExWPtr (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", KEY_WOW64_32KEY, 0);
- RegDeleteKeyExWPtr (HKEY_CURRENT_USER, L"Software\\VeraCrypt", KEY_WOW64_32KEY, 0);
- }
- else
- {
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt");
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\VeraCrypt");
- }
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open\\command");
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open");
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell");
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\DefaultIcon");
- RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume");
-
- if (!bRemoveDeprecated)
- {
- HKEY hKey;
- GetStartupRegKeyName (regk, sizeof(regk));
- DeleteRegistryValue (regk, L"VeraCrypt");
-
- DeleteRegistryKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\.hc");
-
- // enable the SE_TAKE_OWNERSHIP_NAME privilege for this operation
- SetPrivilege (SE_TAKE_OWNERSHIP_NAME, TRUE);
-
- // clean MuiCache list from VeraCrypt entries
- SearchAndDeleteRegistrySubString (HKEY_CLASSES_ROOT, L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", L"VeraCrypt", FALSE, NULL);
-
- // clean other VeraCrypt entries from all users
- SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.hc", NULL, TRUE, NULL);
- SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Compatibility Assistant\\Persisted", L"VeraCrypt", TRUE, NULL);
- SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartPage\\NewShortcuts", L"VeraCrypt", TRUE, NULL);
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS | WRITE_DAC | WRITE_OWNER, &hKey) == ERROR_SUCCESS)
- {
- SearchAndDeleteRegistrySubString (hKey, L"Enum\\Root\\LEGACY_VERACRYPT", NULL, TRUE, L"ControlSet");
- SearchAndDeleteRegistrySubString (hKey, L"services\\veracrypt", NULL, TRUE, L"ControlSet");
- RegCloseKey(hKey);
- }
-
- // disable the SE_TAKE_OWNERSHIP_NAME privilege for this operation
- SetPrivilege (SE_TAKE_OWNERSHIP_NAME, FALSE);
-
- SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
- }
-
- if (hAdvapiDll)
- FreeLibrary (hAdvapiDll);
-
- return TRUE;
-}
-
-
-BOOL DoServiceUninstall (HWND hwndDlg, wchar_t *lpszService)
-{
- SC_HANDLE hManager, hService = NULL;
- BOOL bOK = FALSE, bRet;
- SERVICE_STATUS status;
- BOOL firstTry = TRUE;
- int x;
-
- memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
-
-retry:
-
- hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hManager == NULL)
- goto error;
-
- hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
- if (hService == NULL)
- goto error;
-
- if (wcscmp (L"veracrypt", lpszService) == 0)
- {
- try
- {
- BootEncryption bootEnc (hwndDlg);
- if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
- {
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::DriveFilter); } catch (...) { }
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::VolumeFilter); } catch (...) { }
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::DumpFilter); } catch (...) { }
- }
- }
- catch (...) { }
-
- StatusMessage (hwndDlg, "STOPPING_DRIVER");
- }
- else
- StatusMessageParam (hwndDlg, "STOPPING", lpszService);
-
-#define WAIT_PERIOD 3
-
- for (x = 0; x < WAIT_PERIOD; x++)
- {
- bRet = QueryServiceStatus (hService, &status);
- if (bRet != TRUE)
- goto error;
-
- if (status.dwCurrentState != SERVICE_START_PENDING &&
- status.dwCurrentState != SERVICE_STOP_PENDING &&
- status.dwCurrentState != SERVICE_CONTINUE_PENDING)
- break;
-
- Sleep (1000);
- }
-
- if (status.dwCurrentState != SERVICE_STOPPED)
- {
- bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
- if (bRet == FALSE)
- goto try_delete;
-
- for (x = 0; x < WAIT_PERIOD; x++)
- {
- bRet = QueryServiceStatus (hService, &status);
- if (bRet != TRUE)
- goto error;
-
- if (status.dwCurrentState != SERVICE_START_PENDING &&
- status.dwCurrentState != SERVICE_STOP_PENDING &&
- status.dwCurrentState != SERVICE_CONTINUE_PENDING)
- break;
-
- Sleep (1000);
- }
-
- if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
- goto error;
- }
-
-try_delete:
-
- if (wcscmp (L"veracrypt", lpszService) == 0)
- StatusMessage (hwndDlg, "REMOVING_DRIVER");
- else
- StatusMessageParam (hwndDlg, "REMOVING", lpszService);
-
- if (hService != NULL)
- {
- CloseServiceHandle (hService);
- hService = NULL;
- }
-
- if (hManager != NULL)
- {
- CloseServiceHandle (hManager);
- hManager = NULL;
- }
-
- hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hManager == NULL)
- goto error;
-
- hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
- if (hService == NULL)
- goto error;
-
- bRet = DeleteService (hService);
- if (bRet == FALSE)
- {
- if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
- {
- // Second try for an eventual no-install driver instance
- CloseServiceHandle (hService);
- CloseServiceHandle (hManager);
- hService = NULL;
- hManager = NULL;
-
- Sleep(1000);
- firstTry = FALSE;
- goto retry;
- }
-
- goto error;
- }
-
- bOK = TRUE;
-
-error:
-
- if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
- {
- handleWin32Error (hwndDlg, SRC_POS);
- MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
- }
- else
- bOK = TRUE;
-
- if (hService != NULL)
- CloseServiceHandle (hService);
-
- if (hManager != NULL)
- CloseServiceHandle (hManager);
-
- return bOK;
-}
-
-
-BOOL DoDriverUnload (HWND hwndDlg)
-{
- BOOL bOK = TRUE;
- int status;
-
- status = DriverAttach ();
- if (status != 0)
- {
- if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
- {
- handleWin32Error (hwndDlg, SRC_POS);
- AbortProcess ("NODRIVER");
- }
-
- if (status != ERR_OS_ERROR)
- {
- handleError (NULL, status, SRC_POS);
- AbortProcess ("NODRIVER");
- }
- }
-
- if (hDriver != INVALID_HANDLE_VALUE)
- {
- MOUNT_LIST_STRUCT driver;
- LONG driverVersion = VERSION_NUM;
- int refCount;
- DWORD dwResult;
- BOOL bResult;
-
- // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install).
- DetermineUpgradeDowngradeStatus (FALSE, &driverVersion);
-
- // Test for encrypted boot drive
- try
- {
- BootEncryption bootEnc (hwndDlg);
- if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
- {
- try
- {
- // Check hidden OS update consistency
- if (IsHiddenOSRunning())
- {
- if (bootEnc.GetInstalledBootLoaderVersion() != VERSION_NUM)
- {
- if (AskWarnNoYes ("UPDATE_TC_IN_DECOY_OS_FIRST", hwndDlg) == IDNO)
- AbortProcessSilent ();
- }
- }
- }
- catch (...) { }
-
- if (bUninstallInProgress && !bootEnc.GetStatus().DriveMounted)
- {
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::DriveFilter); } catch (...) { }
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::VolumeFilter); } catch (...) { }
- try { bootEnc.RegisterFilterDriver (false, BootEncryption::DumpFilter); } catch (...) { }
- bootEnc.SetDriverServiceStartType (SERVICE_SYSTEM_START);
- }
- else if (bUninstallInProgress || bDowngrade)
- {
- Error (bDowngrade ? "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED_DOWNGRADE" : "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED", hwndDlg);
- return FALSE;
- }
- else
- {
- if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1)
- AbortProcess ("SYS_ENCRYPTION_UPGRADE_UNSUPPORTED_ON_VISTA_SP0");
-
- SystemEncryptionUpdate = TRUE;
- PortableMode = FALSE;
- }
- }
- }
- catch (...) { }
-
- if (!bUninstall
- && (bUpgrade || SystemEncryptionUpdate)
- && (!bDevm || SystemEncryptionUpdate))
- {
- UnloadDriver = FALSE;
- }
-
- if (PortableMode && !SystemEncryptionUpdate)
- UnloadDriver = TRUE;
-
- if (UnloadDriver)
- {
- int volumesMounted = 0;
-
- // Check mounted volumes
- bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL);
-
- if (!bResult)
- {
- bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL);
- if (bResult)
- volumesMounted = driver.ulMountedDrives;
- }
-
- if (bResult)
- {
- if (volumesMounted != 0)
- {
- bOK = FALSE;
- MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
- }
- }
- else
- {
- bOK = FALSE;
- handleWin32Error (hwndDlg, SRC_POS);
- }
- }
-
- // Try to close all open TC windows
- if (bOK)
- {
- BOOL TCWindowClosed = FALSE;
-
- EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
-
- if (TCWindowClosed)
- Sleep (2000);
- }
-
- // Test for any applications attached to driver
- if (!bUpgrade)
- {
- bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
- sizeof (refCount), &dwResult, NULL);
-
- if (bOK && bResult && refCount > 1)
- {
- MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
- bOK = FALSE;
- }
- }
-
- if (!bOK || UnloadDriver)
- {
- CloseHandle (hDriver);
- hDriver = INVALID_HANDLE_VALUE;
- }
- }
- else
- {
- // Note that the driver may have already been unloaded during this session (e.g. retry after an error, etc.) so it is not
- // guaranteed that the user is installing VeraCrypt for the first time now (we also cannot know if the user has already
- // installed and used VeraCrypt on another system before).
- bPossiblyFirstTimeInstall = TRUE;
- }
-
- return bOK;
-}
-
-
-BOOL UpgradeBootLoader (HWND hwndDlg)
-{
- if (!SystemEncryptionUpdate)
- return TRUE;
-
- try
- {
- BootEncryption bootEnc (hwndDlg);
- uint64 bootLoaderVersion = bootEnc.GetInstalledBootLoaderVersion();
- if ((bootLoaderVersion < VERSION_NUM) || (bReinstallMode && (bootLoaderVersion == VERSION_NUM)))
- {
- StatusMessage (hwndDlg, "INSTALLER_UPDATING_BOOT_LOADER");
-
- bootEnc.InstallBootLoader (true);
-
- if (bootEnc.GetInstalledBootLoaderVersion() <= TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION)
- Info (IsHiddenOSRunning() ? "BOOT_LOADER_UPGRADE_OK_HIDDEN_OS" : "BOOT_LOADER_UPGRADE_OK", hwndDlg);
- }
- return TRUE;
- }
- catch (Exception &e)
- {
- e.Show (hwndDlg);
- }
- catch (...) { }
-
- Error ("BOOT_LOADER_UPGRADE_FAILED", hwndDlg);
- return FALSE;
-}
-
-
-BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir)
-{
- wchar_t szLinkDir[TC_MAX_PATH];
- wchar_t szTmp2[TC_MAX_PATH];
- BOOL bSlash, bOK = FALSE;
- HRESULT hOle;
- int x;
- BOOL allUsers = FALSE;
-
- hOle = OleInitialize (NULL);
-
- // User start menu
- SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
- x = wcslen (szLinkDir);
- if (szLinkDir[x - 1] == L'\\')
- bSlash = TRUE;
- else
- bSlash = FALSE;
-
- if (bSlash == FALSE)
- StringCbCatW (szLinkDir, sizeof(szLinkDir), L"\\");
-
- StringCbCatW (szLinkDir, sizeof(szLinkDir), L"VeraCrypt");
-
- // Global start menu
- {
- struct _stat st;
- wchar_t path[TC_MAX_PATH];
-
- SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
- StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
-
- if (_wstat (path, &st) == 0)
- {
- StringCbCopyW (szLinkDir, sizeof(szLinkDir), path);
- allUsers = TRUE;
- }
- }
-
- // Start menu entries
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
- RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2, FALSE) == FALSE)
- goto error;
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCryptExpander.lnk");
- RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2, FALSE) == FALSE)
- goto error;
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt Website.url");
- RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2, FALSE) == FALSE)
- goto error;
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk");
- RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2, FALSE) == FALSE)
- goto error;
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk");
- StatDeleteFile (szTmp2, FALSE);
-
- // Start menu group
- RemoveMessage ((HWND) hwndDlg, szLinkDir);
- if (StatRemoveDirectory (szLinkDir) == FALSE)
- handleWin32Error ((HWND) hwndDlg, SRC_POS);
-
- // Desktop icon
-
- if (allUsers)
- SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
- else
- SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
-
- RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2, FALSE) == FALSE)
- goto error;
-
- bOK = TRUE;
-
-error:
- OleUninitialize ();
-
- return bOK;
-}
-
-BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
-{
- wchar_t szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
- wchar_t szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
- BOOL bSlash, bOK = FALSE;
- HRESULT hOle;
- int x;
-
- if (bProgGroup == FALSE && bDesktopIcon == FALSE)
- return TRUE;
-
- hOle = OleInitialize (NULL);
-
- GetProgramPath (hwndDlg, szLinkDir);
-
- x = wcslen (szLinkDir);
- if (szLinkDir[x - 1] == L'\\')
- bSlash = TRUE;
- else
- bSlash = FALSE;
-
- if (bSlash == FALSE)
- StringCbCatW (szLinkDir, sizeof(szLinkDir), L"\\");
-
- StringCbCatW (szLinkDir, sizeof(szLinkDir), L"VeraCrypt");
-
- StringCbCopyW (szDir, sizeof(szDir), szDestDir);
- x = wcslen (szDestDir);
- if (szDestDir[x - 1] == L'\\')
- bSlash = TRUE;
- else
- bSlash = FALSE;
-
- if (bSlash == FALSE)
- StringCbCatW (szDir, sizeof(szDir), L"\\");
-
- if (bProgGroup)
- {
- FILE *f;
-
- if (mkfulldir (szLinkDir, TRUE) != 0)
- {
- if (mkfulldir (szLinkDir, FALSE) != 0)
- {
- wchar_t szTmpW[TC_MAX_PATH];
-
- handleWin32Error (hwndDlg, SRC_POS);
- StringCbPrintfW (szTmpW, sizeof(szTmpW), GetString ("CANT_CREATE_FOLDER"), szLinkDir);
- MessageBoxW (hwndDlg, szTmpW, lpszTitle, MB_ICONHAND);
- goto error;
- }
- }
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt.exe");
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
-
- IconMessage (hwndDlg, szTmp2);
- if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCryptExpander.exe");
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCryptExpander.lnk");
-
- IconMessage (hwndDlg, szTmp2);
- if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
- goto error;
-
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt Website.url");
- IconMessage (hwndDlg, szTmp2);
- f = _wfopen (szTmp2, L"w");
- if (f)
- {
- fprintf (f, "[InternetShortcut]\nURL=%s\n", TC_APPLINK);
-
- CheckFileStreamWriteErrors (hwndDlg, f, szTmp2);
- fclose (f);
- }
- else
- goto error;
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt Setup.exe");
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk");
- if (GetSystemDirectory (szTmp3, ARRAYSIZE(szTmp3)))
- {
- StringCbCatW (szTmp3, sizeof(szTmp3), L"\\control.exe");
- }
- else
- StringCbCopyW(szTmp3, sizeof(szTmp3), L"C:\\Windows\\System32\\control.exe");
-
- IconMessage (hwndDlg, szTmp2);
- 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");
- StatDeleteFile (szTmp2, FALSE);
- }
-
- if (bDesktopIcon)
- {
- StringCbCopyW (szDir, sizeof(szDir), szDestDir);
- x = wcslen (szDestDir);
- if (szDestDir[x - 1] == L'\\')
- bSlash = TRUE;
- else
- bSlash = FALSE;
-
- if (bSlash == FALSE)
- StringCbCatW (szDir, sizeof(szDir), L"\\");
-
- if (bForAllUsers)
- SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
- else
- SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
-
- StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt.exe");
- StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
-
- IconMessage (hwndDlg, szTmp2);
-
- if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
- goto error;
- }
-
- bOK = TRUE;
-
-error:
- OleUninitialize ();
-
- return bOK;
-}
-
-
-void OutcomePrompt (HWND hwndDlg, BOOL bOK)
-{
- if (bOK)
- {
- EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
-
- bDone = TRUE;
-
- if (bUninstall == FALSE)
- {
- if (bDevm)
- PostMessage (MainDlg, WM_CLOSE, 0, 0);
- else if (bPossiblyFirstTimeInstall || bRepairMode || (!bUpgrade && !bDowngrade))
- Info ("INSTALL_OK", hwndDlg);
- else
- Info ("SETUP_UPDATE_OK", hwndDlg);
- }
- else
- {
- wchar_t str[4096];
-
- StringCbPrintfW (str, sizeof(str), GetString ("UNINSTALL_OK"), InstallationPath);
- MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
- }
- }
- else
- {
- if (bUninstall == FALSE)
- Error ("INSTALL_FAILED", hwndDlg);
- else
- Error ("UNINSTALL_FAILED", hwndDlg);
- }
-}
-
-static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
-{
- static RESTOREPOINTINFO RestPtInfo;
- static STATEMGRSTATUS SMgrStatus;
- static BOOL failed = FALSE;
- static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
-
- if (!SystemRestoreDll) return;
-
- _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointW");
- if (_SRSetRestorePoint == 0)
- {
- FreeLibrary (SystemRestoreDll);
- SystemRestoreDll = 0;
- return;
- }
-
- if (!finalize)
- {
- StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
-
- RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
- RestPtInfo.dwRestorePtType = bUninstall ? APPLICATION_UNINSTALL : APPLICATION_INSTALL | DEVICE_DRIVER_INSTALL;
- RestPtInfo.llSequenceNumber = 0;
- StringCbCopyW (RestPtInfo.szDescription, sizeof(RestPtInfo.szDescription), bUninstall ? L"VeraCrypt uninstallation" : L"VeraCrypt installation");
-
- if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus))
- {
- StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
- failed = TRUE;
- }
- }
- else if (!failed)
- {
- RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
- RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
-
- if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
- {
- StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
- }
- }
-}
-
-void DoUninstall (void *arg)
-{
- HWND hwndDlg = (HWND) arg;
- BOOL bOK = TRUE;
- BOOL bTempSkipSysRestore = FALSE;
-
- if (!Rollback)
- EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
-
- WaitCursor ();
-
- if (!Rollback)
- {
- ClearLogWindow (hwndDlg);
- }
-
- if (DoDriverUnload (hwndDlg) == FALSE)
- {
- bOK = FALSE;
- bTempSkipSysRestore = TRUE; // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
- }
- else
- {
- if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
- SetSystemRestorePoint (hwndDlg, FALSE);
-
- if (DoServiceUninstall (hwndDlg, L"veracrypt") == FALSE)
- {
- bOK = FALSE;
- }
- else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
- {
- bOK = FALSE;
- }
- else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
- {
- bOK = FALSE;
- }
- else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
- {
- bOK = FALSE;
- }
- else if (!DoApplicationDataUninstall (hwndDlg))
- {
- bOK = FALSE;
- }
- else
- {
- wchar_t temp[MAX_PATH];
- FILE *f;
-
- // Deprecated service
- DoServiceUninstall (hwndDlg, L"VeraCryptService");
-
- GetTempPath (ARRAYSIZE (temp), temp);
- StringCbPrintfW (UninstallBatch, sizeof (UninstallBatch), L"%sVeraCrypt-Uninstall.bat", temp);
-
- UninstallBatch [ARRAYSIZE(UninstallBatch)-1] = 0;
-
- // Create uninstall batch
- f = _wfopen (UninstallBatch, L"w");
- if (!f)
- bOK = FALSE;
- else
- {
- fwprintf (f,L":loop\n"
- L"del \"%s%s\"\n"
- L"if exist \"%s%s\" goto loop\n"
- L"rmdir \"%s\"\n"
- L"del \"%s\"",
- InstallationPath, L"VeraCrypt Setup.exe",
- InstallationPath, L"VeraCrypt Setup.exe",
- InstallationPath,
- UninstallBatch
- );
-
- CheckFileStreamWriteErrors (hwndDlg, f, UninstallBatch);
- fclose (f);
- }
- }
- }
-
- NormalCursor ();
-
- if (Rollback)
- return;
-
- if (bSystemRestore && !bTempSkipSysRestore)
- SetSystemRestorePoint (hwndDlg, TRUE);
-
- if (bOK)
- PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
- else
- bUninstallInProgress = FALSE;
-
- EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
- OutcomePrompt (hwndDlg, bOK);
-}
-
-void DoInstall (void *arg)
-{
- HWND hwndDlg = (HWND) arg;
- BOOL bOK = TRUE;
- wchar_t path[MAX_PATH];
-
- BootEncryption bootEnc (hwndDlg);
-
- // Refresh the main GUI (wizard thread)
- InvalidateRect (MainDlg, NULL, TRUE);
-
- ClearLogWindow (hwndDlg);
-
- if (mkfulldir (InstallationPath, TRUE) != 0)
- {
- if (mkfulldir (InstallationPath, FALSE) != 0)
- {
- wchar_t szTmp[TC_MAX_PATH];
-
- handleWin32Error (hwndDlg, SRC_POS);
- StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), InstallationPath);
- MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
- Error ("INSTALL_FAILED", hwndDlg);
- PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
- return;
- }
- }
-
- UpdateProgressBarProc(2);
-
- if (DoDriverUnload (hwndDlg) == FALSE)
- {
- NormalCursor ();
- PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
- return;
- }
-
- if (bUpgrade
- && (IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L".exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x86.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x64.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x86.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x64.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x86.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x64.exe")
- || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Setup.exe")
- )
- )
- {
- NormalCursor ();
- Error ("CLOSE_TC_FIRST", hwndDlg);
- PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
- return;
- }
-
- UpdateProgressBarProc(12);
-
- if (bSystemRestore)
- SetSystemRestorePoint (hwndDlg, FALSE);
-
- UpdateProgressBarProc(48);
-
- if (bDisableSwapFiles
- && IsPagingFileActive (FALSE))
- {
- if (!DisablePagingFile())
- {
- handleWin32Error (hwndDlg, SRC_POS);
- Error ("FAILED_TO_DISABLE_PAGING_FILES", hwndDlg);
- }
- else
- bRestartRequired = TRUE;
- }
-
- UpdateProgressBarProc(50);
-
- // Remove deprecated
- DoServiceUninstall (hwndDlg, L"VeraCryptService");
-
- UpdateProgressBarProc(55);
-
- if (!SystemEncryptionUpdate)
- DoRegUninstall ((HWND) hwndDlg, TRUE);
-
- UpdateProgressBarProc(61);
-
- GetWindowsDirectory (path, ARRAYSIZE (path));
- StringCbCatW (path, sizeof (path), L"\\VeraCrypt Setup.exe");
- StatDeleteFile (path, FALSE);
-
- if (UpdateProgressBarProc(63) && UnloadDriver && DoServiceUninstall (hwndDlg, L"veracrypt") == FALSE)
- {
- bOK = FALSE;
- }
- else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
- {
- bOK = FALSE;
- }
- else if (UpdateProgressBarProc(80) && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt) == FALSE)
- {
- bOK = FALSE;
- }
- else if (UpdateProgressBarProc(85) && UnloadDriver && DoDriverInstall (hwndDlg) == FALSE)
- {
- bOK = FALSE;
- }
- else if (UpdateProgressBarProc(90) && SystemEncryptionUpdate && UpgradeBootLoader (hwndDlg) == FALSE)
- {
- bOK = FALSE;
- }
- else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
- {
- bOK = FALSE;
- }
-
- if (!UnloadDriver)
- bRestartRequired = TRUE;
-
- try
- {
- bootEnc.RenameDeprecatedSystemLoaderBackup();
- }
- catch (...) { }
-
- if (bOK)
- UpdateProgressBarProc(97);
-
- if (bSystemRestore)
- SetSystemRestorePoint (hwndDlg, TRUE);
-
- if (bOK)
- {
- UpdateProgressBarProc(100);
- UninstallBatch[0] = 0;
- StatusMessage (hwndDlg, "INSTALL_COMPLETED");
- }
- else
- {
- UpdateProgressBarProc(0);
-
- if (!SystemEncryptionUpdate)
- {
- bUninstall = TRUE;
- Rollback = TRUE;
- Silent = TRUE;
-
- DoUninstall (hwndDlg);
-
- bUninstall = FALSE;
- Rollback = FALSE;
- Silent = FALSE;
-
- StatusMessage (hwndDlg, "ROLLBACK");
- }
- else
- {
- Warning ("SYS_ENC_UPGRADE_FAILED", hwndDlg);
- }
- }
-
- OutcomePrompt (hwndDlg, bOK);
-
- if (bOK && !bUninstall && !bDowngrade && !bRepairMode && !bDevm)
- {
- if (!IsHiddenOSRunning()) // A hidden OS user should not see the post-install notes twice (on decoy OS and then on hidden OS).
- {
- if (bRestartRequired || SystemEncryptionUpdate)
- {
- // Restart required
-
- if (bUpgrade)
- {
- SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_RELEASE_NOTES);
- }
- else if (bPossiblyFirstTimeInstall)
- {
- SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_TUTORIAL);
- }
- }
- else
- {
- // No restart will be required
-
- if (bUpgrade)
- {
- bPromptReleaseNotes = TRUE;
- }
- else if (bPossiblyFirstTimeInstall)
- {
- bPromptTutorial = TRUE;
- }
- }
- }
- }
-
- PostMessage (MainDlg, bOK ? TC_APPMSG_INSTALL_SUCCESS : TC_APPMSG_INSTALL_FAILURE, 0, 0);
-}
-
-
-void SetInstallationPath (HWND hwndDlg)
-{
- HKEY hkey;
- BOOL bInstallPathDetermined = FALSE;
- wchar_t path[MAX_PATH+20];
- ITEMIDLIST *itemList;
-
- memset (InstallationPath, 0, sizeof (InstallationPath));
-
- // Determine if VeraCrypt is already installed and try to determine its "Program Files" location
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
- {
- /* Default 'UninstallString' registry strings written by VeraCrypt:
- ------------------------------------------------------------------------------------
- 5.0+ "C:\Program Files\VeraCrypt\VeraCrypt Setup.exe" /u
- */
-
- wchar_t rv[MAX_PATH*4];
- DWORD size = sizeof (rv);
- if (RegQueryValueEx (hkey, L"UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && wcsrchr (rv, L'/'))
- {
- size_t len = 0;
-
- // Cut and paste the location (path) where VeraCrypt is installed to InstallationPath
- if (rv[0] == L'"')
- {
- len = wcsrchr (rv, L'/') - rv - 2;
- StringCchCopyNW (InstallationPath, ARRAYSIZE(InstallationPath), rv + 1, len);
- InstallationPath [len] = 0;
- bInstallPathDetermined = TRUE;
-
- if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\')
- {
- len = wcsrchr (InstallationPath, L'\\') - InstallationPath;
- InstallationPath [len] = 0;
- }
- }
-
- }
- RegCloseKey (hkey);
- }
-
- if (bInstallPathDetermined)
- {
- wchar_t mp[MAX_PATH];
-
- // Determine whether we were launched from the folder where VeraCrypt is installed
- GetModuleFileName (NULL, mp, ARRAYSIZE (mp));
- if (wcsncmp (InstallationPath, mp, min (wcslen(InstallationPath), wcslen(mp))) == 0)
- {
- // We were launched from the folder where VeraCrypt is installed
-
- if (!IsNonInstallMode() && !bDevm)
- bChangeMode = TRUE;
- }
- }
- else
- {
- /* VeraCrypt is not installed or it wasn't possible to determine where it is installed. */
-
- // Default "Program Files" path.
- SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
- SHGetPathFromIDList (itemList, path);
-
- if (Is64BitOs())
- {
- // Use a unified default installation path (registry redirection of %ProgramFiles% does not work if the installation path is user-selectable)
- wstring s = path;
- size_t p = s.find (L" (x86)");
- if (p != wstring::npos)
- {
- s = s.substr (0, p);
- if (_waccess (s.c_str(), 0) != -1)
- StringCbCopyW (path, sizeof (path), s.c_str());
- }
- }
-
- StringCbCatW (path, sizeof(path), L"\\VeraCrypt\\");
- StringCbCopyW (InstallationPath, sizeof(InstallationPath), path);
- }
-
- // Make sure the path ends with a backslash
- if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\')
- {
- StringCbCatW (InstallationPath, sizeof(InstallationPath), L"\\");
- }
-}
-
-
-// Handler for uninstall only (install is handled by the wizard)
-BOOL CALLBACK UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- WORD lw = LOWORD (wParam);
-
- switch (msg)
- {
- case WM_INITDIALOG:
-
- MainDlg = hwndDlg;
-
- if (!CreateAppSetupMutex ())
- AbortProcess ("TC_INSTALLER_IS_RUNNING");
-
- InitDialog (hwndDlg);
- LocalizeDialog (hwndDlg, NULL);
-
- SetWindowTextW (hwndDlg, lpszTitle);
-
- // System Restore
- SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
- if (SystemRestoreDll == 0)
- {
- SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
- }
-
- SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
-
- return 1;
-
- case WM_SYSCOMMAND:
- if (lw == IDC_ABOUT)
- {
- DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
- return 1;
- }
- return 0;
-
- case WM_COMMAND:
- if (lw == IDC_UNINSTALL)
- {
- if (bDone)
- {
- bUninstallInProgress = FALSE;
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
- return 1;
- }
-
- bUninstallInProgress = TRUE;
-
- WaitCursor ();
-
- if (bUninstall)
- _beginthread (DoUninstall, 0, (void *) hwndDlg);
-
- return 1;
- }
-
- if (lw == IDC_SYSTEM_RESTORE)
- {
- bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
- return 1;
- }
-
- if (lw == IDCANCEL)
- {
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
- return 1;
- }
-
- return 0;
-
- case TC_APPMSG_UNINSTALL_SUCCESS:
- SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
- NormalCursor ();
- return 1;
-
- case WM_CLOSE:
- if (bUninstallInProgress)
- {
- NormalCursor();
- if (AskNoYes("CONFIRM_EXIT_UNIVERSAL", hwndDlg) == IDNO)
- {
- return 1;
- }
- WaitCursor ();
- }
- EndDialog (hwndDlg, IDCANCEL);
- return 1;
- }
-
- return 0;
-}
-
-
-int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow)
-{
- atexit (localcleanup);
-
- SelfExtractStartupInit();
-
- lpszTitle = L"VeraCrypt Setup";
-
- /* Call InitApp to initialize the common code */
- InitApp (hInstance, NULL);
-
- if (IsAdmin () != TRUE)
- if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
- {
- FinalizeApp ();
- exit (1);
- }
-
- /* Setup directory */
- {
- wchar_t *s;
- GetModuleFileName (NULL, SetupFilesDir, ARRAYSIZE (SetupFilesDir));
- s = wcsrchr (SetupFilesDir, L'\\');
- if (s)
- s[1] = 0;
- }
-
- /* Parse command line arguments */
-
- if (lpszCommandLine[0] == L'/')
- {
- if (lpszCommandLine[1] == L'u')
- {
- // Uninstall: /u
-
- bUninstall = TRUE;
- }
- else if (lpszCommandLine[1] == L'c')
- {
- // Change: /c
-
- bChangeMode = TRUE;
- }
- else if (lpszCommandLine[1] == L'p')
- {
- // Create self-extracting package: /p
-
- bMakePackage = TRUE;
- }
- else if (lpszCommandLine[1] == L'd')
- {
- // Dev mode: /d
- bDevm = TRUE;
- }
- }
-
- if (bMakePackage)
- {
- /* Create self-extracting package */
-
- MakeSelfExtractingPackage (NULL, SetupFilesDir);
- }
- else
- {
- SetInstallationPath (NULL);
-
- if (!bUninstall)
- {
- if (IsSelfExtractingPackage())
- {
- if (!VerifyPackageIntegrity())
- {
- // Package corrupted
- exit (1);
- }
- bDevm = FALSE;
- }
- else if (!bDevm)
- {
- MessageBox (NULL, L"Error: This installer file does not contain any compressed files.\n\nTo create a self-extracting installation package (with embedded compressed files), run:\n\"VeraCrypt Setup.exe\" /p", L"VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
- FinalizeApp ();
- exit (1);
- }
-
- if (bChangeMode)
- {
- /* VeraCrypt is already installed on this system and we were launched from the Program Files folder */
-
- char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
-
- // Ask the user to select either Repair or Unistallation
- switch (AskMultiChoice ((void **) tmpStr, FALSE, NULL))
- {
- case 1:
- bRepairMode = TRUE;
- break;
- case 2:
- bUninstall = TRUE;
- break;
- default:
- FinalizeApp ();
- exit (1);
- }
- }
- }
-
- // System Restore
- if (IsSystemRestoreEnabled ())
- {
- wchar_t dllPath[MAX_PATH];
- if (GetSystemDirectory (dllPath, MAX_PATH))
- {
- StringCbCatW(dllPath, sizeof(dllPath), L"\\srclient.dll");
- }
- else
- StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\srclient.dll");
- SystemRestoreDll = LoadLibrary (dllPath);
- }
- else
- SystemRestoreDll = 0;
-
- if (!bUninstall)
- {
- /* Create the main dialog for install */
-
- DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc,
- (LPARAM)lpszCommandLine);
- }
- else
- {
- /* Create the main dialog for uninstall */
-
- DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
-
- if (UninstallBatch[0])
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- ZeroMemory (&si, sizeof (si));
- si.cb = sizeof (si);
- si.dwFlags = STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
-
- if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
- DeleteFile (UninstallBatch);
- else
- {
- CloseHandle (pi.hProcess);
- CloseHandle (pi.hThread);
- }
- }
- }
- }
- FinalizeApp ();
- return 0;
-}
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#include "Tcdefs.h"
+#include <SrRestorePtApi.h>
+#include <io.h>
+#include <propkey.h>
+#include <propvarutil.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <tchar.h>
+
+#include "Apidrvr.h"
+#include "BootEncryption.h"
+#include "Boot/Windows/BootCommon.h"
+#include "Combo.h"
+#include "ComSetup.h"
+#include "Dlgcode.h"
+#include "Language.h"
+#include "Registry.h"
+#include "Resource.h"
+
+#include "Dir.h"
+#include "Setup.h"
+#include "SelfExtract.h"
+#include "Wizard.h"
+
+#include "../Common/Resource.h"
+
+using namespace VeraCrypt;
+
+#pragma warning( disable : 4201 )
+#pragma warning( disable : 4115 )
+
+#include <shlobj.h>
+
+#pragma warning( default : 4201 )
+#pragma warning( default : 4115 )
+
+#include <Strsafe.h>
+
+wchar_t InstallationPath[TC_MAX_PATH];
+wchar_t SetupFilesDir[TC_MAX_PATH];
+wchar_t UninstallBatch[MAX_PATH];
+
+BOOL bUninstall = FALSE;
+BOOL bRestartRequired = FALSE;
+BOOL bMakePackage = FALSE;
+BOOL bDone = FALSE;
+BOOL Rollback = FALSE;
+BOOL bUpgrade = FALSE;
+BOOL bDowngrade = FALSE;
+BOOL SystemEncryptionUpdate = FALSE;
+BOOL PortableMode = FALSE;
+BOOL bRepairMode = FALSE;
+BOOL bReinstallMode = FALSE;
+BOOL bChangeMode = FALSE;
+BOOL bDevm = FALSE;
+BOOL bPossiblyFirstTimeInstall = FALSE;
+BOOL bUninstallInProgress = FALSE;
+BOOL UnloadDriver = TRUE;
+
+BOOL bSystemRestore = TRUE;
+BOOL bDisableSwapFiles = FALSE;
+BOOL bForAllUsers = TRUE;
+BOOL bRegisterFileExt = TRUE;
+BOOL bAddToStartMenu = TRUE;
+BOOL bDesktopIcon = TRUE;
+
+BOOL bDesktopIconStatusDetermined = FALSE;
+
+HMODULE volatile SystemRestoreDll = 0;
+
+void localcleanup (void)
+{
+ localcleanupwiz ();
+ cleanup ();
+
+ 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;
+
+ if (bCheckForOldFile)
+ {
+ wchar_t szOldPath[MAX_PATH + 1];
+ StringCbCopyW (szOldPath, sizeof(szOldPath), lpszFile);
+ StringCbCatW (szOldPath, sizeof(szOldPath), VC_FILENAME_RENAMED_SUFFIX);
+
+ if (_wstat64 (szOldPath, &st) == 0)
+ {
+ ForceDeleteFile (szOldPath);
+ }
+ }
+
+ if (_wstat64 (lpszFile, &st) == 0)
+ return ForceDeleteFile (lpszFile);
+ else
+ return TRUE;
+}
+
+BOOL StatRemoveDirectory (wchar_t *lpszDir)
+{
+ struct __stat64 st;
+
+ if (_wstat64 (lpszDir, &st) == 0)
+ {
+ BOOL bStatus = RemoveDirectory (lpszDir);
+ if (!bStatus)
+ {
+ /* force removal of the non empty directory */
+ wchar_t szOpPath[TC_MAX_PATH + 1] = {0};
+ SHFILEOPSTRUCTW op;
+
+ StringCchCopyW(szOpPath, ARRAYSIZE(szOpPath)-1, lpszDir);
+ ZeroMemory(&op, sizeof(op));
+ op.wFunc = FO_DELETE;
+ op.pFrom = szOpPath;
+ op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR;
+
+ if ((0 == SHFileOperation(&op)) && (!op.fAnyOperationsAborted))
+ bStatus = TRUE;
+ }
+ return bStatus;
+ }
+ else
+ return TRUE;
+}
+
+
+/* Recursively set the given OWNER security descriptor to the key and its subkeys */
+static void RecursiveSetOwner (HKEY hKey, PSECURITY_DESCRIPTOR pSD)
+{
+ LSTATUS status = 0;
+ DWORD dwIndex = 0, dwMaxNameLen = 0, dwNameLen = 0, numberSubKeys = 0;
+ HKEY hSubKey;
+
+ if ( (ERROR_SUCCESS == status) && (ERROR_SUCCESS == RegQueryInfoKey(hKey, NULL, NULL, NULL, &numberSubKeys, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
+ && (numberSubKeys >= 1)
+ )
+ {
+ dwMaxNameLen++;
+ wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
+ while (true)
+ {
+ dwNameLen = dwMaxNameLen;
+ status = RegEnumKeyExW (hKey, dwIndex++, szNameValue, &dwNameLen, NULL, NULL, NULL, NULL);
+ if (status == ERROR_SUCCESS)
+ {
+ status = RegOpenKeyExW (hKey, szNameValue, 0, WRITE_OWNER | KEY_READ , &hSubKey);
+ if (ERROR_SUCCESS == status)
+ {
+ RecursiveSetOwner (hSubKey, pSD);
+ RegCloseKey(hSubKey);
+ }
+ }
+ else
+ break;
+ }
+ delete [] szNameValue;
+ }
+
+ RegSetKeySecurity (hKey, OWNER_SECURITY_INFORMATION, pSD);
+}
+
+/* Recursively set the given DACL security descriptor to the key and its subkeys */
+static void RecursiveSetDACL (HKEY hKey, const wchar_t* SubKeyName, PSECURITY_DESCRIPTOR pSD)
+{
+ HKEY hSubKey;
+ DWORD dwIndex = 0, dwMaxNameLen = 0, dwNameLen = 0, numberSubKeys = 0;
+ LSTATUS status = RegOpenKeyExW(hKey, SubKeyName, 0, WRITE_DAC | KEY_READ /*| ACCESS_SYSTEM_SECURITY*/, &hSubKey);
+ if (status == ERROR_SUCCESS)
+ {
+ status = RegSetKeySecurity (hSubKey, DACL_SECURITY_INFORMATION, pSD);
+ if (status == ERROR_SUCCESS)
+ {
+ RegCloseKey(hSubKey);
+ status = RegOpenKeyExW(hKey, SubKeyName, 0, WRITE_DAC | KEY_READ , &hSubKey);
+ }
+
+ if ( (ERROR_SUCCESS == status)
+ && (ERROR_SUCCESS == RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &numberSubKeys, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
+ && (numberSubKeys >= 1)
+ )
+ {
+ dwMaxNameLen++;
+ wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
+ while (true)
+ {
+ dwNameLen = dwMaxNameLen;
+ status = RegEnumKeyExW (hSubKey, dwIndex++, szNameValue, &dwNameLen, NULL, NULL, NULL, NULL);
+ if (status == ERROR_SUCCESS)
+ {
+ RecursiveSetDACL (hSubKey, szNameValue, pSD);
+ }
+ else
+ break;
+ }
+ delete [] szNameValue;
+ }
+ }
+}
+
+/* Correct the key permissions to allow its deletion */
+static void AllowKeyAccess(HKEY Key,const wchar_t* SubKeyName)
+{
+ LSTATUS RegResult;
+ HKEY SvcKey = NULL;
+ DWORD dwLength = 0;
+ HANDLE Token = NULL;
+ PTOKEN_USER pTokenUser = NULL;
+ std::string sNewSD;
+
+ RegResult = RegOpenKeyExW(Key, SubKeyName, 0, WRITE_OWNER | KEY_READ, &SvcKey);
+ if (RegResult==ERROR_SUCCESS)
+ {
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token))
+ {
+ if (!GetTokenInformation(Token, TokenUser, pTokenUser, 0, &dwLength))
+ {
+ if (GetLastError() ==ERROR_INSUFFICIENT_BUFFER)
+ {
+ pTokenUser = (PTOKEN_USER) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
+ if (pTokenUser)
+ {
+ if (GetTokenInformation(Token, TokenUser, pTokenUser, dwLength, &dwLength))
+ {
+ SECURITY_DESCRIPTOR SecDesc;
+ if ( InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION)
+ && SetSecurityDescriptorDacl(&SecDesc, TRUE, NULL, FALSE) // NULL DACL: full access to everyone
+ && SetSecurityDescriptorOwner(&SecDesc, pTokenUser->User.Sid, FALSE)
+ )
+ {
+ RecursiveSetOwner(SvcKey, &SecDesc);
+ }
+ }
+
+ }
+ }
+ }
+ }
+ RegCloseKey(SvcKey);
+ }
+
+ if (pTokenUser)
+ {
+ PSID pSid = pTokenUser->User.Sid;
+ DWORD dwAclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + ::GetLengthSid(pSid) - sizeof(DWORD);
+ PACL pDacl = (PACL) new BYTE[dwAclSize];
+ if (pDacl)
+ {
+ if (TRUE == ::InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
+ {
+ if (TRUE == AddAccessAllowedAceEx(pDacl, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, WRITE_DAC | KEY_ALL_ACCESS, pSid))
+ {
+ SECURITY_DESCRIPTOR SecDesc;
+ if (TRUE == ::InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
+ {
+ if (TRUE == ::SetSecurityDescriptorDacl(&SecDesc, TRUE, pDacl, FALSE))
+ {
+ RecursiveSetDACL (Key, SubKeyName, &SecDesc);
+ }
+ }
+ }
+ }
+ delete [] pDacl;
+ }
+ }
+
+ if (pTokenUser)
+ HeapFree(GetProcessHeap(), 0, pTokenUser);
+ if (Token)
+ CloseHandle(Token);
+}
+
+void SearchAndDeleteRegistrySubString (HKEY hKey, const wchar_t *subKey, const wchar_t *str, BOOL bEnumSubKeys, const wchar_t* enumMatchSubStr)
+{
+ HKEY hSubKey = 0;
+ LSTATUS status = 0;
+ DWORD dwIndex = 0, dwType, dwValueNameLen, dwDataLen;
+ std::list<std::wstring> subKeysList;
+ size_t subStringLength = str? wcslen(str) : 0;
+
+ if (bEnumSubKeys)
+ {
+ DWORD dwMaxNameLen = 0;
+ if (ERROR_SUCCESS == RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, &dwMaxNameLen, NULL, NULL, NULL, NULL, NULL, NULL))
+ {
+ dwMaxNameLen++;
+ wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
+ dwIndex = 0;
+ while (true)
+ {
+ dwValueNameLen = dwMaxNameLen;
+ status = RegEnumKeyExW (hKey, dwIndex++, szNameValue, &dwValueNameLen, NULL, NULL, NULL, NULL);
+ if (status == ERROR_SUCCESS)
+ {
+ if (enumMatchSubStr && !wcsstr(szNameValue, enumMatchSubStr))
+ continue;
+ std::wstring entryName = szNameValue;
+ entryName += L"\\";
+ entryName += subKey;
+ entryName += L"\\";
+ subKeysList.push_back(entryName);
+ }
+ else
+ break;
+ }
+ delete [] szNameValue;
+ }
+ }
+ else
+ {
+ subKeysList.push_back(subKey);
+ }
+
+ for (std::list<std::wstring>::iterator ItSubKey = subKeysList.begin(); ItSubKey != subKeysList.end(); ItSubKey++)
+ {
+ // if the string to search for is empty, delete the sub key, otherwise, look for matching value and delete them
+ if (subStringLength == 0)
+ {
+ if (ERROR_ACCESS_DENIED == DeleteRegistryKey (hKey, ItSubKey->c_str()))
+ {
+ // grant permission to delete
+ AllowKeyAccess (hKey, ItSubKey->c_str());
+
+ // try again
+ DeleteRegistryKey (hKey, ItSubKey->c_str());
+ }
+ }
+ else
+ {
+ if (RegOpenKeyExW (hKey, ItSubKey->c_str(), 0, KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
+ {
+ DWORD dwMaxNameLen = 0, dwMaxDataLen = 0;
+ if (ERROR_SUCCESS == RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dwMaxNameLen, &dwMaxDataLen, NULL, NULL))
+ {
+ dwMaxNameLen++;
+ wchar_t* szNameValue = new wchar_t[dwMaxNameLen];
+ LPBYTE pbData = new BYTE[dwMaxDataLen];
+
+ std::list<std::wstring> foundEntries;
+ dwIndex = 0;
+ do
+ {
+ dwValueNameLen = dwMaxNameLen;
+ dwDataLen = dwMaxDataLen;
+ status = RegEnumValueW(hSubKey, dwIndex++, szNameValue, &dwValueNameLen, NULL, &dwType, pbData, &dwDataLen);
+ if (status == ERROR_SUCCESS)
+ {
+ if ( (wcslen(szNameValue) >= subStringLength && wcsstr(szNameValue, str))
+ || (dwType == REG_SZ && wcslen((wchar_t*) pbData) >= subStringLength && wcsstr((wchar_t*) pbData, str))
+ )
+ {
+ foundEntries.push_back(szNameValue);
+ }
+ }
+ } while ((status == ERROR_SUCCESS) || (status == ERROR_MORE_DATA)); // we ignore ERROR_MORE_DATA errors since
+ // we are sure to use the correct sizes
+
+ // delete the entries
+ if (!foundEntries.empty())
+ {
+ for (std::list<std::wstring>::iterator It = foundEntries.begin();
+ It != foundEntries.end(); It++)
+ {
+ RegDeleteValueW (hSubKey, It->c_str());
+ }
+ }
+
+ delete [] szNameValue;
+ delete [] pbData;
+ }
+
+
+ RegCloseKey (hSubKey);
+ }
+ }
+ }
+}
+
+/* Set the given privilege of the current process */
+BOOL SetPrivilege(LPTSTR szPrivilegeName, BOOL bEnable)
+{
+ TOKEN_PRIVILEGES tp;
+ LUID luid;
+ HANDLE hProcessToken;
+ BOOL bStatus = FALSE;
+
+ if ( OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
+ &hProcessToken) )
+ {
+ if ( LookupPrivilegeValue(
+ NULL,
+ szPrivilegeName,
+ &luid ) )
+ {
+
+ tp.PrivilegeCount = 1;
+ tp.Privileges[0].Luid = luid;
+ tp.Privileges[0].Attributes = bEnable? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED;
+
+ // Enable the privilege
+ bStatus = AdjustTokenPrivileges(
+ hProcessToken,
+ FALSE,
+ &tp,
+ sizeof(TOKEN_PRIVILEGES),
+ (PTOKEN_PRIVILEGES) NULL,
+ (PDWORD) NULL);
+ }
+
+ CloseHandle(hProcessToken);
+ }
+
+ return bStatus;
+}
+
+/*
+ * Creates a VT_LPWSTR propvariant.
+ * we use our own implementation to use SHStrDupW function pointer
+ * that we retreive ourselves to avoid dll hijacking attacks
+ */
+inline HRESULT VCInitPropVariantFromString(__in PCWSTR psz, __out PROPVARIANT *ppropvar)
+{
+ ppropvar->vt = VT_LPWSTR;
+ HRESULT hr = VCStrDupW(psz, &ppropvar->pwszVal);
+ if (FAILED(hr))
+ {
+ PropVariantInit(ppropvar);
+ }
+ return hr;
+}
+
+HRESULT CreateLink (wchar_t *lpszPathObj, wchar_t *lpszArguments,
+ wchar_t *lpszPathLink, const wchar_t* iconFile, int iconIndex)
+{
+ HRESULT hres;
+ IShellLink *psl;
+
+ /* Get a pointer to the IShellLink interface. */
+ hres = CoCreateInstance (CLSID_ShellLink, NULL,
+ CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
+ if (SUCCEEDED (hres))
+ {
+ IPersistFile *ppf;
+
+ /* Set the path to the shortcut target, and add the
+ description. */
+ psl->SetPath (lpszPathObj);
+ psl->SetArguments (lpszArguments);
+ if (iconFile)
+ {
+ psl->SetIconLocation (iconFile, iconIndex);
+ }
+
+ // Application ID
+ if (_tcsstr (lpszPathObj, _T(TC_APP_NAME) _T(".exe")))
+ {
+ IPropertyStore *propStore;
+
+ if (SUCCEEDED (psl->QueryInterface (IID_PPV_ARGS (&propStore))))
+ {
+ PROPVARIANT propVariant;
+ if (SUCCEEDED (VCInitPropVariantFromString (TC_APPLICATION_ID, &propVariant)))
+ {
+ if (SUCCEEDED (propStore->SetValue (PKEY_AppUserModel_ID, propVariant)))
+ propStore->Commit();
+
+ PropVariantClear (&propVariant);
+ }
+
+ propStore->Release();
+ }
+ }
+
+ /* Query IShellLink for the IPersistFile interface for saving
+ the shortcut in persistent storage. */
+ hres = psl->QueryInterface (IID_IPersistFile,
+ (void **) &ppf);
+
+ if (SUCCEEDED (hres))
+ {
+ /* Save the link by calling IPersistFile::Save. */
+ hres = ppf->Save (lpszPathLink, TRUE);
+ ppf->Release ();
+ }
+ psl->Release ();
+ }
+ return hres;
+}
+
+BOOL IsSystemRestoreEnabled ()
+{
+ BOOL bEnabled = FALSE;
+ HKEY hKey;
+ DWORD dwValue = 0, cbValue = sizeof (DWORD);
+ wchar_t szRegPath[MAX_PATH];
+ GetRestorePointRegKeyName (szRegPath, sizeof (szRegPath));
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, szRegPath, 0, KEY_READ | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)
+ {
+ if (IsOSAtLeast (WIN_VISTA))
+ {
+ if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"RPSessionInterval", NULL, NULL, (LPBYTE) &dwValue, &cbValue))
+ && (dwValue == 1)
+ )
+ {
+ bEnabled = TRUE;
+ }
+ }
+ else
+ {
+ if ( (ERROR_SUCCESS == RegQueryValueEx (hKey, L"DisableSR", NULL, NULL, (LPBYTE) &dwValue, &cbValue))
+ && (dwValue == 0)
+ )
+ {
+ bEnabled = TRUE;
+ }
+ }
+
+
+ RegCloseKey (hKey);
+ }
+
+ return bEnabled;
+}
+
+void GetProgramPath (HWND hwndDlg, wchar_t *path)
+{
+ ITEMIDLIST *i;
+ HRESULT res;
+
+ if (bForAllUsers)
+ res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_COMMON_PROGRAMS, &i);
+ else
+ res = SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAMS, &i);
+
+ SHGetPathFromIDList (i, path);
+}
+
+void StatusMessage (HWND hwndDlg, char *stringId)
+{
+ if (Rollback)
+ return;
+
+ SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) GetString (stringId));
+
+ SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
+ SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
+}
+
+void StatusMessageParam (HWND hwndDlg, char *stringId, wchar_t *param)
+{
+ wchar_t szTmp[1024];
+
+ if (Rollback)
+ return;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s %s", GetString (stringId), param);
+ SendMessageW (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_ADDSTRING, 0, (LPARAM) szTmp);
+
+ SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_SETTOPINDEX,
+ SendDlgItemMessage (hwndDlg, IDC_LOG_WINDOW, LB_GETCOUNT, 0, 0) - 1, 0);
+}
+
+void ClearLogWindow (HWND hwndDlg)
+{
+ SendMessage (GetDlgItem (hwndDlg, IDC_LOG_WINDOW), LB_RESETCONTENT, 0, 0);
+}
+
+void RegMessage (HWND hwndDlg, wchar_t *txt)
+{
+ StatusMessageParam (hwndDlg, "ADDING_REG", txt);
+}
+
+void CopyMessage (HWND hwndDlg, wchar_t *txt)
+{
+ StatusMessageParam (hwndDlg, "INSTALLING", txt);
+}
+
+void RemoveMessage (HWND hwndDlg, wchar_t *txt)
+{
+ if (!Rollback)
+ StatusMessageParam (hwndDlg, "REMOVING", txt);
+}
+
+void IconMessage (HWND hwndDlg, wchar_t *txt)
+{
+ StatusMessageParam (hwndDlg, "ADDING_ICON", txt);
+}
+
+void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr)
+{
+ LONG driverVersion = VERSION_NUM;
+ int status = 0;
+
+ if (hDriver == INVALID_HANDLE_VALUE)
+ status = DriverAttach();
+
+ if ((status == 0) && (hDriver != INVALID_HANDLE_VALUE))
+ {
+ DWORD dwResult;
+ BOOL bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
+
+ if (!bResult)
+ bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_DRIVER_VERSION, NULL, 0, &driverVersion, sizeof (driverVersion), &dwResult, NULL);
+
+
+ bUpgrade = (bResult && driverVersion <= VERSION_NUM);
+ bDowngrade = (bResult && driverVersion > VERSION_NUM);
+ bReinstallMode = (bResult && driverVersion == VERSION_NUM);
+
+ PortableMode = DeviceIoControl (hDriver, TC_IOCTL_GET_PORTABLE_MODE_STATUS, NULL, 0, NULL, 0, &dwResult, NULL);
+
+ if (bCloseDriverHandle)
+ {
+ CloseHandle (hDriver);
+ hDriver = INVALID_HANDLE_VALUE;
+ }
+ }
+
+ *driverVersionPtr = driverVersion;
+}
+
+
+static BOOL IsFileInUse (const wstring &filePath)
+{
+ HANDLE useTestHandle = CreateFile (filePath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (useTestHandle != INVALID_HANDLE_VALUE)
+ CloseHandle (useTestHandle);
+ else if (GetLastError() == ERROR_SHARING_VIOLATION)
+ return TRUE;
+
+ return FALSE;
+}
+
+
+BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir)
+{
+ /* WARNING: Note that, despite its name, this function is used during UNinstallation as well. */
+
+ wchar_t szTmp[TC_MAX_PATH];
+ BOOL bOK = TRUE;
+ int i, x, fileNo;
+ wchar_t curFileName [TC_MAX_PATH] = {0};
+
+ if (!bUninstall && !bDevm)
+ {
+ // Self-extract all files to memory
+
+ GetModuleFileName (NULL, szTmp, ARRAYSIZE (szTmp));
+
+ if (!SelfExtractInMemory (szTmp))
+ return FALSE;
+ }
+
+ x = wcslen (szDestDir);
+ if (x < 2)
+ return FALSE;
+
+ if (szDestDir[x - 1] != L'\\')
+ StringCbCatW (szDestDir, MAX_PATH, L"\\");
+
+ for (i = 0; i < sizeof (szFiles) / sizeof (szFiles[0]); i++)
+ {
+ BOOL bResult, driver64 = FALSE;
+ wchar_t szDir[TC_MAX_PATH];
+
+ if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0)
+ {
+ if (bUninstall)
+ continue; // Prevent 'access denied' error
+
+ if (bRepairMode)
+ continue; // Destination = target
+ }
+
+ // skip files that don't apply to the current architecture
+ if ( (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x64.exe") == 0))
+ || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x64.exe") == 0))
+ || (Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x64.exe") == 0))
+ || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0))
+ || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0))
+ || (!Is64BitOs () && (wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0))
+ )
+ {
+ continue;
+ }
+
+ 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'\\')
+ StringCbCatW (szDir, sizeof(szDir), L"\\");
+
+ StringCbCatW (szDir, sizeof(szDir), L"Drivers\\");
+ }
+ else if (*szFiles[i] == L'W')
+ GetWindowsDirectory (szDir, ARRAYSIZE (szDir));
+
+ if (*szFiles[i] == L'I')
+ continue;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, szFiles[i] + 1);
+
+ if (bUninstall == FALSE)
+ CopyMessage (hwndDlg, szTmp);
+ else
+ RemoveMessage (hwndDlg, szTmp);
+
+ if (bUninstall == FALSE)
+ {
+ SetCurrentDirectory (SetupFilesDir);
+
+ if (wcsstr (szFiles[i], L"VeraCrypt Setup") != 0)
+ {
+ // Copy ourselves (the distribution package) to the destination location as 'VeraCrypt Setup.exe'
+
+ wchar_t mp[MAX_PATH];
+
+ GetModuleFileName (NULL, mp, ARRAYSIZE (mp));
+ bResult = TCCopyFile (mp, szTmp);
+ }
+ else
+ {
+ 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)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), FILENAME_64BIT_DRIVER, sizeof (FILENAME_64BIT_DRIVER));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt-x64.exe", sizeof (L"VeraCrypt-x64.exe"));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCrypt-x86.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt.exe", sizeof (L"VeraCrypt.exe"));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCryptExpander.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander-x64.exe", sizeof (L"VeraCryptExpander-x64.exe"));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCryptExpander-x86.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCryptExpander.exe", sizeof (L"VeraCryptExpander.exe"));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCrypt Format.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format-x64.exe", sizeof (L"VeraCrypt Format-x64.exe"));
+ }
+
+ if (Is64BitOs ()
+ && wcscmp (szFiles[i], L"AVeraCrypt Format-x86.exe") == 0)
+ {
+ StringCbCopyNW (curFileName, sizeof(curFileName), L"VeraCrypt Format.exe", sizeof (L"VeraCrypt Format.exe"));
+ }
+
+ if (!bDevm)
+ {
+ bResult = FALSE;
+
+ // Find the correct decompressed file in memory
+ for (fileNo = 0; fileNo < NBR_COMPRESSED_FILES; fileNo++)
+ {
+ // Write the file (stored in memory) directly to the destination location
+ // (there will be no temporary files).
+ if (wmemcmp (
+ curFileName,
+ Decompressed_Files[fileNo].fileName,
+ min (wcslen (curFileName), (size_t) Decompressed_Files[fileNo].fileNameLength)) == 0)
+ {
+ // Dump filter driver cannot be installed to SysWOW64 directory
+ if (driver64 && !EnableWow64FsRedirection (FALSE))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ bResult = FALSE;
+ goto err;
+ }
+
+ bResult = SaveBufferToFile (
+ (char *) Decompressed_Files[fileNo].fileContent,
+ szTmp,
+ Decompressed_Files[fileNo].fileLength,
+ FALSE,
+ TRUE);
+
+ if (driver64)
+ {
+ if (!EnableWow64FsRedirection (TRUE))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ bResult = FALSE;
+ goto err;
+ }
+
+ if (!bResult)
+ goto err;
+
+ }
+
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (driver64)
+ EnableWow64FsRedirection (FALSE);
+
+ bResult = TCCopyFile (curFileName, szTmp);
+
+ if (driver64)
+ EnableWow64FsRedirection (TRUE);
+ }
+
+ if (bResult && wcscmp (szFiles[i], L"AVeraCrypt.exe") == 0)
+ {
+ if (Is64BitOs ())
+ EnableWow64FsRedirection (FALSE);
+
+ wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
+ wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true);
+ wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false);
+ wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true);
+
+ if ( FileExists (servicePath.c_str())
+ || (Is64BitOs () && FileExists (serviceLegacyPath.c_str()))
+ )
+ {
+ CopyMessage (hwndDlg, (wchar_t *) servicePath.c_str());
+ bResult = CopyFile (szTmp, servicePath.c_str(), FALSE);
+ }
+
+ if (bResult && Is64BitOs ()
+ && FileExists (favoritesLegacyFile.c_str())
+ && !FileExists (favoritesFile.c_str()))
+ {
+ // copy the favorites XML file to the native system directory
+ bResult = CopyFile (favoritesLegacyFile.c_str(), favoritesFile.c_str(), FALSE);
+ }
+
+ if (bResult && Is64BitOs () && FileExists (favoritesFile.c_str()) && FileExists (servicePath.c_str()))
+ {
+ // Update the path of the service
+ BootEncryption BootEncObj (hwndDlg);
+
+ try
+ {
+ if (BootEncObj.GetDriverServiceStartType() == SERVICE_BOOT_START)
+ {
+ BootEncObj.UpdateSystemFavoritesService ();
+ }
+ }
+ catch (...) {}
+ }
+
+ if (Is64BitOs ())
+ {
+ // delete files from legacy path
+ if (FileExists (favoritesLegacyFile.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
+ ForceDeleteFile (favoritesLegacyFile.c_str());
+ }
+
+ if (FileExists (serviceLegacyPath.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
+ ForceDeleteFile (serviceLegacyPath.c_str());
+ }
+
+ EnableWow64FsRedirection (TRUE);
+ }
+ }
+ }
+ }
+ 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);
+
+ wstring servicePath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", false);
+ wstring serviceLegacyPath = GetServiceConfigPath (_T(TC_APP_NAME) L".exe", true);
+ wstring favoritesFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false);
+ wstring favoritesLegacyFile = GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, true);
+
+ // delete all files related to system favorites service
+ if (FileExists (favoritesFile.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) favoritesFile.c_str());
+ ForceDeleteFile (favoritesFile.c_str());
+ }
+
+ if (FileExists (servicePath.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) servicePath.c_str());
+ ForceDeleteFile (servicePath.c_str());
+ }
+
+ if (Is64BitOs ())
+ {
+ if (FileExists (favoritesLegacyFile.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) favoritesLegacyFile.c_str());
+ ForceDeleteFile (favoritesLegacyFile.c_str());
+ }
+
+ if (FileExists (serviceLegacyPath.c_str()))
+ {
+ RemoveMessage (hwndDlg, (wchar_t *) serviceLegacyPath.c_str());
+ ForceDeleteFile (serviceLegacyPath.c_str());
+ }
+
+ EnableWow64FsRedirection (TRUE);
+ }
+ }
+ }
+
+err:
+ if (bResult == FALSE)
+ {
+ LPVOID lpMsgBuf;
+ DWORD dwError = GetLastError ();
+ wchar_t szTmp2[700];
+ wchar_t szErrorValue[16];
+ wchar_t* pszDesc;
+
+ FormatMessage (
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ (wchar_t *) &lpMsgBuf,
+ 0,
+ NULL
+ );
+
+ if (lpMsgBuf)
+ pszDesc = (wchar_t*) lpMsgBuf;
+ else
+ {
+ StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"0x%.8X", dwError);
+ pszDesc = szErrorValue;
+ }
+
+ if (bUninstall == FALSE)
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("INSTALL_OF_FAILED"), szTmp, pszDesc);
+ else
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), GetString ("UNINSTALL_OF_FAILED"), szTmp, pszDesc);
+
+ if (lpMsgBuf) LocalFree (lpMsgBuf);
+
+ if (!Silent && MessageBoxW (hwndDlg, szTmp2, lpszTitle, MB_YESNO | MB_ICONHAND) != IDYES)
+ return FALSE;
+ }
+ }
+
+ // Language pack
+ if (bUninstall == FALSE)
+ {
+ WIN32_FIND_DATA f;
+ HANDLE h;
+
+ SetCurrentDirectory (SetupFilesDir);
+ h = FindFirstFile (L"Language.*.xml", &f);
+
+ if (h != INVALID_HANDLE_VALUE)
+ {
+ wchar_t d[MAX_PATH*2];
+ StringCbPrintfW (d, sizeof(d), L"%s%s", szDestDir, f.cFileName);
+ CopyMessage (hwndDlg, d);
+ TCCopyFile (f.cFileName, d);
+ FindClose (h);
+ }
+
+ SetCurrentDirectory (SetupFilesDir);
+ SetCurrentDirectory (L"Setup files");
+ h = FindFirstFile (L"VeraCrypt User Guide.*.pdf", &f);
+ if (h != INVALID_HANDLE_VALUE)
+ {
+ wchar_t d[MAX_PATH*2];
+ StringCbPrintfW (d, sizeof(d), L"%s%s", szDestDir, f.cFileName);
+ CopyMessage (hwndDlg, d);
+ TCCopyFile (f.cFileName, d);
+ FindClose (h);
+ }
+ SetCurrentDirectory (SetupFilesDir);
+ }
+
+ return bOK;
+}
+
+BOOL DoRegInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bInstallType)
+{
+ wchar_t szDir[TC_MAX_PATH], *key;
+ wchar_t szTmp[TC_MAX_PATH*4];
+ HKEY hkey = 0;
+ BOOL bSlash, bOK = FALSE;
+ DWORD dw;
+ int x;
+
+ if (SystemEncryptionUpdate)
+ {
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt",
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_32KEY, NULL, &hkey, &dw) == ERROR_SUCCESS)
+ {
+ StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING));
+ RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t));
+
+ StringCbCopyW (szTmp, sizeof(szTmp), _T(TC_HOMEPAGE));
+ RegSetValueEx (hkey, L"URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t));
+
+ RegCloseKey (hkey);
+ }
+
+ return TRUE;
+ }
+
+ StringCbCopyW (szDir, sizeof(szDir), szDestDir);
+ x = wcslen (szDestDir);
+ if (szDestDir[x - 1] == L'\\')
+ bSlash = TRUE;
+ else
+ bSlash = FALSE;
+
+ if (bSlash == FALSE)
+ StringCbCatW (szDir, sizeof(szDir), L"\\");
+
+ if (bInstallType)
+ {
+
+ key = L"Software\\Classes\\VeraCryptVolume";
+ RegMessage (hwndDlg, key);
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
+ key,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCrypt Volume");
+ if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%ws", TC_APPLICATION_ID);
+ if (RegSetValueEx (hkey, L"AppUserModelID", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ RegCloseKey (hkey);
+ hkey = 0;
+
+ key = L"Software\\Classes\\VeraCryptVolume\\DefaultIcon";
+ RegMessage (hwndDlg, key);
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
+ key,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%sVeraCrypt.exe,1", szDir);
+ if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ RegCloseKey (hkey);
+ hkey = 0;
+
+ key = L"Software\\Classes\\VeraCryptVolume\\Shell\\open\\command";
+ RegMessage (hwndDlg, key);
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
+ key,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt.exe\" /v \"%%1\"", szDir );
+ if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ RegCloseKey (hkey);
+ hkey = 0;
+
+ key = L"Software\\Classes\\.hc";
+ BOOL typeClassChanged = TRUE;
+ wchar_t typeClass[256];
+ DWORD typeClassSize = sizeof (typeClass);
+
+ if (ReadLocalMachineRegistryString (key, L"", typeClass, &typeClassSize) && typeClassSize > 0 && wcscmp (typeClass, L"VeraCryptVolume") == 0)
+ typeClassChanged = FALSE;
+
+ RegMessage (hwndDlg, key);
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
+ key,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCryptVolume");
+ if (RegSetValueEx (hkey, L"", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ RegCloseKey (hkey);
+ hkey = 0;
+
+ if (typeClassChanged)
+ SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
+ }
+
+ key = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt";
+ RegMessage (hwndDlg, key);
+ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
+ key,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_32KEY, NULL, &hkey, &dw) != ERROR_SUCCESS)
+ goto error;
+
+ /* IMPORTANT: IF YOU CHANGE THIS IN ANY WAY, REVISE AND UPDATE SetInstallationPath() ACCORDINGLY! */
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\" /u", szDir);
+ if (RegSetValueEx (hkey, L"UninstallString", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\" /c", szDir);
+ if (RegSetValueEx (hkey, L"ModifyPath", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"\"%sVeraCrypt Setup.exe\"", szDir);
+ if (RegSetValueEx (hkey, L"DisplayIcon", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), _T(VERSION_STRING));
+ if (RegSetValueEx (hkey, L"DisplayVersion", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), L"VeraCrypt");
+ if (RegSetValueEx (hkey, L"DisplayName", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), L"IDRIX");
+ if (RegSetValueEx (hkey, L"Publisher", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ StringCbCopyW (szTmp, sizeof(szTmp), _T(TC_HOMEPAGE));
+ if (RegSetValueEx (hkey, L"URLInfoAbout", 0, REG_SZ, (BYTE *) szTmp, (wcslen (szTmp) + 1) * sizeof (wchar_t)) != ERROR_SUCCESS)
+ goto error;
+
+ bOK = TRUE;
+
+error:
+ if (hkey != 0)
+ RegCloseKey (hkey);
+
+ if (bOK == FALSE)
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ Error ("REG_INSTALL_FAILED", hwndDlg);
+ }
+
+ // Register COM servers for UAC
+ if (IsOSAtLeast (WIN_VISTA))
+ {
+ if (!RegisterComServers (szDir))
+ {
+ Error ("COM_REG_FAILED", hwndDlg);
+ return FALSE;
+ }
+ }
+
+ return bOK;
+}
+
+BOOL DoApplicationDataUninstall (HWND hwndDlg)
+{
+ wchar_t path[MAX_PATH];
+ wchar_t path2[MAX_PATH];
+ BOOL bOK = TRUE;
+
+ StatusMessage (hwndDlg, "REMOVING_APPDATA");
+
+ SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
+ StringCbCatW (path, sizeof(path), L"\\VeraCrypt\\");
+
+ // Delete favorite volumes file
+ StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_FAVORITE_VOLUMES);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ // Delete keyfile defaults
+ StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_DEFAULT_KEYFILES);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ // Delete history file
+ StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_HISTORY);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ // Delete configuration file
+ StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_CONFIGURATION);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ // Delete system encryption configuration file
+ StringCbPrintfW (path2, sizeof(path2), L"%s%s", path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
+ StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
+ RemoveMessage (hwndDlg, path);
+ if (!StatRemoveDirectory (path))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ bOK = FALSE;
+ }
+
+ // remove VeraCrypt under common appdata
+ if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
+ {
+ StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
+
+ // Delete original bootloader
+ StringCbPrintfW (path2, sizeof(path2), L"%s\\%s", path, TC_SYS_BOOT_LOADER_BACKUP_NAME);
+ RemoveMessage (hwndDlg, path2);
+ StatDeleteFile (path2, FALSE);
+
+ // remove VeraCrypt folder
+ RemoveMessage (hwndDlg, path);
+ StatRemoveDirectory (path);
+ }
+
+
+ return bOK;
+}
+
+BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated)
+{
+ wchar_t regk [64];
+ typedef LSTATUS (WINAPI *RegDeleteKeyExWFn) (HKEY hKey,LPCWSTR lpSubKey,REGSAM samDesired,WORD Reserved);
+ RegDeleteKeyExWFn RegDeleteKeyExWPtr = NULL;
+ HMODULE hAdvapiDll = LoadLibrary (L"Advapi32.dll");
+ if (hAdvapiDll)
+ {
+ RegDeleteKeyExWPtr = (RegDeleteKeyExWFn) GetProcAddress(hAdvapiDll, "RegDeleteKeyExW");
+ }
+
+ // Unregister COM servers
+ if (!bRemoveDeprecated && IsOSAtLeast (WIN_VISTA))
+ {
+ if (!UnregisterComServers (InstallationPath))
+ StatusMessage (hwndDlg, "COM_DEREG_FAILED");
+ }
+
+ if (!bRemoveDeprecated)
+ StatusMessage (hwndDlg, "REMOVING_REG");
+
+ if (RegDeleteKeyExWPtr)
+ {
+ RegDeleteKeyExWPtr (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", KEY_WOW64_32KEY, 0);
+ RegDeleteKeyExWPtr (HKEY_CURRENT_USER, L"Software\\VeraCrypt", KEY_WOW64_32KEY, 0);
+ }
+ else
+ {
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt");
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\VeraCrypt");
+ }
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open\\command");
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell\\open");
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\Shell");
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume\\DefaultIcon");
+ RegDeleteKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\VeraCryptVolume");
+
+ if (!bRemoveDeprecated)
+ {
+ HKEY hKey;
+ GetStartupRegKeyName (regk, sizeof(regk));
+ DeleteRegistryValue (regk, L"VeraCrypt");
+
+ DeleteRegistryKey (HKEY_LOCAL_MACHINE, L"Software\\Classes\\.hc");
+
+ // enable the SE_TAKE_OWNERSHIP_NAME privilege for this operation
+ SetPrivilege (SE_TAKE_OWNERSHIP_NAME, TRUE);
+
+ // clean MuiCache list from VeraCrypt entries
+ SearchAndDeleteRegistrySubString (HKEY_CLASSES_ROOT, L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", L"VeraCrypt", FALSE, NULL);
+
+ // clean other VeraCrypt entries from all users
+ SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.hc", NULL, TRUE, NULL);
+ SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Compatibility Assistant\\Persisted", L"VeraCrypt", TRUE, NULL);
+ SearchAndDeleteRegistrySubString (HKEY_USERS, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartPage\\NewShortcuts", L"VeraCrypt", TRUE, NULL);
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM", 0, KEY_ALL_ACCESS | WRITE_DAC | WRITE_OWNER, &hKey) == ERROR_SUCCESS)
+ {
+ SearchAndDeleteRegistrySubString (hKey, L"Enum\\Root\\LEGACY_VERACRYPT", NULL, TRUE, L"ControlSet");
+ SearchAndDeleteRegistrySubString (hKey, L"services\\veracrypt", NULL, TRUE, L"ControlSet");
+ RegCloseKey(hKey);
+ }
+
+ // disable the SE_TAKE_OWNERSHIP_NAME privilege for this operation
+ SetPrivilege (SE_TAKE_OWNERSHIP_NAME, FALSE);
+
+ SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
+ }
+
+ if (hAdvapiDll)
+ FreeLibrary (hAdvapiDll);
+
+ return TRUE;
+}
+
+
+BOOL DoServiceUninstall (HWND hwndDlg, wchar_t *lpszService)
+{
+ SC_HANDLE hManager, hService = NULL;
+ BOOL bOK = FALSE, bRet;
+ SERVICE_STATUS status;
+ BOOL firstTry = TRUE;
+ int x;
+
+ memset (&status, 0, sizeof (status)); /* Keep VC6 quiet */
+
+retry:
+
+ hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (hManager == NULL)
+ goto error;
+
+ hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
+ if (hService == NULL)
+ goto error;
+
+ if (wcscmp (L"veracrypt", lpszService) == 0)
+ {
+ try
+ {
+ BootEncryption bootEnc (hwndDlg);
+ if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
+ {
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::DriveFilter); } catch (...) { }
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::VolumeFilter); } catch (...) { }
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::DumpFilter); } catch (...) { }
+ }
+ }
+ catch (...) { }
+
+ StatusMessage (hwndDlg, "STOPPING_DRIVER");
+ }
+ else
+ StatusMessageParam (hwndDlg, "STOPPING", lpszService);
+
+#define WAIT_PERIOD 3
+
+ for (x = 0; x < WAIT_PERIOD; x++)
+ {
+ bRet = QueryServiceStatus (hService, &status);
+ if (bRet != TRUE)
+ goto error;
+
+ if (status.dwCurrentState != SERVICE_START_PENDING &&
+ status.dwCurrentState != SERVICE_STOP_PENDING &&
+ status.dwCurrentState != SERVICE_CONTINUE_PENDING)
+ break;
+
+ Sleep (1000);
+ }
+
+ if (status.dwCurrentState != SERVICE_STOPPED)
+ {
+ bRet = ControlService (hService, SERVICE_CONTROL_STOP, &status);
+ if (bRet == FALSE)
+ goto try_delete;
+
+ for (x = 0; x < WAIT_PERIOD; x++)
+ {
+ bRet = QueryServiceStatus (hService, &status);
+ if (bRet != TRUE)
+ goto error;
+
+ if (status.dwCurrentState != SERVICE_START_PENDING &&
+ status.dwCurrentState != SERVICE_STOP_PENDING &&
+ status.dwCurrentState != SERVICE_CONTINUE_PENDING)
+ break;
+
+ Sleep (1000);
+ }
+
+ if (status.dwCurrentState != SERVICE_STOPPED && status.dwCurrentState != SERVICE_STOP_PENDING)
+ goto error;
+ }
+
+try_delete:
+
+ if (wcscmp (L"veracrypt", lpszService) == 0)
+ StatusMessage (hwndDlg, "REMOVING_DRIVER");
+ else
+ StatusMessageParam (hwndDlg, "REMOVING", lpszService);
+
+ if (hService != NULL)
+ {
+ CloseServiceHandle (hService);
+ hService = NULL;
+ }
+
+ if (hManager != NULL)
+ {
+ CloseServiceHandle (hManager);
+ hManager = NULL;
+ }
+
+ hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (hManager == NULL)
+ goto error;
+
+ hService = OpenService (hManager, lpszService, SERVICE_ALL_ACCESS);
+ if (hService == NULL)
+ goto error;
+
+ bRet = DeleteService (hService);
+ if (bRet == FALSE)
+ {
+ if (firstTry && GetLastError () == ERROR_SERVICE_MARKED_FOR_DELETE)
+ {
+ // Second try for an eventual no-install driver instance
+ CloseServiceHandle (hService);
+ CloseServiceHandle (hManager);
+ hService = NULL;
+ hManager = NULL;
+
+ Sleep(1000);
+ firstTry = FALSE;
+ goto retry;
+ }
+
+ goto error;
+ }
+
+ bOK = TRUE;
+
+error:
+
+ if (bOK == FALSE && GetLastError ()!= ERROR_SERVICE_DOES_NOT_EXIST)
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ MessageBoxW (hwndDlg, GetString ("DRIVER_UINSTALL_FAILED"), lpszTitle, MB_ICONHAND);
+ }
+ else
+ bOK = TRUE;
+
+ if (hService != NULL)
+ CloseServiceHandle (hService);
+
+ if (hManager != NULL)
+ CloseServiceHandle (hManager);
+
+ return bOK;
+}
+
+
+BOOL DoDriverUnload (HWND hwndDlg)
+{
+ BOOL bOK = TRUE;
+ int status;
+
+ status = DriverAttach ();
+ if (status != 0)
+ {
+ if (status == ERR_OS_ERROR && GetLastError () != ERROR_FILE_NOT_FOUND)
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ AbortProcess ("NODRIVER");
+ }
+
+ if (status != ERR_OS_ERROR)
+ {
+ handleError (NULL, status, SRC_POS);
+ AbortProcess ("NODRIVER");
+ }
+ }
+
+ if (hDriver != INVALID_HANDLE_VALUE)
+ {
+ MOUNT_LIST_STRUCT driver;
+ LONG driverVersion = VERSION_NUM;
+ int refCount;
+ DWORD dwResult;
+ BOOL bResult;
+
+ // Try to determine if it's upgrade (and not reinstall, downgrade, or first-time install).
+ DetermineUpgradeDowngradeStatus (FALSE, &driverVersion);
+
+ // Test for encrypted boot drive
+ try
+ {
+ BootEncryption bootEnc (hwndDlg);
+ if (bootEnc.GetDriverServiceStartType() == SERVICE_BOOT_START)
+ {
+ try
+ {
+ // Check hidden OS update consistency
+ if (IsHiddenOSRunning())
+ {
+ if (bootEnc.GetInstalledBootLoaderVersion() != VERSION_NUM)
+ {
+ if (AskWarnNoYes ("UPDATE_TC_IN_DECOY_OS_FIRST", hwndDlg) == IDNO)
+ AbortProcessSilent ();
+ }
+ }
+ }
+ catch (...) { }
+
+ if (bUninstallInProgress && !bootEnc.GetStatus().DriveMounted)
+ {
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::DriveFilter); } catch (...) { }
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::VolumeFilter); } catch (...) { }
+ try { bootEnc.RegisterFilterDriver (false, BootEncryption::DumpFilter); } catch (...) { }
+ bootEnc.SetDriverServiceStartType (SERVICE_SYSTEM_START);
+ }
+ else if (bUninstallInProgress || bDowngrade)
+ {
+ Error (bDowngrade ? "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED_DOWNGRADE" : "SETUP_FAILED_BOOT_DRIVE_ENCRYPTED", hwndDlg);
+ return FALSE;
+ }
+ else
+ {
+ if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && CurrentOSServicePack < 1)
+ AbortProcess ("SYS_ENCRYPTION_UPGRADE_UNSUPPORTED_ON_VISTA_SP0");
+
+ SystemEncryptionUpdate = TRUE;
+ PortableMode = FALSE;
+ }
+ }
+ }
+ catch (...) { }
+
+ if (!bUninstall
+ && (bUpgrade || SystemEncryptionUpdate)
+ && (!bDevm || SystemEncryptionUpdate))
+ {
+ UnloadDriver = FALSE;
+ }
+
+ if (PortableMode && !SystemEncryptionUpdate)
+ UnloadDriver = TRUE;
+
+ if (UnloadDriver)
+ {
+ int volumesMounted = 0;
+
+ // Check mounted volumes
+ bResult = DeviceIoControl (hDriver, TC_IOCTL_IS_ANY_VOLUME_MOUNTED, NULL, 0, &volumesMounted, sizeof (volumesMounted), &dwResult, NULL);
+
+ if (!bResult)
+ {
+ bResult = DeviceIoControl (hDriver, TC_IOCTL_LEGACY_GET_MOUNTED_VOLUMES, NULL, 0, &driver, sizeof (driver), &dwResult, NULL);
+ if (bResult)
+ volumesMounted = driver.ulMountedDrives;
+ }
+
+ if (bResult)
+ {
+ if (volumesMounted != 0)
+ {
+ bOK = FALSE;
+ MessageBoxW (hwndDlg, GetString ("DISMOUNT_ALL_FIRST"), lpszTitle, MB_ICONHAND);
+ }
+ }
+ else
+ {
+ bOK = FALSE;
+ handleWin32Error (hwndDlg, SRC_POS);
+ }
+ }
+
+ // Try to close all open TC windows
+ if (bOK)
+ {
+ BOOL TCWindowClosed = FALSE;
+
+ EnumWindows (CloseTCWindowsEnum, (LPARAM) &TCWindowClosed);
+
+ if (TCWindowClosed)
+ Sleep (2000);
+ }
+
+ // Test for any applications attached to driver
+ if (!bUpgrade)
+ {
+ bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
+ sizeof (refCount), &dwResult, NULL);
+
+ if (bOK && bResult && refCount > 1)
+ {
+ MessageBoxW (hwndDlg, GetString ("CLOSE_TC_FIRST"), lpszTitle, MB_ICONSTOP);
+ bOK = FALSE;
+ }
+ }
+
+ if (!bOK || UnloadDriver)
+ {
+ CloseHandle (hDriver);
+ hDriver = INVALID_HANDLE_VALUE;
+ }
+ }
+ else
+ {
+ // Note that the driver may have already been unloaded during this session (e.g. retry after an error, etc.) so it is not
+ // guaranteed that the user is installing VeraCrypt for the first time now (we also cannot know if the user has already
+ // installed and used VeraCrypt on another system before).
+ bPossiblyFirstTimeInstall = TRUE;
+ }
+
+ return bOK;
+}
+
+
+BOOL UpgradeBootLoader (HWND hwndDlg)
+{
+ if (!SystemEncryptionUpdate)
+ return TRUE;
+
+ try
+ {
+ BootEncryption bootEnc (hwndDlg);
+ uint64 bootLoaderVersion = bootEnc.GetInstalledBootLoaderVersion();
+ if ((bootLoaderVersion < VERSION_NUM) || (bReinstallMode && (bootLoaderVersion == VERSION_NUM)))
+ {
+ StatusMessage (hwndDlg, "INSTALLER_UPDATING_BOOT_LOADER");
+
+ bootEnc.InstallBootLoader (true);
+
+ if (bootEnc.GetInstalledBootLoaderVersion() <= TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION)
+ Info (IsHiddenOSRunning() ? "BOOT_LOADER_UPGRADE_OK_HIDDEN_OS" : "BOOT_LOADER_UPGRADE_OK", hwndDlg);
+ }
+ return TRUE;
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
+ catch (...) { }
+
+ Error ("BOOT_LOADER_UPGRADE_FAILED", hwndDlg);
+ return FALSE;
+}
+
+
+BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir)
+{
+ wchar_t szLinkDir[TC_MAX_PATH];
+ wchar_t szTmp2[TC_MAX_PATH];
+ BOOL bSlash, bOK = FALSE;
+ HRESULT hOle;
+ int x;
+ BOOL allUsers = FALSE;
+
+ hOle = OleInitialize (NULL);
+
+ // User start menu
+ SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
+ x = wcslen (szLinkDir);
+ if (szLinkDir[x - 1] == L'\\')
+ bSlash = TRUE;
+ else
+ bSlash = FALSE;
+
+ if (bSlash == FALSE)
+ StringCbCatW (szLinkDir, sizeof(szLinkDir), L"\\");
+
+ StringCbCatW (szLinkDir, sizeof(szLinkDir), L"VeraCrypt");
+
+ // Global start menu
+ {
+ struct _stat st;
+ wchar_t path[TC_MAX_PATH];
+
+ SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
+ StringCbCatW (path, sizeof(path), L"\\VeraCrypt");
+
+ if (_wstat (path, &st) == 0)
+ {
+ StringCbCopyW (szLinkDir, sizeof(szLinkDir), path);
+ allUsers = TRUE;
+ }
+ }
+
+ // Start menu entries
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
+ RemoveMessage (hwndDlg, szTmp2);
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
+ goto error;
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCryptExpander.lnk");
+ RemoveMessage (hwndDlg, szTmp2);
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
+ goto error;
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt Website.url");
+ RemoveMessage (hwndDlg, szTmp2);
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
+ goto error;
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk");
+ RemoveMessage (hwndDlg, szTmp2);
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
+ goto error;
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt User's Guide.lnk");
+ StatDeleteFile (szTmp2, FALSE);
+
+ // Start menu group
+ RemoveMessage ((HWND) hwndDlg, szLinkDir);
+ if (StatRemoveDirectory (szLinkDir) == FALSE)
+ handleWin32Error ((HWND) hwndDlg, SRC_POS);
+
+ // Desktop icon
+
+ if (allUsers)
+ SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
+ else
+ SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
+
+ RemoveMessage (hwndDlg, szTmp2);
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
+ goto error;
+
+ bOK = TRUE;
+
+error:
+ OleUninitialize ();
+
+ return bOK;
+}
+
+BOOL DoShortcutsInstall (HWND hwndDlg, wchar_t *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
+{
+ wchar_t szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
+ wchar_t szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
+ BOOL bSlash, bOK = FALSE;
+ HRESULT hOle;
+ int x;
+
+ if (bProgGroup == FALSE && bDesktopIcon == FALSE)
+ return TRUE;
+
+ hOle = OleInitialize (NULL);
+
+ GetProgramPath (hwndDlg, szLinkDir);
+
+ x = wcslen (szLinkDir);
+ if (szLinkDir[x - 1] == L'\\')
+ bSlash = TRUE;
+ else
+ bSlash = FALSE;
+
+ if (bSlash == FALSE)
+ StringCbCatW (szLinkDir, sizeof(szLinkDir), L"\\");
+
+ StringCbCatW (szLinkDir, sizeof(szLinkDir), L"VeraCrypt");
+
+ StringCbCopyW (szDir, sizeof(szDir), szDestDir);
+ x = wcslen (szDestDir);
+ if (szDestDir[x - 1] == L'\\')
+ bSlash = TRUE;
+ else
+ bSlash = FALSE;
+
+ if (bSlash == FALSE)
+ StringCbCatW (szDir, sizeof(szDir), L"\\");
+
+ if (bProgGroup)
+ {
+ FILE *f;
+
+ if (mkfulldir (szLinkDir, TRUE) != 0)
+ {
+ if (mkfulldir (szLinkDir, FALSE) != 0)
+ {
+ wchar_t szTmpW[TC_MAX_PATH];
+
+ handleWin32Error (hwndDlg, SRC_POS);
+ StringCbPrintfW (szTmpW, sizeof(szTmpW), GetString ("CANT_CREATE_FOLDER"), szLinkDir);
+ MessageBoxW (hwndDlg, szTmpW, lpszTitle, MB_ICONHAND);
+ goto error;
+ }
+ }
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt.exe");
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
+
+ IconMessage (hwndDlg, szTmp2);
+ if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCryptExpander.exe");
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCryptExpander.lnk");
+
+ IconMessage (hwndDlg, szTmp2);
+ if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
+ goto error;
+
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt Website.url");
+ IconMessage (hwndDlg, szTmp2);
+ f = _wfopen (szTmp2, L"w");
+ if (f)
+ {
+ fprintf (f, "[InternetShortcut]\nURL=%s\n", TC_APPLINK);
+
+ CheckFileStreamWriteErrors (hwndDlg, f, szTmp2);
+ fclose (f);
+ }
+ else
+ goto error;
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt Setup.exe");
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\Uninstall VeraCrypt.lnk");
+ if (GetSystemDirectory (szTmp3, ARRAYSIZE(szTmp3)))
+ {
+ StringCbCatW (szTmp3, sizeof(szTmp3), L"\\control.exe");
+ }
+ else
+ StringCbCopyW(szTmp3, sizeof(szTmp3), L"C:\\Windows\\System32\\control.exe");
+
+ IconMessage (hwndDlg, szTmp2);
+ 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");
+ StatDeleteFile (szTmp2, FALSE);
+ }
+
+ if (bDesktopIcon)
+ {
+ StringCbCopyW (szDir, sizeof(szDir), szDestDir);
+ x = wcslen (szDestDir);
+ if (szDestDir[x - 1] == L'\\')
+ bSlash = TRUE;
+ else
+ bSlash = FALSE;
+
+ if (bSlash == FALSE)
+ StringCbCatW (szDir, sizeof(szDir), L"\\");
+
+ if (bForAllUsers)
+ SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
+ else
+ SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
+
+ StringCbPrintfW (szTmp, sizeof(szTmp), L"%s%s", szDir, L"VeraCrypt.exe");
+ StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s%s", szLinkDir, L"\\VeraCrypt.lnk");
+
+ IconMessage (hwndDlg, szTmp2);
+
+ if (CreateLink (szTmp, L"", szTmp2, NULL, -1) != S_OK)
+ goto error;
+ }
+
+ bOK = TRUE;
+
+error:
+ OleUninitialize ();
+
+ return bOK;
+}
+
+
+void OutcomePrompt (HWND hwndDlg, BOOL bOK)
+{
+ if (bOK)
+ {
+ EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
+
+ bDone = TRUE;
+
+ if (bUninstall == FALSE)
+ {
+ if (bDevm)
+ PostMessage (MainDlg, WM_CLOSE, 0, 0);
+ else if (bPossiblyFirstTimeInstall || bRepairMode || (!bUpgrade && !bDowngrade))
+ Info ("INSTALL_OK", hwndDlg);
+ else
+ Info ("SETUP_UPDATE_OK", hwndDlg);
+ }
+ else
+ {
+ wchar_t str[4096];
+
+ StringCbPrintfW (str, sizeof(str), GetString ("UNINSTALL_OK"), InstallationPath);
+ MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
+ }
+ }
+ else
+ {
+ if (bUninstall == FALSE)
+ Error ("INSTALL_FAILED", hwndDlg);
+ else
+ Error ("UNINSTALL_FAILED", hwndDlg);
+ }
+}
+
+static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
+{
+ static RESTOREPOINTINFO RestPtInfo;
+ static STATEMGRSTATUS SMgrStatus;
+ static BOOL failed = FALSE;
+ static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
+
+ if (!SystemRestoreDll) return;
+
+ _SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointW");
+ if (_SRSetRestorePoint == 0)
+ {
+ FreeLibrary (SystemRestoreDll);
+ SystemRestoreDll = 0;
+ return;
+ }
+
+ if (!finalize)
+ {
+ StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
+
+ RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
+ RestPtInfo.dwRestorePtType = bUninstall ? APPLICATION_UNINSTALL : APPLICATION_INSTALL | DEVICE_DRIVER_INSTALL;
+ RestPtInfo.llSequenceNumber = 0;
+ StringCbCopyW (RestPtInfo.szDescription, sizeof(RestPtInfo.szDescription), bUninstall ? L"VeraCrypt uninstallation" : L"VeraCrypt installation");
+
+ if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus))
+ {
+ StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
+ failed = TRUE;
+ }
+ }
+ else if (!failed)
+ {
+ RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
+ RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
+
+ if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
+ {
+ StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
+ }
+ }
+}
+
+void DoUninstall (void *arg)
+{
+ HWND hwndDlg = (HWND) arg;
+ BOOL bOK = TRUE;
+ BOOL bTempSkipSysRestore = FALSE;
+
+ if (!Rollback)
+ EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
+
+ WaitCursor ();
+
+ if (!Rollback)
+ {
+ ClearLogWindow (hwndDlg);
+ }
+
+ if (DoDriverUnload (hwndDlg) == FALSE)
+ {
+ bOK = FALSE;
+ bTempSkipSysRestore = TRUE; // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
+ }
+ else
+ {
+ if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
+ SetSystemRestorePoint (hwndDlg, FALSE);
+
+ if (DoServiceUninstall (hwndDlg, L"veracrypt") == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (!DoApplicationDataUninstall (hwndDlg))
+ {
+ bOK = FALSE;
+ }
+ else
+ {
+ wchar_t temp[MAX_PATH];
+ FILE *f;
+
+ // Deprecated service
+ DoServiceUninstall (hwndDlg, L"VeraCryptService");
+
+ GetTempPath (ARRAYSIZE (temp), temp);
+ StringCbPrintfW (UninstallBatch, sizeof (UninstallBatch), L"%sVeraCrypt-Uninstall.bat", temp);
+
+ UninstallBatch [ARRAYSIZE(UninstallBatch)-1] = 0;
+
+ // Create uninstall batch
+ f = _wfopen (UninstallBatch, L"w");
+ if (!f)
+ bOK = FALSE;
+ else
+ {
+ fwprintf (f,L":loop\n"
+ L"del \"%s%s\"\n"
+ L"if exist \"%s%s\" goto loop\n"
+ L"rmdir \"%s\"\n"
+ L"del \"%s\"",
+ InstallationPath, L"VeraCrypt Setup.exe",
+ InstallationPath, L"VeraCrypt Setup.exe",
+ InstallationPath,
+ UninstallBatch
+ );
+
+ CheckFileStreamWriteErrors (hwndDlg, f, UninstallBatch);
+ fclose (f);
+ }
+ }
+ }
+
+ NormalCursor ();
+
+ if (Rollback)
+ return;
+
+ if (bSystemRestore && !bTempSkipSysRestore)
+ SetSystemRestorePoint (hwndDlg, TRUE);
+
+ if (bOK)
+ PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
+ else
+ bUninstallInProgress = FALSE;
+
+ EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
+ OutcomePrompt (hwndDlg, bOK);
+}
+
+void DoInstall (void *arg)
+{
+ HWND hwndDlg = (HWND) arg;
+ BOOL bOK = TRUE;
+ wchar_t path[MAX_PATH];
+
+ BootEncryption bootEnc (hwndDlg);
+
+ // Refresh the main GUI (wizard thread)
+ InvalidateRect (MainDlg, NULL, TRUE);
+
+ ClearLogWindow (hwndDlg);
+
+ if (mkfulldir (InstallationPath, TRUE) != 0)
+ {
+ if (mkfulldir (InstallationPath, FALSE) != 0)
+ {
+ wchar_t szTmp[TC_MAX_PATH];
+
+ handleWin32Error (hwndDlg, SRC_POS);
+ StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CANT_CREATE_FOLDER"), InstallationPath);
+ MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
+ Error ("INSTALL_FAILED", hwndDlg);
+ PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
+ return;
+ }
+ }
+
+ UpdateProgressBarProc(2);
+
+ if (DoDriverUnload (hwndDlg) == FALSE)
+ {
+ NormalCursor ();
+ PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
+ return;
+ }
+
+ if (bUpgrade
+ && (IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L".exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x86.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"-x64.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x86.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Format-x64.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x86.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L"Expander-x64.exe")
+ || IsFileInUse (wstring (InstallationPath) + L'\\' + _T(TC_APP_NAME) L" Setup.exe")
+ )
+ )
+ {
+ NormalCursor ();
+ Error ("CLOSE_TC_FIRST", hwndDlg);
+ PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
+ return;
+ }
+
+ UpdateProgressBarProc(12);
+
+ if (bSystemRestore)
+ SetSystemRestorePoint (hwndDlg, FALSE);
+
+ UpdateProgressBarProc(48);
+
+ if (bDisableSwapFiles
+ && IsPagingFileActive (FALSE))
+ {
+ if (!DisablePagingFile())
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ Error ("FAILED_TO_DISABLE_PAGING_FILES", hwndDlg);
+ }
+ else
+ bRestartRequired = TRUE;
+ }
+
+ UpdateProgressBarProc(50);
+
+ // Remove deprecated
+ DoServiceUninstall (hwndDlg, L"VeraCryptService");
+
+ UpdateProgressBarProc(55);
+
+ if (!SystemEncryptionUpdate)
+ DoRegUninstall ((HWND) hwndDlg, TRUE);
+
+ UpdateProgressBarProc(61);
+
+ GetWindowsDirectory (path, ARRAYSIZE (path));
+ StringCbCatW (path, sizeof (path), L"\\VeraCrypt Setup.exe");
+ StatDeleteFile (path, FALSE);
+
+ if (UpdateProgressBarProc(63) && UnloadDriver && DoServiceUninstall (hwndDlg, L"veracrypt") == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (UpdateProgressBarProc(80) && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (UpdateProgressBarProc(85) && UnloadDriver && DoDriverInstall (hwndDlg) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (UpdateProgressBarProc(90) && SystemEncryptionUpdate && UpgradeBootLoader (hwndDlg) == FALSE)
+ {
+ bOK = FALSE;
+ }
+ else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
+ {
+ bOK = FALSE;
+ }
+
+ if (!UnloadDriver)
+ bRestartRequired = TRUE;
+
+ try
+ {
+ bootEnc.RenameDeprecatedSystemLoaderBackup();
+ }
+ catch (...) { }
+
+ if (bOK)
+ UpdateProgressBarProc(97);
+
+ if (bSystemRestore)
+ SetSystemRestorePoint (hwndDlg, TRUE);
+
+ if (bOK)
+ {
+ UpdateProgressBarProc(100);
+ UninstallBatch[0] = 0;
+ StatusMessage (hwndDlg, "INSTALL_COMPLETED");
+ }
+ else
+ {
+ UpdateProgressBarProc(0);
+
+ if (!SystemEncryptionUpdate)
+ {
+ bUninstall = TRUE;
+ Rollback = TRUE;
+ Silent = TRUE;
+
+ DoUninstall (hwndDlg);
+
+ bUninstall = FALSE;
+ Rollback = FALSE;
+ Silent = FALSE;
+
+ StatusMessage (hwndDlg, "ROLLBACK");
+ }
+ else
+ {
+ Warning ("SYS_ENC_UPGRADE_FAILED", hwndDlg);
+ }
+ }
+
+ OutcomePrompt (hwndDlg, bOK);
+
+ if (bOK && !bUninstall && !bDowngrade && !bRepairMode && !bDevm)
+ {
+ if (!IsHiddenOSRunning()) // A hidden OS user should not see the post-install notes twice (on decoy OS and then on hidden OS).
+ {
+ if (bRestartRequired || SystemEncryptionUpdate)
+ {
+ // Restart required
+
+ if (bUpgrade)
+ {
+ SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_RELEASE_NOTES);
+ }
+ else if (bPossiblyFirstTimeInstall)
+ {
+ SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_TUTORIAL);
+ }
+ }
+ else
+ {
+ // No restart will be required
+
+ if (bUpgrade)
+ {
+ bPromptReleaseNotes = TRUE;
+ }
+ else if (bPossiblyFirstTimeInstall)
+ {
+ bPromptTutorial = TRUE;
+ }
+ }
+ }
+ }
+
+ PostMessage (MainDlg, bOK ? TC_APPMSG_INSTALL_SUCCESS : TC_APPMSG_INSTALL_FAILURE, 0, 0);
+}
+
+
+void SetInstallationPath (HWND hwndDlg)
+{
+ HKEY hkey;
+ BOOL bInstallPathDetermined = FALSE;
+ wchar_t path[MAX_PATH+20];
+ ITEMIDLIST *itemList;
+
+ memset (InstallationPath, 0, sizeof (InstallationPath));
+
+ // Determine if VeraCrypt is already installed and try to determine its "Program Files" location
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VeraCrypt", 0, KEY_READ | KEY_WOW64_32KEY, &hkey) == ERROR_SUCCESS)
+ {
+ /* Default 'UninstallString' registry strings written by VeraCrypt:
+ ------------------------------------------------------------------------------------
+ 5.0+ "C:\Program Files\VeraCrypt\VeraCrypt Setup.exe" /u
+ */
+
+ wchar_t rv[MAX_PATH*4];
+ DWORD size = sizeof (rv);
+ if (RegQueryValueEx (hkey, L"UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && wcsrchr (rv, L'/'))
+ {
+ size_t len = 0;
+
+ // Cut and paste the location (path) where VeraCrypt is installed to InstallationPath
+ if (rv[0] == L'"')
+ {
+ len = wcsrchr (rv, L'/') - rv - 2;
+ StringCchCopyNW (InstallationPath, ARRAYSIZE(InstallationPath), rv + 1, len);
+ InstallationPath [len] = 0;
+ bInstallPathDetermined = TRUE;
+
+ if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\')
+ {
+ len = wcsrchr (InstallationPath, L'\\') - InstallationPath;
+ InstallationPath [len] = 0;
+ }
+ }
+
+ }
+ RegCloseKey (hkey);
+ }
+
+ if (bInstallPathDetermined)
+ {
+ wchar_t mp[MAX_PATH];
+
+ // Determine whether we were launched from the folder where VeraCrypt is installed
+ GetModuleFileName (NULL, mp, ARRAYSIZE (mp));
+ if (wcsncmp (InstallationPath, mp, min (wcslen(InstallationPath), wcslen(mp))) == 0)
+ {
+ // We were launched from the folder where VeraCrypt is installed
+
+ if (!IsNonInstallMode() && !bDevm)
+ bChangeMode = TRUE;
+ }
+ }
+ else
+ {
+ /* VeraCrypt is not installed or it wasn't possible to determine where it is installed. */
+
+ // Default "Program Files" path.
+ SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
+ SHGetPathFromIDList (itemList, path);
+
+ if (Is64BitOs())
+ {
+ // Use a unified default installation path (registry redirection of %ProgramFiles% does not work if the installation path is user-selectable)
+ wstring s = path;
+ size_t p = s.find (L" (x86)");
+ if (p != wstring::npos)
+ {
+ s = s.substr (0, p);
+ if (_waccess (s.c_str(), 0) != -1)
+ StringCbCopyW (path, sizeof (path), s.c_str());
+ }
+ }
+
+ StringCbCatW (path, sizeof(path), L"\\VeraCrypt\\");
+ StringCbCopyW (InstallationPath, sizeof(InstallationPath), path);
+ }
+
+ // Make sure the path ends with a backslash
+ if (InstallationPath [wcslen (InstallationPath) - 1] != L'\\')
+ {
+ StringCbCatW (InstallationPath, sizeof(InstallationPath), L"\\");
+ }
+}
+
+
+// Handler for uninstall only (install is handled by the wizard)
+BOOL CALLBACK UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ WORD lw = LOWORD (wParam);
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+
+ MainDlg = hwndDlg;
+
+ if (!CreateAppSetupMutex ())
+ AbortProcess ("TC_INSTALLER_IS_RUNNING");
+
+ InitDialog (hwndDlg);
+ LocalizeDialog (hwndDlg, NULL);
+
+ SetWindowTextW (hwndDlg, lpszTitle);
+
+ // System Restore
+ SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
+ if (SystemRestoreDll == 0)
+ {
+ SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
+ }
+
+ SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
+
+ return 1;
+
+ case WM_SYSCOMMAND:
+ if (lw == IDC_ABOUT)
+ {
+ DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
+ return 1;
+ }
+ return 0;
+
+ case WM_COMMAND:
+ if (lw == IDC_UNINSTALL)
+ {
+ if (bDone)
+ {
+ bUninstallInProgress = FALSE;
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+ return 1;
+ }
+
+ bUninstallInProgress = TRUE;
+
+ WaitCursor ();
+
+ if (bUninstall)
+ _beginthread (DoUninstall, 0, (void *) hwndDlg);
+
+ return 1;
+ }
+
+ if (lw == IDC_SYSTEM_RESTORE)
+ {
+ bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
+ return 1;
+ }
+
+ if (lw == IDCANCEL)
+ {
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+ return 1;
+ }
+
+ return 0;
+
+ case TC_APPMSG_UNINSTALL_SUCCESS:
+ SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
+ NormalCursor ();
+ return 1;
+
+ case WM_CLOSE:
+ if (bUninstallInProgress)
+ {
+ NormalCursor();
+ if (AskNoYes("CONFIRM_EXIT_UNIVERSAL", hwndDlg) == IDNO)
+ {
+ return 1;
+ }
+ WaitCursor ();
+ }
+ EndDialog (hwndDlg, IDCANCEL);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow)
+{
+ atexit (localcleanup);
+
+ SelfExtractStartupInit();
+
+ lpszTitle = L"VeraCrypt Setup";
+
+ /* Call InitApp to initialize the common code */
+ InitApp (hInstance, NULL);
+
+ if (IsAdmin () != TRUE)
+ if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
+ {
+ FinalizeApp ();
+ exit (1);
+ }
+
+ /* Setup directory */
+ {
+ wchar_t *s;
+ GetModuleFileName (NULL, SetupFilesDir, ARRAYSIZE (SetupFilesDir));
+ s = wcsrchr (SetupFilesDir, L'\\');
+ if (s)
+ s[1] = 0;
+ }
+
+ /* Parse command line arguments */
+
+ if (lpszCommandLine[0] == L'/')
+ {
+ if (lpszCommandLine[1] == L'u')
+ {
+ // Uninstall: /u
+
+ bUninstall = TRUE;
+ }
+ else if (lpszCommandLine[1] == L'c')
+ {
+ // Change: /c
+
+ bChangeMode = TRUE;
+ }
+ else if (lpszCommandLine[1] == L'p')
+ {
+ // Create self-extracting package: /p
+
+ bMakePackage = TRUE;
+ }
+ else if (lpszCommandLine[1] == L'd')
+ {
+ // Dev mode: /d
+ bDevm = TRUE;
+ }
+ }
+
+ if (bMakePackage)
+ {
+ /* Create self-extracting package */
+
+ MakeSelfExtractingPackage (NULL, SetupFilesDir);
+ }
+ else
+ {
+ SetInstallationPath (NULL);
+
+ if (!bUninstall)
+ {
+ if (IsSelfExtractingPackage())
+ {
+ if (!VerifyPackageIntegrity())
+ {
+ // Package corrupted
+ exit (1);
+ }
+ bDevm = FALSE;
+ }
+ else if (!bDevm)
+ {
+ MessageBox (NULL, L"Error: This installer file does not contain any compressed files.\n\nTo create a self-extracting installation package (with embedded compressed files), run:\n\"VeraCrypt Setup.exe\" /p", L"VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
+ FinalizeApp ();
+ exit (1);
+ }
+
+ if (bChangeMode)
+ {
+ /* VeraCrypt is already installed on this system and we were launched from the Program Files folder */
+
+ char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
+
+ // Ask the user to select either Repair or Unistallation
+ switch (AskMultiChoice ((void **) tmpStr, FALSE, NULL))
+ {
+ case 1:
+ bRepairMode = TRUE;
+ break;
+ case 2:
+ bUninstall = TRUE;
+ break;
+ default:
+ FinalizeApp ();
+ exit (1);
+ }
+ }
+ }
+
+ // System Restore
+ if (IsSystemRestoreEnabled ())
+ {
+ wchar_t dllPath[MAX_PATH];
+ if (GetSystemDirectory (dllPath, MAX_PATH))
+ {
+ StringCbCatW(dllPath, sizeof(dllPath), L"\\srclient.dll");
+ }
+ else
+ StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\srclient.dll");
+ SystemRestoreDll = LoadLibrary (dllPath);
+ }
+ else
+ SystemRestoreDll = 0;
+
+ if (!bUninstall)
+ {
+ /* Create the main dialog for install */
+
+ DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc,
+ (LPARAM)lpszCommandLine);
+ }
+ else
+ {
+ /* Create the main dialog for uninstall */
+
+ DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
+
+ if (UninstallBatch[0])
+ {
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+
+ ZeroMemory (&si, sizeof (si));
+ si.cb = sizeof (si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_HIDE;
+
+ if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
+ DeleteFile (UninstallBatch);
+ else
+ {
+ CloseHandle (pi.hProcess);
+ CloseHandle (pi.hThread);
+ }
+ }
+ }
+ }
+ FinalizeApp ();
+ return 0;
+}
diff --git a/src/Setup/Setup.h b/src/Setup/Setup.h
index 0de3417a..da31f3cd 100644
--- a/src/Setup/Setup.h
+++ b/src/Setup/Setup.h
@@ -1,190 +1,190 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#ifndef SETUP_H
-#define SETUP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Specifies what files to install, where (determined by the prefix), and in what order
-static wchar_t *szFiles[]=
-{
- L"AVeraCrypt User Guide.pdf",
- L"ALicense.txt",
- L"ALICENSE",
- L"ANOTICE",
- L"AVeraCrypt.exe",
- L"AVeraCryptExpander.exe",
- L"AVeraCrypt Format.exe",
- L"AVeraCrypt-x86.exe",
- L"AVeraCryptExpander-x86.exe",
- L"AVeraCrypt Format-x86.exe",
- L"AVeraCrypt-x64.exe",
- L"AVeraCryptExpander-x64.exe",
- L"AVeraCrypt Format-x64.exe",
- L"Averacrypt.sys",
- L"Averacrypt-x64.sys",
- L"Dveracrypt.sys",
- L"AVeraCrypt Setup.exe",
- L"ALanguage.ar.xml",
- L"ALanguage.be.xml",
- L"ALanguage.bg.xml",
- L"ALanguage.ca.xml",
- L"ALanguage.cs.xml",
- L"ALanguage.da.xml",
- L"ALanguage.de.xml",
- L"ALanguage.el.xml",
- L"ALanguage.es.xml",
- L"ALanguage.et.xml",
- L"ALanguage.eu.xml",
- L"ALanguage.fa.xml",
- L"ALanguage.fi.xml",
- L"ALanguage.fr.xml",
- L"ALanguage.hu.xml",
- L"ALanguage.id.xml",
- L"ALanguage.it.xml",
- L"ALanguage.ja.xml",
- L"ALanguage.ka.xml",
- L"ALanguage.ko.xml",
- L"ALanguage.lv.xml",
- L"ALanguage.my.xml",
- L"ALanguage.nl.xml",
- L"ALanguage.nn.xml",
- L"ALanguage.pl.xml",
- L"ALanguage.pt-br.xml",
- L"ALanguage.ru.xml",
- L"ALanguage.sk.xml",
- L"ALanguage.sl.xml",
- L"ALanguage.sv.xml",
- L"ALanguage.tr.xml",
- L"ALanguage.uk.xml",
- L"ALanguage.uz.xml",
- L"ALanguage.vi.xml",
- L"ALanguage.zh-cn.xml",
- L"ALanguage.zh-hk.xml",
- L"ALanguage.zh-tw.xml"
-};
-
-// Specifies what files are included in self-extracting packages (no other files will be packaged or extracted).
-static wchar_t *szCompressedFiles[]=
-{
- L"VeraCrypt User Guide.pdf",
- L"License.txt",
- L"LICENSE",
- L"NOTICE",
- L"VeraCrypt.exe",
- L"VeraCryptExpander.exe",
- L"VeraCrypt Format.exe",
- L"VeraCrypt-x64.exe",
- L"VeraCryptExpander-x64.exe",
- L"VeraCrypt Format-x64.exe",
- L"veracrypt.sys",
- L"veracrypt-x64.sys",
- L"Language.ar.xml",
- L"Language.be.xml",
- L"Language.bg.xml",
- L"Language.ca.xml",
- L"Language.cs.xml",
- L"Language.da.xml",
- L"Language.de.xml",
- L"Language.el.xml",
- L"Language.es.xml",
- L"Language.et.xml",
- L"Language.eu.xml",
- L"Language.fa.xml",
- L"Language.fi.xml",
- L"Language.fr.xml",
- L"Language.hu.xml",
- L"Language.id.xml",
- L"Language.it.xml",
- L"Language.ja.xml",
- L"Language.ka.xml",
- L"Language.ko.xml",
- L"Language.lv.xml",
- L"Language.my.xml",
- L"Language.nl.xml",
- L"Language.nn.xml",
- L"Language.pl.xml",
- L"Language.pt-br.xml",
- L"Language.ru.xml",
- L"Language.sk.xml",
- L"Language.sl.xml",
- L"Language.sv.xml",
- L"Language.tr.xml",
- L"Language.uk.xml",
- L"Language.uz.xml",
- L"Language.vi.xml",
- L"Language.zh-cn.xml",
- L"Language.zh-hk.xml",
- L"Language.zh-tw.xml"
-};
-
-#define FILENAME_64BIT_DRIVER L"veracrypt-x64.sys"
-#define NBR_COMPRESSED_FILES (sizeof(szCompressedFiles) / sizeof(szCompressedFiles[0]))
-
-void localcleanup (void);
-BOOL StatDeleteFile ( wchar_t *lpszFile, BOOL bCheckForOldFile );
-BOOL StatRemoveDirectory ( wchar_t *lpszDir );
-HRESULT CreateLink ( wchar_t *lpszPathObj , wchar_t *lpszArguments , wchar_t *lpszPathLink );
-void GetProgramPath ( HWND hwndDlg , wchar_t *path );
-void StatusMessage (HWND hwndDlg, char *stringId);
-void StatusMessageParam (HWND hwndDlg, char *stringId, wchar_t *param);
-void ClearLogWindow (HWND hwndDlg);
-void RegMessage ( HWND hwndDlg , wchar_t *txt );
-void RegRemoveMessage (HWND hwndDlg, wchar_t *txt);
-void CopyMessage ( HWND hwndDlg , wchar_t *txt );
-void RemoveMessage ( HWND hwndDlg , wchar_t *txt );
-void IconMessage ( HWND hwndDlg , wchar_t *txt );
-static int CALLBACK BrowseCallbackProc ( HWND hwnd , UINT uMsg , LPARAM lp , LPARAM pData );
-void LoadLicense ( HWND hwndDlg );
-void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr);
-BOOL DoFilesInstall ( HWND hwndDlg , wchar_t *szDestDir );
-BOOL DoRegInstall ( HWND hwndDlg , wchar_t *szDestDir , BOOL bInstallType );
-BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated);
-BOOL DoServiceUninstall ( HWND hwndDlg , wchar_t *lpszService );
-BOOL DoDriverUnload ( HWND hwndDlg );
-BOOL DoShortcutsInstall ( HWND hwndDlg , wchar_t *szDestDir , BOOL bProgGroup, BOOL bDesktopIcon );
-BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir);
-void OutcomePrompt ( HWND hwndDlg , BOOL bOK );
-void DoUninstall ( void *hwndDlg );
-void DoInstall ( void *hwndDlg );
-void SetInstallationPath (HWND hwndDlg);
-BOOL UpgradeBootLoader (HWND hwndDlg);
-BOOL CALLBACK InstallDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
-
-extern BOOL bDevm;
-extern BOOL Rollback;
-extern BOOL bUpgrade;
-extern BOOL bPossiblyFirstTimeInstall;
-extern BOOL bRepairMode;
-extern BOOL bReinstallMode;
-extern BOOL bSystemRestore;
-extern BOOL bDisableSwapFiles;
-extern BOOL bForAllUsers;
-extern BOOL bRegisterFileExt;
-extern BOOL bAddToStartMenu;
-extern BOOL bDesktopIcon;
-extern BOOL bDesktopIconStatusDetermined;
-extern BOOL SystemEncryptionUpdate;
-extern BOOL bRestartRequired;
-extern HMODULE volatile SystemRestoreDll;
-extern wchar_t InstallationPath[TC_MAX_PATH];
-extern wchar_t SetupFilesDir[TC_MAX_PATH];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // #ifndef SETUP_H
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#ifndef SETUP_H
+#define SETUP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Specifies what files to install, where (determined by the prefix), and in what order
+static wchar_t *szFiles[]=
+{
+ L"AVeraCrypt User Guide.pdf",
+ L"ALicense.txt",
+ L"ALICENSE",
+ L"ANOTICE",
+ L"AVeraCrypt.exe",
+ L"AVeraCryptExpander.exe",
+ L"AVeraCrypt Format.exe",
+ L"AVeraCrypt-x86.exe",
+ L"AVeraCryptExpander-x86.exe",
+ L"AVeraCrypt Format-x86.exe",
+ L"AVeraCrypt-x64.exe",
+ L"AVeraCryptExpander-x64.exe",
+ L"AVeraCrypt Format-x64.exe",
+ L"Averacrypt.sys",
+ L"Averacrypt-x64.sys",
+ L"Dveracrypt.sys",
+ L"AVeraCrypt Setup.exe",
+ L"ALanguage.ar.xml",
+ L"ALanguage.be.xml",
+ L"ALanguage.bg.xml",
+ L"ALanguage.ca.xml",
+ L"ALanguage.cs.xml",
+ L"ALanguage.da.xml",
+ L"ALanguage.de.xml",
+ L"ALanguage.el.xml",
+ L"ALanguage.es.xml",
+ L"ALanguage.et.xml",
+ L"ALanguage.eu.xml",
+ L"ALanguage.fa.xml",
+ L"ALanguage.fi.xml",
+ L"ALanguage.fr.xml",
+ L"ALanguage.hu.xml",
+ L"ALanguage.id.xml",
+ L"ALanguage.it.xml",
+ L"ALanguage.ja.xml",
+ L"ALanguage.ka.xml",
+ L"ALanguage.ko.xml",
+ L"ALanguage.lv.xml",
+ L"ALanguage.my.xml",
+ L"ALanguage.nl.xml",
+ L"ALanguage.nn.xml",
+ L"ALanguage.pl.xml",
+ L"ALanguage.pt-br.xml",
+ L"ALanguage.ru.xml",
+ L"ALanguage.sk.xml",
+ L"ALanguage.sl.xml",
+ L"ALanguage.sv.xml",
+ L"ALanguage.tr.xml",
+ L"ALanguage.uk.xml",
+ L"ALanguage.uz.xml",
+ L"ALanguage.vi.xml",
+ L"ALanguage.zh-cn.xml",
+ L"ALanguage.zh-hk.xml",
+ L"ALanguage.zh-tw.xml"
+};
+
+// Specifies what files are included in self-extracting packages (no other files will be packaged or extracted).
+static wchar_t *szCompressedFiles[]=
+{
+ L"VeraCrypt User Guide.pdf",
+ L"License.txt",
+ L"LICENSE",
+ L"NOTICE",
+ L"VeraCrypt.exe",
+ L"VeraCryptExpander.exe",
+ L"VeraCrypt Format.exe",
+ L"VeraCrypt-x64.exe",
+ L"VeraCryptExpander-x64.exe",
+ L"VeraCrypt Format-x64.exe",
+ L"veracrypt.sys",
+ L"veracrypt-x64.sys",
+ L"Language.ar.xml",
+ L"Language.be.xml",
+ L"Language.bg.xml",
+ L"Language.ca.xml",
+ L"Language.cs.xml",
+ L"Language.da.xml",
+ L"Language.de.xml",
+ L"Language.el.xml",
+ L"Language.es.xml",
+ L"Language.et.xml",
+ L"Language.eu.xml",
+ L"Language.fa.xml",
+ L"Language.fi.xml",
+ L"Language.fr.xml",
+ L"Language.hu.xml",
+ L"Language.id.xml",
+ L"Language.it.xml",
+ L"Language.ja.xml",
+ L"Language.ka.xml",
+ L"Language.ko.xml",
+ L"Language.lv.xml",
+ L"Language.my.xml",
+ L"Language.nl.xml",
+ L"Language.nn.xml",
+ L"Language.pl.xml",
+ L"Language.pt-br.xml",
+ L"Language.ru.xml",
+ L"Language.sk.xml",
+ L"Language.sl.xml",
+ L"Language.sv.xml",
+ L"Language.tr.xml",
+ L"Language.uk.xml",
+ L"Language.uz.xml",
+ L"Language.vi.xml",
+ L"Language.zh-cn.xml",
+ L"Language.zh-hk.xml",
+ L"Language.zh-tw.xml"
+};
+
+#define FILENAME_64BIT_DRIVER L"veracrypt-x64.sys"
+#define NBR_COMPRESSED_FILES (sizeof(szCompressedFiles) / sizeof(szCompressedFiles[0]))
+
+void localcleanup (void);
+BOOL StatDeleteFile ( wchar_t *lpszFile, BOOL bCheckForOldFile );
+BOOL StatRemoveDirectory ( wchar_t *lpszDir );
+HRESULT CreateLink ( wchar_t *lpszPathObj , wchar_t *lpszArguments , wchar_t *lpszPathLink );
+void GetProgramPath ( HWND hwndDlg , wchar_t *path );
+void StatusMessage (HWND hwndDlg, char *stringId);
+void StatusMessageParam (HWND hwndDlg, char *stringId, wchar_t *param);
+void ClearLogWindow (HWND hwndDlg);
+void RegMessage ( HWND hwndDlg , wchar_t *txt );
+void RegRemoveMessage (HWND hwndDlg, wchar_t *txt);
+void CopyMessage ( HWND hwndDlg , wchar_t *txt );
+void RemoveMessage ( HWND hwndDlg , wchar_t *txt );
+void IconMessage ( HWND hwndDlg , wchar_t *txt );
+static int CALLBACK BrowseCallbackProc ( HWND hwnd , UINT uMsg , LPARAM lp , LPARAM pData );
+void LoadLicense ( HWND hwndDlg );
+void DetermineUpgradeDowngradeStatus (BOOL bCloseDriverHandle, LONG *driverVersionPtr);
+BOOL DoFilesInstall ( HWND hwndDlg , wchar_t *szDestDir );
+BOOL DoRegInstall ( HWND hwndDlg , wchar_t *szDestDir , BOOL bInstallType );
+BOOL DoRegUninstall (HWND hwndDlg, BOOL bRemoveDeprecated);
+BOOL DoServiceUninstall ( HWND hwndDlg , wchar_t *lpszService );
+BOOL DoDriverUnload ( HWND hwndDlg );
+BOOL DoShortcutsInstall ( HWND hwndDlg , wchar_t *szDestDir , BOOL bProgGroup, BOOL bDesktopIcon );
+BOOL DoShortcutsUninstall (HWND hwndDlg, wchar_t *szDestDir);
+void OutcomePrompt ( HWND hwndDlg , BOOL bOK );
+void DoUninstall ( void *hwndDlg );
+void DoInstall ( void *hwndDlg );
+void SetInstallationPath (HWND hwndDlg);
+BOOL UpgradeBootLoader (HWND hwndDlg);
+BOOL CALLBACK InstallDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
+
+extern BOOL bDevm;
+extern BOOL Rollback;
+extern BOOL bUpgrade;
+extern BOOL bPossiblyFirstTimeInstall;
+extern BOOL bRepairMode;
+extern BOOL bReinstallMode;
+extern BOOL bSystemRestore;
+extern BOOL bDisableSwapFiles;
+extern BOOL bForAllUsers;
+extern BOOL bRegisterFileExt;
+extern BOOL bAddToStartMenu;
+extern BOOL bDesktopIcon;
+extern BOOL bDesktopIconStatusDetermined;
+extern BOOL SystemEncryptionUpdate;
+extern BOOL bRestartRequired;
+extern HMODULE volatile SystemRestoreDll;
+extern wchar_t InstallationPath[TC_MAX_PATH];
+extern wchar_t SetupFilesDir[TC_MAX_PATH];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // #ifndef SETUP_H
diff --git a/src/Setup/Setup.manifest b/src/Setup/Setup.manifest
index db2b8e62..afd4c1c0 100644
--- a/src/Setup/Setup.manifest
+++ b/src/Setup/Setup.manifest
@@ -1,33 +1,33 @@
-<?xml version="1.0" encoding="utf-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <asmv3:application>
- <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
- <dpiAware>true</dpiAware>
- </asmv3:windowsSettings>
- </asmv3:application>
- <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
- <application>
- <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
- <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
- </application>
- </compatibility>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity
- type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0"
- processorArchitecture="*"
- publicKeyToken="6595b64144ccf1df"
- language="*"
- />
- </dependentAssembly>
- </dependency>
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+ <asmv3:application>
+ <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
+ <dpiAware>true</dpiAware>
+ </asmv3:windowsSettings>
+ </asmv3:application>
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
+ </application>
+ </compatibility>
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.Windows.Common-Controls"
+ version="6.0.0.0"
+ processorArchitecture="*"
+ publicKeyToken="6595b64144ccf1df"
+ language="*"
+ />
+ </dependentAssembly>
+ </dependency>
</assembly> \ No newline at end of file
diff --git a/src/Setup/Setup.rc b/src/Setup/Setup.rc
index 2223505b..bdb89be1 100644
--- a/src/Setup/Setup.rc
+++ b/src/Setup/Setup.rc
@@ -1,327 +1,327 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-#include "..\\common\\resource.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,17,22,0
- PRODUCTVERSION 1,17,22,0
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904b0"
- BEGIN
- VALUE "CompanyName", "IDRIX"
- VALUE "FileDescription", "VeraCrypt Setup"
- VALUE "FileVersion", "1.17"
- VALUE "LegalTrademarks", "VeraCrypt"
- VALUE "OriginalFilename", "VeraCrypt Setup.exe"
- VALUE "ProductName", "VeraCrypt"
- VALUE "ProductVersion", "1.17"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// HEADER
-//
-
-IDR_SETUP_RSRC_HEADER HEADER "resource.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// REGISTRY
-//
-
-IDR_COMREG REGISTRY "ComSetup.rgs"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Dialog
-//
-
-IDD_UNINSTALL DIALOGEX 0, 0, 349, 234
-STYLE DS_SETFONT | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Uninstall VeraCrypt"
-CLASS "VeraCryptCustomDlg"
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- LTEXT "Click Uninstall to remove VeraCrypt from this system.",IDT_UNINSTALL_DIR,8,8,334,8
- LISTBOX IDC_LOG_WINDOW,7,21,335,179,LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_VSCROLL
- DEFPUSHBUTTON "&Uninstall",IDC_UNINSTALL,236,213,50,14
- PUSHBUTTON "Cancel",IDCANCEL,292,213,50,14
- CONTROL "Create System &Restore point",IDC_SYSTEM_RESTORE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,215,194,10
- CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,206,347,1,WS_EX_STATICEDGE
- CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,1,348,1,WS_EX_STATICEDGE
-END
-
-IDD_INSTALL_OPTIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- EDITTEXT IDC_DESTINATION,11,41,260,13,ES_AUTOHSCROLL
- PUSHBUTTON "Bro&wse...",IDC_BROWSE,278,40,59,14
- CONTROL "Install &for all users",IDC_ALL_USERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,77,168,11
- CONTROL "Associate the .hc file &extension with VeraCrypt",IDC_FILE_TYPE,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,113,232,11
- CONTROL "Add VeraCrypt to &Start menu",IDC_PROG_GROUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,89,168,11
- CONTROL "Create System &Restore point",IDC_SYSTEM_RESTORE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,125,194,11
- CONTROL "Add VeraCrypt icon to &desktop",IDC_DESKTOP_ICON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,101,168,11
- LTEXT "Please select or type the location where you want to install the VeraCrypt program files. If the specified folder does not exist, it will be automatically created.",IDT_INSTALL_DESTINATION,11,14,319,25
-END
-
-IDD_INFO_PAGE_DLG DIALOGEX 0, 0, 217, 156
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- LTEXT "",IDC_BOX_HELP,0,10,217,146
-END
-
-IDD_INTRO_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- CONTROL "",IDC_LICENSE_TEXT,"RichEdit20A",ES_MULTILINE | ES_READONLY | ES_NUMBER | WS_BORDER | WS_VSCROLL | WS_TABSTOP,0,23,345,108
- CONTROL "",IDC_AGREE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,2,137,126,10
- LTEXT "",IDC_BOX_HELP,0,0,346,22
-END
-
-IDD_INSTL_DLG DIALOGEX 0, 0, 374, 231
-STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "VeraCrypt Setup Wizard"
-CLASS "VeraCryptCustomDlg"
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- PUSHBUTTON "&Help",IDHELP,150,211,50,14
- PUSHBUTTON "",IDC_PREV,209,211,50,14
- DEFPUSHBUTTON "",IDC_NEXT,259,211,50,14
- PUSHBUTTON "Cancel",IDCANCEL,317,211,50,14
- LTEXT "",IDC_BOX_TITLE,11,5,324,12,0,WS_EX_TRANSPARENT
- CONTROL 107,IDC_BITMAP_SETUP_WIZARD,"Static",SS_BITMAP | SS_NOTIFY,139,3,228,30
- CONTROL 109,IDC_SETUP_WIZARD_BKG,"Static",SS_BITMAP,0,0,11,10
- CONTROL "",IDC_SETUP_WIZARD_GFX_AREA,"Static",SS_GRAYRECT | NOT WS_VISIBLE,0,0,378,36,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
- CONTROL "",IDC_HR_BOTTOM,"Static",SS_ETCHEDHORZ,67,204,306,1,WS_EX_STATICEDGE
- CONTROL "",IDC_HR,"Static",SS_ETCHEDHORZ,0,35,399,1,WS_EX_STATICEDGE
- LTEXT "VeraCrypt Installer",IDC_STATIC,4,200,62,8,WS_DISABLED
- LTEXT "",IDC_BOX_INFO,18,18,317,13,0,WS_EX_TRANSPARENT
- LTEXT "",IDC_MAIN_CONTENT_CANVAS,0,36,374,164
- LTEXT "",IDC_POS_BOX,14,42,346,155,0,WS_EX_TRANSPARENT
-END
-
-IDD_EXTRACTION_OPTIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- PUSHBUTTON "Bro&wse...",IDC_BROWSE,277,32,62,14
- EDITTEXT IDC_DESTINATION,6,33,264,12,ES_AUTOHSCROLL
- LTEXT "Please select or type the location where you want to place the extracted files:",IDT_EXTRACT_DESTINATION,6,15,333,17
- CONTROL "&Open the destination location when finished",IDC_OPEN_CONTAINING_FOLDER,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,91,318,16
- LTEXT "",IDC_BOX_HELP,6,56,333,32
-END
-
-IDD_WIZARD_MODE_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- CONTROL "&Install",IDC_WIZARD_MODE_INSTALL,"Button",BS_AUTORADIOBUTTON,6,14,232,10
- CONTROL "&Extract",IDC_WIZARD_MODE_EXTRACT_ONLY,"Button",BS_AUTORADIOBUTTON,6,60,232,10
- LTEXT "",IDC_BOX_HELP,42,77,286,64
- LTEXT "",IDC_BOX_HELP2,42,30,286,29
-END
-
-IDD_PROGRESS_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
- LISTBOX IDC_LOG_WINDOW,0,1,345,131,LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL
- CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,0,139,345,12
-END
-
-IDD_DONATIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
-STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-EXSTYLE WS_EX_TRANSPARENT
-FONT 8, "MS Shell Dlg", 0, 0, 0x0
-BEGIN
- PUSHBUTTON "Donate now...",IDC_DONATE,124,94,96,14
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Icon
-//
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_SETUP ICON "Setup.ico"
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""afxres.h""\r\n"
- "#include ""..\\\\common\\\\resource.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "#include ""..\\\\common\\\\common.rc""\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO
-BEGIN
- IDD_UNINSTALL, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 342
- TOPMARGIN, 7
- BOTTOMMARGIN, 229
- END
-
- IDD_INSTALL_OPTIONS_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 339
- TOPMARGIN, 7
- BOTTOMMARGIN, 147
- END
-
- IDD_INFO_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 210
- TOPMARGIN, 7
- BOTTOMMARGIN, 149
- END
-
- IDD_INTRO_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 339
- TOPMARGIN, 7
- BOTTOMMARGIN, 145
- END
-
- IDD_INSTL_DLG, DIALOG
- BEGIN
- RIGHTMARGIN, 367
- TOPMARGIN, 1
- BOTTOMMARGIN, 229
- HORZGUIDE, 196
- END
-
- IDD_EXTRACTION_OPTIONS_PAGE_DLG, DIALOG
- BEGIN
- RIGHTMARGIN, 343
- BOTTOMMARGIN, 147
- END
-
- IDD_WIZARD_MODE_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 339
- TOPMARGIN, 7
- BOTTOMMARGIN, 145
- END
-
- IDD_PROGRESS_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 339
- TOPMARGIN, 7
- BOTTOMMARGIN, 145
- END
-
- IDD_DONATIONS_PAGE_DLG, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 339
- TOPMARGIN, 7
- BOTTOMMARGIN, 147
- END
-END
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Bitmap
-//
-
-IDB_SETUP_WIZARD BITMAP "VeraCrypt_setup.bmp"
-IDB_SETUP_WIZARD_BKG BITMAP "VeraCrypt_setup_background.bmp"
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-#include "..\\common\\common.rc"
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+#include "..\\common\\resource.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,17,22,0
+ PRODUCTVERSION 1,17,22,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "IDRIX"
+ VALUE "FileDescription", "VeraCrypt Setup"
+ VALUE "FileVersion", "1.17"
+ VALUE "LegalTrademarks", "VeraCrypt"
+ VALUE "OriginalFilename", "VeraCrypt Setup.exe"
+ VALUE "ProductName", "VeraCrypt"
+ VALUE "ProductVersion", "1.17"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// HEADER
+//
+
+IDR_SETUP_RSRC_HEADER HEADER "resource.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// REGISTRY
+//
+
+IDR_COMREG REGISTRY "ComSetup.rgs"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_UNINSTALL DIALOGEX 0, 0, 349, 234
+STYLE DS_SETFONT | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Uninstall VeraCrypt"
+CLASS "VeraCryptCustomDlg"
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "Click Uninstall to remove VeraCrypt from this system.",IDT_UNINSTALL_DIR,8,8,334,8
+ LISTBOX IDC_LOG_WINDOW,7,21,335,179,LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_VSCROLL
+ DEFPUSHBUTTON "&Uninstall",IDC_UNINSTALL,236,213,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,292,213,50,14
+ CONTROL "Create System &Restore point",IDC_SYSTEM_RESTORE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,215,194,10
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,206,347,1,WS_EX_STATICEDGE
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,1,348,1,WS_EX_STATICEDGE
+END
+
+IDD_INSTALL_OPTIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ EDITTEXT IDC_DESTINATION,11,41,260,13,ES_AUTOHSCROLL
+ PUSHBUTTON "Bro&wse...",IDC_BROWSE,278,40,59,14
+ CONTROL "Install &for all users",IDC_ALL_USERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,77,168,11
+ CONTROL "Associate the .hc file &extension with VeraCrypt",IDC_FILE_TYPE,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,113,232,11
+ CONTROL "Add VeraCrypt to &Start menu",IDC_PROG_GROUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,89,168,11
+ CONTROL "Create System &Restore point",IDC_SYSTEM_RESTORE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,125,194,11
+ CONTROL "Add VeraCrypt icon to &desktop",IDC_DESKTOP_ICON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,101,168,11
+ LTEXT "Please select or type the location where you want to install the VeraCrypt program files. If the specified folder does not exist, it will be automatically created.",IDT_INSTALL_DESTINATION,11,14,319,25
+END
+
+IDD_INFO_PAGE_DLG DIALOGEX 0, 0, 217, 156
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "",IDC_BOX_HELP,0,10,217,146
+END
+
+IDD_INTRO_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "",IDC_LICENSE_TEXT,"RichEdit20A",ES_MULTILINE | ES_READONLY | ES_NUMBER | WS_BORDER | WS_VSCROLL | WS_TABSTOP,0,23,345,108
+ CONTROL "",IDC_AGREE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,2,137,126,10
+ LTEXT "",IDC_BOX_HELP,0,0,346,22
+END
+
+IDD_INSTL_DLG DIALOGEX 0, 0, 374, 231
+STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "VeraCrypt Setup Wizard"
+CLASS "VeraCryptCustomDlg"
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ PUSHBUTTON "&Help",IDHELP,150,211,50,14
+ PUSHBUTTON "",IDC_PREV,209,211,50,14
+ DEFPUSHBUTTON "",IDC_NEXT,259,211,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,317,211,50,14
+ LTEXT "",IDC_BOX_TITLE,11,5,324,12,0,WS_EX_TRANSPARENT
+ CONTROL 107,IDC_BITMAP_SETUP_WIZARD,"Static",SS_BITMAP | SS_NOTIFY,139,3,228,30
+ CONTROL 109,IDC_SETUP_WIZARD_BKG,"Static",SS_BITMAP,0,0,11,10
+ CONTROL "",IDC_SETUP_WIZARD_GFX_AREA,"Static",SS_GRAYRECT | NOT WS_VISIBLE,0,0,378,36,WS_EX_TRANSPARENT | WS_EX_STATICEDGE
+ CONTROL "",IDC_HR_BOTTOM,"Static",SS_ETCHEDHORZ,67,204,306,1,WS_EX_STATICEDGE
+ CONTROL "",IDC_HR,"Static",SS_ETCHEDHORZ,0,35,399,1,WS_EX_STATICEDGE
+ LTEXT "VeraCrypt Installer",IDC_STATIC,4,200,62,8,WS_DISABLED
+ LTEXT "",IDC_BOX_INFO,18,18,317,13,0,WS_EX_TRANSPARENT
+ LTEXT "",IDC_MAIN_CONTENT_CANVAS,0,36,374,164
+ LTEXT "",IDC_POS_BOX,14,42,346,155,0,WS_EX_TRANSPARENT
+END
+
+IDD_EXTRACTION_OPTIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ PUSHBUTTON "Bro&wse...",IDC_BROWSE,277,32,62,14
+ EDITTEXT IDC_DESTINATION,6,33,264,12,ES_AUTOHSCROLL
+ LTEXT "Please select or type the location where you want to place the extracted files:",IDT_EXTRACT_DESTINATION,6,15,333,17
+ CONTROL "&Open the destination location when finished",IDC_OPEN_CONTAINING_FOLDER,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,91,318,16
+ LTEXT "",IDC_BOX_HELP,6,56,333,32
+END
+
+IDD_WIZARD_MODE_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "&Install",IDC_WIZARD_MODE_INSTALL,"Button",BS_AUTORADIOBUTTON,6,14,232,10
+ CONTROL "&Extract",IDC_WIZARD_MODE_EXTRACT_ONLY,"Button",BS_AUTORADIOBUTTON,6,60,232,10
+ LTEXT "",IDC_BOX_HELP,42,77,286,64
+ LTEXT "",IDC_BOX_HELP2,42,30,286,29
+END
+
+IDD_PROGRESS_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LISTBOX IDC_LOG_WINDOW,0,1,345,131,LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL
+ CONTROL "",IDC_PROGRESS_BAR,"msctls_progress32",PBS_SMOOTH | WS_BORDER,0,139,345,12
+END
+
+IDD_DONATIONS_PAGE_DLG DIALOGEX 0, 0, 346, 152
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
+EXSTYLE WS_EX_TRANSPARENT
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ PUSHBUTTON "Donate now...",IDC_DONATE,124,94,96,14
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_SETUP ICON "Setup.ico"
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "#include ""..\\\\common\\\\resource.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "#include ""..\\\\common\\\\common.rc""\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_UNINSTALL, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 342
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 229
+ END
+
+ IDD_INSTALL_OPTIONS_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 339
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_INFO_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 210
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 149
+ END
+
+ IDD_INTRO_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 339
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_INSTL_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 367
+ TOPMARGIN, 1
+ BOTTOMMARGIN, 229
+ HORZGUIDE, 196
+ END
+
+ IDD_EXTRACTION_OPTIONS_PAGE_DLG, DIALOG
+ BEGIN
+ RIGHTMARGIN, 343
+ BOTTOMMARGIN, 147
+ END
+
+ IDD_WIZARD_MODE_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 339
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_PROGRESS_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 339
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 145
+ END
+
+ IDD_DONATIONS_PAGE_DLG, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 339
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 147
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+IDB_SETUP_WIZARD BITMAP "VeraCrypt_setup.bmp"
+IDB_SETUP_WIZARD_BKG BITMAP "VeraCrypt_setup_background.bmp"
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+#include "..\\common\\common.rc"
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/src/Setup/Setup.vcproj b/src/Setup/Setup.vcproj
index 05a67aa0..a1a6a81f 100644
--- a/src/Setup/Setup.vcproj
+++ b/src/Setup/Setup.vcproj
@@ -1,484 +1,484 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="9.00"
- Name="Setup"
- ProjectGUID="{DF5F654D-BD44-4E31-B92E-B68074DC37A8}"
- RootNamespace="Setup"
- Keyword="Win32Proj"
- TargetFrameworkVersion="131072"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
- CharacterSet="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\Common;..\Crypto;..\;..\PKCS11"
- PreprocessorDefinitions="SETUP;WIN32;DEBUG;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;_ATL_NO_DEFAULT_LIBS"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- BufferSecurityCheck="true"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- DebugInformationFormat="4"
- DisableSpecificWarnings="4057;4100;4127;4201;4505;4701;4706"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/NODEFAULTLIB:LIBCMTD"
- AdditionalDependencies="libcmtd.lib atlsd.lib mpr.lib"
- OutputFile="$(OutDir)/VeraCryptSetup.exe"
- LinkIncremental="2"
- GenerateManifest="false"
- UACExecutionLevel="2"
- DelayLoadDLLs="user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll"
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/Setup.pdb"
- SubSystem="2"
- RandomizedBaseAddress="1"
- DataExecutionPrevention="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- AdditionalManifestFiles="Setup.manifest"
- EmbedManifest="true"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="md &quot;..\Debug\Setup Files&quot; 2&gt;NUL:&#x0D;&#x0A;copy Debug\VeraCryptSetup.exe &quot;..\Debug\Setup Files\VeraCrypt Setup.exe&quot; &gt;NUL:&#x0D;&#x0A;"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
- CharacterSet="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalOptions="/w34189"
- Optimization="2"
- AdditionalIncludeDirectories="..\Common;..\Crypto;..\;..\PKCS11"
- PreprocessorDefinitions="SETUP;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;_ATL_NO_DEFAULT_LIBS"
- RuntimeLibrary="0"
- BufferSecurityCheck="true"
- UsePrecompiledHeader="0"
- AssemblerOutput="2"
- AssemblerListingLocation="$(IntDir)/"
- WarningLevel="4"
- DebugInformationFormat="0"
- DisableSpecificWarnings="4057;4100;4127;4201;4505;4701;4706"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="/IGNORE:4089"
- AdditionalDependencies="mpr.lib"
- OutputFile="$(OutDir)/VeraCryptSetup.exe"
- LinkIncremental="1"
- GenerateManifest="false"
- UACExecutionLevel="2"
- DelayLoadDLLs="user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll"
- GenerateDebugInformation="false"
- GenerateMapFile="true"
- SubSystem="2"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- RandomizedBaseAddress="1"
- DataExecutionPrevention="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- AdditionalManifestFiles="Setup.manifest"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="copy Release\VeraCryptSetup.exe &quot;..\Release\Setup Files\VeraCrypt Setup.exe&quot;"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
- >
- <File
- RelativePath=".\ComSetup.cpp"
- >
- </File>
- <File
- RelativePath=".\ComSetup.rgs"
- >
- </File>
- <File
- RelativePath=".\Dir.c"
- >
- </File>
- <File
- RelativePath=".\SelfExtract.c"
- >
- </File>
- <File
- RelativePath=".\Setup.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath=".\Wizard.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\Common\Xml.c"
- >
- </File>
- <Filter
- Name="Common"
- >
- <File
- RelativePath="..\Common\BootEncryption.cpp"
- >
- </File>
- <File
- RelativePath="..\Common\Crc.c"
- >
- </File>
- <File
- RelativePath="..\Common\Dictionary.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\Common\Dlgcode.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- CompileAs="2"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\Common\Endian.c"
- >
- </File>
- <File
- RelativePath="..\Common\Inflate.c"
- >
- </File>
- <File
- RelativePath="..\Common\Language.c"
- >
- </File>
- <File
- RelativePath="..\Common\Registry.c"
- >
- </File>
- </Filter>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
- >
- <File
- RelativePath="..\Common\Apidrvr.h"
- >
- </File>
- <File
- RelativePath="..\Common\Combo.h"
- >
- </File>
- <File
- RelativePath=".\ComSetup.h"
- >
- </File>
- <File
- RelativePath="..\Common\Crc.h"
- >
- </File>
- <File
- RelativePath=".\Dir.h"
- >
- </File>
- <File
- RelativePath="..\Common\Dlgcode.h"
- >
- </File>
- <File
- RelativePath="..\Common\Exception.h"
- >
- </File>
- <File
- RelativePath="..\Common\Inflate.h"
- >
- </File>
- <File
- RelativePath="..\Common\Language.h"
- >
- </File>
- <File
- RelativePath="..\Common\Registry.h"
- >
- </File>
- <File
- RelativePath="..\Common\Resource.h"
- >
- </File>
- <File
- RelativePath=".\Resource.h"
- >
- </File>
- <File
- RelativePath=".\SelfExtract.h"
- >
- </File>
- <File
- RelativePath=".\Setup.h"
- >
- </File>
- <File
- RelativePath="..\Common\Tcdefs.h"
- >
- </File>
- <File
- RelativePath=".\Wizard.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
- >
- <File
- RelativePath=".\Setup.ico"
- >
- </File>
- <File
- RelativePath=".\Setup.manifest"
- >
- </File>
- <File
- RelativePath=".\Setup.rc"
- >
- </File>
- <File
- RelativePath="..\Common\VeraCrypt.ico"
- >
- </File>
- <File
- RelativePath=".\VeraCrypt_setup.bmp"
- >
- </File>
- <File
- RelativePath=".\VeraCrypt_setup_background.bmp"
- >
- </File>
- <File
- RelativePath="..\Common\VeraCrypt_Volume.ico"
- >
- </File>
- <Filter
- Name="Common"
- >
- <File
- RelativePath="..\Common\Common.rc"
- >
- <FileConfiguration
- Name="Debug|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCResourceCompilerTool"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCResourceCompilerTool"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\Common\Language.xml"
- >
- </File>
- <File
- RelativePath="..\Resources\Texts\License.rtf"
- >
- </File>
- <File
- RelativePath="..\Common\Textual_logo_288dpi.bmp"
- >
- </File>
- <File
- RelativePath="..\Common\Textual_logo_96dpi.bmp"
- >
- </File>
- <File
- RelativePath="..\Common\Textual_logo_background.bmp"
- >
- </File>
- </Filter>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="Setup"
+ ProjectGUID="{DF5F654D-BD44-4E31-B92E-B68074DC37A8}"
+ RootNamespace="Setup"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\Common;..\Crypto;..\;..\PKCS11"
+ PreprocessorDefinitions="SETUP;WIN32;DEBUG;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;_ATL_NO_DEFAULT_LIBS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ DebugInformationFormat="4"
+ DisableSpecificWarnings="4057;4100;4127;4201;4505;4701;4706"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="/NODEFAULTLIB:LIBCMTD"
+ AdditionalDependencies="libcmtd.lib atlsd.lib mpr.lib"
+ OutputFile="$(OutDir)/VeraCryptSetup.exe"
+ LinkIncremental="2"
+ GenerateManifest="false"
+ UACExecutionLevel="2"
+ DelayLoadDLLs="user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Setup.pdb"
+ SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ AdditionalManifestFiles="Setup.manifest"
+ EmbedManifest="true"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="md &quot;..\Debug\Setup Files&quot; 2&gt;NUL:&#x0D;&#x0A;copy Debug\VeraCryptSetup.exe &quot;..\Debug\Setup Files\VeraCrypt Setup.exe&quot; &gt;NUL:&#x0D;&#x0A;"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/w34189"
+ Optimization="2"
+ AdditionalIncludeDirectories="..\Common;..\Crypto;..\;..\PKCS11"
+ PreprocessorDefinitions="SETUP;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS;_ATL_NO_DEFAULT_LIBS"
+ RuntimeLibrary="0"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="0"
+ AssemblerOutput="2"
+ AssemblerListingLocation="$(IntDir)/"
+ WarningLevel="4"
+ DebugInformationFormat="0"
+ DisableSpecificWarnings="4057;4100;4127;4201;4505;4701;4706"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="/IGNORE:4089"
+ AdditionalDependencies="mpr.lib"
+ OutputFile="$(OutDir)/VeraCryptSetup.exe"
+ LinkIncremental="1"
+ GenerateManifest="false"
+ UACExecutionLevel="2"
+ DelayLoadDLLs="user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;mpr.dll"
+ GenerateDebugInformation="false"
+ GenerateMapFile="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ AdditionalManifestFiles="Setup.manifest"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="copy Release\VeraCryptSetup.exe &quot;..\Release\Setup Files\VeraCrypt Setup.exe&quot;"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\ComSetup.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\ComSetup.rgs"
+ >
+ </File>
+ <File
+ RelativePath=".\Dir.c"
+ >
+ </File>
+ <File
+ RelativePath=".\SelfExtract.c"
+ >
+ </File>
+ <File
+ RelativePath=".\Setup.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\Wizard.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Xml.c"
+ >
+ </File>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\Common\BootEncryption.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crc.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Dictionary.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Dlgcode.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ CompileAs="2"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Endian.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Inflate.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Language.c"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Registry.c"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\Common\Apidrvr.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Combo.h"
+ >
+ </File>
+ <File
+ RelativePath=".\ComSetup.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Crc.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Dir.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Dlgcode.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Exception.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Inflate.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Language.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Registry.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Resource.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Resource.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SelfExtract.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Setup.h"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Tcdefs.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Wizard.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\Setup.ico"
+ >
+ </File>
+ <File
+ RelativePath=".\Setup.manifest"
+ >
+ </File>
+ <File
+ RelativePath=".\Setup.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\VeraCrypt.ico"
+ >
+ </File>
+ <File
+ RelativePath=".\VeraCrypt_setup.bmp"
+ >
+ </File>
+ <File
+ RelativePath=".\VeraCrypt_setup_background.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\VeraCrypt_Volume.ico"
+ >
+ </File>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\Common\Common.rc"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\Common\Language.xml"
+ >
+ </File>
+ <File
+ RelativePath="..\Resources\Texts\License.rtf"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_288dpi.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_96dpi.bmp"
+ >
+ </File>
+ <File
+ RelativePath="..\Common\Textual_logo_background.bmp"
+ >
+ </File>
+ </Filter>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/src/Setup/Wizard.c b/src/Setup/Wizard.c
index a5ee418b..42ea42c9 100644
--- a/src/Setup/Wizard.c
+++ b/src/Setup/Wizard.c
@@ -1,1195 +1,1195 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#include "Tcdefs.h"
-#include <Shlobj.h>
-#include <io.h>
-#include <stdio.h>
-#include <time.h>
-#include "SelfExtract.h"
-#include "Wizard.h"
-#include "Dlgcode.h"
-#include "Language.h"
-#include "Common/Resource.h"
-#include "Resource.h"
-#include "Setup.h"
-#include <tchar.h>
-#include <Strsafe.h>
-
-using namespace std;
-
-enum wizard_pages
-{
- INTRO_PAGE,
- WIZARD_MODE_PAGE,
- INSTALL_OPTIONS_PAGE,
- INSTALL_PROGRESS_PAGE,
- EXTRACTION_OPTIONS_PAGE,
- EXTRACTION_PROGRESS_PAGE,
- DONATIONS_PAGE
-};
-
-HWND hCurPage = NULL; /* Handle to current wizard page */
-int nCurPageNo = -1; /* The current wizard page */
-wchar_t WizardDestInstallPath [TC_MAX_PATH];
-wchar_t WizardDestExtractPath [TC_MAX_PATH];
-wchar_t SelfFile [TC_MAX_PATH];
-
-HBITMAP hbmWizardBitmapRescaled = NULL;
-
-BOOL bExtractOnly = FALSE;
-BOOL bLicenseAccepted = FALSE;
-BOOL bOpenContainingFolder = TRUE;
-BOOL bExtractionSuccessful = FALSE;
-BOOL bStartInstall = FALSE;
-BOOL bStartExtraction = FALSE;
-BOOL bInProgress = FALSE;
-BOOL bPromptTutorial = FALSE;
-BOOL bPromptReleaseNotes = FALSE;
-
-int nPbar = 0; /* Control ID of progress bar */
-
-static HFONT hDonTextFont;
-static BOOL OsPrngAvailable;
-static HCRYPTPROV hCryptProv;
-static int DonColorSchemeId;
-static COLORREF DonTextColor;
-static COLORREF DonBkgColor;
-
-wstring DonText = L"";
-
-void localcleanupwiz (void)
-{
- /* Delete buffered bitmaps (if any) */
- if (hbmWizardBitmapRescaled != NULL)
- {
- DeleteObject ((HGDIOBJ) hbmWizardBitmapRescaled);
- hbmWizardBitmapRescaled = NULL;
- }
-
- if (hCryptProv != 0)
- {
- OsPrngAvailable = FALSE;
- CryptReleaseContext (hCryptProv, 0);
- hCryptProv = 0;
- }
-
- if (hDonTextFont != NULL)
- {
- DeleteObject (hDonTextFont);
- hDonTextFont = NULL;
- }
-}
-
-static void InitWizardDestInstallPath (void)
-{
- if (wcslen (WizardDestInstallPath) < 2)
- {
- StringCbCopyW (WizardDestInstallPath, sizeof(WizardDestInstallPath), InstallationPath);
- if (WizardDestInstallPath [wcslen (WizardDestInstallPath) - 1] != L'\\')
- {
- StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
- }
- }
-}
-
-void LoadPage (HWND hwndDlg, int nPageNo)
-{
- RECT rD, rW;
-
- if (hCurPage != NULL)
- {
- DestroyWindow (hCurPage);
- }
-
- InvalidateRect (GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS), NULL, TRUE);
-
- GetWindowRect (GetDlgItem (hwndDlg, IDC_POS_BOX), &rW);
-
- nCurPageNo = nPageNo;
-
- switch (nPageNo)
- {
- case INTRO_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INTRO_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case WIZARD_MODE_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_WIZARD_MODE_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case INSTALL_OPTIONS_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INSTALL_OPTIONS_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case INSTALL_PROGRESS_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case EXTRACTION_OPTIONS_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_EXTRACTION_OPTIONS_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case EXTRACTION_PROGRESS_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
-
- case DONATIONS_PAGE:
- hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_DONATIONS_PAGE_DLG), hwndDlg,
- (DLGPROC) PageDialogProc);
- break;
- }
-
- rD.left = 15;
- rD.top = 45;
- rD.right = 0;
- rD.bottom = 0;
- MapDialogRect (hwndDlg, &rD);
-
- if (hCurPage != NULL)
- {
- MoveWindow (hCurPage, rD.left, rD.top, rW.right - rW.left, rW.bottom - rW.top, TRUE);
- ShowWindow (hCurPage, SW_SHOWNORMAL);
- }
-
- /* Refresh the graphics (white background of some texts, etc.) */
- RefreshUIGFX ();
-}
-
-
-static int GetDonVal (int minVal, int maxVal)
-{
- static BOOL prngInitialized = FALSE;
- static unsigned __int8 buffer [2];
-
- if (!prngInitialized)
- {
- if (!CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)
- && !CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
- OsPrngAvailable = FALSE;
- else
- OsPrngAvailable = TRUE;
-
- srand ((unsigned int) time (NULL));
- rand(); // Generate and discard the inital value, as it always appears to be somewhat non-random.
-
- prngInitialized = TRUE;
- }
-
- if (OsPrngAvailable && CryptGenRandom (hCryptProv, sizeof (buffer), buffer) != 0)
- {
- return ((int) ((double) *((uint16 *) buffer) / (0xFFFF+1) * (maxVal + 1 - minVal)) + minVal);
- }
- else
- return ((int) ((double) rand() / (RAND_MAX+1) * (maxVal + 1 - minVal)) + minVal);
-}
-
-
-/* Except in response to the WM_INITDIALOG message, the dialog box procedure
- should return nonzero if it processes the message, and zero if it does
- not. - see DialogProc */
-BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- static char PageDebugId[128];
- WORD lw = LOWORD (wParam);
- WORD hw = HIWORD (wParam);
-
- hCurPage = hwndDlg;
-
- switch (uMsg)
- {
- case WM_INITDIALOG:
- LocalizeDialog (hwndDlg, "IDD_INSTL_DLG");
-
- StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "SETUP_WIZARD_PAGE_%d", nCurPageNo);
- LastDialogId = PageDebugId;
-
- switch (nCurPageNo)
- {
- case INTRO_PAGE:
- {
- char *licenseText = NULL;
-
- licenseText = GetLegalNotices ();
- if (licenseText != NULL)
- {
- SetWindowTextA (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), licenseText);
- free (licenseText);
- }
- else
- {
- Error("CANNOT_DISPLAY_LICENSE", hwndDlg);
- exit (1);
- }
-
- /* For legal reasons, some of the following texts cannot be localized by third parties. */
-
- SetCheckBox (hwndDlg, IDC_AGREE, bLicenseAccepted);
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), L"Please read the license terms");
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), L"You must accept these license terms before you can use, extract, or install VeraCrypt.");
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), L"IMPORTANT: By checking the checkbox below, you accept these license terms and signify that you understand and agree to them. Please click the 'arrow down' icon to see the rest of the license."); // Cannot be localized by third parties (for legal reasons).
- //SendMessage (GetDlgItem (hwndDlg, IDC_BOX_HELP), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_AGREE), L"I &accept the license terms"); // Cannot be localized by third parties (for legal reasons).
- //SetWindowTextW (GetDlgItem (hwndDlg, IDC_DISAGREE), L"I &do not accept the license terms");
-
- //SendMessage (GetDlgItem (hwndDlg, IDC_AGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
- //SendMessage (GetDlgItem (hwndDlg, IDC_DISAGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_AGREE), TRUE);
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), bLicenseAccepted);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), bLicenseAccepted);
-
- // Left margin for license text
- SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), EM_SETMARGINS, (WPARAM) EC_LEFTMARGIN, (LPARAM) CompensateXDPI (4));
- }
- return 1;
-
- case WIZARD_MODE_PAGE:
- {
- LONG driverVersion;
-
- DetermineUpgradeDowngradeStatus (TRUE, &driverVersion);
-
- if (bRepairMode || bReinstallMode)
- {
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), GetString ("REPAIR_REINSTALL"));
- bExtractOnly = FALSE;
- }
- else if (bUpgrade)
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), GetString ("UPGRADE"));
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_MODE_TITLE"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_MODE_INFO"));
-
- SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
- SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
-
- CheckButton (GetDlgItem (hwndDlg, bExtractOnly ? IDC_WIZARD_MODE_EXTRACT_ONLY : IDC_WIZARD_MODE_INSTALL));
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SETUP_MODE_HELP_EXTRACT"));
-
- if (!bRepairMode)
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP2), GetString (bUpgrade ? "SETUP_MODE_HELP_UPGRADE" : "SETUP_MODE_HELP_INSTALL"));
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), !bRepairMode);
- EnableWindow (GetDlgItem (hwndDlg, IDC_BOX_HELP), !bRepairMode);
- EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), TRUE);
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
- }
- return 1;
-
- case EXTRACTION_OPTIONS_PAGE:
-
- if (wcslen(WizardDestExtractPath) < 2)
- {
- StringCbCopyW (WizardDestExtractPath, sizeof(WizardDestExtractPath), SetupFilesDir);
- StringCbCatNW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"VeraCrypt\\", ARRAYSIZE (WizardDestExtractPath) - wcslen (WizardDestExtractPath) - 1);
- }
-
- SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
-
- SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath);
-
- SetCheckBox (hwndDlg, IDC_OPEN_CONTAINING_FOLDER, bOpenContainingFolder);
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTION_OPTIONS_TITLE"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_OPTIONS_INFO"));
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("EXTRACT"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
-
- return 1;
-
- case EXTRACTION_PROGRESS_PAGE:
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTING_VERB"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_PROGRESS_INFO"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
-
- if (bStartExtraction)
- {
- /* Start extraction */
-
- LastDialogId = "EXTRACTION_IN_PROGRESS";
-
- WaitCursor ();
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
-
- if (WizardDestExtractPath [wcslen(WizardDestExtractPath)-1] != L'\\')
- StringCbCatW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"\\");
-
- StringCbCopyW (DestExtractPath, sizeof(DestExtractPath), WizardDestExtractPath);
-
- InitProgressBar ();
-
- bInProgress = TRUE;
- bStartExtraction = FALSE;
-
- _beginthread (ExtractAllFilesThread, 0, (void *) hwndDlg);
- }
- else
- {
- NormalCursor ();
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
- }
-
- return 1;
-
- case INSTALL_OPTIONS_PAGE:
- {
- LONG driverVersion;
-
- DetermineUpgradeDowngradeStatus (TRUE, &driverVersion);
-
- if (!bDesktopIconStatusDetermined)
- {
- bDesktopIcon = !bUpgrade;
- bDesktopIconStatusDetermined = TRUE;
- }
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_OPTIONS_TITLE"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_OPTIONS_INFO"));
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
-
- InitWizardDestInstallPath ();
-
- SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
-
- SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath);
-
- if (bUpgrade)
- {
- SetWindowTextW (GetDlgItem (hwndDlg, IDT_INSTALL_DESTINATION), GetString ("SETUP_UPGRADE_DESTINATION"));
- EnableWindow (GetDlgItem (hwndDlg, IDC_DESTINATION), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_ALL_USERS), FALSE);
-
- wchar_t path[MAX_PATH];
- SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
- bForAllUsers = (_waccess ((wstring (path) + L"\\" _T(TC_APP_NAME)).c_str(), 0) == 0);
- }
-
- // System Restore
- SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
- if (SystemRestoreDll == 0)
- {
- SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
- }
-
- SetCheckBox (hwndDlg, IDC_ALL_USERS, bForAllUsers);
- SetCheckBox (hwndDlg, IDC_FILE_TYPE, bRegisterFileExt);
- SetCheckBox (hwndDlg, IDC_PROG_GROUP, bAddToStartMenu);
- SetCheckBox (hwndDlg, IDC_DESKTOP_ICON, bDesktopIcon);
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString (bUpgrade ? "UPGRADE" : "INSTALL"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
- }
- return 1;
-
- case INSTALL_PROGRESS_PAGE:
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_PROGRESS_TITLE"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_PROGRESS_INFO"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
-
- if (bStartInstall)
- {
- /* Start install */
-
- LastDialogId = "INSTALL_IN_PROGRESS";
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
-
- InitProgressBar ();
-
- if (WizardDestInstallPath [wcslen(WizardDestInstallPath)-1] != L'\\')
- StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
-
- StringCbCopyW (InstallationPath, sizeof(InstallationPath), WizardDestInstallPath);
-
- WaitCursor ();
-
- bInProgress = TRUE;
- bStartInstall = FALSE;
-
- _beginthread (DoInstall, 0, (void *) hwndDlg);
- }
- else
- {
- NormalCursor ();
-
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
-
- }
-
- return 1;
-
- case DONATIONS_PAGE:
-
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bExtractOnly ? "EXTRACTION_FINISHED_TITLE_DON" : (bUpgrade ? "SETUP_FINISHED_UPGRADE_TITLE_DON" : "SETUP_FINISHED_TITLE_DON")));
- SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_FINISHED_INFO_DON"));
-
- DonText = L"Please consider making a donation.";
-
-
- // Colors
-
- switch (DonColorSchemeId)
- {
- case 2:
- // NOP - Default OS colors (foreground and background)
- break;
-
- case 3:
- // Red
- DonTextColor = RGB (255, 255, 255);
- DonBkgColor = RGB (255, 0, 0);
- break;
-
- case 4:
- // Yellow
- DonTextColor = RGB (255, 15, 49);
- DonBkgColor = RGB (255, 255, 0);
- break;
-
- case 5:
- // Light red
- DonTextColor = RGB (255, 255, 255);
- DonBkgColor = RGB (255, 141, 144);
- break;
-
- case 6:
- // Pink
- DonTextColor = RGB (255, 255, 255);
- DonBkgColor = RGB (248, 148, 207);
- break;
-
- case 7:
- // White + red text
- DonTextColor = RGB (255, 15, 49);
- DonBkgColor = RGB (255, 255, 255);
- break;
-
- case 8:
- // Blue
- DonTextColor = RGB (255, 255, 255);
- DonBkgColor = RGB (54, 140, 255);
- break;
-
- case 9:
- // Green
- DonTextColor = RGB (255, 255, 255);
- DonBkgColor = RGB (70, 180, 80);
- break;
- }
-
- {
- // Font
-
- LOGFONTW lf;
- memset (&lf, 0, sizeof(lf));
-
- // Main font
- StringCbCopyW (lf.lfFaceName, sizeof (lf.lfFaceName),L"Times New Roman");
- lf.lfHeight = CompensateDPIFont (-21);
- lf.lfWeight = FW_NORMAL;
- lf.lfWidth = 0;
- lf.lfEscapement = 0;
- lf.lfOrientation = 0;
- lf.lfItalic = FALSE;
- lf.lfUnderline = FALSE;
- lf.lfStrikeOut = FALSE;
- lf.lfCharSet = DEFAULT_CHARSET;
- lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
- lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
- lf.lfQuality = PROOF_QUALITY;
- lf.lfPitchAndFamily = FF_DONTCARE;
- hDonTextFont = CreateFontIndirectW (&lf);
-
- if (hDonTextFont == NULL)
- AbortProcessSilent ();
- }
-
- return 1;
- }
-
- return 0;
-
- case WM_HELP:
- if (bLicenseAccepted)
- OpenPageHelp (GetParent (hwndDlg), nCurPageNo);
-
- return 1;
-
- case WM_ENDSESSION:
-
- bPromptTutorial = FALSE;
- bPromptReleaseNotes = FALSE;
-
- EndDialog (MainDlg, 0);
- localcleanup ();
- return 0;
-
-
- case WM_COMMAND:
-
- if (lw == IDC_AGREE && nCurPageNo == INTRO_PAGE)
- {
- EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), IsButtonChecked (GetDlgItem (hwndDlg, IDC_AGREE)));
- return 1;
- }
-
- if (lw == IDC_WIZARD_MODE_EXTRACT_ONLY && nCurPageNo == WIZARD_MODE_PAGE)
- {
- bExtractOnly = TRUE;
- return 1;
- }
-
- if (lw == IDC_WIZARD_MODE_INSTALL && nCurPageNo == WIZARD_MODE_PAGE)
- {
- bExtractOnly = FALSE;
- return 1;
- }
-
- if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE && hw == EN_CHANGE )
- {
- EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1));
- return 1;
- }
-
- if ( nCurPageNo == INSTALL_OPTIONS_PAGE && hw == EN_CHANGE )
- {
- EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1));
- return 1;
- }
-
- if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE )
- {
- switch (lw)
- {
- case IDC_BROWSE:
- if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestExtractPath))
- {
- if (WizardDestExtractPath [wcslen(WizardDestExtractPath)-1] != L'\\')
- {
- StringCbCatW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"\\");
- }
- SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath);
- }
- return 1;
-
- case IDC_OPEN_CONTAINING_FOLDER:
- bOpenContainingFolder = IsButtonChecked (GetDlgItem (hCurPage, IDC_OPEN_CONTAINING_FOLDER));
- return 1;
- }
- }
-
- if ( nCurPageNo == INSTALL_OPTIONS_PAGE )
- {
- switch (lw)
- {
- case IDC_BROWSE:
- if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestInstallPath))
- {
- if (WizardDestInstallPath [wcslen(WizardDestInstallPath)-1] != L'\\')
- {
- StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
- }
- SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath);
- }
- return 1;
-
- case IDC_SYSTEM_RESTORE:
- bSystemRestore = IsButtonChecked (GetDlgItem (hCurPage, IDC_SYSTEM_RESTORE));
- return 1;
-
- case IDC_ALL_USERS:
- bForAllUsers = IsButtonChecked (GetDlgItem (hCurPage, IDC_ALL_USERS));
- return 1;
-
- case IDC_FILE_TYPE:
- bRegisterFileExt = IsButtonChecked (GetDlgItem (hCurPage, IDC_FILE_TYPE));
- return 1;
-
- case IDC_PROG_GROUP:
- bAddToStartMenu = IsButtonChecked (GetDlgItem (hCurPage, IDC_PROG_GROUP));
- return 1;
-
- case IDC_DESKTOP_ICON:
- bDesktopIcon = IsButtonChecked (GetDlgItem (hCurPage, IDC_DESKTOP_ICON));
- return 1;
-
- }
- }
-
- if (nCurPageNo == DONATIONS_PAGE)
- {
- switch (lw)
- {
- case IDC_DONATE:
- {
- char tmpstr [200];
-
- StringCbPrintfA (tmpstr, sizeof(tmpstr), "&ref=%d", DonColorSchemeId);
-
- Applink ("donate", FALSE, tmpstr);
- }
- return 1;
- }
- }
-
- return 0;
-
-
- case WM_PAINT:
-
- if (nCurPageNo == DONATIONS_PAGE)
- {
- PAINTSTRUCT tmpPaintStruct;
- HDC hdc = BeginPaint (hCurPage, &tmpPaintStruct);
-
- if (hdc == NULL)
- AbortProcessSilent ();
-
- SelectObject (hdc, hDonTextFont);
-
- if (DonColorSchemeId != 2)
- {
- HBRUSH tmpBrush = CreateSolidBrush (DonBkgColor);
-
- if (tmpBrush == NULL)
- AbortProcessSilent ();
-
- RECT trect;
-
- trect.left = 0;
- trect.right = CompensateXDPI (526);
- trect.top = 0;
- trect.bottom = CompensateYDPI (246);
-
- FillRect (hdc, &trect, tmpBrush);
-
- SetTextColor (hdc, DonTextColor);
- SetBkColor (hdc, DonBkgColor);
- }
-
- SetTextAlign(hdc, TA_CENTER);
-
- TextOutW (hdc,
- CompensateXDPI (258),
- CompensateYDPI (70),
- DonText.c_str(),
- DonText.length());
-
- EndPaint (hCurPage, &tmpPaintStruct);
- ReleaseDC (hCurPage, hdc);
- }
- return 0;
-
- }
-
- return 0;
-}
-
-void InitProgressBar (void)
-{
- HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
- SendMessage (hProgressBar, PBM_SETRANGE32, 0, 100);
- SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
- InvalidateRect (hProgressBar, NULL, TRUE);
-}
-
-// Must always return TRUE
-BOOL UpdateProgressBarProc (int nPercent)
-{
- HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
- SendMessage (hProgressBar, PBM_SETPOS, (int) (100.0 * nPercent / 100), 0);
- InvalidateRect (hProgressBar, NULL, TRUE);
- ShowWindow(hProgressBar, SW_HIDE);
- ShowWindow(hProgressBar, SW_SHOW);
- // Prevent the IDC_LOG_WINDOW item from partially disappearing at higher DPIs
- ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_HIDE);
- ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_SHOW);
- RefreshUIGFX();
- return TRUE;
-}
-
-void RefreshUIGFX (void)
-{
- InvalidateRect (GetDlgItem (MainDlg, IDC_SETUP_WIZARD_BKG), NULL, TRUE);
- InvalidateRect (GetDlgItem (MainDlg, IDC_BOX_TITLE), NULL, TRUE);
- InvalidateRect (GetDlgItem (MainDlg, IDC_BOX_INFO), NULL, TRUE);
- InvalidateRect (GetDlgItem (MainDlg, IDC_BITMAP_SETUP_WIZARD), NULL, TRUE);
- InvalidateRect (GetDlgItem (MainDlg, IDC_HR), NULL, TRUE);
- // Prevent these items from disappearing at higher DPIs
- ShowWindow(GetDlgItem(MainDlg, IDC_HR), SW_HIDE);
- ShowWindow(GetDlgItem(MainDlg, IDC_HR), SW_SHOW);
- ShowWindow(GetDlgItem(MainDlg, IDC_HR_BOTTOM), SW_HIDE);
- ShowWindow(GetDlgItem(MainDlg, IDC_HR_BOTTOM), SW_SHOW);
- ShowWindow(GetDlgItem(MainDlg, IDC_BOX_INFO), SW_HIDE);
- ShowWindow(GetDlgItem(MainDlg, IDC_BOX_INFO), SW_SHOW);
- ShowWindow(GetDlgItem(MainDlg, IDC_BOX_TITLE), SW_HIDE);
- ShowWindow(GetDlgItem(MainDlg, IDC_BOX_TITLE), SW_SHOW);
-}
-
-
-/* Except in response to the WM_INITDIALOG message, the dialog box procedure
- should return nonzero if it processes the message, and zero if it does
- not. - see DialogProc */
-BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- WORD lw = LOWORD (wParam);
-
- switch (uMsg)
- {
- case WM_INITDIALOG:
- {
- RECT rec;
-
- GetModuleFileName (NULL, SelfFile, ARRAYSIZE (SelfFile));
-
- MainDlg = hwndDlg;
-
- if (!CreateAppSetupMutex ())
- AbortProcess ("TC_INSTALLER_IS_RUNNING");
-
- InitDialog (hwndDlg);
- LocalizeDialog (hwndDlg, "IDD_INSTL_DLG");
-
- // Resize the bitmap if the user has a non-default DPI
- if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
- {
- hbmWizardBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_SETUP_WIZARD),
- GetDlgItem (hwndDlg, IDC_BITMAP_SETUP_WIZARD),
- 0, 0, 0, 0, FALSE, TRUE);
- }
-
- // Gfx area background (must not keep aspect ratio; must retain Windows-imposed distortion)
- GetClientRect (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_GFX_AREA), &rec);
- SetWindowPos (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_BKG), HWND_TOP, 0, 0, rec.right, rec.bottom, SWP_NOMOVE);
-
- nPbar = IDC_PROGRESS_BAR;
-
- SendMessage (GetDlgItem (hwndDlg, IDC_BOX_TITLE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
-
- SetWindowText (hwndDlg, L"VeraCrypt Setup " _T(VERSION_STRING));
-
- DonColorSchemeId = GetDonVal (2, 9);
-
- if (bDevm)
- {
- InitWizardDestInstallPath ();
- bSystemRestore = FALSE;
- bRegisterFileExt = FALSE;
- bAddToStartMenu = FALSE;
- bDesktopIcon = TRUE;
- bLicenseAccepted = TRUE;
- bStartInstall = TRUE;
- LoadPage (hwndDlg, INSTALL_PROGRESS_PAGE);
- }
- else
- LoadPage (hwndDlg, INTRO_PAGE);
-
- }
- return 0;
-
- case WM_SYSCOMMAND:
- if (lw == IDC_ABOUT)
- {
- if (bLicenseAccepted)
- DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
-
- return 1;
- }
- return 0;
-
- case WM_HELP:
- if (bLicenseAccepted)
- OpenPageHelp (hwndDlg, nCurPageNo);
-
- return 1;
-
-
- case WM_COMMAND:
- if (lw == IDHELP)
- {
- if (bLicenseAccepted)
- OpenPageHelp (hwndDlg, nCurPageNo);
-
- return 1;
- }
- if (lw == IDCANCEL)
- {
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
- return 1;
- }
- if (lw == IDC_NEXT)
- {
- if (nCurPageNo == INTRO_PAGE)
- {
- if (!IsButtonChecked (GetDlgItem (hCurPage, IDC_AGREE)))
- {
- bLicenseAccepted = FALSE;
- return 1;
- }
- bLicenseAccepted = TRUE;
- EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
-
- if (nCurrentOS == WIN_2000)
- {
- WarningDirect (L"Warning: Please note that this may be the last version of VeraCrypt that supports Windows 2000. If you want to be able to upgrade to future versions of VeraCrypt (which is highly recommended), you will need to upgrade to Windows XP or a later version of Windows.\n\nNote: Microsoft stopped issuing security updates for Windows 2000 to the general public on 7/13/2010 (the last non-security update for Windows 2000 was issued to the general public in 2005).", hwndDlg);
-
-
- HKEY hkey;
-
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates\\Windows 2000\\SP5\\Update Rollup 1", 0, KEY_READ, &hkey) != ERROR_SUCCESS)
- {
- ErrorDirect (L"VeraCrypt requires Update Rollup 1 for Windows 2000 SP4 to be installed.\n\nFor more information, see http://support.microsoft.com/kb/891861", hwndDlg);
- AbortProcessSilent ();
- }
-
- RegCloseKey (hkey);
- }
- }
-
- else if (nCurPageNo == WIZARD_MODE_PAGE)
- {
- if (IsButtonChecked (GetDlgItem (hCurPage, IDC_WIZARD_MODE_EXTRACT_ONLY)))
- {
- Info ("TRAVELER_LIMITATIONS_NOTE", hwndDlg);
-
- if (IsUacSupported()
- && AskWarnYesNo ("TRAVELER_UAC_NOTE", hwndDlg) == IDNO)
- {
- return 1;
- }
-
- bExtractOnly = TRUE;
- nCurPageNo = EXTRACTION_OPTIONS_PAGE - 1;
- }
- }
-
- else if (nCurPageNo == EXTRACTION_OPTIONS_PAGE)
- {
- GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestExtractPath, ARRAYSIZE (WizardDestExtractPath));
-
- bStartExtraction = TRUE;
- }
-
- else if (nCurPageNo == INSTALL_OPTIONS_PAGE)
- {
- GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestInstallPath, ARRAYSIZE (WizardDestInstallPath));
-
- bStartInstall = TRUE;
- }
-
- else if (nCurPageNo == INSTALL_PROGRESS_PAGE)
- {
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
- return 1;
- }
-
- else if (nCurPageNo == EXTRACTION_PROGRESS_PAGE)
- {
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
- return 1;
- }
-
- else if (nCurPageNo == DONATIONS_PAGE)
- {
- // 'Finish' button clicked
-
- PostMessage (hwndDlg, WM_CLOSE, 0, 0);
-
- return 1;
- }
-
- LoadPage (hwndDlg, ++nCurPageNo);
-
- return 1;
- }
-
- if (lw == IDC_PREV)
- {
- if (nCurPageNo == WIZARD_MODE_PAGE)
- {
- bExtractOnly = IsButtonChecked (GetDlgItem (hCurPage, IDC_WIZARD_MODE_EXTRACT_ONLY));
- }
-
- else if (nCurPageNo == EXTRACTION_OPTIONS_PAGE)
- {
- GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestExtractPath, ARRAYSIZE (WizardDestExtractPath));
- nCurPageNo = WIZARD_MODE_PAGE + 1;
- }
-
- else if (nCurPageNo == INSTALL_OPTIONS_PAGE)
- {
- GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestInstallPath, ARRAYSIZE (WizardDestInstallPath));
- }
-
- LoadPage (hwndDlg, --nCurPageNo);
-
- return 1;
- }
-
- return 0;
-
-
-
- case WM_PAINT:
-
- if (nCurPageNo == DONATIONS_PAGE && DonColorSchemeId != 2)
- {
- HWND hwndItem = GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS);
-
- PAINTSTRUCT tmpPaintStruct;
- HDC hdc = BeginPaint (hwndItem, &tmpPaintStruct);
-
- if (DonColorSchemeId != 2)
- {
- HBRUSH tmpBrush = CreateSolidBrush (DonBkgColor);
-
- RECT trect;
-
- trect.left = CompensateXDPI (1);
- trect.right = CompensateXDPI (560);
- trect.top = CompensateYDPI (DonColorSchemeId == 7 ? 11 : 0);
- trect.bottom = CompensateYDPI (260);
-
- FillRect (hdc, &trect, tmpBrush);
- }
-
- EndPaint(hwndItem, &tmpPaintStruct);
- ReleaseDC (hwndItem, hdc);
- }
- return 0;
-
-
-
- case WM_CTLCOLORSTATIC:
-
- if ((HWND) lParam != GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS))
- {
- /* This maintains the background under the transparent-backround texts. The above 'if' statement allows
- colored background to be erased automatically when leaving a page that uses it. */
-
- SetBkMode ((HDC) wParam, TRANSPARENT);
- return ((LONG) (HBRUSH) (GetStockObject (NULL_BRUSH)));
- }
-
-
- case WM_ERASEBKGND:
-
- return 0;
-
-
-
- case TC_APPMSG_INSTALL_SUCCESS:
-
- /* Installation completed successfully */
-
- bInProgress = FALSE;
-
- nCurPageNo = DONATIONS_PAGE;
- LoadPage (hwndDlg, DONATIONS_PAGE);
-
- NormalCursor ();
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (hwndDlg, IDHELP), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
-
-
- RefreshUIGFX ();
- return 1;
-
- case TC_APPMSG_INSTALL_FAILURE:
-
- /* Installation failed */
-
- bInProgress = FALSE;
-
- NormalCursor ();
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_TITLE), GetString ("INSTALL_FAILED"));
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_INFO), L"");
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDCANCEL), GetString ("IDCLOSE"));
- EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
-
- RefreshUIGFX();
-
- return 1;
-
- case TC_APPMSG_EXTRACTION_SUCCESS:
-
- /* Extraction completed successfully */
-
- UpdateProgressBarProc(100);
-
- bInProgress = FALSE;
- bExtractionSuccessful = TRUE;
-
- NormalCursor ();
-
- StatusMessage (hCurPage, "EXTRACTION_FINISHED_INFO");
-
- EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
- EnableWindow (GetDlgItem (hwndDlg, IDHELP), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
-
- RefreshUIGFX ();
-
- Info ("EXTRACTION_FINISHED_INFO", hwndDlg);
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
-
- nCurPageNo = DONATIONS_PAGE;
- LoadPage (hwndDlg, DONATIONS_PAGE);
-
- return 1;
-
- case TC_APPMSG_EXTRACTION_FAILURE:
-
- /* Extraction failed */
-
- bInProgress = FALSE;
-
- NormalCursor ();
-
- StatusMessage (hCurPage, "EXTRACTION_FAILED");
-
- UpdateProgressBarProc(0);
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_TITLE), GetString ("EXTRACTION_FAILED"));
- SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_INFO), L"");
-
- SetWindowTextW (GetDlgItem (hwndDlg, IDCANCEL), GetString ("IDCLOSE"));
- EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), FALSE);
- EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
-
- RefreshUIGFX();
-
- Error ("EXTRACTION_FAILED", hwndDlg);
-
- return 1;
-
- case WM_CLOSE:
-
- if (!bDevm)
- {
- if (bInProgress)
- {
- NormalCursor();
- if (AskNoYes("CONFIRM_EXIT_UNIVERSAL", hwndDlg) == IDNO)
- {
- return 1;
- }
- WaitCursor ();
- }
-
- if (bOpenContainingFolder && bExtractOnly && bExtractionSuccessful)
- {
- ShellExecute (NULL, L"open", WizardDestExtractPath, NULL, NULL, SW_SHOWNORMAL);
- }
- else
- {
- if (bPromptReleaseNotes
- && AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES", hwndDlg) == IDYES)
- {
- Applink ("releasenotes", TRUE, "");
- }
-
- bPromptReleaseNotes = FALSE;
-
- if (bPromptTutorial
- && AskYesNo ("AFTER_INSTALL_TUTORIAL", hwndDlg) == IDYES)
- {
- Applink ("beginnerstutorial", TRUE, "");
- }
-
- bPromptTutorial = FALSE;
- }
-
- if (bRestartRequired
- && AskYesNo (bUpgrade ? "UPGRADE_OK_REBOOT_REQUIRED" : "CONFIRM_RESTART", hwndDlg) == IDYES)
- {
- RestartComputer();
- }
- }
-
- EndDialog (hwndDlg, IDCANCEL);
- return 1;
- }
-
- return 0;
-}
-
-
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#include "Tcdefs.h"
+#include <Shlobj.h>
+#include <io.h>
+#include <stdio.h>
+#include <time.h>
+#include "SelfExtract.h"
+#include "Wizard.h"
+#include "Dlgcode.h"
+#include "Language.h"
+#include "Common/Resource.h"
+#include "Resource.h"
+#include "Setup.h"
+#include <tchar.h>
+#include <Strsafe.h>
+
+using namespace std;
+
+enum wizard_pages
+{
+ INTRO_PAGE,
+ WIZARD_MODE_PAGE,
+ INSTALL_OPTIONS_PAGE,
+ INSTALL_PROGRESS_PAGE,
+ EXTRACTION_OPTIONS_PAGE,
+ EXTRACTION_PROGRESS_PAGE,
+ DONATIONS_PAGE
+};
+
+HWND hCurPage = NULL; /* Handle to current wizard page */
+int nCurPageNo = -1; /* The current wizard page */
+wchar_t WizardDestInstallPath [TC_MAX_PATH];
+wchar_t WizardDestExtractPath [TC_MAX_PATH];
+wchar_t SelfFile [TC_MAX_PATH];
+
+HBITMAP hbmWizardBitmapRescaled = NULL;
+
+BOOL bExtractOnly = FALSE;
+BOOL bLicenseAccepted = FALSE;
+BOOL bOpenContainingFolder = TRUE;
+BOOL bExtractionSuccessful = FALSE;
+BOOL bStartInstall = FALSE;
+BOOL bStartExtraction = FALSE;
+BOOL bInProgress = FALSE;
+BOOL bPromptTutorial = FALSE;
+BOOL bPromptReleaseNotes = FALSE;
+
+int nPbar = 0; /* Control ID of progress bar */
+
+static HFONT hDonTextFont;
+static BOOL OsPrngAvailable;
+static HCRYPTPROV hCryptProv;
+static int DonColorSchemeId;
+static COLORREF DonTextColor;
+static COLORREF DonBkgColor;
+
+wstring DonText = L"";
+
+void localcleanupwiz (void)
+{
+ /* Delete buffered bitmaps (if any) */
+ if (hbmWizardBitmapRescaled != NULL)
+ {
+ DeleteObject ((HGDIOBJ) hbmWizardBitmapRescaled);
+ hbmWizardBitmapRescaled = NULL;
+ }
+
+ if (hCryptProv != 0)
+ {
+ OsPrngAvailable = FALSE;
+ CryptReleaseContext (hCryptProv, 0);
+ hCryptProv = 0;
+ }
+
+ if (hDonTextFont != NULL)
+ {
+ DeleteObject (hDonTextFont);
+ hDonTextFont = NULL;
+ }
+}
+
+static void InitWizardDestInstallPath (void)
+{
+ if (wcslen (WizardDestInstallPath) < 2)
+ {
+ StringCbCopyW (WizardDestInstallPath, sizeof(WizardDestInstallPath), InstallationPath);
+ if (WizardDestInstallPath [wcslen (WizardDestInstallPath) - 1] != L'\\')
+ {
+ StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
+ }
+ }
+}
+
+void LoadPage (HWND hwndDlg, int nPageNo)
+{
+ RECT rD, rW;
+
+ if (hCurPage != NULL)
+ {
+ DestroyWindow (hCurPage);
+ }
+
+ InvalidateRect (GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS), NULL, TRUE);
+
+ GetWindowRect (GetDlgItem (hwndDlg, IDC_POS_BOX), &rW);
+
+ nCurPageNo = nPageNo;
+
+ switch (nPageNo)
+ {
+ case INTRO_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INTRO_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case WIZARD_MODE_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_WIZARD_MODE_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case INSTALL_OPTIONS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_INSTALL_OPTIONS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case INSTALL_PROGRESS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case EXTRACTION_OPTIONS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_EXTRACTION_OPTIONS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case EXTRACTION_PROGRESS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_PROGRESS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+
+ case DONATIONS_PAGE:
+ hCurPage = CreateDialogW (hInst, MAKEINTRESOURCEW (IDD_DONATIONS_PAGE_DLG), hwndDlg,
+ (DLGPROC) PageDialogProc);
+ break;
+ }
+
+ rD.left = 15;
+ rD.top = 45;
+ rD.right = 0;
+ rD.bottom = 0;
+ MapDialogRect (hwndDlg, &rD);
+
+ if (hCurPage != NULL)
+ {
+ MoveWindow (hCurPage, rD.left, rD.top, rW.right - rW.left, rW.bottom - rW.top, TRUE);
+ ShowWindow (hCurPage, SW_SHOWNORMAL);
+ }
+
+ /* Refresh the graphics (white background of some texts, etc.) */
+ RefreshUIGFX ();
+}
+
+
+static int GetDonVal (int minVal, int maxVal)
+{
+ static BOOL prngInitialized = FALSE;
+ static unsigned __int8 buffer [2];
+
+ if (!prngInitialized)
+ {
+ if (!CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)
+ && !CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
+ OsPrngAvailable = FALSE;
+ else
+ OsPrngAvailable = TRUE;
+
+ srand ((unsigned int) time (NULL));
+ rand(); // Generate and discard the inital value, as it always appears to be somewhat non-random.
+
+ prngInitialized = TRUE;
+ }
+
+ if (OsPrngAvailable && CryptGenRandom (hCryptProv, sizeof (buffer), buffer) != 0)
+ {
+ return ((int) ((double) *((uint16 *) buffer) / (0xFFFF+1) * (maxVal + 1 - minVal)) + minVal);
+ }
+ else
+ return ((int) ((double) rand() / (RAND_MAX+1) * (maxVal + 1 - minVal)) + minVal);
+}
+
+
+/* Except in response to the WM_INITDIALOG message, the dialog box procedure
+ should return nonzero if it processes the message, and zero if it does
+ not. - see DialogProc */
+BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static char PageDebugId[128];
+ WORD lw = LOWORD (wParam);
+ WORD hw = HIWORD (wParam);
+
+ hCurPage = hwndDlg;
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ LocalizeDialog (hwndDlg, "IDD_INSTL_DLG");
+
+ StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "SETUP_WIZARD_PAGE_%d", nCurPageNo);
+ LastDialogId = PageDebugId;
+
+ switch (nCurPageNo)
+ {
+ case INTRO_PAGE:
+ {
+ char *licenseText = NULL;
+
+ licenseText = GetLegalNotices ();
+ if (licenseText != NULL)
+ {
+ SetWindowTextA (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), licenseText);
+ free (licenseText);
+ }
+ else
+ {
+ Error("CANNOT_DISPLAY_LICENSE", hwndDlg);
+ exit (1);
+ }
+
+ /* For legal reasons, some of the following texts cannot be localized by third parties. */
+
+ SetCheckBox (hwndDlg, IDC_AGREE, bLicenseAccepted);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), L"Please read the license terms");
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), L"You must accept these license terms before you can use, extract, or install VeraCrypt.");
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), L"IMPORTANT: By checking the checkbox below, you accept these license terms and signify that you understand and agree to them. Please click the 'arrow down' icon to see the rest of the license."); // Cannot be localized by third parties (for legal reasons).
+ //SendMessage (GetDlgItem (hwndDlg, IDC_BOX_HELP), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_AGREE), L"I &accept the license terms"); // Cannot be localized by third parties (for legal reasons).
+ //SetWindowTextW (GetDlgItem (hwndDlg, IDC_DISAGREE), L"I &do not accept the license terms");
+
+ //SendMessage (GetDlgItem (hwndDlg, IDC_AGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ //SendMessage (GetDlgItem (hwndDlg, IDC_DISAGREE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_AGREE), TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), bLicenseAccepted);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), bLicenseAccepted);
+
+ // Left margin for license text
+ SendMessage (GetDlgItem (hwndDlg, IDC_LICENSE_TEXT), EM_SETMARGINS, (WPARAM) EC_LEFTMARGIN, (LPARAM) CompensateXDPI (4));
+ }
+ return 1;
+
+ case WIZARD_MODE_PAGE:
+ {
+ LONG driverVersion;
+
+ DetermineUpgradeDowngradeStatus (TRUE, &driverVersion);
+
+ if (bRepairMode || bReinstallMode)
+ {
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), GetString ("REPAIR_REINSTALL"));
+ bExtractOnly = FALSE;
+ }
+ else if (bUpgrade)
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), GetString ("UPGRADE"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_MODE_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_MODE_INFO"));
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+ SendMessage (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ CheckButton (GetDlgItem (hwndDlg, bExtractOnly ? IDC_WIZARD_MODE_EXTRACT_ONLY : IDC_WIZARD_MODE_INSTALL));
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("SETUP_MODE_HELP_EXTRACT"));
+
+ if (!bRepairMode)
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP2), GetString (bUpgrade ? "SETUP_MODE_HELP_UPGRADE" : "SETUP_MODE_HELP_INSTALL"));
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_EXTRACT_ONLY), !bRepairMode);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_BOX_HELP), !bRepairMode);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_WIZARD_MODE_INSTALL), TRUE);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDCANCEL), GetString ("CANCEL"));
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ }
+ return 1;
+
+ case EXTRACTION_OPTIONS_PAGE:
+
+ if (wcslen(WizardDestExtractPath) < 2)
+ {
+ StringCbCopyW (WizardDestExtractPath, sizeof(WizardDestExtractPath), SetupFilesDir);
+ StringCbCatNW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"VeraCrypt\\", ARRAYSIZE (WizardDestExtractPath) - wcslen (WizardDestExtractPath) - 1);
+ }
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
+
+ SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath);
+
+ SetCheckBox (hwndDlg, IDC_OPEN_CONTAINING_FOLDER, bOpenContainingFolder);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTION_OPTIONS_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_OPTIONS_INFO"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("EXTRACT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+
+ return 1;
+
+ case EXTRACTION_PROGRESS_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("EXTRACTING_VERB"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("EXTRACTION_PROGRESS_INFO"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+
+ if (bStartExtraction)
+ {
+ /* Start extraction */
+
+ LastDialogId = "EXTRACTION_IN_PROGRESS";
+
+ WaitCursor ();
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
+
+ if (WizardDestExtractPath [wcslen(WizardDestExtractPath)-1] != L'\\')
+ StringCbCatW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"\\");
+
+ StringCbCopyW (DestExtractPath, sizeof(DestExtractPath), WizardDestExtractPath);
+
+ InitProgressBar ();
+
+ bInProgress = TRUE;
+ bStartExtraction = FALSE;
+
+ _beginthread (ExtractAllFilesThread, 0, (void *) hwndDlg);
+ }
+ else
+ {
+ NormalCursor ();
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ }
+
+ return 1;
+
+ case INSTALL_OPTIONS_PAGE:
+ {
+ LONG driverVersion;
+
+ DetermineUpgradeDowngradeStatus (TRUE, &driverVersion);
+
+ if (!bDesktopIconStatusDetermined)
+ {
+ bDesktopIcon = !bUpgrade;
+ bDesktopIconStatusDetermined = TRUE;
+ }
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_OPTIONS_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_OPTIONS_INFO"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), GetString ("AUTO_FOLDER_CREATION"));
+
+ InitWizardDestInstallPath ();
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_DESTINATION), EM_LIMITTEXT, TC_MAX_PATH - 1, 0);
+
+ SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath);
+
+ if (bUpgrade)
+ {
+ SetWindowTextW (GetDlgItem (hwndDlg, IDT_INSTALL_DESTINATION), GetString ("SETUP_UPGRADE_DESTINATION"));
+ EnableWindow (GetDlgItem (hwndDlg, IDC_DESTINATION), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_ALL_USERS), FALSE);
+
+ wchar_t path[MAX_PATH];
+ SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
+ bForAllUsers = (_waccess ((wstring (path) + L"\\" _T(TC_APP_NAME)).c_str(), 0) == 0);
+ }
+
+ // System Restore
+ SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
+ if (SystemRestoreDll == 0)
+ {
+ SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
+ }
+
+ SetCheckBox (hwndDlg, IDC_ALL_USERS, bForAllUsers);
+ SetCheckBox (hwndDlg, IDC_FILE_TYPE, bRegisterFileExt);
+ SetCheckBox (hwndDlg, IDC_PROG_GROUP, bAddToStartMenu);
+ SetCheckBox (hwndDlg, IDC_DESKTOP_ICON, bDesktopIcon);
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString (bUpgrade ? "UPGRADE" : "INSTALL"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+ }
+ return 1;
+
+ case INSTALL_PROGRESS_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("SETUP_PROGRESS_TITLE"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_PROGRESS_INFO"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
+
+ if (bStartInstall)
+ {
+ /* Start install */
+
+ LastDialogId = "INSTALL_IN_PROGRESS";
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), FALSE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), FALSE);
+
+ InitProgressBar ();
+
+ if (WizardDestInstallPath [wcslen(WizardDestInstallPath)-1] != L'\\')
+ StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
+
+ StringCbCopyW (InstallationPath, sizeof(InstallationPath), WizardDestInstallPath);
+
+ WaitCursor ();
+
+ bInProgress = TRUE;
+ bStartInstall = FALSE;
+
+ _beginthread (DoInstall, 0, (void *) hwndDlg);
+ }
+ else
+ {
+ NormalCursor ();
+
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_PREV), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDHELP), TRUE);
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDCANCEL), TRUE);
+
+ }
+
+ return 1;
+
+ case DONATIONS_PAGE:
+
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString (bExtractOnly ? "EXTRACTION_FINISHED_TITLE_DON" : (bUpgrade ? "SETUP_FINISHED_UPGRADE_TITLE_DON" : "SETUP_FINISHED_TITLE_DON")));
+ SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_INFO), GetString ("SETUP_FINISHED_INFO_DON"));
+
+ DonText = L"Please consider making a donation.";
+
+
+ // Colors
+
+ switch (DonColorSchemeId)
+ {
+ case 2:
+ // NOP - Default OS colors (foreground and background)
+ break;
+
+ case 3:
+ // Red
+ DonTextColor = RGB (255, 255, 255);
+ DonBkgColor = RGB (255, 0, 0);
+ break;
+
+ case 4:
+ // Yellow
+ DonTextColor = RGB (255, 15, 49);
+ DonBkgColor = RGB (255, 255, 0);
+ break;
+
+ case 5:
+ // Light red
+ DonTextColor = RGB (255, 255, 255);
+ DonBkgColor = RGB (255, 141, 144);
+ break;
+
+ case 6:
+ // Pink
+ DonTextColor = RGB (255, 255, 255);
+ DonBkgColor = RGB (248, 148, 207);
+ break;
+
+ case 7:
+ // White + red text
+ DonTextColor = RGB (255, 15, 49);
+ DonBkgColor = RGB (255, 255, 255);
+ break;
+
+ case 8:
+ // Blue
+ DonTextColor = RGB (255, 255, 255);
+ DonBkgColor = RGB (54, 140, 255);
+ break;
+
+ case 9:
+ // Green
+ DonTextColor = RGB (255, 255, 255);
+ DonBkgColor = RGB (70, 180, 80);
+ break;
+ }
+
+ {
+ // Font
+
+ LOGFONTW lf;
+ memset (&lf, 0, sizeof(lf));
+
+ // Main font
+ StringCbCopyW (lf.lfFaceName, sizeof (lf.lfFaceName),L"Times New Roman");
+ lf.lfHeight = CompensateDPIFont (-21);
+ lf.lfWeight = FW_NORMAL;
+ lf.lfWidth = 0;
+ lf.lfEscapement = 0;
+ lf.lfOrientation = 0;
+ lf.lfItalic = FALSE;
+ lf.lfUnderline = FALSE;
+ lf.lfStrikeOut = FALSE;
+ lf.lfCharSet = DEFAULT_CHARSET;
+ lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
+ lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ lf.lfQuality = PROOF_QUALITY;
+ lf.lfPitchAndFamily = FF_DONTCARE;
+ hDonTextFont = CreateFontIndirectW (&lf);
+
+ if (hDonTextFont == NULL)
+ AbortProcessSilent ();
+ }
+
+ return 1;
+ }
+
+ return 0;
+
+ case WM_HELP:
+ if (bLicenseAccepted)
+ OpenPageHelp (GetParent (hwndDlg), nCurPageNo);
+
+ return 1;
+
+ case WM_ENDSESSION:
+
+ bPromptTutorial = FALSE;
+ bPromptReleaseNotes = FALSE;
+
+ EndDialog (MainDlg, 0);
+ localcleanup ();
+ return 0;
+
+
+ case WM_COMMAND:
+
+ if (lw == IDC_AGREE && nCurPageNo == INTRO_PAGE)
+ {
+ EnableWindow (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), IsButtonChecked (GetDlgItem (hwndDlg, IDC_AGREE)));
+ return 1;
+ }
+
+ if (lw == IDC_WIZARD_MODE_EXTRACT_ONLY && nCurPageNo == WIZARD_MODE_PAGE)
+ {
+ bExtractOnly = TRUE;
+ return 1;
+ }
+
+ if (lw == IDC_WIZARD_MODE_INSTALL && nCurPageNo == WIZARD_MODE_PAGE)
+ {
+ bExtractOnly = FALSE;
+ return 1;
+ }
+
+ if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE && hw == EN_CHANGE )
+ {
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1));
+ return 1;
+ }
+
+ if ( nCurPageNo == INSTALL_OPTIONS_PAGE && hw == EN_CHANGE )
+ {
+ EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hCurPage, IDC_DESTINATION)) > 1));
+ return 1;
+ }
+
+ if ( nCurPageNo == EXTRACTION_OPTIONS_PAGE )
+ {
+ switch (lw)
+ {
+ case IDC_BROWSE:
+ if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestExtractPath))
+ {
+ if (WizardDestExtractPath [wcslen(WizardDestExtractPath)-1] != L'\\')
+ {
+ StringCbCatW (WizardDestExtractPath, sizeof(WizardDestExtractPath), L"\\");
+ }
+ SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestExtractPath);
+ }
+ return 1;
+
+ case IDC_OPEN_CONTAINING_FOLDER:
+ bOpenContainingFolder = IsButtonChecked (GetDlgItem (hCurPage, IDC_OPEN_CONTAINING_FOLDER));
+ return 1;
+ }
+ }
+
+ if ( nCurPageNo == INSTALL_OPTIONS_PAGE )
+ {
+ switch (lw)
+ {
+ case IDC_BROWSE:
+ if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", WizardDestInstallPath))
+ {
+ if (WizardDestInstallPath [wcslen(WizardDestInstallPath)-1] != L'\\')
+ {
+ StringCbCatW (WizardDestInstallPath, sizeof(WizardDestInstallPath), L"\\");
+ }
+ SetDlgItemText (hwndDlg, IDC_DESTINATION, WizardDestInstallPath);
+ }
+ return 1;
+
+ case IDC_SYSTEM_RESTORE:
+ bSystemRestore = IsButtonChecked (GetDlgItem (hCurPage, IDC_SYSTEM_RESTORE));
+ return 1;
+
+ case IDC_ALL_USERS:
+ bForAllUsers = IsButtonChecked (GetDlgItem (hCurPage, IDC_ALL_USERS));
+ return 1;
+
+ case IDC_FILE_TYPE:
+ bRegisterFileExt = IsButtonChecked (GetDlgItem (hCurPage, IDC_FILE_TYPE));
+ return 1;
+
+ case IDC_PROG_GROUP:
+ bAddToStartMenu = IsButtonChecked (GetDlgItem (hCurPage, IDC_PROG_GROUP));
+ return 1;
+
+ case IDC_DESKTOP_ICON:
+ bDesktopIcon = IsButtonChecked (GetDlgItem (hCurPage, IDC_DESKTOP_ICON));
+ return 1;
+
+ }
+ }
+
+ if (nCurPageNo == DONATIONS_PAGE)
+ {
+ switch (lw)
+ {
+ case IDC_DONATE:
+ {
+ char tmpstr [200];
+
+ StringCbPrintfA (tmpstr, sizeof(tmpstr), "&ref=%d", DonColorSchemeId);
+
+ Applink ("donate", FALSE, tmpstr);
+ }
+ return 1;
+ }
+ }
+
+ return 0;
+
+
+ case WM_PAINT:
+
+ if (nCurPageNo == DONATIONS_PAGE)
+ {
+ PAINTSTRUCT tmpPaintStruct;
+ HDC hdc = BeginPaint (hCurPage, &tmpPaintStruct);
+
+ if (hdc == NULL)
+ AbortProcessSilent ();
+
+ SelectObject (hdc, hDonTextFont);
+
+ if (DonColorSchemeId != 2)
+ {
+ HBRUSH tmpBrush = CreateSolidBrush (DonBkgColor);
+
+ if (tmpBrush == NULL)
+ AbortProcessSilent ();
+
+ RECT trect;
+
+ trect.left = 0;
+ trect.right = CompensateXDPI (526);
+ trect.top = 0;
+ trect.bottom = CompensateYDPI (246);
+
+ FillRect (hdc, &trect, tmpBrush);
+
+ SetTextColor (hdc, DonTextColor);
+ SetBkColor (hdc, DonBkgColor);
+ }
+
+ SetTextAlign(hdc, TA_CENTER);
+
+ TextOutW (hdc,
+ CompensateXDPI (258),
+ CompensateYDPI (70),
+ DonText.c_str(),
+ DonText.length());
+
+ EndPaint (hCurPage, &tmpPaintStruct);
+ ReleaseDC (hCurPage, hdc);
+ }
+ return 0;
+
+ }
+
+ return 0;
+}
+
+void InitProgressBar (void)
+{
+ HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
+ SendMessage (hProgressBar, PBM_SETRANGE32, 0, 100);
+ SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
+ InvalidateRect (hProgressBar, NULL, TRUE);
+}
+
+// Must always return TRUE
+BOOL UpdateProgressBarProc (int nPercent)
+{
+ HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
+ SendMessage (hProgressBar, PBM_SETPOS, (int) (100.0 * nPercent / 100), 0);
+ InvalidateRect (hProgressBar, NULL, TRUE);
+ ShowWindow(hProgressBar, SW_HIDE);
+ ShowWindow(hProgressBar, SW_SHOW);
+ // Prevent the IDC_LOG_WINDOW item from partially disappearing at higher DPIs
+ ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_HIDE);
+ ShowWindow(GetDlgItem (hCurPage, IDC_LOG_WINDOW), SW_SHOW);
+ RefreshUIGFX();
+ return TRUE;
+}
+
+void RefreshUIGFX (void)
+{
+ InvalidateRect (GetDlgItem (MainDlg, IDC_SETUP_WIZARD_BKG), NULL, TRUE);
+ InvalidateRect (GetDlgItem (MainDlg, IDC_BOX_TITLE), NULL, TRUE);
+ InvalidateRect (GetDlgItem (MainDlg, IDC_BOX_INFO), NULL, TRUE);
+ InvalidateRect (GetDlgItem (MainDlg, IDC_BITMAP_SETUP_WIZARD), NULL, TRUE);
+ InvalidateRect (GetDlgItem (MainDlg, IDC_HR), NULL, TRUE);
+ // Prevent these items from disappearing at higher DPIs
+ ShowWindow(GetDlgItem(MainDlg, IDC_HR), SW_HIDE);
+ ShowWindow(GetDlgItem(MainDlg, IDC_HR), SW_SHOW);
+ ShowWindow(GetDlgItem(MainDlg, IDC_HR_BOTTOM), SW_HIDE);
+ ShowWindow(GetDlgItem(MainDlg, IDC_HR_BOTTOM), SW_SHOW);
+ ShowWindow(GetDlgItem(MainDlg, IDC_BOX_INFO), SW_HIDE);
+ ShowWindow(GetDlgItem(MainDlg, IDC_BOX_INFO), SW_SHOW);
+ ShowWindow(GetDlgItem(MainDlg, IDC_BOX_TITLE), SW_HIDE);
+ ShowWindow(GetDlgItem(MainDlg, IDC_BOX_TITLE), SW_SHOW);
+}
+
+
+/* Except in response to the WM_INITDIALOG message, the dialog box procedure
+ should return nonzero if it processes the message, and zero if it does
+ not. - see DialogProc */
+BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ WORD lw = LOWORD (wParam);
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ {
+ RECT rec;
+
+ GetModuleFileName (NULL, SelfFile, ARRAYSIZE (SelfFile));
+
+ MainDlg = hwndDlg;
+
+ if (!CreateAppSetupMutex ())
+ AbortProcess ("TC_INSTALLER_IS_RUNNING");
+
+ InitDialog (hwndDlg);
+ LocalizeDialog (hwndDlg, "IDD_INSTL_DLG");
+
+ // Resize the bitmap if the user has a non-default DPI
+ if (ScreenDPI != USER_DEFAULT_SCREEN_DPI)
+ {
+ hbmWizardBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_SETUP_WIZARD),
+ GetDlgItem (hwndDlg, IDC_BITMAP_SETUP_WIZARD),
+ 0, 0, 0, 0, FALSE, TRUE);
+ }
+
+ // Gfx area background (must not keep aspect ratio; must retain Windows-imposed distortion)
+ GetClientRect (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_GFX_AREA), &rec);
+ SetWindowPos (GetDlgItem (hwndDlg, IDC_SETUP_WIZARD_BKG), HWND_TOP, 0, 0, rec.right, rec.bottom, SWP_NOMOVE);
+
+ nPbar = IDC_PROGRESS_BAR;
+
+ SendMessage (GetDlgItem (hwndDlg, IDC_BOX_TITLE), WM_SETFONT, (WPARAM) hUserBoldFont, (LPARAM) TRUE);
+
+ SetWindowText (hwndDlg, L"VeraCrypt Setup " _T(VERSION_STRING));
+
+ DonColorSchemeId = GetDonVal (2, 9);
+
+ if (bDevm)
+ {
+ InitWizardDestInstallPath ();
+ bSystemRestore = FALSE;
+ bRegisterFileExt = FALSE;
+ bAddToStartMenu = FALSE;
+ bDesktopIcon = TRUE;
+ bLicenseAccepted = TRUE;
+ bStartInstall = TRUE;
+ LoadPage (hwndDlg, INSTALL_PROGRESS_PAGE);
+ }
+ else
+ LoadPage (hwndDlg, INTRO_PAGE);
+
+ }
+ return 0;
+
+ case WM_SYSCOMMAND:
+ if (lw == IDC_ABOUT)
+ {
+ if (bLicenseAccepted)
+ DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
+
+ return 1;
+ }
+ return 0;
+
+ case WM_HELP:
+ if (bLicenseAccepted)
+ OpenPageHelp (hwndDlg, nCurPageNo);
+
+ return 1;
+
+
+ case WM_COMMAND:
+ if (lw == IDHELP)
+ {
+ if (bLicenseAccepted)
+ OpenPageHelp (hwndDlg, nCurPageNo);
+
+ return 1;
+ }
+ if (lw == IDCANCEL)
+ {
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+ return 1;
+ }
+ if (lw == IDC_NEXT)
+ {
+ if (nCurPageNo == INTRO_PAGE)
+ {
+ if (!IsButtonChecked (GetDlgItem (hCurPage, IDC_AGREE)))
+ {
+ bLicenseAccepted = FALSE;
+ return 1;
+ }
+ bLicenseAccepted = TRUE;
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
+
+ if (nCurrentOS == WIN_2000)
+ {
+ WarningDirect (L"Warning: Please note that this may be the last version of VeraCrypt that supports Windows 2000. If you want to be able to upgrade to future versions of VeraCrypt (which is highly recommended), you will need to upgrade to Windows XP or a later version of Windows.\n\nNote: Microsoft stopped issuing security updates for Windows 2000 to the general public on 7/13/2010 (the last non-security update for Windows 2000 was issued to the general public in 2005).", hwndDlg);
+
+
+ HKEY hkey;
+
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates\\Windows 2000\\SP5\\Update Rollup 1", 0, KEY_READ, &hkey) != ERROR_SUCCESS)
+ {
+ ErrorDirect (L"VeraCrypt requires Update Rollup 1 for Windows 2000 SP4 to be installed.\n\nFor more information, see http://support.microsoft.com/kb/891861", hwndDlg);
+ AbortProcessSilent ();
+ }
+
+ RegCloseKey (hkey);
+ }
+ }
+
+ else if (nCurPageNo == WIZARD_MODE_PAGE)
+ {
+ if (IsButtonChecked (GetDlgItem (hCurPage, IDC_WIZARD_MODE_EXTRACT_ONLY)))
+ {
+ Info ("TRAVELER_LIMITATIONS_NOTE", hwndDlg);
+
+ if (IsUacSupported()
+ && AskWarnYesNo ("TRAVELER_UAC_NOTE", hwndDlg) == IDNO)
+ {
+ return 1;
+ }
+
+ bExtractOnly = TRUE;
+ nCurPageNo = EXTRACTION_OPTIONS_PAGE - 1;
+ }
+ }
+
+ else if (nCurPageNo == EXTRACTION_OPTIONS_PAGE)
+ {
+ GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestExtractPath, ARRAYSIZE (WizardDestExtractPath));
+
+ bStartExtraction = TRUE;
+ }
+
+ else if (nCurPageNo == INSTALL_OPTIONS_PAGE)
+ {
+ GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestInstallPath, ARRAYSIZE (WizardDestInstallPath));
+
+ bStartInstall = TRUE;
+ }
+
+ else if (nCurPageNo == INSTALL_PROGRESS_PAGE)
+ {
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+ return 1;
+ }
+
+ else if (nCurPageNo == EXTRACTION_PROGRESS_PAGE)
+ {
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+ return 1;
+ }
+
+ else if (nCurPageNo == DONATIONS_PAGE)
+ {
+ // 'Finish' button clicked
+
+ PostMessage (hwndDlg, WM_CLOSE, 0, 0);
+
+ return 1;
+ }
+
+ LoadPage (hwndDlg, ++nCurPageNo);
+
+ return 1;
+ }
+
+ if (lw == IDC_PREV)
+ {
+ if (nCurPageNo == WIZARD_MODE_PAGE)
+ {
+ bExtractOnly = IsButtonChecked (GetDlgItem (hCurPage, IDC_WIZARD_MODE_EXTRACT_ONLY));
+ }
+
+ else if (nCurPageNo == EXTRACTION_OPTIONS_PAGE)
+ {
+ GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestExtractPath, ARRAYSIZE (WizardDestExtractPath));
+ nCurPageNo = WIZARD_MODE_PAGE + 1;
+ }
+
+ else if (nCurPageNo == INSTALL_OPTIONS_PAGE)
+ {
+ GetWindowText (GetDlgItem (hCurPage, IDC_DESTINATION), WizardDestInstallPath, ARRAYSIZE (WizardDestInstallPath));
+ }
+
+ LoadPage (hwndDlg, --nCurPageNo);
+
+ return 1;
+ }
+
+ return 0;
+
+
+
+ case WM_PAINT:
+
+ if (nCurPageNo == DONATIONS_PAGE && DonColorSchemeId != 2)
+ {
+ HWND hwndItem = GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS);
+
+ PAINTSTRUCT tmpPaintStruct;
+ HDC hdc = BeginPaint (hwndItem, &tmpPaintStruct);
+
+ if (DonColorSchemeId != 2)
+ {
+ HBRUSH tmpBrush = CreateSolidBrush (DonBkgColor);
+
+ RECT trect;
+
+ trect.left = CompensateXDPI (1);
+ trect.right = CompensateXDPI (560);
+ trect.top = CompensateYDPI (DonColorSchemeId == 7 ? 11 : 0);
+ trect.bottom = CompensateYDPI (260);
+
+ FillRect (hdc, &trect, tmpBrush);
+ }
+
+ EndPaint(hwndItem, &tmpPaintStruct);
+ ReleaseDC (hwndItem, hdc);
+ }
+ return 0;
+
+
+
+ case WM_CTLCOLORSTATIC:
+
+ if ((HWND) lParam != GetDlgItem (MainDlg, IDC_MAIN_CONTENT_CANVAS))
+ {
+ /* This maintains the background under the transparent-backround texts. The above 'if' statement allows
+ colored background to be erased automatically when leaving a page that uses it. */
+
+ SetBkMode ((HDC) wParam, TRANSPARENT);
+ return ((LONG) (HBRUSH) (GetStockObject (NULL_BRUSH)));
+ }
+
+
+ case WM_ERASEBKGND:
+
+ return 0;
+
+
+
+ case TC_APPMSG_INSTALL_SUCCESS:
+
+ /* Installation completed successfully */
+
+ bInProgress = FALSE;
+
+ nCurPageNo = DONATIONS_PAGE;
+ LoadPage (hwndDlg, DONATIONS_PAGE);
+
+ NormalCursor ();
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+
+
+ RefreshUIGFX ();
+ return 1;
+
+ case TC_APPMSG_INSTALL_FAILURE:
+
+ /* Installation failed */
+
+ bInProgress = FALSE;
+
+ NormalCursor ();
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_TITLE), GetString ("INSTALL_FAILED"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_INFO), L"");
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDCANCEL), GetString ("IDCLOSE"));
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
+
+ RefreshUIGFX();
+
+ return 1;
+
+ case TC_APPMSG_EXTRACTION_SUCCESS:
+
+ /* Extraction completed successfully */
+
+ UpdateProgressBarProc(100);
+
+ bInProgress = FALSE;
+ bExtractionSuccessful = TRUE;
+
+ NormalCursor ();
+
+ StatusMessage (hCurPage, "EXTRACTION_FINISHED_INFO");
+
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
+
+ RefreshUIGFX ();
+
+ Info ("EXTRACTION_FINISHED_INFO", hwndDlg);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_NEXT), GetString ("FINALIZE"));
+
+ nCurPageNo = DONATIONS_PAGE;
+ LoadPage (hwndDlg, DONATIONS_PAGE);
+
+ return 1;
+
+ case TC_APPMSG_EXTRACTION_FAILURE:
+
+ /* Extraction failed */
+
+ bInProgress = FALSE;
+
+ NormalCursor ();
+
+ StatusMessage (hCurPage, "EXTRACTION_FAILED");
+
+ UpdateProgressBarProc(0);
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_TITLE), GetString ("EXTRACTION_FAILED"));
+ SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_INFO), L"");
+
+ SetWindowTextW (GetDlgItem (hwndDlg, IDCANCEL), GetString ("IDCLOSE"));
+ EnableWindow (GetDlgItem (hwndDlg, IDHELP), TRUE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREV), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_NEXT), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
+
+ RefreshUIGFX();
+
+ Error ("EXTRACTION_FAILED", hwndDlg);
+
+ return 1;
+
+ case WM_CLOSE:
+
+ if (!bDevm)
+ {
+ if (bInProgress)
+ {
+ NormalCursor();
+ if (AskNoYes("CONFIRM_EXIT_UNIVERSAL", hwndDlg) == IDNO)
+ {
+ return 1;
+ }
+ WaitCursor ();
+ }
+
+ if (bOpenContainingFolder && bExtractOnly && bExtractionSuccessful)
+ {
+ ShellExecute (NULL, L"open", WizardDestExtractPath, NULL, NULL, SW_SHOWNORMAL);
+ }
+ else
+ {
+ if (bPromptReleaseNotes
+ && AskYesNo ("AFTER_UPGRADE_RELEASE_NOTES", hwndDlg) == IDYES)
+ {
+ Applink ("releasenotes", TRUE, "");
+ }
+
+ bPromptReleaseNotes = FALSE;
+
+ if (bPromptTutorial
+ && AskYesNo ("AFTER_INSTALL_TUTORIAL", hwndDlg) == IDYES)
+ {
+ Applink ("beginnerstutorial", TRUE, "");
+ }
+
+ bPromptTutorial = FALSE;
+ }
+
+ if (bRestartRequired
+ && AskYesNo (bUpgrade ? "UPGRADE_OK_REBOOT_REQUIRED" : "CONFIRM_RESTART", hwndDlg) == IDYES)
+ {
+ RestartComputer();
+ }
+ }
+
+ EndDialog (hwndDlg, IDCANCEL);
+ return 1;
+ }
+
+ return 0;
+}
+
+
diff --git a/src/Setup/Wizard.h b/src/Setup/Wizard.h
index fefc297f..3d178e24 100644
--- a/src/Setup/Wizard.h
+++ b/src/Setup/Wizard.h
@@ -1,31 +1,31 @@
-/*
- Legal Notice: Some portions of the source code contained in this file were
- derived from the source code of TrueCrypt 7.1a, which is
- Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
- governed by the TrueCrypt License 3.0, also from the source code of
- Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
- and which is governed by the 'License Agreement for Encryption for the Masses'
- Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
- and are governed by the Apache License 2.0 the full text of which is
- contained in the file License.txt included in VeraCrypt binary and source
- code distribution packages. */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void InitProgressBar (void);
-BOOL UpdateProgressBarProc (int nPercent);
-void RefreshUIGFX (void);
-void localcleanupwiz (void);
-
-BOOL CALLBACK PageDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
-BOOL CALLBACK MainDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
-
-extern BOOL bPromptTutorial;
-extern BOOL bPromptReleaseNotes;
-
-#ifdef __cplusplus
-}
-#endif
+/*
+ Legal Notice: Some portions of the source code contained in this file were
+ derived from the source code of TrueCrypt 7.1a, which is
+ Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
+ governed by the TrueCrypt License 3.0, also from the source code of
+ Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
+ and which is governed by the 'License Agreement for Encryption for the Masses'
+ Modifications and additions to the original source code (contained in this file)
+ and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and are governed by the Apache License 2.0 the full text of which is
+ contained in the file License.txt included in VeraCrypt binary and source
+ code distribution packages. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void InitProgressBar (void);
+BOOL UpdateProgressBarProc (int nPercent);
+void RefreshUIGFX (void);
+void localcleanupwiz (void);
+
+BOOL CALLBACK PageDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
+BOOL CALLBACK MainDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
+
+extern BOOL bPromptTutorial;
+extern BOOL bPromptReleaseNotes;
+
+#ifdef __cplusplus
+}
+#endif