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

Unable to load custom module

0

Im refactoring my current dissector by splitting it up in different lua modules.

The implemented protocol has multiple subprotocols. Which protocol is decided by a field in the top protocol. I created a lua module for each subprotocol, but I am unable to load the module into the wireshark.

the file structure

+$/.wireshark/plugins
    -proto.lua
    -tm_frame.lua

A module

local tm_frame = {}
function tm_frame.handle(tree, buffer)
    local tm_frame_tree = tree:add(buffer, "TM Transfer Frame")
    ...
end
return tm_frame

The line of code to call the module in the main plugin

local tm_frame = require 'tm_frame'

Other information

Mint 17
Lua 5.2.3
Wireshark 1.10.6

How can i load the module?

asked 09 Jan '15, 06:21

Maarten's gravatar image

Maarten
6224
accept rate: 0%

edited 09 Jan '15, 06:22


2 Answers:

0

If you're using Wireshark 1.12.0 or newer, then you can create a sub-directory for your module files in the personal plugins directory - let's call that new sub-directory "tm_modules" - and you can put the tm_frame.lua file in that "tm_modules" directory; keep your main proto.lua Lua file in the main personal plugins directory but put this line before your "require" line in it:

package.prepend_path("tm_modules")
-- then do the require
local tm_frame = require 'tm_frame'

answered 09 Jan '15, 10:26

Hadriel's gravatar image

Hadriel
2.7k2939
accept rate: 18%

Confirmed, compiled the source (1.12.3) with the --with-lua options. Prepend path isnt neccesary. Wireshark is able to find the file.

(12 Jan '15, 02:59) Maarten

0

A bit of a guess but if you are placing two files in plugins directory they both will be executed by lua.

I'd maybe try to 1) place second file one directory above in separate directory ie: my_custom_lib 2) then try something like

dofile("../my_custom_lib/tm_frame.lua")

command in your code in proto.lua

answered 09 Jan '15, 06:31

izopizo's gravatar image

izopizo
2024714
accept rate: 0%

dofile is not neccesary when it the files are in the wireshark plugin directory.

(09 Jan '15, 07:10) Maarten

Yes, that's what I was guessing that will happen. Btw if you are looking at packaging there's pretty good example here

https://github.com/martin-cowie/wireshark-dissector

(09 Jan '15, 08:53) izopizo

never thought of doing dofile() somewhere else than in the init.lua file. Great example!

(12 Jan '15, 01:30) Maarten