summaryrefslogtreecommitdiffstats
path: root/solec.lua
diff options
context:
space:
mode:
authorbt <bt@rctt.net>2026-03-10 14:11:01 +0100
committerbt <bt@rctt.net>2026-03-10 14:11:01 +0100
commite5644d24c51634c0e263a758bd57b797d5949c9c (patch)
tree5f6f33ebb064df45693fc75e0d454f0f11ce4654 /solec.lua
parent6dcbb66fcafce3da6d7c00d9679946b77f6f6186 (diff)
downloadsolec-e5644d24c51634c0e263a758bd57b797d5949c9c.tar.gz
solec-e5644d24c51634c0e263a758bd57b797d5949c9c.zip
Use Kaitai to describe protocol spec, autogenerate Wireshark plugin and diagram
Diffstat (limited to 'solec.lua')
-rw-r--r--solec.lua179
1 files changed, 148 insertions, 31 deletions
diff --git a/solec.lua b/solec.lua
index a367358..f48831b 100644
--- a/solec.lua
+++ b/solec.lua
@@ -1,43 +1,160 @@
--- Wireshark plugin
--- Use following filter: _ws.col.protocol == "SOLEC"
+-- This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
+--
+-- This file is compatible with Lua 5.3
-solec = Proto("SOLEC", "SOLEC Protocol")
+package.path = "kaitai_struct_lua_runtime/?.lua" .. package.path
+local class = require("class")
+require("tvbstream")
+require("kaitaistruct")
+local proto = Proto('solec', 'Solec')
+proto.fields = {}
+local enum = require("enum")
+local Solec_payload_type = ProtoField.new('payload_type', 'Solec.payload_type', ftypes.BYTES)
+table.insert(proto.fields, Solec_payload_type)
+local Solec_payload_length = ProtoField.new('payload_length', 'Solec.payload_length', ftypes.UINT32)
+table.insert(proto.fields, Solec_payload_length)
+local Solec_String_len_payload = ProtoField.new('len_payload', 'Solec.String.len_payload', ftypes.UINT32)
+table.insert(proto.fields, Solec_String_len_payload)
+local str_decode = require("string_decode")
+local Solec_String_payload = ProtoField.new('payload', 'Solec.String.payload', ftypes.STRINGZ)
+table.insert(proto.fields, Solec_String_payload)
+local Solec_Binary_len_payload = ProtoField.new('len_payload', 'Solec.Binary.len_payload', ftypes.UINT32)
+table.insert(proto.fields, Solec_Binary_len_payload)
+local Solec_Binary_payload = ProtoField.new('payload', 'Solec.Binary.payload', ftypes.BYTES)
+table.insert(proto.fields, Solec_Binary_payload)
+local Solec_Test_num1 = ProtoField.new('num1', 'Solec.Test.num1', ftypes.UINT8)
+table.insert(proto.fields, Solec_Test_num1)
+local Solec_Test_time1 = ProtoField.new('time1', 'Solec.Test.time1', ftypes.UINT32)
+table.insert(proto.fields, Solec_Test_time1)
+local Solec_Test_num2 = ProtoField.new('num2', 'Solec.Test.num2', ftypes.UINT32)
+table.insert(proto.fields, Solec_Test_num2)
+local Solec_Test_num3 = ProtoField.new('num3', 'Solec.Test.num3', ftypes.UINT32)
+table.insert(proto.fields, Solec_Test_num3)
+local Solec_Test_num4 = ProtoField.new('num4', 'Solec.Test.num4', ftypes.UINT32)
+table.insert(proto.fields, Solec_Test_num4)
-s_datatype = ProtoField.uint8("solec.datatype", "Datatype", base.HEX, {
- [0x01] = "handshake",
- [0x02] = "ping",
- [0x03] = "pong",
- [0x04] = "message",
- [0xFF] = "test",
-})
+function proto.dissector(tvb, pinfo, root)
+ pinfo.cols.protocol = 'Solec'
+ local tree = root:add(proto, tvb(), 'Solec')
+ local io = KaitaiStream(TVBStream(tvb))
+ local obj = Solec(io, tree)
+end
+
+Solec = class.class(KaitaiStruct)
+
+Solec.Type = enum.Enum {
+ handshake = 1,
+ ping = 2,
+ pong = 3,
+ message = 4,
+ test = 255,
+}
+
+function Solec:_init(io, tree, parent, root)
+ KaitaiStruct._init(self, io)
+ self._parent = parent
+ self._root = root or self
+ self._tree = tree
+ self:_read()
+end
+
+function Solec:_read()
+ local _offset = self._io:pos()
+ self.payload_type = Solec.Type(self._io:read_u1())
+ self._tree:add(Solec_payload_type, self._io._io.tvb(_offset, self._io:pos() - _offset))
+ local _offset = self._io:pos()
+ self.payload_length = self._io:read_u2be()
+ self._tree:add(Solec_payload_length, self._io._io.tvb(_offset, self._io:pos() - _offset), self.payload_length)
+ local _offset = self._io:pos()
+ local _on = self.payload_type
+ if _on == Solec.Type.test then
+ local _tree = self._tree:add(self._io._io.tvb(_offset, 0), 'payload')
+ self.payload = Solec.Test(self._io, _tree, self, self._root)
+ _tree:set_len(self._io:pos() - _offset)
+ end
+end
+
+
+Solec.String = class.class(KaitaiStruct)
-s_handshake_version = ProtoField.uint8("solec.handshake.version", "Protocol version", base.HEX)
-s_pong_timestamp = ProtoField.uint64("solec.pong.timestamp", "Timestamp", base.DEC)
+function Solec.String:_init(io, tree, parent, root)
+ KaitaiStruct._init(self, io)
+ self._parent = parent
+ self._root = root or self
+ self._tree = tree
+ self:_read()
+end
-solec.fields = { s_datatype, s_handshake_version, s_pong_timestamp }
+function Solec.String:_read()
+ local _offset = self._io:pos()
+ self.len_payload = self._io:read_u2be()
+ self._tree:add(Solec_String_len_payload, self._io._io.tvb(_offset, self._io:pos() - _offset), self.len_payload)
+ local _offset = self._io:pos()
+ self.payload = str_decode.decode(self._io:read_bytes(self.len_payload), "UTF-8")
+ self._tree:add(Solec_String_payload, self._io._io.tvb(_offset, self._io:pos() - _offset), self.payload)
+end
-function solec.dissector(buffer, pinfo, tree)
- length = buffer:len()
- if length == 0 then
- return
- end
- pinfo.cols.protocol = solec.name
+Solec.Binary = class.class(KaitaiStruct)
- local subtree = tree:add(solec, buffer(), "SOLEC Protocol Data")
- local dtype = buffer(0,1):uint()
+function Solec.Binary:_init(io, tree, parent, root)
+ KaitaiStruct._init(self, io)
+ self._parent = parent
+ self._root = root or self
+ self._tree = tree
+ self:_read()
+end
+
+function Solec.Binary:_read()
+ local _offset = self._io:pos()
+ self.len_payload = self._io:read_u2be()
+ self._tree:add(Solec_Binary_len_payload, self._io._io.tvb(_offset, self._io:pos() - _offset), self.len_payload)
+ local _offset = self._io:pos()
+ self.payload = self._io:read_bytes(self.len_payload)
+ self._tree:add(Solec_Binary_payload, self._io._io.tvb(_offset, self._io:pos() - _offset), self.payload)
+end
- subtree:add_le(s_datatype, dtype)
- if dtype == 01 then
- local subtree = tree:add(solec, buffer(), "Handshake")
- subtree:add_le(s_handshake_version, buffer(1, 1):uint())
- elseif dtype == 0x03 then
- local subtree = tree:add(solec, buffer(), "Pong")
- local timestamp = buffer(1, 8):uint64()
- subtree:add(s_pong_timestamp, timestamp):append_text(" (" .. os.date('%Y/%m/%d %X', tonumber(timestamp)) .. ")")
- end
+Solec.Test = class.class(KaitaiStruct)
+
+function Solec.Test:_init(io, tree, parent, root)
+ KaitaiStruct._init(self, io)
+ self._parent = parent
+ self._root = root or self
+ self._tree = tree
+ self:_read()
+end
+
+function Solec.Test:_read()
+ local _offset = self._io:pos()
+ self.num1 = self._io:read_u1()
+ self._tree:add(Solec_Test_num1, self._io._io.tvb(_offset, self._io:pos() - _offset), self.num1)
+ local _offset = self._io:pos()
+ self.time1 = self._io:read_u8be()
+ self._tree:add(Solec_Test_time1, self._io._io.tvb(_offset, self._io:pos() - _offset), self.time1)
+ local _offset = self._io:pos()
+ local _tree = self._tree:add(self._io._io.tvb(_offset, 0), 'str1')
+ self.str1 = Solec.String(self._io, _tree, self, self._root)
+ _tree:set_len(self._io:pos() - _offset)
+ local _offset = self._io:pos()
+ self.num2 = self._io:read_u2be()
+ self._tree:add(Solec_Test_num2, self._io._io.tvb(_offset, self._io:pos() - _offset), self.num2)
+ local _offset = self._io:pos()
+ local _tree = self._tree:add(self._io._io.tvb(_offset, 0), 'bin1')
+ self.bin1 = Solec.Binary(self._io, _tree, self, self._root)
+ _tree:set_len(self._io:pos() - _offset)
+ local _offset = self._io:pos()
+ self.num3 = self._io:read_u4be()
+ self._tree:add(Solec_Test_num3, self._io._io.tvb(_offset, self._io:pos() - _offset), self.num3)
+ local _offset = self._io:pos()
+ local _tree = self._tree:add(self._io._io.tvb(_offset, 0), 'str2')
+ self.str2 = Solec.String(self._io, _tree, self, self._root)
+ _tree:set_len(self._io:pos() - _offset)
+ local _offset = self._io:pos()
+ self.num4 = self._io:read_u8be()
+ self._tree:add(Solec_Test_num4, self._io._io.tvb(_offset, self._io:pos() - _offset), self.num4)
end
+
local tcp_port = DissectorTable.get("tcp.port")
-tcp_port:add(9999, solec)
+tcp_port:add(9999, proto)