|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #ifndef TC_HEADER_Mount_BootEncryption ! 10: #define TC_HEADER_Mount_BootEncryption ! 11: ! 12: #include "Tcdefs.h" ! 13: #include "Dlgcode.h" ! 14: #include "Platform/PlatformBase.h" ! 15: ! 16: using namespace std; ! 17: ! 18: namespace TrueCrypt ! 19: { ! 20: struct Exception ! 21: { ! 22: virtual void Show (HWND parent) = 0; ! 23: }; ! 24: ! 25: struct SystemException : public Exception ! 26: { ! 27: SystemException () : ErrorCode (GetLastError()) { } ! 28: ! 29: void Show (HWND parent) ! 30: { ! 31: SetLastError (ErrorCode); ! 32: handleWin32Error (parent); ! 33: } ! 34: ! 35: DWORD ErrorCode; ! 36: }; ! 37: ! 38: struct ErrorException : public Exception ! 39: { ! 40: ErrorException (char *langId) : ErrLangId (langId) { } ! 41: ! 42: void Show (HWND parent) ! 43: { ! 44: ::Error (ErrLangId); ! 45: } ! 46: ! 47: char *ErrLangId; ! 48: }; ! 49: ! 50: struct ParameterIncorrect : public Exception ! 51: { ! 52: ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { } ! 53: ! 54: void Show (HWND parent) ! 55: { ! 56: string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")"; ! 57: MessageBox (parent, msgBody.c_str(), "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); ! 58: } ! 59: ! 60: const char *SrcPos; ! 61: }; ! 62: ! 63: struct UserAbort : public Exception ! 64: { ! 65: UserAbort (const char *srcPos) { } ! 66: void Show (HWND parent) { } ! 67: }; ! 68: ! 69: #define throw_sys_if(condition) do { if (condition) throw SystemException(); } while (false) ! 70: ! 71: ! 72: class File ! 73: { ! 74: public: ! 75: File () : FileOpen (false) { } ! 76: File (string path, bool readOnly = false, bool create = false); ! 77: ~File () { Close(); } ! 78: ! 79: void Close (); ! 80: DWORD Read (byte *buffer, DWORD size); ! 81: void Write (byte *buffer, DWORD size); ! 82: void SeekAt (int64 position); ! 83: ! 84: protected: ! 85: bool Elevated; ! 86: bool FileOpen; ! 87: uint64 FilePointerPosition; ! 88: HANDLE Handle; ! 89: bool IsDevice; ! 90: string Path; ! 91: }; ! 92: ! 93: ! 94: class Device : public File ! 95: { ! 96: public: ! 97: Device (string path, bool readOnly = false); ! 98: }; ! 99: ! 100: ! 101: class Buffer ! 102: { ! 103: public: ! 104: Buffer (size_t size) : DataSize (size) ! 105: { ! 106: DataPtr = new byte[size]; ! 107: if (!DataPtr) ! 108: throw bad_alloc(); ! 109: } ! 110: ! 111: ~Buffer () { delete DataPtr; } ! 112: byte *Ptr () const { return DataPtr; } ! 113: size_t Size () const { return DataSize; } ! 114: ! 115: protected: ! 116: byte *DataPtr; ! 117: size_t DataSize; ! 118: }; ! 119: ! 120: ! 121: struct Partition ! 122: { ! 123: string DevicePath; ! 124: PARTITION_INFORMATION Info; ! 125: string MountPoint; ! 126: int Number; ! 127: BOOL IsGPT; ! 128: }; ! 129: ! 130: typedef list <Partition> PartitionList; ! 131: ! 132: ! 133: struct SystemDriveConfiguration ! 134: { ! 135: string DevicePath; ! 136: int DriveNumber; ! 137: Partition DrivePartition; ! 138: int64 InitialUnallocatedSpace; ! 139: PartitionList Partitions; ! 140: Partition SystemPartition; ! 141: int64 TotalUnallocatedSpace; ! 142: bool SystemLoaderPresent; ! 143: }; ! 144: ! 145: class BootEncryption ! 146: { ! 147: public: ! 148: BootEncryption (HWND parent) ! 149: : DriveConfigValid (false), ! 150: ParentWindow (parent), ! 151: RealSystemDriveSizeValid (false), ! 152: RescueIsoImage (nullptr), ! 153: RescueVolumeHeaderValid (false), ! 154: VolumeHeaderValid (false) ! 155: { ! 156: } ! 157: ! 158: ~BootEncryption (); ! 159: ! 160: void AbortSetup (); ! 161: void AbortSetupWait (); ! 162: void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0); ! 163: int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5); ! 164: void CheckEncryptionSetupResult (); ! 165: void CheckRequirements (); ! 166: void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath); ! 167: void Deinstall (); ! 168: DWORD GetDriverServiceStartType (); ! 169: uint16 GetInstalledBootLoaderVersion (); ! 170: BootEncryptionStatus GetStatus (); ! 171: void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties); ! 172: SystemDriveConfiguration GetSystemDriveConfiguration (); ! 173: void Install (); ! 174: void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath); ! 175: void ProbeRealSystemDriveSize (); ! 176: void RegisterFilterDriver (bool registerDriver); ! 177: bool RestartComputer (void); ! 178: void SetDriverServiceStartType (DWORD startType); ! 179: void StartDecryption (); ! 180: void StartEncryption (WipeAlgorithmId wipeAlgorithm); ! 181: bool SystemPartitionCoversWholeDrive (); ! 182: bool VerifyRescueDisk (); ! 183: ! 184: protected: ! 185: static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image ! 186: ! 187: void BackupSystemLoader (); ! 188: void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5); ! 189: string GetSystemLoaderBackupPath (); ! 190: DISK_GEOMETRY GetDriveGeometry (int driveNumber); ! 191: PartitionList GetDrivePartitions (int driveNumber); ! 192: string GetWindowsDirectory (); ! 193: void InstallBootLoader (); ! 194: void RestoreSystemLoader (); ! 195: void InstallVolumeHeader (); ! 196: void UpdateSystemDriveConfiguration (); ! 197: ! 198: HWND ParentWindow; ! 199: SystemDriveConfiguration DriveConfig; ! 200: byte *RescueIsoImage; ! 201: byte RescueVolumeHeader[HEADER_SIZE]; ! 202: byte VolumeHeader[HEADER_SIZE]; ! 203: bool DriveConfigValid; ! 204: bool RealSystemDriveSizeValid; ! 205: bool RescueVolumeHeaderValid; ! 206: bool VolumeHeaderValid; ! 207: }; ! 208: } ! 209: ! 210: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10 ! 211: ! 212: #define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader.bak" ! 213: ! 214: #endif // TC_HEADER_Mount_BootEncryption
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.