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

Run a C DLL from LUA in Wireshark

0

I was wondering if it would be possible to run a C dll from LUA in wireshark. Let me explain.

I already have the code in C that can take a string of the data that comes over the network and returns a string in XML.

I would like to write a LUA script that takes that XML string returned by the C DLL and translate it directly to the tree structure in Wireshark.

I know it is possible to run C DLLs in LUA, but is it possible to do that using LUA in Wireshark?

Are there any premade LUA scripts out there that will take an XML string and convert it directly to the Tree View in wireshark?

Are there any resources you can point me to that do just this?

I realize this is probably not the prefered way to acomplish my task, but it seems like it is probably the easiest solution since I know nothing about LUA or Wireshark. This task is for work, and due to the nature of the client I cannot reveal any specifics or source code.

Thank you for your time, Brandon

asked 05 Jul '11, 09:58

officialhopsof's gravatar image

officialhopsof
318812
accept rate: 100%

@officialhopsof - Can you post the code you use to run the C DLL in Lua?

(07 Sep '11, 07:18) SwDevMan81

One Answer:

1

One way will be to create a wrapper for your dll --either by making a separate dll which makes calls into your current one, or by adding a Lua interface to your current library. I have successfully created a Lua-based dissector using this method, so the idea is sound. You will need the following --at a minimum --in your dll to expose functionality to Lua:

#define LUA_LIB /* Do this early. Preferably first */
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h> /* You may be able to get away without this one */
/* Forward declare your Lua-exposed functions as so*/
static int your_function(lua_State *L);

static const luaL_reg your_libnamelib[] = /* You could call this anything you want */ { {"your_functions_lua_name", your_function}, {NULL, NULL} }

LUALIB_API int luaopen_your_libname(lua_State *L) { luaL_register(L, "your_libname", your_libnamelib); return 1; }

static int your_function(lua_State L) { / Do your work/call other C functions, etc. / return 0; / return the number of items returned to Lua */ }

You can find more information in Programming in Lua.

answered 07 Sep ‘11, 07:43

multipleinterfaces's gravatar image

multipleinte…
1.3k152340
accept rate: 12%