|
|
1.1.1.10 root 1: /* 1.1.1.12! root 2: Legal Notice: Some portions of the source code contained in this file were ! 3: derived from the source code of Encryption for the Masses 2.02a, which is ! 4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License ! 5: Agreement for Encryption for the Masses'. Modifications and additions to ! 6: the original source code (contained in this file) and all other portions of ! 7: this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed ! 8: by the TrueCrypt License 2.4 the full text of which is contained in the ! 9: file License.txt included in TrueCrypt binary and source code distribution 1.1.1.10 root 10: packages. */ 1.1 root 11: 1.1.1.12! root 12: #ifndef TC_HEADER_NTDRIVER ! 13: #define TC_HEADER_NTDRIVER ! 14: ! 15: #include "EncryptedIoQueue.h" ! 16: 1.1 root 17: /* This structure is used to start new threads */ 18: typedef struct _THREAD_BLOCK_ 19: { 20: PDEVICE_OBJECT DeviceObject; 21: NTSTATUS ntCreateStatus; 1.1.1.7 root 22: WCHAR wszMountVolume[TC_MAX_PATH + 8]; 1.1 root 23: MOUNT_STRUCT *mount; 24: } THREAD_BLOCK, *PTHREAD_BLOCK; 25: 1.1.1.12! root 26: 1.1 root 27: /* This structure is allocated for non-root devices! WARNING: bRootDevice 28: must be the first member of the structure! */ 29: typedef struct EXTENSION 30: { 31: BOOL bRootDevice; /* Is this the root device ? which the 32: user-mode apps talk to */ 1.1.1.12! root 33: BOOL IsDriveFilterDevice; 1.1 root 34: 35: ULONG lMagicNumber; /* To ensure the completion routine is not 36: sending us bad IRP's */ 37: 1.1.1.6 root 38: int UniqueVolumeId; 1.1 root 39: int nDosDriveNo; /* Drive number this extension is mounted 40: against */ 41: BOOL bShuttingDown; /* Is the driver shutting down ? */ 42: BOOL bThreadShouldQuit; /* Instruct per device worker thread to quit */ 43: PETHREAD peThread; /* Thread handle */ 44: KEVENT keCreateEvent; /* Device creation event */ 45: KSPIN_LOCK ListSpinLock; /* IRP spinlock */ 46: LIST_ENTRY ListEntry; /* IRP listentry */ 47: KSEMAPHORE RequestSemaphore; /* IRP list request Semaphore */ 48: 49: HANDLE hDeviceFile; /* Device handle for this device */ 50: PFILE_OBJECT pfoDeviceFile; /* Device fileobject for this device */ 51: PDEVICE_OBJECT pFsdDevice; /* lower level device handle */ 52: 1.1.1.6 root 53: CRYPTO_INFO *cryptoInfo; /* Cryptographic and other information for this device */ 1.1 root 54: 55: __int64 DiskLength; /* The length of the disk referred to by this device */ 56: __int64 NumberOfCylinders; /* Partition info */ 57: ULONG TracksPerCylinder; /* Partition info */ 58: ULONG SectorsPerTrack; /* Partition info */ 59: ULONG BytesPerSector; /* Partition info */ 60: UCHAR PartitionType; /* Partition info */ 1.1.1.10 root 61: 62: int HostBytesPerSector; 1.1 root 63: 64: KEVENT keVolumeEvent; /* Event structure used when setting up a device */ 65: 1.1.1.12! root 66: EncryptedIoQueue Queue; 1.1.1.8 root 67: 1.1.1.4 root 68: BOOL bReadOnly; /* Is this device read-only ? */ 69: BOOL bRemovable; /* Is this device removable media ? */ 70: BOOL bRawDevice; /* Is this a raw-partition or raw-floppy device ? */ 71: BOOL bMountManager; /* Mount manager knows about volume */ 1.1 root 72: 1.1.1.7 root 73: WCHAR wszVolume[TC_MAX_PATH]; /* DONT change this size without also changing MOUNT_LIST_STRUCT! */ 1.1 root 74: 1.1.1.6 root 75: // 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 76: LARGE_INTEGER fileCreationTime; 77: LARGE_INTEGER fileLastAccessTime; 78: LARGE_INTEGER fileLastWriteTime; 79: LARGE_INTEGER fileLastChangeTime; 1.1.1.6 root 80: BOOL bTimeStampValid; 81: 1.1 root 82: } EXTENSION, *PEXTENSION; 83: 1.1.1.12! root 84: extern BOOL DriverShuttingDown; 1.1.1.10 root 85: extern ULONG OsMajorVersion; 86: 1.1 root 87: /* Helper macro returning x seconds in units of 100 nanoseconds */ 1.1.1.4 root 88: #define WAIT_SECONDS(x) ((x)*10000000) 1.1 root 89: 90: /* In order to see any debug output you will need to run a checked build of 91: NT */ 92: #ifdef DEBUG 1.1.1.12! root 93: # if 1 // DbgPrintEx is not available on Windows 2000 ! 94: # define Dump DbgPrint ! 95: # else ! 96: # define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__) ! 97: # endif ! 98: # define DumpMem(...) DumpMemory (__VA_ARGS__) 1.1 root 99: #else 1.1.1.12! root 100: # define Dump(...) ((void) 0) ! 101: # define DumpMem(...) ((void) 0) 1.1 root 102: #endif 103: 1.1.1.4 root 104: #define FSCTL_LOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 6, METHOD_BUFFERED, FILE_ANY_ACCESS) 105: #define FSCTL_UNLOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 7, METHOD_BUFFERED, FILE_ANY_ACCESS) 106: #define FSCTL_DISMOUNT_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 8, METHOD_BUFFERED, FILE_ANY_ACCESS) 1.1.1.6 root 107: 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 108: 109: NTSTATUS DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath); 1.1.1.12! root 110: void DumpMemory (void *memory, int size); ! 111: BOOL IsAccessibleByUser (PUNICODE_STRING objectFileName, BOOL readOnly); ! 112: NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, PIRP Irp); ! 113: NTSTATUS ProcessVolumeDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, PIRP Irp); ! 114: NTSTATUS SendDeviceIoControlRequest (PDEVICE_OBJECT deviceObject, ULONG ioControlCode, void *inputBuffer, int inputBufferSize, void *outputBuffer, int outputBufferSize); 1.1 root 115: NTSTATUS TCDispatchQueueIRP (PDEVICE_OBJECT DeviceObject, PIRP Irp); 116: NTSTATUS TCCreateRootDeviceObject (PDRIVER_OBJECT DriverObject); 1.1.1.4 root 117: NTSTATUS TCCreateDeviceObject (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT * ppDeviceObject, MOUNT_STRUCT * mount); 1.1.1.12! root 118: NTSTATUS TCReadDevice (PDEVICE_OBJECT deviceObject, PVOID buffer, LARGE_INTEGER offset, ULONG length); ! 119: NTSTATUS TCWriteDevice (PDEVICE_OBJECT deviceObject, PVOID buffer, LARGE_INTEGER offset, ULONG length); ! 120: NTSTATUS TCStartThread (PKSTART_ROUTINE threadProc, PVOID threadArg, PKTHREAD *kThread); ! 121: NTSTATUS TCStartVolumeThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension, MOUNT_STRUCT * mount); ! 122: void TCStopThread (PKTHREAD kThread, PKEVENT wakeUpEvent); ! 123: void TCStopVolumeThread (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension); ! 124: VOID VolumeThreadProc (PVOID Context); 1.1.1.5 root 125: void TCSleep (int milliSeconds); 1.1 root 126: void TCGetNTNameFromNumber (LPWSTR ntname, int nDriveNo); 127: void TCGetDosNameFromNumber (LPWSTR dosname, int nDriveNo); 128: LPWSTR TCTranslateCode (ULONG ulCode); 129: PDEVICE_OBJECT TCDeleteDeviceObject (PDEVICE_OBJECT DeviceObject, PEXTENSION Extension); 130: VOID TCUnloadDriver (PDRIVER_OBJECT DriverObject); 1.1.1.4 root 131: NTSTATUS TCDeviceIoControl (PWSTR deviceName, ULONG IoControlCode, void *InputBuffer, int InputBufferSize, void *OutputBuffer, int OutputBufferSize); 132: NTSTATUS TCOpenFsVolume (PEXTENSION Extension, PHANDLE volumeHandle, PFILE_OBJECT * fileObject); 133: void TCCloseFsVolume (HANDLE volumeHandle, PFILE_OBJECT fileObject); 134: NTSTATUS TCFsctlCall (PFILE_OBJECT fileObject, LONG IoControlCode, void *InputBuffer, int InputBufferSize, void *OutputBuffer, int OutputBufferSize); 1.1.1.6 root 135: NTSTATUS CreateDriveLink (int nDosDriveNo); 136: NTSTATUS RemoveDriveLink (int nDosDriveNo); 1.1.1.4 root 137: NTSTATUS MountManagerMount (MOUNT_STRUCT *mount); 138: NTSTATUS MountManagerUnmount (int nDosDriveNo); 139: NTSTATUS MountDevice (PDEVICE_OBJECT deviceObject, MOUNT_STRUCT *mount); 140: NTSTATUS UnmountDevice (PDEVICE_OBJECT deviceObject, BOOL ignoreOpenFiles); 1.1.1.12! root 141: NTSTATUS UnmountAllDevices (PDEVICE_OBJECT DeviceObject, BOOL ignoreOpenFiles); 1.1.1.4 root 142: NTSTATUS SymbolicLinkToTarget (PWSTR symlinkName, PWSTR targetName, USHORT maxTargetNameLength); 1.1.1.5 root 143: void DriverMutexWait (); 144: void DriverMutexRelease (); 1.1.1.6 root 145: BOOL RegionsOverlap (unsigned __int64 start1, unsigned __int64 end1, unsigned __int64 start2, unsigned __int64 end2); 1.1.1.12! root 146: void GetIntersection (uint64 start1, uint32 length1, uint64 start2, uint64 end2, uint64 *intersectStart, uint32 *intersectLength); ! 147: NTSTATUS TCCompleteIrp (PIRP irp, NTSTATUS status, ULONG_PTR information); ! 148: NTSTATUS TCCompleteDiskIrp (PIRP irp, NTSTATUS status, ULONG_PTR information); ! 149: NTSTATUS ProbeRealDriveSize (PDEVICE_OBJECT driveDeviceObject, LARGE_INTEGER *driveSize); ! 150: ! 151: #define TC_TO_STRING2(n) #n ! 152: #define TC_TO_STRING(n) TC_TO_STRING2(n) ! 153: ! 154: #define trace_point Dump (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n") ! 155: ! 156: #define TC_BUG_CHECK(status) KeBugCheckEx (SECURITY_SYSTEM, __LINE__, status, 0, 'TC') ! 157: ! 158: #endif // TC_HEADER_NTDRIVER
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.