mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-06-09 22:36:59 -05:00
Windows: Add an SDK for VeraCrypt Format that allows third-party application to create volumes
This commit is contained in:
@@ -298,7 +298,7 @@ static BOOL IsWindowsMBR (const uint8 *buffer, size_t bufferSize)
|
||||
|
||||
namespace VeraCrypt
|
||||
{
|
||||
#if !defined (SETUP)
|
||||
#if !defined (SETUP) && !defined (VCSDK_DLL)
|
||||
|
||||
class Elevator
|
||||
{
|
||||
@@ -755,6 +755,12 @@ namespace VeraCrypt
|
||||
static void WriteEfiBootSectorUserConfig (uint8 userConfig, const string &customUserMessage, int pim, int hashAlg) { throw ParameterIncorrect (SRC_POS); }
|
||||
static void UpdateSetupConfigFile (bool bForInstall) { throw ParameterIncorrect (SRC_POS); }
|
||||
static void GetSecureBootConfig (BOOL* pSecureBootEnabled, BOOL *pVeraCryptKeysLoaded) { throw ParameterIncorrect (SRC_POS); }
|
||||
static void RegisterSystemFavoritesService(BOOL registerService) { throw ParameterIncorrect(SRC_POS); }
|
||||
static BOOL IsPagingFileActive(BOOL checkNonWindowsPartitionsOnly) { throw ParameterIncorrect(SRC_POS); }
|
||||
static void WriteLocalMachineRegistryDwordValue(wchar_t* keyPath, wchar_t* valueName, DWORD value) { throw ParameterIncorrect(SRC_POS); }
|
||||
static void NotifyService(DWORD dwNotifyCmd) { throw ParameterIncorrect(SRC_POS); }
|
||||
static void CopyFile(const wstring& sourceFile, const wstring& destinationFile) { throw ParameterIncorrect(SRC_POS); }
|
||||
static void DeleteFile(const wstring& file) { throw ParameterIncorrect(SRC_POS); }
|
||||
};
|
||||
|
||||
#endif // SETUP
|
||||
|
||||
+49
-16
@@ -1012,7 +1012,7 @@ BOOL VerifyModuleSignature (const wchar_t* path)
|
||||
|
||||
DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
|
||||
{
|
||||
#ifndef VC_COMREG
|
||||
#if !defined(VC_COMREG) && !defined(VCSDK_DLL)
|
||||
PWSTR lpMsgBuf;
|
||||
DWORD dwError = GetLastError ();
|
||||
wchar_t szErrorValue[32];
|
||||
@@ -3675,7 +3675,7 @@ void DoPostInstallTasks (HWND hwndDlg)
|
||||
SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_REMOVE_ALL);
|
||||
}
|
||||
|
||||
#ifndef SETUP_DLL
|
||||
#if !defined(SETUP_DLL) && !defined(VCSDK_DLL)
|
||||
// Use an idea proposed in https://medium.com/@1ndahous3/safe-code-pitfalls-dll-side-loading-winapi-and-c-73baaf48bdf5
|
||||
// it allows to set safe DLL search mode for the entire process very early on, before even the CRT is initialized and global constructors are called
|
||||
#pragma comment(linker, "/ENTRY:CustomMainCrtStartup")
|
||||
@@ -3715,13 +3715,14 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
WNDCLASSW wc;
|
||||
char langId[6];
|
||||
SetDefaultDllDirectoriesPtr SetDefaultDllDirectoriesFn = NULL;
|
||||
#if !defined(SETUP)
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
wchar_t modPath[MAX_PATH];
|
||||
#endif
|
||||
INITCOMMONCONTROLSEX InitCtrls;
|
||||
|
||||
InitOSVersionInfo();
|
||||
|
||||
#ifndef VCSDK_DLL
|
||||
if (!IsWin10BuildAtLeast(WIN_10_1809_BUILD))
|
||||
{
|
||||
// abort using a message that says that VeraCrypt can run only on Windows 10 version 1809 or later
|
||||
@@ -3740,6 +3741,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
// This can happen only if KB2533623 is missing from Windows 7
|
||||
AbortProcessDirect(L"VeraCrypt requires KB2533623 to be installed on Windows 7 and Windows Server 2008 R2 in order to run.");
|
||||
}
|
||||
#endif
|
||||
|
||||
VirtualLock (&CmdTokenPin, sizeof (CmdTokenPin));
|
||||
|
||||
@@ -3753,13 +3755,11 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
// Load RichEdit library in order to be able to use RichEdit20W class
|
||||
LoadLibraryEx (L"Riched20.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
|
||||
#if !defined(SETUP)
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
GetModuleFileNameW (NULL, modPath, ARRAYSIZE (modPath));
|
||||
if (!VerifyModuleSignature (modPath))
|
||||
AbortProcessDirect (L"This distribution package is damaged. Please try downloading it again (preferably from the official VeraCrypt website at https://veracrypt.jp).");
|
||||
#endif
|
||||
|
||||
#ifndef SETUP
|
||||
/* enable drag-n-drop when we are running elevated */
|
||||
AllowMessageInUIPI (WM_DROPFILES);
|
||||
AllowMessageInUIPI (WM_COPYDATA);
|
||||
@@ -3772,7 +3772,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
SetErrorMode (SetErrorMode (0) | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
#ifndef SETUP
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
// Application ID
|
||||
SetCurrentProcessExplicitAppUserModelID (TC_APPLICATION_ID);
|
||||
#endif
|
||||
@@ -3781,7 +3781,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
langId[0] = 0;
|
||||
SetPreferredLangId (ConfigReadString ("Language", "", langId, sizeof (langId)));
|
||||
|
||||
#ifndef SETUP
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
if (langId[0] == 0)
|
||||
{
|
||||
// check if user selected a language during installation
|
||||
@@ -3820,7 +3820,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
|
||||
LoadLanguageFile ();
|
||||
|
||||
#ifndef SETUP
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
// UAC elevation moniker cannot be used in portable mode.
|
||||
// A new instance of the application must be created with elevated privileges.
|
||||
if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ())
|
||||
@@ -3918,7 +3918,7 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
||||
|
||||
InitHelpFileName ();
|
||||
|
||||
#ifndef SETUP
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
|
||||
EnableRamEncryption ((ReadDriverConfigurationFlags() & VC_DRIVER_CONFIG_ENABLE_RAM_ENCRYPTION) ? TRUE : FALSE);
|
||||
if (IsRamEncryptionEnabled())
|
||||
@@ -10226,7 +10226,7 @@ void CleanLastVisitedMRU (void)
|
||||
}
|
||||
|
||||
|
||||
#ifndef SETUP
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
void ClearHistory (HWND hwndDlgItem)
|
||||
{
|
||||
ArrowWaitCursor ();
|
||||
@@ -12582,7 +12582,7 @@ extern "C" BOOL IsThreadInSecureDesktop(DWORD dwThreadID)
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
#ifndef VCSDK_DLL
|
||||
BOOL InitSecurityTokenLibrary (HWND hwndDlg)
|
||||
{
|
||||
if (SecurityTokenLibraryPath[0] == 0)
|
||||
@@ -12648,7 +12648,7 @@ BOOL InitSecurityTokenLibrary (HWND hwndDlg)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool singleList, bool noFloppy, bool detectUnencryptedFilesystems)
|
||||
{
|
||||
vector <HostDevice> devices;
|
||||
@@ -15032,7 +15032,7 @@ void SafeOpenURL (LPCWSTR szUrl)
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(SETUP)
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
|
||||
#define RtlGenRandom SystemFunction036
|
||||
extern "C" BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
|
||||
@@ -16179,7 +16179,7 @@ cleanup:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(SETUP) && !defined(VC_COMREG)
|
||||
#if !defined(SETUP) && !defined(VC_COMREG) && !defined(VCSDK_DLL)
|
||||
|
||||
/*
|
||||
* Screen Protection Functions
|
||||
@@ -16404,4 +16404,37 @@ BOOL AttachProtectionToCurrentThread(HWND hwnd)
|
||||
void DetachProtectionFromCurrentThread()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// This function moves the file pointer to the given offset. It first retrieves the current
|
||||
// file position using SetFilePointerEx() with FILE_CURRENT as the reference point, and then
|
||||
// calculates the difference between the current position and the desired position. Subsequently,
|
||||
// it moves the file pointer by the difference calculated using SetFilePointerEx() again.
|
||||
//
|
||||
// This approach of moving the file pointer relatively (instead of absolutely) was implemented
|
||||
// as a workaround to address the performance issues related to in-place encryption. When using
|
||||
// SetFilePointerEx() with FILE_BEGIN as the reference point, reaching the end of large drives
|
||||
// during in-place encryption can cause significant slowdowns. By moving the file pointer
|
||||
// relatively, these performance issues are mitigated.
|
||||
//
|
||||
// We fall back to absolute positioning if the relative positioning fails.
|
||||
BOOL MoveFilePointer(HANDLE dev, LARGE_INTEGER offset)
|
||||
{
|
||||
LARGE_INTEGER currOffset;
|
||||
LARGE_INTEGER diffOffset;
|
||||
|
||||
currOffset.QuadPart = 0;
|
||||
if (SetFilePointerEx(dev, currOffset, &currOffset, FILE_CURRENT))
|
||||
{
|
||||
diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
|
||||
if (diffOffset.QuadPart == 0)
|
||||
return TRUE;
|
||||
|
||||
// Moves the file pointer by the difference between current and desired positions
|
||||
if (SetFilePointerEx(dev, diffOffset, NULL, FILE_CURRENT))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// An error occurred, fallback to absolute positioning
|
||||
return SetFilePointerEx(dev, offset, NULL, FILE_BEGIN);
|
||||
}
|
||||
|
||||
@@ -600,12 +600,13 @@ BitLockerEncryptionStatus GetBitLockerEncryptionStatus(WCHAR driveLetter);
|
||||
BOOL IsTestSigningModeEnabled ();
|
||||
DWORD SendServiceNotification (DWORD dwNotificationCmd);
|
||||
DWORD FastResizeFile (const wchar_t* filePath, __int64 fileSize);
|
||||
#if !defined(SETUP)
|
||||
#if !defined(SETUP) && !defined(VCSDK_DLL)
|
||||
void GetAppRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed);
|
||||
#endif
|
||||
BOOL IsInternetConnected();
|
||||
BOOL AttachProtectionToCurrentThread(HWND hwnd);
|
||||
void DetachProtectionFromCurrentThread();
|
||||
BOOL MoveFilePointer(HANDLE dev, LARGE_INTEGER offset);
|
||||
|
||||
#if defined(SETUP) && !defined (PORTABLE)
|
||||
typedef struct _SECURITY_INFO_BACKUP {
|
||||
|
||||
+56
-15
@@ -24,6 +24,7 @@
|
||||
#include "Progress.h"
|
||||
#include "Random.h"
|
||||
#include "Volumes.h"
|
||||
#include "Dlgcode.h"
|
||||
|
||||
void
|
||||
GetFatParams (fatparams * ft)
|
||||
@@ -255,7 +256,7 @@ static void PutFSInfo (unsigned char *sector, fatparams *ft)
|
||||
|
||||
|
||||
int
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat, BOOL bDevice)
|
||||
FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, volatile void *volParamsArg)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
@@ -267,6 +268,9 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
int retVal;
|
||||
CRYPTOPP_ALIGN_DATA(16) char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
HWND hwndDlg = (HWND) hwndDlgPtr;
|
||||
volatile FORMAT_VOL_PARAMETERS* volParams = (volatile FORMAT_VOL_PARAMETERS*)volParamsArg;
|
||||
BOOL quickFormat = volParams->quickFormat;
|
||||
BOOL bDevice = volParams->bDevice;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
@@ -292,7 +296,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* fat32 boot area */
|
||||
@@ -301,7 +305,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
/* fsinfo */
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
|
||||
/* reserved */
|
||||
@@ -311,7 +315,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
sector[508+3]=0xaa; /* TrailSig */
|
||||
sector[508+2]=0x55;
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -319,12 +323,12 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
memset (sector, 0, ft->sector_size);
|
||||
PutBoot (ft, (unsigned char *) sector);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
|
||||
PutFSInfo((unsigned char *) sector, ft);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -333,7 +337,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -377,7 +381,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
}
|
||||
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -388,7 +392,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
{
|
||||
memset (sector, 0, ft->sector_size);
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
|
||||
}
|
||||
@@ -452,10 +456,19 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
while (x--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
UpdateProgressBar ((nSecNo - startSector) * ft->sector_size);
|
||||
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
volParams->progress_callback ((nSecNo - startSector) * ft->sector_size, volParams->progress_callback_user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateProgressBar ((nSecNo - startSector) * ft->sector_size);
|
||||
}
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
{
|
||||
@@ -498,16 +511,44 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
|
||||
nSecNo++;
|
||||
num_sectors -= nSkipSectors;
|
||||
|
||||
if (UpdateProgressBar ((nSecNo - startSector)* ft->sector_size))
|
||||
goto fail;
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
if (!volParams->progress_callback ((nSecNo - startSector) * ft->sector_size, volParams->progress_callback_user_data))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UpdateProgressBar ((nSecNo - startSector)* ft->sector_size))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nSecNo += num_sectors;
|
||||
UpdateProgressBar ((nSecNo - startSector)* ft->sector_size);
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
volParams->progress_callback ((nSecNo - startSector) * ft->sector_size, volParams->progress_callback_user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateProgressBar ((nSecNo - startSector)* ft->sector_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
volParams->progress_callback ((uint64) ft->num_sectors * ft->sector_size, volParams->progress_callback_user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size);
|
||||
}
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
|
||||
+1
-1
@@ -66,4 +66,4 @@ struct msdos_boot_sector
|
||||
|
||||
void GetFatParams ( fatparams *ft );
|
||||
void PutBoot ( fatparams *ft , unsigned char *boot );
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat, BOOL bDevice);
|
||||
int FormatFat (void* hwndDlg, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, volatile void *);
|
||||
|
||||
+62
-16
@@ -349,12 +349,15 @@ begin_format:
|
||||
if (!SetPrivilege(SE_MANAGE_VOLUME_NAME, TRUE))
|
||||
{
|
||||
DWORD dwLastError = GetLastError();
|
||||
#ifndef VCSDK_DLL
|
||||
if (!IsAdmin () && IsUacSupported ())
|
||||
{
|
||||
speedupFileCreation = TRUE;
|
||||
delayedSpeedupFileCreation = TRUE;
|
||||
}
|
||||
else if (Silent || (MessageBoxW(hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_MANAGE_VOLUME"), lpszTitle, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDNO))
|
||||
else
|
||||
#endif
|
||||
if (Silent || (MessageBoxW(hwndDlg, GetString ("ADMIN_PRIVILEGES_WARN_MANAGE_VOLUME"), lpszTitle, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDNO))
|
||||
{
|
||||
SetLastError(dwLastError);
|
||||
nStatus = ERR_OS_ERROR;
|
||||
@@ -421,6 +424,7 @@ begin_format:
|
||||
|
||||
if (speedupFileCreation)
|
||||
{
|
||||
#ifndef VCSDK_DLL
|
||||
// accelerate file creation by telling Windows not to fill all file content with zeros
|
||||
// this has security issues since it will put existing disk content into file container
|
||||
// We use this mechanism only when switch /fastCreateFile specific and when quick format
|
||||
@@ -460,7 +464,9 @@ begin_format:
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else if (!SetFileValidData (dev, volumeSize.QuadPart))
|
||||
else
|
||||
#endif
|
||||
if (!SetFileValidData (dev, volumeSize.QuadPart))
|
||||
{
|
||||
nStatus = ERR_OS_ERROR;
|
||||
goto error;
|
||||
@@ -579,7 +585,7 @@ begin_format:
|
||||
goto error;
|
||||
}
|
||||
|
||||
nStatus = FormatNoFs (hwndDlg, startSector, num_sectors, dev, cryptoInfo, volParams->quickFormat, volParams->bDevice);
|
||||
nStatus = FormatNoFs (hwndDlg, startSector, num_sectors, dev, cryptoInfo, volParams);
|
||||
|
||||
if (volParams->bDevice)
|
||||
StopFormatWriteThread();
|
||||
@@ -604,7 +610,7 @@ begin_format:
|
||||
ft.cluster_size = volParams->clusterSize;
|
||||
memcpy (ft.volume_name, "NO NAME ", 11);
|
||||
GetFatParams (&ft);
|
||||
*(volParams->realClusterSize) = ft.cluster_size * FormatSectorSize;
|
||||
if (volParams->realClusterSize ) *(volParams->realClusterSize) = ft.cluster_size * FormatSectorSize;
|
||||
|
||||
if (volParams->bDevice && !StartFormatWriteThread())
|
||||
{
|
||||
@@ -612,7 +618,7 @@ begin_format:
|
||||
goto error;
|
||||
}
|
||||
|
||||
nStatus = FormatFat (hwndDlg, startSector, &ft, (void *) dev, cryptoInfo, volParams->quickFormat, volParams->bDevice);
|
||||
nStatus = FormatFat (hwndDlg, startSector, &ft, (void *) dev, cryptoInfo, volParams);
|
||||
|
||||
if (volParams->bDevice)
|
||||
StopFormatWriteThread();
|
||||
@@ -832,11 +838,12 @@ error:
|
||||
retCode = ExternalFormatFs (driveNo, volParams->clusterSize, fsType);
|
||||
if (retCode != 0)
|
||||
{
|
||||
|
||||
#ifndef VCSDK_DLL
|
||||
/* fallback to using FormatEx function from fmifs.dll */
|
||||
if (!Silent && !IsAdmin () && IsUacSupported ())
|
||||
retCode = UacFormatFs (volParams->hwndDlg, driveNo, volParams->clusterSize, fsType);
|
||||
else
|
||||
#endif
|
||||
retCode = FormatFs (driveNo, volParams->clusterSize, fsType, FALSE); /* no need to fallback to format.com since we have already tried it without elevation */
|
||||
|
||||
if (retCode != 0)
|
||||
@@ -888,7 +895,7 @@ fv_end:
|
||||
}
|
||||
|
||||
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num_sectors, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat, BOOL bDevice)
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num_sectors, void * dev, PCRYPTO_INFO cryptoInfo, volatile FORMAT_VOL_PARAMETERS *volParams)
|
||||
{
|
||||
int write_buf_cnt = 0;
|
||||
char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf;
|
||||
@@ -899,6 +906,8 @@ int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num
|
||||
DWORD err;
|
||||
CRYPTOPP_ALIGN_DATA(16) char temporaryKey[MASTER_KEYDATA_SIZE];
|
||||
CRYPTOPP_ALIGN_DATA(16) char originalK2[MASTER_KEYDATA_SIZE];
|
||||
BOOL quickFormat = volParams->quickFormat;
|
||||
BOOL bDevice = volParams->bDevice;
|
||||
|
||||
LARGE_INTEGER startOffset;
|
||||
LARGE_INTEGER newOffset;
|
||||
@@ -965,12 +974,21 @@ int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num
|
||||
while (num_sectors--)
|
||||
{
|
||||
if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector,
|
||||
cryptoInfo) == FALSE)
|
||||
cryptoInfo, volParams) == FALSE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (UpdateProgressBar ((nSecNo - startSector) * FormatSectorSize))
|
||||
return FALSE;
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
if (!volParams->progress_callback ((nSecNo - startSector) * FormatSectorSize, volParams->progress_callback_user_data))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UpdateProgressBar ((nSecNo - startSector) * FormatSectorSize))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo))
|
||||
goto fail;
|
||||
@@ -1002,8 +1020,17 @@ int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num
|
||||
nSecNo++;
|
||||
num_sectors -= nSkipSectors;
|
||||
|
||||
if (UpdateProgressBar ((nSecNo - startSector)* FormatSectorSize))
|
||||
goto fail;
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
if (!volParams->progress_callback ((nSecNo - startSector) * FormatSectorSize, volParams->progress_callback_user_data))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UpdateProgressBar ((nSecNo - startSector)* FormatSectorSize))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
nSecNo += num_sectors;
|
||||
@@ -1013,7 +1040,15 @@ int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num
|
||||
nSecNo += num_sectors;
|
||||
}
|
||||
|
||||
UpdateProgressBar ((nSecNo - startSector) * FormatSectorSize);
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
volParams->progress_callback ((nSecNo - startSector) * FormatSectorSize, volParams->progress_callback_user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateProgressBar ((nSecNo - startSector) * FormatSectorSize);
|
||||
}
|
||||
|
||||
// Restore the original secondary key (XTS mode) in case NTFS format fails and the user wants to try FAT immediately
|
||||
memcpy (cryptoInfo->k2, originalK2, sizeof (cryptoInfo->k2));
|
||||
@@ -1341,7 +1376,7 @@ int ExternalFormatFs (int driveNo, int clusterSize, int fsType)
|
||||
|
||||
BOOL WriteSector (void *dev, char *sector,
|
||||
char *write_buf, int *write_buf_cnt,
|
||||
unsigned __int64 *nSecNo, unsigned __int64 startSector, PCRYPTO_INFO cryptoInfo)
|
||||
unsigned __int64 *nSecNo, unsigned __int64 startSector, PCRYPTO_INFO cryptoInfo, volatile FORMAT_VOL_PARAMETERS *volParams)
|
||||
{
|
||||
static __int32 updateTime = 0;
|
||||
|
||||
@@ -1355,8 +1390,19 @@ BOOL WriteSector (void *dev, char *sector,
|
||||
|
||||
if (GetTickCount () - updateTime > 25)
|
||||
{
|
||||
if (UpdateProgressBar ((*nSecNo - startSector) * FormatSectorSize))
|
||||
return FALSE;
|
||||
if (volParams->progress_callback)
|
||||
{
|
||||
// Call the progress callback function if it is set
|
||||
if (!volParams->progress_callback ((*nSecNo - startSector) * FormatSectorSize, volParams->progress_callback_user_data))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UpdateProgressBar ((*nSecNo - startSector) * FormatSectorSize))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
updateTime = GetTickCount ();
|
||||
}
|
||||
|
||||
+4
-3
@@ -46,6 +46,8 @@ typedef struct
|
||||
HWND hwndDlg;
|
||||
BOOL bForceOperation;
|
||||
BOOL bGuiMode;
|
||||
BOOL (__cdecl *progress_callback)(unsigned __int64 bytesProcessed, void* cbData);
|
||||
void* progress_callback_user_data;
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
@@ -80,12 +82,11 @@ int FormatFs (int driveNo, int clusterSize, int fsType, BOOL bFallBackExternal);
|
||||
int ExternalFormatFs (int driveNo, int clusterSize, int fsType);
|
||||
LPCWSTR FormatExGetMessage (int command);
|
||||
uint64 GetVolumeDataAreaSize (BOOL hiddenVolume, uint64 volumeSize);
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat, BOOL bDevice);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , unsigned __int64 *nSecNo , unsigned __int64 startSector, PCRYPTO_INFO cryptoInfo );
|
||||
int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, unsigned __int64 num_sectors, void *dev, PCRYPTO_INFO cryptoInfo, volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL WriteSector ( void *dev , char *sector , char *write_buf , int *write_buf_cnt , unsigned __int64 *nSecNo , unsigned __int64 startSector, PCRYPTO_INFO cryptoInfo, volatile FORMAT_VOL_PARAMETERS *volParams);
|
||||
BOOL FlushFormatWriteBuffer (void *dev, char *write_buf, int *write_buf_cnt, __int64 *nSecNo, PCRYPTO_INFO cryptoInfo);
|
||||
static BOOL StartFormatWriteThread ();
|
||||
static void StopFormatWriteThread ();
|
||||
BOOL MoveFilePointer (HANDLE dev, LARGE_INTEGER offset);
|
||||
|
||||
#define FILESYS_NONE 0
|
||||
#define FILESYS_FAT 1
|
||||
|
||||
@@ -250,6 +250,10 @@ static BOOL LoadLanguageData (int resourceid, BOOL bForceSetPreferredLanguage, B
|
||||
int headers[] = { IDR_COMMON_RSRC_HEADER, IDR_SETUP_RSRC_HEADER, 0 };
|
||||
#endif
|
||||
|
||||
#ifdef VCSDK_DLL
|
||||
int headers[] = { 0 };
|
||||
#endif
|
||||
|
||||
LocalizationActive = FALSE;
|
||||
ActiveLangPackVersion[0] = 0;
|
||||
ClearDictionaryPool ();
|
||||
|
||||
+4
-1
@@ -129,8 +129,11 @@ int RandinitWithCheck ( int* pAlreadyInitialized)
|
||||
VirtualLock (pRandPool, RANDOMPOOL_ALLOCSIZE);
|
||||
}
|
||||
|
||||
#ifndef VCSDK_DLL
|
||||
bIgnoreHookError = IsThreadInSecureDesktop(GetCurrentThreadId());
|
||||
|
||||
#else
|
||||
bIgnoreHookError = TRUE;
|
||||
#endif
|
||||
hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ());
|
||||
if (hKeyboard == 0 && !bIgnoreHookError) handleWin32Error (0, SRC_POS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user