新生命X组件,数据中间件XCode、日志、网络、RPC、序列化、缓存、Windows服务 www.newlifex.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.5 KiB

  1. do
  2. local p_newlife = Proto("newlife", "新生命标准网络封包")
  3. -- https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Proto.html#lua_class_ProtoField
  4. local FF_flag = {
  5. [0x80] = "[Reply]",
  6. [0x81] = "[Reply]",
  7. [8] = "[Reply]",
  8. [7] = "[Error/Oneway]",
  9. [2] = "[Json]",
  10. [1] = "[Binary]"
  11. }
  12. local f_flag = ProtoField.uint8("NewLife.flag", "标记", base.HEX, FF_flag, 0xFF)
  13. local f_seq = ProtoField.uint8("NewLife.seq", "序列号", base.DEC)
  14. local f_length = ProtoField.uint16("NewLife.length", "长度", base.DEC, nil, "字节长度")
  15. local f_data = ProtoField.bytes("NewLife.data", "数据", base.SPACE)
  16. p_newlife.fields = {f_flag, f_seq, f_length, f_data}
  17. local data_dis = Dissector.get("data")
  18. local function NewLife_dissector(buffer, pinfo, tree)
  19. if buffer:len() < 4 then return false end
  20. local flags = buffer(0, 1):uint()
  21. local seq = buffer(1, 1):uint()
  22. local len = buffer(2, 2):le_uint()
  23. if 4 + len ~= buffer:len() then return false end
  24. pinfo.cols.protocol = "NewLife"
  25. local t = tree:add(p_newlife, buffer)
  26. t:add(f_flag, buffer(0, 1), flags)
  27. t:add(f_seq, buffer(1, 1), seq)
  28. local len_item = t:add_le(f_length, buffer(2, 2), len)
  29. -- 检查负载数据长度是否超出实际捕获的数据长度
  30. if buffer:len() - 4 < len then
  31. len_item:add_expert_info(PI_MALFORMED, PI_WARN, "Payload length is beyond the end of the packet")
  32. return
  33. end
  34. if len > 0 then
  35. t:add(f_data, buffer(4, len), "Payload")
  36. end
  37. return true
  38. end
  39. function p_newlife.dissector(buffer, pinfo, tree)
  40. if NewLife_dissector(buffer, pinfo, tree) then
  41. -- valid NewLife diagram
  42. else
  43. data_dis:call(buffer, pinfo, tree)
  44. end
  45. end
  46. -- register_postdissector(p_newlife)
  47. -- DissectorTable.new("newlife")
  48. local udp_encap_table = DissectorTable.get("udp.port")
  49. udp_encap_table:add(5500, p_newlife)
  50. udp_encap_table:add(9999, p_newlife)
  51. udp_encap_table:add(777, p_newlife)
  52. udp_encap_table:add(12345, p_newlife)
  53. local tcp_encap_table = DissectorTable.get("tcp.port")
  54. tcp_encap_table:add(5500, p_newlife)
  55. tcp_encap_table:add(9999, p_newlife)
  56. tcp_encap_table:add(777, p_newlife)
  57. tcp_encap_table:add(12345, p_newlife)
  58. DissectorTable.new("newlife")
  59. end