Creates a new ByteArray
object.
Starting in version 1.11.3, if the second argument is a boolean true
,
then the first argument is treated as a raw Lua string of bytes to use,
instead of a hexadecimal string.
local empty = ByteArray.new() local b1 = ByteArray.new("a1 b2 c3 d4") local b2 = ByteArray.new("112233")
true
is used, then the first argument
is treated as raw binary data
The new ByteArray object.
Concatenate two ByteArray
s.
The new composite ByteArray
.
Sets the size of a ByteArray
, either truncating it or filling it with zeros.
Sets the value of an index of a ByteArray
.
Get the value of a byte in a ByteArray
.
The value [0-255] of the byte.
Obtain a segment of a ByteArray
, as a new ByteArray
.
A ByteArray
containing the requested segment.
Obtain a Lua string of the binary bytes in a ByteArray
.
Since: 1.11.3
A Lua string of the binary bytes in the ByteArray.
Obtain a Lua string of the bytes in a ByteArray
as hex-ascii, with given separator
Since: 1.11.3
A hex-ascii string representation of the ByteArray
.
Obtain a Lua string containing the bytes in a ByteArray
so that it can be used in
display filters (e.g. "01FE456789AB").
A hex-ascii string representation of the ByteArray
.
function proto_foo.dissector(buf, pinfo, tree) -- Create a new tab named "My Tvb" and add some data to it local b = ByteArray.new("11223344") local tvb = ByteArray.tvb(b, "My Tvb") -- Create a tree item that, when clicked, automatically shows the tab we just created tree:add( tvb(1,2), "Foo" ) end
The created Tvb
.
A Tvb
represents the packet’s buffer. It is passed as an argument to listeners and dissectors,
and can be used to extract information (via TvbRange
) from the packet’s data.
To create a TvbRange
the Tvb
must be called with offset and length as optional arguments;
the offset defaults to 0 and the length to tvb:len()
.
Warning | |
---|---|
Tvbs are usable only by the current listener or dissector call and are destroyed as soon as the listener or dissector returns, so references to them are unusable once the function has returned. |
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.
The string.
Obtain the reported (not captured) length of packet data to end of a Tvb
or -1 if the
offset is beyond the end of the Tvb
.
The captured length of the Tvb
.
Obtain a ByteArray
from a Tvb
.
Since: 1.99.8
Tvb
. Defaults to 0.
Tvb
.
The ByteArray
object or nil.
Returns the raw offset (from the beginning of the source Tvb
) of a sub Tvb
.
The raw offset of the Tvb
.
Creates a TvbRange
from this Tvb
.
Tvb
. Defaults to 0.
Tvb
.
The TvbRange
Obtain a Lua string of the binary bytes in a Tvb
.
Since: 1.11.3
Tvb
.
A Lua string of the binary bytes in the Tvb
.
A TvbRange
represents a usable range of a Tvb
and is used to extract data from the Tvb
that generated it.
TvbRange
s are created by calling a Tvb
(e.g. 'tvb(offset,length)').
If the TvbRange
span is outside the Tvb
's range the creation will cause a runtime error.
Get a Big Endian (network order) unsigned integer from a TvbRange
.
The range must be 1-4 octets long.
The unsigned integer value.
Get a Little Endian unsigned integer from a TvbRange
.
The range must be 1-4 octets long.
The unsigned integer value
Get a Big Endian (network order) unsigned 64 bit integer from a TvbRange
, as a UInt64
object.
The range must be 1-8 octets long.
The UInt64
object.
Get a Little Endian unsigned 64 bit integer from a TvbRange
, as a UInt64
object.
The range must be 1-8 octets long.
The UInt64
object.
Get a Big Endian (network order) signed integer from a TvbRange
.
The range must be 1-4 octets long.
The signed integer value.
Get a Little Endian signed integer from a TvbRange
.
The range must be 1-4 octets long.
The signed integer value.
Get a Big Endian (network order) signed 64 bit integer from a TvbRange
, as an Int64
object.
The range must be 1-8 octets long.
The Int64
object.
Get a Little Endian signed 64 bit integer from a TvbRange
, as an Int64
object.
The range must be 1-8 octets long.
The Int64
object.
Get a Big Endian (network order) floating point number from a TvbRange
.
The range must be 4 or 8 octets long.
The floating point value.
Get a Little Endian floating point number from a TvbRange
.
The range must be 4 or 8 octets long.
The floating point value.
Get an Little Endian IPv4 Address from a TvbRange
, as an Address
object.
The IPv4 Address
object.
Get an Ethernet Address from a TvbRange
, as an Address
object.
The Ethernet Address
object.
Obtain a time_t structure from a TvbRange
, as an NSTime
object.
The NSTime
object and number of bytes used, or nil on failure.
Obtain a nstime from a TvbRange
, as an NSTime
object.
The NSTime
object.
Obtain a string from a TvbRange
.
A string containing all bytes in the TvbRange
including all zeroes (e.g., "a\000bc\000").
Obtain a Big Endian (network order) UTF-16 encoded string from a TvbRange
.
A string containing all bytes in the TvbRange
including all zeroes (e.g., "a\000bc\000").
Obtain a Little Endian UTF-16 encoded string from a TvbRange
.
A string containing all bytes in the TvbRange
including all zeroes (e.g., "a\000bc\000").
Obtain a zero terminated string from a TvbRange
.
The string containing all bytes in the TvbRange
up to the first terminating zero.
Find the size of a zero terminated string from a TvbRange
.
The size of the string includes the terminating zero.
Since: 1.11.3
Length of the zero terminated string.
Obtain a Big Endian (network order) UTF-16 encoded zero terminated string from a TvbRange
.
Two return values: the zero terminated string, and the length.
Obtain a Little Endian UTF-16 encoded zero terminated string from a TvbRange
Two return values: the zero terminated string, and the length.
Obtain a ByteArray
from a TvbRange
.
Starting in 1.11.4, this function also takes an optional encoding
argument,
which can be set to ENC_STR_HEX
to decode a hex-string from the TvbRange
into the returned ByteArray
. The encoding
can be bitwise-or’ed with one
or more separator encodings, such as ENC_SEP_COLON
, to allow separators
to occur between each pair of hex characters.
The return value also now returns the number of bytes used as a second return value.
On failure or error, nil is returned for both return values.
Note | |
---|---|
The encoding type of the hex string should also be set, for example
|
The ByteArray
object or nil, and number of bytes consumed or nil.
Get a bitfield from a TvbRange
.
TvbRange
. Defaults to 0.
The bitfield value
Creates a sub-TvbRange
from this TvbRange
.
TvbRange
. Defaults to 0.
TvbRange
.
The TvbRange
.
Obtain an uncompressed TvbRange
from a TvbRange
The TvbRange
.
Obtain the length of a TvbRange
.
Obtain the offset in a TvbRange
.
Obtain a Lua string of the binary bytes in a TvbRange
.
Since: 1.11.3
A Lua string of the binary bytes in the TvbRange
.