""" SWF (Macromedia/Adobe Flash) file parser. Documentation: - Alexis' SWF Reference: http://www.m2osw.com/swf_alexref.html Author: Sebastien Ponce Creation date: 26 April 2008 """ from lib.hachoir_core.field import (FieldSet, ParserError, Bit, Bits, UInt8, UInt32, Int16, UInt16, Float32, CString, RawBytes) #from lib.hachoir_core.field import Field from lib.hachoir_core.field.float import FloatExponent from struct import unpack class FlashFloat64(FieldSet): def createFields(self): yield Bits(self, "mantisa_high", 20) yield FloatExponent(self, "exponent", 11) yield Bit(self, "negative") yield Bits(self, "mantisa_low", 32) def createValue(self): # Manual computation: # mantisa = mantisa_high * 2^32 + mantisa_low # float = 2^exponent + (1 + mantisa / 2^52) # (and float is negative if negative=True) bytes = self.parent.stream.readBytes( self.absolute_address, self.size//8) # Mix bytes: xxxxyyyy <=> yyyyxxxx bytes = bytes[4:8] + bytes[0:4] return unpack('