dissector byte swap words in double field

asked 2021-06-11 15:21:57 +0000

DanS gravatar image


I am writing a dissector using lua for data that contains 64-bit floating point numbers. I need to byte swap the bytes in each individual word in the number so that the value is displayed correctly. By this I mean that the number is transmitted as: 0011223344556677 but needs to have each word swapped so the number is read as 1100332255447766.

Currently in my dissector I have declared

fins_proto.fields.fp64       = ProtoField.double("fins.fp64", "FP64")

and have a function that extracts an array of floats function addFloats(buffer, subtree)

 for idx = 0, buffer:len()-1, 8 do
      subtree:add(fins_proto.fields.fp64, buffer(idx,8))

In order to perform the correction, I have tried to extract and concatenate individual words but get the error attempt to perform arithmetic on a userdata value.

                  ((((((((buffer(idx+1,1) * 256) + 
                         buffer(idx,1)   * 256) + 
                        buffer(idx+3,1) * 256) + 
                       buffer(idx+2,1) * 256) + 
                      buffer(idx+5,1) * 256) + 
                     buffer(idx+4,1) * 256) + 
                    buffer(idx+7,1) * 256) + 

Is there a simple way of performing this swap from the trb buffer and then evaluating the bytes as a real number?

thanks dan

edit retag flag offensive close merge delete