--- truecrypt/boot/windows/platform.cpp 2018/04/24 16:49:04 1.1 +++ truecrypt/boot/windows/platform.cpp 2018/04/24 16:55:29 1.1.1.4 @@ -1,12 +1,13 @@ /* Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. - Governed by the TrueCrypt License 2.4 the full text of which is contained + Governed by the TrueCrypt License 2.5 the full text of which is contained in the file License.txt included in TrueCrypt binary and source code distribution packages. */ #include "Platform.h" +#include "BootConsoleIo.h" uint64 operator+ (const uint64 &a, const uint64 &b) @@ -35,6 +36,11 @@ uint64 operator+ (const uint64 &a, uint3 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; @@ -61,6 +67,11 @@ uint64 operator- (const uint64 &a, uint3 return a - b64; } +uint64 &operator-= (uint64 &a, const uint64 &b) +{ + return a = a - b; +} + uint64 operator>> (const uint64 &a, int shiftCount) { uint64 r = a; @@ -83,14 +94,18 @@ uint64 operator<< (const uint64 &a, int uint64 r = a; while (shiftCount--) - r = r + r; + r += r; return r; } uint64 &operator++ (uint64 &a) { - return a = a + 1; + uint64 b; + b.HighPart = 0; + b.LowPart = 1; + + return a += b; } bool operator== (const uint64 &a, const uint64 &b) @@ -127,7 +142,11 @@ bool TestInt64 () b.HighPart = 0x00ffeeddUL; b.LowPart = 0xffffFFFFUL; + a += b; + a -= b; + ++a; + b = b + (uint32) 1UL; c = (a - ((a + b) >> 32) - (uint32) 1UL); @@ -139,22 +158,6 @@ bool TestInt64 () } -void Jump (uint16 jumpSegment, uint16 jumpOffset, byte dlRegister) -{ - uint32 addr = (uint32 (jumpSegment) << 16) | jumpOffset; - __asm - { - mov dl, dlRegister - mov ax, jumpSegment - mov ds, ax - mov es, ax - mov ss, ax - mov sp, 0xffff - jmp cs:addr - } -} - - void CopyMemory (byte *source, uint16 destSegment, uint16 destOffset, uint16 blockSize) { __asm @@ -191,7 +194,33 @@ void CopyMemory (uint16 sourceSegment, u } +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); +}