VirtualBox

Changeset 93126 in vbox


Ignore:
Timestamp:
Jan 5, 2022 1:04:16 AM (3 years ago)
Author:
vboxsync
Message:

Main/Unattended/os2_util: Added a --file-to-backdoor for uploading a whole file to VBox.log. Handy for failure situations. Fixed the treat-as-zero feature (uninitialized variable). Flag the executable for long-filename support and mark it protected mode only.

Location:
trunk/src/VBox/Main/src-helper-apps/os2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-helper-apps/os2/Makefile.kmk

    r93123 r93126  
    4242        OPTION STACK=8192 \
    4343        OPTION HEAPSize=4096 \
    44         OPTION MANYAUTODATA \
     44        OPTION NEWFile \
     45        OPTION PROTmode \
    4546        SEGMENT IOPL IOPL EXECUTEREAD
    4647if 0
  • trunk/src/VBox/Main/src-helper-apps/os2/os2_util.c

    r93120 r93126  
    5757*********************************************************************************************************************************/
    5858void __far VBoxBackdoorPrint(PSZ psz, unsigned cch);
     59static PSZ MyGetOptValue(PSZ psz, PSZ pszOption, PSZ *ppszValue);
    5960
    6061
     
    143144
    144145
    145 static void MyApiErrorAndQuit(PSZ pszOperation, USHORT rc)
     146static DECL_NO_RETURN(void) MyApiErrorAndQuit(PSZ pszOperation, USHORT rc)
    146147{
    147148    MyOutStr("Os2Util: error: ");
     
    154155
    155156
    156 static void MyApiError3AndQuit(PSZ pszOperation, PSZ psz2, PSZ psz3, USHORT rc)
     157static DECL_NO_RETURN(void) MyApiError3AndQuit(PSZ pszOperation, PSZ psz2, PSZ psz3, USHORT rc)
    157158{
    158159    MyOutStr("Os2Util: error: ");
     
    167168
    168169
    169 static void MySyntaxErrorAndQuit(PSZ pszMsg)
     170static DECL_NO_RETURN(void) MySyntaxErrorAndQuit(PSZ pszMsg)
    170171{
    171172    MyOutStr("Os2Util: syntax error: ");
     
    184185    USHORT    rc;
    185186    rc = DosOpen(pszTeeToFile, &hFile, &usAction, 0 /*cbInitial*/, 0 /*fFileAttribs*/,
    186                   OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
    187                   OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT | OPEN_FLAGS_SEQUENTIAL, 0 /*Reserved*/);
     187                 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     188                 OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT | OPEN_FLAGS_SEQUENTIAL, 0 /*Reserved*/);
    188189    if (rc == NO_ERROR)
    189190    {
     
    352353
    353354
     355/**
     356 * Handles --file-to-backdoor / -c.
     357 */
     358static void CopyFileToBackdoorAndQuit(PSZ psz, BOOL fLongOpt, PSZ pszBuf, USHORT cbBuf)
     359{
     360    HFILE  hFile    = 0;
     361    USHORT usAction = 0;
     362    USHORT rc;
     363
     364    /*
     365     * Get the filename and check that it is the last thing on the commandline.
     366     */
     367    PSZ  pszFilename = NULL;
     368    CHAR ch;
     369    psz = MyGetOptValue(psz, fLongOpt ? "--file-to-backdoor" : "-c", &pszFilename);
     370    while ((ch = *psz) != '\0' && IS_BLANK(ch))
     371        psz++;
     372    if (ch != '\0')
     373        MySyntaxErrorAndQuit("No options allowed after -c/--file-to-backdoor");
     374
     375    /*
     376     * Open the file
     377     */
     378    rc = DosOpen(pszFilename, &hFile, &usAction, 0 /*cbInitial*/, 0 /*fFileAttribs*/,
     379                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     380                 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_NOINHERIT | OPEN_FLAGS_SEQUENTIAL, 0 /*Reserved*/);
     381    if (rc != NO_ERROR)
     382        MyApiError3AndQuit("Failed to open \"", pszFilename, "\" for reading", rc);
     383
     384    VBoxBackdoorPrint(RT_STR_TUPLE("--- BEGIN OF \""));
     385    VBoxBackdoorPrint(pszFilename, MyStrLen(pszFilename));
     386    VBoxBackdoorPrint(RT_STR_TUPLE("\" ---\n"));
     387
     388    for (;;)
     389    {
     390        USHORT cbRead = 0;
     391        rc = DosRead(hFile, pszBuf, cbBuf, &cbRead);
     392        if (rc == NO_ERROR)
     393        {
     394            if (cbRead == 0)
     395                break;
     396            VBoxBackdoorPrint(pszBuf, cbRead);
     397        }
     398        else if (rc != ERROR_INTERRUPT)
     399            MyApiError3AndQuit("Reading \"", pszFilename, "\"", rc);
     400    }
     401
     402    VBoxBackdoorPrint(RT_STR_TUPLE("--- END OF \""));
     403    VBoxBackdoorPrint(pszFilename, MyStrLen(pszFilename));
     404    VBoxBackdoorPrint(RT_STR_TUPLE("\" ---\n"));
     405
     406    DosClose(hFile);
     407    DosExit(EXIT_PROCESS, 1);
     408}
     409
     410
    354411/** Displays version string and quits.   */
    355 static void ShowVersionAndQuit(void)
     412static DECL_NO_RETURN(void) ShowVersionAndQuit(void)
    356413{
    357414    CHAR szVer[] = "$Rev$\r\n";
     
    363420
    364421/** Displays usage info and quits.   */
    365 static void ShowUsageAndQuit(void)
     422static DECL_NO_RETURN(void) ShowUsageAndQuit(void)
    366423{
    367424    static char s_szHelp[] =
     
    377434        "                   -- <prog> [args]\r\n"
    378435        "   or  Os2Util.exe <-w<msg>|--write-backdoor <msg>>\r\n"
     436        "   or  Os2Util.exe <-c<file>|--file-to-backdoor <file>>\r\n"
    379437        "\r\n"
    380438        "Note! Does not supported any kind of quoting before the child arguments.\r\n"
     
    419477static PSZ MyGetOptNum(PSZ psz, PSZ pszOption, PUSHORT puValue)
    420478{
    421     PSZ    pszError = NULL;
    422     PSZ    pszValueStart = NULL;
    423     PSZ    pszValue;
    424     CHAR   ch;
    425     USHORT uValue;
    426     psz = MyGetOptValue(psz, pszOption, &pszValueStart);
    427 
    428     pszValue = pszValueStart;
    429     uValue   = 0;
     479    PSZ         pszError      = NULL;
     480    PSZ         pszValue      = NULL;
     481    PSZ const   pszRet        = MyGetOptValue(psz, pszOption, &pszValue);
     482    PSZ const   pszValueStart = pszValue;
     483    USHORT      uValue        = 0;
     484    CHAR        ch;
    430485    if (pszValue[0] == '0' && ((ch = pszValue[1]) == 'x' || ch == 'X'))
    431486    {
     
    487542
    488543    *puValue = uValue;
    489     return psz;
     544    return pszRet;
    490545}
    491546
     
    545600    HQUEUE      hQueue         = ~(HQUEUE)0;
    546601    CHAR        szQueueName[64];
    547     unsigned    cAsZero;
     602    unsigned    cAsZero        = 0;
    548603    USHORT      auAsZero[16];
    549604
     
    584639                    if (cAsZero > RT_ELEMENTS(auAsZero))
    585640                        MySyntaxErrorAndQuit("Too many --as-zero/-z options");
    586                     psz = MyGetOptNum(psz + 1, "--as-zero", &auAsZero[cAsZero]);
     641                    psz = MyGetOptNum(psz, "--as-zero", &auAsZero[cAsZero]);
    587642                    cAsZero++;
    588643                }
     644                else if (ch == 'f' && MyMatchLongOption(&psz, RT_STR_TUPLE("file-to-backdoor")))
     645                    CopyFileToBackdoorAndQuit(psz, TRUE /*fLongOpt*/, szBuf, sizeof(szBuf));
    589646                else if (ch == 'h' && MyMatchLongOption(&psz, RT_STR_TUPLE("help")))
    590647                    ShowUsageAndQuit();
     
    617674                    else if (ch == 'b')
    618675                        g_fOutputToBackdoor = fTeeToBackdoor = TRUE;
     676                    else if (ch == 'c')
     677                        CopyFileToBackdoorAndQuit(psz + 1, FALSE /*fLongOpt*/, szBuf, sizeof(szBuf));
    619678                    else if (ch == 'f')
    620679                    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette