In my dissector I have this code
My problem is in second bitwise operation in I know, that problem might be in With any values I got this message: asked 13 Feb '14, 02:00 im_infamous |
2 Answers:
Problem solved. The matter is that my dissector don't cover cases of null application protocol payload, and thats why i got these errors. The solution is to add one "if" statement, that checks out length of the payload. Hadriel, thank you very much for your help. answered 14 Feb '14, 02:03 im_infamous edited 14 Feb '14, 02:07 |
ByteArray:set_index() and get_index() actually use 0-based indexing, not normal Lua 1-based indexing. The only time you should see that "index out of range" error is if the index number you used in ByteArray:get_index() was either negative, or it's greater than or equal to the length of the Byte Array. Which exact line in that code snippet is causing you the error? Also, just to be clear, your code snippet is this, right?:
answered 13 Feb '14, 10:02 Hadriel showing 5 of 6 show 1 more comments |
Thanks for your reply! Yep, we are talking about that snippet. The error now is in the second line and sounds like "attempt to index ByteArray global (a nil value)"
What wireshark version/release are you using?
Im using wireshark portable 1.8.2
When evaluating lua in wireshark, I got message "bad argument #1 to 'get index' (index out of range) and when it comes to lua executor "attempt to index global ByteArray(a nil value)"
Oh, you were trying this in just the stand-alone lua interpreter? (i.e. outside of wireshark) Then yes, of course it would give that "a nil value" error. That error is telling you there's no global variable named "ByteArray", and thus no table to try calling "ByteArray.new()" on. There is no such global variable in that, because ByteArray is a table created by Wireshark, not something Lua comes with. That's why I was asking what version you were running, because it didn't make sense that it couldn't find a ByteArry table - but if you got that error when you were just running the Lua interpreter by itself, then sure it won't work. As for the other error - the "index out of range" one, I'll look into the 1.8.2 code but basically it means what I had said: the index number you're giving it is either negative or greater than or equal to the length of the byte array.
Is it possible the Tvb only had one or zero bytes in it? In other words, your call to 'data_tvb():bytes()', which returns a ByteArray from the Tvb - could it just be only one byte? If so, your for-loop will get messed up and be trying to get_index() too large a number.
Regardless, try putting some print() statements in the code to see what the values of those things are. Like 'print("len="..defaultdata:len())'