Пример #1
0
    def __init__(self, io):
        if isinstance(io, str):
            io = StringIO(io)

        self.signature, self.version, self.filesize = struct.unpack(
            '<3sBL', io.read(8))
        self.frame_size = StructRect(io)
        self.frame_rate, self.frame_count = struct.unpack('<HH', io.read(4))
        self.frame_rate /= 0x100

        # if self.is_compressed():
        #     body = io.read()
        #     io = StringIO(zlib.decompress(io.read()))
        #     self.signature = 'FWS'

        self.tags = []
        tag = None
        while tag is None or not isinstance(tag, swftag.End):
            tag = SWFTag(io)
            self.tags.append(tag)
Пример #2
0
class StructRectTestCase(unittest.TestCase):
    def setUp(self):
        self.rect = StructRect(cws_bytes[8:])
        self.original_bytes = cws_bytes[8:8+len(self.rect)]

    def testParseRect(self):
        assert self.rect[0] == 0
        assert self.rect[1] == 4800
        assert self.rect[2] == 0
        assert self.rect[3] == 4800

    def testBuildRect(self):
        assert self.rect.build() == self.original_bytes
Пример #3
0
class StructRectTestCase(unittest.TestCase):
    def setUp(self):
        self.rect = StructRect(cws_bytes[8:])
        self.original_bytes = cws_bytes[8:8 + len(self.rect)]

    def testParseRect(self):
        assert self.rect[0] == 0
        assert self.rect[1] == 4800
        assert self.rect[2] == 0
        assert self.rect[3] == 4800

    def testBuildRect(self):
        assert self.rect.build() == self.original_bytes
Пример #4
0
    def __init__(self, io):
        if isinstance(io, str):
            io = StringIO(io)

        self.signature, self.version, self.filesize = struct.unpack('<3sBL',
                                                                    io.read(8))
        self.frame_size  = StructRect(io)
        self.frame_rate, self.frame_count = struct.unpack('<HH', io.read(4))
        self.frame_rate /= 0x100

        # if self.is_compressed():
        #     body = io.read()
        #     io = StringIO(zlib.decompress(io.read()))
        #     self.signature = 'FWS'

        self.tags = []
        tag = None
        while tag is None or not isinstance(tag, swftag.End):
            tag = SWFTag(io)
            self.tags.append(tag)
Пример #5
0
class SWF:
    __images = None

    def __init__(self, io):
        if isinstance(io, str):
            io = StringIO(io)

        self.signature, self.version, self.filesize = struct.unpack('<3sBL',
                                                                    io.read(8))
        self.frame_size  = StructRect(io)
        self.frame_rate, self.frame_count = struct.unpack('<HH', io.read(4))
        self.frame_rate /= 0x100

        # if self.is_compressed():
        #     body = io.read()
        #     io = StringIO(zlib.decompress(io.read()))
        #     self.signature = 'FWS'

        self.tags = []
        tag = None
        while tag is None or not isinstance(tag, swftag.End):
            tag = SWFTag(io)
            self.tags.append(tag)

    def is_compressed(self):
        if self.signature == 'CWS':
            return True
        elif self.signature == 'FWS':
            return False
        else:
            raise SWFParseError, 'invalid signature %s' % self.signature

    @property
    def x_min(self):
        return self.frame_size[0] / 20

    @property
    def x_max(self):
        return self.frame_size[1] / 20

    @property
    def y_min(self):
        return self.frame_size[2] / 20

    @property
    def y_max(self):
        return self.frame_size[3] / 20

    @property
    def width(self):
        return self.x_max - self.x_min

    @property
    def height(self):
        return self.y_max - self.y_min

    def build_header(self):
        # self.filesize += sum(tag.filesize_changed for tag in self.tags)
        self.filesize = 12 + len(self.frame_size) + sum(len(tag) for tag in self.tags)
        return struct.pack('<3sBL', self.signature, self.version, self.filesize) + \
               self.frame_size.build() + \
               struct.pack('<HH', self.frame_rate * 0x100, self.frame_count)
        
    def build(self):
        return self.build_header() + ''.join(tag.build() for tag in self.tags)

    def find_tag(self, cls):
        for tag in self.tags:
            if isinstance(tag, cls):
                return tag

    def find_tags(self, cls):
        return tuple(tag for tag in self.tags if isinstance(tag, cls))

    @property
    def images(self):
        if self.__images is None:
            self.__images = SWFImages(self)
        return self.__images
Пример #6
0
 def setUp(self):
     self.rect = StructRect(cws_bytes[8:])
     self.original_bytes = cws_bytes[8:8+len(self.rect)]
Пример #7
0
 def bounds(self):
     if self.__bounds is None:
         self.body_bits.seekbyte(2)
         self.__bounds = StructRect(bits=self.body_bits)
     return self.__bounds
Пример #8
0
 def setUp(self):
     self.rect = StructRect(cws_bytes[8:])
     self.original_bytes = cws_bytes[8:8 + len(self.rect)]
Пример #9
0
class SWF:
    __images = None

    def __init__(self, io):
        if isinstance(io, str):
            io = StringIO(io)

        self.signature, self.version, self.filesize = struct.unpack(
            '<3sBL', io.read(8))
        self.frame_size = StructRect(io)
        self.frame_rate, self.frame_count = struct.unpack('<HH', io.read(4))
        self.frame_rate /= 0x100

        # if self.is_compressed():
        #     body = io.read()
        #     io = StringIO(zlib.decompress(io.read()))
        #     self.signature = 'FWS'

        self.tags = []
        tag = None
        while tag is None or not isinstance(tag, swftag.End):
            tag = SWFTag(io)
            self.tags.append(tag)

    def is_compressed(self):
        if self.signature == 'CWS':
            return True
        elif self.signature == 'FWS':
            return False
        else:
            raise SWFParseError, 'invalid signature %s' % self.signature

    @property
    def x_min(self):
        return self.frame_size[0] / 20

    @property
    def x_max(self):
        return self.frame_size[1] / 20

    @property
    def y_min(self):
        return self.frame_size[2] / 20

    @property
    def y_max(self):
        return self.frame_size[3] / 20

    @property
    def width(self):
        return self.x_max - self.x_min

    @property
    def height(self):
        return self.y_max - self.y_min

    def build_header(self):
        # self.filesize += sum(tag.filesize_changed for tag in self.tags)
        self.filesize = 12 + len(self.frame_size) + sum(
            len(tag) for tag in self.tags)
        return struct.pack('<3sBL', self.signature, self.version, self.filesize) + \
               self.frame_size.build() + \
               struct.pack('<HH', self.frame_rate * 0x100, self.frame_count)

    def build(self):
        return self.build_header() + ''.join(tag.build() for tag in self.tags)

    def find_tag(self, cls):
        for tag in self.tags:
            if isinstance(tag, cls):
                return tag

    def find_tags(self, cls):
        return tuple(tag for tag in self.tags if isinstance(tag, cls))

    @property
    def images(self):
        if self.__images is None:
            self.__images = SWFImages(self)
        return self.__images