Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: [Wireshark-dev] wspython building and running

From: Eliot Blennerhassett <eblennerhassett@xxxxxxxxxxxxxxxx>
Date: Thu, 29 Sep 2011 14:50:36 +1300
Greetings,

I'm building wireshark from SVN head on linux x86_64
I want to use a wspython dissector. (source at the end of this email)
But I encountered a number of problems, any tips on how to debug and fix
appreciated!
(BTW I do know how to build a C plugin to do this job,  but I still want
to get the python dissector working)


First problem:
> creating dissector failed /usr/local/lib/libwireshark.so.0: undefined
> symbol: py_generic_dissector

Hmm. Is it in the library?

> /usr/local/lib$ nm libwireshark.so | grep py_gen
> 00000000018ad780 t py_generic_dissector

Sort of, but ?Not exported?

So, I manually added py_generic_dissector to epan/libwireshark.sym and
rebuilt. (But should it be getting added automatically?)

>  /usr/local/lib$ nm libwireshark.so | grep py_gen
> 00000000018ad7c0 T py_generic_dissector


Also I had to tweak wspy_dissector.py (dissector_add is a define now?)
- self.__wsl.dissector_add(type, protocol_id, handle)
+ self.__wsl.dissector_add_uint(type, protocol_id, handle)


Better, but...

> ~/.wireshark/plugins$ wireshark ~/tmp/cn.pcap 
> import cobranet_py
> cobranet_py.register_protocol
> cobranet_py.protocol_ids
> cobranet_py.protocol_ids
> **
> ERROR:about_dlg.c:252:splash_update: assertion failed: (ul_sofar <= ul_count)
> Aborted
> ~/.wireshark/plugins$ 

Well, I blindly comment out the assertion in the splash update code,
thinking maybe it is spurious. (I can't work out exactly what it is
trying to do).

Wireshark now starts and runs better, (surviving a different assertion)

> ~/.wireshark$ wireshark 
> import cobranet_py
> cobranet_py.register_protocol
> cobranet_py.protocol_ids
> cobranet_py.protocol_ids
> 
> (wireshark:22123): Gtk-CRITICAL **: gtk_progress_set_percentage: assertion `percentage >= 0 && percentage <= 1.0' failed
> 

until it hits a packet that triggers my dissector, at which point it
segfaults.  I don't think it reaches the point where my dissector python
code is running (something would get printed to the console)


> Program received signal SIGSEGV, Segmentation fault.
> (gdb) bt
> #0  0x00000000f5de3830 in ?? ()
> #1  0x00007ffff54d2f70 in call_dissector_through_handle (handle=0x1955b70, tvb=0x1d01cc0, pinfo=0x7fffffffd500, tree=0x0)
>     at packet.c:384
> #2  0x00007ffff54d369d in call_dissector_work (handle=0x1955b70, tvb=0x1d01cc0, pinfo_arg=0x7fffffffd500, 
>     tree=<value optimized out>, add_proto_name=1) at packet.c:475
> #3  0x00007ffff54d46c1 in dissector_try_uint_new (sub_dissectors=<value optimized out>, uint_val=34841, tvb=0x1d01cc0, 
>     pinfo=0x7fffffffd500, tree=0x0, add_proto_name=1) at packet.c:900
> #4  0x00007ffff56f1a8a in ethertype (etype=<value optimized out>, tvb=<value optimized out>, 
>     offset_after_etype=<value optimized out>, pinfo=<value optimized out>, tree=<value optimized out>, 
>     fh_tree=<value optimized out>, etype_id=19409, trailer_id=19412, fcs_len=-1) at packet-ethertype.c:265
> #5  0x00007ffff56f0b70 in dissect_eth_common (tvb=0x1d01e40, pinfo=0x7fffffffd500, parent_tree=0x0, fcs_len=<value optimized out>)
>     at packet-eth.c:396
> #6  0x00007ffff54d2f70 in call_dissector_through_handle (handle=0xc71f00, tvb=0x1d01e40, pinfo=0x7fffffffd500, tree=0x0)
>     at packet.c:384

regards

-- 
Eliot Blennerhassett
AudioScience Inc.

# Skeleton cobranet dissector

from wspy_dissector import Dissector
from wspy_dissector import FT_UINT8, FT_NONE
from wspy_dissector import BASE_NONE

print 'import cobranet_py'

if True:
    class cobranet_py(Dissector):
        def protocol_ids(self):
            print 'cobranet_py.protocol_ids'
            return [ ("ethertype", 0x8819, None) ]

        def dissect(self):
            print 'cobranet_py.dissect'
            self.dissect_header()

        def dissect_header(self):
            print 'cobranet_py.dissect_header'
            self.c_tree = self.tree
            try:
                self.c_tree.add_item(self.hf.cobranet_py_type, length=1)
                self.c_tree.add_item(self.hf.cobranet_py_version, length=1)
            except Exception,e:
                print e
else:
    class cobranet_py(Dissector):
        pass

if True:

    def register_protocol():
        print 'cobranet_py.register_protocol'
        tp = cobranet_py("CobraNet_py protocol", "CobraNet_py",
"cobranet_py")
        tp.hf.add("Cobranet PDU type", "cobranet_py.type", FT_UINT8,
BASE_NONE)
        tp.hf.add("Cobranet PDU version", "cobranet_py.version",
FT_UINT8, BASE_NONE)

        return tp