DLN DLN - 2 months ago 16
Python Question

Decoding Actionscript ByteArray using python

I am using actionscript to send an array to the server with this code(I am only writing that part of the code here):-

var a:ByteArray=new ByteArray;
a.writeObject({'a':'b','c':'d'});
socket.writeBytes(a);
socket.flush();


here I already opened a socket to a port on my server and I have a python code listenting on that port. How do I decode the bytes I receive using python when I run the swf after compiling it?
I received the following in the server side:-
b'\n\x0b\x01\x03c\x06\x03d\x03a\x06\x03b\x01'

Answer

ActionScript uses AMF format. There is an AMF library for Python which you can use: PyAMF.

I got this when I tested it (with Python 2.7):

>>> import pyamf
>>> for item in pyamf.decode('\n\x0b\x01\x03c\x06\x03d\x03a\x06\x03b\x01'):
...     print item
...
{'a': u'b', 'c': u'd'}