Exemple #1
0
DWORD
RegLexParseDefaultState(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state == REGLEX_STATE_IN_QUOTE ||
            lexHandle->state == REGLEX_STATE_IN_KEY)
    {
        /* Append current character to string */
        RegLexAppendChar(lexHandle, inC);
    }
    else if (lexHandle->state == REGLEX_STATE_BINHEX_STR)
    {
        if (inC == ' ' || inC == ',')
        {
            /* Eat white spaces in binhex strings */
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_HEXPAIR;
            return dwError;
        }

        if (!isxdigit((int)inC))
        {
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            return dwError;
        }
        if (lexHandle->curToken.valueCursor == 2)
        {
            dwError = RegIOUnGetChar(ioHandle, &inC);
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_HEXPAIR;
            return dwError;
        }
        RegLexAppendChar(lexHandle, inC);

    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
        if (lexHandle->state != REGLEX_STATE_DWORD)
        {
            lexHandle->curToken.token = REGLEX_PLAIN_TEXT;
        }
#ifdef _LW_DEBUG
        if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
                lexHandle->state != REGLEX_STATE_IN_KEY &&
                lexHandle->state != REGLEX_STATE_BINHEX_STR)
        {
            printf("<%c> <%02x>\n", inC, inC);
        }
#endif
    }
    return dwError;
}
Exemple #2
0
DWORD
RegLexParseDash(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;
    BOOLEAN eof = FALSE;
    BOOLEAN isDash = FALSE;

    if (lexHandle->curToken.pszValue[lexHandle->curToken.valueCursor] == '-')
    {
        isDash = TRUE;
    }
    else
    {
        dwError = RegIOGetChar(ioHandle, &inC, &eof);
        if (inC == '\r' || inC == '\n')
        {
            isDash = TRUE;
        }
        else if (inC != '-')
        {
            RegLexAppendChar(lexHandle, '-');
            RegLexAppendChar(lexHandle, inC);
            return dwError;
        }
        else
        {
            dwError = RegIOUnGetChar(ioHandle, NULL);
            isDash = TRUE;
        }
    }
    if (isDash && lexHandle->state != REGLEX_STATE_IN_QUOTE &&
        lexHandle->state != REGLEX_STATE_IN_KEY &&
        lexHandle->eValueNameType != REGLEX_VALUENAME_SECURITY)
    {
        if (lexHandle->curToken.valueCursor > 0)
        {
            dwError = RegIOUnGetChar(ioHandle, NULL);
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_DASH;
            lexHandle->curToken.valueCursor = 0;
            RegLexAppendChar(lexHandle, inC);
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #3
0
DWORD
RegLexParseAt(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;
    BOOLEAN eof = FALSE;
    BOOLEAN bHasSecurity = FALSE;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
            lexHandle->state != REGLEX_STATE_IN_KEY)
    {
        /* Default value for a registry key */
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        lexHandle->curToken.token = REGLEX_KEY_NAME_DEFAULT;
        lexHandle->state = REGLEX_STATE_INIT;
        lexHandle->curToken.valueCursor = 0;
        RegLexAppendChar(lexHandle, inC);

        /* Handle the case of @frob, i.e. "@security" */
        dwError = RegIOGetChar(ioHandle, &inC, &eof);
        while (dwError == 0 && !eof && isalpha((int) inC))
        {
            RegLexAppendChar(lexHandle, inC);
            dwError = RegIOGetChar(ioHandle, &inC, &eof);
            bHasSecurity = TRUE;
        }
        if (eof)
        {
            return dwError;
        }
        dwError = RegIOUnGetChar(ioHandle, NULL);
        if (bHasSecurity)
        {
            if (strcmp(lexHandle->curToken.pszValue, "@security") == 0)
            {
                lexHandle->eValueNameType = REGLEX_VALUENAME_SECURITY;
            }
            else
            {
                dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            }
        }
    }
    return dwError;
}
Exemple #4
0
DWORD
RegLexParseComment(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;
    BOOLEAN eof = FALSE;

    if (lexHandle->state == REGLEX_STATE_IN_QUOTE ||
            lexHandle->state == REGLEX_STATE_IN_KEY)
    {
        RegLexAppendChar(lexHandle, inC);
    }
    else
    {
        do
        {
            dwError = RegIOGetChar(ioHandle, &inC, &eof);
        } while (dwError == 0 && !eof && inC != '\n' && inC != '\r');

        if (!eof && (inC == '\n' || inC == '\r'))
        {
            dwError = RegIOUnGetChar(ioHandle, NULL);
        }
    }
    return dwError;
}
Exemple #5
0
DWORD
RegLexParseComma(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
            lexHandle->state != REGLEX_STATE_IN_KEY)
    {
        if (lexHandle->curToken.valueCursor > 0 && lexHandle->curToken.valueCursor <=2)
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_HEXPAIR;
        }
        else
        {
            /* Syntax error: Hex pair is only 2 characters */
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #6
0
DWORD
RegLexParseEquals(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
            lexHandle->state != REGLEX_STATE_IN_KEY)
    {
        if (lexHandle->curToken.valueCursor > 0)
        {
            dwError = RegIOUnGetChar(ioHandle, NULL);
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_EQUALS;
            lexHandle->curToken.valueCursor = 0;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #7
0
DWORD
RegLexParseCloseBrace(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
            lexHandle->state != REGLEX_STATE_IN_KEY)
    {
        if (lexHandle->eValueNameType != REGLEX_VALUENAME_ATTRIBUTES)
        {
            /* This is a problem, can't have } without a previous { */
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_ATTRIBUTES_END;
            lexHandle->state = REGLEX_STATE_INIT;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #8
0
DWORD
RegLexParseCloseBracket(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE)
    {
        lexHandle->curToken.token = REGLEX_KEY_SUFFIX;
        if (lexHandle->state != REGLEX_STATE_IN_KEY)
        {
            /* This is a problem, can't have ] without a previous [ */
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_REG_KEY;
            lexHandle->state = REGLEX_STATE_INIT;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #9
0
DWORD
RegLexParseColon(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state == REGLEX_STATE_IN_QUOTE ||
            lexHandle->state == REGLEX_STATE_IN_KEY ||
            lexHandle->eValueNameType == REGLEX_VALUENAME_SECURITY)
    {
        RegLexAppendChar(lexHandle, inC);
        return dwError;
    }

    return RegLexParseBinary(lexHandle);
}
Exemple #10
0
DWORD
RegLexParseQuote(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->curToken.token == REGLEX_PLAIN_TEXT)
    {
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        dwError = RegIOUnGetChar(ioHandle, NULL);
        return dwError;
    }
    /*
     * Track state of "in quote" and "out quote" since
     * the same character begins/ends a string literal.
     * This is further complicated by escaped '\"' sequences
     * which are a literal quote in a quoted string.
     */
    if (lexHandle->state == REGLEX_STATE_IN_KEY)
    {
        RegLexAppendChar(lexHandle, inC);
    }
    else if (lexHandle->state != REGLEX_STATE_IN_QUOTE)
    {
        /* Close quote found, done with current string */
        lexHandle->curToken.token = REGLEX_QUOTE_BEGIN;
        lexHandle->state = REGLEX_STATE_IN_QUOTE;
        lexHandle->curToken.valueCursor = 0;
        lexHandle->curToken.pszValue[lexHandle->curToken.valueCursor] = '\0';
    }
    else
    {
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        lexHandle->curToken.token = REGLEX_REG_SZ;
        lexHandle->state = REGLEX_STATE_INIT;
        return dwError;
    }

    return dwError;
}
Exemple #11
0
DWORD
RegLexParseWhitespace(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state == REGLEX_STATE_IN_QUOTE ||
            lexHandle->state == REGLEX_STATE_IN_KEY)
    {
        RegLexAppendChar(lexHandle, inC);
    }
    else if (lexHandle->state == REGLEX_STATE_BINHEX_STR)
    {
        if (lexHandle->curToken.valueCursor > 0 &&
                lexHandle->curToken.valueCursor <= 2)
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_HEXPAIR;
        }
    }
    else
    {
        dwError = RegLexParseBinary(lexHandle);
        if (dwError || lexHandle->isToken)
        {
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            return dwError;
        }
        if (lexHandle->curToken.token != REGLEX_FIRST)
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
    }
    return dwError;
}
Exemple #12
0
DWORD
RegLexParseOpenBrace(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE &&
            lexHandle->state != REGLEX_STATE_IN_KEY)
    {
        lexHandle->curToken.token = REGLEX_ATTRIBUTES_BEGIN;
        if (lexHandle->eValueNameType == REGLEX_VALUENAME_ATTRIBUTES)
        {
            /* This is a problem, can't have { then another { */
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else if (!lexHandle->curToken.pszValue ||
                 !lexHandle->curToken.pszValue[0])
        {
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->curToken.token = REGLEX_ATTRIBUTES_BEGIN;
            lexHandle->eValueNameType = REGLEX_VALUENAME_ATTRIBUTES;
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.valueCursor = 0;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #13
0
DWORD
RegLexParseOpenBracket(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;

    if (lexHandle->curToken.token == REGLEX_PLAIN_TEXT)
    {
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        dwError = RegIOUnGetChar(ioHandle, NULL);
        return dwError;
    }
    if (lexHandle->state != REGLEX_STATE_IN_QUOTE)
    {
        lexHandle->curToken.token = REGLEX_KEY_PREFIX;
        if (lexHandle->state == REGLEX_STATE_IN_KEY)
        {
            /* This is a problem, can't have [ then another [ */
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        }
        else
        {
            lexHandle->curToken.token = REGLEX_KEY_PREFIX;
            lexHandle->state = REGLEX_STATE_IN_KEY;
            lexHandle->curToken.valueCursor = 0;
        }
    }
    else
    {
        RegLexAppendChar(lexHandle, inC);
    }
    return dwError;
}
Exemple #14
0
DWORD
RegLexParseNewline(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;
    CHAR prevC = '\0';
    BOOLEAN eof = 0;

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE)
    {
        /*
         * Throw out CR when not in a quoted string. CR/LF
         * is still handled correctly by this treatment.
         */
        if (inC == '\r')
        {
            return dwError;
        }
    }
    else
    {
        /*
         * Count CR/LF sequence in a quoted string as a single newline.
         * A bare CR is maintained, but not counted as a newline.
         */
        if (inC == '\r')
        {
            RegLexAppendChar(lexHandle, inC);
            dwError = RegIOGetChar(ioHandle, &inC, &eof);
            if (eof)
            {
                return dwError;
            }
            if (inC == '\n')
            {
                RegLexAppendChar(lexHandle, inC);
                lexHandle->parseLineNum++;
            }
            else
            {
                dwError = RegIOUnGetChar(ioHandle, &inC);
            }
        }
    }

    if (lexHandle->state != REGLEX_STATE_IN_QUOTE)
    {
        lexHandle->parseLineNum++;
    }

    /* Emit the final token in a BINHEX_STR sequence */
    if (lexHandle->state == REGLEX_STATE_BINHEX_STR)
    {
        /* Don't care about "\\n sequence */
        dwError = RegIOGetPrevChar(ioHandle, &prevC);
        if (dwError == ERROR_SUCCESS && prevC == '\\')
        {
            return dwError;
        }

        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        lexHandle->curToken.token = REGLEX_HEXPAIR_END;
        lexHandle->state = REGLEX_STATE_INIT;
        return dwError;
    }
    else if (lexHandle->tokenDataType == REGLEX_REG_STRING_ARRAY)
    {
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum;
        lexHandle->tokenDataType = REGLEX_FIRST;
        return dwError;
    }
    else if (lexHandle->state == REGLEX_STATE_DWORD)
    {
        if (lexHandle->curToken.valueCursor == 8)
        {
            lexHandle->isToken = TRUE;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            lexHandle->curToken.token = REGLEX_REG_DWORD;
            return dwError;
        }
        else
        {
            dwError = LWREG_ERROR_UNEXPECTED_TOKEN;
            lexHandle->curToken.lineNum = lexHandle->parseLineNum;
            return dwError;
        }
    }
    else if ((lexHandle->state == REGLEX_STATE_INIT ||
              lexHandle->state == REGLEX_STATE_INTEGER_RANGE) &&
             lexHandle->curToken.valueCursor > 0)
    {
        /*
         * This is "junk" accumulated so far, since no valid token start
         * has been found before the current end-of-line.
         */
        lexHandle->isToken = TRUE;
        lexHandle->curToken.lineNum = lexHandle->parseLineNum - 1;
        lexHandle->curToken.token = REGLEX_PLAIN_TEXT;
        return dwError;
    }
    else
    {
        /* Syntax error case... */
        /* Error needed */
    }
    return dwError;
}
Exemple #15
0
DWORD
RegLexParseBackslash(
    PREGLEX_ITEM lexHandle,
    HANDLE ioHandle,
    CHAR inC)
{
    DWORD dwError = 0;
    BOOLEAN eof = FALSE;

    if (lexHandle->state == REGLEX_STATE_BINHEX_STR ||
            lexHandle->tokenDataType == REGLEX_REG_STRING_ARRAY)
    {
        /* Eat line continuation character when in BINHEX state */
        dwError = RegIOGetChar(ioHandle, &inC, &eof);
        if (eof)
        {
            return dwError;
        }
        if (inC == '\r' || inC == '\n')
        {
            lexHandle->parseLineNum++;
            dwError = RegIOGetChar(ioHandle, &inC, &eof);
            if (eof)
            {
                return dwError;
            }
            if (inC != '\r' && inC != '\n')
            {
                dwError = RegIOUnGetChar(ioHandle, NULL);
            }
        }
        else
        {
            dwError = RegIOUnGetChar(ioHandle, NULL);
        }
    }

    if (lexHandle->state == REGLEX_STATE_IN_QUOTE)
    {
        /*
         * Treat sequence '\C'  (C=any character) as
         * the literal escaped character. Only handle backslashes
         * in this way when in quoted strings. When processing a
         * registry key value, this is a "bad thing" to do.
         * [HKEY_LOCAL_MACHINE\HARDWARE]
         * This processing in this case would be an escaped 'H', not
         * what is intended.
         */
        dwError = RegIOGetChar(ioHandle, &inC, &eof);
        if (!eof)
        {
            switch(inC)
            {
            case 'n':
                RegLexAppendChar(lexHandle, '\n');
                break;

            case 'r':
                RegLexAppendChar(lexHandle, '\r');
                break;

            case 't':
                RegLexAppendChar(lexHandle, '\t');
                break;

            case 'a':
                RegLexAppendChar(lexHandle, '\a');
                break;

            case 'v':
                RegLexAppendChar(lexHandle, '\v');
                break;

            case 'f':
                RegLexAppendChar(lexHandle, '\f');
                break;

            case '\\':
                RegLexAppendChar(lexHandle, '\\');
                break;

            case '"':
                RegLexAppendChar(lexHandle, '"');
                break;

            default:
                RegLexAppendChar(lexHandle, '\\');
                RegLexAppendChar(lexHandle, inC);
                break;
            }
        }
    }
    else if (lexHandle->state == REGLEX_STATE_IN_KEY)
    {
        RegLexAppendChar(lexHandle, '\\');
    }
    else if (lexHandle->state != REGLEX_STATE_BINHEX_STR) {
        RegLexAppendChar(lexHandle, '\\');
    }
    lexHandle->curToken.lineNum = lexHandle->parseLineNum;
    return dwError;
}