在 Wireshark Dissector 中将用户数据转换为十六进制

Convert Userdata to hex in Wireshark Dissector

我正在编写 Wireshark Dissector lua 脚本。

如何将userdata转换为十六进制字符串?
我想得到这样的输出 0102030405060708000a0b0c0d0e0f10

我可以使用 tostring.
转换十六进制字符串 但它省略了长数据。 Output Image

如何在不省略长数据的情况下将userdata转换为十六进制字符串?

proto = Proto("Test", "My Test Protocol")

function proto.dissector(buffer, pinfo, tree)
  print(tostring(buffer()))
  -- "userdata"
  -- print(type(buffer()))
end

tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(1234, proto)

环境

我对 Wireshark 不是很熟悉,但是通过快速查看手册我知道缓冲区是 a Tvb

buffer()等同于buffer:range()其中returns一个TvbRange

有一个 Tvb:__tostring 函数声称

Convert the bytes of a Tvb into a string. This is primarily useful for debugging purposes since the string will be truncated if it is too long.

打印 TvbRange 被截断为 24 个字节。

我会尝试从您的 Tvb 获取 ByteArray 并使用

获取该 ByteArray 的十六进制字符串

11.8.1.14. bytearray:tohex([lowercase], [separator]) Obtain a Lua string of the bytes in a ByteArray as hex-ascii, with given separator

因此您的代码可能类似于

proto = Proto("Test", "My Test Protocol")
function proto.dissector(buffer, pinfo, tree)
  print(buffer:bytes():tohex())
  -- or print(buffer():bytes():tohex())
  -- but I guess if you don't give a range in buffer()
  -- it will be pretty much the same as buffer.
end