VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Boot/Windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/Boot/Windows')
-rw-r--r--src/Boot/Windows/Bios.h2
-rw-r--r--src/Boot/Windows/BootCommon.h8
-rw-r--r--src/Boot/Windows/BootConfig.cpp10
-rw-r--r--src/Boot/Windows/BootConfig.h8
-rw-r--r--src/Boot/Windows/BootConsoleIo.cpp24
-rw-r--r--src/Boot/Windows/BootConsoleIo.h8
-rw-r--r--src/Boot/Windows/BootDebug.cpp8
-rw-r--r--src/Boot/Windows/BootDebug.h4
-rw-r--r--src/Boot/Windows/BootDiskIo.cpp58
-rw-r--r--src/Boot/Windows/BootDiskIo.h66
-rw-r--r--src/Boot/Windows/BootEncryptedIo.cpp4
-rw-r--r--src/Boot/Windows/BootEncryptedIo.h4
-rw-r--r--src/Boot/Windows/BootMain.cpp46
-rw-r--r--src/Boot/Windows/BootMain.h12
-rw-r--r--src/Boot/Windows/IntFilter.cpp14
-rw-r--r--src/Boot/Windows/Platform.cpp2
-rw-r--r--src/Boot/Windows/Release/BootLoader.com.gzbin17457 -> 17432 bytes
-rw-r--r--src/Boot/Windows/Release_AES/BootLoader.com.gzbin11662 -> 11664 bytes
-rw-r--r--src/Boot/Windows/Release_AES_SHA2/BootLoader.com.gzbin11747 -> 11743 bytes
-rw-r--r--src/Boot/Windows/Release_Camellia/BootLoader.com.gzbin12582 -> 12577 bytes
-rw-r--r--src/Boot/Windows/Release_Camellia_SHA2/BootLoader.com.gzbin12619 -> 12652 bytes
-rw-r--r--src/Boot/Windows/Release_SHA2/BootLoader.com.gzbin17480 -> 17488 bytes
-rw-r--r--src/Boot/Windows/Release_Serpent/BootLoader.com.gzbin11985 -> 11994 bytes
-rw-r--r--src/Boot/Windows/Release_Serpent_SHA2/BootLoader.com.gzbin12045 -> 12051 bytes
-rw-r--r--src/Boot/Windows/Release_Twofish/BootLoader.com.gzbin11666 -> 11675 bytes
-rw-r--r--src/Boot/Windows/Release_Twofish_SHA2/BootLoader.com.gzbin11723 -> 11723 bytes
-rw-r--r--src/Boot/Windows/Rescue/BootLoader.com.gzbin17984 -> 17982 bytes
-rw-r--r--src/Boot/Windows/Rescue_AES/BootLoader.com.gzbin12228 -> 12215 bytes
-rw-r--r--src/Boot/Windows/Rescue_AES_SHA2/BootLoader.com.gzbin12281 -> 12280 bytes
-rw-r--r--src/Boot/Windows/Rescue_Camellia/BootLoader.com.gzbin13123 -> 13132 bytes
-rw-r--r--src/Boot/Windows/Rescue_Camellia_SHA2/BootLoader.com.gzbin13164 -> 13180 bytes
-rw-r--r--src/Boot/Windows/Rescue_SHA2/BootLoader.com.gzbin18021 -> 18045 bytes
-rw-r--r--src/Boot/Windows/Rescue_Serpent/BootLoader.com.gzbin12517 -> 12537 bytes
-rw-r--r--src/Boot/Windows/Rescue_Serpent_SHA2/BootLoader.com.gzbin12605 -> 12607 bytes
-rw-r--r--src/Boot/Windows/Rescue_Twofish/BootLoader.com.gzbin12216 -> 12216 bytes
-rw-r--r--src/Boot/Windows/Rescue_Twofish_SHA2/BootLoader.com.gzbin12264 -> 12273 bytes
36 files changed, 139 insertions, 139 deletions
diff --git a/src/Boot/Windows/Bios.h b/src/Boot/Windows/Bios.h
index 7085e7a2..0282fad7 100644
--- a/src/Boot/Windows/Bios.h
+++ b/src/Boot/Windows/Bios.h
@@ -1,33 +1,33 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_Bios
#define TC_HEADER_Boot_Bios
#include "Platform.h"
#define TC_LB_SIZE_BIT_SHIFT_DIVISOR 9
#define TC_FIRST_BIOS_DRIVE 0x80
#define TC_LAST_BIOS_DRIVE 0x8f
#define TC_INVALID_BIOS_DRIVE (TC_FIRST_BIOS_DRIVE - 1)
enum
{
BiosResultSuccess = 0x00,
BiosResultInvalidFunction = 0x01,
BiosResultTimeout = 0x80
};
-typedef byte BiosResult;
+typedef uint8 BiosResult;
#endif // TC_HEADER_Boot_Bios
diff --git a/src/Boot/Windows/BootCommon.h b/src/Boot/Windows/BootCommon.h
index d2ee42a1..45a1a650 100644
--- a/src/Boot/Windows/BootCommon.h
+++ b/src/Boot/Windows/BootCommon.h
@@ -16,61 +16,61 @@
#include "Common/Password.h"
#include "BootDefs.h"
// The user will be advised to upgrade the rescue disk if upgrading from the following or any previous version
#define TC_RESCUE_DISK_UPGRADE_NOTICE_MAX_VERSION 0x0125
#define TC_BOOT_LOADER_AREA_SIZE (TC_BOOT_LOADER_AREA_SECTOR_COUNT * TC_SECTOR_SIZE_BIOS)
#define TC_BOOT_VOLUME_HEADER_SECTOR (TC_BOOT_LOADER_AREA_SECTOR_COUNT - 1)
#define TC_BOOT_VOLUME_HEADER_SECTOR_OFFSET (TC_BOOT_VOLUME_HEADER_SECTOR * TC_SECTOR_SIZE_BIOS)
#define TC_CD_BOOTSECTOR_OFFSET 0xd000
#define TC_CD_BOOT_LOADER_SECTOR 26
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR TC_BOOT_LOADER_AREA_SECTOR_COUNT
#define TC_ORIG_BOOT_LOADER_BACKUP_SECTOR_OFFSET (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR * TC_SECTOR_SIZE_BIOS)
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR (TC_ORIG_BOOT_LOADER_BACKUP_SECTOR + TC_BOOT_LOADER_AREA_SECTOR_COUNT)
#define TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR_OFFSET (TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR * TC_SECTOR_SIZE_BIOS)
#define TC_MBR_SECTOR 0
#define TC_MAX_MBR_BOOT_CODE_SIZE 440
#define TC_MAX_EXTRA_BOOT_PARTITION_SIZE (512UL * 1024UL * 1024UL)
#pragma pack (1)
typedef struct
{
- byte Flags;
+ uint8 Flags;
} BootSectorConfiguration;
// Modifying this value can introduce incompatibility with previous versions
#define TC_BOOT_LOADER_ARGS_OFFSET 0x10
typedef struct
{
// Modifying this structure can introduce incompatibility with previous versions
char Signature[8];
uint16 BootLoaderVersion;
uint16 CryptoInfoOffset;
uint16 CryptoInfoLength;
uint32 HeaderSaltCrc32;
PasswordLegacy BootPassword;
uint64 HiddenSystemPartitionStart;
uint64 DecoySystemPartitionStart;
uint32 Flags;
uint32 BootDriveSignature;
uint32 BootArgumentsCrc32;
} BootArguments;
// Modifying these values can introduce incompatibility with previous versions
#define TC_BOOT_ARGS_FLAG_EXTRA_BOOT_PARTITION 0x1
#pragma pack ()
// Boot arguments signature should not be defined as a static string
@@ -93,126 +93,126 @@ typedef struct
#define DE_IDX_MAINGPTENTRYS 4
#define DE_IDX_ALTGPTHDR 5
#define DE_IDX_ALTGPTENTRYS 6
#define DE_IDX_EXEC 7
#define DE_IDX_PWDCACHE 8
#define DE_IDX_RND 9
#define DE_IDX_TOTAL 10
CSTATIC_ASSERT(DE_IDX_TOTAL <= 15, DE_IDX_TOTAL_too_big);
enum DcsDiskEntryTypes {
DE_Unused = 0,
DE_Sectors,
DE_List,
DE_DISKID,
DE_ExecParams,
DE_PwdCache,
DE_Rnd
};
#pragma pack(1)
typedef struct _SECREGION_BOOT_PARAMS {
uint64 Ptr;
uint32 Size;
uint32 Crc;
} SECREGION_BOOT_PARAMS;
typedef struct {
uint32 Data1;
uint16 Data2;
uint16 Data3;
- byte Data4[8];
+ uint8 Data4[8];
} DCS_GUID;
// DE types
typedef struct _DCS_DISK_ENTRY_SECTORS {
uint32 Type;
uint32 Offset; // Offset in memory
uint64 Reserved;
uint64 Start; // Start on disk (byte)
uint64 Length; // length on disk (byte)
} DCS_DISK_ENTRY_SECTORS;
CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_SECTORS) == 32, Wrong_size_DCS_DISK_ENTRY_SECTORS);
typedef struct _DCS_DISK_ENTRY_PARAMS {
uint32 Type;
uint32 Offset;
uint64 Reserved[2];
uint64 Length; // size of data
} DCS_DISK_ENTRY_PARAMS;
CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_PARAMS) == 32, Wrong_size_DCS_DISK_ENTRY_PARAMS);
typedef struct _DCS_DISK_ENTRY_DISKID {
uint32 Type;
uint32 MbrID;
uint64 ReservedDiskId;
DCS_GUID GptID;
} DCS_DISK_ENTRY_DISKID;
CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_DISKID) == 32, Wrong_size_DCS_DISK_ENTRY_DISKID);
#pragma warning(disable:4201)
typedef struct _DCS_DISK_ENTRY {
union {
struct {
uint32 Type;
uint32 Offset;
- byte reserved[16];
+ uint8 reserved[16];
uint64 Length; // size of structure at Offset
};
DCS_DISK_ENTRY_SECTORS Sectors;
DCS_DISK_ENTRY_DISKID DiskId;
DCS_DISK_ENTRY_PARAMS Prm;
};
} DCS_DISK_ENTRY;
#pragma warning(default:4201)
CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY) == 32, Wrong_size_DCS_DISK_ENTRY);
// Static compile time checks field offsets
#ifndef FIELD_OFFSET
#define FIELD_OFFSET(t, f) ((UINTN)(&((t*)0)->f))
#endif
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type) == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Type), Wrong_Type_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type) == FIELD_OFFSET(DCS_DISK_ENTRY_DISKID, Type), Wrong_Type_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Type) == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS, Type), Wrong_Type_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Length) == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Length), Wrong_Length_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Length) == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS, Length), Wrong_Length_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Offset) == FIELD_OFFSET(DCS_DISK_ENTRY_SECTORS, Offset), Wrong_Offset_offset);
CSTATIC_ASSERT(FIELD_OFFSET(DCS_DISK_ENTRY, Offset) == FIELD_OFFSET(DCS_DISK_ENTRY_PARAMS, Offset), Wrong_Offset_offset);
// DE type specific data
// DE List
typedef struct _DCS_DISK_ENTRY_LIST {
// EFI_TABLE_HEADER
uint64 Signature;
uint32 Revision;
uint32 HeaderSize; //< The size, in bytes, of the entire table including the EFI_TABLE_HEADER.
uint32 CRC32; //< The 32-bit CRC for the entire table. This value is computed by setting this field to 0, and computing the 32-bit CRC for HeaderSize bytes.
uint32 Reserved; //< Reserved field that must be set to 0.
//
uint32 Count;
uint32 DataSize;
//
DCS_DISK_ENTRY DE[15];
} DCS_DISK_ENTRY_LIST;
CSTATIC_ASSERT(sizeof(DCS_DISK_ENTRY_LIST) == 512, Wrong_size_DCS_DISK_ENTRY_LIST);
typedef struct _DCS_DEP_EXEC {
DCS_GUID ExecPartGuid;
uint16 ExecCmd[248];
} DCS_DEP_EXEC;
CSTATIC_ASSERT(sizeof(DCS_DEP_EXEC) == 512, Wrong_size_DCS_DEP_EXEC);
#define DCS_DEP_PWD_CACHE_SIGN SIGNATURE_64 ('P','W','D','C','A','C','H','E')
typedef struct _DCS_DEP_PWD_CACHE {
uint64 Sign;
uint32 CRC;
uint32 Count;
PasswordLegacy Pwd[4];
int32 Pim[4];
- byte pad[512 - 8 - 4 - 4 - (sizeof(PasswordLegacy) + 4) * 4];
+ uint8 pad[512 - 8 - 4 - 4 - (sizeof(PasswordLegacy) + 4) * 4];
} DCS_DEP_PWD_CACHE;
CSTATIC_ASSERT(sizeof(DCS_DEP_PWD_CACHE) == 512, Wrong_size_DCS_DEP_PWD_CACHE);
#pragma pack()
#endif // #if !defined(TC_WINDOWS_BOOT)
#endif // TC_HEADER_Boot_BootCommon
diff --git a/src/Boot/Windows/BootConfig.cpp b/src/Boot/Windows/BootConfig.cpp
index 0412d082..948dfd93 100644
--- a/src/Boot/Windows/BootConfig.cpp
+++ b/src/Boot/Windows/BootConfig.cpp
@@ -1,116 +1,116 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#include "BootConfig.h"
-byte BootSectorFlags;
+uint8 BootSectorFlags;
-byte BootLoaderDrive;
-byte BootDrive;
+uint8 BootLoaderDrive;
+uint8 BootDrive;
bool BootDriveGeometryValid = false;
bool PreventNormalSystemBoot = false;
bool PreventBootMenu = false;
char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
uint32 OuterVolumeBackupHeaderCrc;
bool BootStarted = false;
DriveGeometry BootDriveGeometry;
CRYPTO_INFO *BootCryptoInfo;
Partition EncryptedVirtualPartition;
Partition ActivePartition;
Partition PartitionFollowingActive;
bool ExtraBootPartitionPresent = false;
uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
uint64 HiddenVolumeStartSector;
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
void ReadBootSectorUserConfiguration ()
{
- byte userConfig;
+ uint8 userConfig;
AcquireSectorBuffer();
if (ReadWriteMBR (false, BootLoaderDrive, true) != BiosResultSuccess)
goto ret;
userConfig = SectorBuffer[TC_BOOT_SECTOR_USER_CONFIG_OFFSET];
#ifdef TC_WINDOWS_BOOT_AES
EnableHwEncryption (!(userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION));
#endif
PreventBootMenu = (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_ESC);
memcpy (CustomUserMessage, SectorBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET, TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH);
CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH] = 0;
if (userConfig & TC_BOOT_USER_CFG_FLAG_SILENT_MODE)
{
if (CustomUserMessage[0])
{
InitVideoMode();
Print (CustomUserMessage);
}
DisableScreenOutput();
}
if (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_PIM)
{
PimValueOrHiddenVolumeStartUnitNo.LowPart = 0;
memcpy (&PimValueOrHiddenVolumeStartUnitNo.LowPart, SectorBuffer + TC_BOOT_SECTOR_PIM_VALUE_OFFSET, TC_BOOT_SECTOR_PIM_VALUE_SIZE);
}
else
PimValueOrHiddenVolumeStartUnitNo.LowPart = -1;
OuterVolumeBackupHeaderCrc = *(uint32 *) (SectorBuffer + TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET);
ret:
ReleaseSectorBuffer();
}
-BiosResult UpdateBootSectorConfiguration (byte drive)
+BiosResult UpdateBootSectorConfiguration (uint8 drive)
{
uint64 mbrSector;
mbrSector.HighPart = 0;
mbrSector.LowPart = 0;
AcquireSectorBuffer();
/*
BiosResult result = ReadWriteMBR (false, drive);
if (result != BiosResultSuccess)
goto ret;
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
result = ReadWriteMBR (true, drive);
*/
BiosResult result = ReadWriteSectors (false, TC_BOOT_LOADER_BUFFER_SEGMENT, 0, drive, mbrSector, 8, false);
if (result != BiosResultSuccess)
goto ret;
CopyMemory (TC_BOOT_LOADER_BUFFER_SEGMENT, 0, SectorBuffer, TC_LB_SIZE);
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
CopyMemory (SectorBuffer, TC_BOOT_LOADER_BUFFER_SEGMENT,0, TC_LB_SIZE);
result = ReadWriteSectors (true, TC_BOOT_LOADER_BUFFER_SEGMENT, 0, drive, mbrSector, 8, false);
ret:
ReleaseSectorBuffer();
return result;
}
diff --git a/src/Boot/Windows/BootConfig.h b/src/Boot/Windows/BootConfig.h
index b66dc233..5338109f 100644
--- a/src/Boot/Windows/BootConfig.h
+++ b/src/Boot/Windows/BootConfig.h
@@ -1,46 +1,46 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_BootConfig
#define TC_HEADER_Boot_BootConfig
#include "Crypto.h"
#include "Platform.h"
#include "BootDiskIo.h"
-extern byte BootSectorFlags;
+extern uint8 BootSectorFlags;
-extern byte BootLoaderDrive;
-extern byte BootDrive;
+extern uint8 BootLoaderDrive;
+extern uint8 BootDrive;
extern bool BootDriveGeometryValid;
extern DriveGeometry BootDriveGeometry;
extern bool PreventNormalSystemBoot;
extern bool PreventBootMenu;
extern char CustomUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
extern uint32 OuterVolumeBackupHeaderCrc;
extern bool BootStarted;
extern CRYPTO_INFO *BootCryptoInfo;
extern Partition EncryptedVirtualPartition;
extern Partition ActivePartition;
extern Partition PartitionFollowingActive;
extern bool ExtraBootPartitionPresent;
extern uint64 PimValueOrHiddenVolumeStartUnitNo; // reuse this variable for stored PIM value to reduce memory usage
extern uint64 HiddenVolumeStartSector;
void ReadBootSectorUserConfiguration ();
-BiosResult UpdateBootSectorConfiguration (byte drive);
+BiosResult UpdateBootSectorConfiguration (uint8 drive);
#endif // TC_HEADER_Boot_BootConfig
diff --git a/src/Boot/Windows/BootConsoleIo.cpp b/src/Boot/Windows/BootConsoleIo.cpp
index 706e36f6..046f580b 100644
--- a/src/Boot/Windows/BootConsoleIo.cpp
+++ b/src/Boot/Windows/BootConsoleIo.cpp
@@ -74,71 +74,71 @@ void Print (const char *str)
while (c = *str++)
PrintChar (c);
}
void Print (uint32 number)
{
char str[12];
int pos = 0;
while (number >= 10)
{
str[pos++] = (char) (number % 10) + '0';
number /= 10;
}
str[pos] = (char) (number % 10) + '0';
while (pos >= 0)
PrintChar (str[pos--]);
}
void Print (const uint64 &number)
{
if (number.HighPart == 0)
Print (number.LowPart);
else
PrintHex (number);
}
-void PrintHex (byte b)
+void PrintHex (uint8 b)
{
PrintChar (((b >> 4) >= 0xA ? 'A' - 0xA : '0') + (b >> 4));
PrintChar (((b & 0xF) >= 0xA ? 'A' - 0xA : '0') + (b & 0xF));
}
void PrintHex (uint16 data)
{
- PrintHex (byte (data >> 8));
- PrintHex (byte (data));
+ PrintHex (uint8 (data >> 8));
+ PrintHex (uint8 (data));
}
void PrintHex (uint32 data)
{
PrintHex (uint16 (data >> 16));
PrintHex (uint16 (data));
}
void PrintHex (const uint64 &data)
{
PrintHex (data.HighPart);
PrintHex (data.LowPart);
}
void PrintRepeatedChar (char c, int n)
{
while (n-- > 0)
PrintChar (c);
}
void PrintEndl ()
{
Print ("\r\n");
}
void PrintEndl (int cnt)
@@ -192,177 +192,177 @@ void ClearScreen ()
mov ah, 2
int 0x10
}
}
void PrintBackspace ()
{
PrintChar (TC_BIOS_CHAR_BACKSPACE);
PrintCharAtCursor (' ');
}
void PrintError (const char *message)
{
Print (TC_BOOT_STR_ERROR);
Print (message);
PrintEndl();
Beep();
}
void PrintErrorNoEndl (const char *message)
{
Print (TC_BOOT_STR_ERROR);
Print (message);
Beep();
}
-byte GetShiftFlags ()
+uint8 GetShiftFlags ()
{
- byte flags;
+ uint8 flags;
__asm
{
mov ah, 2
int 0x16
mov flags, al
}
return flags;
}
-byte GetKeyboardChar ()
+uint8 GetKeyboardChar ()
{
return GetKeyboardChar (nullptr);
}
/*
inline void Sleep ()
{
__asm
{
mov al, 0
mov ah, 0x86
// Sleep for 250 milliseconds = 250 000 microseconds = 0x0003D090
mov cx, 0x0003
mov dx, 0xD090
int 0x15
}
}
*/
-byte GetKeyboardChar (byte *scanCode)
+uint8 GetKeyboardChar (uint8 *scanCode)
{
// Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer)
while (!IsKeyboardCharAvailable())
{
// reduce CPU usage by halting CPU until the next external interrupt is fired
__asm
{
hlt
}
}
- byte asciiCode;
- byte scan;
+ uint8 asciiCode;
+ uint8 scan;
__asm
{
mov ah, 0
int 0x16
mov asciiCode, al
mov scan, ah
}
if (scanCode)
*scanCode = scan;
return asciiCode;
}
bool IsKeyboardCharAvailable ()
{
bool available = false;
__asm
{
mov ah, 1
int 0x16
jz not_avail
mov available, true
not_avail:
}
return available;
}
bool EscKeyPressed ()
{
if (IsKeyboardCharAvailable ())
{
- byte keyScanCode;
+ uint8 keyScanCode;
GetKeyboardChar (&keyScanCode);
return keyScanCode == TC_BIOS_KEY_ESC;
}
return false;
}
void ClearBiosKeystrokeBuffer ()
{
__asm
{
push es
xor ax, ax
mov es, ax
mov di, 0x41e
mov cx, 32
cld
rep stosb
// reset position pointers at 0x41A and 0x41C to the begining
// of keyboard buffer to avoid revealing password/PIM length
mov ax, 0x001e
mov es:[0x41a], ax
mov es:[0x41c], ax
pop es
}
}
bool IsPrintable (char c)
{
return c >= ' ' && c <= '~';
}
bool IsDigit (char c)
{
return c >= '0' && c <= '9';
}
int GetString (char *buffer, size_t bufferSize)
{
- byte c;
- byte scanCode;
+ uint8 c;
+ uint8 scanCode;
size_t pos = 0;
while (pos < bufferSize)
{
c = GetKeyboardChar (&scanCode);
if (scanCode == TC_BIOS_KEY_ENTER)
break;
if (scanCode == TC_BIOS_KEY_ESC)
return 0;
buffer[pos++] = c;
PrintChar (IsPrintable (c) ? c : ' ');
}
return pos;
}
diff --git a/src/Boot/Windows/BootConsoleIo.h b/src/Boot/Windows/BootConsoleIo.h
index 349782eb..cf10d2c6 100644
--- a/src/Boot/Windows/BootConsoleIo.h
+++ b/src/Boot/Windows/BootConsoleIo.h
@@ -18,55 +18,55 @@
#define TC_DEBUG_PORT 0
#define TC_BIOS_KEY_ESC 1
#define TC_BIOS_KEY_BACKSPACE 14
#define TC_BIOS_KEY_ENTER 28
#define TC_BIOS_KEY_F1 0x3b
#define TC_BIOS_KEY_F2 0x3c
#define TC_BIOS_KEY_F3 0x3d
#define TC_BIOS_KEY_F4 0x3e
#define TC_BIOS_KEY_F5 0x3f
#define TC_BIOS_KEY_F6 0x40
#define TC_BIOS_KEY_F7 0x41
#define TC_BIOS_KEY_F8 0x42
#define TC_BIOS_KEY_F9 0x43
#define TC_BIOS_KEY_F10 0x44
#define TC_BIOS_SHIFTMASK_CAPSLOCK (1 << 6)
#define TC_BIOS_SHIFTMASK_LSHIFT (1 << 1)
#define TC_BIOS_SHIFTMASK_RSHIFT (1 << 0)
#define TC_BIOS_CHAR_BACKSPACE 8
#define TC_BIOS_MAX_CHARS_PER_LINE 80
void Beep ();
void ClearBiosKeystrokeBuffer ();
void ClearScreen ();
void DisableScreenOutput ();
void EnableScreenOutput ();
bool EscKeyPressed ();
-byte GetKeyboardChar ();
-byte GetKeyboardChar (byte *scanCode);
-byte GetShiftFlags ();
+uint8 GetKeyboardChar ();
+uint8 GetKeyboardChar (uint8 *scanCode);
+uint8 GetShiftFlags ();
int GetString (char *buffer, size_t bufferSize);
void InitVideoMode ();
bool IsKeyboardCharAvailable ();
bool IsPrintable (char c);
bool IsDigit (char c);
void Print (const char *str);
void Print (uint32 number);
void Print (const uint64 &number);
void PrintBackspace ();
void PrintChar (char c);
void PrintCharAtCursor (char c);
void PrintEndl ();
void PrintEndl (int cnt);
void PrintRepeatedChar (char c, int n);
void PrintError (const char *message);
void PrintErrorNoEndl (const char *message);
-void PrintHex (byte b);
+void PrintHex (uint8 b);
void PrintHex (uint16 data);
void PrintHex (uint32 data);
void PrintHex (const uint64 &data);
#endif // TC_HEADER_Boot_BootConsoleIo
diff --git a/src/Boot/Windows/BootDebug.cpp b/src/Boot/Windows/BootDebug.cpp
index bea063c1..b490f5e8 100644
--- a/src/Boot/Windows/BootDebug.cpp
+++ b/src/Boot/Windows/BootDebug.cpp
@@ -7,161 +7,161 @@
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#include "Platform.h"
#include "Bios.h"
#include "BootConsoleIo.h"
#include "BootDefs.h"
#include "BootDiskIo.h"
#include "BootDebug.h"
#ifdef TC_BOOT_TRACING_ENABLED
void InitDebugPort ()
{
__asm
{
mov dx, TC_DEBUG_PORT
mov ah, 1
int 0x17
mov dx, TC_DEBUG_PORT
mov ah, 0xe2
int 0x17
}
}
-void WriteDebugPort (byte dataByte)
+void WriteDebugPort (uint8 dataByte)
{
__asm
{
mov al, dataByte
mov dx, TC_DEBUG_PORT
mov ah, 0
int 0x17
}
}
#endif // TC_BOOT_TRACING_ENABLED
#ifdef TC_BOOT_DEBUG_ENABLED
extern "C" void PrintDebug (uint32 debugVal)
{
Print (debugVal);
PrintEndl();
}
void PrintVal (const char *message, const uint32 value, bool newLine, bool hex)
{
Print (message);
Print (": ");
if (hex)
PrintHex (value);
else
Print (value);
if (newLine)
PrintEndl();
}
void PrintVal (const char *message, const uint64 &value, bool newLine, bool hex)
{
Print (message);
Print (": ");
PrintHex (value);
if (newLine)
PrintEndl();
}
-void PrintHexDump (byte *mem, size_t size, uint16 *memSegment)
+void PrintHexDump (uint8 *mem, size_t size, uint16 *memSegment)
{
const size_t width = 16;
for (size_t pos = 0; pos < size; )
{
for (int pass = 1; pass <= 2; ++pass)
{
size_t i;
for (i = 0; i < width && pos < size; ++i)
{
- byte dataByte;
+ uint8 dataByte;
if (memSegment)
{
__asm
{
push es
mov si, ss:memSegment
mov es, ss:[si]
mov si, ss:mem
add si, pos
mov al, es:[si]
mov dataByte, al
pop es
}
pos++;
}
else
dataByte = mem[pos++];
if (pass == 1)
{
PrintHex (dataByte);
PrintChar (' ');
}
else
PrintChar (IsPrintable (dataByte) ? dataByte : '.');
}
if (pass == 1)
{
pos -= i;
PrintChar (' ');
}
}
PrintEndl ();
}
}
void PrintHexDump (uint16 memSegment, uint16 memOffset, size_t size)
{
- PrintHexDump ((byte *) memOffset, size, &memSegment);
+ PrintHexDump ((uint8 *) memOffset, size, &memSegment);
}
#endif // TC_BOOT_DEBUG_ENABLED
#ifdef TC_BOOT_STACK_CHECKING_ENABLED
extern "C" char end[];
static void PrintStackInfo ()
{
uint16 spReg;
__asm mov spReg, sp
Print ("Stack: "); Print (TC_BOOT_LOADER_STACK_TOP - spReg);
Print ("/"); Print (TC_BOOT_LOADER_STACK_TOP - (uint16) end);
}
void CheckStack ()
{
uint16 spReg;
__asm mov spReg, sp
if (*(uint32 *) end != 0x12345678UL || spReg < (uint16) end)
{
__asm cli
__asm mov sp, TC_BOOT_LOADER_STACK_TOP
PrintError ("Stack overflow");
diff --git a/src/Boot/Windows/BootDebug.h b/src/Boot/Windows/BootDebug.h
index f94ab900..35fce41f 100644
--- a/src/Boot/Windows/BootDebug.h
+++ b/src/Boot/Windows/BootDebug.h
@@ -24,37 +24,37 @@
# define TC_BOOT_STACK_CHECKING_ENABLED
extern "C" void CheckStack ();
#else
# define CheckStack()
#endif
#if 0
# define TC_BOOT_TRACING_ENABLED
# if 1
# define TC_TRACE_INT13
# endif
# if 0
# define TC_TRACE_INT15
# endif
#endif
#ifdef TC_BOOT_DEBUG_ENABLED
# define trace_point do { Print(__FILE__); PrintChar (':'); Print (TC_TO_STRING (__LINE__)); PrintEndl(); } while (false)
# define trace_val(VAL) PrintVal (#VAL, VAL);
# define trace_hex(VAL) do { Print (#VAL), PrintChar (':'); PrintHex (VAL); PrintEndl(); } while (false)
# define assert(COND) do { if (!(COND)) { trace_point; __asm jmp $ } } while (false)
#else
# define trace_point
# define trace_val(VAL)
# define trace_hex(VAL)
# define assert(COND)
#endif
void InitDebugPort ();
void InitStackChecker ();
-void WriteDebugPort (byte dataByte);
-void PrintHexDump (byte *mem, size_t size, uint16 *memSegment = nullptr);
+void WriteDebugPort (uint8 dataByte);
+void PrintHexDump (uint8 *mem, size_t size, uint16 *memSegment = nullptr);
void PrintHexDump (uint16 memSegment, uint16 memOffset, size_t size);
void PrintVal (const char *message, const uint32 value, bool newLine = true, bool hex = false);
void PrintVal (const char *message, const uint64 &value, bool newLine = true, bool hex = false);
#endif // TC_HEADER_Boot_BootDebug
diff --git a/src/Boot/Windows/BootDiskIo.cpp b/src/Boot/Windows/BootDiskIo.cpp
index 437c462e..ddd00e1c 100644
--- a/src/Boot/Windows/BootDiskIo.cpp
+++ b/src/Boot/Windows/BootDiskIo.cpp
@@ -1,493 +1,493 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#include "Bios.h"
#include "BootConsoleIo.h"
#include "BootConfig.h"
#include "BootDebug.h"
#include "BootDefs.h"
#include "BootDiskIo.h"
#include "BootStrings.h"
-byte SectorBuffer[TC_LB_SIZE];
+uint8 SectorBuffer[TC_LB_SIZE];
#ifdef TC_BOOT_DEBUG_ENABLED
static bool SectorBufferInUse = false;
void AcquireSectorBuffer ()
{
if (SectorBufferInUse)
TC_THROW_FATAL_EXCEPTION;
SectorBufferInUse = true;
}
void ReleaseSectorBuffer ()
{
SectorBufferInUse = false;
}
#endif
-bool IsLbaSupported (byte drive)
+bool IsLbaSupported (uint8 drive)
{
- static byte CachedDrive = TC_INVALID_BIOS_DRIVE;
+ static uint8 CachedDrive = TC_INVALID_BIOS_DRIVE;
static bool CachedStatus;
uint16 result = 0;
if (CachedDrive == drive)
goto ret;
__asm
{
mov bx, 0x55aa
mov dl, drive
mov ah, 0x41
int 0x13
jc err
mov result, bx
err:
}
CachedDrive = drive;
CachedStatus = (result == 0xaa55);
ret:
return CachedStatus;
}
-void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs)
+void PrintDiskError (BiosResult error, bool write, uint8 drive, const uint64 *sector, const ChsAddress *chs)
{
PrintEndl();
Print (write ? "Write" : "Read"); Print (" error:");
Print (error);
Print (" Drive:");
Print (drive ^ 0x80);
if (sector)
{
Print (" Sector:");
Print (*sector);
}
if (chs)
{
Print (" CHS:");
Print (*chs);
}
PrintEndl();
Beep();
}
void Print (const ChsAddress &chs)
{
Print (chs.Cylinder);
PrintChar ('/');
Print (chs.Head);
PrintChar ('/');
Print (chs.Sector);
}
void PrintSectorCountInMB (const uint64 &sectorCount)
{
Print (sectorCount >> (TC_LB_SIZE_BIT_SHIFT_DIVISOR + 2)); Print (" MiB ");
}
-BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
+BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent)
{
CheckStack();
- byte cylinderLow = (byte) chs.Cylinder;
- byte sector = chs.Sector;
- sector |= byte (chs.Cylinder >> 2) & 0xc0;
- byte function = write ? 0x03 : 0x02;
+ uint8 cylinderLow = (uint8) chs.Cylinder;
+ uint8 sector = chs.Sector;
+ sector |= uint8 (chs.Cylinder >> 2) & 0xc0;
+ uint8 function = write ? 0x03 : 0x02;
BiosResult result;
- byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
+ uint8 tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
do
{
result = BiosResultSuccess;
__asm
{
push es
mov ax, bufferSegment
mov es, ax
mov bx, bufferOffset
mov dl, drive
mov ch, cylinderLow
mov si, chs
mov dh, [si].Head
mov cl, sector
mov al, sectorCount
mov ah, function
int 0x13
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
mov result, ah
ok:
pop es
}
if (result == BiosResultEccCorrected)
result = BiosResultSuccess;
// Some BIOSes report I/O errors prematurely in some cases
} while (result != BiosResultSuccess && --tryCount != 0);
if (!silent && result != BiosResultSuccess)
PrintDiskError (result, write, drive, nullptr, &chs);
return result;
}
#ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
-BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
+BiosResult ReadWriteSectors (bool write, uint8 *buffer, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent)
{
uint16 codeSeg;
__asm mov codeSeg, cs
return ReadWriteSectors (write, codeSeg, (uint16) buffer, drive, chs, sectorCount, silent);
}
-BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
+BiosResult ReadSectors (uint8 *buffer, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent)
{
return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent);
}
#if 0
-BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
+BiosResult WriteSectors (uint8 *buffer, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent)
{
return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent);
}
#endif
#endif
-static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
CheckStack();
if (!IsLbaSupported (drive))
{
DriveGeometry geometry;
BiosResult result = GetDriveGeometry (drive, geometry, silent);
if (result != BiosResultSuccess)
return result;
ChsAddress chs;
LbaToChs (geometry, sector, chs);
return ReadWriteSectors (write, (uint16) (dapPacket.Buffer >> 16), (uint16) dapPacket.Buffer, drive, chs, sectorCount, silent);
}
dapPacket.Size = sizeof (dapPacket);
dapPacket.Reserved = 0;
dapPacket.SectorCount = sectorCount;
dapPacket.Sector = sector;
- byte function = write ? 0x43 : 0x42;
+ uint8 function = write ? 0x43 : 0x42;
BiosResult result;
- byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
+ uint8 tryCount = TC_MAX_BIOS_DISK_IO_RETRIES;
do
{
result = BiosResultSuccess;
__asm
{
mov bx, 0x55aa
mov dl, drive
mov si, [dapPacket]
mov ah, function
xor al, al
int 0x13
jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes
mov result, ah
ok:
}
if (result == BiosResultEccCorrected)
result = BiosResultSuccess;
// Some BIOSes report I/O errors prematurely in some cases
} while (result != BiosResultSuccess && --tryCount != 0);
if (!silent && result != BiosResultSuccess)
PrintDiskError (result, write, drive, &sector);
return result;
}
-BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+BiosResult ReadWriteSectors (bool write, uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
BiosLbaPacket dapPacket;
dapPacket.Buffer = (uint32) buffer;
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
}
-BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
BiosLbaPacket dapPacket;
dapPacket.Buffer = ((uint32) bufferSegment << 16) | bufferOffset;
return ReadWriteSectors (write, dapPacket, drive, sector, sectorCount, silent);
}
-BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
return ReadWriteSectors (false, bufferSegment, bufferOffset, drive, sector, sectorCount, silent);
}
-BiosResult ReadSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+BiosResult ReadSectors (uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
BiosResult result;
uint16 codeSeg;
__asm mov codeSeg, cs
result = ReadSectors (BootStarted ? codeSeg : TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, drive, sector, sectorCount, silent);
// Alternative segment is used to prevent memory corruption caused by buggy BIOSes
if (!BootStarted)
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, (uint16) buffer, buffer, sectorCount * TC_LB_SIZE);
return result;
}
-BiosResult WriteSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
+BiosResult WriteSectors (uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent)
{
return ReadWriteSectors (true, buffer, drive, sector, sectorCount, silent);
}
-BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent)
+BiosResult GetDriveGeometry (uint8 drive, DriveGeometry &geometry, bool silent)
{
CheckStack();
- byte maxCylinderLow, maxHead, maxSector;
+ uint8 maxCylinderLow, maxHead, maxSector;
BiosResult result;
__asm
{
push es
mov dl, drive
mov ah, 0x08
int 0x13
mov result, ah
mov maxCylinderLow, ch
mov maxSector, cl
mov maxHead, dh
pop es
}
if (result == BiosResultSuccess)
{
geometry.Cylinders = (maxCylinderLow | (uint16 (maxSector & 0xc0) << 2)) + 1;
geometry.Heads = maxHead + 1;
geometry.Sectors = maxSector & ~0xc0;
}
else if (!silent)
{
Print ("Drive ");
Print (drive ^ 0x80);
Print (" not found: ");
PrintErrorNoEndl ("");
Print (result);
PrintEndl();
}
return result;
}
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba)
{
lba.HighPart = 0;
lba.LowPart = (uint32 (chs.Cylinder) * geometry.Heads + chs.Head) * geometry.Sectors + chs.Sector - 1;
}
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs)
{
- chs.Sector = (byte) ((lba.LowPart % geometry.Sectors) + 1);
+ chs.Sector = (uint8) ((lba.LowPart % geometry.Sectors) + 1);
uint32 ch = lba.LowPart / geometry.Sectors;
- chs.Head = (byte) (ch % geometry.Heads);
+ chs.Head = (uint8) (ch % geometry.Heads);
chs.Cylinder = (uint16) (ch / geometry.Heads);
}
void PartitionEntryMBRToPartition (const PartitionEntryMBR &partEntry, Partition &partition)
{
partition.Active = partEntry.BootIndicator == 0x80;
partition.EndSector.HighPart = 0;
partition.EndSector.LowPart = partEntry.StartLBA + partEntry.SectorCountLBA - 1;
partition.SectorCount.HighPart = 0;
partition.SectorCount.LowPart = partEntry.SectorCountLBA;
partition.StartSector.HighPart = 0;
partition.StartSector.LowPart = partEntry.StartLBA;
partition.Type = partEntry.Type;
}
-BiosResult ReadWriteMBR (bool write, byte drive, bool silent)
+BiosResult ReadWriteMBR (bool write, uint8 drive, bool silent)
{
uint64 mbrSector;
mbrSector.HighPart = 0;
mbrSector.LowPart = 0;
if (write)
return WriteSectors (SectorBuffer, drive, mbrSector, 1, silent);
return ReadSectors (SectorBuffer, drive, mbrSector, 1, silent); // Uses alternative segment
}
-BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly, Partition *findPartitionFollowingThis, bool silent)
+BiosResult GetDrivePartitions (uint8 drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly, Partition *findPartitionFollowingThis, bool silent)
{
Partition *followingPartition;
Partition tmpPartition;
if (findPartitionFollowingThis)
{
assert (partitionArrayCapacity == 1);
partitionArrayCapacity = 0xff;
followingPartition = partitionArray;
partitionArray = &tmpPartition;
followingPartition->Drive = TC_INVALID_BIOS_DRIVE;
followingPartition->StartSector.LowPart = 0xFFFFffffUL;
}
AcquireSectorBuffer();
BiosResult result = ReadWriteMBR (false, drive, silent);
ReleaseSectorBuffer();
partitionCount = 0;
MBR *mbr = (MBR *) SectorBuffer;
if (result != BiosResultSuccess || mbr->Signature != 0xaa55)
return result;
PartitionEntryMBR mbrPartitions[4];
memcpy (mbrPartitions, mbr->Partitions, sizeof (mbrPartitions));
size_t partitionArrayPos = 0, partitionNumber;
for (partitionNumber = 0;
partitionNumber < array_capacity (mbrPartitions) && partitionArrayPos < partitionArrayCapacity;
++partitionNumber)
{
const PartitionEntryMBR &partEntry = mbrPartitions[partitionNumber];
if (partEntry.SectorCountLBA > 0)
{
Partition &partition = partitionArray[partitionArrayPos];
PartitionEntryMBRToPartition (partEntry, partition);
if (activeOnly && !partition.Active)
continue;
partition.Drive = drive;
partition.Number = partitionArrayPos;
if (partEntry.Type == 0x5 || partEntry.Type == 0xf) // Extended partition
{
if (IsLbaSupported (drive))
{
// Find all extended partitions
uint64 firstExtStartLBA = partition.StartSector;
uint64 extStartLBA = partition.StartSector;
MBR *extMbr = (MBR *) SectorBuffer;
while (partitionArrayPos < partitionArrayCapacity &&
- (result = ReadSectors ((byte *) extMbr, drive, extStartLBA, 1, silent)) == BiosResultSuccess
+ (result = ReadSectors ((uint8 *) extMbr, drive, extStartLBA, 1, silent)) == BiosResultSuccess
&& extMbr->Signature == 0xaa55)
{
if (extMbr->Partitions[0].SectorCountLBA > 0)
{
Partition &logPart = partitionArray[partitionArrayPos];
PartitionEntryMBRToPartition (extMbr->Partitions[0], logPart);
logPart.Drive = drive;
logPart.Number = partitionArrayPos;
logPart.Primary = false;
logPart.StartSector.LowPart += extStartLBA.LowPart;
logPart.EndSector.LowPart += extStartLBA.LowPart;
if (findPartitionFollowingThis)
{
if (logPart.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
&& logPart.StartSector.LowPart < followingPartition->StartSector.LowPart)
{
*followingPartition = logPart;
}
}
else
++partitionArrayPos;
}
// Secondary extended
if (extMbr->Partitions[1].Type != 0x5 && extMbr->Partitions[1].Type == 0xf
|| extMbr->Partitions[1].SectorCountLBA == 0)
break;
extStartLBA.LowPart = extMbr->Partitions[1].StartLBA + firstExtStartLBA.LowPart;
}
}
}
else
{
partition.Primary = true;
if (findPartitionFollowingThis)
{
if (partition.StartSector.LowPart > findPartitionFollowingThis->EndSector.LowPart
&& partition.StartSector.LowPart < followingPartition->StartSector.LowPart)
{
*followingPartition = partition;
}
}
else
++partitionArrayPos;
}
}
}
partitionCount = partitionArrayPos;
return result;
}
-bool GetActivePartition (byte drive)
+bool GetActivePartition (uint8 drive)
{
size_t partCount;
if (GetDrivePartitions (drive, &ActivePartition, 1, partCount, true) != BiosResultSuccess || partCount < 1)
{
ActivePartition.Drive = TC_INVALID_BIOS_DRIVE;
PrintError (TC_BOOT_STR_NO_BOOT_PARTITION);
return false;
}
return true;
}
diff --git a/src/Boot/Windows/BootDiskIo.h b/src/Boot/Windows/BootDiskIo.h
index 621acd8f..0b92aa29 100644
--- a/src/Boot/Windows/BootDiskIo.h
+++ b/src/Boot/Windows/BootDiskIo.h
@@ -1,121 +1,121 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_BootDiskIo
#define TC_HEADER_Boot_BootDiskIo
#include "Bios.h"
#include "BootDebug.h"
#include "BootDefs.h"
#define TC_MAX_BIOS_DISK_IO_RETRIES 5
enum
{
BiosResultEccCorrected = 0x11
};
#pragma pack(1)
struct PartitionEntryMBR
{
- byte BootIndicator;
+ uint8 BootIndicator;
- byte StartHead;
- byte StartCylSector;
- byte StartCylinder;
+ uint8 StartHead;
+ uint8 StartCylSector;
+ uint8 StartCylinder;
- byte Type;
+ uint8 Type;
- byte EndHead;
- byte EndSector;
- byte EndCylinder;
+ uint8 EndHead;
+ uint8 EndSector;
+ uint8 EndCylinder;
uint32 StartLBA;
uint32 SectorCountLBA;
};
struct MBR
{
- byte Code[446];
+ uint8 Code[446];
PartitionEntryMBR Partitions[4];
uint16 Signature;
};
struct BiosLbaPacket
{
- byte Size;
- byte Reserved;
+ uint8 Size;
+ uint8 Reserved;
uint16 SectorCount;
uint32 Buffer;
uint64 Sector;
};
#pragma pack()
struct ChsAddress
{
uint16 Cylinder;
- byte Head;
- byte Sector;
+ uint8 Head;
+ uint8 Sector;
};
struct Partition
{
- byte Number;
- byte Drive;
+ uint8 Number;
+ uint8 Drive;
bool Active;
uint64 EndSector;
bool Primary;
uint64 SectorCount;
uint64 StartSector;
- byte Type;
+ uint8 Type;
};
struct DriveGeometry
{
uint16 Cylinders;
- byte Heads;
- byte Sectors;
+ uint8 Heads;
+ uint8 Sectors;
};
#ifdef TC_BOOT_DEBUG_ENABLED
void AcquireSectorBuffer ();
void ReleaseSectorBuffer ();
#else
# define AcquireSectorBuffer()
# define ReleaseSectorBuffer()
#endif
void ChsToLba (const DriveGeometry &geometry, const ChsAddress &chs, uint64 &lba);
-bool GetActivePartition (byte drive);
-BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent = false);
-BiosResult GetDrivePartitions (byte drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly = false, Partition *findPartitionFollowingThis = nullptr, bool silent = false);
-bool IsLbaSupported (byte drive);
+bool GetActivePartition (uint8 drive);
+BiosResult GetDriveGeometry (uint8 drive, DriveGeometry &geometry, bool silent = false);
+BiosResult GetDrivePartitions (uint8 drive, Partition *partitionArray, size_t partitionArrayCapacity, size_t &partitionCount, bool activeOnly = false, Partition *findPartitionFollowingThis = nullptr, bool silent = false);
+bool IsLbaSupported (uint8 drive);
void LbaToChs (const DriveGeometry &geometry, const uint64 &lba, ChsAddress &chs);
void Print (const ChsAddress &chs);
-void PrintDiskError (BiosResult error, bool write, byte drive, const uint64 *sector, const ChsAddress *chs = nullptr);
+void PrintDiskError (BiosResult error, bool write, uint8 drive, const uint64 *sector, const ChsAddress *chs = nullptr);
void PrintSectorCountInMB (const uint64 &sectorCount);
-BiosResult ReadWriteMBR (bool write, byte drive, bool silent = false);
-BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
-BiosResult ReadSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
-BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
-BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent);
-BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent);
-BiosResult WriteSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
-BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
-
-extern byte SectorBuffer[TC_LB_SIZE];
+BiosResult ReadWriteMBR (bool write, uint8 drive, bool silent = false);
+BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
+BiosResult ReadSectors (uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
+BiosResult ReadSectors (uint8 *buffer, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent = false);
+BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent);
+BiosResult ReadWriteSectors (bool write, uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent);
+BiosResult WriteSectors (uint8 *buffer, uint8 drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
+BiosResult WriteSectors (uint8 *buffer, uint8 drive, const ChsAddress &chs, uint8 sectorCount, bool silent = false);
+
+extern uint8 SectorBuffer[TC_LB_SIZE];
#endif // TC_HEADER_Boot_BootDiskIo
diff --git a/src/Boot/Windows/BootEncryptedIo.cpp b/src/Boot/Windows/BootEncryptedIo.cpp
index 8ca55635..24fbbbd0 100644
--- a/src/Boot/Windows/BootEncryptedIo.cpp
+++ b/src/Boot/Windows/BootEncryptedIo.cpp
@@ -1,109 +1,109 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#include "Crypto.h"
#include "Platform.h"
#include "BootConfig.h"
#include "BootDebug.h"
#include "BootDefs.h"
#include "BootDiskIo.h"
#include "BootEncryptedIo.h"
-BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount)
+BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, uint8 drive, uint64 sector, uint16 sectorCount)
{
BiosResult result;
bool decrypt = true;
if (BootCryptoInfo->hiddenVolume)
{
if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount))
return BiosResultInvalidFunction;
if (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
{
// Remap the request to the hidden volume
sector -= EncryptedVirtualPartition.StartSector;
sector += HiddenVolumeStartSector;
}
else
decrypt = false;
}
result = ReadSectors (destSegment, destOffset, drive, sector, sectorCount);
if (result != BiosResultSuccess || !decrypt)
return result;
if (BootCryptoInfo->hiddenVolume)
{
// Convert sector number to data unit number of the hidden volume
sector -= HiddenVolumeStartSector;
sector += PimValueOrHiddenVolumeStartUnitNo;
}
if (drive == EncryptedVirtualPartition.Drive)
{
while (sectorCount-- > 0)
{
if (BootCryptoInfo->hiddenVolume
|| (sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector))
{
AcquireSectorBuffer();
CopyMemory (destSegment, destOffset, SectorBuffer, TC_LB_SIZE);
DecryptDataUnits (SectorBuffer, &sector, 1, BootCryptoInfo);
CopyMemory (SectorBuffer, destSegment, destOffset, TC_LB_SIZE);
ReleaseSectorBuffer();
}
++sector;
destOffset += TC_LB_SIZE;
}
}
return result;
}
-BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount)
+BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, uint8 drive, uint64 sector, uint16 sectorCount)
{
BiosResult result = BiosResultSuccess;
AcquireSectorBuffer();
uint64 dataUnitNo;
uint64 writeOffset;
dataUnitNo = sector;
writeOffset.HighPart = 0;
writeOffset.LowPart = 0;
if (BootCryptoInfo->hiddenVolume)
{
if (ReadWritePartiallyCoversEncryptedArea (sector, sectorCount))
return BiosResultInvalidFunction;
// Remap the request to the hidden volume
writeOffset = HiddenVolumeStartSector;
writeOffset -= EncryptedVirtualPartition.StartSector;
dataUnitNo -= EncryptedVirtualPartition.StartSector;
dataUnitNo += PimValueOrHiddenVolumeStartUnitNo;
}
while (sectorCount-- > 0)
{
CopyMemory (sourceSegment, sourceOffset, SectorBuffer, TC_LB_SIZE);
if (drive == EncryptedVirtualPartition.Drive && sector >= EncryptedVirtualPartition.StartSector && sector <= EncryptedVirtualPartition.EndSector)
{
EncryptDataUnits (SectorBuffer, &dataUnitNo, 1, BootCryptoInfo);
}
diff --git a/src/Boot/Windows/BootEncryptedIo.h b/src/Boot/Windows/BootEncryptedIo.h
index d1c9e5f3..d2fa6d96 100644
--- a/src/Boot/Windows/BootEncryptedIo.h
+++ b/src/Boot/Windows/BootEncryptedIo.h
@@ -1,22 +1,22 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_BootEncryptionIo
#define TC_HEADER_Boot_BootEncryptionIo
#include "Platform.h"
-BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, byte drive, uint64 sector, uint16 sectorCount);
-BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byte drive, uint64 sector, uint16 sectorCount);
+BiosResult ReadEncryptedSectors (uint16 destSegment, uint16 destOffset, uint8 drive, uint64 sector, uint16 sectorCount);
+BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, uint8 drive, uint64 sector, uint16 sectorCount);
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 &sector, uint16 sectorCount);
#endif // TC_HEADER_Boot_BootEncryptionIo
diff --git a/src/Boot/Windows/BootMain.cpp b/src/Boot/Windows/BootMain.cpp
index 8bfbe4b3..e85f2be5 100644
--- a/src/Boot/Windows/BootMain.cpp
+++ b/src/Boot/Windows/BootMain.cpp
@@ -57,61 +57,61 @@ static void InitScreen ()
PrintEndl (2);
}
static void PrintMainMenu ()
{
if (PreventBootMenu)
return;
Print (" Keyboard Controls:\r\n");
Print (" [F5] Hide/Show Password and PIM\r\n");
Print (" [Esc] ");
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
Print ((BootSectorFlags & TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE) != TC_HIDDEN_OS_CREATION_PHASE_NONE
? "Boot Non-Hidden System (Boot Manager)"
: "Skip Authentication (Boot Manager)");
#else // TC_WINDOWS_BOOT_RESCUE_DISK_MODE
Print ("Skip Authentication (Boot Manager)");
Print ("\r\n [F8] "); Print ("Repair Options");
#endif // TC_WINDOWS_BOOT_RESCUE_DISK_MODE
PrintEndl (3);
}
-static bool IsMenuKey (byte scanCode)
+static bool IsMenuKey (uint8 scanCode)
{
#ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
return scanCode == TC_MENU_KEY_REPAIR;
#else
return false;
#endif
}
static bool AskYesNo (const char *message)
{
Print (message);
Print ("? (y/n): ");
while (true)
{
switch (GetKeyboardChar())
{
case 'y':
case 'Y':
case 'z':
case 'Z':
Print ("y\r\n");
return true;
case 'n':
case 'N':
Print ("n\r\n");
return false;
default:
@@ -122,66 +122,66 @@ static bool AskYesNo (const char *message)
static int AskSelection (const char *options[], size_t optionCount)
{
for (int i = 0; i < optionCount; ++i)
{
Print ("["); Print (i + 1); Print ("] ");
Print (options[i]);
PrintEndl();
}
Print ("[Esc] Cancel\r\n\r\n");
Print ("To select, press 1-9: ");
char str;
while (true)
{
if (GetString (&str, 1) == 0)
return 0;
if (str >= '1' && str <= optionCount + '0')
return str - '0';
Beep();
PrintBackspace();
}
}
-static byte AskPassword (Password &password, int& pim)
+static uint8 AskPassword (Password &password, int& pim)
{
size_t pos = 0;
- byte scanCode;
- byte asciiCode;
- byte hidePassword = 1;
+ uint8 scanCode;
+ uint8 asciiCode;
+ uint8 hidePassword = 1;
pim = 0;
Print ("Enter password");
Print (PreventNormalSystemBoot ? " for hidden system:\r\n" : ": ");
while (true)
{
asciiCode = GetKeyboardChar (&scanCode);
switch (scanCode)
{
case TC_BIOS_KEY_ENTER:
password.Length = pos;
Print ("\r");
if (!PreventNormalSystemBoot)
Print ("Enter password: ");
pos = 0;
while (pos < MAX_PASSWORD)
{
pos++;
if (pos < MAX_PASSWORD)
PrintChar ('*');
else
PrintCharAtCursor ('*');
}
ClearBiosKeystrokeBuffer();
PrintEndl();
@@ -285,87 +285,87 @@ static byte AskPassword (Password &password, int& pim)
default:
if (scanCode == TC_BIOS_KEY_ESC || IsMenuKey (scanCode))
{
burn (password.Text, sizeof (password.Text));
ClearBiosKeystrokeBuffer();
PrintEndl();
return scanCode;
}
}
if (!IsDigit (asciiCode) || pos == MAX_PIM)
{
Beep();
continue;
}
pim = 10*pim + (asciiCode - '0');
pos++;
if (hidePassword) asciiCode = '*';
if (pos < MAX_PIM)
PrintChar (asciiCode);
else
PrintCharAtCursor (asciiCode);
}
}
}
-static void ExecuteBootSector (byte drive, byte *sectorBuffer)
+static void ExecuteBootSector (uint8 drive, uint8 *sectorBuffer)
{
Print ("Booting...\r\n");
CopyMemory (sectorBuffer, 0x0000, 0x7c00, TC_LB_SIZE);
BootStarted = true;
uint32 addr = 0x7c00;
__asm
{
cli
mov dl, drive // Boot drive
mov dh, 0
xor ax, ax
mov si, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
sti
jmp cs:addr
}
}
-static bool OpenVolume (byte drive, Password &password, int pim, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32, bool skipNormal, bool skipHidden)
+static bool OpenVolume (uint8 drive, Password &password, int pim, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32, bool skipNormal, bool skipHidden)
{
int volumeType;
bool hiddenVolume;
uint64 headerSec;
AcquireSectorBuffer();
for (volumeType = 1; volumeType <= 2; ++volumeType)
{
hiddenVolume = (volumeType == 2);
if (hiddenVolume)
{
if (skipHidden || PartitionFollowingActive.Drive != drive || PartitionFollowingActive.SectorCount <= ActivePartition.SectorCount)
continue;
headerSec = PartitionFollowingActive.StartSector + TC_HIDDEN_VOLUME_HEADER_OFFSET / TC_LB_SIZE;
}
else
{
if (skipNormal)
continue;
headerSec.HighPart = 0;
headerSec.LowPart = TC_BOOT_VOLUME_HEADER_SECTOR;
}
if (ReadSectors (SectorBuffer, drive, headerSec, 1) != BiosResultSuccess)
continue;
@@ -393,61 +393,61 @@ static bool OpenVolume (byte drive, Password &password, int pim, CRYPTO_INFO **c
static bool CheckMemoryRequirements ()
{
uint16 codeSeg;
__asm mov codeSeg, cs
if (codeSeg == TC_BOOT_LOADER_LOWMEM_SEGMENT)
{
PrintErrorNoEndl ("BIOS reserved too much memory: ");
uint16 memFree;
__asm
{
push es
xor ax, ax
mov es, ax
mov ax, es:[0x413]
mov memFree, ax
pop es
}
Print (memFree);
PrintEndl();
Print (TC_BOOT_STR_UPGRADE_BIOS);
return false;
}
return true;
}
-static bool MountVolume (byte drive, byte &exitKey, bool skipNormal, bool skipHidden)
+static bool MountVolume (uint8 drive, uint8 &exitKey, bool skipNormal, bool skipHidden)
{
BootArguments *bootArguments = (BootArguments *) TC_BOOT_LOADER_ARGS_OFFSET;
int incorrectPasswordCount = 0, pim = 0;
EraseMemory (bootArguments, sizeof (*bootArguments));
// Open volume header
while (true)
{
exitKey = AskPassword (bootArguments->BootPassword, pim);
if (exitKey != TC_BIOS_KEY_ENTER)
return false;
Print ("Verifying password...");
if (OpenVolume (BootDrive, bootArguments->BootPassword, pim, &BootCryptoInfo, &bootArguments->HeaderSaltCrc32, skipNormal, skipHidden))
{
Print ("OK\r\n");
break;
}
if (GetShiftFlags() & TC_BIOS_SHIFTMASK_CAPSLOCK)
Print ("Warning: Caps Lock is on.\r\n");
Print ("Incorrect password.\r\n\r\n");
if (++incorrectPasswordCount == 4)
{
#ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
Print ("If you are sure the password is correct, the key data may be damaged.\r\n"
@@ -472,163 +472,163 @@ static bool MountVolume (byte drive, byte &exitKey, bool skipNormal, bool skipHi
bootArguments->Flags |= TC_BOOT_ARGS_FLAG_EXTRA_BOOT_PARTITION;
TC_SET_BOOT_ARGUMENTS_SIGNATURE (bootArguments->Signature);
// Setup virtual encrypted partition
if (BootCryptoInfo->EncryptedAreaLength.HighPart != 0 || BootCryptoInfo->EncryptedAreaLength.LowPart != 0)
{
EncryptedVirtualPartition.Drive = BootDrive;
EncryptedVirtualPartition.StartSector = BootCryptoInfo->EncryptedAreaStart >> TC_LB_SIZE_BIT_SHIFT_DIVISOR;
PimValueOrHiddenVolumeStartUnitNo = EncryptedVirtualPartition.StartSector;
HiddenVolumeStartSector = PartitionFollowingActive.StartSector;
HiddenVolumeStartSector += EncryptedVirtualPartition.StartSector;
EncryptedVirtualPartition.SectorCount = BootCryptoInfo->EncryptedAreaLength >> TC_LB_SIZE_BIT_SHIFT_DIVISOR;
EncryptedVirtualPartition.EndSector = EncryptedVirtualPartition.SectorCount - 1;
EncryptedVirtualPartition.EndSector += EncryptedVirtualPartition.StartSector;
}
else
{
// Drive not encrypted
EncryptedVirtualPartition.Drive = TC_INVALID_BIOS_DRIVE;
}
return true;
}
-static bool GetSystemPartitions (byte drive)
+static bool GetSystemPartitions (uint8 drive)
{
size_t partCount;
if (!GetActivePartition (drive))
return false;
// Find partition following the active one
GetDrivePartitions (drive, &PartitionFollowingActive, 1, partCount, false, &ActivePartition);
// If there is an extra boot partition, use the partitions following it.
// The real boot partition is determined in BootEncryptedDrive().
if (ActivePartition.SectorCount.HighPart == 0 && ActivePartition.SectorCount.LowPart <= TC_MAX_EXTRA_BOOT_PARTITION_SIZE / TC_LB_SIZE
&& PartitionFollowingActive.Drive != TC_INVALID_BIOS_DRIVE)
{
ExtraBootPartitionPresent = true;
ActivePartition = PartitionFollowingActive;
GetDrivePartitions (drive, &PartitionFollowingActive, 1, partCount, false, &ActivePartition);
}
return true;
}
-static byte BootEncryptedDrive ()
+static uint8 BootEncryptedDrive ()
{
BootArguments *bootArguments = (BootArguments *) TC_BOOT_LOADER_ARGS_OFFSET;
- byte exitKey;
+ uint8 exitKey;
BootCryptoInfo = NULL;
if (!GetSystemPartitions (BootDrive))
goto err;
if (!MountVolume (BootDrive, exitKey, PreventNormalSystemBoot, false))
return exitKey;
if (!CheckMemoryRequirements ())
goto err;
if (BootCryptoInfo->hiddenVolume)
{
EncryptedVirtualPartition = ActivePartition;
bootArguments->DecoySystemPartitionStart = ActivePartition.StartSector << TC_LB_SIZE_BIT_SHIFT_DIVISOR;
}
if (ExtraBootPartitionPresent && !GetActivePartition (BootDrive))
goto err;
if (ReadWriteMBR (false, ActivePartition.Drive) != BiosResultSuccess)
goto err;
bootArguments->BootDriveSignature = *(uint32 *) (SectorBuffer + 0x1b8);
if (!InstallInterruptFilters())
goto err;
- bootArguments->BootArgumentsCrc32 = GetCrc32 ((byte *) bootArguments, (byte *) &bootArguments->BootArgumentsCrc32 - (byte *) bootArguments);
+ bootArguments->BootArgumentsCrc32 = GetCrc32 ((uint8 *) bootArguments, (uint8 *) &bootArguments->BootArgumentsCrc32 - (uint8 *) bootArguments);
while (true)
{
// Execute boot sector of the active partition
if (ReadSectors (SectorBuffer, ActivePartition.Drive, ActivePartition.StartSector, 1) == BiosResultSuccess)
{
if (*(uint16 *) (SectorBuffer + 510) != 0xaa55)
{
PrintError (TC_BOOT_STR_NO_BOOT_PARTITION);
GetKeyboardChar();
}
ExecuteBootSector (ActivePartition.Drive, SectorBuffer);
}
GetKeyboardChar();
}
err:
if (BootCryptoInfo)
{
crypto_close (BootCryptoInfo);
BootCryptoInfo = NULL;
}
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
PimValueOrHiddenVolumeStartUnitNo.LowPart = -1;
#endif
EncryptedVirtualPartition.Drive = TC_INVALID_BIOS_DRIVE;
EraseMemory ((void *) TC_BOOT_LOADER_ARGS_OFFSET, sizeof (BootArguments));
- byte scanCode;
+ uint8 scanCode;
GetKeyboardChar (&scanCode);
return scanCode;
}
static void BootMenu ()
{
BiosResult result;
Partition partitions[16];
Partition bootablePartitions[9];
size_t partitionCount;
size_t bootablePartitionCount = 0;
- for (byte drive = TC_FIRST_BIOS_DRIVE; drive <= TC_LAST_BIOS_DRIVE; ++drive)
+ for (uint8 drive = TC_FIRST_BIOS_DRIVE; drive <= TC_LAST_BIOS_DRIVE; ++drive)
{
if (GetDrivePartitions (drive, partitions, array_capacity (partitions), partitionCount, false, nullptr, true) == BiosResultSuccess)
{
for (size_t i = 0; i < partitionCount; ++i)
{
const Partition &partition = partitions[i];
result = ReadSectors (SectorBuffer, drive, partition.StartSector, 1);
if (result == BiosResultSuccess && *(uint16 *) (SectorBuffer + TC_LB_SIZE - 2) == 0xaa55)
{
// Windows writes boot loader on all NTFS/FAT filesytems it creates and, therefore,
// NTFS/FAT partitions must have the boot indicator set to be considered bootable.
if (!partition.Active
&& (*(uint32 *) (SectorBuffer + 3) == 0x5346544e // 'NTFS'
|| *(uint32 *) (SectorBuffer + 3) == 0x41465845 && SectorBuffer[7] == 'T' // 'exFAT'
|| *(uint16 *) (SectorBuffer + 54) == 0x4146 && SectorBuffer[56] == 'T' // 'FAT'
|| *(uint16 *) (SectorBuffer + 82) == 0x4146 && SectorBuffer[84] == 'T'))
{
continue;
}
// Bootable sector found
if (bootablePartitionCount < array_capacity (bootablePartitions))
bootablePartitions[bootablePartitionCount++] = partition;
}
}
}
}
if (bootablePartitionCount < 1)
@@ -662,61 +662,61 @@ static void BootMenu ()
}
else
{
Print ("[Esc] Cancel\r\n\r\n");
Print ("Press 1-9 to select partition: ");
if (GetString (&partChar, 1) == 0)
return;
PrintEndl();
if (partChar < '1' || partChar > '0' + bootablePartitionCount)
{
Beep();
continue;
}
}
const Partition &partition = bootablePartitions[partChar - '0' - 1];
if (ReadSectors (SectorBuffer, partition.Drive, partition.StartSector, 1) == BiosResultSuccess)
{
ExecuteBootSector (partition.Drive, SectorBuffer);
}
}
}
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
-static bool CopySystemPartitionToHiddenVolume (byte drive, byte &exitKey)
+static bool CopySystemPartitionToHiddenVolume (uint8 drive, uint8 &exitKey)
{
bool status = false;
uint64 sectorsRemaining;
uint64 sectorOffset;
sectorOffset.LowPart = 0;
sectorOffset.HighPart = 0;
int fragmentSectorCount = 0x7f; // Maximum safe value supported by BIOS
int statCount = 0;
if (!CheckMemoryRequirements ())
goto err;
if (!GetSystemPartitions (drive))
goto err;
if (PartitionFollowingActive.Drive == TC_INVALID_BIOS_DRIVE)
TC_THROW_FATAL_EXCEPTION;
// Check if BIOS can read the last sector of the hidden system
AcquireSectorBuffer();
if (ReadSectors (SectorBuffer, PartitionFollowingActive.Drive, PartitionFollowingActive.EndSector - (TC_VOLUME_HEADER_GROUP_SIZE / TC_LB_SIZE - 2), 1) != BiosResultSuccess
|| GetCrc32 (SectorBuffer, sizeof (SectorBuffer)) != OuterVolumeBackupHeaderCrc)
{
PrintErrorNoEndl ("Your BIOS does not support large drives");
Print (IsLbaSupported (PartitionFollowingActive.Drive) ? " due to a bug" : "\r\n- Enable LBA in BIOS");
PrintEndl();
Print (TC_BOOT_STR_UPGRADE_BIOS);
@@ -785,63 +785,63 @@ static bool CopySystemPartitionToHiddenVolume (byte drive, byte &exitKey)
Print ("\rRemaining: ");
PrintSectorCountInMB (sectorsRemaining);
}
}
crypto_close (BootCryptoInfo);
if (sectorsRemaining.HighPart == 0 && sectorsRemaining.LowPart == 0)
{
status = true;
Print ("\rCopying completed.");
}
PrintEndl (2);
goto ret;
err:
exitKey = TC_BIOS_KEY_ESC;
GetKeyboardChar();
ret:
PimValueOrHiddenVolumeStartUnitNo.LowPart = -1;
EraseMemory ((void *) TC_BOOT_LOADER_ARGS_OFFSET, sizeof (BootArguments));
return status;
}
#else // TC_WINDOWS_BOOT_RESCUE_DISK_MODE
-static void DecryptDrive (byte drive)
+static void DecryptDrive (uint8 drive)
{
- byte exitKey;
+ uint8 exitKey;
if (!MountVolume (drive, exitKey, false, true))
return;
BootArguments *bootArguments = (BootArguments *) TC_BOOT_LOADER_ARGS_OFFSET;
bool headerUpdateRequired = false;
uint64 sectorsRemaining = EncryptedVirtualPartition.EndSector + 1 - EncryptedVirtualPartition.StartSector;
uint64 sector = EncryptedVirtualPartition.EndSector + 1;
int fragmentSectorCount = 0x7f; // Maximum safe value supported by BIOS
int statCount = 0;
bool skipBadSectors = false;
Print ("\r\nUse only if Windows cannot start. Decryption under Windows is much faster\r\n"
"(in VeraCrypt, select 'System' > 'Permanently Decrypt').\r\n\r\n");
if (!AskYesNo ("Decrypt now"))
{
crypto_close (BootCryptoInfo);
goto ret;
}
if (EncryptedVirtualPartition.Drive == TC_INVALID_BIOS_DRIVE)
{
// Drive already decrypted
sectorsRemaining.HighPart = 0;
sectorsRemaining.LowPart = 0;
}
else
@@ -898,69 +898,69 @@ askBadSectorSkip:
skipBadSectors = true;
sector = sector + fragmentSectorCount;
fragmentSectorCount = 1;
}
crypto_close (BootCryptoInfo);
if (headerUpdateRequired)
{
Print ("\rUpdating header...");
AcquireSectorBuffer();
uint64 headerSector;
headerSector.HighPart = 0;
headerSector.LowPart = TC_BOOT_VOLUME_HEADER_SECTOR;
// Update encrypted area size in volume header
CRYPTO_INFO *headerCryptoInfo = crypto_open();
while (ReadSectors (SectorBuffer, drive, headerSector, 1) != BiosResultSuccess);
if (ReadVolumeHeader (TRUE, (char *) SectorBuffer, &bootArguments->BootPassword, (int) (bootArguments->Flags >> 16), NULL, headerCryptoInfo) == 0)
{
DecryptBuffer (SectorBuffer + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
uint64 encryptedAreaLength = sectorsRemaining << TC_LB_SIZE_BIT_SHIFT_DIVISOR;
for (int i = 7; i >= 0; --i)
{
- SectorBuffer[TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH + i] = (byte) encryptedAreaLength.LowPart;
+ SectorBuffer[TC_HEADER_OFFSET_ENCRYPTED_AREA_LENGTH + i] = (uint8) encryptedAreaLength.LowPart;
encryptedAreaLength = encryptedAreaLength >> 8;
}
uint32 headerCrc32 = GetCrc32 (SectorBuffer + TC_HEADER_OFFSET_MAGIC, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC);
for (i = 3; i >= 0; --i)
{
- SectorBuffer[TC_HEADER_OFFSET_HEADER_CRC + i] = (byte) headerCrc32;
+ SectorBuffer[TC_HEADER_OFFSET_HEADER_CRC + i] = (uint8) headerCrc32;
headerCrc32 >>= 8;
}
EncryptBuffer (SectorBuffer + HEADER_ENCRYPTED_DATA_OFFSET, HEADER_ENCRYPTED_DATA_SIZE, headerCryptoInfo);
}
crypto_close (headerCryptoInfo);
while (WriteSectors (SectorBuffer, drive, headerSector, 1) != BiosResultSuccess);
ReleaseSectorBuffer();
Print ("Done!\r\n");
}
if (sectorsRemaining.HighPart == 0 && sectorsRemaining.LowPart == 0)
Print ("\rDrive decrypted.\r\n");
else
Print ("\r\nDecryption deferred.\r\n");
GetKeyboardChar();
ret:
EraseMemory (bootArguments, sizeof (*bootArguments));
}
static void RepairMenu ()
{
DriveGeometry bootLoaderDriveGeometry;
if (GetDriveGeometry (BootLoaderDrive, bootLoaderDriveGeometry, true) != BiosResultSuccess)
@@ -993,114 +993,114 @@ static void RepairMenu ()
(BootSectorFlags & TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER) ? array_capacity (options) : array_capacity (options) - 1);
PrintEndl();
switch (selection)
{
case RestoreNone:
return;
case DecryptVolume:
DecryptDrive (BootDrive);
continue;
case RestoreOriginalSystemLoader:
if (!AskYesNo ("Is the system partition/drive decrypted"))
{
Print ("Please decrypt it first.\r\n");
GetKeyboardChar();
continue;
}
break;
}
bool writeConfirmed = false;
BiosResult result;
uint64 sector;
sector.HighPart = 0;
ChsAddress chs;
- byte mbrPartTable[TC_LB_SIZE - TC_MAX_MBR_BOOT_CODE_SIZE];
+ uint8 mbrPartTable[TC_LB_SIZE - TC_MAX_MBR_BOOT_CODE_SIZE];
AcquireSectorBuffer();
for (int i = (selection == RestoreVolumeHeader ? TC_BOOT_VOLUME_HEADER_SECTOR : TC_MBR_SECTOR);
i < TC_BOOT_LOADER_AREA_SECTOR_COUNT; ++i)
{
sector.LowPart = i;
if (selection == RestoreOriginalSystemLoader)
sector.LowPart += TC_ORIG_BOOT_LOADER_BACKUP_SECTOR;
else if (selection == RestoreTrueCryptLoader)
sector.LowPart += TC_BOOT_LOADER_BACKUP_RESCUE_DISK_SECTOR;
// The backup medium may be a floppy-emulated bootable CD. The emulation may fail if LBA addressing is used.
// Therefore, only CHS addressing can be used.
LbaToChs (bootLoaderDriveGeometry, sector, chs);
sector.LowPart = i;
if (i == TC_MBR_SECTOR)
{
// Read current partition table
result = ReadSectors (SectorBuffer, TC_FIRST_BIOS_DRIVE, sector, 1);
if (result != BiosResultSuccess)
goto err;
memcpy (mbrPartTable, SectorBuffer + TC_MAX_MBR_BOOT_CODE_SIZE, sizeof (mbrPartTable));
}
result = ReadSectors (SectorBuffer, BootLoaderDrive, chs, 1);
if (result != BiosResultSuccess)
goto err;
if (i == TC_MBR_SECTOR)
{
// Preserve current partition table
memcpy (SectorBuffer + TC_MAX_MBR_BOOT_CODE_SIZE, mbrPartTable, sizeof (mbrPartTable));
}
// Volume header
if (i == TC_BOOT_VOLUME_HEADER_SECTOR)
{
if (selection == RestoreTrueCryptLoader)
continue;
if (selection == RestoreVolumeHeader)
{
while (true)
{
bool validHeaderPresent = false;
uint32 masterKeyScheduleCrc;
Password password;
int pim;
- byte exitKey = AskPassword (password, pim);
+ uint8 exitKey = AskPassword (password, pim);
if (exitKey != TC_BIOS_KEY_ENTER)
goto abort;
CRYPTO_INFO *cryptoInfo;
CopyMemory (SectorBuffer, TC_BOOT_LOADER_BUFFER_SEGMENT, 0, TC_LB_SIZE);
ReleaseSectorBuffer();
// Restore volume header only if the current one cannot be used
if (OpenVolume (TC_FIRST_BIOS_DRIVE, password, pim, &cryptoInfo, nullptr, false, true))
{
validHeaderPresent = true;
masterKeyScheduleCrc = GetCrc32 (cryptoInfo->ks, sizeof (cryptoInfo->ks));
crypto_close (cryptoInfo);
}
AcquireSectorBuffer();
CopyMemory (TC_BOOT_LOADER_BUFFER_SEGMENT, 0, SectorBuffer, TC_LB_SIZE);
if (ReadVolumeHeader (TRUE, (char *) SectorBuffer, &password, pim, &cryptoInfo, nullptr) == 0)
{
if (validHeaderPresent)
{
if (masterKeyScheduleCrc == GetCrc32 (cryptoInfo->ks, sizeof (cryptoInfo->ks)))
{
Print ("Original header preserved.\r\n");
goto err;
}
@@ -1194,67 +1194,67 @@ void main ()
else
BootDriveGeometryValid = true;
}
else
BootDriveGeometryValid = true;
#ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
// Check whether the user is not using the Rescue Disk to create a hidden system
if (ReadWriteMBR (false, BootDrive, true) == BiosResultSuccess
&& *(uint32 *) (SectorBuffer + 6) == 0x61726556
&& *(uint32 *) (SectorBuffer + 10) == 0x70797243
&& (SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] & TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE) != TC_HIDDEN_OS_CREATION_PHASE_NONE)
{
PrintError ("It appears you are creating a hidden OS.");
if (AskYesNo ("Is this correct"))
{
Print ("Please remove the Rescue Disk from the drive and restart.");
while (true);
}
}
#endif // TC_WINDOWS_BOOT_RESCUE_DISK_MODE
// Main menu
while (true)
{
- byte exitKey;
+ uint8 exitKey;
InitScreen();
#ifndef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
// Hidden system setup
- byte hiddenSystemCreationPhase = BootSectorFlags & TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE;
+ uint8 hiddenSystemCreationPhase = BootSectorFlags & TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE;
if (hiddenSystemCreationPhase != TC_HIDDEN_OS_CREATION_PHASE_NONE)
{
PreventNormalSystemBoot = true;
PrintMainMenu();
if (hiddenSystemCreationPhase == TC_HIDDEN_OS_CREATION_PHASE_CLONING)
{
if (CopySystemPartitionToHiddenVolume (BootDrive, exitKey))
{
BootSectorFlags = (BootSectorFlags & ~TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE) | TC_HIDDEN_OS_CREATION_PHASE_WIPING;
UpdateBootSectorConfiguration (BootLoaderDrive);
}
else if (exitKey == TC_BIOS_KEY_ESC)
goto bootMenu;
else
continue;
}
}
else
PrintMainMenu();
exitKey = BootEncryptedDrive();
#else // TC_WINDOWS_BOOT_RESCUE_DISK_MODE
PrintMainMenu();
exitKey = BootEncryptedDrive();
if (exitKey == TC_MENU_KEY_REPAIR)
diff --git a/src/Boot/Windows/BootMain.h b/src/Boot/Windows/BootMain.h
index 52d5c8cc..af445024 100644
--- a/src/Boot/Windows/BootMain.h
+++ b/src/Boot/Windows/BootMain.h
@@ -1,34 +1,34 @@
/*
Derived from source code of TrueCrypt 7.1a, which is
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Boot_BootMain
#define TC_HEADER_Boot_BootMain
#include "TCdefs.h"
#include "Platform.h"
-static byte AskPassword (Password &password, int& pim);
+static uint8 AskPassword (Password &password, int& pim);
static int AskSelection (const char *options[], size_t optionCount);
static bool AskYesNo (const char *message);
-static byte BootEncryptedDrive ();
+static uint8 BootEncryptedDrive ();
static void BootMenu ();
-static void ExecuteBootSector (byte drive, byte *sectorBuffer);
+static void ExecuteBootSector (uint8 drive, uint8 *sectorBuffer);
static void InitScreen ();
-static bool IsMenuKey (byte scanCode);
-static bool MountVolume (byte drive, byte &exitKey);
-static bool OpenVolume (byte drive, Password &password, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32 = nullptr, bool skipNormal = false, bool skipHidden = false);
+static bool IsMenuKey (uint8 scanCode);
+static bool MountVolume (uint8 drive, uint8 &exitKey);
+static bool OpenVolume (uint8 drive, Password &password, CRYPTO_INFO **cryptoInfo, uint32 *headerSaltCrc32 = nullptr, bool skipNormal = false, bool skipHidden = false);
static void PrintMainMenu ();
static void RepairMenu ();
#define TC_MENU_KEY_REPAIR TC_BIOS_KEY_F8
#endif // TC_HEADER_Boot_BootMain
diff --git a/src/Boot/Windows/IntFilter.cpp b/src/Boot/Windows/IntFilter.cpp
index 9e5c8536..36837d58 100644
--- a/src/Boot/Windows/IntFilter.cpp
+++ b/src/Boot/Windows/IntFilter.cpp
@@ -11,151 +11,151 @@
*/
#include "Platform.h"
#include "BootMemory.h"
#include "BootConfig.h"
#include "BootConsoleIo.h"
#include "BootDebug.h"
#include "BootDefs.h"
#include "BootDiskIo.h"
#include "BootEncryptedIo.h"
#include "BootStrings.h"
#include "IntFilter.h"
static uint32 OriginalInt13Handler;
static uint32 OriginalInt15Handler;
static Registers IntRegisters;
bool Int13Filter ()
{
CheckStack();
Registers regs;
memcpy (&regs, &IntRegisters, sizeof (regs));
__asm sti
static int ReEntryCount = -1;
++ReEntryCount;
- byte function = (byte) (regs.AX >> 8);
+ uint8 function = (uint8) (regs.AX >> 8);
#ifdef TC_TRACE_INT13
DisableScreenOutput();
PrintHex (function);
Print (" EN:"); Print (ReEntryCount);
Print (" SS:"); PrintHex (regs.SS);
uint16 spdbg;
__asm mov spdbg, sp
PrintChar (' ');
PrintHex (spdbg);
PrintChar ('<'); PrintHex (TC_BOOT_LOADER_STACK_TOP);
#endif
bool passOriginalRequest = true;
switch (function)
{
case 0x2: // Read sectors
case 0x3: // Write sectors
{
- byte drive = (byte) regs.DX;
+ uint8 drive = (uint8) regs.DX;
ChsAddress chs;
chs.Cylinder = ((regs.CX << 2) & 0x300) | (regs.CX >> 8);
chs.Head = regs.DX >> 8;
chs.Sector = regs.CX & 0x3f;
- byte sectorCount = (byte) regs.AX;
+ uint8 sectorCount = (uint8) regs.AX;
#ifdef TC_TRACE_INT13
PrintVal (": Drive", drive - TC_FIRST_BIOS_DRIVE, false);
Print (" Chs: "); Print (chs);
#endif
uint64 sector;
if (drive == BootDrive)
{
if (!BootDriveGeometryValid)
TC_THROW_FATAL_EXCEPTION;
ChsToLba (BootDriveGeometry, chs, sector);
#ifdef TC_TRACE_INT13
PrintVal (" Sec", sector.LowPart, false);
#endif
}
#ifdef TC_TRACE_INT13
PrintVal (" Count", sectorCount, false);
Print (" Buf: "); PrintHex (regs.ES); PrintChar (':'); PrintHex (regs.BX);
PrintEndl();
#endif
if (ReEntryCount == 0 && drive == EncryptedVirtualPartition.Drive)
{
BiosResult result;
if (function == 0x3)
result = WriteEncryptedSectors (regs.ES, regs.BX, drive, sector, sectorCount);
else
result = ReadEncryptedSectors (regs.ES, regs.BX, drive, sector, sectorCount);
__asm cli
memcpy (&IntRegisters, &regs, sizeof (regs));
IntRegisters.AX = (uint16) result << 8;
if (result == BiosResultSuccess)
{
IntRegisters.AX |= sectorCount;
IntRegisters.Flags &= ~TC_X86_CARRY_FLAG;
}
else
IntRegisters.Flags |= TC_X86_CARRY_FLAG;
passOriginalRequest = false;
}
}
break;
case 0x42: // Read sectors LBA
case 0x43: // Write sectors LBA
{
- byte drive = (byte) regs.DX;
+ uint8 drive = (uint8) regs.DX;
BiosLbaPacket lba;
- CopyMemory (regs.DS, regs.SI, (byte *) &lba, sizeof (lba));
+ CopyMemory (regs.DS, regs.SI, (uint8 *) &lba, sizeof (lba));
#ifdef TC_TRACE_INT13
PrintVal (": Drive", drive - TC_FIRST_BIOS_DRIVE, false);
PrintVal (" Sec", lba.Sector.LowPart, false);
PrintVal (" Count", lba.SectorCount, false);
PrintVal (" Buf", lba.Buffer, false, true);
PrintEndl();
#endif
if (ReEntryCount == 0 && drive == EncryptedVirtualPartition.Drive)
{
BiosResult result;
uint16 segment = (uint16) (lba.Buffer >> 16);
uint16 offset = (uint16) lba.Buffer;
if (function == 0x43)
result = WriteEncryptedSectors (segment, offset, drive, lba.Sector, lba.SectorCount);
else
result = ReadEncryptedSectors (segment, offset, drive, lba.Sector, lba.SectorCount);
__asm cli
memcpy (&IntRegisters, &regs, sizeof (regs));
IntRegisters.AX = (IntRegisters.AX & 0xff) | ((uint16) result << 8);
if (result == BiosResultSuccess)
IntRegisters.Flags &= ~TC_X86_CARRY_FLAG;
else
IntRegisters.Flags |= TC_X86_CARRY_FLAG;
@@ -310,104 +310,104 @@ bool Int15Filter ()
DisableScreenOutput();
Print ("15-");
PrintHex (IntRegisters.AX);
Print (" SS:"); PrintHex (IntRegisters.SS);
uint16 spdbg;
__asm mov spdbg, sp
PrintChar (' ');
PrintHex (spdbg);
PrintChar ('<'); PrintHex (TC_BOOT_LOADER_STACK_TOP);
Print (" EAX:"); PrintHex (IntRegisters.EAX);
Print (" EBX:"); PrintHex (IntRegisters.EBX);
Print (" ECX:"); PrintHex (IntRegisters.ECX);
Print (" EDX:"); PrintHex (IntRegisters.EDX);
Print (" DI:"); PrintHex (IntRegisters.DI);
PrintEndl();
#endif
if (IntRegisters.EBX >= BiosMemoryMapSize)
{
IntRegisters.Flags |= TC_X86_CARRY_FLAG;
IntRegisters.EBX = 0;
IntRegisters.AX = -1;
}
else
{
- CopyMemory ((byte *) &BiosMemoryMap[IntRegisters.EBX], IntRegisters.ES, IntRegisters.DI, sizeof (BiosMemoryMap[0]));
+ CopyMemory ((uint8 *) &BiosMemoryMap[IntRegisters.EBX], IntRegisters.ES, IntRegisters.DI, sizeof (BiosMemoryMap[0]));
IntRegisters.Flags &= ~TC_X86_CARRY_FLAG;
IntRegisters.EAX = 0x534D4150UL;
++IntRegisters.EBX;
if (IntRegisters.EBX >= BiosMemoryMapSize)
IntRegisters.EBX = 0;
IntRegisters.ECX = sizeof (BiosMemoryMap[0]);
}
if (IntRegisters.EBX == 0 && !(BootSectorFlags & TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER))
{
// Uninstall filter when the modified map has been issued three times to prevent
// problems with hardware drivers on some notebooks running Windows XP.
static int CompleteMapIssueCount = 0;
if (++CompleteMapIssueCount >= 3)
{
__asm
{
cli
push es
lea si, OriginalInt15Handler
xor ax, ax
mov es, ax
mov di, 0x15 * 4
mov ax, [si]
mov es:[di], ax
mov ax, [si + 2]
mov es:[di + 2], ax
pop es
sti
}
}
}
#ifdef TC_TRACE_INT15
BiosMemoryMapEntry entry;
- CopyMemory (IntRegisters.ES, IntRegisters.DI, (byte *) &entry, sizeof (entry));
+ CopyMemory (IntRegisters.ES, IntRegisters.DI, (uint8 *) &entry, sizeof (entry));
PrintHex (entry.Type); PrintChar (' ');
PrintHex (entry.BaseAddress); PrintChar (' ');
PrintHex (entry.Length); PrintChar (' ');
PrintHex (entry.BaseAddress + entry.Length); PrintEndl();
Print ("EAX:"); PrintHex (IntRegisters.EAX);
Print (" EBX:"); PrintHex (IntRegisters.EBX);
Print (" ECX:"); PrintHex (IntRegisters.ECX);
Print (" EDX:"); PrintHex (IntRegisters.EDX);
Print (" DI:"); PrintHex (IntRegisters.DI);
Print (" FL:"); PrintHex (IntRegisters.Flags);
PrintEndl (2);
#endif
#ifdef TC_TRACE_INT15
EnableScreenOutput();
#endif
return false;
}
void IntFilterEntry ()
{
// No automatic variables should be used in this scope as SS may change
static uint16 OrigStackPointer;
static uint16 OrigStackSegment;
__asm
{
pushf
diff --git a/src/Boot/Windows/Platform.cpp b/src/Boot/Windows/Platform.cpp
index 046fa4a4..3b94d22c 100644
--- a/src/Boot/Windows/Platform.cpp
+++ b/src/Boot/Windows/Platform.cpp
@@ -57,61 +57,61 @@ uint64 operator- (const uint64 &a, const uint64 &b)
mov carry, 1
nocarry:
}
r.HighPart = a.HighPart - b.HighPart - carry;
return r;
}
uint64 operator- (const uint64 &a, uint32 b)
{
uint64 b64;
b64.HighPart = 0;
b64.LowPart = b;
return a - b64;
}
uint64 &operator-= (uint64 &a, const uint64 &b)
{
return a = a - b;
}
uint64 operator>> (const uint64 &a, int shiftCount)
{
uint64 r = a;
while (shiftCount--)
{
r.LowPart >>= 1;
- if ((byte) r.HighPart & 1)
+ if ((uint8) r.HighPart & 1)
r.LowPart |= 0x80000000UL;
r.HighPart >>= 1;
}
return r;
}
uint64 operator<< (const uint64 &a, int shiftCount)
{
uint64 r = a;
while (shiftCount--)
r += r;
return r;
}
uint64 &operator++ (uint64 &a)
{
uint64 b;
b.HighPart = 0;
b.LowPart = 1;
return a += b;
}
bool operator== (const uint64 &a, const uint64 &b)
{
return a.HighPart == b.HighPart && a.LowPart == b.LowPart;
diff --git a/src/Boot/Windows/Release/BootLoader.com.gz b/src/Boot/Windows/Release/BootLoader.com.gz
index d4cd2a66..9bf2133e 100644
--- a/src/Boot/Windows/Release/BootLoader.com.gz
+++ b/src/Boot/Windows/Release/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_AES/BootLoader.com.gz b/src/Boot/Windows/Release_AES/BootLoader.com.gz
index de7d9c35..222aa5a1 100644
--- a/src/Boot/Windows/Release_AES/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_AES/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_AES_SHA2/BootLoader.com.gz b/src/Boot/Windows/Release_AES_SHA2/BootLoader.com.gz
index 42c271aa..6aebbf06 100644
--- a/src/Boot/Windows/Release_AES_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_AES_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Camellia/BootLoader.com.gz b/src/Boot/Windows/Release_Camellia/BootLoader.com.gz
index 090efd03..f090cdfb 100644
--- a/src/Boot/Windows/Release_Camellia/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Camellia/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Camellia_SHA2/BootLoader.com.gz b/src/Boot/Windows/Release_Camellia_SHA2/BootLoader.com.gz
index 13ff1405..edc5e25f 100644
--- a/src/Boot/Windows/Release_Camellia_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Camellia_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_SHA2/BootLoader.com.gz b/src/Boot/Windows/Release_SHA2/BootLoader.com.gz
index d596c445..b9d83263 100644
--- a/src/Boot/Windows/Release_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Serpent/BootLoader.com.gz b/src/Boot/Windows/Release_Serpent/BootLoader.com.gz
index 9cb0b0cb..2a9cac0b 100644
--- a/src/Boot/Windows/Release_Serpent/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Serpent/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Serpent_SHA2/BootLoader.com.gz b/src/Boot/Windows/Release_Serpent_SHA2/BootLoader.com.gz
index 7353e440..19ab043c 100644
--- a/src/Boot/Windows/Release_Serpent_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Serpent_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Twofish/BootLoader.com.gz b/src/Boot/Windows/Release_Twofish/BootLoader.com.gz
index 69e3b264..885190f2 100644
--- a/src/Boot/Windows/Release_Twofish/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Twofish/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Release_Twofish_SHA2/BootLoader.com.gz b/src/Boot/Windows/Release_Twofish_SHA2/BootLoader.com.gz
index 6e008a19..0090b771 100644
--- a/src/Boot/Windows/Release_Twofish_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Release_Twofish_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue/BootLoader.com.gz b/src/Boot/Windows/Rescue/BootLoader.com.gz
index 3e6ee5c3..181b2d35 100644
--- a/src/Boot/Windows/Rescue/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_AES/BootLoader.com.gz b/src/Boot/Windows/Rescue_AES/BootLoader.com.gz
index 6a3cfdcb..5114925b 100644
--- a/src/Boot/Windows/Rescue_AES/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_AES/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_AES_SHA2/BootLoader.com.gz b/src/Boot/Windows/Rescue_AES_SHA2/BootLoader.com.gz
index 0cb31996..52382753 100644
--- a/src/Boot/Windows/Rescue_AES_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_AES_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Camellia/BootLoader.com.gz b/src/Boot/Windows/Rescue_Camellia/BootLoader.com.gz
index 7c934a57..60d7d41a 100644
--- a/src/Boot/Windows/Rescue_Camellia/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Camellia/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Camellia_SHA2/BootLoader.com.gz b/src/Boot/Windows/Rescue_Camellia_SHA2/BootLoader.com.gz
index ca2952aa..f2a0fc22 100644
--- a/src/Boot/Windows/Rescue_Camellia_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Camellia_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_SHA2/BootLoader.com.gz b/src/Boot/Windows/Rescue_SHA2/BootLoader.com.gz
index 3a9410ba..47e8283a 100644
--- a/src/Boot/Windows/Rescue_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Serpent/BootLoader.com.gz b/src/Boot/Windows/Rescue_Serpent/BootLoader.com.gz
index cd6fe5d5..c248eb6b 100644
--- a/src/Boot/Windows/Rescue_Serpent/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Serpent/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Serpent_SHA2/BootLoader.com.gz b/src/Boot/Windows/Rescue_Serpent_SHA2/BootLoader.com.gz
index 37d4d02b..e3e889e0 100644
--- a/src/Boot/Windows/Rescue_Serpent_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Serpent_SHA2/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Twofish/BootLoader.com.gz b/src/Boot/Windows/Rescue_Twofish/BootLoader.com.gz
index 6a2d1c5f..6525bcaa 100644
--- a/src/Boot/Windows/Rescue_Twofish/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Twofish/BootLoader.com.gz
Binary files differ
diff --git a/src/Boot/Windows/Rescue_Twofish_SHA2/BootLoader.com.gz b/src/Boot/Windows/Rescue_Twofish_SHA2/BootLoader.com.gz
index f262a558..9837e671 100644
--- a/src/Boot/Windows/Rescue_Twofish_SHA2/BootLoader.com.gz
+++ b/src/Boot/Windows/Rescue_Twofish_SHA2/BootLoader.com.gz
Binary files differ