diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-03-10 01:54:51 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-03-14 07:29:15 +0000 |
commit | 04c39bb0972bac1f95eb9394b5ca1086f19c0d93 (patch) | |
tree | 62171e4584b86bb746d6a73181eb7627a15b9e44 /epan/wslua/wslua_internals.c | |
parent | a59ac1bd10d29d05ca5cd657b7c64ab13a08670d (diff) | |
download | wireshark-04c39bb0972bac1f95eb9394b5ca1086f19c0d93.tar.gz |
Add Lua heuristic dissector support
This adds the ability for Lua scripts to register heuristic dissectors
for any protocol that has registered a heuristic dissector list, such
as UDP, TCP, and ~50 others. The Lua function can also establish a
conversation tied to its Proto dissector, to avoid having to check the
heuristics for the same flow. The example dissector in the testsuite
has also been enhanced to include a heuristic dissector, to verify
the functionality and provide an example implementation.
Change-Id: Ie232602779f43d3418fe8db09c61d5fc0b59597a
Reviewed-on: https://code.wireshark.org/review/576
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wslua/wslua_internals.c')
-rw-r--r-- | epan/wslua/wslua_internals.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/epan/wslua/wslua_internals.c b/epan/wslua/wslua_internals.c index 50cd8a3d40..15d62845ff 100644 --- a/epan/wslua/wslua_internals.c +++ b/epan/wslua/wslua_internals.c @@ -99,13 +99,17 @@ WSLUA_API void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { lua_pop(L, nup); /* remove upvalues */ } -/* identical to lua_getfield but without triggering metamethods */ +/* identical to lua_getfield but without triggering metamethods + warning: cannot be used directly with negative index (and shouldn't be changed to) + decrement your negative index if you want to use this */ static void lua_rawgetfield(lua_State *L, int idx, const char *k) { lua_pushstring(L, k); lua_rawget(L, idx); } -/* identical to lua_setfield but without triggering metamethods */ +/* identical to lua_setfield but without triggering metamethods + warning: cannot be used with negative index (and shouldn't be changed to) + decrement your negative index if you want to use this */ static void lua_rawsetfield (lua_State *L, int idx, const char *k) { lua_pushstring(L, k); lua_insert(L, -2); @@ -140,6 +144,38 @@ const gchar* wslua_typeof(lua_State *L, int idx) { return classname; } +/* this gets a Lua table of the given name, from the table at the given + * location idx. If it does not get a table, it pops whatever it got + * and returns false. + * warning: cannot be used with pseudo-indeces like LUA_REGISTRYINDEX + */ +gboolean wslua_get_table(lua_State *L, int idx, const gchar *name) { + gboolean result = TRUE; + if (idx < 0) idx--; + lua_rawgetfield(L, idx, name); + if (!lua_istable(L,-1)) { + lua_pop(L,1); + result = FALSE; + } + return result; +} + +/* this gets a table field of the given name, from the table at the given + * location idx. If it does not get a field, it pops whatever it got + * and returns false. + * warning: cannot be used with pseudo-indeces like LUA_REGISTRYINDEX + */ +gboolean wslua_get_field(lua_State *L, int idx, const gchar *name) { + gboolean result = TRUE; + if (idx < 0) idx--; + lua_rawgetfield(L, idx, name); + if (lua_isnil(L,-1)) { + lua_pop(L,1); + result = FALSE; + } + return result; +} + /* This verifies/asserts that field 'name' doesn't already exist in table at location idx. * If it does, this EXITS wireshark, because this is a fundamental programming error. * As such, this function is only useful for special circumstances, notably |