📄 main.c
字号:
// Description:
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW: http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//
#include "main.h"
#include "FreeOTFEDebug.h"
#include "FreeOTFEGUIlib.h"
#include "FreeOTFElib.h"
#include "wndMain.h"
#include "wndUserRNG.h"
#include "dlgAbout.h"
#include "resource.h"
#include "SDUGeneral.h"
#include "dlgMount.h"
#include "DriverInterface.h"
#include <windows.h>
#include <commctrl.h>
#include <aygshell.h> // Required for SH... functions/definitions/etc
#pragma comment(lib, "aygshell") // Link in aygshell.lib
#define IDC_MAIN_LISTBOX 100
// Portable mode related command line parameters...
//#define CMDLINE_PORTABLE TEXT("portable")
//#define CMDLINE_START TEXT("start")
//#define CMDLINE_ON TEXT("on")
//#define CMDLINE_STOP TEXT("stop")
//#define CMDLINE_OFF TEXT("off")
// Mount related command line parameters...
#define CMDLINE_MOUNT TEXT("mount")
//#define CMDLINE_FREEOTFE TEXT("freeotfe")
//#define CMDLINE_LINUX TEXT("linux")
#define CMDLINE_VOLUME TEXT("volume")
#define CMDLINE_KEYFILE TEXT("keyfile")
#define CMDLINE_PASSWORD TEXT("password")
#define CMDLINE_READONLY TEXT("readonly")
#define CMDLINE_OFFSET TEXT("offset")
#define CMDLINE_NOCDBATOFFSET TEXT("nocdbatoffset")
#define CMDLINE_KEYITERATIONS TEXT("keyiterations")
#define CMDLINE_SALTLENGTH TEXT("saltlength")
#define CMDLINE_MOUNTPOINT TEXT("mountpoint")
// Dismount related command line parameters...
#define CMDLINE_DISMOUNT TEXT("dismount")
#define CMDLINE_FORCE TEXT("force")
#define CMDLINE_ALL TEXT("all")
#define CMDLINE_SUCCESS 0
#define CMDLINE_EXIT_INVALID_CMDLINE 100
//#define CMDLINE_EXIT_UNABLE_TO_CONNECT 101
#define CMDLINE_EXIT_UNABLE_TO_MOUNT 102
#define CMDLINE_EXIT_UNABLE_TO_DISMOUNT 103
//#define CMDLINE_EXIT_UNABLE_TO_START_PORTABLE_MODE 104
//#define CMDLINE_EXIT_UNABLE_TO_STOP_PORTABLE_MODE 105
// =========================================================================
BOOL InitApp(HINSTANCE hInstance)
{
BOOL retval = TRUE;
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Test number: %d\n"), 101));
if (retval)
{
retval = WndMainRegister();
}
if (retval)
{
retval = WndUserRNGRegister();
}
return retval;
}
// =========================================================================
BOOL InitInstance(HINSTANCE hInstance, int iCmdShow)
{
G_hWndMain = WndMainCreate();
return (G_hWndMain != NULL);
}
// =========================================================================
void main_BadCommandLine()
{
MsgError(NULL, TEXT("Please check your command line parameters"));
}
// =========================================================================
LARGE_INTEGER main_CommandLineParameter_Name_AsNumber(
WCHAR* Name,
int Default
)
{
LARGE_INTEGER retval;
WCHAR* value;
retval.QuadPart = Default;
value = SDUCommandLineParameter_Name(Name);
if (value != NULL)
{
retval.QuadPart = _wtoi64(value);
SecZeroAndFreeWCHARMemory(value);
}
return retval;
}
// =========================================================================
// Returns -1 if there was no command line parameters, otherwise an exit value
int main_ProcessCmdLine()
{
int retval;
WCHAR* dismountMountpoint;
BOOL forceDismount;
BOOL dismountAll;
WCHAR* mountVolume;
BOOL readOnly;
WCHAR* keyfile;
WCHAR* password;
WCHAR* volume;
WCHAR* useMountpoint;
BOOL noCDBAtOffset;
LARGE_INTEGER keyiterations;
LARGE_INTEGER offset;
LARGE_INTEGER saltlength;
retval = -1;
// Check for dismount...
if (SDUCommandLineSwitch(CMDLINE_DISMOUNT))
{
retval = CMDLINE_EXIT_UNABLE_TO_DISMOUNT;
dismountMountpoint = SDUCommandLineParameter_Name(CMDLINE_DISMOUNT);
if (dismountMountpoint == NULL)
{
main_BadCommandLine();
retval = CMDLINE_EXIT_INVALID_CMDLINE;
}
else
{
// Dismount...
forceDismount = SDUCommandLineSwitch(CMDLINE_FORCE);
dismountAll = (wcscmp(dismountMountpoint, CMDLINE_ALL) == 0);
if (dismountAll)
{
if (driver_DismountAll(forceDismount))
{
retval = CMDLINE_SUCCESS;
}
}
else
{
// Remove any leading "\" the user may have inserted
useMountpoint = dismountMountpoint;
if (useMountpoint[0] == '\\')
{
useMountpoint = &(dismountMountpoint[1]);
}
if (driver_Dismount(useMountpoint, forceDismount))
{
retval = CMDLINE_SUCCESS;
}
}
SecZeroAndFreeWCHARMemory(dismountMountpoint);
}
}
// Check for mount...
if (SDUCommandLineSwitch(CMDLINE_MOUNT))
{
retval = CMDLINE_EXIT_UNABLE_TO_MOUNT;
volume = SDUCommandLineParameter_Name(CMDLINE_VOLUME);
if (volume == NULL)
{
main_BadCommandLine();
retval = CMDLINE_EXIT_INVALID_CMDLINE;
}
else if (wcslen(volume) <= 0)
{
main_BadCommandLine();
retval = CMDLINE_EXIT_INVALID_CMDLINE;
}
else
{
// Mount...
readOnly = SDUCommandLineSwitch(CMDLINE_READONLY);
keyfile = SDUCommandLineParameter_Name(CMDLINE_KEYFILE);
password = SDUCommandLineParameter_Name(CMDLINE_PASSWORD);
noCDBAtOffset = SDUCommandLineSwitch(CMDLINE_NOCDBATOFFSET);
offset = main_CommandLineParameter_Name_AsNumber(
CMDLINE_OFFSET,
DEFAULT_OFFSET
);
keyiterations = main_CommandLineParameter_Name_AsNumber(
CMDLINE_KEYITERATIONS,
DEFAULT_KEYITERATIONS
);
saltlength = main_CommandLineParameter_Name_AsNumber(
CMDLINE_SALTLENGTH,
DEFAULT_SALTLENGTH
);
mountVolume = SDUCommandLineParameter_Name(CMDLINE_MOUNTPOINT);
// Remove any leading "\" the user may have inserted
useMountpoint = mountVolume;
if (useMountpoint[0] == '\\')
{
useMountpoint = &(mountVolume[1]);
}
DisplayDlgMount_Params(
NULL,
useMountpoint,
volume,
keyfile,
offset,
(!(noCDBAtOffset)),
password,
saltlength.LowPart, // In *bits*
keyiterations.LowPart,
readOnly
);
// The user will either have cancelled, or it'll have mounted
// successfully; either way the user will already know
retval = CMDLINE_SUCCESS;
SecZeroAndFreeWCHARMemory(mountVolume);
SecZeroAndFreeWCHARMemory(keyfile);
SecZeroAndFreeWCHARMemory(password);
}
}
return retval;
}
// =========================================================================
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
HWND hWndExisting = NULL;
int exitValue;
#if DBG
FreeOTFEDebugLevel =
DEBUGLEV_ERROR |
DEBUGLEV_WARN |
DEBUGLEV_INFO |
DEBUGLEV_ENTER |
DEBUGLEV_EXIT;
//FreeOTFEDebugLevel = 0;
#endif
G_hInstance = hInstance;
// If a copy of this application is already running, bring it to the top,
// and exit
hWndExisting = FindWindow(APP_TITLE, APP_TITLE);
if (hWndExisting != NULL)
{
SetForegroundWindow(hWndExisting);
return TRUE;
}
if (hPrevInstance == NULL)
{
if (!(InitApp(hInstance)))
{
MsgError(NULL, TEXT("Unable to InitApp"));
return FALSE;
}
}
G_Options = OptionsRead();
// Check for command line options
exitValue = main_ProcessCmdLine();
if (exitValue == -1)
{
if (!(InitInstance(hInstance, nCmdShow)))
{
MsgError(NULL, TEXT("Unable to InitInstance"));
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
exitValue = (int)(msg.wParam);
}
OptionsFree(G_Options);
return exitValue;
}
// =========================================================================
void ExploreMountpoint(WCHAR* Mountpoint)
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Explore mountpoint: %ls\n"), Mountpoint));
CreateProcess(
G_Options->ExplorerExe,
Mountpoint,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
NULL,
NULL
);
}
// =========================================================================
// =========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -