/* 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 #include #include #include #include #include #include #include #include "CoreLinux.h" #include "Platform/SystemInfo.h" #include "Platform/TextReader.h" #include "Volume/EncryptionModeXTS.h" #include "Driver/Fuse/FuseService.h" #include "Core/Unix/CoreServiceProxy.h" namespace VeraCrypt { CoreLinux::CoreLinux () { } CoreLinux::~CoreLinux () { } DevicePath CoreLinux::AttachFileToLoopDevice (const FilePath &filePath, bool readOnly) const { list loopPaths; loopPaths.push_back ("/dev/loop"); loopPaths.push_back ("/dev/loop/"); loopPaths.push_back ("/dev/.static/dev/loop"); // On Fedora 23,"losetup -f" must be called first to create a default loop device list args; args.push_back ("-f"); try { Process::Execute ("losetup", args); } catch (...) { } for (int devIndex = 0; devIndex < 256; devIndex++) { string loopDev; foreach (const string &loopPath, loopPaths) { loopDev = loopPath + StringConverter::ToSingle (devIndex); if (FilesystemPath (loopDev).IsBlockDevice()) break; } if (loopDev.empty()) continue; list args; list ::iterator readOnlyArg; if (readOnly) { args.push_back ("-r"); readOnlyArg = --args.end(); } args.push_back ("--"); args.push_back (loopDev); args.push_back (filePath); try { Process::Execute ("losetup", args); return loopDev; } catch (ExecutedProcessFailed&) { if (readOnly) { try { args.erase (readOnlyArg); Process::Execute ("losetup", args); return loopDev; } catch (ExecutedProcessFailed&) { } } } } throw LoopDeviceSetupFailed (SRC_POS, wstring (filePath)); } void CoreLinux::DetachLoopDevice (const DevicePath &devicePath) const { list args; args.push_back ("-d"); args.push_back (devicePath); for (int t = 0; true; t++) { try { Process::Execute ("losetup", args); break; } catch (ExecutedProcessFailed&) { if (t > 5) throw; Thread::Sleep (200); } } } void CoreLinux::DismountNativeVolume (shared_ptr mountedVolume) const { string devPath = mountedVolume->VirtualDevice; if (devPath.find ("/dev/mapper/veracrypt") != 0) throw NotApplicable (SRC_POS); size_t devCount = 0; while (FilesystemPath (devPath).IsBlockDevice()) { list dmsetupArgs; dmsetupArgs.push_back ("remove"); dmsetupArgs.push_back (StringConverter::Split (devPath, "/").back()); for (int t = 0; true; t++) { try { Process::Execute ("dmsetup", dmsetupArgs); break; } catch (...) { if (t > 20) throw; Thread::Sleep (100); } } for (int t = 0; FilesystemPath (devPath).IsBlockDevice() && t < 20; t++) { Thread::Sleep (100); } devPath = string (mountedVolume->VirtualDevice) + "_" + StringConverter::ToSingle (devCount++); } } HostDeviceList CoreLinux::GetHostDevices (bool pathListOnly) const { HostDeviceList devices; TextReader tr ("/proc/partitions"); string line; while (tr.ReadLine (line)) { vector fields = StringConverter::Split (line); if (fields.size() != 4 || fields[3].find ("loop") == 0 // skip loop devices || fields[3].find ("cloop") == 0 || fields[3].find ("ram") == 0 // skip RAM devices || fields[3].find ("dm-") == 0 // skip device mapper devices || fields[2] == "1" // skip extended partitions ) continue; try { StringConverter::ToUInt32 (fields[0]); } catch (...) { continue; } try { make_shared_auto (HostDevice, hostDevice); hostDevice->Path = string (fields[3].find ("/dev/") == string::npos ? "/dev/" : "") + fields[3]; if (!pathListOnly) { hostDevice->Size = StringConverter::ToUInt64 (fields[2]) * 1024; hostDevice->MountPoint = GetDeviceMountPoint (hostDevice->Path); hostDevice->SystemNumber = 0; } try { StringConverter::GetTrailingNumber (fields[3]); if (devices.size() > 0) { HostDevice &prevDev = **--devices.end(); if (string (hostDevice->Path).find (prevDev.
/*
 Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.

 Governed by the TrueCrypt License 3.0 the full text of which is contained in
 the file License.txt included in TrueCrypt binary and source code distribution
 packages.
*/

#ifndef TC_HEADER_Main_Forms_RandomPoolEnrichmentDialog
#define TC_HEADER_Main_Forms_RandomPoolEnrichmentDialog

#include "Forms.h"
#include "Main/Main.h"

namespace VeraCrypt
{
	class RandomPoolEnrichmentDialog : public RandomPoolEnrichmentDialogBase
	{
	public:
		RandomPoolEnrichmentDialog (wxWindow* parent);
		~RandomPoolEnrichmentDialog ();

	protected:
		void OnHashSelected (wxCommandEvent& event);
		void OnMouseMotion (wxMouseEvent& event);
		void OnShowRandomPoolCheckBoxClicked (wxCommandEvent& event);
		void ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer);
		
		HashList Hashes;
	};
}

#endif // TC_HEADER_Main_Forms_RandomPoolEnrichmentDialog
hLoopDevice (volumePath); } catch (...) { } throw; } } auto_ptr Core (new CoreServiceProxy ); auto_ptr CoreDirect (new CoreLinux); }