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

📄 asn1print.c

📁 ASN.1解析解码工具,可以解析各种ASN.1格式的文件,并对相应的BER文件解码
💻 C
📖 第 1 页 / 共 2 页
字号:
		asn1constraint_range_free(range);		return 0;	}	switch(type) {	case ACT_CT_FROM: printf("(FROM("); break;	case ACT_CT_SIZE: printf("(SIZE("); break;	default: printf("("); break;	}	for(i = -1; i < range->el_count; i++) {		asn1cnst_range_t *r;		if(i == -1) {			if(range->el_count) continue;			r = range;		} else {			r = range->elements[i];		}		if(i > 0) {			printf(" | ");		}		asn1print_crange_value(&r->left, as_char);		if(r->left.type != r->right.type		|| r->left.value != r->right.value) {			printf("..");			asn1print_crange_value(&r->right, as_char);		}	}	if(range->extensible)		printf(",...");	printf(type==ACT_EL_RANGE?")":"))");	if(range->empty_constraint)		printf(":Empty!");	asn1constraint_range_free(range);	return 0;}intasn1print_constraint_explain(asn1p_expr_type_e expr_type,		asn1p_constraint_t *ct, int s_PV) {	asn1print_constraint_explain_type(expr_type, ct, ACT_EL_RANGE, s_PV);	printf(" ");	asn1print_constraint_explain_type(expr_type, ct, ACT_CT_SIZE, s_PV);	printf(" ");	asn1print_constraint_explain_type(expr_type, ct, ACT_CT_FROM, s_PV);	return 0;}intasn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) {	int SEQ_OF = 0;	if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))		INDENT("-- #line %d\n", tc->_lineno);	/* Reconstruct compiler directive information */	if((tc->marker.flags & EM_INDIRECT)	&& (tc->marker.flags & EM_OMITABLE) != EM_OMITABLE) {		if((flags & APF_NOINDENT))			printf(" --<ASN1C.RepresentAsPointer>-- ");		else			INDENT("--<ASN1C.RepresentAsPointer>--\n");	}	if(tc->Identifier	&& (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE)	 || level == 0))		INDENT("%s", tc->Identifier);	if(tc->lhs_params) {		asn1print_params(tc->lhs_params, flags);	}	if(tc->meta_type != AMT_VALUE	&& tc->meta_type != AMT_VALUESET	&& tc->expr_type != A1TC_EXTENSIBLE) {		if(level) {			if(tc->Identifier && !(flags & APF_NOINDENT))				printf("\t");		} else {			printf(" ::=");		}	}	if(tc->tag.tag_class) {		printf(" ");		asn1print_tag(tc, flags);	}	switch(tc->expr_type) {	case A1TC_EXTENSIBLE:		if(tc->value) {			printf("!");			asn1print_value(tc->value, flags);		}		break;	case A1TC_COMPONENTS_OF:		SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */		printf("    COMPONENTS OF");		break;	case A1TC_REFERENCE:	case A1TC_UNIVERVAL:		break;	case A1TC_CLASSDEF:		printf(" CLASS");		break;/*	case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS: */	case A1TC_CLASSFIELD_TFS	:	/* TypeFieldSpec */
	case A1TC_CLASSFIELD_FTVFS:		/* FixedTypeValueFieldSpec */
	case A1TC_CLASSFIELD_VTVFS:		/* VariableTypeValueFieldSpec */
	case A1TC_CLASSFIELD_FTVSFS:		/* FixedTypeValueSetFieldSpec */
	case A1TC_CLASSFIELD_VTVSFS:		/* VariableTypeValueSetFieldSpec */
	case A1TC_CLASSFIELD_OFS:		/* ObjectFieldSpec */
	case A1TC_CLASSFIELD_OSFS:		/* ObjectSetFieldSpec */
		/* Nothing to print here */		break;	case ASN_CONSTR_SET_OF:	case ASN_CONSTR_SEQUENCE_OF:		SEQ_OF = 1;		if(tc->expr_type == ASN_CONSTR_SET_OF)			printf(" SET");		else			printf(" SEQUENCE");		if(tc->constraints) {			printf(" ");			asn1print_constraint(tc->constraints, flags);		}		printf(" OF");		break;	case A1TC_VALUESET:		break;	default:		{			char *p = ASN_EXPR_TYPE2STR(tc->expr_type);			printf(" %s", p?p:"<unknown type!>");		}		break;	}	/*	 * Put the name of the referred type.	 */	if(tc->reference) {		printf(" ");		asn1print_ref(tc->reference, flags);	}	if(tc->meta_type == AMT_VALUESET && level == 0)		printf(" ::=");	/*	 * Display the descendants (children) of the current type.	 */	if(TQ_FIRST(&(tc->members))	|| (tc->expr_type & ASN_CONSTR_MASK)	|| tc->meta_type == AMT_OBJECT	|| tc->meta_type == AMT_OBJECTCLASS	|| tc->meta_type == AMT_OBJECTFIELD	) {		asn1p_expr_t *se;	/* SubExpression */		int put_braces = (!SEQ_OF) /* Don't need 'em, if SET OF... */			&& (tc->meta_type != AMT_OBJECTFIELD);		if(put_braces) {			if(flags & APF_NOINDENT) {				printf("{");				if(!TQ_FIRST(&tc->members))					printf("}");			} else {				printf(" {");				if(TQ_FIRST(&tc->members))					printf("\n");				else					printf(" }");			}		}		TQ_FOR(se, &(tc->members), next) {			/*			 * Print the expression as it were a stand-alone type.			 */			asn1print_expr(asn, mod, se, flags, level + 1);			if((se->marker.flags & EM_DEFAULT) == EM_DEFAULT) {				printf(" DEFAULT ");				asn1print_value(se->marker.default_value, flags);			} else if((se->marker.flags & EM_OPTIONAL)					== EM_OPTIONAL) {				printf(" OPTIONAL");			}			if(TQ_NEXT(se, next)) {				printf(",");				if(!(flags & APF_NOINDENT))					INDENT("\n");			}		}		if(put_braces && TQ_FIRST(&tc->members)) {			if(!(flags & APF_NOINDENT))				printf("\n");			INDENT("}");		}	}	if(tc->with_syntax) {		printf(" WITH SYNTAX {");		asn1print_with_syntax(tc->with_syntax, flags);		printf("}\n");	}	/* Right hand specialization */	if(tc->rhs_pspecs) {		asn1p_expr_t *se;		printf("{");		TQ_FOR(se, &(tc->rhs_pspecs->members), next) {			asn1print_expr(asn, mod, se, flags, level + 1);			if(TQ_NEXT(se, next)) printf(", ");		}		printf("}");	}	if(!SEQ_OF && tc->constraints) {		printf(" ");		if(tc->meta_type == AMT_VALUESET)			printf("{");		asn1print_constraint(tc->constraints, flags);		if(tc->meta_type == AMT_VALUESET)			printf("}");	}	if(tc->unique) {		printf(" UNIQUE");	}	if(tc->meta_type == AMT_VALUE	&& tc->expr_type != A1TC_EXTENSIBLE) {		if(tc->expr_type == A1TC_UNIVERVAL) {			if(tc->value) {				printf("(");				asn1print_value(tc->value, flags);				printf(")");			}		} else {			if(level == 0) printf(" ::= ");			asn1print_value(tc->value, flags);		}	}	/*	 * The following section exists entirely for debugging.	 */	if(flags & APF_PRINT_CONSTRAINTS	&& tc->expr_type != A1TC_EXTENSIBLE) {		asn1p_expr_t *top_parent;		if(tc->combined_constraints) {			printf("\n-- Combined constraints: ");			asn1print_constraint(tc->combined_constraints, flags);		}		top_parent = asn1f_find_terminal_type_ex(asn, tc);		if(top_parent) {			printf("\n-- Practical constraints (%s): ",				top_parent->Identifier);			asn1print_constraint_explain(top_parent->expr_type,				tc->combined_constraints, 0);			printf("\n-- PER-visible constraints (%s): ",				top_parent->Identifier);			asn1print_constraint_explain(top_parent->expr_type,				tc->combined_constraints, 1);		}		printf("\n");	}	if(flags & APF_PRINT_CLASS_MATRIX	&& tc->expr_type == A1TC_CLASSDEF) do {		int r, col, maxidlen;		if(tc->object_class_matrix.rows == 0) {			printf("\n-- Class matrix is empty");			break;		}		printf("\n-- Class matrix has %d entr%s:\n",				tc->object_class_matrix.rows,				tc->object_class_matrix.rows==1 ? "y" : "ies");		maxidlen = tc->object_class_matrix.max_identifier_length;		for(r = -1; r < tc->object_class_matrix.rows; r++) {			struct asn1p_ioc_row_s *row;			row = tc->object_class_matrix.row[r<0?0:r];			if(r < 0) printf("--    %s", r > 9 ? " " : "");			else printf("-- [%*d]", r > 9 ? 2 : 1, r+1);			for(col = 0; col < row->columns; col++) {				struct asn1p_ioc_cell_s *cell;				cell = &row->column[col];				if(r < 0) {					printf("[%*s]", maxidlen,						cell->field->Identifier);					continue;				}				if(!cell->value) {					printf(" %*s ", maxidlen, "<no entry>");					continue;				}				printf(" %*s ", maxidlen,					cell->value->Identifier);			}			printf("\n");		}	} while(0);	if(flags & APF_PRINT_CLASS_MATRIX	&& tc->lhs_params) do {		int i;		if(tc->specializations.pspecs_count == 0) {			printf("\n-- No specializations found\n");			break;		}		printf("\n-- Specializations list has %d entr%s:\n",			tc->specializations.pspecs_count,			tc->specializations.pspecs_count == 1 ? "y" : "ies");		for(i = 0; i < tc->specializations.pspecs_count; i++) {			asn1p_expr_t *se;			struct asn1p_pspec_s *pspec;			pspec = &tc->specializations.pspec[i];			printf("-- ");			TQ_FOR(se, &(pspec->rhs_pspecs->members), next) {				asn1print_expr(asn, mod, se, flags, level+1);			}			printf("\n");		}	} while(0);	return 0;}intasn1print_expr_dtd(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, enum asn1print_flags flags, int level) {	asn1p_expr_t *se;	int expr_unordered = 0;	int dont_involve_children = 0;	switch(expr->meta_type) {	case AMT_TYPE:	case AMT_TYPEREF:		break;	default:		if(expr->expr_type == A1TC_UNIVERVAL)			break;		return 0;	}	if(!expr->Identifier) return 0;	if(flags & APF_LINE_COMMENTS)		INDENT("<!-- #line %d -->\n", expr->_lineno);	INDENT("<!ELEMENT %s", expr->Identifier);	if(expr->expr_type == A1TC_REFERENCE) {		se = asn1f_find_terminal_type_ex(asn, expr);		if(!se) {			printf(" (ANY)");			return 0;		}		expr = se;		dont_involve_children = 1;	}	if(expr->expr_type == ASN_CONSTR_CHOICE	|| expr->expr_type == ASN_CONSTR_SEQUENCE_OF	|| expr->expr_type == ASN_CONSTR_SET_OF	|| expr->expr_type == ASN_CONSTR_SET	|| expr->expr_type == ASN_BASIC_INTEGER	|| expr->expr_type == ASN_BASIC_ENUMERATED) {		expr_unordered = 1;	}	if(TQ_FIRST(&expr->members)) {		int extensible = 0;		printf(" (");		TQ_FOR(se, &(expr->members), next) {			if(se->expr_type == A1TC_EXTENSIBLE) {				extensible = 1;				continue;			} else if(!se->Identifier					&& se->expr_type == A1TC_REFERENCE) {				asn1print_ref(se->reference, flags);			} else if(se->Identifier) {				printf("%s", se->Identifier);			} else {				printf("ANY");			}			if(expr->expr_type != ASN_CONSTR_SET			&& expr->expr_type != ASN_CONSTR_CHOICE			&& expr->expr_type != ASN_BASIC_INTEGER			&& expr->expr_type != ASN_BASIC_ENUMERATED) {				if(expr_unordered)					printf("*");				else if(se->marker.flags)					printf("?");			}			if(TQ_NEXT(se, next)			&& TQ_NEXT(se, next)->expr_type != A1TC_EXTENSIBLE) {				printf(expr_unordered?"|":", ");			}		}		if(extensible) {			printf(expr_unordered?"|":", ");			printf("ANY");			if(expr->expr_type != ASN_CONSTR_SET			&& expr->expr_type != ASN_CONSTR_CHOICE			&& expr->expr_type != ASN_BASIC_INTEGER			&& expr->expr_type != ASN_BASIC_ENUMERATED)				printf("*");		}		printf(")");		if(expr->expr_type == ASN_CONSTR_SET)			printf("*");	} else switch(expr->expr_type) {	case ASN_BASIC_BOOLEAN:		printf(" (true|false)");		break;	case ASN_CONSTR_CHOICE:	case ASN_CONSTR_SET:	case ASN_CONSTR_SET_OF:	case ASN_CONSTR_SEQUENCE:	case ASN_CONSTR_SEQUENCE_OF:	case ASN_BASIC_NULL:	case A1TC_UNIVERVAL:		printf(" EMPTY");		break;	case ASN_TYPE_ANY:		printf(" ANY");		break;	case ASN_BASIC_BIT_STRING:	case ASN_BASIC_OCTET_STRING:	case ASN_BASIC_OBJECT_IDENTIFIER:	case ASN_BASIC_RELATIVE_OID:	case ASN_BASIC_INTEGER:	case ASN_BASIC_UTCTime:	case ASN_BASIC_GeneralizedTime:	case ASN_STRING_NumericString:	case ASN_STRING_PrintableString:		printf(" (#PCDATA)");		break;	case ASN_STRING_VisibleString:	case ASN_STRING_ISO646String:		/* Entity references, but not XML elements may be present */		printf(" (#PCDATA)");		break;	case ASN_BASIC_REAL:		/* e.g. <MINUS-INFINITY/> */	case ASN_BASIC_ENUMERATED:	/* e.g. <enumIdentifier1/> */	default:		/*		 * XML elements are allowed.		 * For example, a UTF8String may contain "<bel/>".		 */		printf(" ANY");	}	printf(">\n");	/*	 * Display the descendants (children) of the current type.	 */	if(!dont_involve_children) {		TQ_FOR(se, &(expr->members), next) {			if(se->expr_type == A1TC_EXTENSIBLE) continue;			asn1print_expr_dtd(asn, mod, se, flags, level + 1);		}	}	return 0;}

⌨️ 快捷键说明

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