|
|
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:
1.1.1.2 ! root 132: #pragma pack (push)
! 133: #pragma pack(1)
! 134:
! 135: struct PartitionEntryMBR
! 136: {
! 137: byte BootIndicator;
! 138:
! 139: byte StartHead;
! 140: byte StartCylSector;
! 141: byte StartCylinder;
! 142:
! 143: byte Type;
! 144:
! 145: byte EndHead;
! 146: byte EndSector;
! 147: byte EndCylinder;
! 148:
! 149: uint32 StartLBA;
! 150: uint32 SectorCountLBA;
! 151: };
! 152:
! 153: struct MBR
! 154: {
! 155: byte Code[446];
! 156: PartitionEntryMBR Partitions[4];
! 157: uint16 Signature;
! 158: };
! 159:
! 160: #pragma pack (pop)
1.1 root 161:
162: struct SystemDriveConfiguration
163: {
164: string DevicePath;
165: int DriveNumber;
166: Partition DrivePartition;
167: int64 InitialUnallocatedSpace;
168: PartitionList Partitions;
169: Partition SystemPartition;
170: int64 TotalUnallocatedSpace;
171: bool SystemLoaderPresent;
172: };
173:
174: class BootEncryption
175: {
176: public:
177: BootEncryption (HWND parent)
178: : DriveConfigValid (false),
179: ParentWindow (parent),
180: RealSystemDriveSizeValid (false),
181: RescueIsoImage (nullptr),
182: RescueVolumeHeaderValid (false),
183: VolumeHeaderValid (false)
184: {
185: }
186:
187: ~BootEncryption ();
188:
189: void AbortSetup ();
190: void AbortSetupWait ();
191: void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
192: int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
193: void CheckEncryptionSetupResult ();
194: void CheckRequirements ();
195: void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
196: void Deinstall ();
197: DWORD GetDriverServiceStartType ();
198: uint16 GetInstalledBootLoaderVersion ();
199: BootEncryptionStatus GetStatus ();
200: void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
201: SystemDriveConfiguration GetSystemDriveConfiguration ();
202: void Install ();
1.1.1.2 ! root 203: void InstallBootLoader ();
1.1 root 204: void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
205: void ProbeRealSystemDriveSize ();
206: void RegisterFilterDriver (bool registerDriver);
207: bool RestartComputer (void);
208: void SetDriverServiceStartType (DWORD startType);
209: void StartDecryption ();
210: void StartEncryption (WipeAlgorithmId wipeAlgorithm);
1.1.1.2 ! root 211: bool SystemDriveContainsPartitionType (byte type);
! 212: bool SystemDriveContainsExtendedPartition ();
1.1 root 213: bool SystemPartitionCoversWholeDrive ();
1.1.1.2 ! root 214: bool SystemDriveIsDynamic ();
1.1 root 215: bool VerifyRescueDisk ();
216:
217: protected:
218: static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
219:
220: void BackupSystemLoader ();
221: void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
222: string GetSystemLoaderBackupPath ();
223: DISK_GEOMETRY GetDriveGeometry (int driveNumber);
224: PartitionList GetDrivePartitions (int driveNumber);
225: string GetWindowsDirectory ();
226: void RestoreSystemLoader ();
227: void InstallVolumeHeader ();
228: void UpdateSystemDriveConfiguration ();
229:
230: HWND ParentWindow;
231: SystemDriveConfiguration DriveConfig;
232: byte *RescueIsoImage;
233: byte RescueVolumeHeader[HEADER_SIZE];
234: byte VolumeHeader[HEADER_SIZE];
235: bool DriveConfigValid;
236: bool RealSystemDriveSizeValid;
237: bool RescueVolumeHeaderValid;
238: bool VolumeHeaderValid;
239: };
240: }
241:
242: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
243:
244: #define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader.bak"
245:
246: #endif // TC_HEADER_Mount_BootEncryption
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.