Ask Your Question

custom LUA dissector: format display

asked 2018-12-12 14:12:18 +0000

BMWE gravatar image

updated 2019-01-30 17:18:33 +0000

cmaynard gravatar image


Lets say I'd like to have a field named ABC which will be 2 unsigned bytes: 0 to 65535 However, the actual value which is represented is -5.0 to 60.0 with linear conversion between the bits to the actual value.

I have some XML which defines the messages and their elements: the name, location, bits value (min & max), actual value (min & max), how it is stored in the database (XML is output from the database), conversion type.

I'm writing some conversion tool from the XML to LUA format. How should I write the dissector so that I'll see values between -5 to 60 ?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-12-13 19:50:14 +0000

cmaynard gravatar image

updated 2018-12-13 19:50:39 +0000

The basic idea is to grab the 2-byte value and only add it to the tree after some computation is performed on it. Below is a simple Lua snippet to illustrate the idea and assumes the byte-order is big-endian (use le_uint() instead of uint() if it's little-endian):

abc = buf(offset, 2):uint()
abc_tree:add(f_abc, buf(offset, 2)):set_text(string.format("ABC: %f", -5.0 + (abc * 65.0/65535)))
edit flag offensive delete link more


Thank you, I'll check it once I'll get my work computer. Meanwhile, can it be written in single line?

BMWE gravatar imageBMWE ( 2018-12-14 03:51:35 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-12-12 14:12:18 +0000

Seen: 530 times

Last updated: Dec 13 '18