我现在正在编写Wireshark Dissector lua脚本。
如何将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)
环境
- 线鲨 3.2.1
我对 Wireshark 不是很熟悉,但通过快速浏览手册,我发现缓冲区是 Tvb
buffer()
等效于返回 TvbRange 的buffer:range()
有一个Tvb:__tostring函数声称
将 Tvb 的字节转换为字符串。这主要用于 调试目的,因为如果字符串太 长。
打印 TvbRange 被截断为 24 个字节。
我会尝试从您的 Tvb 获取一个字节数组,并使用
11.8.1.14.
bytearray:tohex([lowercase], [separator])
获取字节数组中字节的 Lua 字符串作为十六进制 ascii,并带有给定的分隔符
所以你的代码可能看起来像
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