|
|
1.1 root 1: /* 1.1.1.6 ! root 2: Copyright (c) 2008-2009 TrueCrypt Foundation. All rights reserved. 1.1 root 3: 1.1.1.5 root 4: Governed by the TrueCrypt License 2.6 the full text of which is contained 1.1 root 5: in the file License.txt included in TrueCrypt binary and source code 6: distribution packages. 7: */ 8: 1.1.1.5 root 9: #ifndef TC_HEADER_Common_BootEncryption 10: #define TC_HEADER_Common_BootEncryption 1.1 root 11: 12: #include "Tcdefs.h" 13: #include "Dlgcode.h" 1.1.1.5 root 14: #include "Exception.h" 1.1 root 15: #include "Platform/PlatformBase.h" 1.1.1.4 root 16: #include "Volumes.h" 1.1 root 17: 18: using namespace std; 19: 20: namespace TrueCrypt 21: { 22: class File 23: { 24: public: 25: File () : FileOpen (false) { } 26: File (string path, bool readOnly = false, bool create = false); 27: ~File () { Close(); } 28: 29: void Close (); 30: DWORD Read (byte *buffer, DWORD size); 31: void Write (byte *buffer, DWORD size); 32: void SeekAt (int64 position); 33: 34: protected: 35: bool Elevated; 36: bool FileOpen; 37: uint64 FilePointerPosition; 38: HANDLE Handle; 39: bool IsDevice; 40: string Path; 41: }; 42: 43: 44: class Device : public File 45: { 46: public: 47: Device (string path, bool readOnly = false); 48: }; 49: 50: 51: class Buffer 52: { 53: public: 54: Buffer (size_t size) : DataSize (size) 55: { 56: DataPtr = new byte[size]; 57: if (!DataPtr) 58: throw bad_alloc(); 59: } 60: 61: ~Buffer () { delete DataPtr; } 62: byte *Ptr () const { return DataPtr; } 63: size_t Size () const { return DataSize; } 64: 65: protected: 66: byte *DataPtr; 67: size_t DataSize; 68: }; 69: 70: 71: struct Partition 72: { 73: string DevicePath; 74: PARTITION_INFORMATION Info; 75: string MountPoint; 76: int Number; 77: BOOL IsGPT; 1.1.1.6 ! root 78: wstring VolumeNameId; 1.1 root 79: }; 80: 81: typedef list <Partition> PartitionList; 82: 1.1.1.2 root 83: #pragma pack (push) 84: #pragma pack(1) 85: 86: struct PartitionEntryMBR 87: { 88: byte BootIndicator; 89: 90: byte StartHead; 91: byte StartCylSector; 92: byte StartCylinder; 93: 94: byte Type; 95: 96: byte EndHead; 97: byte EndSector; 98: byte EndCylinder; 99: 100: uint32 StartLBA; 101: uint32 SectorCountLBA; 102: }; 103: 104: struct MBR 105: { 106: byte Code[446]; 107: PartitionEntryMBR Partitions[4]; 108: uint16 Signature; 109: }; 110: 111: #pragma pack (pop) 1.1 root 112: 113: struct SystemDriveConfiguration 114: { 1.1.1.4 root 115: string DeviceKernelPath; 1.1 root 116: string DevicePath; 117: int DriveNumber; 118: Partition DrivePartition; 119: int64 InitialUnallocatedSpace; 120: PartitionList Partitions; 121: Partition SystemPartition; 122: int64 TotalUnallocatedSpace; 123: bool SystemLoaderPresent; 124: }; 125: 126: class BootEncryption 127: { 128: public: 1.1.1.5 root 129: BootEncryption (HWND parent); 1.1 root 130: ~BootEncryption (); 131: 1.1.1.5 root 132: void AbortDecoyOSWipe (); 1.1 root 133: void AbortSetup (); 134: void AbortSetupWait (); 135: void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0); 136: int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5); 1.1.1.5 root 137: void CheckDecoyOSWipeResult (); 1.1 root 138: void CheckEncryptionSetupResult (); 139: void CheckRequirements (); 1.1.1.4 root 140: void CheckRequirementsHiddenOS (); 1.1 root 141: void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath); 142: void Deinstall (); 1.1.1.5 root 143: DecoySystemWipeStatus GetDecoyOSWipeStatus (); 1.1 root 144: DWORD GetDriverServiceStartType (); 1.1.1.4 root 145: unsigned int GetHiddenOSCreationPhase (); 1.1 root 146: uint16 GetInstalledBootLoaderVersion (); 1.1.1.4 root 147: Partition GetPartitionForHiddenOS (); 1.1.1.3 root 148: bool IsBootLoaderOnDrive (char *devicePath); 1.1 root 149: BootEncryptionStatus GetStatus (); 1.1.1.5 root 150: string GetTempPath (); 1.1 root 151: void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties); 152: SystemDriveConfiguration GetSystemDriveConfiguration (); 1.1.1.5 root 153: void Install (bool hiddenSystem); 154: void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false); 1.1.1.4 root 155: void InvalidateCachedSysDriveProperties (); 156: bool IsHiddenSystemRunning (); 1.1.1.5 root 157: bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly); 158: void PrepareHiddenOSCreation (int ea, int mode, int pkcs5); 1.1 root 159: void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath); 160: void ProbeRealSystemDriveSize (); 1.1.1.6 ! root 161: void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr); 1.1.1.5 root 162: void RegisterBootDriver (bool hiddenSystem); 1.1.1.4 root 163: void RegisterFilterDriver (bool registerDriver, bool volumeClass); 164: void RenameDeprecatedSystemLoaderBackup (); 1.1 root 165: bool RestartComputer (void); 1.1.1.5 root 166: void InitialSecurityChecksForHiddenOS (); 1.1.1.6 ! root 167: void RestrictPagingFilesToSystemPartition (); 1.1 root 168: void SetDriverServiceStartType (DWORD startType); 1.1.1.4 root 169: void SetHiddenOSCreationPhase (unsigned int newPhase); 1.1.1.6 ! root 170: void StartDecryption (BOOL discardUnreadableEncryptedSectors); 1.1.1.5 root 171: void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm); 172: void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors); 1.1.1.2 root 173: bool SystemDriveContainsPartitionType (byte type); 174: bool SystemDriveContainsExtendedPartition (); 1.1 root 175: bool SystemPartitionCoversWholeDrive (); 1.1.1.2 root 176: bool SystemDriveIsDynamic (); 1.1 root 177: bool VerifyRescueDisk (); 1.1.1.5 root 178: void WipeHiddenOSCreationConfig (); 179: void WriteBootDriveSector (uint64 offset, byte *data); 1.1.1.4 root 180: void WriteBootSectorConfig (const byte newConfig[]); 1.1.1.5 root 181: void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage); 1.1.1.4 root 182: void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value); 1.1 root 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 (); 1.1.1.5 root 188: void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false); 1.1 root 189: void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5); 190: string GetSystemLoaderBackupPath (); 1.1.1.3 root 191: uint32 GetChecksum (byte *data, size_t size); 1.1 root 192: DISK_GEOMETRY GetDriveGeometry (int driveNumber); 193: PartitionList GetDrivePartitions (int driveNumber); 1.1.1.4 root 194: wstring GetRemarksOnHiddenOS (); 1.1 root 195: string GetWindowsDirectory (); 1.1.1.4 root 196: void RegisterDeviceClassFilter (bool registerFilter, const GUID *deviceClassGuid); 1.1 root 197: void RestoreSystemLoader (); 198: void InstallVolumeHeader (); 199: 200: HWND ParentWindow; 201: SystemDriveConfiguration DriveConfig; 1.1.1.3 root 202: int SelectedEncryptionAlgorithmId; 1.1.1.5 root 203: Partition HiddenOSCandidatePartition; 1.1 root 204: byte *RescueIsoImage; 1.1.1.4 root 205: byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE]; 206: byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE]; 1.1 root 207: bool DriveConfigValid; 208: bool RealSystemDriveSizeValid; 209: bool RescueVolumeHeaderValid; 210: bool VolumeHeaderValid; 211: }; 212: } 213: 214: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10 215: 1.1.1.4 root 216: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1 217: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05 218: 219: #define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader" 220: #define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY "Original System Loader.bak" // Deprecated to prevent removal by some "cleaners" 1.1 root 221: 1.1.1.5 root 222: #endif // TC_HEADER_Common_BootEncryption
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.