This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

LUA: hex-highlighting for self made fields

1

How do I make it that if I click on a self made protocol field in the packet detail window that the hex data in the Packet Bytes window get highlighted?

asked 18 May '11, 01:01

chill's gravatar image

chill
16223
accept rate: 0%


One Answer:

0

There are a couple ways: add a ProtoField (which must include a buffer), or add a buffer with a label.

proto_foo = Proto("foo", "Foo Protocol")
proto_foo.fields.bar = ProtoField.uint32("foo.bar", "Bar field")

function proto_foo.dissector(buf, pinfo, tree) – we need at least 5 bytes… if buf:len() < 5 then return end

-- Add the first 4 bytes as an unsigned integer.
-- Bytes 0 through 3 will be highlighted when the
-- bar field is selected in the packet details.
tree:add( proto_foo.fields.bar, buf(0, 4) )

-- Add the next byte ad hoc. Byte 4 will be highlighted
-- when this ad-hoc field is selected in the packet
-- details.
tree:add( buf(4, 1), &quot;Ad-hoc byte&quot; )

end

answered 18 May ‘11, 08:09

bstn's gravatar image

bstn
3751415
accept rate: 14%

at first thx for the hint with the buffer(x,y) thats nice. So my code is working now but It look a bit redundancy.

My Code: local F_md5 = ProtoField.string(“http.my.md5”, “MD5: “) local subtreeitem = treeitem:add(http_my_proto, tvbuffer) subtreeitem:set_text(“http post decoded”) subtreeitem:add(F_md5, tvbuffer(1,32), s_info[‘md5’]):set_text(“MD5: " .. s_info[‘md5’])

if I write it that way:

My Code: local F_md5 = ProtoField.string(“http.my.md5”, “MD5: “) local subtreeitem = treeitem:add(http_my_proto, tvbuffer) subtreeitem:set_text(“http post decoded”) subtreeitem:add(F_md5, tvbuffer(1,32), s_info[‘md5’]

then the n in the s_info[‘md5’] is not translated.

btw: how do I mark code as code?

(19 May ‘11, 01:30) chill

First, you don’t need to add a colon to the ProtoField description because that’s already done internally. That should be ProtoField.string(“http.my.md5”, “MD5”). In your 1st example, there’s no point in using the ProtoField’s label arg since you’re just going to overwrite the entire tree-item text with set_text. The two examples should produce the same results, assuming s_info[‘md5’] is a string. What does s_info[‘md5’] return?

(19 May ‘11, 14:46) bstn

Three ways to mark text as code:

  1. Surround the text with backticks (`); This is the only way to do it for comments (afaik).
  2. Select the text and click the “Code Sample button” in the answer toolbar (the button that shows as 101010); This can only be done for answers.
  3. Select the text and press Ctrl+K; This can only be done for answers.
(19 May ‘11, 14:52) bstn