Skip to content

Commit f59447b

Browse files
noctellajenkins
authored andcommitted
finagle/finagle-mux: Update mux Wireshark plugin for Wireshark 4.6.0
Problem The lua version that Wireshark 4.6.0 comes with has no `bit32` module. This causes an error on startup when this plugin is installed: ``` Lua: Error during loading: ...mux_dissector.lua:87: attempt to index a nil value (global 'bit32') stack traceback: .../.local/lib/wireshark/plugins/4-6/mux_dissector.lua:87 ``` Solution Add compatibility function. Differential Revision: https://phabricator.twitter.biz/D1268488
1 parent cccf48e commit f59447b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

finagle-mux/src/main/lua/mux_dissector.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,39 @@ resetDebugLevel()
5757
dprint2("Wireshark version = ".. get_version())
5858
dprint2("Lua version = ".. _VERSION)
5959

60+
61+
-- bit32 compatibility shim for different Lua runtimes (Lua 5.2, LuaJIT, Lua 5.3+)
62+
local bit32 = bit32 -- use existing if present
63+
64+
if not bit32 then
65+
-- Lua 5.3+ supports native bitwise operators
66+
local vers = tonumber((_VERSION:match("Lua (%d+%.%d+)")) or 0)
67+
if vers >= 5.3 then
68+
bit32 = {
69+
lshift = function(x,n) return (x << n) & 0xFFFFFFFF end,
70+
rshift = function(x,n) return (x >> n) & 0xFFFFFFFF end,
71+
band = function(a,b) return (a & b) end,
72+
bnot = function(x) return (~x) & 0xFFFFFFFF end,
73+
}
74+
else
75+
-- Try to require common bit libraries (Lua 5.2/ LuaJIT)
76+
local ok, b = pcall(require, "bit32")
77+
if not ok then ok, b = pcall(require, "bit") end
78+
79+
if ok and b then
80+
-- adapt bit / bit32 APIs to a common bit32-like table
81+
bit32 = {
82+
lshift = b.lshift or b.bit_lshift,
83+
rshift = b.rshift or b.bit_rshift,
84+
band = b.band or b.bit_and,
85+
bnot = b.bnot or function(x) return b.bxor(x, 0xFFFFFFFF) end,
86+
}
87+
else
88+
error("No bit library available: need bit32 / bit or Lua 5.3+")
89+
end
90+
end
91+
end
92+
6093
----------------------------------------
6194
-- the lua api for tcp segment reassembly was introduced in 1.99.2
6295
local major, minor, micro = get_version():match("(%d+)%.(%d+)%.(%d+)")

0 commit comments

Comments
 (0)