lunarmodules / luacov

LuaCov is a simple coverage analyzer for Lua code.
http://lunarmodules.github.io/luacov/
MIT License
297 stars 67 forks source link

Luacov with Wireshark Lua plugin #55

Open shakthimaan opened 6 years ago

shakthimaan commented 6 years ago

I have installed luacov (version 0.12.0-1) using luarocks. I am trying to use the same with a Wireshark Lua dissector plugin.

I have included the following in the top of the Lua dissector plugin:

local luacov = require("luacov")

I start Wireshark as follows:

$ wireshark -r capture.pcapng -X lua_script:dissector.lua

But, the plugin fails to load with the message "~/.luarocks/share/lua/5.1/luacov/hook.lua:26:attempt to index global 'debug' (a function value)".

How to use luacov with Wireshark Lua plugins?

ignacio commented 6 years ago

Check wireshark documentation. They seem to be replacing the debug module with a debug function. Probably for sandboxing reasons.

El El mié, 31 de ene. de 2018 a las 11:26, Shakthi Kannan < notifications@github.com> escribió:

I have installed luacov (version 0.12.0-1) using luarocks. I am trying to use the same with a Wireshark Lua dissector plugin.

I have included the following in the top of the Lua dissector plugin:

local luacov = require("luacov")

I start Wireshark as follows:

$ wireshark -r capture.pcapng -X lua_script:dissector.lua

But, the plugin fails to load with the message "~/.luarocks/share/lua/5.1/luacov/hook.lua:26:attempt to index global 'debug' (a function value)".

How to use luacov with Wireshark Lua plugins?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/keplerproject/luacov/issues/55, or mute the thread https://github.com/notifications/unsubscribe-auth/AABZo7WgXN3yby6ZEe7xy-F7EdApvimHks5tQD_AgaJpZM4RzvYp .

shakthimaan commented 6 years ago

In hook.lua, when the local variable "name" is assigned the full path of the Lua plugin prefixed by "@", the coverage statistics get generated. Bascially, the following is used to retrieve the name:

  local name = debug.getinfo(level, "S").source -- returns "@dissector.lua"

So, the following hard-coded assginment works:

  local name = "@dissector.lua"
  local prefixed_name = string.match(name, "^@(.*)")

Why is the debug module or function used to retrieve the path to the Wireshark Lua plugin? Are there any other alternatives possible, or is there anything that can be set in the Wireshark Lua plugin to satisfy "debug"?

Lekensteyn commented 6 years ago

Check wireshark documentation. They seem to be replacing the debug module with a debug function. Probably for sandboxing reasons.

I don't think it was intentionally done. Someone added logger functions such as "critical", "warn", "message", "info" and "debug". I think that these should be removed or renamed. As a workaround, you can add this to your dissector:

_G.debug = require("debug")

Internally Wireshark uses plain lua_load. It seems that Lua only prepends a @ if the luaL_loadfilex function is used: https://github.com/lua/lua/blob/v5-2/lauxlib.c#L630-L644

Going back to the Lua manual we find this:

source: the source of the chunk that created the function. If source starts with a '@', it means that the function was defined in a file where the file name follows the '@'. If source starts with a '=', the remainder of its contents describe the source in a user-dependent manner. Otherwise, the function was defined in a string where source is that string.

It looks like Wireshark (and all other applications that use lua_load directly) need fixing.

Edit: proposed Wireshark patches https://code.wireshark.org/review/29447 - fix for missing @ https://code.wireshark.org/review/29449 - do not overwrite the debug name

Lekensteyn commented 6 years ago

The @ issue and debug collision fixes are now merged as v2.9.0rc0-1690-g6fa2ad4922. The fix for the @ issue is backported as v2.6.4rc0-25-gb407f7a945 (and will end up in a future Wireshark 2.6.4 release). For the debug collision, please apply the _G.debug = require("debug") workaround.