[Closed] [LUA] [Preferences] How to add?

asked 2023-10-31 08:22:34 +0000

Babb gravatar image

updated 2023-11-02 11:17:21 +0000

Hello,

I am trying to add a new dissector using LUA, in Wireshark 3.6.18, that comes with LUA 5.2.4. What I did is:

local foo_proto = Proto.new("foo","foo_description")

All good so far, no errors. Now I want this proto to have some preferences editable from the GUI, so I did this:

foo_proto.prefs:__newindex("foo_abbr",Pref.string("foo_pref_label","","foo_pref_descr"))

Problem is that, at this point, when the LUA file is loading I get:

bad argument #2 to '__index' (Prefs__index: no preference named like this)

According to Wireshark Docs, call to newindex is

prefs:__newindex(name, pref)

What am I doing wrong? Can someone help?

Thank you!

Edit1:

Okay, found a solution to the above problem. Instead of calling __newindex, just assign a new Pref object to proto.prefs, as such:

foo_proto.prefs["foo_pref_abbr"] = Pref.string("foo_pref_label","foo_pref_default_val","foo_pref_descr")

Now, the protocol preference is visible in GUI, but, there's another problem that arises.

It seems that the newly set preference is not updated, because when I launch tshark using -o switch, the value of the preference is not set, but the default one is kept.

For example, let's assume that foo_pref_abbr preference has a default value of 1.22. Now, I launch tshark as follows:

tshark -o "foo_proto.foo_pref_abbr:1.75"

And somewhere in the lua code, there's a print, that actually reads the value. It doesn't matter at all what I set there, the printed value is always the same as foo_pref_default_val above. Always.

Any ideas?

Edit2

Found the problem to problem from Edit1. I had not prefs_changed routine to handle changes. It seems that whenever you are using -o switch, tshark 1st loads the default value for a preference and then it changes it immediately, so it is mandatory to have a prefs_changed routine to update things.

With that being said, case is closed.

Thank you!

edit retag flag offensive close merge delete