28 static const char suricata_bytevar_mt[] =
"suricata:bytevar:mt";
34 lua_gettable(luastate, LUA_REGISTRYINDEX);
35 ld = lua_touserdata(luastate, -1);
41 const Signature *s = lua_touserdata(L, -2);
42 const char *
name = luaL_checkstring(L, -1);
46 for (uint16_t i = 0; i < ld->
bytevars; i++) {
54 luaL_error(L,
"too many bytevars mapped");
59 luaL_error(L,
"unknown byte_extract or byte_math variable: %s",
name);
64 luaL_error(L,
"failed to allocate memory for bytevar name: %s",
name);
73 const char *
name = luaL_checkstring(L, 1);
76 return luaL_error(L,
"internal error: no lua data");
79 for (uint16_t i = 0; i < ld->
bytevars; i++) {
81 uint32_t *bytevar_id = lua_newuserdata(L,
sizeof(*bytevar_id));
83 luaL_getmetatable(L, suricata_bytevar_mt);
84 lua_setmetatable(L, -2);
89 return luaL_error(L,
"unknown bytevar: %s",
name);
94 uint32_t *bytevar_id = luaL_checkudata(L, 1, suricata_bytevar_mt);
96 if (det_ctx == NULL) {
99 lua_pushinteger(L, det_ctx->
byte_values[*bytevar_id]);
103 static const luaL_Reg bytevarlib[] = {
105 {
"map", LuaBytevarMap, },
106 {
"get", LuaBytevarGet, },
111 static const luaL_Reg bytevarmt[] = {
113 {
"value", LuaBytevarValue, },
120 luaL_newmetatable(L, suricata_bytevar_mt);
121 lua_pushvalue(L, -1);
122 lua_setfield(L, -2,
"__index");
123 luaL_setfuncs(L, bytevarmt, 0);
125 luaL_newlib(L, bytevarlib);