Skip to content

Commit

Permalink
TrueCrypt Source Version 5.0a
Browse files Browse the repository at this point in the history
  • Loading branch information
Truecrypt Foundation authored and FreeApophis committed May 29, 2014
1 parent e1850f7 commit ea0cb8c
Show file tree
Hide file tree
Showing 47 changed files with 941 additions and 488 deletions.
8 changes: 8 additions & 0 deletions Boot/Windows/Boot.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
RelativePath=".\BootMain.cpp"
>
</File>
<File
RelativePath=".\BootMemory.cpp"
>
</File>
<File
RelativePath=".\BootSector.asm"
>
Expand Down Expand Up @@ -194,6 +198,10 @@
RelativePath=".\BootMain.h"
>
</File>
<File
RelativePath=".\BootMemory.h"
>
</File>
<File
RelativePath=".\IntFilter.h"
>
Expand Down
16 changes: 16 additions & 0 deletions Boot/Windows/BootConsoleIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ bool IsKeyboardCharAvailable ()
}


void ClearBiosKeystrokeBuffer ()
{
__asm
{
push es
xor ax, ax
mov es, ax
mov di, 0x41e
mov cx, 32
cld
rep stosb
pop es
}
}


bool IsPrintable (char c)
{
return c >= ' ' && c <= '~';
Expand Down
2 changes: 1 addition & 1 deletion Boot/Windows/BootConsoleIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define TC_BIOS_MAX_CHARS_PER_LINE 80

void Beep ();
void ClearBiosKeystrokeBuffer ();
void ClearScreen ();
void DisableScreenOutput ();
void EnableScreenOutput ();
Expand All @@ -59,6 +60,5 @@ void PrintHex (byte b);
void PrintHex (uint16 data);
void PrintHex (uint32 data);
void PrintHex (const uint64 &data);
void SendToDebugPort (byte dataByte);

#endif // TC_HEADER_Boot_BootConsoleIo
4 changes: 2 additions & 2 deletions Boot/Windows/BootDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
distribution packages.
*/

// Total memory required (CODE + DATA + BSS + STACK) in KBytes - determined from linker map.
#define TC__BOOT_MEMORY_REQUIRED 60
// Total memory required (CODE + DATA + BSS + STACK + 0x100) in KBytes - determined from linker map.
#define TC__BOOT_MEMORY_REQUIRED 42

// Windows Vista boot loader uses memory up to 8000:FFFF, disregarding the BIOS memory map and the amount
// of available memory at 0:0413. Therefore, the code has to be loaded at or above 9000:0000.
Expand Down
106 changes: 83 additions & 23 deletions Boot/Windows/BootMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "BootDebug.h"
#include "BootDiskIo.h"
#include "BootEncryptedIo.h"
#include "BootMemory.h"
#include "IntFilter.h"


Expand Down Expand Up @@ -119,8 +120,11 @@ static byte AskPassword (Password &password)
switch (scanCode)
{
case TC_BIOS_KEY_ENTER:
ClearBiosKeystrokeBuffer();
PrintEndl();
goto ret;

password.Length = pos;
return scanCode;

case TC_BIOS_KEY_BACKSPACE:
if (pos > 0)
Expand All @@ -138,6 +142,8 @@ static byte AskPassword (Password &password)
if (scanCode == TC_BIOS_KEY_ESC || IsMenuKey (scanCode))
{
burn (password.Text, sizeof (password.Text));
ClearBiosKeystrokeBuffer();

PrintEndl();
return scanCode;
}
Expand All @@ -155,10 +161,6 @@ static byte AskPassword (Password &password)
else
PrintCharAtCusor ('*');
}

ret:
password.Length = pos;
return TC_BIOS_KEY_ENTER;
}


Expand Down Expand Up @@ -191,6 +193,59 @@ static bool OpenVolume (byte drive, Password &password, CRYPTO_INFO **cryptoInfo
}


static bool CheckMemoryRequirements ()
{
uint16 codeSeg;
__asm mov codeSeg, cs
if (codeSeg == TC_BOOT_LOADER_LOWMEM_SEGMENT)
{
PrintError ("Insufficient base memory: ", true, false);

uint16 memFree;
__asm
{
push es
xor ax, ax
mov es, ax
mov ax, es:[0x413]
mov memFree, ax
pop es
}

Print (memFree); Print (" KB\r\n");

return false;
}

// Check for conflicts with BIOS memory map
uint64 bootLoaderStart;
bootLoaderStart.HighPart = 0;
bootLoaderStart.LowPart = GetLinearAddress (codeSeg, 0);

BiosMemoryMapEntry entry;
if (GetFirstBiosMemoryMapEntry (entry))
{
do
{
if (entry.Type != 0x1
&& RegionsIntersect (bootLoaderStart, TC_BOOT_MEMORY_REQUIRED * 1024UL, entry.BaseAddress, entry.BaseAddress + entry.Length - 1))
{
PrintError ("Your BIOS reserved a memory area required by TrueCrypt:");
Print ("Type:"); Print (entry.Type);
Print (" Start:"); PrintHex (entry.BaseAddress);
Print (" Length:"); PrintHex (entry.Length);
PrintEndl (2);

return false;
}
}
while (GetNextBiosMemoryMapEntry (entry));
}

return true;
}


static bool MountVolume (byte drive, byte &exitKey)
{
BootArguments *bootArguments = (BootArguments *) TC_BOOT_LOADER_ARGS_OFFSET;
Expand All @@ -208,17 +263,6 @@ static bool MountVolume (byte drive, byte &exitKey)

Print ("Incorrect password or not a TrueCrypt volume.\r\n\r\n");
}

// Check memory
uint16 codeSeg;
__asm mov codeSeg, cs
if (codeSeg == TC_BOOT_LOADER_LOWMEM_SEGMENT)
{
PrintError ("Insufficient memory for encryption");
EncryptedVirtualPartition.Drive = TC_FIRST_BIOS_DRIVE - 1;
GetKeyboardChar ();
return false;
}

// Setup boot arguments
bootArguments->CryptoInfoOffset = (uint16) BootCryptoInfo;
Expand Down Expand Up @@ -266,7 +310,15 @@ static byte BootEncryptedDrive ()
if (!MountVolume (BootDrive, exitKey))
return exitKey;

InstallInterruptFilters();
if (!CheckMemoryRequirements ())
{
Print ("Try disabling unneeded components (RAID, AHCI, integrated audio card, etc.) in\r\n"
"BIOS setup menu (invoked by pressing Del or F2 after turning on your computer).\r\n");
goto err;
}

if (!InstallInterruptFilters())
goto err;

// Execute boot sector of the active partition
byte bootSector[TC_LB_SIZE];
Expand All @@ -276,6 +328,9 @@ static byte BootEncryptedDrive ()
}

err:
EncryptedVirtualPartition.Drive = TC_FIRST_BIOS_DRIVE - 1;
memset ((void *) TC_BOOT_LOADER_ARGS_OFFSET, 0, sizeof (BootArguments));

byte scanCode;
GetKeyboardChar (&scanCode);
return scanCode;
Expand Down Expand Up @@ -534,13 +589,18 @@ static void RepairMenu ()
int selection = AskSelection (options, optionCount);
PrintEndl();

if (selection == RestoreNone)
return;

if (selection == DecryptVolume)
switch (selection)
{
DecryptDrive (BootDrive);
continue;
case RestoreNone:
return;

case DecryptVolume:
DecryptDrive (BootDrive);
continue;

case RestoreOriginalSystemLoader:
if (!AskYesNo ("Is the drive decrypted"))
continue;
}

bool writeConfirmed = false;
Expand Down
73 changes: 73 additions & 0 deletions Boot/Windows/BootMemory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
Governed by the TrueCrypt License 2.4 the full text of which is contained
in the file License.txt included in TrueCrypt binary and source code
distribution packages.
*/

#include "BootMemory.h"

static uint32 MemoryMapContValue;

static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
{
static const uint32 function = 0x0000E820UL;
static const uint32 magic = 0x534D4150UL;
static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);

bool carry = false;
uint32 resultMagic;
uint32 resultSize;

__asm
{
lea di, function
TC_ASM_MOV_EAX_DI
lea di, MemoryMapContValue
TC_ASM_MOV_EBX_DI
lea di, bufferSize
TC_ASM_MOV_ECX_DI
lea di, magic
TC_ASM_MOV_EDX_DI
lea di, MemoryMapContValue
TC_ASM_MOV_DI_ECX

lea di, entry
mov di, [entry]

int 0x15
jnc no_carry
mov carry, true
no_carry:

lea di, resultMagic
TC_ASM_MOV_DI_EAX
lea di, MemoryMapContValue
TC_ASM_MOV_DI_EBX
lea di, resultSize
TC_ASM_MOV_DI_ECX
}

// BIOS may set CF at the end of the list
if (carry)
MemoryMapContValue = 0;

return resultMagic == magic && resultSize == bufferSize;
}


bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
{
MemoryMapContValue = 0;
return GetMemoryMapEntry (entry);
}


bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
{
if (MemoryMapContValue == 0)
return false;

return GetMemoryMapEntry (entry);
}
24 changes: 24 additions & 0 deletions Boot/Windows/BootMemory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
Governed by the TrueCrypt License 2.4 the full text of which is contained
in the file License.txt included in TrueCrypt binary and source code
distribution packages.
*/

#include "Platform.h"
#include "Bios.h"

#pragma pack(1)

struct BiosMemoryMapEntry
{
uint64 BaseAddress;
uint64 Length;
uint32 Type;
};

#pragma pack()

bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
Loading

0 comments on commit ea0cb8c

Please sign in to comment.