我正在编写Wireshark Dissector脚本。
如何将userdata转换为十六进制字符串?
我想要输出像这样的0102030405060708000a0b0c0d0e0f10
我可以使用tostring转换十六进制字符串。
但它忽略了长数据。输出图像
如何在不忽略长数据的情况下将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)环境
发布于 2020-06-07 07:49:17
我对Wireshark不是很熟悉,但是快速查看一下手册,我得到的缓冲区是无线电视
buffer()与返回TvbRange的buffer:range()等效
有一个Tvb:__tostring函数,它声称
将Tvb的字节转换为字符串。这主要用于调试目的,因为如果字符串太长,字符串将被截断。
打印一个TvbRange被截断为24个字节。
我将尝试从您的Tvb中获取一个ByteArray,并使用以下方法获取ByteArray的十六进制字符串
11.8.1.14
bytearray:tohex([lowercase], [separator])以十六进制的形式获取ByteArray中字节的Lua字符串,并使用给定的分隔符。
所以您的代码可能看起来像
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.
endhttps://stackoverflow.com/questions/62240784
复制相似问题