I need to analyze amf data.
Unfortunately, data contains dictionary market dictionary-marker=0x11
and pyamf failed to parse it.
Nevertheless I dont need to parse it all, I need to analyze only some pieces of data
For example when I need to get amf-integer, I can use the following function
def parse_u29(byte_sequence):
value = 0
# Handle the initial bytes
for byte in byte_sequence[:-1]:
# Ensure it has its high bit set.
assert byte & 0x80
# Extract the value and add it to the accumulator.
value <<= 7
value |= byte & 0x7F
# Handle the last byte.
value <<= 8 if len(byte_sequence) > 3 else 7
value |= byte_sequence[-1]
# Handle sign.
value = (value + 2**28) % 2**29 - 2**28
return value
Can be something similar way to get Numeric data (with floating point)?
And the reversed function for both Integer and number with a python?
So I need something like def parse_numeric(byte_sequence), def create_u29(...), def create_numeric(...)
UPD: thanks to found source I get int encoder to u29 as:
def encode_int_to_u29(value):
tmp = []
value &= 0x1fffffff
if value < 0x80
tmp.append(value)
elif value < 0x4000:
tmp.append((value >> 7 & 0x7f) | 0x80)
tmp.append(value & 0x7f)
elif value < 0x200000:
tmp.append((value >> 14 & 0x7f) | 0x80)
tmp.append((value >> 7 & 0x7f) | 0x80)
tmp.append(value & 0x7f)
elif value < 0x40000000:
tmp.append((value >> 22 & 0x7f) | 0x80)
tmp.append((value >> 15 & 0x7f) | 0x80)
tmp.append((value >> 8 & 0x7f) | 0x80)
tmp.append(value & 0xff)
else:
raise ValueError('Int is too big to be encoded by amf')
return b"".join([int.to_bytes(item, 1, 'big') for item in tmp])
But I'm still in trouble with numeric types.