Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Looking for strategies When Lua dissectors are getting too big

Hey there!

While working on my first dissector I hit Wireshark's and Lua's ressource constraints. I used up all the 200 local variables at ProtoFields, and from the looks I still have use for at least 200+ variables. At the moment the dissector has about 2000 lines of code, and I covered roughly 20% of the protocol.

I get error messages like these:

  • [..] too many local variables (limit is 200) ..
  • [..] function or expression too complex near ..

The second error is apparently from the Lua VM. According to this SO comment the Lua VM has (only) 255 registers: https://stackoverflow.com/q/54609218

There is potential to reduce the number of local variables within functions that get referenced by proto.dissector() - but the readability of the code will suffer, and I'm not sure if these non-ProtoField local variables are contributing to the exhaustion after all. Nevertheless such an optimization won't free nearly enough variables to cover the remaining 80% of the protocol.

I found this posting in which cmaynard suggested putting the variables in a Lua table but the example wasn't verbose enough for me to successfully apply. I tried putting ProtoFields in a table but I failed unpacking the content in proto.fields = {}. :(

https://osqa-ask.wireshark.org/questions/63458/how-to-circumvent-lua-limitation-for-200-local-variables-when-machine-generating-a-dissector-from-xml-description-of-protocol/

So what are the/my options to successfully implement such a variable-heavy protocol in Wireshark?

  • Break up the dissector and write a dissector for each component of the protocol?
  • Use global variables instead of local vars?
  • [Your brilliant suggestions here :) ]

Thank you and have a nice day!

Looking for strategies When Lua dissectors are getting too big

Hey there!

While working on my first dissector I hit Wireshark's and Lua's ressource constraints. I used up all the 200 local variables at ProtoFields, and from the looks I still have use for at least 200+ variables. At the moment the dissector has about 2000 lines of code, and I covered roughly 20% of the protocol.

I get error messages like these:

  • [..] too many local variables (limit is 200) ..
  • [..] function or expression too complex near ..

The second error is apparently from the Lua VM. According to this SO comment the Lua VM has (only) 255 registers: https://stackoverflow.com/q/54609218

There is potential to reduce the number of local variables within functions that get referenced by proto.dissector() - but the readability of the code will suffer, and I'm not sure if these non-ProtoField local variables are contributing to the exhaustion after all. Nevertheless such an optimization won't free nearly enough variables to cover the remaining 80% of the protocol.

I found this posting in which cmaynard suggested putting the variables in a Lua table but the example wasn't verbose enough for me to successfully apply. I tried putting ProtoFields in a table but I failed unpacking the content in proto.fields = {}. :(

https://osqa-ask.wireshark.org/questions/63458/how-to-circumvent-lua-limitation-for-200-local-variables-when-machine-generating-a-dissector-from-xml-description-of-protocol/

So what are the/my options to successfully implement such a variable-heavy protocol in Wireshark?

  • Break up the dissector and write a dissector for each component of the protocol?
  • Use global variables instead of local vars?
  • [Your brilliant suggestions here :) ]

Thank you and have a nice day!