#
# By Fermin J. Serna - fjserna@gmail.com - @fjserna
# http://zhodiac.hispahack.com
# Jul/19/2013
#

import zlib
from StringIO import StringIO

def decompressSWF(f):
	if type(f) is str:
		f = StringIO(f)
      
	f.seek(0, 0)
	magic = f.read(3)
   
	if magic == "CWS":
		return "FWS" + f.read(5) + zlib.decompress(f.read())
	else:
		return None

def test():
	fich=file('Test.swf', 'rb')
	data = decompressSWF(fich.read())
	fich.close()

	fich=file('Test.swf', 'wb')
	fich.write(data)
	fich.close()
	
	print "decompressed (%d) bytes" % (len(data))
   
   
if __name__ == "__main__":
	test()