lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> To be more precise I'd like to convert a string into a userdata so I can use that type of function :
> 
> function xxx(buf,pkt,tree)
>
> local apdu = buf(0,1):uint()
> local pdu_variant = buf(1,1):uint()

...

As the others said, this is not really a Lua question but instead a Wireshark API question.

Just as a starting pointer: the "buf" your dissector gets is a Wireshark object of type "Tvb" [1], representing the packet's buffer.
Calling it with (0,1) returns a TvbRange [2].

So if you wanted to create an intermediate/temporary Tvb from an array of bytes, you would want to look at (Wireshark) functions that create Tvbs. A quick scan of the Wireshark API documentation [3] leads me to believe that what you're looking for is a "ByteArray" [4] (again, a Wireshark construct, not a Lua feature).

From the ByteArray documentation, it is evident that you can construct ByteArray objects (with the .new function) and then construct a Tvb with the .tvb function, which seems roughly what you want to do.

Maybe there are other methods but that's a Wireshark question.

Cheers,
Tom

PS: You did not mention what your intent is. If it is some sort of unit-testing framework for your dissector, be aware that all the listed functions (Tvb/ByteArray etc.) are extensions to Lua, provided by Wireshark. They will only work inside the Wireshark implementation (or a clone thereof that you would have to provide).


[1] https://wiki.wireshark.org/LuaAPI/Tvb#Tvb
[2] https://wiki.wireshark.org/LuaAPI/Tvb#TvbRange
[3] https://wiki.wireshark.org/LuaAPI
[4] https://wiki.wireshark.org/LuaAPI/ByteArray