⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freeotfe4pdaoptions.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 2 页
字号:
// Description: 
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW:   http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//


#include <stdlib.h>
#include <windows.h> // Required for INI read/write routines

#include "SDUGeneral.h"

#include "FreeOTFEDebug.h"
#include "FreeOTFEAPIConstsCommon.h"
#include "FreeOTFEPlatform.h"
#include "FreeOTFElib.h"
#include "FreeOTFE4PDAlib.h"
#include "FreeOTFE4PDAOptions.h"
#include "FreeOTFEDriverConstsCommon.h"
#include "FreeOTFE4PDAAPI.h"

// =========================================================================
// Forward declarations...
BOOL itob(int Value);
int btoi(BOOL Value);


// =========================================================================
// Consts...

//#define EXE_MS_FILE_EXPLORER   TEXT("\\Windows\\MSFEXPLORE")
//#define EXE_MS_FILE_EXPLORER   TEXT("\\Windows\\FEXPLORE")
#define EXE_MS_FILE_EXPLORER  TEXT("FEXPLORE")

#define F4P_INI_SECTION  TEXT("FreeOTFE4PDA")

#define F4P_INI_CONFIGVERSION                TEXT("ConfigVersion")
#define   F4P_INIDFLT_CONFIGVERSION            1
#define F4P_INI_SAVESETTINGS                 TEXT("SaveSettings")
#define   F4P_INIDFLT_SAVESETTINGS             FALSE
#define F4P_INI_MNTPNTUSEVOLFILEMAME         TEXT("MountpointVolFilename")
#define   F4P_INIDFLT_MNTPNTUSEVOLFILEMAME     FALSE
#define F4P_INI_MNTPNTDEFAULT                TEXT("MountpointDefault")
#define   F4P_INIDFLT_MNTPNTDEFAULT            TEXT("FreeOTFE storage")
#define F4P_INI_EXPLORER                     TEXT("ExplorerExe")
#define   F4P_INIDFLT_EXPLORER                 EXE_MS_FILE_EXPLORER
#define F4P_INI_EXPLOREONMOUNT               TEXT("ExploreOnMount") 
#define   F4P_INIDFLT_EXPLOREONMOUNT           FALSE
#define F4P_INI_LARGEICONS                   TEXT("LargeIcons") 
#define   F4P_INIDFLT_LARGEICONS               TRUE

// =========================================================================
// Allocate memory for the INI filename
// Note: It it the caller's responsibility to free off the memory allocated
WCHAR* _AllocMainINIFullFilename()
{
    WCHAR* fullFilename;
    WCHAR tmpFilename[FREEOTFE_MAX_FILENAME_LENGTH];
    WCHAR* uncMachine;
    WCHAR* drive;
    WCHAR* path;
    WCHAR* filename;
    WCHAR* fileExtension;

    DEBUGOUTDRV(DEBUGLEV_ENTER, (TEXT("_AllocMainINIFullFilename\n")));

    fullFilename = NULL;
    if (GetModuleFileName(NULL, tmpFilename, sizeof(tmpFilename)) != 0)
        {
        // Replace .exe filename with INI filename
        SDUParsePath(
                     tmpFilename, 
                     &uncMachine,
                     &drive,
                     &path,
                     &filename,
                     &fileExtension
                    );
        if (filename != NULL)
            {
            wcscpy(filename, FREEOTFE_INI);
                
            // +1 for NULL terminator
            fullFilename = calloc((wcslen(tmpFilename) + 1), sizeof(*fullFilename));
            if (fullFilename == NULL)
                {
                DEBUGOUTDRV(DEBUGLEV_ERROR, (TEXT("Unable to malloc enough memory to store INI path & filename\n")));
                }
            else
                {
                wcscpy(fullFilename, tmpFilename);
                DEBUGOUTDRV(DEBUGLEV_INFO, (TEXT("INI filename: %ls\n"), fullFilename));
                }
            }
        }

    DEBUGOUTDRV(DEBUGLEV_EXIT, (TEXT("_AllocMainINIFullFilename\n")));
    return fullFilename;
}


// =========================================================================
void _FreeMainINIFullFilename(WCHAR* fullFilename)
{
    WCHAR* tmpFilename;
    int len;
    
    // The user may have changed the filename previously returned (e.g. to
    // insert NULLs into the middle of it)
    // Because this means we can't find the size of the full filename,
    // we get it again, just to get it's size.
    tmpFilename = _AllocMainINIFullFilename();
    if (tmpFilename == NULL)
        {
        len = wcslen(fullFilename);
        }
    else
        {
        len = wcslen(tmpFilename);
        }

    SecZeroAndFreeMemory(fullFilename, (len * sizeof(*fullFilename)));

    SecZeroAndFreeWCHARMemory(tmpFilename);
}


// =========================================================================
#define MAX_INI_LINE  1024
BOOL GotoSection(FILE* hFile, WCHAR* Section)
{
    WCHAR line[MAX_INI_LINE];
    BOOL retval;

    DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("SEEK section: %s\n"), Section));

    retval = FALSE;

    if (hFile != NULL)
        {
        fseek(hFile, 0, SEEK_SET);
        memset(line, 0, sizeof(line));
        while (!(feof(hFile)))
            {
            memset(line, 0, sizeof(line));
            fgetws(line, sizeof(line), hFile);
            if (wcsncmp(line, TEXT("["), 1) == 0)
                {
                // 1 because we skip the first "["
                if (wcsncmp(&(line[1]), Section, wcslen(Section)) == 0)
                    {
                    retval = TRUE;
                    DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Section found.\n")));
                    break;
                    }
                }

            }
        }

    return retval;
}


// =========================================================================
// Note: It is the *callers* responsibility to free off "Value"
BOOL GetValueString(FILE* hFile, WCHAR* Name, WCHAR** Value)
{
    WCHAR line[MAX_INI_LINE];
    BOOL retval;
    fpos_t storedFilePos;
    WCHAR* readName;
    WCHAR* readValue;

    retval = FALSE;

    DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("READ Name: %s\n"), Name));

    if (hFile != NULL)
        {
        fgetpos(hFile, &storedFilePos);

        memset(line, 0, sizeof(line));
        while (
               (!(feof(hFile))) &&
               (wcsncmp(line, TEXT("["), 1) != 0)
              )
            {
            memset(line, 0, sizeof(line));
            fgetws(line, sizeof(line), hFile);

            readName = wcstok(line, TEXT("="));
            if (readName != NULL)
                {
                if (wcscmp(readName, Name) == 0)
                    {
                    readValue = wcstok(NULL, TEXT("\n"));
                    // +1 to include terminating NULL
                    *Value = calloc((wcslen(readValue) + 1), sizeof(*readValue));
                    if (*Value == NULL)
                        {
                        DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc for INI value read in\n")));
                        }
                    else
                        {
                        wcscpy(*Value, readValue);
                        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("READ Value: %s\n"), *Value));
                        retval = TRUE;                
                        }
                    break;
                    }
                }
            }

        fsetpos(hFile, &storedFilePos);
        }

    return retval;
}


// =========================================================================
// Note: It is the *callers* responsibility to free off "Value"
void GetValueStringDflt(FILE* hFile, WCHAR* Name, WCHAR** Value, WCHAR* Default)
{
    BOOL retval;

    retval = GetValueString(hFile, Name, Value);
    if (!(retval))
        {
        // +1 to include terminating NULL
        *Value = calloc((wcslen(Default) + 1), sizeof(*Default));
        if (*Value == NULL)
            {
            DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc value for default.\n")));
            }
        else
            {
            wcscpy(*Value, Default);
            }
        }

}


// =========================================================================
BOOL GetValueInt(FILE* hFile, WCHAR* Name, int* Value)
{
    WCHAR* strValue;
    BOOL retval;

    *Value = 0;

    retval = GetValueString(hFile, Name, &strValue);

    if (retval)
        {
        *Value = _wtoi(strValue);
        SecZeroAndFreeWCHARMemory(strValue);
        }

    return retval;
}


// =========================================================================
// Note: It is the *callers* responsibility to free off "Value"
void GetValueIntDflt(FILE* hFile, WCHAR* Name, int* Value, int Default)
{
    BOOL retval;

    retval = GetValueInt(hFile, Name, Value);
    if (!(retval))
        {
        *Value = Default;
        }

}


// =========================================================================
BOOL GetValueBool(FILE* hFile, WCHAR* Name, BOOL* Value)
{
    int intValue;
    BOOL retval;

    *Value = FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -