floating point issue in wsgd dissector
i have implemented the following function in a wsgd dissector:
function string hex_and_float (in uint32 value)
{
hide var uint32 b0 = (value & 0xFF000000) >> 8;
hide var uint32 b1 = (value & 0x00FF0000) << 8;
hide var uint32 b2 = (value & 0x0000FF00) >> 8 ;
hide var uint32 b3 = (value & 0x000000FF) << 8;
hide var uint32 i = b0 + b1 + b2 + b3;
hide var string str = print("0x%x (%.2e)", i, i);
return str;
}
The string returned is correct for the hexadecimal part but not for the floating part. It seems that the variable i is considered as a 64 bits float. But it's a 32 bit float.
Example of output of hex_and_float():
0x428c4dad (5.52e-315)
How to force the print function to consider i as a 32 bits float ?
With the disclaimer that all this is very non-portable, but how about:
float *fp = (float *)&i; float f = *fp; print("0x%x (%.2e)", i, f);The function hex_and_float() is written in WSGD syntax not C.
The value for a
uint32can exceed the range of a float32.If you know the value will be less than max for a
float32, how about:hide var float32 flt = i;or
hide var float32 flt = b0 + b1 + b2 + b3;Yes the value will always fit in a float32. Already tested:
It's not working. The issue seems to be located in the print() function. Any number given to
%for%eseems promoted to 64 bits float. It may be related to Wireskark running in 64 bits ?byte_interpret.cpp:
promote_printf_string_to_64bits(words[0]);Maybe open an issue with
WSGD? WireShark Generic Dissector -Issues