-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlppb.lua
54 lines (44 loc) · 1.62 KB
/
lppb.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local lppb = Proto("lppb","Length Prefixed Protocol Buffers");
len_F = ProtoField.string("lppb.len","Length")
lppb.fields = {len_F}
lppb.prefs.port = Pref.uint("TCP Port:", 0, "")
lppb.prefs.schema = Pref.string("Schema:", "", "E.g. MY.PROTOBUF.MESSAGE")
lppb.prefs.prefix_size = Pref.uint("Prefix size (bytes):", 4, "")
function get_message_len(tvb, pinfo, tree)
local len = tvb:range(0, lppb.prefs.prefix_size):uint()
return len + lppb.prefs.prefix_size
end
function dissect_message(tvb, pinfo, tree)
local subtree = tree:add(lppb,tvb(),"Length Prefixed Protocol Buffers Data")
local len = get_message_len(tvb, pinfo, tree)
subtree:add(len_F, tostring(len - lppb.prefs.prefix_size))
if lppb.prefs.schema == "" then
subtree:add_expert_info(PI_DEBUG, PI_ERROR, "No protobuf schema specified")
else
local dissector = DissectorTable.get("protobuf.message"):get_dissector(lppb.prefs.schema)
if dissector == nil then
subtree:add_expert_info(PI_DEBUG, PI_ERROR, "Schema not found: "..lppb.prefs.schema)
else
return dissector:call(tvb(lppb.prefs.prefix_size):tvb(), pinfo, subtree)
end
end
return 0
end
function lppb.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, lppb.prefs.prefix_size, get_message_len, dissect_message)
end
local port = 0
lppb.prefs_changed = function()
if port ~= lppb.prefs.port then
-- remove old port, if not 0
if port ~= 0 then
DissectorTable.get("tcp.port"):remove(port, lppb)
end
-- save new port
port = lppb.prefs.port
-- add new port, if not 0
if port ~= 0 then
DissectorTable.get("tcp.port"):add(port, lppb)
end
end
end