开发者

bytearray:set_size(5) fails for Lua Wireshark

In a Lua-based dissector, I would like to transform a tvb content to an other tvb. The code:

loca开发者_如何学Cl strbuf = buffer(offset, strlen * 2) -- range from tvb
offset = offset + strlen * 2

local inbytes = strbuf:bytes()
local outbytes = ByteArray.new()            
outbytes:set_size(strlen) -- fails; using a number instead strlen fails to

The fail message is expected userdata, got number. Why would set_size expect userdata? Alternatively, how do I allocate a ByteArray of a given size?


It seems that you found a bug in their implementation. According to their own API, creating an empty ByteArray isn't incompatible with using set_size.

I could not find an issue tracker for it, but you could try sending the bug you found to their mailing list: https://www.wireshark.org/mailman/listinfo/wireshark-dev

As an workaround, have you tried initializing the ByteArray with just an empty string?

local outbytes = ByteArray.new("") -- notice the empty string here            
outbytes:set_size(strlen)


The following works, but is not too elegant:

local s = ""
for i = 0, strlen-1 do
    s = s .. "ff"
end
local outbytes = ByteArray.new(s)            
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜