1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-12 11:28:26 -06:00

Normalize all line terminators

This commit is contained in:
David Foerster
2016-05-10 20:20:14 +02:00
parent 98b04198c6
commit fc37cc4a02
297 changed files with 202290 additions and 202290 deletions

View File

@@ -1,32 +1,32 @@
/*
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-2016 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
};
typedef byte BiosResult;
#endif // TC_HEADER_Boot_Bios
/*
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-2016 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
};
typedef byte BiosResult;
#endif // TC_HEADER_Boot_Bios

View File

@@ -1,246 +1,246 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Boot"
ProjectGUID="{8B7F059F-E4C7-4E11-88F5-EE8B8433072E}"
RootNamespace="Boot"
Keyword="MakeFileProj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;md Release_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
ReBuildCommandLine="del /q /s Release &gt;NUL:&#x0D;&#x0A;md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES &gt;NUL:&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent &gt;NUL:&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish &gt;NUL:&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue &gt;NUL:&#x0D;&#x0A;md Rescue 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_AES &gt;NUL:&#x0D;&#x0A;md Rescue_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_AES_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Serpent &gt;NUL:&#x0D;&#x0A;md Rescue_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Serpent_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Twofish &gt;NUL:&#x0D;&#x0A;md Rescue_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish Rescue Rescue_AES Rescue_Serpent Rescue_Twofish &gt;NUL:&#x0D;&#x0A;del /q /s Release_SHA2 Release_AES_SHA2 Release_Serpent_SHA2 Release_Twofish_SHA2 Rescue_SHA2 Rescue_AES_SHA2 Rescue_Serpent_SHA2 Rescue_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;"
Output="Release\BootLoader.com"
PreprocessorDefinitions="WIN32;NDEBUG"
IncludeSearchPath="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(MSVC16_ROOT)\Include&quot;"
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
<Configuration
Name="Release Loader|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
ReBuildCommandLine="del /q /s Release &gt;NUL:&#x0D;&#x0A;md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES &gt;NUL:&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent &gt;NUL:&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish &gt;NUL:&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish &gt;NUL:"
Output="Release\BootLoader.com"
PreprocessorDefinitions="WIN32;NDEBUG"
IncludeSearchPath="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(MSVC16_ROOT)\Include&quot;"
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\BootConfig.cpp"
>
</File>
<File
RelativePath=".\BootConsoleIo.cpp"
>
</File>
<File
RelativePath=".\BootCrt.asm"
>
</File>
<File
RelativePath=".\BootDebug.cpp"
>
</File>
<File
RelativePath=".\BootDiskIo.cpp"
>
</File>
<File
RelativePath=".\BootEncryptedIo.cpp"
>
</File>
<File
RelativePath=".\BootMain.cpp"
>
</File>
<File
RelativePath=".\BootMemory.cpp"
>
</File>
<File
RelativePath=".\BootSector.asm"
>
</File>
<File
RelativePath=".\Decompressor.c"
>
</File>
<File
RelativePath=".\IntFilter.cpp"
>
</File>
<File
RelativePath=".\Platform.cpp"
>
</File>
<Filter
Name="Common"
>
<File
RelativePath="..\..\Common\Crc.c"
>
</File>
<File
RelativePath="..\..\Common\Crypto.c"
>
</File>
<File
RelativePath="..\..\Common\Endian.c"
>
</File>
<File
RelativePath="..\..\Common\Pkcs5.c"
>
</File>
<File
RelativePath="..\..\Common\Volumes.c"
>
</File>
<File
RelativePath="..\..\Common\Xts.c"
>
</File>
</Filter>
<Filter
Name="Crypto"
>
<File
RelativePath="..\..\Crypto\Aes_hw_cpu.asm"
>
</File>
<File
RelativePath="..\..\Crypto\AesSmall.c"
>
</File>
<File
RelativePath="..\..\Crypto\AesSmall_x86.asm"
>
</File>
<File
RelativePath="..\..\Crypto\Rmd160.c"
>
</File>
<File
RelativePath="..\..\Crypto\Serpent.c"
>
</File>
<File
RelativePath="..\..\Crypto\Sha2Small.c"
>
</File>
<File
RelativePath="..\..\Crypto\Twofish.c"
>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\Bios.h"
>
</File>
<File
RelativePath=".\BootCommon.h"
>
</File>
<File
RelativePath=".\BootConfig.h"
>
</File>
<File
RelativePath=".\BootConsoleIo.h"
>
</File>
<File
RelativePath=".\BootDebug.h"
>
</File>
<File
RelativePath=".\BootDefs.h"
>
</File>
<File
RelativePath=".\BootDiskIo.h"
>
</File>
<File
RelativePath=".\BootEncryptedIo.h"
>
</File>
<File
RelativePath=".\BootMain.h"
>
</File>
<File
RelativePath=".\BootMemory.h"
>
</File>
<File
RelativePath=".\BootStrings.h"
>
</File>
<File
RelativePath=".\IntFilter.h"
>
</File>
<File
RelativePath=".\Platform.h"
>
</File>
</Filter>
<Filter
Name="Build Files"
>
<File
RelativePath=".\Makefile"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Boot"
ProjectGUID="{8B7F059F-E4C7-4E11-88F5-EE8B8433072E}"
RootNamespace="Boot"
Keyword="MakeFileProj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;md Release_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;md Rescue_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
ReBuildCommandLine="del /q /s Release &gt;NUL:&#x0D;&#x0A;md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES &gt;NUL:&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent &gt;NUL:&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish &gt;NUL:&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;md Release_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue &gt;NUL:&#x0D;&#x0A;md Rescue 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_AES &gt;NUL:&#x0D;&#x0A;md Rescue_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_AES_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_AES_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Serpent &gt;NUL:&#x0D;&#x0A;md Rescue_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Serpent_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_Serpent_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT RESCUE_DISK=1 SINGLE_PRF=SHA2&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Twofish &gt;NUL:&#x0D;&#x0A;md Rescue_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Rescue_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;md Rescue_Twofish_SHA2 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH RESCUE_DISK=1 SINGLE_PRF=SHA2"
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish Rescue Rescue_AES Rescue_Serpent Rescue_Twofish &gt;NUL:&#x0D;&#x0A;del /q /s Release_SHA2 Release_AES_SHA2 Release_Serpent_SHA2 Release_Twofish_SHA2 Rescue_SHA2 Rescue_AES_SHA2 Rescue_Serpent_SHA2 Rescue_Twofish_SHA2 &gt;NUL:&#x0D;&#x0A;"
Output="Release\BootLoader.com"
PreprocessorDefinitions="WIN32;NDEBUG"
IncludeSearchPath="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(MSVC16_ROOT)\Include&quot;"
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
<Configuration
Name="Release Loader|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
ReBuildCommandLine="del /q /s Release &gt;NUL:&#x0D;&#x0A;md Release 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_AES &gt;NUL:&#x0D;&#x0A;md Release_AES 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=AES&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Serpent &gt;NUL:&#x0D;&#x0A;md Release_Serpent 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=SERPENT&#x0D;&#x0A;&#x0D;&#x0A;del /q /s Release_Twofish &gt;NUL:&#x0D;&#x0A;md Release_Twofish 2&gt;NUL:&#x0D;&#x0A;nmake.exe /nologo RELEASE=1 SINGLE_CIPHER=TWOFISH"
CleanCommandLine="del /q /s Release Release_AES Release_Serpent Release_Twofish &gt;NUL:"
Output="Release\BootLoader.com"
PreprocessorDefinitions="WIN32;NDEBUG"
IncludeSearchPath="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)\Common&quot;;&quot;$(SolutionDir)\Crypto&quot;;&quot;$(MSVC16_ROOT)\Include&quot;"
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\BootConfig.cpp"
>
</File>
<File
RelativePath=".\BootConsoleIo.cpp"
>
</File>
<File
RelativePath=".\BootCrt.asm"
>
</File>
<File
RelativePath=".\BootDebug.cpp"
>
</File>
<File
RelativePath=".\BootDiskIo.cpp"
>
</File>
<File
RelativePath=".\BootEncryptedIo.cpp"
>
</File>
<File
RelativePath=".\BootMain.cpp"
>
</File>
<File
RelativePath=".\BootMemory.cpp"
>
</File>
<File
RelativePath=".\BootSector.asm"
>
</File>
<File
RelativePath=".\Decompressor.c"
>
</File>
<File
RelativePath=".\IntFilter.cpp"
>
</File>
<File
RelativePath=".\Platform.cpp"
>
</File>
<Filter
Name="Common"
>
<File
RelativePath="..\..\Common\Crc.c"
>
</File>
<File
RelativePath="..\..\Common\Crypto.c"
>
</File>
<File
RelativePath="..\..\Common\Endian.c"
>
</File>
<File
RelativePath="..\..\Common\Pkcs5.c"
>
</File>
<File
RelativePath="..\..\Common\Volumes.c"
>
</File>
<File
RelativePath="..\..\Common\Xts.c"
>
</File>
</Filter>
<Filter
Name="Crypto"
>
<File
RelativePath="..\..\Crypto\Aes_hw_cpu.asm"
>
</File>
<File
RelativePath="..\..\Crypto\AesSmall.c"
>
</File>
<File
RelativePath="..\..\Crypto\AesSmall_x86.asm"
>
</File>
<File
RelativePath="..\..\Crypto\Rmd160.c"
>
</File>
<File
RelativePath="..\..\Crypto\Serpent.c"
>
</File>
<File
RelativePath="..\..\Crypto\Sha2Small.c"
>
</File>
<File
RelativePath="..\..\Crypto\Twofish.c"
>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\Bios.h"
>
</File>
<File
RelativePath=".\BootCommon.h"
>
</File>
<File
RelativePath=".\BootConfig.h"
>
</File>
<File
RelativePath=".\BootConsoleIo.h"
>
</File>
<File
RelativePath=".\BootDebug.h"
>
</File>
<File
RelativePath=".\BootDefs.h"
>
</File>
<File
RelativePath=".\BootDiskIo.h"
>
</File>
<File
RelativePath=".\BootEncryptedIo.h"
>
</File>
<File
RelativePath=".\BootMain.h"
>
</File>
<File
RelativePath=".\BootMemory.h"
>
</File>
<File
RelativePath=".\BootStrings.h"
>
</File>
<File
RelativePath=".\IntFilter.h"
>
</File>
<File
RelativePath=".\Platform.h"
>
</File>
</Filter>
<Filter
Name="Build Files"
>
<File
RelativePath=".\Makefile"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -1,82 +1,82 @@
/*
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-2016 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_BootCommon
#define TC_HEADER_Boot_BootCommon
#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 0x0117
#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;
} 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;
Password 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
// Modifying these values can introduce incompatibility with previous versions
#define TC_SET_BOOT_ARGUMENTS_SIGNATURE(SG) do { SG[0] = 'T'; SG[1] = 'R'; SG[2] = 'U'; SG[3] = 'E'; SG[4] = 0x11; SG[5] = 0x23; SG[6] = 0x45; SG[7] = 0x66; } while (FALSE)
#define TC_IS_BOOT_ARGUMENTS_SIGNATURE(SG) (SG[0] == 'T' && SG[1] == 'R' && SG[2] == 'U' && SG[3] == 'E' && SG[4] == 0x11 && SG[5] == 0x23 && SG[6] == 0x45 && SG[7] == 0x66)
#endif // TC_HEADER_Boot_BootCommon
/*
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-2016 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_BootCommon
#define TC_HEADER_Boot_BootCommon
#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 0x0117
#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;
} 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;
Password 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
// Modifying these values can introduce incompatibility with previous versions
#define TC_SET_BOOT_ARGUMENTS_SIGNATURE(SG) do { SG[0] = 'T'; SG[1] = 'R'; SG[2] = 'U'; SG[3] = 'E'; SG[4] = 0x11; SG[5] = 0x23; SG[6] = 0x45; SG[7] = 0x66; } while (FALSE)
#define TC_IS_BOOT_ARGUMENTS_SIGNATURE(SG) (SG[0] == 'T' && SG[1] == 'R' && SG[2] == 'U' && SG[3] == 'E' && SG[4] == 0x11 && SG[5] == 0x23 && SG[6] == 0x45 && SG[7] == 0x66)
#endif // TC_HEADER_Boot_BootCommon

View File

@@ -1,102 +1,102 @@
/*
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-2016 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;
byte BootLoaderDrive;
byte 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;
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)
{
AcquireSectorBuffer();
BiosResult result = ReadWriteMBR (false, drive);
if (result != BiosResultSuccess)
goto ret;
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
result = ReadWriteMBR (true, drive);
ret:
ReleaseSectorBuffer();
return result;
}
#endif // !TC_WINDOWS_BOOT_RESCUE_DISK_MODE
/*
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-2016 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;
byte BootLoaderDrive;
byte 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;
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)
{
AcquireSectorBuffer();
BiosResult result = ReadWriteMBR (false, drive);
if (result != BiosResultSuccess)
goto ret;
SectorBuffer[TC_BOOT_SECTOR_CONFIG_OFFSET] = BootSectorFlags;
result = ReadWriteMBR (true, drive);
ret:
ReleaseSectorBuffer();
return result;
}
#endif // !TC_WINDOWS_BOOT_RESCUE_DISK_MODE

View File

@@ -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-2016 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 byte BootLoaderDrive;
extern byte 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);
#endif // TC_HEADER_Boot_BootConfig
/*
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-2016 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 byte BootLoaderDrive;
extern byte 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);
#endif // TC_HEADER_Boot_BootConfig

View File

@@ -1,339 +1,339 @@
/*
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-2016 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 "BootDebug.h"
#include "BootStrings.h"
static int ScreenOutputDisabled = 0;
void DisableScreenOutput ()
{
++ScreenOutputDisabled;
}
void EnableScreenOutput ()
{
--ScreenOutputDisabled;
}
void PrintChar (char c)
{
#ifdef TC_BOOT_TRACING_ENABLED
WriteDebugPort (c);
#endif
if (ScreenOutputDisabled)
return;
__asm
{
mov bx, 7
mov al, c
mov ah, 0xe
int 0x10
}
}
void PrintCharAtCursor (char c)
{
if (ScreenOutputDisabled)
return;
__asm
{
mov bx, 7
mov al, c
mov cx, 1
mov ah, 0xa
int 0x10
}
}
void Print (const char *str)
{
char c;
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)
{
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));
}
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)
{
while (cnt-- > 0)
PrintEndl ();
}
void Beep ()
{
PrintChar (7);
}
void InitVideoMode ()
{
if (ScreenOutputDisabled)
return;
__asm
{
// Text mode 80x25
mov ax, 3
int 0x10
// Page 0
mov ax, 0x500
int 0x10
}
}
void ClearScreen ()
{
if (ScreenOutputDisabled)
return;
__asm
{
// White text on black
mov bh, 7
xor cx, cx
mov dx, 0x184f
mov ax, 0x600
int 0x10
// Cursor at 0,0
xor bh, bh
xor dx, dx
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 ()
{
byte flags;
__asm
{
mov ah, 2
int 0x16
mov flags, al
}
return flags;
}
byte GetKeyboardChar ()
{
return GetKeyboardChar (nullptr);
}
byte GetKeyboardChar (byte *scanCode)
{
// Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer)
while (!IsKeyboardCharAvailable());
byte asciiCode;
byte 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;
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
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;
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;
}
/*
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-2016 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 "BootDebug.h"
#include "BootStrings.h"
static int ScreenOutputDisabled = 0;
void DisableScreenOutput ()
{
++ScreenOutputDisabled;
}
void EnableScreenOutput ()
{
--ScreenOutputDisabled;
}
void PrintChar (char c)
{
#ifdef TC_BOOT_TRACING_ENABLED
WriteDebugPort (c);
#endif
if (ScreenOutputDisabled)
return;
__asm
{
mov bx, 7
mov al, c
mov ah, 0xe
int 0x10
}
}
void PrintCharAtCursor (char c)
{
if (ScreenOutputDisabled)
return;
__asm
{
mov bx, 7
mov al, c
mov cx, 1
mov ah, 0xa
int 0x10
}
}
void Print (const char *str)
{
char c;
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)
{
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));
}
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)
{
while (cnt-- > 0)
PrintEndl ();
}
void Beep ()
{
PrintChar (7);
}
void InitVideoMode ()
{
if (ScreenOutputDisabled)
return;
__asm
{
// Text mode 80x25
mov ax, 3
int 0x10
// Page 0
mov ax, 0x500
int 0x10
}
}
void ClearScreen ()
{
if (ScreenOutputDisabled)
return;
__asm
{
// White text on black
mov bh, 7
xor cx, cx
mov dx, 0x184f
mov ax, 0x600
int 0x10
// Cursor at 0,0
xor bh, bh
xor dx, dx
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 ()
{
byte flags;
__asm
{
mov ah, 2
int 0x16
mov flags, al
}
return flags;
}
byte GetKeyboardChar ()
{
return GetKeyboardChar (nullptr);
}
byte GetKeyboardChar (byte *scanCode)
{
// Work around potential BIOS bugs (Windows boot manager polls the keystroke buffer)
while (!IsKeyboardCharAvailable());
byte asciiCode;
byte 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;
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
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;
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;
}

View File

@@ -1,72 +1,72 @@
/*
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-2016 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_BootConsoleIo
#define TC_HEADER_Boot_BootConsoleIo
#include "Platform.h"
#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 ();
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 (uint16 data);
void PrintHex (uint32 data);
void PrintHex (const uint64 &data);
#endif // TC_HEADER_Boot_BootConsoleIo
/*
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-2016 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_BootConsoleIo
#define TC_HEADER_Boot_BootConsoleIo
#include "Platform.h"
#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 ();
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 (uint16 data);
void PrintHex (uint32 data);
void PrintHex (const uint64 &data);
#endif // TC_HEADER_Boot_BootConsoleIo

View File

@@ -1,27 +1,27 @@
;
; 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-2016 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.
;
.MODEL tiny, C
.386
INCLUDE BootDefs.i
EXTERNDEF main:NEAR
_TEXT SEGMENT
ORG TC_COM_EXECUTABLE_OFFSET
start:
jmp main
_TEXT ENDS
END start
;
; 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-2016 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.
;
.MODEL tiny, C
.386
INCLUDE BootDefs.i
EXTERNDEF main:NEAR
_TEXT SEGMENT
ORG TC_COM_EXECUTABLE_OFFSET
start:
jmp main
_TEXT ENDS
END start

View File

@@ -1,181 +1,181 @@
/*
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-2016 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)
{
__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)
{
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;
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);
}
#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");
TC_THROW_FATAL_EXCEPTION;
}
}
void InitStackChecker ()
{
*(uint32 *) end = 0x12345678UL;
PrintStackInfo();
PrintEndl();
}
#endif // TC_BOOT_STACK_CHECKING_ENABLED
/*
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-2016 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)
{
__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)
{
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;
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);
}
#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");
TC_THROW_FATAL_EXCEPTION;
}
}
void InitStackChecker ()
{
*(uint32 *) end = 0x12345678UL;
PrintStackInfo();
PrintEndl();
}
#endif // TC_BOOT_STACK_CHECKING_ENABLED

View File

@@ -1,60 +1,60 @@
/*
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-2016 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_BootDebug
#define TC_HEADER_Boot_BootDebug
#include "Platform.h"
#include "BootConsoleIo.h"
#if 0
# define TC_BOOT_DEBUG_ENABLED
#endif
#if 0 || defined (TC_BOOT_DEBUG_ENABLED)
# 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 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
/*
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-2016 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_BootDebug
#define TC_HEADER_Boot_BootDebug
#include "Platform.h"
#include "BootConsoleIo.h"
#if 0
# define TC_BOOT_DEBUG_ENABLED
#endif
#if 0 || defined (TC_BOOT_DEBUG_ENABLED)
# 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 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

View File

@@ -1,199 +1,199 @@
/*
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-2016 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_BootDefs
#define TC_HEADER_Boot_BootDefs
// Total memory required (CODE + DATA + BSS + STACK + 0x100) in KBytes - determined from linker map.
#define TC__BOOT_MEMORY_REQUIRED 43
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
# undef TC__BOOT_MEMORY_REQUIRED
# ifdef TC_WINDOWS_BOOT_AES
# ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
# define TC__BOOT_MEMORY_REQUIRED 31
# else
# define TC__BOOT_MEMORY_REQUIRED 29
# endif
# elif defined (TC_WINDOWS_BOOT_SERPENT)
# define TC__BOOT_MEMORY_REQUIRED 33
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
# define TC__BOOT_MEMORY_REQUIRED 41
# endif
#if 0
# undef TC__BOOT_MEMORY_REQUIRED
# define TC__BOOT_MEMORY_REQUIRED 60
#endif
#endif
// Modifying this value can introduce incompatibility with previous versions
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000) // Some buggy BIOS routines fail if CS bits 0-10 are not zero
#if TC__BOOT_MEMORY_REQUIRED <= 32
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 32 * 1024 / 16)
#else
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 64 * 1024 / 16)
#endif
#define TC__COM_EXECUTABLE_OFFSET TC_HEX (100)
#define TC__BOOT_LOADER_LOWMEM_SEGMENT TC_HEX (2000)
#define TC__BOOT_LOADER_BUFFER_SEGMENT TC_HEX (4000)
#define TC__BOOT_LOADER_ALT_SEGMENT TC_HEX (6000)
#define TC__BOOT_LOADER_STACK_TOP (TC_BOOT_MEMORY_REQUIRED * TC_UNSIGNED (1024) - 4)
#define TC__LB_SIZE 512
#define TC__BOOT_LOADER_AREA_SECTOR_COUNT 63
#define TC__BOOT_SECTOR_VERSION_OFFSET 430
#define TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET 432
#define TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET 434
#define TC__BOOT_SECTOR_USER_CONFIG_OFFSET 438
#define TC__BOOT_SECTOR_CONFIG_OFFSET 439 // The last byte that is reserved for the boot loader
#define TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH 24
#define TC__BOOT_SECTOR_USER_MESSAGE_OFFSET (TC__BOOT_SECTOR_VERSION_OFFSET - TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE 4
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET (TC__BOOT_SECTOR_USER_MESSAGE_OFFSET - TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE)
#define TC__BOOT_SECTOR_PIM_VALUE_SIZE 2
#define TC__BOOT_SECTOR_PIM_VALUE_OFFSET (TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET - TC__BOOT_SECTOR_PIM_VALUE_SIZE)
#define TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR 2
#define TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT 4
#define TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE 32768
#define TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET (TC_COM_EXECUTABLE_OFFSET + 3072)
#define TC__BOOT_LOADER_START_SECTOR (TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT)
#define TC__MAX_BOOT_LOADER_SECTOR_COUNT (TC_BOOT_LOADER_AREA_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT - 2)
#define TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE ((TC_BOOT_LOADER_AREA_SECTOR_COUNT - 2) * TC_LB_SIZE)
#define TC__BOOT_LOADER_BACKUP_SECTOR_COUNT 30
#define TC__GZIP_HEADER_SIZE 10
#define TC__BOOT_CFG_FLAG_AREA_SIZE 1 // In bytes
// If you add more flags, revise TC__BOOT_CFG_FLAG_AREA_SIZE
#define TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC_HEX (02)
#define TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC_HEX (04)
#define TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC_HEX (10)
#define TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC_HEX (20)
#define TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE (TC_HEX (40) + TC_HEX (80))
// Modifying the following values can introduce incompatibility with previous versions
#define TC__BOOT_USER_CFG_FLAG_SILENT_MODE TC_HEX (01)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_ESC TC_HEX (02)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC_HEX (04)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_PIM TC_HEX (08)
// The following items are treated as a 2-bit value (apply TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE to obtain the value)
#define TC__HIDDEN_OS_CREATION_PHASE_NONE 0
#define TC__HIDDEN_OS_CREATION_PHASE_CLONING TC_HEX (40) // The boot loader is to copy the content of the system partition to the hidden volume
#define TC__HIDDEN_OS_CREATION_PHASE_WIPING TC_HEX (80) // The boot loader has successfully copied the content of the system partition to the hidden volume. The original OS is to be wiped now.
#define TC__HIDDEN_OS_CREATION_PHASE_WIPED (TC_HEX (40) + TC_HEX (80)) // The original OS has been wiped. The user is required to install a new OS (decoy OS) on the system partition now.
#ifdef TC_ASM_PREPROCESS
#define TC_HEX(N) 0##N##h
#define TC_UNSIGNED(N) N
TC_BOOT_MEMORY_REQUIRED = TC__BOOT_MEMORY_REQUIRED
TC_BOOT_LOADER_SEGMENT = TC__BOOT_LOADER_SEGMENT
TC_BOOT_LOADER_SEGMENT_LOW = TC__BOOT_LOADER_SEGMENT_LOW
TC_COM_EXECUTABLE_OFFSET = TC__COM_EXECUTABLE_OFFSET
TC_BOOT_LOADER_LOWMEM_SEGMENT = TC__BOOT_LOADER_LOWMEM_SEGMENT
TC_BOOT_LOADER_BUFFER_SEGMENT = TC__BOOT_LOADER_BUFFER_SEGMENT
TC_BOOT_LOADER_ALT_SEGMENT = TC__BOOT_LOADER_ALT_SEGMENT
TC_BOOT_LOADER_STACK_TOP = TC__BOOT_LOADER_STACK_TOP
TC_LB_SIZE = TC__LB_SIZE
TC_BOOT_LOADER_AREA_SECTOR_COUNT = TC__BOOT_LOADER_AREA_SECTOR_COUNT
TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET = TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET = TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
TC_BOOT_SECTOR_CONFIG_OFFSET = TC__BOOT_SECTOR_CONFIG_OFFSET
TC_BOOT_SECTOR_USER_CONFIG_OFFSET = TC__BOOT_SECTOR_USER_CONFIG_OFFSET
TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR = TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT = TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE = TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET = TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
TC_BOOT_LOADER_START_SECTOR = TC__BOOT_LOADER_START_SECTOR
TC_MAX_BOOT_LOADER_SECTOR_COUNT = TC__MAX_BOOT_LOADER_SECTOR_COUNT
TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE = TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
TC_BOOT_LOADER_BACKUP_SECTOR_COUNT = TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
TC_GZIP_HEADER_SIZE = TC__GZIP_HEADER_SIZE
TC_BOOT_CFG_FLAG_AREA_SIZE = TC__BOOT_CFG_FLAG_AREA_SIZE
TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE = TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER = TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER = TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE = TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
TC_BOOT_USER_CFG_FLAG_SILENT_MODE = TC__BOOT_USER_CFG_FLAG_SILENT_MODE
TC_HIDDEN_OS_CREATION_PHASE_NONE = TC__HIDDEN_OS_CREATION_PHASE_NONE
TC_HIDDEN_OS_CREATION_PHASE_CLONING = TC__HIDDEN_OS_CREATION_PHASE_CLONING
TC_HIDDEN_OS_CREATION_PHASE_WIPING = TC__HIDDEN_OS_CREATION_PHASE_WIPING
TC_HIDDEN_OS_CREATION_PHASE_WIPED = TC__HIDDEN_OS_CREATION_PHASE_WIPED
#else // TC_ASM_PREPROCESS
#define TC_HEX(N) 0x##N
#define TC_UNSIGNED(N) N##U
#define TC_BOOT_MEMORY_REQUIRED TC__BOOT_MEMORY_REQUIRED
#define TC_BOOT_LOADER_SEGMENT TC__BOOT_LOADER_SEGMENT
#define TC_COM_EXECUTABLE_OFFSET TC__COM_EXECUTABLE_OFFSET
#define TC_BOOT_LOADER_LOWMEM_SEGMENT TC__BOOT_LOADER_LOWMEM_SEGMENT
#define TC_BOOT_LOADER_BUFFER_SEGMENT TC__BOOT_LOADER_BUFFER_SEGMENT
#define TC_BOOT_LOADER_ALT_SEGMENT TC__BOOT_LOADER_ALT_SEGMENT
#define TC_BOOT_LOADER_STACK_TOP (TC__BOOT_LOADER_STACK_TOP)
#define TC_BOOT_LOADER_AREA_SECTOR_COUNT TC__BOOT_LOADER_AREA_SECTOR_COUNT
#define TC_BOOT_SECTOR_USER_MESSAGE_OFFSET TC__BOOT_SECTOR_USER_MESSAGE_OFFSET
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET
#define TC_BOOT_SECTOR_PIM_VALUE_SIZE TC__BOOT_SECTOR_PIM_VALUE_SIZE
#define TC_BOOT_SECTOR_PIM_VALUE_OFFSET TC__BOOT_SECTOR_PIM_VALUE_OFFSET
#define TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH
#define TC_BOOT_SECTOR_VERSION_OFFSET TC__BOOT_SECTOR_VERSION_OFFSET
#define TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
#define TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
#define TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
#define TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
#define TC_BOOT_SECTOR_CONFIG_OFFSET TC__BOOT_SECTOR_CONFIG_OFFSET
#define TC_BOOT_SECTOR_USER_CONFIG_OFFSET TC__BOOT_SECTOR_USER_CONFIG_OFFSET
#define TC_BOOT_LOADER_START_SECTOR TC__BOOT_LOADER_START_SECTOR
#define TC_LB_SIZE TC__LB_SIZE
#define TC_MAX_BOOT_LOADER_SECTOR_COUNT TC__MAX_BOOT_LOADER_SECTOR_COUNT
#define TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
#define TC_BOOT_LOADER_BACKUP_SECTOR_COUNT TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
#define TC_GZIP_HEADER_SIZE TC__GZIP_HEADER_SIZE
#define TC_BOOT_CFG_FLAG_AREA_SIZE TC__BOOT_CFG_FLAG_AREA_SIZE
#define TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
#define TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
#define TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
#define TC_BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION
#define TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
#define TC_BOOT_USER_CFG_FLAG_SILENT_MODE TC__BOOT_USER_CFG_FLAG_SILENT_MODE
#define TC_BOOT_USER_CFG_FLAG_DISABLE_ESC TC__BOOT_USER_CFG_FLAG_DISABLE_ESC
#define TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION
#define TC_BOOT_USER_CFG_FLAG_DISABLE_PIM TC__BOOT_USER_CFG_FLAG_DISABLE_PIM
#define TC_HIDDEN_OS_CREATION_PHASE_NONE TC__HIDDEN_OS_CREATION_PHASE_NONE
#define TC_HIDDEN_OS_CREATION_PHASE_CLONING TC__HIDDEN_OS_CREATION_PHASE_CLONING
#define TC_HIDDEN_OS_CREATION_PHASE_WIPING TC__HIDDEN_OS_CREATION_PHASE_WIPING
#define TC_HIDDEN_OS_CREATION_PHASE_WIPED TC__HIDDEN_OS_CREATION_PHASE_WIPED
#endif // TC_ASM_PREPROCESS
#endif // TC_HEADER_Boot_BootDefs
/*
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-2016 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_BootDefs
#define TC_HEADER_Boot_BootDefs
// Total memory required (CODE + DATA + BSS + STACK + 0x100) in KBytes - determined from linker map.
#define TC__BOOT_MEMORY_REQUIRED 43
#ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
# undef TC__BOOT_MEMORY_REQUIRED
# ifdef TC_WINDOWS_BOOT_AES
# ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE
# define TC__BOOT_MEMORY_REQUIRED 31
# else
# define TC__BOOT_MEMORY_REQUIRED 29
# endif
# elif defined (TC_WINDOWS_BOOT_SERPENT)
# define TC__BOOT_MEMORY_REQUIRED 33
# elif defined (TC_WINDOWS_BOOT_TWOFISH)
# define TC__BOOT_MEMORY_REQUIRED 41
# endif
#if 0
# undef TC__BOOT_MEMORY_REQUIRED
# define TC__BOOT_MEMORY_REQUIRED 60
#endif
#endif
// Modifying this value can introduce incompatibility with previous versions
#define TC__BOOT_LOADER_SEGMENT TC_HEX (9000) // Some buggy BIOS routines fail if CS bits 0-10 are not zero
#if TC__BOOT_MEMORY_REQUIRED <= 32
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 32 * 1024 / 16)
#else
# define TC__BOOT_LOADER_SEGMENT_LOW (TC__BOOT_LOADER_SEGMENT - 64 * 1024 / 16)
#endif
#define TC__COM_EXECUTABLE_OFFSET TC_HEX (100)
#define TC__BOOT_LOADER_LOWMEM_SEGMENT TC_HEX (2000)
#define TC__BOOT_LOADER_BUFFER_SEGMENT TC_HEX (4000)
#define TC__BOOT_LOADER_ALT_SEGMENT TC_HEX (6000)
#define TC__BOOT_LOADER_STACK_TOP (TC_BOOT_MEMORY_REQUIRED * TC_UNSIGNED (1024) - 4)
#define TC__LB_SIZE 512
#define TC__BOOT_LOADER_AREA_SECTOR_COUNT 63
#define TC__BOOT_SECTOR_VERSION_OFFSET 430
#define TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET 432
#define TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET 434
#define TC__BOOT_SECTOR_USER_CONFIG_OFFSET 438
#define TC__BOOT_SECTOR_CONFIG_OFFSET 439 // The last byte that is reserved for the boot loader
#define TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH 24
#define TC__BOOT_SECTOR_USER_MESSAGE_OFFSET (TC__BOOT_SECTOR_VERSION_OFFSET - TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE 4
#define TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET (TC__BOOT_SECTOR_USER_MESSAGE_OFFSET - TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE)
#define TC__BOOT_SECTOR_PIM_VALUE_SIZE 2
#define TC__BOOT_SECTOR_PIM_VALUE_OFFSET (TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET - TC__BOOT_SECTOR_PIM_VALUE_SIZE)
#define TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR 2
#define TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT 4
#define TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE 32768
#define TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET (TC_COM_EXECUTABLE_OFFSET + 3072)
#define TC__BOOT_LOADER_START_SECTOR (TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT)
#define TC__MAX_BOOT_LOADER_SECTOR_COUNT (TC_BOOT_LOADER_AREA_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT - 2)
#define TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE ((TC_BOOT_LOADER_AREA_SECTOR_COUNT - 2) * TC_LB_SIZE)
#define TC__BOOT_LOADER_BACKUP_SECTOR_COUNT 30
#define TC__GZIP_HEADER_SIZE 10
#define TC__BOOT_CFG_FLAG_AREA_SIZE 1 // In bytes
// If you add more flags, revise TC__BOOT_CFG_FLAG_AREA_SIZE
#define TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC_HEX (02)
#define TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC_HEX (04)
#define TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC_HEX (10)
#define TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC_HEX (20)
#define TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE (TC_HEX (40) + TC_HEX (80))
// Modifying the following values can introduce incompatibility with previous versions
#define TC__BOOT_USER_CFG_FLAG_SILENT_MODE TC_HEX (01)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_ESC TC_HEX (02)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC_HEX (04)
#define TC__BOOT_USER_CFG_FLAG_DISABLE_PIM TC_HEX (08)
// The following items are treated as a 2-bit value (apply TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE to obtain the value)
#define TC__HIDDEN_OS_CREATION_PHASE_NONE 0
#define TC__HIDDEN_OS_CREATION_PHASE_CLONING TC_HEX (40) // The boot loader is to copy the content of the system partition to the hidden volume
#define TC__HIDDEN_OS_CREATION_PHASE_WIPING TC_HEX (80) // The boot loader has successfully copied the content of the system partition to the hidden volume. The original OS is to be wiped now.
#define TC__HIDDEN_OS_CREATION_PHASE_WIPED (TC_HEX (40) + TC_HEX (80)) // The original OS has been wiped. The user is required to install a new OS (decoy OS) on the system partition now.
#ifdef TC_ASM_PREPROCESS
#define TC_HEX(N) 0##N##h
#define TC_UNSIGNED(N) N
TC_BOOT_MEMORY_REQUIRED = TC__BOOT_MEMORY_REQUIRED
TC_BOOT_LOADER_SEGMENT = TC__BOOT_LOADER_SEGMENT
TC_BOOT_LOADER_SEGMENT_LOW = TC__BOOT_LOADER_SEGMENT_LOW
TC_COM_EXECUTABLE_OFFSET = TC__COM_EXECUTABLE_OFFSET
TC_BOOT_LOADER_LOWMEM_SEGMENT = TC__BOOT_LOADER_LOWMEM_SEGMENT
TC_BOOT_LOADER_BUFFER_SEGMENT = TC__BOOT_LOADER_BUFFER_SEGMENT
TC_BOOT_LOADER_ALT_SEGMENT = TC__BOOT_LOADER_ALT_SEGMENT
TC_BOOT_LOADER_STACK_TOP = TC__BOOT_LOADER_STACK_TOP
TC_LB_SIZE = TC__LB_SIZE
TC_BOOT_LOADER_AREA_SECTOR_COUNT = TC__BOOT_LOADER_AREA_SECTOR_COUNT
TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET = TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET = TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
TC_BOOT_SECTOR_CONFIG_OFFSET = TC__BOOT_SECTOR_CONFIG_OFFSET
TC_BOOT_SECTOR_USER_CONFIG_OFFSET = TC__BOOT_SECTOR_USER_CONFIG_OFFSET
TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR = TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT = TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE = TC__BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET = TC__BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
TC_BOOT_LOADER_START_SECTOR = TC__BOOT_LOADER_START_SECTOR
TC_MAX_BOOT_LOADER_SECTOR_COUNT = TC__MAX_BOOT_LOADER_SECTOR_COUNT
TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE = TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
TC_BOOT_LOADER_BACKUP_SECTOR_COUNT = TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
TC_GZIP_HEADER_SIZE = TC__GZIP_HEADER_SIZE
TC_BOOT_CFG_FLAG_AREA_SIZE = TC__BOOT_CFG_FLAG_AREA_SIZE
TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE = TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER = TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER = TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE = TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
TC_BOOT_USER_CFG_FLAG_SILENT_MODE = TC__BOOT_USER_CFG_FLAG_SILENT_MODE
TC_HIDDEN_OS_CREATION_PHASE_NONE = TC__HIDDEN_OS_CREATION_PHASE_NONE
TC_HIDDEN_OS_CREATION_PHASE_CLONING = TC__HIDDEN_OS_CREATION_PHASE_CLONING
TC_HIDDEN_OS_CREATION_PHASE_WIPING = TC__HIDDEN_OS_CREATION_PHASE_WIPING
TC_HIDDEN_OS_CREATION_PHASE_WIPED = TC__HIDDEN_OS_CREATION_PHASE_WIPED
#else // TC_ASM_PREPROCESS
#define TC_HEX(N) 0x##N
#define TC_UNSIGNED(N) N##U
#define TC_BOOT_MEMORY_REQUIRED TC__BOOT_MEMORY_REQUIRED
#define TC_BOOT_LOADER_SEGMENT TC__BOOT_LOADER_SEGMENT
#define TC_COM_EXECUTABLE_OFFSET TC__COM_EXECUTABLE_OFFSET
#define TC_BOOT_LOADER_LOWMEM_SEGMENT TC__BOOT_LOADER_LOWMEM_SEGMENT
#define TC_BOOT_LOADER_BUFFER_SEGMENT TC__BOOT_LOADER_BUFFER_SEGMENT
#define TC_BOOT_LOADER_ALT_SEGMENT TC__BOOT_LOADER_ALT_SEGMENT
#define TC_BOOT_LOADER_STACK_TOP (TC__BOOT_LOADER_STACK_TOP)
#define TC_BOOT_LOADER_AREA_SECTOR_COUNT TC__BOOT_LOADER_AREA_SECTOR_COUNT
#define TC_BOOT_SECTOR_USER_MESSAGE_OFFSET TC__BOOT_SECTOR_USER_MESSAGE_OFFSET
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_SIZE
#define TC_BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET TC__BOOT_SECTOR_OUTER_VOLUME_BAK_HEADER_CRC_OFFSET
#define TC_BOOT_SECTOR_PIM_VALUE_SIZE TC__BOOT_SECTOR_PIM_VALUE_SIZE
#define TC_BOOT_SECTOR_PIM_VALUE_OFFSET TC__BOOT_SECTOR_PIM_VALUE_OFFSET
#define TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH TC__BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH
#define TC_BOOT_SECTOR_VERSION_OFFSET TC__BOOT_SECTOR_VERSION_OFFSET
#define TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET TC__BOOT_SECTOR_LOADER_LENGTH_OFFSET
#define TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET TC__BOOT_SECTOR_LOADER_CHECKSUM_OFFSET
#define TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR TC__BOOT_LOADER_DECOMPRESSOR_START_SECTOR
#define TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT TC__BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
#define TC_BOOT_SECTOR_CONFIG_OFFSET TC__BOOT_SECTOR_CONFIG_OFFSET
#define TC_BOOT_SECTOR_USER_CONFIG_OFFSET TC__BOOT_SECTOR_USER_CONFIG_OFFSET
#define TC_BOOT_LOADER_START_SECTOR TC__BOOT_LOADER_START_SECTOR
#define TC_LB_SIZE TC__LB_SIZE
#define TC_MAX_BOOT_LOADER_SECTOR_COUNT TC__MAX_BOOT_LOADER_SECTOR_COUNT
#define TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE TC__MAX_BOOT_LOADER_DECOMPRESSED_SIZE
#define TC_BOOT_LOADER_BACKUP_SECTOR_COUNT TC__BOOT_LOADER_BACKUP_SECTOR_COUNT
#define TC_GZIP_HEADER_SIZE TC__GZIP_HEADER_SIZE
#define TC_BOOT_CFG_FLAG_AREA_SIZE TC__BOOT_CFG_FLAG_AREA_SIZE
#define TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE TC__BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE
#define TC_BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER TC__BOOT_CFG_FLAG_WINDOWS_VISTA_OR_LATER
#define TC_BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER TC__BOOT_CFG_FLAG_RESCUE_DISK_ORIG_SYS_LOADER
#define TC_BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION TC__BOOT_CFG_FLAG_RESCUE_DISABLE_HW_ENCRYPTION
#define TC_BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE TC__BOOT_CFG_MASK_HIDDEN_OS_CREATION_PHASE
#define TC_BOOT_USER_CFG_FLAG_SILENT_MODE TC__BOOT_USER_CFG_FLAG_SILENT_MODE
#define TC_BOOT_USER_CFG_FLAG_DISABLE_ESC TC__BOOT_USER_CFG_FLAG_DISABLE_ESC
#define TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION TC__BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION
#define TC_BOOT_USER_CFG_FLAG_DISABLE_PIM TC__BOOT_USER_CFG_FLAG_DISABLE_PIM
#define TC_HIDDEN_OS_CREATION_PHASE_NONE TC__HIDDEN_OS_CREATION_PHASE_NONE
#define TC_HIDDEN_OS_CREATION_PHASE_CLONING TC__HIDDEN_OS_CREATION_PHASE_CLONING
#define TC_HIDDEN_OS_CREATION_PHASE_WIPING TC__HIDDEN_OS_CREATION_PHASE_WIPING
#define TC_HIDDEN_OS_CREATION_PHASE_WIPED TC__HIDDEN_OS_CREATION_PHASE_WIPED
#endif // TC_ASM_PREPROCESS
#endif // TC_HEADER_Boot_BootDefs

View File

@@ -1,491 +1,491 @@
/*
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-2016 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];
#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)
{
static byte 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)
{
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 (" MB ");
}
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
{
CheckStack();
byte cylinderLow = (byte) chs.Cylinder;
byte sector = chs.Sector;
sector |= byte (chs.Cylinder >> 2) & 0xc0;
byte function = write ? 0x03 : 0x02;
BiosResult result;
byte 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;
}
BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte 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)
{
return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent);
}
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
{
return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent);
}
static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte 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;
BiosResult result;
byte 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;
}
static BiosResult ReadWriteSectors (bool write, byte *buffer, byte 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)
{
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)
{
return ReadWriteSectors (false, bufferSegment, bufferOffset, drive, sector, sectorCount, silent);
}
BiosResult ReadSectors (byte *buffer, byte 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)
{
return ReadWriteSectors (true, buffer, drive, sector, sectorCount, silent);
}
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent)
{
CheckStack();
byte 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);
uint32 ch = lba.LowPart / geometry.Sectors;
chs.Head = (byte) (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)
{
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)
{
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
&& 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)
{
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;
}
/*
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-2016 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];
#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)
{
static byte 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)
{
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 (" MB ");
}
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
{
CheckStack();
byte cylinderLow = (byte) chs.Cylinder;
byte sector = chs.Sector;
sector |= byte (chs.Cylinder >> 2) & 0xc0;
byte function = write ? 0x03 : 0x02;
BiosResult result;
byte 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;
}
BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte 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)
{
return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent);
}
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent)
{
return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent);
}
static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte 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;
BiosResult result;
byte 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;
}
static BiosResult ReadWriteSectors (bool write, byte *buffer, byte 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)
{
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)
{
return ReadWriteSectors (false, bufferSegment, bufferOffset, drive, sector, sectorCount, silent);
}
BiosResult ReadSectors (byte *buffer, byte 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)
{
return ReadWriteSectors (true, buffer, drive, sector, sectorCount, silent);
}
BiosResult GetDriveGeometry (byte drive, DriveGeometry &geometry, bool silent)
{
CheckStack();
byte 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);
uint32 ch = lba.LowPart / geometry.Sectors;
chs.Head = (byte) (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)
{
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)
{
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
&& 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)
{
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;
}

View File

@@ -1,120 +1,120 @@
/*
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-2016 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;
byte StartHead;
byte StartCylSector;
byte StartCylinder;
byte Type;
byte EndHead;
byte EndSector;
byte EndCylinder;
uint32 StartLBA;
uint32 SectorCountLBA;
};
struct MBR
{
byte Code[446];
PartitionEntryMBR Partitions[4];
uint16 Signature;
};
struct BiosLbaPacket
{
byte Size;
byte Reserved;
uint16 SectorCount;
uint32 Buffer;
uint64 Sector;
};
#pragma pack()
struct ChsAddress
{
uint16 Cylinder;
byte Head;
byte Sector;
};
struct Partition
{
byte Number;
byte Drive;
bool Active;
uint64 EndSector;
bool Primary;
uint64 SectorCount;
uint64 StartSector;
byte Type;
};
struct DriveGeometry
{
uint16 Cylinders;
byte Heads;
byte 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);
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 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 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];
#endif // TC_HEADER_Boot_BootDiskIo
/*
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-2016 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;
byte StartHead;
byte StartCylSector;
byte StartCylinder;
byte Type;
byte EndHead;
byte EndSector;
byte EndCylinder;
uint32 StartLBA;
uint32 SectorCountLBA;
};
struct MBR
{
byte Code[446];
PartitionEntryMBR Partitions[4];
uint16 Signature;
};
struct BiosLbaPacket
{
byte Size;
byte Reserved;
uint16 SectorCount;
uint32 Buffer;
uint64 Sector;
};
#pragma pack()
struct ChsAddress
{
uint16 Cylinder;
byte Head;
byte Sector;
};
struct Partition
{
byte Number;
byte Drive;
bool Active;
uint64 EndSector;
bool Primary;
uint64 SectorCount;
uint64 StartSector;
byte Type;
};
struct DriveGeometry
{
uint16 Cylinders;
byte Heads;
byte 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);
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 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 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];
#endif // TC_HEADER_Boot_BootDiskIo

View File

@@ -1,132 +1,132 @@
/*
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-2016 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 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 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);
}
result = WriteSectors (SectorBuffer, drive, sector + writeOffset, 1);
if (result != BiosResultSuccess)
break;
++sector;
++dataUnitNo;
sourceOffset += TC_LB_SIZE;
}
ReleaseSectorBuffer();
return result;
}
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 &sector, uint16 sectorCount)
{
uint64 readWriteEnd = sector + --sectorCount;
return ((sector < EncryptedVirtualPartition.StartSector && readWriteEnd >= EncryptedVirtualPartition.StartSector)
|| (sector >= EncryptedVirtualPartition.StartSector && readWriteEnd > EncryptedVirtualPartition.EndSector));
}
/*
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-2016 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 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 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);
}
result = WriteSectors (SectorBuffer, drive, sector + writeOffset, 1);
if (result != BiosResultSuccess)
break;
++sector;
++dataUnitNo;
sourceOffset += TC_LB_SIZE;
}
ReleaseSectorBuffer();
return result;
}
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 &sector, uint16 sectorCount)
{
uint64 readWriteEnd = sector + --sectorCount;
return ((sector < EncryptedVirtualPartition.StartSector && readWriteEnd >= EncryptedVirtualPartition.StartSector)
|| (sector >= EncryptedVirtualPartition.StartSector && readWriteEnd > EncryptedVirtualPartition.EndSector));
}

View File

@@ -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-2016 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);
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 &sector, uint16 sectorCount);
#endif // TC_HEADER_Boot_BootEncryptionIo
/*
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-2016 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);
static bool ReadWritePartiallyCoversEncryptedArea (const uint64 &sector, uint16 sectorCount);
#endif // TC_HEADER_Boot_BootEncryptionIo

File diff suppressed because it is too large Load Diff

View File

@@ -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-2016 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 int AskSelection (const char *options[], size_t optionCount);
static bool AskYesNo (const char *message);
static byte BootEncryptedDrive ();
static void BootMenu ();
static void ExecuteBootSector (byte drive, byte *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 void PrintMainMenu ();
static void RepairMenu ();
#define TC_MENU_KEY_REPAIR TC_BIOS_KEY_F8
#endif // TC_HEADER_Boot_BootMain
/*
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-2016 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 int AskSelection (const char *options[], size_t optionCount);
static bool AskYesNo (const char *message);
static byte BootEncryptedDrive ();
static void BootMenu ();
static void ExecuteBootSector (byte drive, byte *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 void PrintMainMenu ();
static void RepairMenu ();
#define TC_MENU_KEY_REPAIR TC_BIOS_KEY_F8
#endif // TC_HEADER_Boot_BootMain

View File

@@ -1,86 +1,86 @@
/*
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-2016 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 "BootDefs.h"
#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
{
push es
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
// Use alternative segment to prevent memory corruption caused by buggy BIOSes
push TC_BOOT_LOADER_ALT_SEGMENT
pop es
mov di, 0
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
pop es
}
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
// 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);
}
/*
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-2016 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 "BootDefs.h"
#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
{
push es
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
// Use alternative segment to prevent memory corruption caused by buggy BIOSes
push TC_BOOT_LOADER_ALT_SEGMENT
pop es
mov di, 0
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
pop es
}
CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
// 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);
}

View File

@@ -1,28 +1,28 @@
/*
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-2016 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"
#pragma pack(1)
struct BiosMemoryMapEntry
{
uint64 BaseAddress;
uint64 Length;
uint32 Type;
};
#pragma pack()
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
/*
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-2016 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"
#pragma pack(1)
struct BiosMemoryMapEntry
{
uint64 BaseAddress;
uint64 Length;
uint32 Type;
};
#pragma pack()
bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry);
bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry);

View File

@@ -1,244 +1,244 @@
;
; 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-2016 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.
;
.MODEL tiny
.386
_TEXT SEGMENT USE16
INCLUDE BootDefs.i
ORG 7C00h ; Standard boot sector offset
start:
; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
; Far jump to the next instruction sets IP to the standard offset 7C00.
db 0EAh ; jmp 0:main
dw main, 0
loader_name_msg:
db ' VeraCrypt Boot Loader', 13, 10, 0
main:
cli
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 7C00h
sti
; Display boot loader name
test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
jnz skip_loader_name_msg
lea si, loader_name_msg
call print
skip_loader_name_msg:
; Determine boot loader segment
mov ax, TC_BOOT_LOADER_SEGMENT
; Check available memory
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
mov ax, TC_BOOT_LOADER_SEGMENT_LOW
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
; Insufficient memory
mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
memory_ok:
mov es, ax
; Clear BSS section
xor al, al
mov di, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
cld
rep stosb
mov ax, es
sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16 ; Decompressor segment
mov es, ax
; Load decompressor
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
retry_backup:
mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov bx, TC_COM_EXECUTABLE_OFFSET
call read_sectors
; Decompressor checksum
xor ebx, ebx
mov si, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
call checksum
push ebx
; Load compressed boot loader
mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cl, TC_BOOT_LOADER_START_SECTOR
mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
test backup_loader_used, 1
jz non_backup
mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
non_backup:
call read_sectors
; Boot loader checksum
pop ebx
mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
call checksum
; Verify checksum
cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
je checksum_ok
; Checksum incorrect - try using backup if available
test backup_loader_used, 1
jnz loader_damaged
mov backup_loader_used, 1
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
jnz retry_backup
loader_damaged:
lea si, loader_damaged_msg
call print
lea si, loader_name_msg
call print
jmp $
checksum_ok:
; Set up decompressor segment
mov ax, es
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
sti
push dx
; Decompress boot loader
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
sub cx, TC_GZIP_HEADER_SIZE
push cx ; Compressed data size
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size
push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET ; Output buffer
push cs
push decompressor_ret
push es
push TC_COM_EXECUTABLE_OFFSET
retf
decompressor_ret:
add sp, 8
pop dx
; Restore boot sector segment
push cs
pop ds
; Check decompression result
test ax, ax
jz decompression_ok
lea si, loader_damaged_msg
call print
jmp $
decompression_ok:
; DH = boot sector flags
mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
; Set up boot loader segment
mov ax, es
add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
mov es, ax
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_STACK_TOP
sti
; Execute boot loader
push es
push TC_COM_EXECUTABLE_OFFSET
retf
; Print string
print:
xor bx, bx
mov ah, 0eh
cld
@@: lodsb
test al, al
jz print_end
int 10h
jmp @B
print_end:
ret
; Read sectors of the first cylinder
read_sectors:
mov ch, 0 ; Cylinder
mov dh, 0 ; Head
; DL = drive number passed from BIOS
mov ah, 2
int 13h
jnc read_ok
lea si, disk_error_msg
call print
read_ok:
ret
; Calculate checksum
checksum:
push ds
push es
pop ds
xor eax, eax
cld
@@: lodsb
add ebx, eax
rol ebx, 1
loop @B
pop ds
ret
backup_loader_used db 0
disk_error_msg db 'Disk error', 13, 10, 7, 0
loader_damaged_msg db 7, 'Loader damaged! Repair with Rescue Disk', 0
ORG 7C00h + 510
dw 0AA55h ; Boot sector signature
_TEXT ENDS
END start
;
; 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-2016 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.
;
.MODEL tiny
.386
_TEXT SEGMENT USE16
INCLUDE BootDefs.i
ORG 7C00h ; Standard boot sector offset
start:
; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
; Far jump to the next instruction sets IP to the standard offset 7C00.
db 0EAh ; jmp 0:main
dw main, 0
loader_name_msg:
db ' VeraCrypt Boot Loader', 13, 10, 0
main:
cli
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 7C00h
sti
; Display boot loader name
test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
jnz skip_loader_name_msg
lea si, loader_name_msg
call print
skip_loader_name_msg:
; Determine boot loader segment
mov ax, TC_BOOT_LOADER_SEGMENT
; Check available memory
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
mov ax, TC_BOOT_LOADER_SEGMENT_LOW
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
; Insufficient memory
mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
memory_ok:
mov es, ax
; Clear BSS section
xor al, al
mov di, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
cld
rep stosb
mov ax, es
sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16 ; Decompressor segment
mov es, ax
; Load decompressor
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
retry_backup:
mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov bx, TC_COM_EXECUTABLE_OFFSET
call read_sectors
; Decompressor checksum
xor ebx, ebx
mov si, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
call checksum
push ebx
; Load compressed boot loader
mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cl, TC_BOOT_LOADER_START_SECTOR
mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
test backup_loader_used, 1
jz non_backup
mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
non_backup:
call read_sectors
; Boot loader checksum
pop ebx
mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
call checksum
; Verify checksum
cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
je checksum_ok
; Checksum incorrect - try using backup if available
test backup_loader_used, 1
jnz loader_damaged
mov backup_loader_used, 1
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
jnz retry_backup
loader_damaged:
lea si, loader_damaged_msg
call print
lea si, loader_name_msg
call print
jmp $
checksum_ok:
; Set up decompressor segment
mov ax, es
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
sti
push dx
; Decompress boot loader
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
sub cx, TC_GZIP_HEADER_SIZE
push cx ; Compressed data size
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size
push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET ; Output buffer
push cs
push decompressor_ret
push es
push TC_COM_EXECUTABLE_OFFSET
retf
decompressor_ret:
add sp, 8
pop dx
; Restore boot sector segment
push cs
pop ds
; Check decompression result
test ax, ax
jz decompression_ok
lea si, loader_damaged_msg
call print
jmp $
decompression_ok:
; DH = boot sector flags
mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
; Set up boot loader segment
mov ax, es
add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
mov es, ax
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_STACK_TOP
sti
; Execute boot loader
push es
push TC_COM_EXECUTABLE_OFFSET
retf
; Print string
print:
xor bx, bx
mov ah, 0eh
cld
@@: lodsb
test al, al
jz print_end
int 10h
jmp @B
print_end:
ret
; Read sectors of the first cylinder
read_sectors:
mov ch, 0 ; Cylinder
mov dh, 0 ; Head
; DL = drive number passed from BIOS
mov ah, 2
int 13h
jnc read_ok
lea si, disk_error_msg
call print
read_ok:
ret
; Calculate checksum
checksum:
push ds
push es
pop ds
xor eax, eax
cld
@@: lodsb
add ebx, eax
rol ebx, 1
loop @B
pop ds
ret
backup_loader_used db 0
disk_error_msg db 'Disk error', 13, 10, 7, 0
loader_damaged_msg db 7, 'Loader damaged! Repair with Rescue Disk', 0
ORG 7C00h + 510
dw 0AA55h ; Boot sector signature
_TEXT ENDS
END start

View File

@@ -1,20 +1,20 @@
/*
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-2016 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_BootStrings
#define TC_HEADER_Boot_BootStrings
#define TC_BOOT_STR_ERROR "Error: "
#define TC_BOOT_STR_NO_BOOT_PARTITION "No bootable partition found"
#define TC_BOOT_STR_UPGRADE_BIOS "- Upgrade BIOS\r\n- Use a different motherboard model/brand\r\n"
#endif // TC_HEADER_Boot_BootStrings
/*
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-2016 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_BootStrings
#define TC_HEADER_Boot_BootStrings
#define TC_BOOT_STR_ERROR "Error: "
#define TC_BOOT_STR_NO_BOOT_PARTITION "No bootable partition found"
#define TC_BOOT_STR_UPGRADE_BIOS "- Upgrade BIOS\r\n- Use a different motherboard model/brand\r\n"
#endif // TC_HEADER_Boot_BootStrings

View File

@@ -83,7 +83,7 @@ local int stored(struct state *s)
s->bitbuf = 0;
s->bitcnt = 0;
if (s->incnt + 4 > s->inlen)
if (s->incnt + 4 > s->inlen)
return 2; /* not enough input */
/* get length and check against its one's complement */
@@ -93,7 +93,7 @@ local int stored(struct state *s)
s->in[s->incnt++] != ((~len >> 8) & 0xff))
return -2; /* didn't match complement! */
if (s->incnt + len > s->inlen)
if (s->incnt + len > s->inlen)
return 2; /* not enough input */
/* copy len bytes from in to out */
@@ -379,21 +379,21 @@ local int dynamic(struct state *s)
lengths[index++] = symbol;
else { /* repeat instruction */
len = 0; /* assume repeating zeros */
switch(symbol)
{
case 16: { /* repeat last length 3..6 times */
if (index == 0) return -5; /* no last length! */
len = lengths[index - 1]; /* last length */
symbol = 3 + bits(s, 2);
break;
}
case 17: /* repeat zero 3..10 times */
symbol = 3 + bits(s, 3);
break;
default: /* == 18, repeat zero 11..138 times */
symbol = 11 + bits(s, 7);
break;
}
switch(symbol)
{
case 16: { /* repeat last length 3..6 times */
if (index == 0) return -5; /* no last length! */
len = lengths[index - 1]; /* last length */
symbol = 3 + bits(s, 2);
break;
}
case 17: /* repeat zero 3..10 times */
symbol = 3 + bits(s, 3);
break;
default: /* == 18, repeat zero 11..138 times */
symbol = 11 + bits(s, 7);
break;
}
if ((index + symbol > nlen + ndist))
return -6; /* too many lengths! */
while (symbol--) /* repeat last or zero symbol times */
@@ -401,8 +401,8 @@ local int dynamic(struct state *s)
}
}
/* check for end-of-block code -- there better be one! */
if (lengths[256] == 0)
/* check for end-of-block code -- there better be one! */
if (lengths[256] == 0)
return -9;
/* build huffman table for literal/length codes */
@@ -423,50 +423,50 @@ local int dynamic(struct state *s)
void _acrtused () { }
// Decompress deflated data
int far main (
unsigned char *dest, /* pointer to destination pointer */
unsigned int destlen, /* amount of output space */
unsigned char *source, /* pointer to source data pointer */
unsigned int sourcelen)
{
struct state s; /* input/output state */
int last, type; /* block information */
int err; /* return value */
/* initialize output state */
s.out = dest;
s.outlen = destlen; /* ignored if dest is NIL */
s.outcnt = 0;
/* initialize input state */
s.in = source;
s.inlen = sourcelen;
s.incnt = 0;
s.bitbuf = 0;
s.bitcnt = 0;
/* process blocks until last block or error */
do {
last = bits(&s, 1); /* one if last block */
type = bits(&s, 2); /* block type 0..3 */
switch(type)
{
case 0:
err = stored(&s);
break;
case 1:
err = fixed(&s);
break;
case 2:
err = dynamic(&s);
break;
default:
err = -1; /* type == 3, invalid */
break;
}
if (err != 0) break; /* return with error */
} while (!last);
return err;
int far main (
unsigned char *dest, /* pointer to destination pointer */
unsigned int destlen, /* amount of output space */
unsigned char *source, /* pointer to source data pointer */
unsigned int sourcelen)
{
struct state s; /* input/output state */
int last, type; /* block information */
int err; /* return value */
/* initialize output state */
s.out = dest;
s.outlen = destlen; /* ignored if dest is NIL */
s.outcnt = 0;
/* initialize input state */
s.in = source;
s.inlen = sourcelen;
s.incnt = 0;
s.bitbuf = 0;
s.bitcnt = 0;
/* process blocks until last block or error */
do {
last = bits(&s, 1); /* one if last block */
type = bits(&s, 2); /* block type 0..3 */
switch(type)
{
case 0:
err = stored(&s);
break;
case 1:
err = fixed(&s);
break;
case 2:
err = dynamic(&s);
break;
default:
err = -1; /* type == 3, invalid */
break;
}
if (err != 0) break; /* return with error */
} while (!last);
return err;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,20 @@
/*
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-2016 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_IntFilter
#define TC_HEADER_Boot_IntFilter
#include "Platform.h"
bool InstallInterruptFilters ();
#endif TC_HEADER_Boot_IntFilter
/*
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-2016 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_IntFilter
#define TC_HEADER_Boot_IntFilter
#include "Platform.h"
bool InstallInterruptFilters ();
#endif TC_HEADER_Boot_IntFilter

View File

@@ -1,202 +1,202 @@
#
# 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-2016 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.
PROJ = BootLoader
.SILENT:
!ifndef MSVC16_ROOT
!error Environment variable MSVC16_ROOT must point to the installation directory of MS Visual C++ 1.5
!endif
ENVPATH = $(PATH)
CC = $(MSVC16_ROOT)\bin\cl.exe
LD = $(MSVC16_ROOT)\bin\link.exe
AFLAGS = /nologo /omf
CFLAGS = /nologo /W3 /Fc /I "$(MSVC16_ROOT)\Include" /I"..\..\.." /I"..\..\..\Common" /I"..\..\..\Crypto"
CFLAGS = $(CFLAGS) /D __int8=char /D __int16=int /D __int32=long /D BOOL=char /D FALSE=0 /D TRUE=1
CFLAGS = $(CFLAGS) /D LITTLE_ENDIAN=1234 /D BYTE_ORDER=1234 /D TC_WINDOWS_BOOT /D TC_MINIMIZE_CODE_SIZE /D TC_NO_COMPILER_INT64
CFLAGS = $(CFLAGS) /D malloc=malloc_NA
LFLAGS = /NOLOGO /ONERROR:NOEXE /NOI /BATCH
OBJDIR = Release
!ifdef RESCUE_DISK
OBJDIR = Rescue
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RESCUE_DISK_MODE
!endif
!ifdef SINGLE_CIPHER
OBJDIR = $(OBJDIR)_$(SINGLE_CIPHER)
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE /D TC_WINDOWS_BOOT_$(SINGLE_CIPHER)
!endif
!ifdef SINGLE_PRF
OBJDIR = $(OBJDIR)_$(SINGLE_PRF)
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_$(SINGLE_PRF)
!else
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RIPEMD160
!endif
OUTDIR = $(OBJDIR)
TARGETEXT = com
TARGETS = $(OUTDIR)\BootDefs.i $(OUTDIR)\BootSector.bin $(OUTDIR)\Decompressor.com
CFLAGS = $(CFLAGS) /AT /Zl /f- /G3 /Oe /Os /Ob1 /OV0 /Gs /Gf /Gy /D NDEBUG
LFLAGS = $(LFLAGS) /NOD /NOE /TINY
OBJS = $(OUTDIR)\BootCrt.obj
LIBS = slibce
!if 1
SRCDIR = ..
!else
SRCDIR = $(MAKEDIR)
!endif
TARGETS = $(TARGETS) $(OUTDIR)\$(PROJ).$(TARGETEXT)
OBJS = $(OBJS) $(OUTDIR)\BootConfig.obj
OBJS = $(OBJS) $(OUTDIR)\BootConsoleIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootDebug.obj
OBJS = $(OBJS) $(OUTDIR)\BootDiskIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootEncryptedIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootMain.obj
OBJS = $(OBJS) $(OUTDIR)\BootMemory.obj
OBJS = $(OBJS) $(OUTDIR)\IntFilter.obj
OBJS = $(OBJS) $(OUTDIR)\Platform.obj
OBJS = $(OBJS) $(OUTDIR)\Crc.obj
OBJS = $(OBJS) $(OUTDIR)\Crypto.obj
OBJS = $(OBJS) $(OUTDIR)\Endian.obj
OBJS = $(OBJS) $(OUTDIR)\Pkcs5.obj
OBJS = $(OBJS) $(OUTDIR)\Volumes.obj
OBJS = $(OBJS) $(OUTDIR)\Xts.obj
!if "$(SINGLE_PRF)" == "SHA2"
OBJS = $(OBJS) $(OUTDIR)\Sha2Small.obj
!else
OBJS = $(OBJS) $(OUTDIR)\Rmd160.obj
!endif
!if !DEFINED (SINGLE_CIPHER)
OBJS = $(OBJS) $(OUTDIR)\AesSmall.obj
!else if "$(SINGLE_CIPHER)" == "AES"
OBJS = $(OBJS) $(OUTDIR)\Aes_hw_cpu.obj
OBJS = $(OBJS) $(OUTDIR)\AesSmall_x86.obj
OBJS = $(OBJS) $(OUTDIR)\Aestab.obj
!endif
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "SERPENT"
OBJS = $(OBJS) $(OUTDIR)\Serpent.obj
!endif
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "TWOFISH"
OBJS = $(OBJS) $(OUTDIR)\Twofish.obj
!endif
all: env $(TARGETS)
env:
set INCLUDE=.
set LIB=.
set LIBPATH=.
clean:
-del /q /s $(OBJDIR) >NUL:
.asm{$(OUTDIR)}.obj:
cd $(OBJDIR)
$(AS) $(AFLAGS) /c "$(SRCDIR)\$<"
cd ..
{..\..\Crypto}.asm{$(OUTDIR)}.obj:
cd $(OBJDIR)
echo $(<F)
nasm.exe -Xvc -f obj -Ox -o "$(<B).obj" -l "$(<B).lst" "$(SRCDIR)\$<"
cd ..
{..\..\Crypto}.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
{..\..\Common}.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
.cpp{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
$(OUTDIR)\BootDefs.i: BootDefs.h
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /D TC_ASM_PREPROCESS /P /EP "$(SRCDIR)\BootDefs.h"
set PATH=$(ENVPATH)
cd ..
$(OUTDIR)\BootSector.bin: $(OUTDIR)\BootSector.obj
cd $(OBJDIR)
$(LD) $(LFLAGS) BootSector.obj,BootSector.bin,,,, >NUL:
-dd.exe conv=notrunc bs=512 if=BootSector.bin of=$(PROJ).flp 2>NUL:
cd ..
$(OUTDIR)\Decompressor.com: $(OUTDIR)\BootCrt.obj $(OUTDIR)\Decompressor.obj
cd $(OBJDIR)
$(LD) $(LFLAGS) BootCrt.obj Decompressor.obj,Decompressor.com,Decompressor.map,$(MSVC16_ROOT)\lib\+slibce,,
-dd.exe conv=notrunc,sync bs=512 seek=1 if=Decompressor.com of=$(PROJ).flp 2>NUL:
cd ..
$(OUTDIR)\$(PROJ).$(TARGETEXT): $(OBJS)
@echo Linking...
cd $(OBJDIR)
echo >NUL: @<<$(PROJ).crf2
$(PROJ).$(TARGETEXT)
$(PROJ).map
$(MSVC16_ROOT)\lib\+
$(LIBS)
;
<<
del $(PROJ).crf >NUL: 2>NUL:
for %F in ($(**F)) do @echo %F + >>$(PROJ).crf
type $(PROJ).crf2 >>$(PROJ).crf
$(LD) $(LFLAGS) @$(PROJ).crf
del $(PROJ).crf $(PROJ).crf2
# Compress the Rescue Disk botloader for Cascades and Serpent since it is too big (size > 31232 bytes)
!if DEFINED(RESCUE_DISK) && (!DEFINED (SINGLE_CIPHER) || ("$(SINGLE_CIPHER)" == "SERPENT"))
upx $(PROJ).$(TARGETEXT)
!endif
gzip.exe -c -n --best $(PROJ).$(TARGETEXT) >$(PROJ).$(TARGETEXT).gz
-dd.exe conv=notrunc,sync bs=512 seek=5 if=$(PROJ).$(TARGETEXT).gz of=$(PROJ).flp 2>NUL:
cd ..
#
# 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-2016 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.
PROJ = BootLoader
.SILENT:
!ifndef MSVC16_ROOT
!error Environment variable MSVC16_ROOT must point to the installation directory of MS Visual C++ 1.5
!endif
ENVPATH = $(PATH)
CC = $(MSVC16_ROOT)\bin\cl.exe
LD = $(MSVC16_ROOT)\bin\link.exe
AFLAGS = /nologo /omf
CFLAGS = /nologo /W3 /Fc /I "$(MSVC16_ROOT)\Include" /I"..\..\.." /I"..\..\..\Common" /I"..\..\..\Crypto"
CFLAGS = $(CFLAGS) /D __int8=char /D __int16=int /D __int32=long /D BOOL=char /D FALSE=0 /D TRUE=1
CFLAGS = $(CFLAGS) /D LITTLE_ENDIAN=1234 /D BYTE_ORDER=1234 /D TC_WINDOWS_BOOT /D TC_MINIMIZE_CODE_SIZE /D TC_NO_COMPILER_INT64
CFLAGS = $(CFLAGS) /D malloc=malloc_NA
LFLAGS = /NOLOGO /ONERROR:NOEXE /NOI /BATCH
OBJDIR = Release
!ifdef RESCUE_DISK
OBJDIR = Rescue
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RESCUE_DISK_MODE
!endif
!ifdef SINGLE_CIPHER
OBJDIR = $(OBJDIR)_$(SINGLE_CIPHER)
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE /D TC_WINDOWS_BOOT_$(SINGLE_CIPHER)
!endif
!ifdef SINGLE_PRF
OBJDIR = $(OBJDIR)_$(SINGLE_PRF)
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_$(SINGLE_PRF)
!else
CFLAGS = $(CFLAGS) /D TC_WINDOWS_BOOT_RIPEMD160
!endif
OUTDIR = $(OBJDIR)
TARGETEXT = com
TARGETS = $(OUTDIR)\BootDefs.i $(OUTDIR)\BootSector.bin $(OUTDIR)\Decompressor.com
CFLAGS = $(CFLAGS) /AT /Zl /f- /G3 /Oe /Os /Ob1 /OV0 /Gs /Gf /Gy /D NDEBUG
LFLAGS = $(LFLAGS) /NOD /NOE /TINY
OBJS = $(OUTDIR)\BootCrt.obj
LIBS = slibce
!if 1
SRCDIR = ..
!else
SRCDIR = $(MAKEDIR)
!endif
TARGETS = $(TARGETS) $(OUTDIR)\$(PROJ).$(TARGETEXT)
OBJS = $(OBJS) $(OUTDIR)\BootConfig.obj
OBJS = $(OBJS) $(OUTDIR)\BootConsoleIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootDebug.obj
OBJS = $(OBJS) $(OUTDIR)\BootDiskIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootEncryptedIo.obj
OBJS = $(OBJS) $(OUTDIR)\BootMain.obj
OBJS = $(OBJS) $(OUTDIR)\BootMemory.obj
OBJS = $(OBJS) $(OUTDIR)\IntFilter.obj
OBJS = $(OBJS) $(OUTDIR)\Platform.obj
OBJS = $(OBJS) $(OUTDIR)\Crc.obj
OBJS = $(OBJS) $(OUTDIR)\Crypto.obj
OBJS = $(OBJS) $(OUTDIR)\Endian.obj
OBJS = $(OBJS) $(OUTDIR)\Pkcs5.obj
OBJS = $(OBJS) $(OUTDIR)\Volumes.obj
OBJS = $(OBJS) $(OUTDIR)\Xts.obj
!if "$(SINGLE_PRF)" == "SHA2"
OBJS = $(OBJS) $(OUTDIR)\Sha2Small.obj
!else
OBJS = $(OBJS) $(OUTDIR)\Rmd160.obj
!endif
!if !DEFINED (SINGLE_CIPHER)
OBJS = $(OBJS) $(OUTDIR)\AesSmall.obj
!else if "$(SINGLE_CIPHER)" == "AES"
OBJS = $(OBJS) $(OUTDIR)\Aes_hw_cpu.obj
OBJS = $(OBJS) $(OUTDIR)\AesSmall_x86.obj
OBJS = $(OBJS) $(OUTDIR)\Aestab.obj
!endif
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "SERPENT"
OBJS = $(OBJS) $(OUTDIR)\Serpent.obj
!endif
!if !DEFINED (SINGLE_CIPHER) || "$(SINGLE_CIPHER)" == "TWOFISH"
OBJS = $(OBJS) $(OUTDIR)\Twofish.obj
!endif
all: env $(TARGETS)
env:
set INCLUDE=.
set LIB=.
set LIBPATH=.
clean:
-del /q /s $(OBJDIR) >NUL:
.asm{$(OUTDIR)}.obj:
cd $(OBJDIR)
$(AS) $(AFLAGS) /c "$(SRCDIR)\$<"
cd ..
{..\..\Crypto}.asm{$(OUTDIR)}.obj:
cd $(OBJDIR)
echo $(<F)
nasm.exe -Xvc -f obj -Ox -o "$(<B).obj" -l "$(<B).lst" "$(SRCDIR)\$<"
cd ..
{..\..\Crypto}.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
{..\..\Common}.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
.c{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
.cpp{$(OUTDIR)}.obj:
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /c "$(SRCDIR)\$<"
set PATH=$(ENVPATH)
cd ..
$(OUTDIR)\BootDefs.i: BootDefs.h
cd $(OBJDIR)
set PATH=.
$(CC) $(CFLAGS) /D TC_ASM_PREPROCESS /P /EP "$(SRCDIR)\BootDefs.h"
set PATH=$(ENVPATH)
cd ..
$(OUTDIR)\BootSector.bin: $(OUTDIR)\BootSector.obj
cd $(OBJDIR)
$(LD) $(LFLAGS) BootSector.obj,BootSector.bin,,,, >NUL:
-dd.exe conv=notrunc bs=512 if=BootSector.bin of=$(PROJ).flp 2>NUL:
cd ..
$(OUTDIR)\Decompressor.com: $(OUTDIR)\BootCrt.obj $(OUTDIR)\Decompressor.obj
cd $(OBJDIR)
$(LD) $(LFLAGS) BootCrt.obj Decompressor.obj,Decompressor.com,Decompressor.map,$(MSVC16_ROOT)\lib\+slibce,,
-dd.exe conv=notrunc,sync bs=512 seek=1 if=Decompressor.com of=$(PROJ).flp 2>NUL:
cd ..
$(OUTDIR)\$(PROJ).$(TARGETEXT): $(OBJS)
@echo Linking...
cd $(OBJDIR)
echo >NUL: @<<$(PROJ).crf2
$(PROJ).$(TARGETEXT)
$(PROJ).map
$(MSVC16_ROOT)\lib\+
$(LIBS)
;
<<
del $(PROJ).crf >NUL: 2>NUL:
for %F in ($(**F)) do @echo %F + >>$(PROJ).crf
type $(PROJ).crf2 >>$(PROJ).crf
$(LD) $(LFLAGS) @$(PROJ).crf
del $(PROJ).crf $(PROJ).crf2
# Compress the Rescue Disk botloader for Cascades and Serpent since it is too big (size > 31232 bytes)
!if DEFINED(RESCUE_DISK) && (!DEFINED (SINGLE_CIPHER) || ("$(SINGLE_CIPHER)" == "SERPENT"))
upx $(PROJ).$(TARGETEXT)
!endif
gzip.exe -c -n --best $(PROJ).$(TARGETEXT) >$(PROJ).$(TARGETEXT).gz
-dd.exe conv=notrunc,sync bs=512 seek=5 if=$(PROJ).$(TARGETEXT).gz of=$(PROJ).flp 2>NUL:
cd ..

View File

@@ -1,230 +1,230 @@
/*
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-2016 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 "BootConsoleIo.h"
uint64 operator+ (const uint64 &a, const uint64 &b)
{
int carry = 0;
uint64 r;
r.LowPart = a.LowPart + b.LowPart;
__asm
{
jnc nocarry
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, const uint64 &b)
{
int carry = 0;
uint64 r;
r.LowPart = a.LowPart - b.LowPart;
__asm
{
jnc nocarry
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)
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;
}
bool operator> (const uint64 &a, const uint64 &b)
{
return (a.HighPart > b.HighPart) || (a.HighPart == b.HighPart && a.LowPart > b.LowPart);
}
bool operator< (const uint64 &a, const uint64 &b)
{
return (a.HighPart < b.HighPart) || (a.HighPart == b.HighPart && a.LowPart < b.LowPart);
}
bool operator>= (const uint64 &a, const uint64 &b)
{
return a > b || a == b;
}
bool operator<= (const uint64 &a, const uint64 &b)
{
return a < b || a == b;
}
bool TestInt64 ()
{
uint64 a, b, c;
a.HighPart = 0x00112233UL;
a.LowPart = 0xabcd1234UL;
b.HighPart = 0x00ffeeddUL;
b.LowPart = 0xffffFFFFUL;
a += b;
a -= b;
++a;
b = b + (uint32) 1UL;
c = (a - ((a + b) >> 32) - (uint32) 1UL);
if (c.HighPart != 0x112233UL || c.LowPart != 0xAABC0123UL)
return false;
c = c << 9;
return c.HighPart == 0x22446755UL && c.LowPart == 0x78024600UL;
}
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize)
{
__asm
{
push es
mov si, ss:source
mov es, ss:destSegment
mov di, ss:destOffset
mov cx, ss:blockSize
cld
rep movsb
pop es
}
}
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize)
{
__asm
{
push ds
push es
mov ax, ds
mov es, ax
mov di, ss:destination
mov si, ss:sourceOffset
mov cx, ss:blockSize
mov ds, ss:sourceSegment
cld
rep movsb
pop es
pop ds
}
}
void EraseMemory (void *memory, int size)
{
memset (memory, 0, size);
}
uint32 GetLinearAddress (uint16 segment, uint16 offset)
{
return (uint32 (segment) << 4) + offset;
}
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2)
{
uint64 end1 = start1 + length1 - 1UL;
uint64 intersectEnd = (end1 <= end2) ? end1 : end2;
uint64 intersectStart = (start1 >= start2) ? start1 : start2;
if (intersectStart > intersectEnd)
return false;
return (intersectEnd + 1UL - intersectStart).LowPart != 0;
}
void ThrowFatalException (int line)
{
PrintChar ('#'); Print (line);
while (1);
}
/*
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-2016 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 "BootConsoleIo.h"
uint64 operator+ (const uint64 &a, const uint64 &b)
{
int carry = 0;
uint64 r;
r.LowPart = a.LowPart + b.LowPart;
__asm
{
jnc nocarry
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, const uint64 &b)
{
int carry = 0;
uint64 r;
r.LowPart = a.LowPart - b.LowPart;
__asm
{
jnc nocarry
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)
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;
}
bool operator> (const uint64 &a, const uint64 &b)
{
return (a.HighPart > b.HighPart) || (a.HighPart == b.HighPart && a.LowPart > b.LowPart);
}
bool operator< (const uint64 &a, const uint64 &b)
{
return (a.HighPart < b.HighPart) || (a.HighPart == b.HighPart && a.LowPart < b.LowPart);
}
bool operator>= (const uint64 &a, const uint64 &b)
{
return a > b || a == b;
}
bool operator<= (const uint64 &a, const uint64 &b)
{
return a < b || a == b;
}
bool TestInt64 ()
{
uint64 a, b, c;
a.HighPart = 0x00112233UL;
a.LowPart = 0xabcd1234UL;
b.HighPart = 0x00ffeeddUL;
b.LowPart = 0xffffFFFFUL;
a += b;
a -= b;
++a;
b = b + (uint32) 1UL;
c = (a - ((a + b) >> 32) - (uint32) 1UL);
if (c.HighPart != 0x112233UL || c.LowPart != 0xAABC0123UL)
return false;
c = c << 9;
return c.HighPart == 0x22446755UL && c.LowPart == 0x78024600UL;
}
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize)
{
__asm
{
push es
mov si, ss:source
mov es, ss:destSegment
mov di, ss:destOffset
mov cx, ss:blockSize
cld
rep movsb
pop es
}
}
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize)
{
__asm
{
push ds
push es
mov ax, ds
mov es, ax
mov di, ss:destination
mov si, ss:sourceOffset
mov cx, ss:blockSize
mov ds, ss:sourceSegment
cld
rep movsb
pop es
pop ds
}
}
void EraseMemory (void *memory, int size)
{
memset (memory, 0, size);
}
uint32 GetLinearAddress (uint16 segment, uint16 offset)
{
return (uint32 (segment) << 4) + offset;
}
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2)
{
uint64 end1 = start1 + length1 - 1UL;
uint64 intersectEnd = (end1 <= end2) ? end1 : end2;
uint64 intersectStart = (start1 >= start2) ? start1 : start2;
if (intersectStart > intersectEnd)
return false;
return (intersectEnd + 1UL - intersectStart).LowPart != 0;
}
void ThrowFatalException (int line)
{
PrintChar ('#'); Print (line);
while (1);
}

View File

@@ -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-2016 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_Platform
#define TC_HEADER_Boot_Platform
#pragma warning (disable: 4018 4102 4704 4769)
#include "TCdefs.h"
#include <memory.h>
typedef char bool;
#define false 0
#define true 1
#define nullptr 0
#define NULL 0
typedef UINT64_STRUCT uint64;
#define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0]))
#define TC_TO_STRING2(n) #n
#define TC_TO_STRING(n) TC_TO_STRING2(n)
#define TC_X86_CARRY_FLAG 0x1
#define TC_ASM_EMIT(A,B) __asm _emit 0x##A __asm _emit 0x##B
#define TC_ASM_EMIT3(A,B,C) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C
#define TC_ASM_EMIT4(A,B,C,D) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C __asm _emit 0x##D
#define TC_ASM_MOV_EAX_DI TC_ASM_EMIT3 (66, 8B, 05)
#define TC_ASM_MOV_EBX_DI TC_ASM_EMIT3 (66, 8B, 1D)
#define TC_ASM_MOV_ECX_DI TC_ASM_EMIT3 (66, 8B, 0D)
#define TC_ASM_MOV_EDX_DI TC_ASM_EMIT3 (66, 8B, 15)
#define TC_ASM_MOV_DI_EAX TC_ASM_EMIT3 (66, 89, 05)
#define TC_ASM_MOV_DI_EBX TC_ASM_EMIT3 (66, 89, 1D)
#define TC_ASM_MOV_DI_ECX TC_ASM_EMIT3 (66, 89, 0D)
#define TC_ASM_MOV_DI_EDX TC_ASM_EMIT3 (66, 89, 15)
#pragma pack(1)
struct Registers
{
uint16 Flags;
union
{
uint32 EAX;
struct { uint16 AX; uint16 EAXH; };
};
union
{
uint32 EBX;
struct { uint16 BX; uint16 EBXH; };
};
union
{
uint32 ECX;
struct { uint16 CX; uint16 ECXH; };
};
union
{
uint32 EDX;
struct { uint16 DX; uint16 EDXH; };
};
uint16 DI;
uint16 SI;
uint16 DS;
uint16 ES;
uint16 SS;
};
#pragma pack()
uint64 operator+ (const uint64 &a, const uint64 &b);
uint64 operator+ (const uint64 &a, uint32 b);
uint64 &operator+= (uint64 &a, const uint64 &b);
uint64 operator- (const uint64 &a, const uint64 &b);
uint64 operator- (const uint64 &a, uint32 b);
uint64 &operator-= (uint64 &a, const uint64 &b);
uint64 operator>> (const uint64 &a, int shiftCount);
uint64 operator<< (const uint64 &a, int shiftCount);
uint64 &operator++ (uint64 &a);
bool operator== (const uint64 &a, const uint64 &b);
bool operator> (const uint64 &a, const uint64 &b);
bool operator< (const uint64 &a, const uint64 &b);
bool operator>= (const uint64 &a, const uint64 &b);
bool operator<= (const uint64 &a, const uint64 &b);
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize);
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize);
extern "C" void EraseMemory (void *memory, int size);
uint32 GetLinearAddress (uint16 segment, uint16 offset);
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2);
bool TestInt64 ();
extern "C" void ThrowFatalException (int line);
#endif // TC_HEADER_Boot_Platform
/*
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-2016 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_Platform
#define TC_HEADER_Boot_Platform
#pragma warning (disable: 4018 4102 4704 4769)
#include "TCdefs.h"
#include <memory.h>
typedef char bool;
#define false 0
#define true 1
#define nullptr 0
#define NULL 0
typedef UINT64_STRUCT uint64;
#define array_capacity(arr) (sizeof (arr) / sizeof ((arr)[0]))
#define TC_TO_STRING2(n) #n
#define TC_TO_STRING(n) TC_TO_STRING2(n)
#define TC_X86_CARRY_FLAG 0x1
#define TC_ASM_EMIT(A,B) __asm _emit 0x##A __asm _emit 0x##B
#define TC_ASM_EMIT3(A,B,C) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C
#define TC_ASM_EMIT4(A,B,C,D) __asm _emit 0x##A __asm _emit 0x##B __asm _emit 0x##C __asm _emit 0x##D
#define TC_ASM_MOV_EAX_DI TC_ASM_EMIT3 (66, 8B, 05)
#define TC_ASM_MOV_EBX_DI TC_ASM_EMIT3 (66, 8B, 1D)
#define TC_ASM_MOV_ECX_DI TC_ASM_EMIT3 (66, 8B, 0D)
#define TC_ASM_MOV_EDX_DI TC_ASM_EMIT3 (66, 8B, 15)
#define TC_ASM_MOV_DI_EAX TC_ASM_EMIT3 (66, 89, 05)
#define TC_ASM_MOV_DI_EBX TC_ASM_EMIT3 (66, 89, 1D)
#define TC_ASM_MOV_DI_ECX TC_ASM_EMIT3 (66, 89, 0D)
#define TC_ASM_MOV_DI_EDX TC_ASM_EMIT3 (66, 89, 15)
#pragma pack(1)
struct Registers
{
uint16 Flags;
union
{
uint32 EAX;
struct { uint16 AX; uint16 EAXH; };
};
union
{
uint32 EBX;
struct { uint16 BX; uint16 EBXH; };
};
union
{
uint32 ECX;
struct { uint16 CX; uint16 ECXH; };
};
union
{
uint32 EDX;
struct { uint16 DX; uint16 EDXH; };
};
uint16 DI;
uint16 SI;
uint16 DS;
uint16 ES;
uint16 SS;
};
#pragma pack()
uint64 operator+ (const uint64 &a, const uint64 &b);
uint64 operator+ (const uint64 &a, uint32 b);
uint64 &operator+= (uint64 &a, const uint64 &b);
uint64 operator- (const uint64 &a, const uint64 &b);
uint64 operator- (const uint64 &a, uint32 b);
uint64 &operator-= (uint64 &a, const uint64 &b);
uint64 operator>> (const uint64 &a, int shiftCount);
uint64 operator<< (const uint64 &a, int shiftCount);
uint64 &operator++ (uint64 &a);
bool operator== (const uint64 &a, const uint64 &b);
bool operator> (const uint64 &a, const uint64 &b);
bool operator< (const uint64 &a, const uint64 &b);
bool operator>= (const uint64 &a, const uint64 &b);
bool operator<= (const uint64 &a, const uint64 &b);
void CopyMemory (void *source, uint16 destSegment, uint16 destOffset, uint16 blockSize);
void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, void *destination, uint16 blockSize);
extern "C" void EraseMemory (void *memory, int size);
uint32 GetLinearAddress (uint16 segment, uint16 offset);
bool RegionsIntersect (const uint64 &start1, uint32 length1, const uint64 &start2, const uint64 &end2);
bool TestInt64 ();
extern "C" void ThrowFatalException (int line);
#endif // TC_HEADER_Boot_Platform