ftds_dissector.lua 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. function ftds_dissector(buffer, pinfo, tree, ftds_protocol, offset)
  2. local f_control_field = ProtoField.uint8("ftds_protocol.control_field", "Control Field", base.DEC)
  3. local f_session_id = ProtoField.uint8("ftds_protocol.session_id", "File Transfer Session ID", base.DEC)
  4. local f_segment_type = ProtoField.uint8("ftds_protocol.segment_type", "Segment Type", base.DEC)
  5. local f_sequence_num_size = ProtoField.uint8("ftds_protocol.sequence_num_size", "Sequence Number Size", base.DEC)
  6. local f_data_length_size = ProtoField.uint8("ftds_protocol.data_length_size", "Data Length Size", base.DEC)
  7. local f_sequence_num = ProtoField.uint32("ftds_protocol.sequence_num", "Sequence Number", base.DEC)
  8. local f_data_length = ProtoField.uint16("ftds_protocol.data_length", "Data Segment Length", base.DEC)
  9. local f_data_bytes = ProtoField.bytes("ftds_protocol.data_bytes", "Data Bytes", base.SPACE)
  10. -- Add the fields to the protocol
  11. ftds_protocol.fields = {
  12. f_control_field,
  13. f_session_id,
  14. f_segment_type,
  15. f_sequence_num_size,
  16. f_data_length_size,
  17. f_sequence_num,
  18. f_data_length,
  19. f_data_bytes
  20. }
  21. local subtree = tree:add(ftds_protocol, buffer(),"FTDS")
  22. local control_field = buffer(offset, 1):le_uint()
  23. subtree:add(f_control_field, control_field)
  24. offset = offset + 1
  25. -- Extract bits from Control Field
  26. local session_id = (control_field & 0x07) -- Bits 0-2
  27. local segment_type = ((control_field >> 3) & 0x03) -- Bits 3-4
  28. local seq_num_size = ((control_field >> 5) & 0x03) -- Bits 5-6
  29. local data_length_size = ((control_field >> 7) & 0x01) -- Bit 7
  30. -- Add the extracted fields to the tree
  31. local subtree1 = subtree:add(ftds_protocol, buffer(), "CONTROL FIELD DATA")
  32. subtree1:add(f_session_id, session_id)
  33. subtree1:add(f_segment_type, segment_type)
  34. subtree1:add(f_sequence_num_size, seq_num_size)
  35. subtree1:add(f_data_length_size, data_length_size)
  36. -- Sequence Number (1 to 4 bytes)
  37. local seq_num_length
  38. if seq_num_size == 0 then
  39. seq_num_length = 1
  40. elseif seq_num_size == 1 then
  41. seq_num_length = 2
  42. elseif seq_num_size == 2 then
  43. seq_num_length = 4
  44. end
  45. local sequence_num = buffer(offset, seq_num_length):le_uint()
  46. subtree:add(f_sequence_num, sequence_num)
  47. offset = offset + seq_num_length
  48. -- Data Segment Length (1 or 2 bytes)
  49. local data_length_length
  50. if data_length_size == 0 then
  51. data_length_length = 1
  52. elseif data_length_size == 1 then
  53. data_length_length = 2
  54. end
  55. local data_length = buffer(offset, data_length_length):le_uint()
  56. subtree:add(f_data_length, data_length)
  57. offset = offset + data_length_length
  58. local chunk_size = 16 -- You can adjust this value for your display preferences
  59. -- Iterate through the buffer and add chunks to the protocol tree
  60. while offset < data_length do
  61. -- Get the chunk data
  62. local chunk = buffer(offset, chunk_size)
  63. -- Format the label with the byte range, e.g., "Data bytes [0001-0016]:"
  64. local label = string.format("Data bytes [%.4d-%.4d]:", offset , offset + chunk_size)
  65. -- Add the chunk to the tree, using the label
  66. local data_field = subtree:add(f_data_bytes, chunk)
  67. -- Update the offset for the next chunk
  68. offset = offset + chunk_size
  69. end
  70. end