Plugin (lua) shows name but nothing else

asked 2024-06-20 07:04:42 +0000

updated 2024-06-20 21:13:33 +0000

Chuckc gravatar image

Hi there, I have a lua script for separating data, as shown I can see the name of the protocol but there is nothing else. There should be a drop down where all the data is sorted so I can read the data better. Does anyone know where the bug is here? Thank you very much.

    -- Definieren der Protokollinformationen
local p_wsci = Proto("wsci", "Workstation Control Interface")

-- Definieren der Felder, die im Protokoll angezeigt werden sollen
local f_wsci_action = ProtoField.string("wsci.action", "Action")
local f_wsci_data = ProtoField.string("wsci.data", "Data")

p_wsci.fields = {f_wsci_action, f_wsci_data}

-- Definieren der Dissektor-Funktion
function p_wsci.dissector(tvb, pinfo, tree)
    pinfo.cols.protocol:set("WSCI")
    pinfo.cols.info:clear()

    local subtree = tree:add(p_wsci, tvb())

    -- Überprüfung, ob die Daten mit 55555555000000b200000002 beginnen
    local data = tvb:range(0):bytes():tohex()
    print("Data: " .. data)  -- Print the data for debugging
    if string.sub(data, 1, 24) == "55555555000000b200000002" then
        print("Data starts with 55 55 55 55 00 00 00 b2 00 00 00 02")  -- Print a message for debugging
        -- Extrahieren der benötigten Ziffern
        local action = tvb:range(12):string()
        subtree:add(f_wsci_action, action)

        -- Extrahieren der Daten und Umwandeln von Hexadezimal in ASCII
        local hex_data = string.sub(data, 25)
        local ascii_data = ""
        for i = 1, #hex_data, 2 do
            local byte = string.sub(hex_data, i, i+1)
            ascii_data = ascii_data .. string.char(tonumber(byte, 16))
        end
        print("ASCII data: " .. ascii_data)  -- Print the ASCII data for debugging

        -- Aufteilen der Daten an den Kommas und Hinzufügen zu einem Dropdown-Menü
        local data_items = split(ascii_data, ',')
        for i, item in ipairs(data_items) do
            subtree:add(f_wsci_data, item)
        end
    end
end

-- Funktion zum Aufteilen einer Zeichenkette an einem Trennzeichen
function split(s, delimiter)
    result = {}
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match)
    end
    return result
end

-- Registrieren vom Dissektor
local tcp_port = DissectorTable.get("tcp.port")
tcp_port:add(55671, p_wsci)
edit retag flag offensive close merge delete

Comments

Test packet:

0000   20 52 45 43 56 00 20 53 45 4e 44 00 08 00 45 00
0010   00 34 12 34 00 00 ff 06 92 8a 0a 01 01 01 0a 02
0020   02 02 00 00 d9 77 00 00 00 00 00 00 00 00 50 00
0030   20 00 f3 fc 00 00 55 55 55 55 00 00 00 b2 00 00
0040   00 02
Chuckc gravatar imageChuckc ( 2024-06-20 20:43:49 +0000 )edit

Uppercase "B" vs lowercase "b".
f_wsci_action is not a string in hex bytes.
Give the range a start just to be clear what it wants.

        local action = tvb:range(0,12)
        subtree:add(f_wsci_action, action)
Data: 55555555000000B200000002

Data starts with 55 55 55 55 00 00 00 B2 00 00 00 02
Workstation Control Interface
    Action: 55555555000000b200000002
    Data: 

    -- Definieren der Protokollinformationen
local p_wsci = Proto("wsci", "Workstation Control Interface")

-- Definieren der Felder, die im Protokoll angezeigt werden sollen
local f_wsci_action = ProtoField.bytes("wsci.action", "Action")
local f_wsci_data = ProtoField.string("wsci.data", "Data")

p_wsci.fields = {f_wsci_action, f_wsci_data}

-- Definieren der Dissektor-Funktion
function p_wsci.dissector(tvb, pinfo, tree)
    pinfo.cols.protocol:set("WSCI")
    pinfo.cols.info:clear()

    local subtree = tree:add(p_wsci, tvb())

    -- Überprüfung, ob die Daten mit 55555555000000b200000002 beginnen
    local data = tvb:range(0):bytes():tohex()
    print("Data: " .. data)  -- Print the data for debugging
    if string.sub(data, 1, 24) == "55555555000000B200000002" then
        print ...
(more)
Chuckc gravatar imageChuckc ( 2024-06-20 21:07:55 +0000 )edit

Lowercase tohex() available with flag:

    local data = tvb:range(0):bytes():tohex(true)
Chuckc gravatar imageChuckc ( 2024-06-20 21:12:23 +0000 )edit