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

📄 asn1p_y.y

📁 ASN.1解析解码工具,可以解析各种ASN.1格式的文件,并对相应的BER文件解码
💻 Y
📖 第 1 页 / 共 4 页
字号:
TypeDeclaration:	NSTD_IndirectMarker TypeDeclarationSet {		$$ = $2;		$$->marker.flags |= $1;		if(($$->marker.flags & EM_INDIRECT)		&& ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {			fprintf(stderr,				"INFO: Directive <ASN1C:RepresentAsPointer> "				"applied to %s at line %d\n",				ASN_EXPR_TYPE2STR($$->expr_type)					?  ASN_EXPR_TYPE2STR($$->expr_type)					: "member",				$$->_lineno			);		}	}	;TypeDeclarationSet:	DefinedType {		$$ = $1;	}	| TOK_CHOICE '{' AlternativeTypeLists '}' {		$$ = $3;		assert($$->expr_type == A1TC_INVALID);		$$->expr_type = ASN_CONSTR_CHOICE;		$$->meta_type = AMT_TYPE;	}	| TOK_SEQUENCE '{' optComponentTypeLists '}' {		$$ = $3;		assert($$->expr_type == A1TC_INVALID);		$$->expr_type = ASN_CONSTR_SEQUENCE;		$$->meta_type = AMT_TYPE;	}	| TOK_SET '{' optComponentTypeLists '}' {		$$ = $3;		assert($$->expr_type == A1TC_INVALID);		$$->expr_type = ASN_CONSTR_SET;		$$->meta_type = AMT_TYPE;	}	| TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {		$$ = NEW_EXPR();		checkmem($$);		$$->constraints = $2;		$$->expr_type = ASN_CONSTR_SEQUENCE_OF;		$$->meta_type = AMT_TYPE;		$6->Identifier = $4;		$6->tag = $5;		asn1p_expr_add($$, $6);	}	| TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {		$$ = NEW_EXPR();		checkmem($$);		$$->constraints = $2;		$$->expr_type = ASN_CONSTR_SET_OF;		$$->meta_type = AMT_TYPE;		$6->Identifier = $4;		$6->tag = $5;		asn1p_expr_add($$, $6);	}	| TOK_ANY 					{		$$ = NEW_EXPR();		checkmem($$);		$$->expr_type = ASN_TYPE_ANY;		$$->meta_type = AMT_TYPE;	}	| TOK_ANY TOK_DEFINED TOK_BY Identifier		{		int ret;		$$ = NEW_EXPR();		checkmem($$);		$$->reference = asn1p_ref_new(yylineno);		ret = asn1p_ref_add_component($$->reference,			$4, RLT_lowercase);		checkmem(ret == 0);		$$->expr_type = ASN_TYPE_ANY;		$$->meta_type = AMT_TYPE;	}	| TOK_INSTANCE TOK_OF ComplexTypeReference {		$$ = NEW_EXPR();		checkmem($$);		$$->reference = $3;		$$->expr_type = A1TC_INSTANCE;		$$->meta_type = AMT_TYPE;	}	;/* * A type name consisting of several components. * === EXAMPLE === * === EOF === */ComplexTypeReference:	TOK_typereference {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);		checkmem(ret == 0);		free($1);	}	| TOK_typereference '.' TypeRefName {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);		checkmem(ret == 0);		ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);		checkmem(ret == 0);		free($1);	}	| ObjectClassReference '.' TypeRefName {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);		checkmem(ret == 0);		ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);		checkmem(ret == 0);		free($1);	}	| TOK_typereference '.' Identifier {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);		checkmem(ret == 0);		ret = asn1p_ref_add_component($$, $3, RLT_lowercase);		checkmem(ret == 0);		free($1);	}	| ObjectClassReference {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);		free($1);		checkmem(ret == 0);	}	| ObjectClassReference '.' ComplexTypeReferenceAmpList {		int ret;		$$ = $3;		ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);		free($1);		checkmem(ret == 0);		/*		 * Move the last element infront.		 */		{			struct asn1p_ref_component_s tmp_comp;			tmp_comp = $$->components[$$->comp_count-1];			memmove(&$$->components[1],				&$$->components[0],				sizeof($$->components[0])				* ($$->comp_count - 1));			$$->components[0] = tmp_comp;		}	}	;ComplexTypeReferenceAmpList:	ComplexTypeReferenceElement {		int ret;		$$ = asn1p_ref_new(yylineno);		checkmem($$);		ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);		free($1.name);		checkmem(ret == 0);	}	| ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {		int ret;		$$ = $1;		ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);		free($3.name);		checkmem(ret == 0);	}	;ComplexTypeReferenceElement:	PrimitiveFieldReference;PrimitiveFieldReference:	/* "&Type1" */	TOK_typefieldreference {		$$.lex_type = RLT_AmpUppercase;		$$.name = $1;	}	/* "&id" */	| TOK_valuefieldreference {		$$.lex_type = RLT_Amplowercase;		$$.name = $1;	}	;FieldName:	/* "&Type1" */	TOK_typefieldreference {		$$ = asn1p_ref_new(yylineno);		asn1p_ref_add_component($$, $1, RLT_AmpUppercase);	}	| FieldName '.' TOK_typefieldreference {		$$ = $$;		asn1p_ref_add_component($$, $3, RLT_AmpUppercase);	}	| FieldName '.' TOK_valuefieldreference {		$$ = $$;		asn1p_ref_add_component($$, $3, RLT_Amplowercase);	}	;DefinedObjectClass:	TOK_capitalreference {		$$ = asn1p_ref_new(yylineno);		asn1p_ref_add_component($$, $1, RLT_CAPITALS);	}/*	| TypeRefName '.' TOK_capitalreference {		$$ = asn1p_ref_new(yylineno);		asn1p_ref_add_component($$, $1, RLT_AmpUppercase);		asn1p_ref_add_component($$, $3, RLT_CAPITALS);	}*/	;/* * === EXAMPLE === * value INTEGER ::= 1 * === EOF === */ValueDefinition:	Identifier DefinedType TOK_PPEQ Value {		$$ = $2;		assert($$->Identifier == NULL);		$$->Identifier = $1;		$$->meta_type = AMT_VALUE;		$$->value = $4;	}	;Value:	SimpleValue	| DefinedValue	| Identifier ':' Value {		$$ = asn1p_value_fromint(0);		checkmem($$);		$$->type = ATV_CHOICE_IDENTIFIER;		$$->value.choice_identifier.identifier = $1;		$$->value.choice_identifier.value = $3;	}	| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {		$$ = asn1p_value_frombuf($3.buf, $3.len, 0);		checkmem($$);		$$->type = ATV_UNPARSED;	}	| TOK_NULL {		$$ = asn1p_value_fromint(0);		checkmem($$);		$$->type = ATV_NULL;	}	;SimpleValue:	TOK_FALSE {		$$ = asn1p_value_fromint(0);		checkmem($$);		$$->type = ATV_FALSE;	}	| TOK_TRUE {		$$ = asn1p_value_fromint(0);		checkmem($$);		$$->type = ATV_TRUE;	}	| TOK_bstring {		$$ = _convert_bitstring2binary($1, 'B');		checkmem($$);	}	| TOK_hstring {		$$ = _convert_bitstring2binary($1, 'H');		checkmem($$);	}	| RestrictedCharacterStringValue {		$$ = $$;	}	| SignedNumber {		$$ = $1;	}	;DefinedValue:	Identifier {		asn1p_ref_t *ref;		int ret;		ref = asn1p_ref_new(yylineno);		checkmem(ref);		ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);		checkmem(ret == 0);		$$ = asn1p_value_fromref(ref, 0);		checkmem($$);		free($1);	}	| TypeRefName '.' Identifier {		asn1p_ref_t *ref;		int ret;		ref = asn1p_ref_new(yylineno);		checkmem(ref);		ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);		checkmem(ret == 0);		ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);		checkmem(ret == 0);		$$ = asn1p_value_fromref(ref, 0);		checkmem($$);		free($1);		free($3);	}	;RestrictedCharacterStringValue:	TOK_cstring {		$$ = asn1p_value_frombuf($1.buf, $1.len, 0);		checkmem($$);	}	| TOK_tuple {		$$ = asn1p_value_fromint($1);		checkmem($$);		$$->type = ATV_TUPLE;	}	| TOK_quadruple {		$$ = asn1p_value_fromint($1);		checkmem($$);		$$->type = ATV_QUADRUPLE;	}	/*	| '{' TOK_number ',' TOK_number '}' {		asn1c_integer_t v = ($2 << 4) + $4;		if($2 > 7) return yyerror("X.680:2003, #37.14 "				"mandates 0..7 range for Tuple's TableColumn");		if($4 > 15) return yyerror("X.680:2003, #37.14 "				"mandates 0..15 range for Tuple's TableRow");		$$ = asn1p_value_fromint(v);		checkmem($$);		$$->type = ATV_TUPLE;	}	| '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {		asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;		if($2 > 127) return yyerror("X.680:2003, #37.12 "				"mandates 0..127 range for Quadruple's Group");		if($4 > 255) return yyerror("X.680:2003, #37.12 "				"mandates 0..255 range for Quadruple's Plane");		if($6 > 255) return yyerror("X.680:2003, #37.12 "				"mandates 0..255 range for Quadruple's Row");		if($8 > 255) return yyerror("X.680:2003, #37.12 "				"mandates 0..255 range for Quadruple's Cell");		$$ = asn1p_value_fromint(v);		checkmem($$);		$$->type = ATV_QUADRUPLE;	}	*/	;Opaque:	TOK_opaque {		$$.len = $1.len + 1;		$$.buf = malloc($$.len + 1);		checkmem($$.buf);		$$.buf[0] = '{';		memcpy($$.buf + 1, $1.buf, $1.len);		$$.buf[$$.len] = '\0';		free($1.buf);	}	| Opaque TOK_opaque {		int newsize = $1.len + $2.len;		char *p = malloc(newsize + 1);		checkmem(p);		memcpy(p         , $1.buf, $1.len);		memcpy(p + $1.len, $2.buf, $2.len);		p[newsize] = '\0';		free($1.buf);		free($2.buf);		$$.buf = p;		$$.len = newsize;	}	;BasicTypeId:	TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }	| TOK_NULL { $$ = ASN_BASIC_NULL; }	| TOK_REAL { $$ = ASN_BASIC_REAL; }	| BasicTypeId_UniverationCompatible { $$ = $1; }	| TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }	| TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }	| TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }	| TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }	| TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }	| TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }	| TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }	| TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }	| BasicString { $$ = $1; }	;/* * A type identifier which may be used with "{ a(1), b(2) }" clause. */BasicTypeId_UniverationCompatible:	TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }	| TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }	| TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }	;BasicType:	BasicTypeId {		$$ = NEW_EXPR();		checkmem($$);		$$->expr_type = $1;		$$->meta_type = AMT_TYPE;	}	| BasicTypeId_UniverationCompatible UniverationDefinition {		if($2) {			$$ = $2;		} else {			$$ = NEW_EXPR();			checkmem($$);		}		$$->expr_type = $1;		$$->meta_type = AMT_TYPE;	}	;BasicString:	TOK_BMPString { $$ = ASN_STRING_BMPString; }	| TOK_GeneralString {		$$ = ASN_STRING_GeneralString;		fprintf(stderr, "WARNING: GeneralString is not fully supported\n");	}	| TOK_GraphicString {		$$ = ASN_STRING_GraphicString;		fprintf(stderr, "WARNING: GraphicString is not fully supported\n");	}	| TOK_IA5String { $$ = ASN_STRING_IA5String; }	| TOK_ISO646String { $$ = ASN_STRING_ISO646String; }	| TOK_NumericString { $$ = ASN_STRING_NumericString; }	| TOK_PrintableString { $$ = ASN_STRING_PrintableString; }	| TOK_T61String {		$$ = ASN_STRING_T61String;		fprintf(stderr, "WARNING: T61String is not fully supported\n");	}	| TOK_TeletexString { $$ = ASN_STRING_TeletexString; }	| TOK_UniversalString { $$ = ASN_STRING_UniversalString; }	| TOK_UTF8String { $$ = ASN_STRING_UTF8String; }	| TOK_VideotexString {		$$ = ASN_STRING_VideotexString;		fprintf(stderr, "WARNING: VideotexString is not fully supported\n");	}	| TOK_VisibleString { $$ = ASN_STRING_VisibleString; }	| TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }	;/* * Data type constraints. */Union:		'|' | TOK_UNION;Intersection:	'^' | TOK_INTERSECTION;Except:		      TOK_EXCEPT;optConstraints:	{ $$ = 0; }	| Constraint {		$$ = $1;	}	;Constraint:	SubtypeConstraint	| '(' GeneralConstraint ')' {		$$ = $2;	}	;SubtypeConstraint:	SetOfConstraints {		CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);	}	| TOK_SIZE '('  ElementSetSpecs ')' {		/*		 * This is a special case, for compatibility purposes.		 * It goes without parentheses.		 */		CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);	}	;SetOfConstraints:	'(' ElementSetSpecs ')' {		$$ = $2;	}	| SetOfConstraints '(' ElementSetSpecs ')' {		CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);	}	;ElementSetSpecs:	TOK_ThreeDots  {		$$ = asn1p_constraint_new(yylineno);		$$->type = ACT_EL_EXT;	}	| ElementSetSpec {		$$ = $1;	}	| ElementSetSpec ',' TOK_ThreeDots {		asn1p_constraint_t *ct;		ct = asn1p_constraint_new(yylineno);		ct->type = ACT_EL_EXT;		CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);	}	| ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {		asn1p_constraint_t *ct;		ct = asn1p_constraint_new(yylineno);		ct->type = ACT_EL_EXT;		CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);		ct = $$;		CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);	}	;ElementSetSpec:	ConstraintSubtypeElement {		$$ = $1;	}	| TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {		CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);	}	| ElementSetSpec Union ConstraintSubtypeElement {		CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);	}	| ElementSetSpec Intersection ConstraintSubtypeElement {		CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);	}	| ConstraintSubtypeElement Except ConstraintSubtypeElement {		CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);	}	;ConstraintSubtypeElement:	ConstraintSpec '(' ElementSetSpecs ')' {		int ret;		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = $1;		ret = asn1p_constraint_insert($$, $3);		checkmem(ret == 0);	}	| '(' ElementSetSpecs ')' {		int ret;		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = ACT_CA_SET;		ret = asn1p_constraint_insert($$, $2);		checkmem(ret == 0);	}	| SingleValue {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = ACT_EL_VALUE;		$$->value = $1;	}	| ContainedSubtype {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = ACT_EL_TYPE;		$$->containedSubtype = $1;	}	| SingleValue ConstraintRangeSpec SingleValue {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = $2;		$$->range_start = $1;		$$->range_stop = $3;	}	| TOK_MIN ConstraintRangeSpec SingleValue {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = $2;		$$->range_start = asn1p_value_fromint(-123);		$$->range_stop = $3;		$$->range_start->type = ATV_MIN;	}	| SingleValue ConstraintRangeSpec TOK_MAX {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = $2;		$$->range_start = $1;		$$->range_stop = asn1p_value_fromint(321);		$$->range_stop->type = ATV_MAX;	}	| TOK_MIN ConstraintRangeSpec TOK_MAX {		$$ = asn1p_constraint_new(yylineno);		checkmem($$);		$$->type = $2;		$$->range_start = asn1p_value_fromint(-123);		$$->range_stop = asn1p_value_fromint(321);		$$->range_start->type = ATV_MIN;		$$->range_stop->type = ATV_MAX;	}	| InnerTypeConstraint {		$$ = $1;	}	;ConstraintSpec:	TOK_SIZE {		$$ = ACT_CT_SIZE;	}	| TOK_FROM {		$$ = ACT_CT_FROM;	}

⌨️ 快捷键说明

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