Пример #1
0
void eat2(enum token t, const char *fnam, int line, int die)
{
	if(t != curtok){
		const int ident = curtok == token_identifier;
		parse_had_error = 1;

		warn_at_print_error(NULL,
				"expecting token %s, got %s %s%s%s(%s:%d)",
				token_to_str(t), token_to_str(curtok),
				ident ? "\"" : "",
				ident ? token_current_spel_peek() : "",
				ident ? "\" " : "",
				fnam, line);

		if(die || --cc1_error_limit <= 0)
			exit(1);

		/* XXX: we continue here, assuming we had the token anyway */
	}else{
		if(curtok_save != token_unknown){
			curtok = curtok_save;
			curtok_save = token_unknown;
		}else{
			nexttoken();
		}
	}
}
Пример #2
0
HRESULT assembly_get_pubkey_token(ASSEMBLY *assembly, LPWSTR *token)
{
    ULONG i, size;
    LONG offset;
    BYTE *hashdata, *pubkey, *ptr;
    HCRYPTPROV crypt;
    HCRYPTHASH hash;
    BYTE tokbytes[BYTES_PER_TOKEN];
    HRESULT hr = E_FAIL;
    LPWSTR tok;
    DWORD idx;

    *token = NULL;

    offset = assembly->tables[TableFromToken(mdtAssembly)].offset;
    if (offset == -1)
        return E_FAIL;

    ptr = assembly_data_offset(assembly, offset);
    if (!ptr)
        return E_FAIL;

    ptr += FIELD_OFFSET(ASSEMBLYTABLE, PublicKey);
    if (assembly->blobsz == sizeof(DWORD))
        idx = *(DWORD *)ptr;
    else
        idx = *(WORD *)ptr;

    pubkey = assembly_get_blob(assembly, idx, &size);

    if (!CryptAcquireContextA(&crypt, NULL, NULL, PROV_RSA_FULL,
                              CRYPT_VERIFYCONTEXT))
        return E_FAIL;

    if (!CryptCreateHash(crypt, CALG_SHA1, 0, 0, &hash))
        return E_FAIL;

    if (!CryptHashData(hash, pubkey, size, 0))
        return E_FAIL;

    size = 0;
    if (!CryptGetHashParam(hash, HP_HASHVAL, NULL, &size, 0))
        return E_FAIL;

    hashdata = HeapAlloc(GetProcessHeap(), 0, size);
    if (!hashdata)
    {
        hr = E_OUTOFMEMORY;
        goto done;
    }

    if (!CryptGetHashParam(hash, HP_HASHVAL, hashdata, &size, 0))
        goto done;

    for (i = size - 1; i >= size - 8; i--)
        tokbytes[size - i - 1] = hashdata[i];

    tok = HeapAlloc(GetProcessHeap(), 0, (TOKEN_LENGTH + 1) * sizeof(WCHAR));
    if (!tok)
    {
        hr = E_OUTOFMEMORY;
        goto done;
    }

    token_to_str(tokbytes, tok);

    *token = tok;
    hr = S_OK;

done:
    HeapFree(GetProcessHeap(), 0, hashdata);
    CryptDestroyHash(hash);
    CryptReleaseContext(crypt, 0);

    return hr;
}
Пример #3
0
char *curtok_to_identifier(int *alloc)
{
	switch(curtok){
		case token_do:
		case token_if:
		case token_else:
		case token_while:
		case token_for:
		case token_break:
		case token_return:
		case token_switch:
		case token_case:
		case token_default:
		case token_continue:
		case token_goto:
		case token_asm:
		case token_sizeof:
		case token_typeof:
		case token__Generic:
		case token__Static_assert:
		case token_extern:
		case token_static:
		case token_auto:
		case token_register:
		case token__Alignof:
		case token__Alignas:
		case token_inline:
		case token__Noreturn:
		case token_const:
		case token_volatile:
		case token_restrict:
		case token_void:
		case token_char:
		case token_short:
		case token_int:
		case token_long:
		case token_float:
		case token_double:
		case token__Bool:
		case token_signed:
		case token_unsigned:
		case token_typedef:
		case token_struct:
		case token_union:
		case token_enum:
		case token___builtin_va_list:
		case token_attribute:
		case token___extension__:
		case token___auto_type:
		case token___label__:
			/* we can stringify these */
			*alloc = 0;
			return token_to_str(curtok);
		case token_identifier:
			*alloc = 1;
			return token_current_spel();

		case token_integer:
		case token_floater:
		case token_character:
		case token_string:
		case token_elipsis:
		case token_open_paren:
		case token_open_block:
		case token_open_square:
		case token_close_paren:
		case token_close_block:
		case token_close_square:
		case token_comma:
		case token_semicolon:
		case token_colon:
		case token_plus:
		case token_minus:
		case token_multiply:
		case token_divide:
		case token_modulus:
		case token_increment:
		case token_decrement:
		case token_assign:
		case token_dot:
		case token_eq:
		case token_le:
		case token_lt:
		case token_ge:
		case token_gt:
		case token_ne:
		case token_not:
		case token_bnot:
		case token_andsc:
		case token_and:
		case token_orsc:
		case token_or:
		case token_xor:
		case token_question:
		case token_plus_assign:
		case token_minus_assign:
		case token_multiply_assign:
		case token_divide_assign:
		case token_modulus_assign:
		case token_not_assign:
		case token_bnot_assign:
		case token_and_assign:
		case token_or_assign:
		case token_xor_assign:
		case token_shiftl:
		case token_shiftr:
		case token_shiftl_assign:
		case token_shiftr_assign:
		case token_ptr:
		case token_eof:
		case token_unknown:
			break;
	}
	return NULL;
}