"Fossies" - the Fresh Open Source Software Archive

Member "src/Driver/Ntdriver.h" (10 Oct 2018, 9338 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Ntdriver.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.22_Source_vs_1.23_Source.

    1 /*
    2  Legal Notice: Some portions of the source code contained in this file were
    3  derived from the source code of TrueCrypt 7.1a, which is
    4  Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
    5  governed by the TrueCrypt License 3.0, also from the source code of
    6  Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
    7  and which is governed by the 'License Agreement for Encryption for the Masses'
    8  Modifications and additions to the original source code (contained in this file)
    9  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
   10  and are governed by the Apache License 2.0 the full text of which is
   11  contained in the file License.txt included in VeraCrypt binary and source
   12  code distribution packages. */
   13 
   14 #ifndef TC_HEADER_NTDRIVER
   15 #define TC_HEADER_NTDRIVER
   16 
   17 #include "Common.h"
   18 #include "EncryptedIoQueue.h"
   19 
   20 /* This structure is used to start new threads */
   21 typedef struct _THREAD_BLOCK_
   22 {
   23     PDEVICE_OBJECT DeviceObject;
   24     NTSTATUS ntCreateStatus;
   25     WCHAR wszMountVolume[TC_MAX_PATH + 8];
   26     MOUNT_STRUCT *mount;
   27 } THREAD_BLOCK, *PTHREAD_BLOCK;
   28 
   29 
   30 /* This structure is allocated for non-root devices! WARNING: bRootDevice
   31    must be the first member of the structure! */
   32 typedef struct EXTENSION
   33 {
   34     BOOL bRootDevice;   /* Is this the root device ? which the user-mode apps talk to */
   35     BOOL IsVolumeDevice;
   36     BOOL IsDriveFilterDevice;
   37     BOOL IsVolumeFilterDevice;
   38 
   39     int UniqueVolumeId;
   40     int nDosDriveNo;    /* Drive number this extension is mounted against */
   41 
   42     BOOL bShuttingDown;         /* Is the driver shutting down ? */
   43     BOOL bThreadShouldQuit;     /* Instruct per device worker thread to quit */
   44     PETHREAD peThread;          /* Thread handle */
   45     KEVENT keCreateEvent;       /* Device creation event */
   46     KSPIN_LOCK ListSpinLock;    /* IRP spinlock */
   47     LIST_ENTRY ListEntry;       /* IRP listentry */
   48     KSEMAPHORE RequestSemaphore;    /* IRP list request  Semaphore */
   49 
   50     HANDLE hDeviceFile;         /* Device handle for this device */
   51     PFILE_OBJECT pfoDeviceFile; /* Device fileobject for this device */
   52     PDEVICE_OBJECT pFsdDevice;  /* lower level device handle */
   53 
   54     CRYPTO_INFO *cryptoInfo;    /* Cryptographic and other information for this device */
   55 
   56     __int64 HostLength;
   57     __int64 DiskLength;         /* The length of the disk referred to by this device */
   58     __int64 NumberOfCylinders;      /* Partition info */
   59     ULONG TracksPerCylinder;    /* Partition info */
   60     ULONG SectorsPerTrack;      /* Partition info */
   61     ULONG BytesPerSector;       /* Partition info */
   62     UCHAR PartitionType;        /* Partition info */
   63 
   64     uint32 HostBytesPerSector;
   65     uint32 HostBytesPerPhysicalSector;
   66     ULONG HostMaximumTransferLength;
   67     ULONG HostMaximumPhysicalPages;
   68     ULONG HostAlignmentMask;
   69     ULONG DeviceNumber;
   70 
   71     BOOL IncursSeekPenalty;
   72     BOOL TrimEnabled;
   73 
   74     KEVENT keVolumeEvent;       /* Event structure used when setting up a device */
   75 
   76     EncryptedIoQueue Queue;
   77 
   78     BOOL bReadOnly;             /* Is this device read-only ? */
   79     BOOL bRemovable;            /* Is this device removable media ? */
   80     BOOL PartitionInInactiveSysEncScope;
   81     BOOL bRawDevice;            /* Is this a raw-partition or raw-floppy device ? */
   82     BOOL bMountManager;         /* Mount manager knows about volume */
   83     BOOL SystemFavorite;
   84 
   85     WCHAR wszVolume[TC_MAX_PATH];   /*  DONT change this size without also changing MOUNT_LIST_STRUCT! */
   86     WCHAR wszLabel[33];
   87     BOOL bIsNTFS;
   88     BOOL bDriverSetLabel;
   89 
   90     unsigned char volumeID[VOLUME_ID_SIZE];
   91 
   92     LARGE_INTEGER fileCreationTime;
   93     LARGE_INTEGER fileLastAccessTime;
   94     LARGE_INTEGER fileLastWriteTime;
   95     LARGE_INTEGER fileLastChangeTime;
   96     BOOL bTimeStampValid;
   97 
   98     PSID UserSid;
   99     BOOL SecurityClientContextValid;
  100     SECURITY_CLIENT_CONTEXT SecurityClientContext;
  101 
  102 } EXTENSION, *PEXTENSION;
  103 
  104 
  105 typedef enum
  106 {
  107     ValidateInput,
  108     ValidateOutput,
  109     ValidateInputOutput
  110 } ValidateIOBufferSizeType;
  111 
  112 typedef enum
  113 {
  114     DeviceNamespaceDefault,
  115     DeviceNamespaceGlobal,
  116 } DeviceNamespaceType;
  117 
  118 extern PDRIVER_OBJECT TCDriverObject;
  119 extern PDEVICE_OBJECT RootDeviceObject;
  120 extern BOOL DriverShuttingDown;
  121 extern ULONG OsMajorVersion;
  122 extern ULONG OsMinorVersion;
  123 extern BOOL VolumeClassFilterRegistered;
  124 extern BOOL CacheBootPassword;
  125 extern BOOL CacheBootPim;
  126 extern BOOL BlockSystemTrimCommand;
  127 extern BOOL AllowWindowsDefrag;
  128 /* Helper macro returning x seconds in units of 100 nanoseconds */
  129 #define WAIT_SECONDS(x) ((x)*10000000)
  130 
  131 NTSTATUS DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
  132 NTSTATUS DriverAddDevice (PDRIVER_OBJECT driverObject, PDEVICE_OBJECT pdo);
  133 void DumpMemory (void *memory, int size);
  134 BOOL IsAccessibleByUser (PUNICODE_STRING objectFileName, BOOL readOnly);
  135 NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, PIRP Irp);
  136 NTSTATUS ProcessVolumeDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, PIRP Irp);
  137 NTSTATUS SendDeviceIoControlRequest (PDEVICE_OBJECT deviceObject, ULONG ioControlCode, void *inputBuffer, int inputBufferSize, void *outputBuffer, int outputBufferSize);
  138 NTSTATUS TCDispatchQueueIRP (PDEVICE_OBJECT DeviceObject, PIRP Irp);
  139 NTSTATUS TCCreateRootDeviceObject (PDRIVER_OBJECT DriverObject);
  140 NTSTATUS TCCreateDeviceObject (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT * ppDeviceObject, MOUNT_STRUCT * mount);
  141 NTSTATUS TCReadDevice (PDEVICE_OBJECT deviceObject, PVOID buffer, LARGE_INTEGER offset, ULONG length);
  142 NTSTATUS TCWriteDevice (PDEVICE_OBJECT deviceObject, PVOID buffer, LARGE_INTEGER offset, ULONG length);
  143 NTSTATUS TCStartThread (PKSTART_ROUTINE threadProc, PVOID threadArg, PKTHREAD *kThread);
  144 NTSTATUS TCStartThreadInProcess (PKSTART_ROUTINE threadProc, PVOID threadArg, PKTHREAD *kThread, PEPROCESS process);
  145 NTSTATUS TCStartVolumeThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, MOUNT_STRUCT * mount);
  146 void TCStopThread (PKTHREAD kThread, PKEVENT wakeUpEvent);
  147 void TCStopVolumeThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension);
  148 VOID VolumeThreadProc (PVOID Context);
  149 void TCSleep (int milliSeconds);
  150 void TCGetNTNameFromNumber (LPWSTR ntname, int cbNtName, int nDriveNo);
  151 void TCGetDosNameFromNumber (LPWSTR dosname, int cbDosName, int nDriveNo, DeviceNamespaceType namespaceType);
  152 LPWSTR TCTranslateCode (ULONG ulCode);
  153 void TCDeleteDeviceObject (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension);
  154 VOID TCUnloadDriver (PDRIVER_OBJECT DriverObject);
  155 void OnShutdownPending ();
  156 NTSTATUS TCDeviceIoControl (PWSTR deviceName, ULONG IoControlCode, void *InputBuffer, ULONG InputBufferSize, void *OutputBuffer, ULONG OutputBufferSize);
  157 NTSTATUS TCOpenFsVolume (PEXTENSION Extension, PHANDLE volumeHandle, PFILE_OBJECT * fileObject);
  158 void TCCloseFsVolume (HANDLE volumeHandle, PFILE_OBJECT fileObject);
  159 NTSTATUS TCFsctlCall (PFILE_OBJECT fileObject, LONG IoControlCode, void *InputBuffer, int InputBufferSize, void *OutputBuffer, int OutputBufferSize);
  160 NTSTATUS CreateDriveLink (int nDosDriveNo);
  161 NTSTATUS RemoveDriveLink (int nDosDriveNo);
  162 NTSTATUS MountManagerMount (MOUNT_STRUCT *mount);
  163 NTSTATUS MountManagerUnmount (int nDosDriveNo);
  164 NTSTATUS MountDevice (PDEVICE_OBJECT deviceObject, MOUNT_STRUCT *mount);
  165 NTSTATUS UnmountDevice (UNMOUNT_STRUCT *unmountRequest, PDEVICE_OBJECT deviceObject, BOOL ignoreOpenFiles);
  166 NTSTATUS UnmountAllDevices (UNMOUNT_STRUCT *unmountRequest, BOOL ignoreOpenFiles);
  167 NTSTATUS SymbolicLinkToTarget (PWSTR symlinkName, PWSTR targetName, USHORT maxTargetNameLength);
  168 BOOL RootDeviceControlMutexAcquireNoWait ();
  169 void RootDeviceControlMutexRelease ();
  170 BOOL RegionsOverlap (unsigned __int64 start1, unsigned __int64 end1, unsigned __int64 start2, unsigned __int64 end2);
  171 void GetIntersection (uint64 start1, uint32 length1, uint64 start2, uint64 end2, uint64 *intersectStart, uint32 *intersectLength);
  172 NTSTATUS TCCompleteIrp (PIRP irp, NTSTATUS status, ULONG_PTR information);
  173 NTSTATUS TCCompleteDiskIrp (PIRP irp, NTSTATUS status, ULONG_PTR information);
  174 NTSTATUS ProbeRealDriveSize (PDEVICE_OBJECT driveDeviceObject, LARGE_INTEGER *driveSize);
  175 BOOL UserCanAccessDriveDevice ();
  176 size_t GetCpuCount ();
  177 void EnsureNullTerminatedString (wchar_t *str, size_t maxSizeInBytes);
  178 void *AllocateMemoryWithTimeout (size_t size, int retryDelay, int timeout);
  179 BOOL IsDriveLetterAvailable (int nDosDriveNo, DeviceNamespaceType namespaceType);
  180 NTSTATUS TCReadRegistryKey (PUNICODE_STRING keyPath, wchar_t *keyValueName, PKEY_VALUE_PARTIAL_INFORMATION *keyData);
  181 NTSTATUS TCWriteRegistryKey (PUNICODE_STRING keyPath, wchar_t *keyValueName, ULONG keyValueType, void *valueData, ULONG valueSize);
  182 BOOL IsVolumeClassFilterRegistered ();
  183 NTSTATUS ReadRegistryConfigFlags (BOOL driverEntry);
  184 NTSTATUS WriteRegistryConfigFlags (uint32 flags);
  185 BOOL ValidateIOBufferSize (PIRP irp, size_t requiredBufferSize, ValidateIOBufferSizeType type);
  186 NTSTATUS GetDeviceSectorSize (PDEVICE_OBJECT deviceObject, ULONG *bytesPerSector);
  187 NTSTATUS ZeroUnreadableSectors (PDEVICE_OBJECT deviceObject, LARGE_INTEGER startOffset, ULONG size, uint64 *zeroedSectorCount);
  188 NTSTATUS ReadDeviceSkipUnreadableSectors (PDEVICE_OBJECT deviceObject, byte *buffer, LARGE_INTEGER startOffset, ULONG size, uint64 *badSectorCount);
  189 BOOL IsVolumeAccessibleByCurrentUser (PEXTENSION volumeDeviceExtension);
  190 void GetElapsedTimeInit (LARGE_INTEGER *lastPerfCounter);
  191 int64 GetElapsedTime (LARGE_INTEGER *lastPerfCounter);
  192 BOOL IsOSAtLeast (OSVersionEnum reqMinOS);
  193 
  194 #define TC_BUG_CHECK(status) KeBugCheckEx (SECURITY_SYSTEM, __LINE__, (ULONG_PTR) status, 0, 'VC')
  195 
  196 #endif // TC_HEADER_NTDRIVER