📄 freeotfefrmmain.pas
字号:
not(suppressMsgs) and
not(OTFEFreeOTFE.Active) and
not(ShuttingDownFlag) // Don't complain to user is we're about to exit!
) then
begin
if (obsoleteDriver) then
begin
SDUMessageDlg(
'In order to use this software, you must first upgrade your '+SDUCRLF+
'FreeOTFE drivers to a later version.'+SDUCRLF+
SDUCRLF+
'If you have just upgraded your copy of FreeOTFE from a '+SDUCRLF+
'previous version, please ensure that you have followed the '+SDUCRLF+
'upgrade instructions that came with it, and have rebooted '+SDUCRLF+
'if necessary.',
mtError,
[mbOK],
0
);
end
else
begin
MessageDlg(
'Unable to connect to the FreeOTFE driver.'+SDUCRLF+
SDUCRLF+
'Please ensure that the main "FreeOTFE" driver is installed and started.'+SDUCRLF+
SDUCRLF+
'If you have only just installed FreeOTFE, please reboot and try again.',
mtError,
[mbOK],
0
);
end;
// Note that we don't terminate here; the user may still use the driver
// control functionality to install and/or start the FreeOTFE driver
end;
// Let Windows know whether we accept dropped files or not
DragAcceptFiles(self.Handle, OTFEFreeOTFE.Active);
Result := OTFEFreeOTFE.Active;
end;
procedure TfrmFreeOTFEMain.DeactivateFreeOTFEComponent();
begin
OTFEFreeOTFE.Active := FALSE;
// Let Windows know we accept dropped files or not
DragAcceptFiles(self.Handle, OTFEFreeOTFE.Active);
end;
// The array passed in is zero-indexed; populate elements zero to "bytesRequired"
procedure TfrmFreeOTFEMain.GenerateOverwriteData(Sender: TObject; passNumber: integer; bytesRequired: cardinal; var outputBlock: TShredBlock);
var
i: integer;
tempArraySize: cardinal;
blocksizeBytes: cardinal;
plaintext: string;
cyphertext: string;
IV: string;
localIV: int64;
begin
// Generate an array of random data containing "bytesRequired" bytes of data,
// plus additional random data to pad out to the nearest multiple of the
// cypher's blocksize bits
// Cater for if the blocksize was -ve or zero
if (TempCypherDetails.BlockSize < 1) then
begin
blocksizeBytes := 1;
end
else
begin
blocksizeBytes := (TempCypherDetails.BlockSize div 8);
end;
tempArraySize := bytesRequired + (blocksizeBytes - (bytesRequired mod blocksizeBytes));
plaintext := '';
for i:=1 to tempArraySize do
begin
plaintext := plaintext + char(random(256));
end;
// Adjust the IV so that this block of encrypted pseudorandom data should be
// reasonably unique
IV := '';
if (TempCypherDetails.BlockSize > 0) then
begin
IV := StringOfChar(#0, (TempCypherDetails.BlockSize div 8));
inc(TempCypherIV);
localIV := TempCypherIV;
for i:=1 to min(sizeof(localIV), length(IV)) do
begin
IV[i] := char((localIV AND $FF));
localIV := localIV shr 8;
end;
end;
// Encrypt the pseudorandom data generated
if not(OTFEFreeOTFE.EncryptData(
TempCypherDriver,
TempCypherGUID,
TempCypherKey,
IV,
plaintext,
cyphertext
)) then
begin
SDUMessageDlg(
'Unable to encrypt pseudorandom data before using for '+SDUCRLF+
'overwrite buffer?!',
mtWarning,
[mbOK],
0
);
end;
// Copy the encrypted data into the outputBlock
for i:=0 to (bytesRequired-1) do
begin
outputBlock[i] := byte(cyphertext[i+1]);
end;
end;
function TfrmFreeOTFEMain.PortableModeSet(setTo: TPortableModeAction; suppressMsgs: boolean): boolean;
var
retval: boolean;
begin
retval := FALSE;
if not(OTFEFreeOTFE.CanUserManageDrivers()) then
begin
// On Vista, escalate UAC
if SDUOSVistaOrLater() then
begin
UACEscalateForPortableMode(setTo, suppressMsgs);
end
else
begin
// On pre-Vista, just let user know they can't do it
if not(suppressMsgs) then
begin
SDUMessageDlg(
TEXT_NEED_ADMIN,
mtWarning,
[mbOK],
0
);
end;
end;
end
else
begin
case setTo of
pmaStart:
begin
retval := _PortableModeStart(suppressMsgs);
end;
pmaStop:
begin
retval := _PortableModeStop(suppressMsgs);
end;
pmaToggle:
begin
retval := _PortableModeToggle(suppressMsgs);
end;
end;
// In case we UAC escalated (i.e. ran a separate process to handle the
// drivers, we send out a message to any other running instances of
// FreeOTFE to refresh
SDUPostMessageExistingApp(GLOBAL_VAR_WM_FREEOTFE_REFRESH, 0, 0);
end;
Result := retval;
end;
function TfrmFreeOTFEMain._PortableModeStart(suppressMsgs: boolean): boolean;
var
driverFilenames: TStringList;
fileIterator: TSDUFileIterator;
filename: string;
allOK: boolean;
begin
allOK:= FALSE;
driverFilenames:= TStringList.Create();
try
// Compile a list of drivers in the CWD
fileIterator:= TSDUFileIterator.Create(nil);
try
fileIterator.Directory := ExtractFilePath(Application.ExeName);
fileIterator.FileMask := '*.sys';
fileIterator.RecurseSubDirs := FALSE;
fileIterator.OmitStartDirPrefix := FALSE;
fileIterator.IncludeDirNames := FALSE;
fileIterator.Reset();
filename := fileIterator.Next();
while (filename<>'') do
begin
driverFilenames.Add(filename);
filename := fileIterator.Next();
end;
finally
fileIterator.Free();
end;
if (driverFilenames.count<1) then
begin
if not(suppressMsgs) then
begin
SDUMessageDlg(
'Unable to locate any portable FreeOTFE drivers.'+SDUCRLF+
SDUCRLF+
'Please ensure that the a copy of the FreeOTFE drivers (".sys" files) '+SDUCRLF+
'you wish to use are located in the correct directory.',
mtWarning,
[mbOK],
0
);
end;
end
else
begin
DeactivateFreeOTFEComponent();
if OTFEFreeOTFE.PortableStart(driverFilenames, not(suppressMsgs)) then
begin
if not(suppressMsgs) then
begin
SDUMessageDlg('Portable mode drivers installed and started.', mtInformation, [mbOK], 0);
end;
allOK:= TRUE;
end
else
begin
if not(suppressMsgs) then
begin
SDUMessageDlg(
'One or more of your portable FreeOTFE drivers could not be '+SDUCRLF+
'installed/started.'+SDUCRLF+
SDUCRLF+
TEXT_NEED_ADMIN+SDUCRLF+
SDUCRLF+
'Please select "File | Drivers..." to check which drivers are '+SDUCRLF+
'currently operating.',
mtWarning,
[mbOK],
0
);
end;
end;
end;
finally
driverFilenames.Free();
ActivateFreeOTFEComponent(suppressMsgs);
end;
Result := allOK;
end;
function TfrmFreeOTFEMain._PortableModeStop(suppressMsgs: boolean): boolean;
var
allOK: boolean;
stopOK: boolean;
begin
allOK := FALSE;
// Note that if the component was *not* active, then we can shutdown all
// portable mode drivers; if we aren't active, this implies the main driver
// isn't installed/running - in which case we don't need the user to confirm
// as no drives can be mounted
stopOK := TRUE;
if OTFEFreeOTFE.Active then
begin
if (OTFEFreeOTFE.CountDrivesMounted() > 0) then
begin
if suppressMsgs then
begin
stopOK := FALSE;
end
else
begin
stopOK := (SDUMessageDlg(
'You have one or more volumes mounted.'+SDUCRLF+
SDUCRLF+
'If any of the currently mounted volumes makes use of any of the '+SDUCRLF+
'FreeOTFE drivers which are currently in portable mode, '+SDUCRLF+
'stopping portable mode is not advisable.'+SDUCRLF+
SDUCRLF+
'It is recommended that you dismount all volumes before '+SDUCRLF+
'stopping portable mode.'+SDUCRLF+
SDUCRLF+
'Do you wish to continue stopping portable mode?',
mtWarning,
[mbYes,mbNo],
0
) = mrYes);
end;
end;
end;
if stopOK then
begin
DeactivateFreeOTFEComponent();
if OTFEFreeOTFE.PortableStop() then
begin
// No point in informing user; they would have been prompted if they
// wanted to do this, and they can tell they've stopped as the
// application will just exit; only popping up a messagebox if there's a
// problem
if not(ShuttingDownFlag) then
begin
if not(suppressMsgs) then
begin
SDUMessageDlg('Portable mode drivers stopped and uninstalled.', mtInformation, [mbOK], 0);
end;
end;
allOK := TRUE;
end
else
begin
if not(suppressMsgs) then
begin
SDUMessageDlg(
'One or more of your portable FreeOTFE drivers could not be '+SDUCRLF+
'stopped/uninstalled.'+SDUCRLF+
SDUCRLF+
TEXT_NEED_ADMIN+SDUCRLF+
SDUCRLF+
'Please select "File | Drivers..." to check which drivers are '+SDUCRLF+
'currently operating.',
mtWarning,
[mbOK],
0
);
end;
end;
ActivateFreeOTFEComponent(suppressMsgs);
end;
Result := allOK;
end;
function TfrmFreeOTFEMain._PortableModeToggle(suppressMsgs: boolean): boolean;
var
retval: boolean;
cntPortable: integer;
begin
retval := FALSE;
cntPortable := OTFEFreeOTFE.DriversInPortableMode();
if (cntPortable < 0) then
begin
// We *should* be authorised to do this by the time we get here...
// Do nothing; retval already set to FALSE
end
else if (cntPortable > 0) then
begin
retval := PortableModeSet(pmaStop, suppressMsgs);
end
else
begin
retval := PortableModeSet(pmaStart, suppressMsgs);
end;
Result := retval;
end;
procedure TfrmFreeOTFEMain.miCDBBackupClick(Sender: TObject);
var
dlg: TfrmFreeOTFECDBBackupRestore;
begin
dlg:= TfrmFreeOTFECDBBackupRestore.Create(self);
try
dlg.OTFEFreeOTFE := OTFEFreeOTFE;
dlg.DlgType := opBackup;
dlg.ShowModal();
finally
dlg.Free();
end;
end;
procedure TfrmFreeOTFEMain.miCDBRestoreClick(Sender: TObject);
var
dlg: TfrmFreeOTFECDBBackupRestore;
begin
dlg:= TfrmFreeOTFECDBBackupRestore.Create(self);
try
dlg.OTFEFreeOTFE := OTFEFreeOTFE;
dlg.DlgType := opRestore;
dlg.ShowModal();
finally
dlg.Free();
end;
end;
procedure TfrmFreeOTFEMain.miCreateKeyfileClick(Sender: TObject);
begin
OTFEFreeOTFE.WizardCreateKeyfile();
end;
procedure TfrmFreeOTFEMain.miChangePasswordClick(
Sender: TObject);
begin
OTFEFreeOTFE.WizardChangePassword();
end;
procedure TfrmFreeOTFEMain.miCDBPlaintextDumpClick(Sender: TObject);
begin
DumpDetailsToFile(FALSE);
end;
procedure TfrmFreeOTFEMain.miLUKSDumpClick(Sender: TObject);
begin
DumpDetailsToFile(TRUE);
end;
procedure TfrmFreeOTFEMain.DumpDetailsToFile(LUKSDump: boolean);
var
dlg: TfrmFreeOTFECDBDump;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -