-
Notifications
You must be signed in to change notification settings - Fork 7
/
template.lua
46 lines (40 loc) · 1.56 KB
/
template.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
{{data.meta.id}}_proto = Proto("{{data.meta.id}}","{{data.meta.id}} file")
local f = {{data.meta.id}}_proto.fields
-- field declaration
{% for item in data.seq %}
f.{{item.id}} = ProtoField.bytes("{{data.meta.id}}.{{item.id}}", "{{item.id}}")
{% endfor %}
{% for item in data["types"].items() %}
{% for seqitem in item.1.seq %}
f.{{seqitem.id}} = ProtoField.bytes("{{data.meta.id}}.{{item.0}}.{{seqitem.id}}", "{{seqitem.id}}")
{% endfor %}
{% endfor %}
-- main function
function modes_proto.dissector(buffer,pinfo,tree)
pinfo.cols.protocol = "{{data.meta.id}}"
main = tree:add({{data.meta.id}}_proto, "{{data.meta.id}} file")
{% set offset = 0 %}
{% for item in data["types"].items() %}
local {{item.0}} = main:add(f.{{item.0}},"{{item.0}}")
{% for seqitem in item.1.seq %}
{% if seqitem.type == "u1" %}
{{item.0}}:add(buffer({{offset}},1), f.{{seqitem.id}})
{% set offset = offset+1 %}
{% elif seqitem.type == "u2" %}
{{item.0}}:add(buffer({{offset}},2), f.{{seqitem.id}})
{% set offset = offset+2 %}
{% elif seqitem.type == "u3" %}
{{item.0}}:add(buffer({{offset}},3), f.{{seqitem.id}})
{% set offset = offset+3 %}
{% elif seqitem.contents %}
{{item.0}}:add(buffer({{offset}},{{seqitem.contents|length}}), f.{{seqitem.id}})
{% set offset = offset + seqitem.contents|length %}
{% elif seqitem.size %}
{{item.0}}:add(buffer({{offset}},{{seqitem.size}}), f.{{seqitem.id}})
{% set offset = offset + seqitem.size %}
{% endif %}
{% endfor %}
{% endfor %}
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(<port>, {{data.meta.id}}_proto)