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

📄 dlgmount.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 3 页
字号:
            }

        case PSN_APPLY:
            {
            // This notification is received when the user clicks
            // "OK"/"Apply"
            // Because this is called once for each of the tabs, and we only
            // want to execute this functionality once for the whole dialog,
            // we only handle it for the "Basic" tab
            if (!(_dlgMount_GetPageIdxOfPage(hDlg) == PAGE_IDX_MOUNT_BASIC))
                {
                // Not the basic tab; set result as "OK"
                SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
                }
            else
                {                 
                DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Dialog OK'd by user\n")));
                if (dlgMount_Mount(hDlg))
                    {
#if DBG
                    // Only bother feeding back success if we're debugging
                    MsgInfo(hDlg, TEXT("Mounted OK"));
#endif

                    if (G_Options->ExploreOnMount)
                        {
                        ExploreMountpoint(G_UserMountParams.Mountpoint);
                        }

                    SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
                    }
                else
                    {
                    MsgError(hDlg, TEXT("Mount failed; please check your password and other settings"));
                    SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_INVALID);
                    }
                }
                
            break; 
            }

        case PSN_RESET:
            {
            // This notification is received when the user clicks
            // "Close"/"Cancel"
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Dialog cancelled by user\n")));
            SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
            break; 
            }

        }


    DEBUGOUTGUI(DEBUGLEV_VERBOSE_EXIT, (TEXT("dlgMount_HandleMsg_WM_NOTIFY\n")));
    return TRUE;
}


// =========================================================================
// This function is required in order to get the WinCE look & feel to the
// tabbed dialog.
int CALLBACK dlgMount_PropSheetProc(
  HWND hwndDlg, 
  UINT uMsg, 
  LPARAM lParam 
)
{
    int retval = 0;
    switch (uMsg)
        {
        case PSCB_GETVERSION:
            {
            retval = COMCTL32_VERSION;
            break; 
            }

        }

    return retval;
}


// =========================================================================
void dlgMount_HandleMsg_DefaultMountpoint(HWND hDlg)
{
    const TRYMOUNTPOINTS = 100;
    WCHAR initBaseMountpoint[FREEOTFE_MAX_FILENAME_LENGTH];
    WCHAR testMountpoint[FREEOTFE_MAX_FILENAME_LENGTH];
    WCHAR useMountpoint[FREEOTFE_MAX_FILENAME_LENGTH];
    int i;
    WCHAR* uncMachine;
    WCHAR* drive;
    WCHAR* path;
    WCHAR* filename;
    WCHAR* fileExtension;

    // Identify default mountpoint to use...    
    memset(initBaseMountpoint, 0, sizeof(initBaseMountpoint));
    if (G_Options->MntPntUseVolFilename)
        {
        if (_dlgMount_QuerySiblings(GetParent(hDlg)))
            {
            SDUParsePath(
                         G_UserMountParams.Filename, 
                         &uncMachine,
                         &drive,
                         &path,
                         &filename,
                         &fileExtension
                        );
            if (fileExtension != NULL)
                {
                if (wcsicmp(fileExtension, VOL_FILE_EXTN) == 0)
                    {
                    // -1 because we want to replace the "."
                    *(fileExtension-1) = (WCHAR)NULL;
                    }
                }
            if (filename != NULL)
                {
                wcscpy(initBaseMountpoint, filename);
                }
            }
        }

    if (wcslen(initBaseMountpoint) == 0)
        {
        wcscpy(initBaseMountpoint, G_Options->MntPntDefault);
        }

    memset(useMountpoint, 0, sizeof(useMountpoint));
    for (i = 1; i < TRYMOUNTPOINTS; i++)
        {
        if (i == 1)
            {
            wcscpy(testMountpoint, initBaseMountpoint);
            }
        else
            {
            _snwprintf(
                       testMountpoint, 
                       (sizeof(testMountpoint) / sizeof(testMountpoint[0])),
                       TEXT("%s (%d)"),
                       initBaseMountpoint,
                       i
                      );
            }
        if (ValidateMountpoint(hDlg, testMountpoint, FALSE, TRUE))
            {
            wcscpy(useMountpoint, testMountpoint);
            break;
            }
        }

    _dlgMount_SetDlgMountpoint(useMountpoint);
}


// =========================================================================
void _dlgMount_SetDlgMountpoint(WCHAR* Mountpoint)
{
    SetDlgItemText(
                   _dlgMount_GetPageHWNDForPage(PAGE_IDX_MOUNT_ADVANCED),
                   IDC_EDIT_MOUNTPOINT, 
                   Mountpoint
                  );
}


// =========================================================================
BOOL CALLBACK dlgMount_HandleMsg_WM_INITDIALOG(HWND hDlg, LPARAM lParam)
{
    SHINITDLGINFO shidi;
    int currPageIdx;
    UINT checkCDBAtOffset;
    int userPasswordSize;
    int pwLen;
    WCHAR* userPassword;
    BOOL checkReadonly;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("dlgMount_HandleMsg_WM_INITDIALOG\n")));

    // Don't recreate menu if it's already been done
    if (G_dlgMount_MenuBar == NULL)
        {
        G_dlgMount_MenuBar = SetupMenu(hDlg, IDR_MENU_DONECANCEL);
        }

    // This isn't actually needed for property sheet dialog...
    shidi.dwMask = SHIDIM_FLAGS;
    shidi.dwFlags = (
                     SHIDIF_DONEBUTTON | 
                     SHIDIF_SIPDOWN | 
                     SHIDIF_SIZEDLGFULLSCREEN
                    );
    shidi.hDlg = hDlg;
    SHInitDialog(&shidi);

    // Set userdata on the page being initialized; we use this to identify
    // the different pages
    currPageIdx = ((LPPROPSHEETPAGE)lParam)->lParam;
    SetWindowLong(
                  hDlg,
                  GWL_USERDATA,
                  currPageIdx
                 );
    G_dlgMount_PropPage[currPageIdx] = hDlg;


    // Default values for controls...
    if (currPageIdx == PAGE_IDX_MOUNT_BASIC)
        {
        // Basic page...
        if (G_UserMountParams.Filename != NULL)
            {
            SetDlgItemText(hDlg, IDC_EDIT_FILENAME, G_UserMountParams.Filename);
            SecZeroWCHARMemory(G_UserMountParams.Filename);
            }
        if (G_UserMountParams.Keyfile != NULL)
            {
            SetDlgItemText(hDlg, IDC_EDIT_KEYFILE, G_UserMountParams.Keyfile);
            SecZeroWCHARMemory(G_UserMountParams.Keyfile);
            }
        if (G_UserMountParams.UserPassword != NULL)
            {
            pwLen = strlen(G_UserMountParams.UserPassword);
            // +1 for terminating NULL
            userPasswordSize = (pwLen + 1) * sizeof(*userPassword);
            userPassword = malloc(userPasswordSize);
            if (userPassword != NULL) 
                {
                memset(userPassword, 0, userPasswordSize);
                mbstowcs(
                         userPassword, 
                         G_UserMountParams.UserPassword, 
                         strlen(G_UserMountParams.UserPassword)
                        );

                SetDlgItemText(hDlg, IDC_EDIT_PASSWORD, userPassword);
                SecZeroAndFreeWCHARMemory(userPassword);
                }

            SecZeroAndFreeMemory(G_UserMountParams.UserPassword, strlen(G_UserMountParams.UserPassword));
            G_UserMountParams.UserPassword = NULL;
            }

        // Readonly checkbox...
        checkReadonly = BST_UNCHECKED;
        if (G_UserMountParams.ReadOnly == TRUE)
            {
            checkReadonly = BST_CHECKED;
            }
        CheckDlgButton(
                       hDlg, 
                       IDC_CHECK_READONLY,
                       checkReadonly
                      );
        }
    else if (currPageIdx == PAGE_IDX_MOUNT_ADVANCED)
        {
        // Advanced page...

        // Default mountpoint...
        dlgMount_HandleMsg_DefaultMountpoint(hDlg);
        if (G_UserMountParams.Mountpoint != NULL)
            {
            if (wcslen(G_UserMountParams.Mountpoint) > 0)
                {
                _dlgMount_SetDlgMountpoint(G_UserMountParams.Mountpoint);
                }
            }
        SecZeroWCHARMemory(G_UserMountParams.Mountpoint);

        SetDlgItemInt(
                      hDlg, 
                      IDC_EDIT_OFFSET, 
                      G_UserMountParams.OffsetWithinFile.LowPart, 
                      TRUE
                     );

        // CDB at offset checkbox...
        checkCDBAtOffset = BST_UNCHECKED;
        if (G_UserMountParams.CDBAtOffset == TRUE)
            {
            checkCDBAtOffset = BST_CHECKED;
            }
        CheckDlgButton(
                       hDlg, 
                       IDC_CHECK_CDBATOFFSET,
                       checkCDBAtOffset
                      );

        SetDlgItemInt(
                      hDlg,
                      IDC_EDIT_SALTLENGTH,
                      G_UserMountParams.SaltLength,
                      TRUE
                     );
        SetDlgItemInt(
                      hDlg,
                      IDC_EDIT_KEYITERATIONS,
                      G_UserMountParams.KeyIterations,
                      TRUE
                     );
        }

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("dlgMount_HandleMsg_WM_INITDIALOG\n")));
    return TRUE;
}


// =========================================================================
void _dlgMount_SecZeroParams()
{
    if (G_UserMountParams.UserPassword != NULL)
        {
        SecZeroAndFreeMemory(
                    G_UserMountParams.UserPassword,
                    strlen(G_UserMountParams.UserPassword)
                   );
        G_UserMountParams.UserPassword = NULL;
        }

    SecZeroMemory(&G_UserMountParams, sizeof(G_UserMountParams));
}


// =========================================================================
BOOL CALLBACK dlgMount_HandleMsg_WM_DESTROY(HWND hWnd)
{
    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("dlgMount_HandleMsg_WM_DESTROY\n")));
    if (G_dlgMount_MenuBar != NULL)
        {
        DestroyWindow(G_dlgMount_MenuBar);
        G_dlgMount_MenuBar = NULL;
        }

    _dlgMount_SecZeroParams();

    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("dlgMount_HandleMsg_WM_DESTROY\n")));
    return TRUE;
}


// =========================================================================
// Pass this the HWND for the *main* dialog
BOOL _dlgMount_QuerySiblings(HWND hDlg)
{
    BOOL retval = FALSE;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("_dlgMount_QuerySiblings\n")));

⌨️ 快捷键说明

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