"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/Cmdline.c" (10 Oct 2018, 4318 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Cmdline.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Legal Notice: Some portions of the source code contained in this file were
    3  derived from the source code of TrueCrypt 7.1a, which is
    4  Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
    5  governed by the TrueCrypt License 3.0, also from the source code of
    6  Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
    7  and which is governed by the 'License Agreement for Encryption for the Masses'
    8  Modifications and additions to the original source code (contained in this file)
    9  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
   10  and are governed by the Apache License 2.0 the full text of which is
   11  contained in the file License.txt included in VeraCrypt binary and source
   12  code distribution packages. */
   13 
   14 #include "Tcdefs.h"
   15 
   16 #include <malloc.h>
   17 #include <ctype.h>
   18 #include "Cmdline.h"
   19 
   20 #include "Resource.h"
   21 #include "Crypto.h"
   22 #include "Apidrvr.h"
   23 #include "Dlgcode.h"
   24 #include "Language.h"
   25 #include <Strsafe.h>
   26 
   27 #ifndef SRC_POS
   28 #define SRC_POS (__FUNCTION__ ":" TC_TO_STRING(__LINE__))
   29 #endif
   30 
   31 /* Except in response to the WM_INITDIALOG message, the dialog box procedure
   32    should return nonzero if it processes the message, and zero if it does
   33    not. - see DialogProc */
   34 BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
   35 {
   36     UNREFERENCED_PARAMETER (lParam);        /* remove warning */
   37     UNREFERENCED_PARAMETER (wParam);        /* remove warning */
   38 
   39     switch (msg)
   40     {
   41     case WM_INITDIALOG:
   42         {
   43         wchar_t * tmp = err_malloc(8192 * sizeof (wchar_t));
   44         wchar_t tmp2[MAX_PATH * 2];
   45         argumentspec *as;
   46         int i;
   47 
   48         LocalizeDialog (hwndDlg, "IDD_COMMANDHELP_DLG");
   49 
   50         as = (argumentspec*) lParam;
   51 
   52         *tmp = 0;
   53 
   54         StringCchCopyW (tmp, 8192, L"VeraCrypt " _T(VERSION_STRING));
   55 #ifdef _WIN64
   56         StringCchCatW (tmp, 8192, L"  (64-bit)");
   57 #else
   58         StringCchCatW (tmp, 8192, L"  (32-bit)");
   59 #endif
   60 #if (defined(_DEBUG) || defined(DEBUG))
   61         StringCchCatW (tmp, 8192, L"  (debug)");
   62 #endif
   63 
   64         StringCchCatW (tmp, 8192, L"\n\nCommand line options:\n\n");
   65         for (i = 0; i < as->arg_cnt; i ++)
   66         {
   67             if (!as->args[i].Internal)
   68             {
   69                 StringCchPrintfW(tmp2, MAX_PATH * 2, L"%s\t%s\n", as->args[i].short_name, as->args[i].long_name);
   70                 StringCchCatW(tmp, 8192, tmp2);
   71             }
   72         }
   73 
   74         StringCchCatW (tmp, 8192, L"\nExamples:\n\nMount a volume as X:\tveracrypt.exe /q /v volume.hc /l X\nDismount a volume X:\tveracrypt.exe /q /d X");
   75 
   76         SetWindowTextW (GetDlgItem (hwndDlg, IDC_COMMANDHELP_TEXT), tmp);
   77 
   78         TCfree(tmp);
   79         return 1;
   80         }
   81 
   82     case WM_COMMAND:
   83         EndDialog (hwndDlg, IDOK);
   84         return 1;
   85     case WM_CLOSE:
   86         EndDialog (hwndDlg, 0);
   87         return 1;
   88     }
   89 
   90     return 0;
   91 }
   92 
   93 int Win32CommandLine (wchar_t ***lpszArgs)
   94 {
   95     int argumentCount;
   96     int i;
   97 
   98     LPWSTR *arguments = CommandLineToArgvW (GetCommandLineW(), &argumentCount);
   99     if (!arguments)
  100     {
  101         handleWin32Error (NULL, SRC_POS);
  102         return 0;
  103     }
  104 
  105     --argumentCount;
  106     if (argumentCount < 1)
  107     {
  108         LocalFree (arguments);
  109         return 0;
  110     }
  111 
  112     *lpszArgs = malloc (sizeof (wchar_t *) * argumentCount);
  113     if (!*lpszArgs)
  114         AbortProcess ("OUTOFMEMORY");
  115 
  116     for (i = 0; i < argumentCount; ++i)
  117     {
  118         wchar_t *arg = _wcsdup (arguments[i + 1]);
  119         if (!arg)
  120             AbortProcess ("OUTOFMEMORY");
  121 
  122         (*lpszArgs)[i] = arg;
  123     }
  124 
  125     LocalFree (arguments);
  126     return argumentCount;
  127 }
  128 
  129 int GetArgSepPosOffset (wchar_t *lpszArgument)
  130 {
  131     if (lpszArgument[0] == L'/')
  132         return 1;
  133 
  134     return 0;
  135 }
  136 
  137 int GetArgumentID (argumentspec *as, wchar_t *lpszArgument)
  138 {
  139     int i;
  140 
  141     for (i = 0; i < as->arg_cnt; i++)
  142     {
  143         if (_wcsicmp (as->args[i].long_name, lpszArgument) == 0)
  144         {
  145             return as->args[i].Id;
  146         }
  147     }
  148 
  149     for (i = 0; i < as->arg_cnt; i++)
  150     {
  151         if (as->args[i].short_name[0] == 0)
  152             continue;
  153 
  154         if (_wcsicmp (as->args[i].short_name, lpszArgument) == 0)
  155         {
  156             return as->args[i].Id;
  157         }
  158     }
  159 
  160 
  161     return -1;
  162 }
  163 
  164 int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
  165           int nNoCommandLineArgs, wchar_t *lpszValue, int nValueSize)
  166 {
  167     *lpszValue = 0;
  168 
  169     if (*nArgIdx + 1 < nNoCommandLineArgs)
  170     {
  171         int x = GetArgSepPosOffset (lpszCommandLineArgs[*nArgIdx + 1]);
  172         if (x == 0)
  173         {
  174             /* Handles the case of space between parameter code
  175                and value */
  176             StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
  177             lpszValue[nValueSize - 1] = 0;
  178             (*nArgIdx)++;
  179             return HAS_ARGUMENT;
  180         }
  181     }
  182 
  183     return HAS_NO_ARGUMENT;
  184 }