diff options
Diffstat (limited to 'src/Platform')
62 files changed, 237 insertions, 157 deletions
diff --git a/src/Platform/Buffer.cpp b/src/Platform/Buffer.cpp index a53fd3da..5829b1d9 100644 --- a/src/Platform/Buffer.cpp +++ b/src/Platform/Buffer.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -43,9 +43,9 @@ namespace VeraCrypt } try { - DataPtr = static_cast<byte *> ((alignment > 0)? Memory::AllocateAligned (size, alignment) : Memory::Allocate (size)); + DataPtr = static_cast<uint8 *> ((alignment > 0)? Memory::AllocateAligned (size, alignment) : Memory::Allocate (size)); DataSize = size; DataAlignment = alignment; } catch (...) @@ -76,9 +76,9 @@ namespace VeraCrypt void Buffer::Erase () { if (DataSize > 0) - Memory::Erase (DataPtr, DataSize); + burn (DataPtr, DataSize); } void Buffer::Free () { diff --git a/src/Platform/Buffer.h b/src/Platform/Buffer.h index 797cd7ff..a1eb0918 100644 --- a/src/Platform/Buffer.h +++ b/src/Platform/Buffer.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -23,22 +23,22 @@ namespace VeraCrypt { public: ConstBufferPtr () : DataPtr (nullptr), DataSize (0) { } - ConstBufferPtr (const byte *data, size_t size) + ConstBufferPtr (const uint8 *data, size_t size) : DataPtr (data), DataSize (size) { } virtual ~ConstBufferPtr () { } - operator const byte * () const { return DataPtr; } + operator const uint8 * () const { return DataPtr; } bool IsDataEqual (const ConstBufferPtr &other) const { return Memory::Compare (DataPtr, DataSize, other.DataPtr, other.DataSize) == 0; } - const byte *Get () const { return DataPtr; } + const uint8 *Get () const { return DataPtr; } ConstBufferPtr GetRange (size_t offset, size_t size) const; - void Set (const byte *data, size_t size) { DataPtr = data; DataSize = size; } + void Set (const uint8 *data, size_t size) { DataPtr = data; DataSize = size; } size_t Size () const { return DataSize; } protected: - const byte *DataPtr; + const uint8 *DataPtr; size_t DataSize; }; @@ -46,25 +46,25 @@ namespace VeraCrypt { public: BufferPtr () : DataPtr (nullptr), DataSize (0) { } - BufferPtr (byte *data, size_t size) + BufferPtr (uint8 *data, size_t size) : DataPtr (data), DataSize (size) { } virtual ~BufferPtr () { } - operator byte * () const { return DataPtr; } + operator uint8 * () const { return DataPtr; } void CopyFrom (const ConstBufferPtr &bufferPtr) const; void Erase () const { Zero(); } - byte *Get () const { return DataPtr; } + uint8 *Get () const { return DataPtr; } BufferPtr GetRange (size_t offset, size_t size) const; - void Set (byte *data, size_t size) { DataPtr = data; DataSize = size; } + void Set (uint8 *data, size_t size) { DataPtr = data; DataSize = size; } size_t Size () const { return DataSize; } void Zero () const { Memory::Zero (DataPtr, DataSize); } operator ConstBufferPtr () const { return ConstBufferPtr (DataPtr, DataSize); } protected: - byte *DataPtr; + uint8 *DataPtr; size_t DataSize; }; class Buffer @@ -76,23 +76,23 @@ namespace VeraCrypt virtual ~Buffer (); virtual void Allocate (size_t size, size_t alignment = 0); virtual void CopyFrom (const ConstBufferPtr &bufferPtr, size_t alignment = 0); - virtual byte *Ptr () const { return DataPtr; } + virtual uint8 *Ptr () const { return DataPtr; } virtual void Erase (); virtual void Free (); virtual BufferPtr GetRange (size_t offset, size_t size) const; virtual size_t Size () const { return DataSize; } virtual size_t Alignment () const { return DataAlignment; } virtual bool IsAllocated () const { return DataSize != 0; } virtual void Zero (); - virtual operator byte * () const { return DataPtr; } + virtual operator uint8 * () const { return DataPtr; } virtual operator BufferPtr () const { return BufferPtr (DataPtr, DataSize); } virtual operator ConstBufferPtr () const { return ConstBufferPtr (DataPtr, DataSize); } protected: - byte *DataPtr; + uint8 *DataPtr; size_t DataSize; size_t DataAlignment; private: diff --git a/src/Platform/Directory.h b/src/Platform/Directory.h index 89b91ad3..b960db0e 100644 --- a/src/Platform/Directory.h +++ b/src/Platform/Directory.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Event.cpp b/src/Platform/Event.cpp index bfa0da7c..86dcdde1 100644 --- a/src/Platform/Event.cpp +++ b/src/Platform/Event.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Event.h b/src/Platform/Event.h index 5aef3621..7d1cc2e4 100644 --- a/src/Platform/Event.h +++ b/src/Platform/Event.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Exception.cpp b/src/Platform/Exception.cpp index 40739edd..7bce461f 100644 --- a/src/Platform/Exception.cpp +++ b/src/Platform/Exception.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Exception.h b/src/Platform/Exception.h index 0b3aab43..36981a74 100644 --- a/src/Platform/Exception.h +++ b/src/Platform/Exception.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -81,8 +81,9 @@ namespace VeraCrypt TC_EXCEPTION_NODECL (Exception); \ TC_EXCEPTION_NODECL (ExecutedProcessFailed); \ TC_EXCEPTION (AlreadyInitialized); \ TC_EXCEPTION (AssertionFailed); \ + TC_EXCEPTION (DeviceSectorSizeMismatch); \ TC_EXCEPTION (ExternalException); \ TC_EXCEPTION (InsufficientData); \ TC_EXCEPTION (NotApplicable); \ TC_EXCEPTION (NotImplemented); \ @@ -90,13 +91,12 @@ namespace VeraCrypt TC_EXCEPTION (ParameterIncorrect); \ TC_EXCEPTION (ParameterTooLarge); \ TC_EXCEPTION (PartitionDeviceRequired); \ TC_EXCEPTION (StringConversionFailed); \ + TC_EXCEPTION (TerminalNotFound); \ TC_EXCEPTION (TestFailed); \ TC_EXCEPTION (TimeOut); \ TC_EXCEPTION (UnknownException); \ - TC_EXCEPTION (UnsupportedAlgoInTrueCryptMode); \ - TC_EXCEPTION (UnsupportedTrueCryptFormat); \ TC_EXCEPTION (UserAbort) TC_EXCEPTION_SET; diff --git a/src/Platform/File.h b/src/Platform/File.h index 5bb25a01..a8befe38 100644 --- a/src/Platform/File.h +++ b/src/Platform/File.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -53,9 +53,13 @@ namespace VeraCrypt #else typedef int SystemFileHandleType; #endif - File () : FileIsOpen (false), SharedHandle (false) { } + File () : FileIsOpen (false), mFileOpenFlags (FlagsNone), SharedHandle (false), FileHandle (0) +#ifndef TC_WINDOWS + ,AccTime(0), ModTime (0) +#endif + { } virtual ~File (); void AssignSystemHandle (SystemFileHandleType openFileHandle, bool sharedHandle = true) { diff --git a/src/Platform/FileCommon.cpp b/src/Platform/FileCommon.cpp index a5331266..11d23dd2 100644 --- a/src/Platform/FileCommon.cpp +++ b/src/Platform/FileCommon.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/FileStream.h b/src/Platform/FileStream.h index e64160e5..66df1999 100644 --- a/src/Platform/FileStream.h +++ b/src/Platform/FileStream.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -42,9 +42,9 @@ namespace VeraCrypt string str; vector <char> buffer (4096); uint64 len; - while ((len = DataFile->Read (BufferPtr (reinterpret_cast <byte *> (&buffer[0]), buffer.size()))) > 0) + while ((len = DataFile->Read (BufferPtr (reinterpret_cast <uint8 *> (&buffer[0]), buffer.size()))) > 0) str.insert (str.end(), buffer.begin(), buffer.begin() + static_cast <int> (len)); return str; } diff --git a/src/Platform/FilesystemPath.h b/src/Platform/FilesystemPath.h index 145be3f8..c92f684e 100644 --- a/src/Platform/FilesystemPath.h +++ b/src/Platform/FilesystemPath.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Finally.h b/src/Platform/Finally.h index 7afd9aef..63f07109 100644 --- a/src/Platform/Finally.h +++ b/src/Platform/Finally.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/ForEach.h b/src/Platform/ForEach.h index b16da0cf..a6131ebb 100644 --- a/src/Platform/ForEach.h +++ b/src/Platform/ForEach.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Functor.h b/src/Platform/Functor.h index f17801d6..e23e12dd 100644 --- a/src/Platform/Functor.h +++ b/src/Platform/Functor.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Memory.cpp b/src/Platform/Memory.cpp index 1184d466..c4afed64 100644 --- a/src/Platform/Memory.cpp +++ b/src/Platform/Memory.cpp @@ -3,15 +3,14 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ -#include "Common/Tcdefs.h" #include "Memory.h" #include "Exception.h" #include <stdlib.h> @@ -61,13 +60,8 @@ namespace VeraCrypt assert (memoryDestination != nullptr && memorySource != nullptr); memcpy (memoryDestination, memorySource, size); } - void Memory::Erase (void *memory, size_t size) - { - burn (memory, size); - } - void Memory::Zero (void *memory, size_t size) { memset (memory, 0, size); } diff --git a/src/Platform/Memory.h b/src/Platform/Memory.h index d303c23e..b124022f 100644 --- a/src/Platform/Memory.h +++ b/src/Platform/Memory.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -15,8 +15,9 @@ #include <new> #include <memory.h> #include "PlatformBase.h" +#include "Common/Tcdefs.h" #ifdef TC_WINDOWS # ifndef LITTLE_ENDIAN @@ -75,18 +76,17 @@ namespace VeraCrypt static void *Allocate (size_t size); static void *AllocateAligned (size_t size, size_t alignment); static int Compare (const void *memory1, size_t size1, const void *memory2, size_t size2); static void Copy (void *memoryDestination, const void *memorySource, size_t size); - static void Erase (void *memory, size_t size); static void Free (void *memory); static void FreeAligned (void *memory); static void Zero (void *memory, size_t size); }; class Endian { public: - static byte Big (const byte &x) + static uint8 Big (const uint8 &x) { return x; } @@ -116,9 +116,9 @@ namespace VeraCrypt return MirrorBytes (x); #endif } - static byte Little (const byte &x) + static uint8 Little (const uint8 &x) { return x; } @@ -156,24 +156,24 @@ namespace VeraCrypt } static uint32 MirrorBytes (const uint32 &x) { - uint32 n = (byte) x; - n <<= 8; n |= (byte) (x >> 8); - n <<= 8; n |= (byte) (x >> 16); - return (n << 8) | (byte) (x >> 24); + uint32 n = (uint8) x; + n <<= 8; n |= (uint8) (x >> 8); + n <<= 8; n |= (uint8) (x >> 16); + return (n << 8) | (uint8) (x >> 24); } static uint64 MirrorBytes (const uint64 &x) { - uint64 n = (byte) x; - n <<= 8; n |= (byte) (x >> 8); - n <<= 8; n |= (byte) (x >> 16); - n <<= 8; n |= (byte) (x >> 24); - n <<= 8; n |= (byte) (x >> 32); - n <<= 8; n |= (byte) (x >> 40); - n <<= 8; n |= (byte) (x >> 48); - return (n << 8) | (byte) (x >> 56); + uint64 n = (uint8) x; + n <<= 8; n |= (uint8) (x >> 8); + n <<= 8; n |= (uint8) (x >> 16); + n <<= 8; n |= (uint8) (x >> 24); + n <<= 8; n |= (uint8) (x >> 32); + n <<= 8; n |= (uint8) (x >> 40); + n <<= 8; n |= (uint8) (x >> 48); + return (n << 8) | (uint8) (x >> 56); } }; } diff --git a/src/Platform/MemoryStream.cpp b/src/Platform/MemoryStream.cpp index ed888f4f..1bd090b9 100644 --- a/src/Platform/MemoryStream.cpp +++ b/src/Platform/MemoryStream.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -17,9 +17,9 @@ namespace VeraCrypt { MemoryStream::MemoryStream (const ConstBufferPtr &data) : ReadPosition (0) { - Data = vector <byte> (data.Size()); + Data = vector <uint8> (data.Size()); BufferPtr (&Data[0], Data.size()).CopyFrom (data); } uint64 MemoryStream::Read (const BufferPtr &buffer) diff --git a/src/Platform/MemoryStream.h b/src/Platform/MemoryStream.h index 0c38f4d2..068e6d6e 100644 --- a/src/Platform/MemoryStream.h +++ b/src/Platform/MemoryStream.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -31,9 +31,9 @@ namespace VeraCrypt virtual void ReadCompleteBuffer (const BufferPtr &buffer); virtual void Write (const ConstBufferPtr &data); protected: - vector <byte> Data; + vector <uint8> Data; size_t ReadPosition; }; } diff --git a/src/Platform/Mutex.h b/src/Platform/Mutex.h index 7289c5ce..83082825 100644 --- a/src/Platform/Mutex.h +++ b/src/Platform/Mutex.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Platform.h b/src/Platform/Platform.h index c1c0834b..6f7f791e 100644 --- a/src/Platform/Platform.h +++ b/src/Platform/Platform.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Platform.make b/src/Platform/Platform.make index 3c04bd1a..0a3c1435 100644 --- a/src/Platform/Platform.make +++ b/src/Platform/Platform.make @@ -3,9 +3,9 @@ # 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX # and are governed by the Apache License 2.0 the full text of which is # contained in the file License.txt included in VeraCrypt binary and source # code distribution packages. # diff --git a/src/Platform/PlatformBase.h b/src/Platform/PlatformBase.h index bbe116f4..e378704c 100644 --- a/src/Platform/PlatformBase.h +++ b/src/Platform/PlatformBase.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -42,9 +42,9 @@ namespace VeraCrypt typedef __int8 int8; typedef __int16 int16; typedef __int32 int32; typedef __int64 int64; - typedef unsigned __int8 byte; + typedef unsigned __int8 uint8; typedef unsigned __int16 uint16; typedef unsigned __int32 uint32; typedef unsigned __int64 uint64; # endif @@ -52,9 +52,9 @@ namespace VeraCrypt typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; - typedef uint8_t byte; + typedef uint8_t uint8; typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; #endif diff --git a/src/Platform/PlatformTest.cpp b/src/Platform/PlatformTest.cpp index f5f5b1cb..9a3faae2 100644 --- a/src/Platform/PlatformTest.cpp +++ b/src/Platform/PlatformTest.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -75,9 +75,9 @@ namespace VeraCrypt wstringList.push_back (wstr + L"3"); Buffer buffer (10); for (size_t i = 0; i < buffer.Size(); i++) - buffer[i] = (byte) i; + buffer[i] = (uint8) i; ser.Serialize ("int32", i32); ser.Serialize ("int64", i64); ser.Serialize ("string", str); @@ -140,9 +140,9 @@ namespace VeraCrypt Buffer dbuffer (10); ser.Deserialize ("buffer", buffer); for (size_t i = 0; i < buffer.Size(); i++) - if (buffer[i] != (byte) i) + if (buffer[i] != (uint8) i) throw TestFailed (SRC_POS); shared_ptr <ExecutedProcessFailed> dex = Serializable::DeserializeNew <ExecutedProcessFailed> (stream); if (!dex @@ -237,9 +237,9 @@ namespace VeraCrypt bool PlatformTest::TestAll () { // Integer types - if (sizeof (byte) != 1 || sizeof (int8) != 1 || sizeof (__int8) != 1) throw TestFailed (SRC_POS); + if (sizeof (uint8) != 1 || sizeof (int8) != 1 || sizeof (__int8) != 1) throw TestFailed (SRC_POS); if (sizeof (uint16) != 2 || sizeof (int16) != 2 || sizeof (__int16) != 2) throw TestFailed (SRC_POS); if (sizeof (uint32) != 4 || sizeof (int32) != 4 || sizeof (__int32) != 4) throw TestFailed (SRC_POS); if (sizeof (uint64) != 8 || sizeof (int64) != 8) throw TestFailed (SRC_POS); diff --git a/src/Platform/PlatformTest.h b/src/Platform/PlatformTest.h index 4b37f3a7..64810f85 100644 --- a/src/Platform/PlatformTest.h +++ b/src/Platform/PlatformTest.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Serializable.cpp b/src/Platform/Serializable.cpp index a9151c0d..4a307e92 100644 --- a/src/Platform/Serializable.cpp +++ b/src/Platform/Serializable.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Serializable.h b/src/Platform/Serializable.h index ef1fbdbe..c92bc170 100644 --- a/src/Platform/Serializable.h +++ b/src/Platform/Serializable.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Serializer.cpp b/src/Platform/Serializer.cpp index 0016694a..6f428b15 100644 --- a/src/Platform/Serializer.cpp +++ b/src/Platform/Serializer.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -20,29 +20,29 @@ namespace VeraCrypt template <typename T> T Serializer::Deserialize () { uint64 size; - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &size, sizeof (size))); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &size, sizeof (size))); if (Endian::Big (size) != sizeof (T)) throw ParameterIncorrect (SRC_POS); T data; - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data, sizeof (data))); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data, sizeof (data))); return Endian::Big (data); } void Serializer::Deserialize (const string &name, bool &data) { ValidateName (name); - data = Deserialize <byte> () == 1; + data = Deserialize <uint8> () == 1; } - void Serializer::Deserialize (const string &name, byte &data) + void Serializer::Deserialize (const string &name, uint8 &data) { ValidateName (name); - data = Deserialize <byte> (); + data = Deserialize <uint8> (); } void Serializer::Deserialize (const string &name, int32 &data) { @@ -126,9 +126,9 @@ namespace VeraCrypt { uint64 size = Deserialize <uint64> (); vector <char> data ((size_t) size); - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data[0], (size_t) size)); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data[0], (size_t) size)); return string (&data[0]); } @@ -154,9 +154,9 @@ namespace VeraCrypt { uint64 size = Deserialize <uint64> (); vector <wchar_t> data ((size_t) size / sizeof (wchar_t)); - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data[0], (size_t) size)); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data[0], (size_t) size)); return wstring (&data[0]); } @@ -181,22 +181,22 @@ namespace VeraCrypt template <typename T> void Serializer::Serialize (T data) { uint64 size = Endian::Big (uint64 (sizeof (data))); - DataStream->Write (ConstBufferPtr ((byte *) &size, sizeof (size))); + DataStream->Write (ConstBufferPtr ((uint8 *) &size, sizeof (size))); data = Endian::Big (data); - DataStream->Write (ConstBufferPtr ((byte *) &data, sizeof (data))); + DataStream->Write (ConstBufferPtr ((uint8 *) &data, sizeof (data))); } void Serializer::Serialize (const string &name, bool data) { SerializeString (name); - byte d = data ? 1 : 0; + uint8 d = data ? 1 : 0; Serialize (d); } - void Serializer::Serialize (const string &name, byte data) + void Serializer::Serialize (const string &name, uint8 data) { SerializeString (name); Serialize (data); } @@ -281,16 +281,16 @@ namespace VeraCrypt void Serializer::SerializeString (const string &data) { Serialize ((uint64) data.size() + 1); - DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), data.size() + 1)); + DataStream->Write (ConstBufferPtr ((uint8 *) (data.data() ? data.data() : data.c_str()), data.size() + 1)); } void Serializer::SerializeWString (const wstring &data) { uint64 size = (data.size() + 1) * sizeof (wchar_t); Serialize (size); - DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), (size_t) size)); + DataStream->Write (ConstBufferPtr ((uint8 *) (data.data() ? data.data() : data.c_str()), (size_t) size)); } void Serializer::ValidateName (const string &name) { diff --git a/src/Platform/Serializer.h b/src/Platform/Serializer.h index 97d3f128..3617a83b 100644 --- a/src/Platform/Serializer.h +++ b/src/Platform/Serializer.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -26,9 +26,9 @@ namespace VeraCrypt Serializer (shared_ptr <Stream> stream) : DataStream (stream) { } virtual ~Serializer () { } void Deserialize (const string &name, bool &data); - void Deserialize (const string &name, byte &data); + void Deserialize (const string &name, uint8 &data); void Deserialize (const string &name, int32 &data); void Deserialize (const string &name, int64 &data); void Deserialize (const string &name, uint32 &data); void Deserialize (const string &name, uint64 &data); @@ -44,9 +44,9 @@ namespace VeraCrypt list <string> DeserializeStringList (const string &name); wstring DeserializeWString (const string &name); list <wstring> DeserializeWStringList (const string &name); void Serialize (const string &name, bool data); - void Serialize (const string &name, byte data); + void Serialize (const string &name, uint8 data); void Serialize (const string &name, const char *data); void Serialize (const string &name, int32 data); void Serialize (const string &name, int64 data); void Serialize (const string &name, uint32 data); diff --git a/src/Platform/SerializerFactory.cpp b/src/Platform/SerializerFactory.cpp index 03bf9482..4c7f4f7e 100644 --- a/src/Platform/SerializerFactory.cpp +++ b/src/Platform/SerializerFactory.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SerializerFactory.h b/src/Platform/SerializerFactory.h index 29a1f655..9c53d309 100644 --- a/src/Platform/SerializerFactory.h +++ b/src/Platform/SerializerFactory.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SharedPtr.h b/src/Platform/SharedPtr.h index 5e865470..f80b2167 100644 --- a/src/Platform/SharedPtr.h +++ b/src/Platform/SharedPtr.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -13,14 +13,27 @@ #ifndef TC_HEADER_Platform_SharedPtr #define TC_HEADER_Platform_SharedPtr #include <stdexcept> +#include <memory> #include "SharedVal.h" #ifdef nullptr namespace VeraCrypt { +#if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) + #define VC_USE_NATIVE_PTR 1 +#endif + +#ifdef VC_USE_NATIVE_PTR + +#define shared_ptr std::shared_ptr +#define make_shared std::make_shared +#define move_ptr std::move + +#else + template <class T> class SharedPtr { public: @@ -156,8 +169,12 @@ namespace VeraCrypt } #define make_shared VeraCrypt::make_shared +#define unique_ptr auto_ptr +#define move_ptr(p) p + +#endif } #endif // nullptr diff --git a/src/Platform/SharedVal.h b/src/Platform/SharedVal.h index b66deaeb..fc64f3f3 100644 --- a/src/Platform/SharedVal.h +++ b/src/Platform/SharedVal.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Stream.h b/src/Platform/Stream.h index ac3d52d1..b9862a50 100644 --- a/src/Platform/Stream.h +++ b/src/Platform/Stream.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/StringConverter.cpp b/src/Platform/StringConverter.cpp index c6934aed..7b3134ee 100644 --- a/src/Platform/StringConverter.cpp +++ b/src/Platform/StringConverter.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -232,9 +232,9 @@ namespace VeraCrypt throw StringConversionFailed (SRC_POS, wstr); str.clear(); str.insert (0, &buf.front(), size); - Memory::Erase (&buf.front(), buf.size()); + burn (&buf.front(), buf.size()); } catch (...) { if (!noThrow) @@ -384,11 +384,11 @@ namespace VeraCrypt return; } BufferPtr ( - (byte *) buffer, + (uint8 *) buffer, bufferSize).CopyFrom ( - ConstBufferPtr ((byte *) (wstring (str).c_str()), + ConstBufferPtr ((uint8 *) (wstring (str).c_str()), (str.length() + 1) * sizeof (wchar_t) ) ); } diff --git a/src/Platform/StringConverter.h b/src/Platform/StringConverter.h index ad391fc4..8756d5ba 100644 --- a/src/Platform/StringConverter.h +++ b/src/Platform/StringConverter.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SyncEvent.h b/src/Platform/SyncEvent.h index aa87cc16..fde6380f 100644 --- a/src/Platform/SyncEvent.h +++ b/src/Platform/SyncEvent.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/System.h b/src/Platform/System.h index 918f264a..5024568f 100644 --- a/src/Platform/System.h +++ b/src/Platform/System.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SystemException.h b/src/Platform/SystemException.h index 7ba48e17..ede3c5cf 100644 --- a/src/Platform/SystemException.h +++ b/src/Platform/SystemException.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SystemInfo.h b/src/Platform/SystemInfo.h index 89d3f448..5e1f63c2 100644 --- a/src/Platform/SystemInfo.h +++ b/src/Platform/SystemInfo.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/SystemLog.h b/src/Platform/SystemLog.h index 72bd920f..cff3f212 100644 --- a/src/Platform/SystemLog.h +++ b/src/Platform/SystemLog.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/TextReader.cpp b/src/Platform/TextReader.cpp index 1f4003e5..bdaf19c2 100644 --- a/src/Platform/TextReader.cpp +++ b/src/Platform/TextReader.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -25,9 +25,9 @@ namespace VeraCrypt { outputString.erase(); char c; - while (InputStream->Read (BufferPtr ((byte *) &c, sizeof (c))) == sizeof (c)) + while (InputStream->Read (BufferPtr ((uint8 *) &c, sizeof (c))) == sizeof (c)) { if (c == '\r') continue; diff --git a/src/Platform/TextReader.h b/src/Platform/TextReader.h index 4acc6a3d..bfeaa524 100644 --- a/src/Platform/TextReader.h +++ b/src/Platform/TextReader.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Thread.h b/src/Platform/Thread.h index 6e8c394f..2f16d2a7 100644 --- a/src/Platform/Thread.h +++ b/src/Platform/Thread.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Time.h b/src/Platform/Time.h index ff606876..c85b363c 100644 --- a/src/Platform/Time.h +++ b/src/Platform/Time.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Directory.cpp b/src/Platform/Unix/Directory.cpp index 9c0590cb..50de000b 100644 --- a/src/Platform/Unix/Directory.cpp +++ b/src/Platform/Unix/Directory.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/File.cpp b/src/Platform/Unix/File.cpp index 5c45dcfc..207efb4e 100644 --- a/src/Platform/Unix/File.cpp +++ b/src/Platform/Unix/File.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -22,8 +22,14 @@ #ifdef TC_BSD #include <sys/disk.h> #endif +#ifdef TC_OPENBSD +#include <sys/ioctl.h> +#include <sys/dkio.h> +#include <sys/disklabel.h> +#endif + #ifdef TC_SOLARIS #include <stropts.h> #include <sys/dkio.h> #endif @@ -31,8 +37,12 @@ #include <sys/file.h> #include <sys/types.h> #include <sys/stat.h> +#ifdef TC_FREEBSD +#include <sys/sysctl.h> +#endif + #include "Platform/File.h" #include "Platform/TextReader.h" namespace VeraCrypt @@ -112,8 +122,13 @@ namespace VeraCrypt u_int sectorSize; throw_sys_sub_if (ioctl (FileHandle, DIOCGSECTORSIZE, §orSize) == -1, wstring (Path)); return (uint32) sectorSize; +#elif defined (TC_OPENBSD) + struct disklabel dl; + throw_sys_sub_if (ioctl (FileHandle, DIOCGPDINFO, &dl) == -1, wstring (Path)); + return (uint32) dl.d_secsize; + #elif defined (TC_SOLARIS) struct dk_minfo mediaInfo; throw_sys_sub_if (ioctl (FileHandle, DKIOCGMEDIAINFO, &mediaInfo) == -1, wstring (Path)); return mediaInfo.dki_lbsize; @@ -145,8 +160,33 @@ namespace VeraCrypt uint64 offset; throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBASE, &offset) == -1, wstring (Path)); return offset; +#elif defined (TC_FREEBSD) + // Get the kernel GEOM configuration + size_t sysctlDataLen, mibLen; + int mib[4]; + mibLen = 4; + throw_sys_sub_if (sysctlnametomib ("kern.geom.conftxt", mib, &mibLen), wstring (Path)); + throw_sys_sub_if (sysctl (mib, mibLen, NULL, &sysctlDataLen, NULL, 0), wstring (Path)); + vector<char> conftxt(sysctlDataLen); + throw_sys_sub_if (sysctl (mib, mibLen, (void *)conftxt.data(), &sysctlDataLen, NULL, 0), wstring (Path)); + + // Find the slice/partition data + string conftxtStr (conftxt.begin(), conftxt.end()); + size_t confLoc = conftxtStr.find (Path.ToBaseName()); + throw_sys_sub_if (confLoc == string::npos, wstring (Path)); + + // Skip to the ninth column + for (int i = 0; i < 6;i++) { + confLoc = conftxtStr.find (" ", confLoc + 1); + throw_sys_sub_if (confLoc == string::npos, wstring (Path)); + } + confLoc++; + size_t end = conftxtStr.find (" ", confLoc); + throw_sys_sub_if (end == string::npos, wstring (Path)); + return StringConverter::ToUInt64 (conftxtStr.substr (confLoc, end - confLoc)); + #elif defined (TC_SOLARIS) struct extpart_info partInfo; throw_sys_sub_if (ioctl (FileHandle, DKIOCEXTPARTINFO, &partInfo) == -1, wstring (Path)); @@ -170,15 +210,30 @@ namespace VeraCrypt uint64 blockCount; throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKSIZE, &blockSize) == -1, wstring (Path)); throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKCOUNT, &blockCount) == -1, wstring (Path)); return blockCount * blockSize; +# elif TC_OPENBSD + struct disklabel dl; + throw_sys_sub_if (ioctl (FileHandle, DIOCGPDINFO, &dl) == -1, wstring (Path)); + return DL_GETDSIZE(&dl); # else uint64 mediaSize; throw_sys_sub_if (ioctl (FileHandle, DIOCGMEDIASIZE, &mediaSize) == -1, wstring (Path)); return mediaSize; # endif } #endif +#ifdef TC_LINUX + // On Linux, try to use BLKGETSIZE64 for devices + if (Path.IsDevice()) + { + uint64 mediaSize; + if (ioctl (FileHandle, BLKGETSIZE64, &mediaSize) != -1) + { + return mediaSize; + } + } +#endif off_t current = lseek (FileHandle, 0, SEEK_CUR); throw_sys_sub_if (current == -1, wstring (Path)); SeekEnd (0); uint64 length = lseek (FileHandle, 0, SEEK_CUR); diff --git a/src/Platform/Unix/FilesystemPath.cpp b/src/Platform/Unix/FilesystemPath.cpp index f5d59f9f..1230c2aa 100644 --- a/src/Platform/Unix/FilesystemPath.cpp +++ b/src/Platform/Unix/FilesystemPath.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -14,8 +14,11 @@ #include "Platform/SystemException.h" #include "Platform/StringConverter.h" #include <stdio.h> #include <sys/stat.h> +#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(__OpenBSD__) +#include <sys/sysmacros.h> +#endif namespace VeraCrypt { void FilesystemPath::Delete () const @@ -71,8 +74,31 @@ namespace VeraCrypt #ifdef TC_LINUX path = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path)); + // If simply removing trailing number didn't produce a valid drive name, try to use sysfs to get the right one + if (!path.IsDevice()) { + struct stat st; + + if(stat (StringConverter::ToSingle (Path).c_str (), &st) == 0) { + const long maxPathLength = pathconf ("/", _PC_PATH_MAX); + + if(maxPathLength != -1) { + string linkPathName ("/sys/dev/block/"); + linkPathName += StringConverter::ToSingle (major (st.st_rdev)) + string (":") + StringConverter::ToSingle (minor (st.st_rdev)); + + vector<char> linkTargetPath(maxPathLength+1); + + if(readlink(linkPathName.c_str (), linkTargetPath.data(), linkTargetPath.size()) != -1) { + const string targetPathStr (linkTargetPath.data()); + const size_t lastSlashPos = targetPathStr.find_last_of ('/'); + const size_t secondLastSlashPos = targetPathStr.find_last_of ('/', lastSlashPos-1); + path = string ("/dev/") + targetPathStr.substr (secondLastSlashPos+1, lastSlashPos-secondLastSlashPos-1); + } + } + } + } + #elif defined (TC_MACOSX) string pathStr = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path)); path = pathStr.substr (0, pathStr.size() - 1); @@ -80,10 +106,13 @@ namespace VeraCrypt #elif defined (TC_FREEBSD) string pathStr = StringConverter::ToSingle (Path); size_t p = pathStr.rfind ("s"); - if (p == string::npos) - throw PartitionDeviceRequired (SRC_POS); + if (p == string::npos) { + p = pathStr.rfind ("p"); + if (p == string::npos) + throw PartitionDeviceRequired (SRC_POS); + } path = pathStr.substr (0, p); #elif defined (TC_SOLARIS) diff --git a/src/Platform/Unix/Mutex.cpp b/src/Platform/Unix/Mutex.cpp index a6b61de6..b69a5c6c 100644 --- a/src/Platform/Unix/Mutex.cpp +++ b/src/Platform/Unix/Mutex.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Pipe.cpp b/src/Platform/Unix/Pipe.cpp index f427ae63..b05acd7c 100644 --- a/src/Platform/Unix/Pipe.cpp +++ b/src/Platform/Unix/Pipe.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Pipe.h b/src/Platform/Unix/Pipe.h index 72af91bd..eb79d9dd 100644 --- a/src/Platform/Unix/Pipe.h +++ b/src/Platform/Unix/Pipe.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Poller.cpp b/src/Platform/Unix/Poller.cpp index 6b845631..25d2ba71 100644 --- a/src/Platform/Unix/Poller.cpp +++ b/src/Platform/Unix/Poller.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Poller.h b/src/Platform/Unix/Poller.h index 054fe75e..a46c0359 100644 --- a/src/Platform/Unix/Poller.h +++ b/src/Platform/Unix/Poller.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Process.cpp b/src/Platform/Unix/Process.cpp index 92a8f478..46b14a1e 100644 --- a/src/Platform/Unix/Process.cpp +++ b/src/Platform/Unix/Process.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -29,9 +29,9 @@ namespace VeraCrypt { string Process::Execute (const string &processName, const list <string> &arguments, int timeOut, ProcessExecFunctor *execFunctor, const Buffer *inputData) { char *args[32]; - if (array_capacity (args) <= arguments.size()) + if (array_capacity (args) <= (arguments.size() + 1)) throw ParameterTooLarge (SRC_POS); #if 0 stringstream dbg; @@ -52,35 +52,15 @@ namespace VeraCrypt { try { int argIndex = 0; - /* Workaround for gcc 5.X issue related to the use of STL (string and list) with muliple fork calls. - * - * The char* pointers retrieved from the elements of parameter "arguments" are no longer valid after - * a second fork is called. "arguments" was created in the parent of the current child process. - * - * The only solution is to copy the elements of "arguments" parameter in a local string array on this - * child process and then use char* pointers retrieved from this local copies before calling fork. - * - * gcc 4.x doesn't suffer from this issue. - * - */ - string argsCopy[array_capacity (args)]; if (!execFunctor) - { - argsCopy[argIndex++] = processName; - } - - foreach (const string &arg, arguments) - { - argsCopy[argIndex++] = arg; - } + args[argIndex++] = const_cast <char*> (processName.c_str()); - for (int i = 0; i < argIndex; i++) + for (list<string>::const_iterator it = arguments.begin(); it != arguments.end(); it++) { - args[i] = const_cast <char*> (argsCopy[i].c_str()); + args[argIndex++] = const_cast <char*> (it->c_str()); } - args[argIndex] = nullptr; if (inputData) { @@ -138,9 +118,8 @@ namespace VeraCrypt throw_sys_if (fcntl (errPipe.GetReadFD(), F_SETFL, O_NONBLOCK) == -1); throw_sys_if (fcntl (exceptionPipe.GetReadFD(), F_SETFL, O_NONBLOCK) == -1); vector <char> buffer (4096), stdOutput (4096), errOutput (4096), exOutput (4096); - buffer.clear (); stdOutput.clear (); errOutput.clear (); exOutput.clear (); @@ -189,14 +168,14 @@ namespace VeraCrypt throw_sys_if (waitRes == -1); if (!exOutput.empty()) { - auto_ptr <Serializable> deserializedObject; + unique_ptr <Serializable> deserializedObject; Exception *deserializedException = nullptr; try { - shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((byte *) &exOutput[0], exOutput.size()))); + shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((uint8 *) &exOutput[0], exOutput.size()))); deserializedObject.reset (Serializable::DeserializeNew (stream)); deserializedException = dynamic_cast <Exception*> (deserializedObject.get()); } catch (...) { } diff --git a/src/Platform/Unix/Process.h b/src/Platform/Unix/Process.h index d19d5737..bb8482f2 100644 --- a/src/Platform/Unix/Process.h +++ b/src/Platform/Unix/Process.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/SyncEvent.cpp b/src/Platform/Unix/SyncEvent.cpp index 10bbc0c9..0336164b 100644 --- a/src/Platform/Unix/SyncEvent.cpp +++ b/src/Platform/Unix/SyncEvent.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/System.h b/src/Platform/Unix/System.h index 30384907..7225dae2 100644 --- a/src/Platform/Unix/System.h +++ b/src/Platform/Unix/System.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/SystemException.cpp b/src/Platform/Unix/SystemException.cpp index be051cc0..428edfe7 100644 --- a/src/Platform/Unix/SystemException.cpp +++ b/src/Platform/Unix/SystemException.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/SystemInfo.cpp b/src/Platform/Unix/SystemInfo.cpp index c3e3ab38..f09674aa 100644 --- a/src/Platform/Unix/SystemInfo.cpp +++ b/src/Platform/Unix/SystemInfo.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -23,8 +23,10 @@ namespace VeraCrypt #elif defined (TC_MACOSX) return L"Mac OS X"; #elif defined (TC_FREEBSD) return L"FreeBSD"; +#elif defined (TC_OPENBSD) + return L"OpenBSD"; #elif defined (TC_SOLARIS) return L"Solaris"; #else # error GetPlatformName() undefined diff --git a/src/Platform/Unix/SystemLog.cpp b/src/Platform/Unix/SystemLog.cpp index 88027e40..72221375 100644 --- a/src/Platform/Unix/SystemLog.cpp +++ b/src/Platform/Unix/SystemLog.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Thread.cpp b/src/Platform/Unix/Thread.cpp index 2d9fae09..099c4658 100644 --- a/src/Platform/Unix/Thread.cpp +++ b/src/Platform/Unix/Thread.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/Unix/Time.cpp b/src/Platform/Unix/Time.cpp index e98cea69..356dde74 100644 --- a/src/Platform/Unix/Time.cpp +++ b/src/Platform/Unix/Time.cpp @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ diff --git a/src/Platform/User.h b/src/Platform/User.h index ae7c179f..d5b51aad 100644 --- a/src/Platform/User.h +++ b/src/Platform/User.h @@ -3,9 +3,9 @@ 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 all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ |