|
|
1.1.1.6 root 1: /* Legal Notice: The source code contained in this file has been derived from
2: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
3: 1998-99 Paul Le Roux and which is covered by the 'License Agreement for
4: Encryption for the Masses'. Modifications and additions to that source code
1.1.1.8 ! root 5: contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.6 root 6: Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0
7: the full text of which is contained in the file License.txt included in
8: TrueCrypt binary and source code distribution archives. */
1.1 root 9:
10: /* This structure is used to start new threads */
11: typedef struct _THREAD_BLOCK_
12: {
13: PDEVICE_OBJECT DeviceObject;
14: NTSTATUS ntCreateStatus;
1.1.1.7 root 15: WCHAR wszMountVolume[TC_MAX_PATH + 8];
1.1 root 16: MOUNT_STRUCT *mount;
17: } THREAD_BLOCK, *PTHREAD_BLOCK;
18:
19: /* This structure is allocated for non-root devices! WARNING: bRootDevice
20: must be the first member of the structure! */
21: typedef struct EXTENSION
22: {
23: BOOL bRootDevice; /* Is this the root device ? which the
24: user-mode apps talk to */
25:
26: ULONG lMagicNumber; /* To ensure the completion routine is not
27: sending us bad IRP's */
28:
1.1.1.6 root 29: int UniqueVolumeId;
1.1 root 30: int nDosDriveNo; /* Drive number this extension is mounted
31: against */
32: BOOL bShuttingDown; /* Is the driver shutting down ? */
33: BOOL bThreadShouldQuit; /* Instruct per device worker thread to quit */
34: PETHREAD peThread; /* Thread handle */
35: KEVENT keCreateEvent; /* Device creation event */
36: KSPIN_LOCK ListSpinLock; /* IRP spinlock */
37: LIST_ENTRY ListEntry; /* IRP listentry */
38: KSEMAPHORE RequestSemaphore; /* IRP list request Semaphore */
39:
40: #ifdef USE_KERNEL_MUTEX
41: KMUTEX KernelMutex; /* Sync. mutex for entire thread */
42: #endif
43:
44: HANDLE hDeviceFile; /* Device handle for this device */
45: PFILE_OBJECT pfoDeviceFile; /* Device fileobject for this device */
46: PDEVICE_OBJECT pFsdDevice; /* lower level device handle */
47:
1.1.1.6 root 48: CRYPTO_INFO *cryptoInfo; /* Cryptographic and other information for this device */
1.1 root 49:
50: __int64 DiskLength; /* The length of the disk referred to by this device */
51: __int64 NumberOfCylinders; /* Partition info */
52: ULONG TracksPerCylinder; /* Partition info */
53: ULONG SectorsPerTrack; /* Partition info */
54: ULONG BytesPerSector; /* Partition info */
55: UCHAR PartitionType; /* Partition info */
56:
57: KEVENT keVolumeEvent; /* Event structure used when setting up a device */
58:
1.1.1.8 ! root 59: BOOL bSystemVolume; /* System volume is hidden from user and supports system files (paging, hibernation). */
! 60: BOOL bPersistentVolume; /* Persistent volume is hidden from user. */
! 61:
1.1.1.4 root 62: BOOL bReadOnly; /* Is this device read-only ? */
63: BOOL bRemovable; /* Is this device removable media ? */
64: BOOL bRawDevice; /* Is this a raw-partition or raw-floppy device ? */
65: BOOL bMountManager; /* Mount manager knows about volume */
1.1 root 66:
1.1.1.7 root 67: WCHAR wszVolume[TC_MAX_PATH]; /* DONT change this size without also changing MOUNT_LIST_STRUCT! */
1.1 root 68:
1.1.1.6 root 69: // Container file date/time (used to reset date and time of file-hosted volumes after dismount or unsuccessful mount attempt, to preserve plausible deniability of hidden volumes).
1.1.1.4 root 70: LARGE_INTEGER fileCreationTime;
71: LARGE_INTEGER fileLastAccessTime;
72: LARGE_INTEGER fileLastWriteTime;
73: LARGE_INTEGER fileLastChangeTime;
1.1.1.6 root 74: BOOL bTimeStampValid;
75:
76: unsigned __int64 TotalBytesRead; // Bytes read from volume
77: unsigned __int64 TotalBytesWritten; // Bytes written to volume
1.1.1.4 root 78:
1.1 root 79: } EXTENSION, *PEXTENSION;
80:
81: /* Helper macro returning x seconds in units of 100 nanoseconds */
1.1.1.4 root 82: #define WAIT_SECONDS(x) ((x)*10000000)
1.1 root 83:
84: /* In order to see any debug output you will need to run a checked build of
85: NT */
86: #ifdef DEBUG
87: #define Dump DbgPrint
88: #else
89: #define Dump
90: #endif
91:
92: #ifdef USE_KERNEL_MUTEX
93: #pragma message ("Compiling " __FILE__ " with USE_KERNEL_MUTEX on")
94: #endif
95:
1.1.1.4 root 96: #define FSCTL_LOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
97: #define FSCTL_UNLOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
98: #define FSCTL_DISMOUNT_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
1.1.1.6 root 99: NTKERNELAPI NTSTATUS ObOpenObjectByPointer (IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState OPTIONAL, IN ACCESS_MASK DesiredAccess OPTIONAL, IN POBJECT_TYPE ObjectType OPTIONAL, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle);
1.1 root 100:
101: NTSTATUS DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
102: NTSTATUS TCDispatchQueueIRP (PDEVICE_OBJECT DeviceObject, PIRP Irp);
103: NTSTATUS TCCreateRootDeviceObject (PDRIVER_OBJECT DriverObject);
1.1.1.4 root 104: NTSTATUS TCCreateDeviceObject (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT * ppDeviceObject, MOUNT_STRUCT * mount);
1.1 root 105: NTSTATUS TCDeviceControl (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, PIRP Irp);
106: NTSTATUS TCStartThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, MOUNT_STRUCT * mount);
107: void TCStopThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension);
108: VOID TCThreadIRP (PVOID Context);
1.1.1.5 root 109: void TCSleep (int milliSeconds);
1.1 root 110: void TCGetNTNameFromNumber (LPWSTR ntname, int nDriveNo);
111: void TCGetDosNameFromNumber (LPWSTR dosname, int nDriveNo);
112: LPWSTR TCTranslateCode (ULONG ulCode);
113: PDEVICE_OBJECT TCDeleteDeviceObject (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension);
114: VOID TCUnloadDriver (PDRIVER_OBJECT DriverObject);
1.1.1.4 root 115: NTSTATUS TCDeviceIoControl (PWSTR deviceName, ULONG IoControlCode, void *InputBuffer, int InputBufferSize, void *OutputBuffer, int OutputBufferSize);
116: NTSTATUS TCOpenFsVolume (PEXTENSION Extension, PHANDLE volumeHandle, PFILE_OBJECT * fileObject);
117: void TCCloseFsVolume (HANDLE volumeHandle, PFILE_OBJECT fileObject);
118: NTSTATUS TCFsctlCall (PFILE_OBJECT fileObject, LONG IoControlCode, void *InputBuffer, int InputBufferSize, void *OutputBuffer, int OutputBufferSize);
1.1.1.6 root 119: NTSTATUS CreateDriveLink (int nDosDriveNo);
120: NTSTATUS RemoveDriveLink (int nDosDriveNo);
1.1.1.4 root 121: NTSTATUS MountManagerMount (MOUNT_STRUCT *mount);
122: NTSTATUS MountManagerUnmount (int nDosDriveNo);
123: NTSTATUS MountDevice (PDEVICE_OBJECT deviceObject, MOUNT_STRUCT *mount);
124: NTSTATUS UnmountDevice (PDEVICE_OBJECT deviceObject, BOOL ignoreOpenFiles);
1.1.1.8 ! root 125: NTSTATUS UnmountAllDevices (PDEVICE_OBJECT DeviceObject, BOOL ignoreOpenFiles, BOOL unmountSystem, BOOL unmountPersistent);
1.1.1.4 root 126: NTSTATUS SymbolicLinkToTarget (PWSTR symlinkName, PWSTR targetName, USHORT maxTargetNameLength);
1.1.1.5 root 127: void DriverMutexWait ();
128: void DriverMutexRelease ();
1.1.1.6 root 129: BOOL RegionsOverlap (unsigned __int64 start1, unsigned __int64 end1, unsigned __int64 start2, unsigned __int64 end2);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.