This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Migrating ASN.1 based dissector plugin to Wireshark 2.1

0

Hi,

in our company we use some Wireshark plugins. They worked fine for Wireshark 1.x. For Wireshark 2.1 they do no longer work and I am trying to migrate them to Wireshark 2.1.

I managed to compile them for Windows 64 bit. The generation of c files from the .asn files didn't work with CMake but I managed to create them manually using awn2wrs. I updated some renamed functions and now Windows 64 bit works fine.

What causes some headache is compiling for Linux. (Ubuntu 14.04 64bit)

I found instructions in README.plugins and followed them. They are not fully complete but I managed to build some plugins that do not use asn.1 files.

What I did is updating these files to include my plugins: - CMakeListsCustom.txt - configure.ac - plugins/Custom.m4 - plugins/Custom.make

I also deleted my Makefile.common and Makefile.am files and created new ones based on plugins/gryphon example.

Doing this for non-ASN.1 dissectors works fine but it doesn't help if ASN.1 is used.

All samples and instructions I found lack some hints on how to use them with latest Wireshark version.

Also the ASN.1 sample dissector does not build:

Making all in toyasn1
...
make  all-am
make[4]: Entering directory `/Development/x/Wireshark/plugins/toyasn1'
make[4]: *** No rule to make target `../../tools/make-dissector-reg', needed by `plugin.c'.  Stop.

Are there any updated build instructions available to create plugins? Are there any migration instructions available?

I never compiled for Wireshark before. I am not aware with which version the changes in the dissector API and in the build process were introduced with.

I hope the experts here can ease my pain. ;)

BR, Gerhard


Edit1: When I updated the non ASN.1 plugins I had to remove the rule to create plugin.c from Makefile.am. This is what causes the error message about missing make-dissector-re.py tool. I also applied this change to the ASN.1 based plugins. But this only shifts the problem a bit further:

make  all-am
make[4]: Entering directory `/Development/x/Wireshark/plugins/toyasn1'
Makefile:1100: warning: overriding commands for target `checkapi'
Makefile:1074: warning: ignoring old commands for target `checkapi'
Making plugin.c
No files found
make[4]: *** [plugin.c] Error 1
make[4]: Leaving directory `/Development/x/Wireshark/plugins/toyasn1'

Now there is no file plugin.c created. I cannot apply all the other changes from the makefiles as they are rather different with regards to the autogenerated files and I cannot really figure out which part I still need or with what other rules I have to replace the content.

asked 22 Jun '16, 08:06

gerhardh's gravatar image

gerhardh
11113
accept rate: 0%

edited 24 Jun '16, 04:30


One Answer:

0

The "No files found" text means that tools/make-dissector-reg.py was called with an empty $REGISTER_SRC_FILES list. If you look at plugins\Makefile.common.inc, you will get this definition:

REGISTER_SRC_FILES = \
    $(FLEX_GENERATED_REGISTER_C_FILES) \
    $(FLEX_GENERATED_REGISTER_CPP_FILES) \
    $(LEMON_GENERATED_REGISTER_C_FILES) \
    $(LEMON_GENERATED_REGISTER_CPP_FILES) \
    $(NONGENERATED_REGISTER_C_FILES) \
    $(NONGENERATED_REGISTER_CPP_FILES)

Where those lists are supposed to be defined in the Makefile.common file in your plugin folder. So ensure to have something like:

NONGENERATED_REGISTER_C_FILES = \
    packet-toyasn1.c

Where you replace packet-toyasn1.c by whatever file name contains your register and handoff functions.

PS: given that you were able to compile with CMake on Windows, it might be easier to use CMake on Linux also rather that updating the Makefile.(am|common) files.

answered 24 Jun '16, 06:21

Pascal%20Quantin's gravatar image

Pascal Quantin
5.5k1060
accept rate: 30%

Thanks a lot for your answer.

Calling tools/make-dissector-reg.py will not be possible even with proper parameters. This tool does not exist any longer. I had to remove the whole part where plugin.c was created.

I tried to apply the same changes as with the non-ASN.1 plugins and add the differences for ASN.1 on top of them. After some fiddling around I managed to get a version of the Makefiles that work for me (more or less).


The new content of Makefile.am is:

include Makefile.common
include $(top_srcdir)/Makefile.am.inc
include ../Makefile.am.inc
plugindir = @[email protected]
BUILT_SOURCES = packet-toyasn1.h
plugin_LTLIBRARIES = toyasn1.la
toyasn1_la_SOURCES = \
    plugin.c \
    moduleinfo.h \
    $(DISSECTOR_SRC) \
    $(DISSECTOR_INCLUDES)
toyasn1_la_CPPFLAGS = $(AM_CPPFLAGS) $(PLUGIN_CPPFLAGS)
toyasn1_la_CFLAGS = $(AM_CFLAGS) $(PLUGIN_CFLAGS)
toyasn1_la_LDFLAGS = $(PLUGIN_LDFLAGS)
generate_dissector: $(DISSECTOR_FILES)
generate_export: $(EXPORT_FILES)
PROTO_OPT ?= -p $(PLUGIN_NAME)
$(DISSECTOR_FILES): $(top_srcdir)/tools/asn2wrs.py $(SRC_FILES) $(EXTRA_CNF)
    python $(top_srcdir)/tools/asn2wrs.py \
    $(A2W_FLAGS) \
    $(PROTO_OPT) \
    -c $(srcdir)/$(PLUGIN_NAME).cnf \
    -s $(srcdir)/packet-$(PLUGIN_NAME)-template \
    -D $(srcdir) $(EXT_ASN_FILE_LIST) $(ASN_FILE_LIST) $(EXT_ASN_FILE_LIST_LATE)
$(EXPORT_FILES): $(top_srcdir)/tools/asn2wrs.py $(SRC_FILES)
    python $(top_srcdir)/tools/asn2wrs.py \
    -E $(A2W_FLAGS) \
    $(PROTO_OPT) \
    -c $(srcdir)/$(PLUGIN_NAME).cnf \
    -D $(srcdir) $(EXT_ASN_FILE_LIST) $(ASN_FILE_LIST) $(EXT_ASN_FILE_LIST_LATE)
CLEANFILES = \
parsetab.py \
parsetab.pyc \
$(DISSECTOR_FILES) \
-exp.cnf \
packet--{dis-tab,ettarr,ett,fn,hfarr,hf,table,val,exp}.[hc] \
~
MAINTAINERCLEANFILES = \
Makefile.in \
plugin.c
EXTRA_DIST = \
Makefile.common     \
Makefile.nmake      \
$(ASN_FILE_LIST) \
packet-$(PLUGIN_NAME)-template.c \
packet-$(PLUGIN_NAME)-template.h \
$(PLUGIN_NAME).cnf \
$(PLUGIN_NAME).asn \
moduleinfo.nmake    \
plugin.rc.in

The new content of Makefile.common is:

PLUGIN_NAME = toyasn1
PLUG = toyasn1
Non-generated sources to be scanned for registration routines
NONGENERATED_REGISTER_C_FILES = \
packet-toyasn1.c
Non-generated sources
NONGENERATED_C_FILES = \
$(NONGENERATED_REGISTER_C_FILES)
Headers.
CLEAN_HEADER_FILES = \
packet-toyasn1.h
HEADER_FILES = \
$(CLEAN_HEADER_FILES)
the dissector sources (without any helpers)
DISSECTOR_SRC = \
packet-toyasn1.c
corresponding headers
DISSECTOR_INCLUDES =    \
packet-toyasn1.h
DISSECTOR_FILES = $(DISSECTOR_SRC) $(DISSECTOR_INCLUDES)
BUILT_FILES = packet-$(PLUG)-template.c packet-$(PLUG)-template.h $(PLUG).cnf $(PLUG).asn
A2W_FLAGS= -b -L
ASN_FILE_LIST = $(PLUGIN_NAME).asn
PROTO_OPT = -p $(PLUGIN_NAME)
srcdir = .
EXTRA_CNF =
Dissector helpers. They're included in the source files in this
directory, but they're not dissectors themselves, i.e. they're not
used to generate "plugin.c".
DISSECTOR_SUPPORT_SRC =
include ../Makefile.common.inc

The only drawback of these Makefiles is that packet-toyasn1.c|h are only created from packet-toyasn1-template.c|h if they do not exist. If they already exist and the template files are changed, asn2wrs tool ist not called again to update the autogenerated files. As I do not need to touch the dissector code itself a lot, this limitation is fine for me.

When using cmake for building the Windows version these C and H files were not created from the template files automatically at all. This is one of the reasons why I didn't use cmake to build the Linux version.

With this solution my problem is solved. Thanks for helping

(27 Jun '16, 06:01) gerhardh

I do not know why you say that tools/make-dissector-reg.py does not exist anymore. It does and in master branch it is called from plugins/Makefile.am.inc file (you are supposed to include it in your Makefile, see Makefile.am in plugins/gryphon folder for example).

(27 Jun '16, 08:14) Pascal Quantin

I am sorry. I provided wrong link to ASN.1 sample plugin in the initial question. I didn't use foo.tar.gz sample file but toyasn1.tar.gz sample file from here: https://wiki.wireshark.org/ASN1_plugin

Maybe it would have worked better if I had used to foo ASN.1 example.

With toyasn1 sample code I got the error message about missing ../../tools/make-dissector-reg script that I showed in initial question. That shell script is not existing in the git repository.

What I didn't notice is the missing file extension. You were talking about make-dissector-reg.py which does exist in tools directory.

Looking a bit closer into Makefile.am it seems that it assumes that there is a script for use with Python and one without Python. But the latter is not existing in the folder, causing the error message.

Sorry for the confusion.

(28 Jun '16, 01:02) gerhardh

Indeed toyasn1 plugin is really out of date (if you check the wiki page you will see that it was last updated in 2010) and does not work out of the box with current master branch (as you unfortunately discovered).

(28 Jun '16, 01:43) Pascal Quantin