开源asn1c使用

下载

master版本:https://github.com/vlm/asn1c,
aper版本:https://github.com/mouse07410/asn1c/

编译安装

参照文件INSTALL.md

解析H.323协议

下载asn文件

从wireshark源码获取文件 :
H235-SECURITY-MESSAGES.asn
H323-MESSAGES.asn
MULTIMEDIA-SYSTEM-CONTROL.asn、

生成c文件

mater版本

  1. 将H235-SECURITY-MESSAGES.asn MULTIMEDIA-SYSTEM-CONTROL.asn放到/usr/local/share/asn1/standard-modules
  2. asn1c -fcompound-names -gen-autotools -pdu=RasMessage H323-MESSAGES.asn
    asn1c -fcompound-names -gen-autotools -pdu=MultimediaSystemControlMessage H323-MESSAGES.asn
  3. 修改InfoRequestResponse.h
    106行:将如下语句提到前面:

typedef struct InfoRequestResponse__perCallInfo__Member__pdu__Member {
			H323_UU_PDU_t	 h323pdu;
			BOOLEAN_t	 sent;
			
			/* Context for parsing across buffer boundaries */
			asn_struct_ctx_t _asn_ctx;
		} InfoRequestResponse__perCallInfo__Member__pdu__Member;
  1. 编译
    autoreconf -ivf && ./configure && make -j
    编译选项:
    调试打印:export CFLAGS=“-DEMIT_ASN_DEBUG=1”
    5.测试
    ./asn1convert -iaper /home/zhb/tmp/gatekeeper.bin

aper版本

  1. 生成c文件
    asn1c -fcompound-names -pdu=MultimediaSystemControlMessage -gen-PER /home/zhb/tmp/asn1/origin/MULTIMEDIA-SYSTEM-CONTROL.asn
  2. 修改per_opentype.c
uper_open_type_skip(asn_codec_ctx_t *ctx, asn_per_data_t *pd) {
	asn_TYPE_descriptor_t s_td;
	asn_dec_rval_t rv;
	//add
	s_td.op = calloc(1, sizeof(asn_TYPE_operation_t));

	s_td.name = "";
	s_td.op->uper_decoder = uper_sot_suck;

	rv = uper_open_type_get(ctx, &s_td, 0, 0, pd);
	if(rv.code != RC_OK)
		return -1;
	else
		return 0;
}
  1. 编译
    make -f Makefile.am.sample
  2. 测试
    ./progname -iaper /home/zhb/tmp/h245request.bin

你可能感兴趣的:(opensource,ASN1)