Annotation of truecrypt/common/bootencryption.h, revision 1.1.1.4

1.1       root        1: /*
                      2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                      3: 
1.1.1.4 ! root        4:  Governed by the TrueCrypt License 2.5 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: 
                      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"
1.1.1.4 ! root       15: #include "Volumes.h"
1.1       root       16: 
                     17: using namespace std;
                     18: 
                     19: namespace TrueCrypt
                     20: {
                     21:        struct Exception
                     22:        {
                     23:                virtual void Show (HWND parent) = 0;
                     24:        };
                     25: 
                     26:        struct SystemException : public Exception
                     27:        {
                     28:                SystemException () : ErrorCode (GetLastError()) { }
                     29: 
                     30:                void Show (HWND parent)
                     31:                {
                     32:                        SetLastError (ErrorCode);
                     33:                        handleWin32Error (parent);
                     34:                }
                     35: 
                     36:                DWORD ErrorCode;
                     37:        };
                     38: 
                     39:        struct ErrorException : public Exception
                     40:        {
                     41:                ErrorException (char *langId) : ErrLangId (langId) { }
1.1.1.4 ! root       42:                ErrorException (const wstring &errMsg) : ErrMsg (errMsg) { }
1.1       root       43: 
                     44:                void Show (HWND parent)
                     45:                {
1.1.1.4 ! root       46:                        if (ErrMsg.empty())
        !            47:                                ::Error (ErrLangId);
        !            48:                        else
        !            49:                                ::ErrorDirect (ErrMsg.c_str());
1.1       root       50:                }
                     51: 
                     52:                char *ErrLangId;
1.1.1.4 ! root       53:                wstring ErrMsg;
1.1       root       54:        };
                     55: 
                     56:        struct ParameterIncorrect : public Exception
                     57:        {
                     58:                ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
                     59: 
                     60:                void Show (HWND parent)
                     61:                {
                     62:                        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) + ")";
                     63:                        MessageBox (parent, msgBody.c_str(), "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
                     64:                }
                     65: 
                     66:                const char *SrcPos;
                     67:        };
                     68: 
1.1.1.3   root       69:        struct TimeOut : public Exception
                     70:        {
                     71:                TimeOut (const char *srcPos) { }
                     72:                void Show (HWND parent) { MessageBox (parent, "Timeout", "TrueCrypt", MB_ICONERROR); }
                     73:        };
                     74: 
1.1       root       75:        struct UserAbort : public Exception
                     76:        {
                     77:                UserAbort (const char *srcPos) { }
                     78:                void Show (HWND parent) { }
                     79:        };
                     80: 
                     81: #define throw_sys_if(condition) do { if (condition) throw SystemException(); } while (false)
                     82: 
                     83: 
                     84:        class File
                     85:        {
                     86:        public:
                     87:                File () : FileOpen (false) { }
                     88:                File (string path, bool readOnly = false, bool create = false);
                     89:                ~File () { Close(); }
                     90: 
                     91:                void Close ();
                     92:                DWORD Read (byte *buffer, DWORD size);
                     93:                void Write (byte *buffer, DWORD size);
                     94:                void SeekAt (int64 position);
                     95: 
                     96:        protected:
                     97:                bool Elevated;
                     98:                bool FileOpen;
                     99:                uint64 FilePointerPosition;
                    100:                HANDLE Handle;
                    101:                bool IsDevice;
                    102:                string Path;
                    103:        };
                    104: 
                    105: 
                    106:        class Device : public File
                    107:        {
                    108:        public:
                    109:                Device (string path, bool readOnly = false);
                    110:        };
                    111: 
                    112: 
                    113:        class Buffer
                    114:        {
                    115:        public:
                    116:                Buffer (size_t size) : DataSize (size)
                    117:                {
                    118:                        DataPtr = new byte[size];
                    119:                        if (!DataPtr)
                    120:                                throw bad_alloc();
                    121:                }
                    122: 
                    123:                ~Buffer () { delete DataPtr; }
                    124:                byte *Ptr () const { return DataPtr; }
                    125:                size_t Size () const { return DataSize; }
                    126: 
                    127:        protected:
                    128:                byte *DataPtr;
                    129:                size_t DataSize;
                    130:        };
                    131: 
                    132: 
                    133:        struct Partition
                    134:        {
                    135:                string DevicePath;
                    136:                PARTITION_INFORMATION Info;
                    137:                string MountPoint;
                    138:                int Number;
                    139:                BOOL IsGPT;
                    140:        };
                    141: 
                    142:        typedef list <Partition> PartitionList;
                    143: 
1.1.1.2   root      144: #pragma pack (push)
                    145: #pragma pack(1)
                    146: 
                    147:        struct PartitionEntryMBR
                    148:        {
                    149:                byte BootIndicator;
                    150: 
                    151:                byte StartHead;
                    152:                byte StartCylSector;
                    153:                byte StartCylinder;
                    154: 
                    155:                byte Type;
                    156: 
                    157:                byte EndHead;
                    158:                byte EndSector;
                    159:                byte EndCylinder;
                    160: 
                    161:                uint32 StartLBA;
                    162:                uint32 SectorCountLBA;
                    163:        };
                    164: 
                    165:        struct MBR
                    166:        {
                    167:                byte Code[446];
                    168:                PartitionEntryMBR Partitions[4];
                    169:                uint16 Signature;
                    170:        };
                    171: 
                    172: #pragma pack (pop)
1.1       root      173: 
                    174:        struct SystemDriveConfiguration
                    175:        {
1.1.1.4 ! root      176:                string DeviceKernelPath;
1.1       root      177:                string DevicePath;
                    178:                int DriveNumber;
                    179:                Partition DrivePartition;
                    180:                int64 InitialUnallocatedSpace;
                    181:                PartitionList Partitions;
                    182:                Partition SystemPartition;
                    183:                int64 TotalUnallocatedSpace;
                    184:                bool SystemLoaderPresent;
                    185:        };
                    186: 
                    187:        class BootEncryption
                    188:        {
                    189:        public:
                    190:                BootEncryption (HWND parent)
                    191:                        : DriveConfigValid (false),
                    192:                        ParentWindow (parent),
                    193:                        RealSystemDriveSizeValid (false),
                    194:                        RescueIsoImage (nullptr),
                    195:                        RescueVolumeHeaderValid (false),
1.1.1.3   root      196:                        SelectedEncryptionAlgorithmId (0),
1.1       root      197:                        VolumeHeaderValid (false)
                    198:                {
                    199:                }
                    200: 
                    201:                ~BootEncryption ();
                    202: 
                    203:                void AbortSetup ();
                    204:                void AbortSetupWait ();
                    205:                void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
                    206:                int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
                    207:                void CheckEncryptionSetupResult ();
                    208:                void CheckRequirements ();
1.1.1.4 ! root      209:                void CheckRequirementsHiddenOS ();
1.1       root      210:                void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
                    211:                void Deinstall ();
                    212:                DWORD GetDriverServiceStartType ();
1.1.1.4 ! root      213:                unsigned int GetHiddenOSCreationPhase ();
1.1       root      214:                uint16 GetInstalledBootLoaderVersion ();
1.1.1.4 ! root      215:                Partition GetPartitionForHiddenOS ();
1.1.1.3   root      216:                bool IsBootLoaderOnDrive (char *devicePath);
1.1       root      217:                BootEncryptionStatus GetStatus ();
                    218:                void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
                    219:                SystemDriveConfiguration GetSystemDriveConfiguration ();
                    220:                void Install ();
1.1.1.2   root      221:                void InstallBootLoader ();
1.1.1.4 ! root      222:                void InvalidateCachedSysDriveProperties ();
        !           223:                bool IsHiddenSystemRunning ();
        !           224:                bool IsPagingFileActive ();
1.1       root      225:                void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
                    226:                void ProbeRealSystemDriveSize ();
1.1.1.4 ! root      227:                void ReadBootSectorConfig (byte *config, size_t bufLength);
1.1.1.3   root      228:                void RegisterBootDriver ();
1.1.1.4 ! root      229:                void RegisterFilterDriver (bool registerDriver, bool volumeClass);
        !           230:                void RenameDeprecatedSystemLoaderBackup ();
1.1       root      231:                bool RestartComputer (void);
                    232:                void SetDriverServiceStartType (DWORD startType);
1.1.1.4 ! root      233:                void SetHiddenOSCreationPhase (unsigned int newPhase);
1.1       root      234:                void StartDecryption ();
                    235:                void StartEncryption (WipeAlgorithmId wipeAlgorithm);
1.1.1.2   root      236:                bool SystemDriveContainsPartitionType (byte type);
                    237:                bool SystemDriveContainsExtendedPartition ();
1.1       root      238:                bool SystemPartitionCoversWholeDrive ();
1.1.1.2   root      239:                bool SystemDriveIsDynamic ();
1.1       root      240:                bool VerifyRescueDisk ();
1.1.1.4 ! root      241:                void WriteBootSectorConfig (const byte newConfig[]);
        !           242:                void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value);
1.1       root      243: 
                    244:        protected:
                    245:                static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
                    246: 
                    247:                void BackupSystemLoader ();
                    248:                void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
                    249:                string GetSystemLoaderBackupPath ();
1.1.1.4 ! root      250:                void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk);
1.1.1.3   root      251:                uint32 GetChecksum (byte *data, size_t size);
1.1       root      252:                DISK_GEOMETRY GetDriveGeometry (int driveNumber);
                    253:                PartitionList GetDrivePartitions (int driveNumber);
1.1.1.4 ! root      254:                wstring GetRemarksOnHiddenOS ();
1.1       root      255:                string GetWindowsDirectory ();
1.1.1.4 ! root      256:                void RegisterDeviceClassFilter (bool registerFilter, const GUID *deviceClassGuid);
1.1       root      257:                void RestoreSystemLoader ();
                    258:                void InstallVolumeHeader ();
                    259:                void UpdateSystemDriveConfiguration ();
                    260: 
                    261:                HWND ParentWindow;
                    262:                SystemDriveConfiguration DriveConfig;
1.1.1.3   root      263:                int SelectedEncryptionAlgorithmId;
1.1       root      264:                byte *RescueIsoImage;
1.1.1.4 ! root      265:                byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
        !           266:                byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
1.1       root      267:                bool DriveConfigValid;
                    268:                bool RealSystemDriveSizeValid;
                    269:                bool RescueVolumeHeaderValid;
                    270:                bool VolumeHeaderValid;
                    271:        };
                    272: }
                    273: 
                    274: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL       10
                    275: 
1.1.1.4 ! root      276: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS   2.1
        !           277: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT            1.05
        !           278: 
        !           279: #define TC_SYS_BOOT_LOADER_BACKUP_NAME                 "Original System Loader"
        !           280: #define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY  "Original System Loader.bak"    // Deprecated to prevent removal by some "cleaners"
1.1       root      281: 
                    282: #endif // TC_HEADER_Mount_BootEncryption

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.