Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Final code. I'm happy with that :)

function hex2string(buffer, offset, len)
  local bytearr = {}
  for i = 1, len do
    bytearr[i] = string.format("%.2X", buffer(offset +i-1, 1):uint())
  end
  return table.concat(bytearr)
end

function hex2ascii(buffer, offset, len)
  local bytearr = {}
  for i = 1, len do
    bytearr[i] = string.char(buffer(offset +i-1, 1):uint())
  end
  return table.concat(bytearr)
end


    f.data = ProtoField.bytes ("S8HR_proto.data", "Data Hex")

    local tlv_data = tlv_tree:add (f.data, buffer(offset, tlvlen))
    local data_hex = hex2string(buffer, offset, tlvlen)
    local data_ascii = hex2ascii(buffer, offset, tlvlen)
    tlv_data:set_text("Data Hex: " .. data_hex .. ", Data Ascii: '".. data_ascii .. "'")

It basically set the tree with f.data (so it get highlighted when selected). It also read the sequence and store as hex-string and ascii-string. Finally it update the tree's text with that value.

Hope it could be of any help for other Lua's newbies.