mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-12 19:38:26 -06:00
Windows: fix high CPU usage when a favorite is configured to mount using VolumeID when its host device is connected to the machine.
This commit is contained in:
@@ -266,9 +266,9 @@ typedef struct
|
|||||||
BOOL TCBootLoaderDetected;
|
BOOL TCBootLoaderDetected;
|
||||||
BOOL DetectFilesystem;
|
BOOL DetectFilesystem;
|
||||||
BOOL FilesystemDetected;
|
BOOL FilesystemDetected;
|
||||||
BOOL bMatchVolumeID;
|
BOOL bComputeVolumeIDs;
|
||||||
unsigned char volumeID[VOLUME_ID_SIZE];
|
unsigned char volumeIDs[TC_VOLUME_TYPE_COUNT][VOLUME_ID_SIZE];
|
||||||
BOOL VolumeIDMatched;
|
BOOL VolumeIDComputed[TC_VOLUME_TYPE_COUNT];
|
||||||
} OPEN_TEST_STRUCT;
|
} OPEN_TEST_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1090,6 +1090,7 @@ namespace VeraCrypt
|
|||||||
memcpy (fingerprint, request.Fingerprint, sizeof (request.Fingerprint));
|
memcpy (fingerprint, request.Fingerprint, sizeof (request.Fingerprint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SETUP
|
||||||
// Note that this does not require admin rights (it just requires the driver to be running)
|
// Note that this does not require admin rights (it just requires the driver to be running)
|
||||||
bool BootEncryption::IsBootLoaderOnDrive (wchar_t *devicePath)
|
bool BootEncryption::IsBootLoaderOnDrive (wchar_t *devicePath)
|
||||||
{
|
{
|
||||||
@@ -1114,6 +1115,7 @@ namespace VeraCrypt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
BootEncryptionStatus BootEncryption::GetStatus ()
|
BootEncryptionStatus BootEncryption::GetStatus ()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,8 +74,22 @@
|
|||||||
#include "Setup/Setup.h"
|
#include "Setup/Setup.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Setupapi.h>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
|
#pragma comment( lib, "setupapi.lib" )
|
||||||
|
|
||||||
|
/* GPT Partition Type GUIDs */
|
||||||
|
#define LOCAL_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = {l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8}
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_ENTRY_UNUSED_GUID, 0x00000000L, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); // Entry unused
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_SYSTEM_GUID, 0xC12A7328L, 0xF81F, 0x11D2, 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B); // EFI system partition
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_MSFT_RESERVED_GUID, 0xE3C9E316L, 0x0B5C, 0x4DB8, 0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE); // Microsoft reserved space
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_BASIC_DATA_GUID, 0xEBD0A0A2L, 0xB9E5, 0x4433, 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7); // Basic data partition
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_LDM_METADATA_GUID, 0x5808C8AAL, 0x7E8F, 0x42E0, 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3); // Logical Disk Manager metadata partition
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_LDM_DATA_GUID, 0xAF9B60A0L, 0x1431, 0x4F62, 0xBC, 0x68, 0x33, 0x11, 0x71, 0x4A, 0x69, 0xAD); // Logical Disk Manager data partition
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_MSFT_RECOVERY_GUID, 0xDE94BBA4L, 0x06D1, 0x4D40, 0xA1, 0x6A, 0xBF, 0xD5, 0x01, 0x79, 0xD6, 0xAC); // Microsoft recovery partition
|
||||||
|
LOCAL_DEFINE_GUID(PARTITION_CLUSTER_GUID, 0xdb97dba9L, 0x0840, 0x4bae, 0x97, 0xf0, 0xff, 0xb9, 0xa3, 0x27, 0xc7, 0xe1); // Cluster metadata partition
|
||||||
|
|
||||||
using namespace VeraCrypt;
|
using namespace VeraCrypt;
|
||||||
|
|
||||||
LONG DriverVersion;
|
LONG DriverVersion;
|
||||||
@@ -174,6 +188,13 @@ volatile HANDLE hAppSetupMutex = NULL;
|
|||||||
/* Critical section used to protect access to global variables used in WNetGetConnection calls */
|
/* Critical section used to protect access to global variables used in WNetGetConnection calls */
|
||||||
CRITICAL_SECTION csWNetCalls;
|
CRITICAL_SECTION csWNetCalls;
|
||||||
|
|
||||||
|
/* Critical section used to protect access to global list of physical drives */
|
||||||
|
CRITICAL_SECTION csMountableDevices;
|
||||||
|
CRITICAL_SECTION csVolumeIdCandidates;
|
||||||
|
|
||||||
|
static std::vector<HostDevice> mountableDevices;
|
||||||
|
static std::vector<HostDevice> rawHostDeviceList;
|
||||||
|
|
||||||
HINSTANCE hInst = NULL;
|
HINSTANCE hInst = NULL;
|
||||||
HCURSOR hCursor = NULL;
|
HCURSOR hCursor = NULL;
|
||||||
|
|
||||||
@@ -448,6 +469,8 @@ void cleanup ()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DeleteCriticalSection (&csWNetCalls);
|
DeleteCriticalSection (&csWNetCalls);
|
||||||
|
DeleteCriticalSection (&csMountableDevices);
|
||||||
|
DeleteCriticalSection (&csVolumeIdCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2658,6 +2681,8 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine)
|
|||||||
VirtualLock (&CmdTokenPin, sizeof (CmdTokenPin));
|
VirtualLock (&CmdTokenPin, sizeof (CmdTokenPin));
|
||||||
|
|
||||||
InitializeCriticalSection (&csWNetCalls);
|
InitializeCriticalSection (&csWNetCalls);
|
||||||
|
InitializeCriticalSection (&csMountableDevices);
|
||||||
|
InitializeCriticalSection (&csVolumeIdCandidates);
|
||||||
|
|
||||||
LoadSystemDll (L"ntmarta.dll", &hntmartadll, TRUE, SRC_POS);
|
LoadSystemDll (L"ntmarta.dll", &hntmartadll, TRUE, SRC_POS);
|
||||||
LoadSystemDll (L"MPR.DLL", &hmprdll, TRUE, SRC_POS);
|
LoadSystemDll (L"MPR.DLL", &hmprdll, TRUE, SRC_POS);
|
||||||
@@ -3049,7 +3074,8 @@ void InitHelpFileName (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem, BOOL matchVolumeID, const BYTE* pbVolumeID)
|
#ifndef SETUP
|
||||||
|
BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem, BOOL computeVolumeIDs)
|
||||||
{
|
{
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
BOOL bResult;
|
BOOL bResult;
|
||||||
@@ -3062,9 +3088,7 @@ BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectF
|
|||||||
|
|
||||||
driver->bDetectTCBootLoader = FALSE;
|
driver->bDetectTCBootLoader = FALSE;
|
||||||
driver->DetectFilesystem = detectFilesystem;
|
driver->DetectFilesystem = detectFilesystem;
|
||||||
driver->bMatchVolumeID = matchVolumeID;
|
driver->bComputeVolumeIDs = computeVolumeIDs;
|
||||||
if (matchVolumeID && pbVolumeID)
|
|
||||||
memcpy (driver->volumeID, pbVolumeID, VOLUME_ID_SIZE);
|
|
||||||
|
|
||||||
bResult = DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST,
|
bResult = DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST,
|
||||||
driver, sizeof (OPEN_TEST_STRUCT),
|
driver, sizeof (OPEN_TEST_STRUCT),
|
||||||
@@ -3092,7 +3116,7 @@ BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectF
|
|||||||
{
|
{
|
||||||
driver->TCBootLoaderDetected = FALSE;
|
driver->TCBootLoaderDetected = FALSE;
|
||||||
driver->FilesystemDetected = FALSE;
|
driver->FilesystemDetected = FALSE;
|
||||||
driver->VolumeIDMatched = FALSE;
|
memset (driver->VolumeIDComputed, 0, sizeof (driver->VolumeIDComputed));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -3102,6 +3126,7 @@ BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectF
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Tells the driver that it's running in portable mode
|
// Tells the driver that it's running in portable mode
|
||||||
void NotifyDriverOfPortableMode (void)
|
void NotifyDriverOfPortableMode (void)
|
||||||
@@ -7510,6 +7535,7 @@ void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SETUP
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static BOOL PerformMountIoctl (MOUNT_STRUCT* pmount, LPDWORD pdwResult, BOOL useVolumeID, BYTE volumeID[VOLUME_ID_SIZE])
|
static BOOL PerformMountIoctl (MOUNT_STRUCT* pmount, LPDWORD pdwResult, BOOL useVolumeID, BYTE volumeID[VOLUME_ID_SIZE])
|
||||||
@@ -7989,6 +8015,8 @@ retry:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int nDosDriveNo;
|
int nDosDriveNo;
|
||||||
@@ -8087,8 +8115,6 @@ BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo)
|
|||||||
return UnmountVolumeBase (hwndDlg, nDosDriveNo, FALSE, TRUE);
|
return UnmountVolumeBase (hwndDlg, nDosDriveNo, FALSE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //!SETUP
|
|
||||||
|
|
||||||
BOOL IsPasswordCacheEmpty (void)
|
BOOL IsPasswordCacheEmpty (void)
|
||||||
{
|
{
|
||||||
DWORD dw;
|
DWORD dw;
|
||||||
@@ -8106,9 +8132,14 @@ BOOL IsMountedVolumeID (BYTE volumeID[VOLUME_ID_SIZE])
|
|||||||
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if (mlist.ulMountedDrives)
|
||||||
|
{
|
||||||
for (i=0 ; i<26; i++)
|
for (i=0 ; i<26; i++)
|
||||||
if (0 == memcmp (mlist.volumeID[i], volumeID, VOLUME_ID_SIZE))
|
{
|
||||||
|
if ((mlist.ulMountedDrives & (1 << i)) && (0 == memcmp (mlist.volumeID[i], volumeID, VOLUME_ID_SIZE)))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -8145,10 +8176,15 @@ BOOL IsMountedVolume (const wchar_t *volname)
|
|||||||
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if (mlist.ulMountedDrives)
|
||||||
|
{
|
||||||
for (i=0 ; i<26; i++)
|
for (i=0 ; i<26; i++)
|
||||||
if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], volume))
|
{
|
||||||
|
if ((mlist.ulMountedDrives & (1 << i)) && (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], volume)))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -8178,13 +8214,19 @@ int GetMountedVolumeDriveNo (wchar_t *volname)
|
|||||||
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if (mlist.ulMountedDrives)
|
||||||
|
{
|
||||||
for (i=0 ; i<26; i++)
|
for (i=0 ; i<26; i++)
|
||||||
if (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], (WCHAR *)volume))
|
{
|
||||||
|
if ((mlist.ulMountedDrives & (1 << i)) && (0 == _wcsicmp ((wchar_t *) mlist.wszVolume[i], (WCHAR *)volume)))
|
||||||
return i;
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //!SETUP
|
||||||
|
|
||||||
BOOL IsAdmin (void)
|
BOOL IsAdmin (void)
|
||||||
{
|
{
|
||||||
@@ -11523,7 +11565,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
const wchar_t *devPath = devPathStr.c_str();
|
const wchar_t *devPath = devPathStr.c_str();
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0, FALSE, NULL))
|
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0, FALSE))
|
||||||
{
|
{
|
||||||
if (partNumber == 0)
|
if (partNumber == 0)
|
||||||
break;
|
break;
|
||||||
@@ -11627,7 +11669,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
const wchar_t *devPath = devPathStr.c_str();
|
const wchar_t *devPath = devPathStr.c_str();
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems, FALSE, NULL))
|
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems, FALSE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DISK_PARTITION_INFO_STRUCT info;
|
DISK_PARTITION_INFO_STRUCT info;
|
||||||
@@ -11667,8 +11709,305 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partNumber)
|
||||||
|
{
|
||||||
|
wstringstream strm;
|
||||||
|
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
||||||
|
wstring devPathStr (strm.str());
|
||||||
|
const wchar_t *devPath = devPathStr.c_str();
|
||||||
|
|
||||||
|
HostDevice device;
|
||||||
|
device.SystemNumber = devNumber;
|
||||||
|
device.Path = devPath;
|
||||||
|
|
||||||
|
devices.push_back (device);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector <HostDevice> GetHostRawDeviceList ()
|
||||||
|
{
|
||||||
|
std::vector <HostDevice> list;
|
||||||
|
HDEVINFO diskClassDevices;
|
||||||
|
GUID diskClassDeviceInterfaceGuid = GUID_DEVINTERFACE_DISK;
|
||||||
|
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
|
||||||
|
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData;
|
||||||
|
DWORD requiredSize;
|
||||||
|
DWORD deviceIndex;
|
||||||
|
|
||||||
|
STORAGE_DEVICE_NUMBER diskNumber;
|
||||||
|
DWORD bytesReturned;
|
||||||
|
|
||||||
|
diskClassDevices = SetupDiGetClassDevs( &diskClassDeviceInterfaceGuid,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
DIGCF_PRESENT |
|
||||||
|
DIGCF_DEVICEINTERFACE );
|
||||||
|
if ( INVALID_HANDLE_VALUE != diskClassDevices)
|
||||||
|
{
|
||||||
|
ZeroMemory( &deviceInterfaceData, sizeof( SP_DEVICE_INTERFACE_DATA ) );
|
||||||
|
deviceInterfaceData.cbSize = sizeof( SP_DEVICE_INTERFACE_DATA );
|
||||||
|
deviceIndex = 0;
|
||||||
|
|
||||||
|
while ( SetupDiEnumDeviceInterfaces( diskClassDevices,
|
||||||
|
NULL,
|
||||||
|
&diskClassDeviceInterfaceGuid,
|
||||||
|
deviceIndex,
|
||||||
|
&deviceInterfaceData ) )
|
||||||
|
{
|
||||||
|
++deviceIndex;
|
||||||
|
|
||||||
|
if (!SetupDiGetDeviceInterfaceDetail( diskClassDevices,
|
||||||
|
&deviceInterfaceData,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&requiredSize,
|
||||||
|
NULL ) && ( ERROR_INSUFFICIENT_BUFFER == GetLastError()))
|
||||||
|
{
|
||||||
|
deviceInterfaceDetailData = ( PSP_DEVICE_INTERFACE_DETAIL_DATA ) malloc( requiredSize );
|
||||||
|
ZeroMemory( deviceInterfaceDetailData, requiredSize );
|
||||||
|
deviceInterfaceDetailData->cbSize = sizeof( SP_DEVICE_INTERFACE_DETAIL_DATA );
|
||||||
|
if (SetupDiGetDeviceInterfaceDetail( diskClassDevices,
|
||||||
|
&deviceInterfaceData,
|
||||||
|
deviceInterfaceDetailData,
|
||||||
|
requiredSize,
|
||||||
|
NULL,
|
||||||
|
NULL ))
|
||||||
|
{
|
||||||
|
HANDLE disk = CreateFile( deviceInterfaceDetailData->DevicePath,
|
||||||
|
0,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
0,
|
||||||
|
NULL );
|
||||||
|
if ( INVALID_HANDLE_VALUE != disk)
|
||||||
|
{
|
||||||
|
if (DeviceIoControl( disk,
|
||||||
|
IOCTL_STORAGE_GET_DEVICE_NUMBER,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&diskNumber,
|
||||||
|
sizeof( STORAGE_DEVICE_NUMBER ),
|
||||||
|
&bytesReturned,
|
||||||
|
NULL ))
|
||||||
|
{
|
||||||
|
HostDevice device;
|
||||||
|
device.Path = deviceInterfaceDetailData->DevicePath;
|
||||||
|
device.SystemNumber = diskNumber.DeviceNumber;
|
||||||
|
list.push_back (device);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle( disk );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free (deviceInterfaceDetailData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupDiDestroyDeviceInfoList( diskClassDevices );
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CompareDeviceList (const std::vector<HostDevice>& list1, const std::vector<HostDevice>& list2)
|
||||||
|
{
|
||||||
|
if (list1.size() != list2.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (std::vector<HostDevice>::const_iterator It1 = list1.begin(); It1 != list1.end(); It1++)
|
||||||
|
{
|
||||||
|
bool bFound = false;
|
||||||
|
for (std::vector<HostDevice>::const_iterator It2 = list2.begin(); It2 != list2.end(); It2++)
|
||||||
|
{
|
||||||
|
if (It1->Path == It2->Path && It1->SystemNumber == It2->SystemNumber)
|
||||||
|
{
|
||||||
|
bFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bFound)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateMountableHostDeviceList ()
|
||||||
|
{
|
||||||
|
ByteArray buffer(4096);
|
||||||
|
DWORD bytesReturned;
|
||||||
|
bool dynamicVolumesPresent = false;
|
||||||
|
|
||||||
|
EnterCriticalSection (&csMountableDevices);
|
||||||
|
finally_do ({ LeaveCriticalSection (&csMountableDevices); });
|
||||||
|
|
||||||
|
std::vector<HostDevice> newList = GetHostRawDeviceList ();
|
||||||
|
std::map<DWORD, bool> existingDevicesMap;
|
||||||
|
|
||||||
|
if (CompareDeviceList (newList, rawHostDeviceList))
|
||||||
|
return; //no change, return
|
||||||
|
|
||||||
|
// remove raw devices that don't exist anymore
|
||||||
|
for (std::vector<HostDevice>::iterator It = rawHostDeviceList.begin();
|
||||||
|
It != rawHostDeviceList.end();)
|
||||||
|
{
|
||||||
|
for (std::vector<HostDevice>::iterator newIt = newList.begin(); newIt != newList.end(); newIt++)
|
||||||
|
{
|
||||||
|
if (newIt->SystemNumber == It->SystemNumber)
|
||||||
|
{
|
||||||
|
existingDevicesMap[It->SystemNumber] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingDevicesMap[It->SystemNumber])
|
||||||
|
It++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
It = rawHostDeviceList.erase (It);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove mountable devices that don't exist anymore
|
||||||
|
for (std::vector<HostDevice>::iterator It = mountableDevices.begin();
|
||||||
|
It != mountableDevices.end();)
|
||||||
|
{
|
||||||
|
if (existingDevicesMap[It->SystemNumber])
|
||||||
|
It++;
|
||||||
|
else
|
||||||
|
It = mountableDevices.erase (It);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new devices
|
||||||
|
for (std::vector<HostDevice>::iterator It = newList.begin(); It != newList.end(); It++)
|
||||||
|
{
|
||||||
|
if (existingDevicesMap[It->SystemNumber])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
HANDLE disk = CreateFile( It->Path.c_str(),
|
||||||
|
0,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
0,
|
||||||
|
NULL );
|
||||||
|
if ( INVALID_HANDLE_VALUE != disk)
|
||||||
|
{
|
||||||
|
bool bIsDynamic = false;
|
||||||
|
bool bHasPartition = false;
|
||||||
|
if (DeviceIoControl(
|
||||||
|
disk,
|
||||||
|
IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
(LPVOID) buffer.data(),
|
||||||
|
(DWORD) buffer.size(),
|
||||||
|
(LPDWORD) &bytesReturned,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
PDRIVE_LAYOUT_INFORMATION_EX layout = (PDRIVE_LAYOUT_INFORMATION_EX) buffer.data();
|
||||||
|
for (DWORD i = 0; i < layout->PartitionCount; i++)
|
||||||
|
{
|
||||||
|
if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_MBR)
|
||||||
|
{
|
||||||
|
if (layout->PartitionEntry[i].Mbr.PartitionType == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bHasPartition = true;
|
||||||
|
|
||||||
|
/* skip dynamic volume */
|
||||||
|
if (layout->PartitionEntry[i].Mbr.PartitionType == PARTITION_LDM)
|
||||||
|
{
|
||||||
|
bIsDynamic = true;
|
||||||
|
/* remove any partition that may have been added */
|
||||||
|
while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber))
|
||||||
|
mountableDevices.pop_back ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (layout->PartitionEntry[i].PartitionStyle == PARTITION_STYLE_GPT)
|
||||||
|
{
|
||||||
|
if (IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_ENTRY_UNUSED_GUID))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bHasPartition = true;
|
||||||
|
|
||||||
|
/* skip dynamic volume */
|
||||||
|
if ( IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_METADATA_GUID)
|
||||||
|
|| IsEqualGUID(layout->PartitionEntry[i].Gpt.PartitionType, PARTITION_LDM_DATA_GUID)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
bIsDynamic = true;
|
||||||
|
/* remove any partition that may have been added */
|
||||||
|
while (!mountableDevices.empty() && (mountableDevices.back().SystemNumber == It->SystemNumber))
|
||||||
|
mountableDevices.pop_back ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WCHAR path[MAX_PATH];
|
||||||
|
StringCbPrintfW (path, sizeof(path), L"\\\\?\\GLOBALROOT\\Device\\Harddisk%d\\Partition%d", It->SystemNumber, layout->PartitionEntry[i].PartitionNumber);
|
||||||
|
HANDLE handle = CreateFile( path,
|
||||||
|
0,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
0,
|
||||||
|
NULL );
|
||||||
|
if (handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
AddDeviceToList (mountableDevices, It->SystemNumber, layout->PartitionEntry[i].PartitionNumber);
|
||||||
|
CloseHandle (handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsDynamic)
|
||||||
|
dynamicVolumesPresent = true;
|
||||||
|
|
||||||
|
if (!bHasPartition)
|
||||||
|
AddDeviceToList (mountableDevices, It->SystemNumber, 0);
|
||||||
|
|
||||||
|
CloseHandle (disk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rawHostDeviceList = newList;
|
||||||
|
|
||||||
|
// Starting from Vista, Windows does not create partition links for dynamic volumes so it is necessary to scan \\Device\\HarddiskVolumeX devices
|
||||||
|
if (dynamicVolumesPresent && (CurrentOSMajor >= 6))
|
||||||
|
{
|
||||||
|
for (int devNumber = 0; devNumber < 256; devNumber++)
|
||||||
|
{
|
||||||
|
wstringstream strm;
|
||||||
|
strm << L"\\Device\\HarddiskVolume" << devNumber;
|
||||||
|
wstring devPathStr (strm.str());
|
||||||
|
const wchar_t *devPath = devPathStr.c_str();
|
||||||
|
|
||||||
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
|
if (!OpenDevice (devPath, &openTest, FALSE, FALSE))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DISK_PARTITION_INFO_STRUCT info;
|
||||||
|
if (GetDeviceInfo (devPath, &info) && info.IsDynamic)
|
||||||
|
{
|
||||||
|
HostDevice device;
|
||||||
|
device.SystemNumber = devNumber;
|
||||||
|
device.Path = devPath;
|
||||||
|
|
||||||
|
mountableDevices.push_back (device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
||||||
{
|
{
|
||||||
|
static std::vector<HostDevice> volumeIdCandidates;
|
||||||
|
|
||||||
/* if it is already mounted, get the real path name used for mounting */
|
/* if it is already mounted, get the real path name used for mounting */
|
||||||
MOUNT_LIST_STRUCT mlist;
|
MOUNT_LIST_STRUCT mlist;
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
@@ -11678,30 +12017,88 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
|||||||
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if (mlist.ulMountedDrives)
|
||||||
|
{
|
||||||
for (int i=0 ; i < 26; i++)
|
for (int i=0 ; i < 26; i++)
|
||||||
{
|
{
|
||||||
if (0 == memcmp (mlist.volumeID[i], volumeID, VOLUME_ID_SIZE))
|
if ((mlist.ulMountedDrives & (1 << i)) && (0 == memcmp (mlist.volumeID[i], volumeID, VOLUME_ID_SIZE)))
|
||||||
return mlist.wszVolume[i];
|
return mlist.wszVolume[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* not mounted. Look for it in the local drives*/
|
/* not mounted. Look for it in the local drives*/
|
||||||
for (int devNumber = 0; devNumber < MAX_HOST_DRIVE_NUMBER; devNumber++)
|
|
||||||
{
|
|
||||||
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
|
|
||||||
{
|
|
||||||
wstringstream strm;
|
|
||||||
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
EnterCriticalSection (&csMountableDevices);
|
||||||
if (!OpenDevice (devPath, &openTest, FALSE, TRUE, volumeID))
|
std::vector<HostDevice> newDevices = mountableDevices;
|
||||||
|
LeaveCriticalSection (&csMountableDevices);
|
||||||
|
|
||||||
|
EnterCriticalSection (&csVolumeIdCandidates);
|
||||||
|
finally_do ({ LeaveCriticalSection (&csVolumeIdCandidates); });
|
||||||
|
|
||||||
|
/* remove any devices that don't exist anymore */
|
||||||
|
for (std::vector<HostDevice>::iterator It = volumeIdCandidates.begin();
|
||||||
|
It != volumeIdCandidates.end();)
|
||||||
{
|
{
|
||||||
continue;
|
bool bFound = false;
|
||||||
|
for (std::vector<HostDevice>::iterator newIt = newDevices.begin();
|
||||||
|
newIt != newDevices.end(); newIt++)
|
||||||
|
{
|
||||||
|
if (It->Path == newIt->Path)
|
||||||
|
{
|
||||||
|
bFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openTest.VolumeIDMatched)
|
if (bFound)
|
||||||
return devPath;
|
It++;
|
||||||
|
else
|
||||||
|
It = volumeIdCandidates.erase (It);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add newly inserted devices and compute their VolumeID */
|
||||||
|
for (std::vector<HostDevice>::iterator newIt = newDevices.begin();
|
||||||
|
newIt != newDevices.end(); newIt++)
|
||||||
|
{
|
||||||
|
bool bFound = false;
|
||||||
|
|
||||||
|
for (std::vector<HostDevice>::iterator It = volumeIdCandidates.begin();
|
||||||
|
It != volumeIdCandidates.end(); It++)
|
||||||
|
{
|
||||||
|
if (It->Path == newIt->Path)
|
||||||
|
{
|
||||||
|
bFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bFound)
|
||||||
|
{
|
||||||
|
/* new device/partition. Compute its Volume IDs */
|
||||||
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
|
if (OpenDevice (newIt->Path.c_str(), &openTest, TRUE, TRUE)
|
||||||
|
&& (openTest.VolumeIDComputed[TC_VOLUME_TYPE_NORMAL] && openTest.VolumeIDComputed[TC_VOLUME_TYPE_HIDDEN])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
memcpy (newIt->VolumeIDs, openTest.volumeIDs, sizeof (newIt->VolumeIDs));
|
||||||
|
newIt->HasVolumeIDs = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
newIt->HasVolumeIDs = false;
|
||||||
|
volumeIdCandidates.push_back (*newIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::vector<HostDevice>::iterator It = volumeIdCandidates.begin();
|
||||||
|
It != volumeIdCandidates.end(); It++)
|
||||||
|
{
|
||||||
|
if ( It->HasVolumeIDs &&
|
||||||
|
( (0 == memcmp (volumeID, It->VolumeIDs[TC_VOLUME_TYPE_NORMAL], VOLUME_ID_SIZE))
|
||||||
|
|| (0 == memcmp (volumeID, It->VolumeIDs[TC_VOLUME_TYPE_HIDDEN], VOLUME_ID_SIZE))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return It->Path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11922,7 +12319,7 @@ BOOL DisableFileCompression (HANDLE file)
|
|||||||
return DeviceIoControl (file, FSCTL_SET_COMPRESSION, &format, sizeof (format), NULL, 0, &bytesOut, NULL);
|
return DeviceIoControl (file, FSCTL_SET_COMPRESSION, &format, sizeof (format), NULL, 0, &bytesOut, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SETUP
|
||||||
BOOL VolumePathExists (const wchar_t *volumePath)
|
BOOL VolumePathExists (const wchar_t *volumePath)
|
||||||
{
|
{
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
@@ -11931,7 +12328,7 @@ BOOL VolumePathExists (const wchar_t *volumePath)
|
|||||||
UpperCaseCopy (upperCasePath, sizeof(upperCasePath), volumePath);
|
UpperCaseCopy (upperCasePath, sizeof(upperCasePath), volumePath);
|
||||||
|
|
||||||
if (wcsstr (upperCasePath, L"\\DEVICE\\") == upperCasePath)
|
if (wcsstr (upperCasePath, L"\\DEVICE\\") == upperCasePath)
|
||||||
return OpenDevice (volumePath, &openTest, FALSE, FALSE, NULL);
|
return OpenDevice (volumePath, &openTest, FALSE, FALSE);
|
||||||
|
|
||||||
wstring path = volumePath;
|
wstring path = volumePath;
|
||||||
if (path.find (L"\\\\?\\Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
|
if (path.find (L"\\\\?\\Volume{") == 0 && path.rfind (L"}\\") == path.size() - 2)
|
||||||
@@ -12039,6 +12436,7 @@ std::wstring HarddiskVolumePathToPartitionPath (const std::wstring &harddiskVolu
|
|||||||
return wstring();
|
return wstring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp)
|
BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ void InitOSVersionInfo ();
|
|||||||
void InitApp ( HINSTANCE hInstance, wchar_t *lpszCommandLine );
|
void InitApp ( HINSTANCE hInstance, wchar_t *lpszCommandLine );
|
||||||
void FinalizeApp (void);
|
void FinalizeApp (void);
|
||||||
void InitHelpFileName (void);
|
void InitHelpFileName (void);
|
||||||
BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem, BOOL matchVolumeID, const BYTE* pbVolumeID);
|
BOOL OpenDevice (const wchar_t *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFilesystem, BOOL computeVolumeID);
|
||||||
void NotifyDriverOfPortableMode (void);
|
void NotifyDriverOfPortableMode (void);
|
||||||
int GetAvailableFixedDisks ( HWND hComboBox , char *lpszRootPath );
|
int GetAvailableFixedDisks ( HWND hComboBox , char *lpszRootPath );
|
||||||
int GetAvailableRemovables ( HWND hComboBox , char *lpszRootPath );
|
int GetAvailableRemovables ( HWND hComboBox , char *lpszRootPath );
|
||||||
@@ -543,8 +543,31 @@ struct HostDevice
|
|||||||
HasUnencryptedFilesystem (false),
|
HasUnencryptedFilesystem (false),
|
||||||
Removable (false),
|
Removable (false),
|
||||||
Size (0),
|
Size (0),
|
||||||
SystemNumber((uint32) -1)
|
SystemNumber((uint32) -1),
|
||||||
|
HasVolumeIDs (false)
|
||||||
{
|
{
|
||||||
|
ZeroMemory (VolumeIDs, sizeof (VolumeIDs));
|
||||||
|
}
|
||||||
|
|
||||||
|
HostDevice (const HostDevice& device)
|
||||||
|
:
|
||||||
|
Bootable (device.Bootable),
|
||||||
|
ContainsSystem (device.ContainsSystem),
|
||||||
|
DynamicVolume (device.DynamicVolume),
|
||||||
|
Floppy (device.Floppy),
|
||||||
|
IsPartition (device.IsPartition),
|
||||||
|
IsVirtualPartition (device.IsVirtualPartition),
|
||||||
|
HasUnencryptedFilesystem (device.HasUnencryptedFilesystem),
|
||||||
|
MountPoint (device.MountPoint),
|
||||||
|
Name (device.Name),
|
||||||
|
Path (device.Path),
|
||||||
|
Removable (device.Removable),
|
||||||
|
Size (device.Size),
|
||||||
|
SystemNumber (device.SystemNumber),
|
||||||
|
HasVolumeIDs (device.HasVolumeIDs),
|
||||||
|
Partitions (device.Partitions)
|
||||||
|
{
|
||||||
|
memcpy (VolumeIDs, device.VolumeIDs, sizeof (VolumeIDs));
|
||||||
}
|
}
|
||||||
|
|
||||||
~HostDevice () {}
|
~HostDevice () {}
|
||||||
@@ -562,6 +585,8 @@ struct HostDevice
|
|||||||
bool Removable;
|
bool Removable;
|
||||||
uint64 Size;
|
uint64 Size;
|
||||||
uint32 SystemNumber;
|
uint32 SystemNumber;
|
||||||
|
BYTE VolumeIDs[TC_VOLUME_TYPE_COUNT][VOLUME_ID_SIZE];
|
||||||
|
bool HasVolumeIDs;
|
||||||
|
|
||||||
std::vector <HostDevice> Partitions;
|
std::vector <HostDevice> Partitions;
|
||||||
};
|
};
|
||||||
@@ -597,6 +622,7 @@ inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos)
|
|||||||
{
|
{
|
||||||
return std::wstring (msg? msg : L"") + L"\n\nSource: " + SingleStringToWide (srcPos);
|
return std::wstring (msg? msg : L"") + L"\n\nSource: " + SingleStringToWide (srcPos);
|
||||||
}
|
}
|
||||||
|
void UpdateMountableHostDeviceList ();
|
||||||
|
|
||||||
// Display a wait dialog while calling the provided callback with the given parameter
|
// Display a wait dialog while calling the provided callback with the given parameter
|
||||||
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
|
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
|
||||||
|
|||||||
@@ -203,6 +203,16 @@ void DumpMemory (void *mem, int size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL IsAllZeroes (unsigned char* pbData, DWORD dwDataLen)
|
||||||
|
{
|
||||||
|
while (dwDataLen--)
|
||||||
|
{
|
||||||
|
if (*pbData)
|
||||||
|
return FALSE;
|
||||||
|
pbData++;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL ValidateIOBufferSize (PIRP irp, size_t requiredBufferSize, ValidateIOBufferSizeType type)
|
BOOL ValidateIOBufferSize (PIRP irp, size_t requiredBufferSize, ValidateIOBufferSizeType type)
|
||||||
{
|
{
|
||||||
@@ -1293,7 +1303,7 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
|
|||||||
|
|
||||||
InitializeObjectAttributes (&ObjectAttributes, &FullFileName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
InitializeObjectAttributes (&ObjectAttributes, &FullFileName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
||||||
|
|
||||||
if (opentest->bDetectTCBootLoader || opentest->DetectFilesystem || opentest->bMatchVolumeID)
|
if (opentest->bDetectTCBootLoader || opentest->DetectFilesystem || opentest->bComputeVolumeIDs)
|
||||||
access |= FILE_READ_DATA;
|
access |= FILE_READ_DATA;
|
||||||
|
|
||||||
ntStatus = ZwCreateFile (&NtFileHandle,
|
ntStatus = ZwCreateFile (&NtFileHandle,
|
||||||
@@ -1304,9 +1314,10 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
|
|||||||
{
|
{
|
||||||
opentest->TCBootLoaderDetected = FALSE;
|
opentest->TCBootLoaderDetected = FALSE;
|
||||||
opentest->FilesystemDetected = FALSE;
|
opentest->FilesystemDetected = FALSE;
|
||||||
opentest->VolumeIDMatched = FALSE;
|
memset (opentest->VolumeIDComputed, 0, sizeof (opentest->VolumeIDComputed));
|
||||||
|
memset (opentest->volumeIDs, 0, sizeof (opentest->volumeIDs));
|
||||||
|
|
||||||
if (opentest->bDetectTCBootLoader || opentest->DetectFilesystem || opentest->bMatchVolumeID)
|
if (opentest->bDetectTCBootLoader || opentest->DetectFilesystem || opentest->bComputeVolumeIDs)
|
||||||
{
|
{
|
||||||
byte *readBuffer = TCalloc (TC_MAX_VOLUME_SECTOR_SIZE);
|
byte *readBuffer = TCalloc (TC_MAX_VOLUME_SECTOR_SIZE);
|
||||||
if (!readBuffer)
|
if (!readBuffer)
|
||||||
@@ -1352,15 +1363,20 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
|
|||||||
{
|
{
|
||||||
switch (BE64 (*(uint64 *) readBuffer))
|
switch (BE64 (*(uint64 *) readBuffer))
|
||||||
{
|
{
|
||||||
case 0xEB52904E54465320: // NTFS
|
case 0xEB52904E54465320ULL: // NTFS
|
||||||
case 0xEB3C904D53444F53: // FAT16/FAT32
|
case 0xEB3C904D53444F53ULL: // FAT16/FAT32
|
||||||
case 0xEB58904D53444F53: // FAT32
|
case 0xEB58904D53444F53ULL: // FAT32
|
||||||
case 0xEB76904558464154: // exFAT
|
case 0xEB76904558464154ULL: // exFAT
|
||||||
case 0x0000005265465300: // ReFS
|
case 0x0000005265465300ULL: // ReFS
|
||||||
case 0xEB58906D6B66732E: // FAT32 mkfs.fat
|
case 0xEB58906D6B66732EULL: // FAT32 mkfs.fat
|
||||||
case 0xEB58906D6B646F73: // FAT32 mkfs.vfat/mkdosfs
|
case 0xEB58906D6B646F73ULL: // FAT32 mkfs.vfat/mkdosfs
|
||||||
case 0xEB3C906D6B66732E: // FAT16/FAT12 mkfs.fat
|
case 0xEB3C906D6B66732EULL: // FAT16/FAT12 mkfs.fat
|
||||||
case 0xEB3C906D6B646F73: // FAT16/FAT12 mkfs.vfat/mkdosfs
|
case 0xEB3C906D6B646F73ULL: // FAT16/FAT12 mkfs.vfat/mkdosfs
|
||||||
|
opentest->FilesystemDetected = TRUE;
|
||||||
|
break;
|
||||||
|
case 0x0000000000000000ULL:
|
||||||
|
// all 512 bytes are zeroes => unencrypted filesystem like Microsoft reserved partition
|
||||||
|
if (IsAllZeroes (readBuffer + 8, TC_VOLUME_HEADER_EFFECTIVE_SIZE - 8))
|
||||||
opentest->FilesystemDetected = TRUE;
|
opentest->FilesystemDetected = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1368,11 +1384,9 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opentest->bMatchVolumeID)
|
if (opentest->bComputeVolumeIDs && (!opentest->DetectFilesystem || !opentest->FilesystemDetected))
|
||||||
{
|
{
|
||||||
int volumeType;
|
int volumeType;
|
||||||
BYTE volumeID[VOLUME_ID_SIZE];
|
|
||||||
|
|
||||||
// Go through all volume types (e.g., normal, hidden)
|
// Go through all volume types (e.g., normal, hidden)
|
||||||
for (volumeType = TC_VOLUME_TYPE_NORMAL;
|
for (volumeType = TC_VOLUME_TYPE_NORMAL;
|
||||||
volumeType < TC_VOLUME_TYPE_COUNT;
|
volumeType < TC_VOLUME_TYPE_COUNT;
|
||||||
@@ -1404,13 +1418,8 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
|
|||||||
if (NT_SUCCESS (ntStatus))
|
if (NT_SUCCESS (ntStatus))
|
||||||
{
|
{
|
||||||
/* compute the ID of this volume: SHA-256 of the effective header */
|
/* compute the ID of this volume: SHA-256 of the effective header */
|
||||||
sha256 (volumeID, readBuffer, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
|
sha256 (opentest->volumeIDs[volumeType], readBuffer, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
|
||||||
|
opentest->VolumeIDComputed[volumeType] = TRUE;
|
||||||
if (0 == memcmp (volumeID, opentest->volumeID, VOLUME_ID_SIZE))
|
|
||||||
{
|
|
||||||
opentest->VolumeIDMatched = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ using namespace VeraCrypt;
|
|||||||
enum timer_ids
|
enum timer_ids
|
||||||
{
|
{
|
||||||
TIMER_ID_MAIN = 0xff,
|
TIMER_ID_MAIN = 0xff,
|
||||||
TIMER_ID_KEYB_LAYOUT_GUARD
|
TIMER_ID_KEYB_LAYOUT_GUARD,
|
||||||
|
TIMER_ID_UPDATE_DEVICE_LIST
|
||||||
};
|
};
|
||||||
|
|
||||||
enum hidden_os_read_only_notif_mode
|
enum hidden_os_read_only_notif_mode
|
||||||
@@ -73,6 +74,7 @@ enum hidden_os_read_only_notif_mode
|
|||||||
|
|
||||||
#define TIMER_INTERVAL_MAIN 500
|
#define TIMER_INTERVAL_MAIN 500
|
||||||
#define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10
|
#define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10
|
||||||
|
#define TIMER_INTERVAL_UPDATE_DEVICE_LIST 1000
|
||||||
|
|
||||||
BootEncryption *BootEncObj = NULL;
|
BootEncryption *BootEncObj = NULL;
|
||||||
BootEncryptionStatus BootEncStatus;
|
BootEncryptionStatus BootEncStatus;
|
||||||
@@ -290,6 +292,7 @@ void EndMainDlg (HWND hwndDlg)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
KillTimer (hwndDlg, TIMER_ID_MAIN);
|
KillTimer (hwndDlg, TIMER_ID_MAIN);
|
||||||
|
KillTimer (hwndDlg, TIMER_ID_UPDATE_DEVICE_LIST);
|
||||||
TaskBarIconRemove (hwndDlg);
|
TaskBarIconRemove (hwndDlg);
|
||||||
UnregisterWtsNotification(hwndDlg);
|
UnregisterWtsNotification(hwndDlg);
|
||||||
EndDialog (hwndDlg, 0);
|
EndDialog (hwndDlg, 0);
|
||||||
@@ -1482,6 +1485,7 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
|
|||||||
if (bResult == FALSE)
|
if (bResult == FALSE)
|
||||||
{
|
{
|
||||||
KillTimer (MainDlg, TIMER_ID_MAIN);
|
KillTimer (MainDlg, TIMER_ID_MAIN);
|
||||||
|
KillTimer (hwndDlg, TIMER_ID_UPDATE_DEVICE_LIST);
|
||||||
handleWin32Error (hTree, SRC_POS);
|
handleWin32Error (hTree, SRC_POS);
|
||||||
AbortProcessSilent();
|
AbortProcessSilent();
|
||||||
}
|
}
|
||||||
@@ -4978,6 +4982,8 @@ retry:
|
|||||||
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
|
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
|
||||||
|
|
||||||
// remove any custom label from registry
|
// remove any custom label from registry
|
||||||
|
if (prevMountList.ulMountedDrives)
|
||||||
|
{
|
||||||
for (i = 0; i < 26; i++)
|
for (i = 0; i < 26; i++)
|
||||||
{
|
{
|
||||||
if ((prevMountList.ulMountedDrives & (1 << i)) && (!(mountList.ulMountedDrives & (1 << i))) && wcslen (prevMountList.wszLabel[i]))
|
if ((prevMountList.ulMountedDrives & (1 << i)) && (!(mountList.ulMountedDrives & (1 << i))) && wcslen (prevMountList.wszLabel[i]))
|
||||||
@@ -4985,6 +4991,7 @@ retry:
|
|||||||
UpdateDriveCustomLabel (i, prevMountList.wszLabel[i], FALSE);
|
UpdateDriveCustomLabel (i, prevMountList.wszLabel[i], FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountList.ulMountedDrives & ~mountList.ulMountedDrives);
|
BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountList.ulMountedDrives & ~mountList.ulMountedDrives);
|
||||||
|
|
||||||
@@ -5013,6 +5020,8 @@ retry:
|
|||||||
// Undo SHCNE_DRIVEREMOVED
|
// Undo SHCNE_DRIVEREMOVED
|
||||||
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, NULL, 0, &mountList, sizeof (mountList), &dwResult, NULL);
|
DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, NULL, 0, &mountList, sizeof (mountList), &dwResult, NULL);
|
||||||
|
|
||||||
|
if (mountList.ulMountedDrives)
|
||||||
|
{
|
||||||
for (i = 0; i < 26; i++)
|
for (i = 0; i < 26; i++)
|
||||||
{
|
{
|
||||||
if (mountList.ulMountedDrives & (1 << i))
|
if (mountList.ulMountedDrives & (1 << i))
|
||||||
@@ -5022,6 +5031,7 @@ retry:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -6799,6 +6809,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
|
|
||||||
GetMountList (&LastKnownMountList);
|
GetMountList (&LastKnownMountList);
|
||||||
SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
|
SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
|
||||||
|
SetTimer (hwndDlg, TIMER_ID_UPDATE_DEVICE_LIST, TIMER_INTERVAL_UPDATE_DEVICE_LIST, NULL);
|
||||||
|
|
||||||
taskBarCreatedMsg = RegisterWindowMessage (L"TaskbarCreated");
|
taskBarCreatedMsg = RegisterWindowMessage (L"TaskbarCreated");
|
||||||
|
|
||||||
@@ -6954,6 +6965,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
|
{
|
||||||
|
if (wParam == TIMER_ID_UPDATE_DEVICE_LIST)
|
||||||
|
{
|
||||||
|
UpdateMountableHostDeviceList ();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Check mount list and update GUI if needed
|
// Check mount list and update GUI if needed
|
||||||
CheckMountList (hwndDlg, FALSE);
|
CheckMountList (hwndDlg, FALSE);
|
||||||
@@ -7146,6 +7163,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
case TC_APPMSG_TASKBAR_ICON:
|
case TC_APPMSG_TASKBAR_ICON:
|
||||||
{
|
{
|
||||||
@@ -7316,7 +7334,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
|
|
||||||
for (i = 0; i < 26; i++)
|
for (i = 0; i < 26; i++)
|
||||||
{
|
{
|
||||||
if ((vol->dbcv_unitmask & (1 << i)) && !(GetUsedLogicalDrives() & (1 << i)))
|
if (LastKnownMountList.ulMountedDrives && (vol->dbcv_unitmask & (1 << i)) && !(GetUsedLogicalDrives() & (1 << i)))
|
||||||
{
|
{
|
||||||
for (m = 0; m < 26; m++)
|
for (m = 0; m < 26; m++)
|
||||||
{
|
{
|
||||||
@@ -7352,7 +7370,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
{
|
{
|
||||||
OPEN_TEST_STRUCT ots = {0};
|
OPEN_TEST_STRUCT ots = {0};
|
||||||
|
|
||||||
if (!OpenDevice (vol, &ots, FALSE, FALSE, NULL))
|
if (!OpenDevice (vol, &ots, FALSE, FALSE))
|
||||||
{
|
{
|
||||||
UnmountVolume (hwndDlg, m, TRUE);
|
UnmountVolume (hwndDlg, m, TRUE);
|
||||||
WarningBalloon ("HOST_DEVICE_REMOVAL_DISMOUNT_WARN_TITLE", "HOST_DEVICE_REMOVAL_DISMOUNT_WARN", hwndDlg);
|
WarningBalloon ("HOST_DEVICE_REMOVAL_DISMOUNT_WARN_TITLE", "HOST_DEVICE_REMOVAL_DISMOUNT_WARN", hwndDlg);
|
||||||
|
|||||||
Reference in New Issue
Block a user