Compare commits

..

3 Commits

Author SHA1 Message Date
c6867aad85 comment out prints 2024-02-06 10:35:54 +03:00
61894f0943 merge updates from original (use heuristic) 2024-02-06 10:33:09 +03:00
2a5e8853c9 assembling split packets 2024-02-06 09:01:47 +03:00

View File

@ -864,6 +864,10 @@ do
t2:add(f_message_length, buffer(pos + 2, 2))
t2:add(f_message, buffer(pos + 4, message_length))
local ao_dis = Dissector.get("minetest.active_object_message")
new_tvb = ByteArray.tvb(buffer(pos + 4, message_length):bytes())
local bytes_dissected = ao_dis:call(new_tvb(0):tvb(), pinfo, t2)
pos = pos + 4 + message_length
end
end
@ -1051,14 +1055,16 @@ end
-- ...
minetest_server_commands[0x57] = {"MODCHANNEL_MSG", 2}
minetest_server_commands[0x58] = {"MODCHANNEL_SIGNAL", 2}
minetest_server_commands[0x59] = {"NODEMETA_CHANGED", 2}
minetest_server_commands[0x5a] = {"SET_SUN", 2}
minetest_server_commands[0x5b] = {"SET_MOON", 2}
minetest_server_commands[0x5c] = {"SET_STARS", 2}
minetest_server_commands[0x60] = {"SRP_BYTES_S_B", 2}
minetest_server_commands[0x61] = {"FORMSPEC_PREPEND", 2}
minetest_server_commands[0x57] = { "MODCHANNEL_MSG", 2 }
minetest_server_commands[0x58] = { "MODCHANNEL_SIGNAL", 2 }
minetest_server_commands[0x59] = { "NODEMETA_CHANGED", 2 }
minetest_server_commands[0x5a] = { "SET_SUN", 2 }
minetest_server_commands[0x5b] = { "SET_MOON", 2 }
minetest_server_commands[0x5c] = { "SET_STARS", 2 }
minetest_server_commands[0x60] = { "SRP_BYTES_S_B", 2 }
minetest_server_commands[0x61] = { "FORMSPEC_PREPEND", 2 }
minetest_server_commands[0x62] = { "MINIMAP_MODES", 2 }
minetest_server_commands[0x63] = { "SET_LIGHTING", 2 }
------------------------------------
@ -1212,24 +1218,143 @@ end
minetest_define_client_or_server_proto(true) -- minetest.client
minetest_define_client_or_server_proto(false) -- minetest.server
-- minetest.active_object_message
do
local ao_proto = Proto("minetest.active_object_message", "Minetest AO message")
local vs_command = {
[0] = "SET_PROPERTIES",
[1] = "UPDATE_POSITION",
[2] = "SET_TEXTURE_MOD",
[3] = "SET_SPRITE",
[4] = "PUNCHED",
[5] = "UPDATE_ARMOR_GROUPS",
[6] = "SET_ANIMATION",
[7] = "SET_BONE_POSITION",
[8] = "ATTACH_TO",
[9] = "SET_PHYSICS_OVERRIDE",
[10] = "OBSOLETE1", -- UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0
[11] = "SPAWN_INFANT",
[12] = "SET_ANIMATION_SPEED",
}
local f_command = ProtoField.uint8("minetest.active_object_message.cmd", "Command", base.DEC, vs_command)
-- local f_control_ack = ProtoField.uint16("minetest.control.ack", "ACK sequence number", base.DEC)
-- local f_control_peerid = ProtoField.uint8("minetest.control.peerid", "New peer ID", base.DEC)
ao_proto.fields = { f_command }
function ao_proto.dissector(buffer, pinfo, tree)
-- print("---------------------------------")
local t = tree:add(ao_proto, buffer(0, 1))
t:add(f_command, buffer(0, 1))
end
end
-- minetest.split dissector
local split_store = {}
do
local p_split = Proto("minetest.split", "Minetest Split Message")
local f_split_seq = ProtoField.uint16("minetest.split.seq", "Sequence number", base.DEC)
local f_split_chunkcount = ProtoField.uint16("minetest.split.chunkcount", "Chunk count", base.DEC)
local f_split_chunknum = ProtoField.uint16("minetest.split.chunknum", "Chunk number", base.DEC)
function p_split.init()
-- print("(re-)initialise")
split_store.fragments = {}
split_store.concats = {}
end
local f_split_seq = ProtoField.uint16("minetest.split.seq", "Sequence number", base.DEC) -- this number is same for all parts
local f_split_chunkcount = ProtoField.uint16("minetest.split.chunkcount", "Chunk count", base.DEC) -- total number of fragments
local f_split_chunknum = ProtoField.uint16("minetest.split.chunknum", "Chunk number", base.DEC) -- index of this chunk
local f_split_data = ProtoField.bytes("minetest.split.data", "Split message data")
p_split.fields = { f_split_seq, f_split_chunkcount, f_split_chunknum, f_split_data }
local f_assembled_data = ProtoField.bytes("minetest.split.assembleddata", "Assembled message data")
p_split.fields = { f_split_seq, f_split_chunkcount, f_split_chunknum, f_split_data, f_assembled_data }
function p_split.dissector(buffer, pinfo, tree)
local t = tree:add(p_split, buffer(0,6))
t:add(f_split_seq, buffer(0,2))
t:add(f_split_chunkcount, buffer(2,2))
t:add(f_split_chunknum, buffer(4,2))
t:add(f_split_data, buffer(6))
pinfo.cols.info:append(" " .. buffer(0,2):uint() .. " chunk " .. buffer(4,2):uint() .. "/" .. buffer(2,2):uint())
-- print("---------------------------------")
local t = tree:add(p_split, buffer(0, 6))
local seq_number = buffer(0, 2)
t:add(f_split_seq, seq_number)
local seq_frag_total = buffer(2, 2)
t:add(f_split_chunkcount, seq_frag_total)
local seq_frag_index = buffer(4, 2)
t:add(f_split_chunknum, seq_frag_index)
local seq_frag_data = buffer(6)
t:add(f_split_data, seq_frag_data)
pinfo.cols.info:append(" " .. buffer(0, 2):uint() .. " chunkos " .. buffer(4, 2):uint() ..
"/" .. buffer(2, 2):uint())
--print("visited", pinfo.visited)
if (pinfo.visited == false) then
seq_number = buffer(0, 2):uint() -- convert from tvbrange to string
seq_frag_index = buffer(4, 2):uint()
seq_frag_total = buffer(2, 2):uint()
local seq_fragments = split_store.fragments[seq_number]
if not seq_fragments then
-- print("first known fragment for", seq_number, seq_frag_index)
seq_fragments = {
total_frag_number = seq_frag_total,
collected_frag_count = 0,
}
split_store.fragments[seq_number] = seq_fragments
else
-- print("other fragment for", seq_number, seq_frag_index)
end
if not seq_fragments[seq_frag_index] then
seq_fragments[seq_frag_index] = buffer(6):bytes()
seq_fragments.collected_frag_count = seq_fragments.collected_frag_count + 1
end
-- print(("%s seq %s collected %s / %s"):format(
seq_number,
seq_frag_index,
seq_fragments.collected_frag_count,
seq_fragments.total_frag_number
))
local assembled_message = ByteArray.new()
--local assembled_message = ""
if seq_fragments.collected_frag_count == seq_fragments.total_frag_number then
local i = 0
while i < seq_fragments.total_frag_number do
--print("concat", i, assembled_message)
assembled_message:append(seq_fragments[i])
i = i + 1
end
split_store.concats[pinfo.number] = assembled_message
split_store.fragments[seq_number] = nil -- free existing
-- --data_dis:call(tvb(7):tvb(), pinfo, tree) -- what is this???
--local data_dis = Proto("minetest", "Minetest")
local data_dis = Dissector.get("minetest.server")
new_tvb = ByteArray.tvb(split_store.concats[pinfo.number])
local bytes_dissected = data_dis:call(new_tvb(0):tvb(), pinfo, tree)
-- print("data dis", bytes_dissected)
end
end
if split_store.concats[pinfo.number] then
local data_dis = Dissector.get("minetest.server")
new_tvb = ByteArray.tvb(split_store.concats[pinfo.number])
local bytes_dissected = data_dis:call(new_tvb(0):tvb(), pinfo, tree)
-- print("data dis", bytes_dissected)
-- print("has assembled")
--new_tvb = ByteArray.tvb(split_store.concats[pinfo.number])
--t:add(f_assembled_data, seq_frag_data)
--t:add(f_assembled_data, new_tvb) --split_store.concats[pinfo.number]:tohex()) -- HMMM????
-- local data_dis = Proto("minetest", "Minetest")
-- data_dis:call(new_tvb(0):tvb(), pinfo, tree)
end
end
end
@ -1280,13 +1405,14 @@ do
function p_minetest.dissector(buffer, pinfo, tree)
-- Add Minetest tree item and verify the ID
-- Defer if payload doesn't have Minetest's magic number
if buffer(0,4):uint() ~= minetest_id then
return false
end
-- Add Minetest tree item
local t = tree:add(p_minetest, buffer(0,8))
t:add(f_id, buffer(0,4))
if buffer(0,4):uint() ~= minetest_id then
t:add_expert_info(PI_UNDECODED, PI_WARN, "Invalid ID, this is not a Minetest packet")
return
end
-- ID is valid, so replace packet's shown protocol
pinfo.cols.protocol = "Minetest"
@ -1339,12 +1465,11 @@ do
end
pinfo.cols.info:append(" (" .. reliability_info .. ")")
return true
end
-- FIXME Is there a way to let the dissector table check if the first payload bytes are 0x4f457403?
DissectorTable.get("udp.port"):add(30000, p_minetest)
DissectorTable.get("udp.port"):add(30001, p_minetest)
p_minetest:register_heuristic("udp", p_minetest.dissector)
end