Git Product home page Git Product logo

pyswf's Introduction

PYSWF

A Python library for reading and writing SWF files. PYSWF is a Python port of Claus Wahlers great SWF parser https://github.com/claus/as3swf Can't thank Claus enough!

Build Status

INSTALL

$ pip install pyswf==1.5.4

or:

$ git clone [email protected]:timknip/pyswf.git
$ cd pyswf
$ python setup.py install

or you might need do:

$ sudo python setup.py install

WINDOWS

Install Pillow, lxml and pylzma from a binary distribution before running setup.

Installing the *.whl files:

$ pip install the-downloaded.whl

USAGE

Basic example:

from swf.movie import SWF

# create a file object
file = open('path/to/swf', 'rb')

# print out the SWF file structure
print SWF(file)

SVG export example:

from swf.movie import SWF
from swf.export import SVGExporter

# create a file object
file = open('path/to/swf', 'rb')

# load and parse the SWF
swf = SWF(file)

# create the SVG exporter
svg_exporter = SVGExporter()

# export!
svg = swf.export(svg_exporter)

# save the SVG
open('path/to/svg', 'wb').write(svg.read())

pyswf's People

Contributors

apolkosnik-old avatar charley-peng avatar counterpillow avatar crackinglandia avatar ctz avatar intonarumori avatar jackrusher avatar leag avatar marcocova avatar mikep-moto avatar robvinson avatar skrat avatar timknip avatar timknip2 avatar tuomassalo avatar zhzhzoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyswf's Issues

Unknown fill style type: 0xff

Problem happens when converting a SWF to SVG. (I'm running on Windows 8.1 Pro 64-bit)

Log:

Traceback (most recent call last):
  File "C:\pyswf-master\build\lib\convert.py", line 8, in <module>
    swf = SWF(file)
  File "C:\pyswf-master\build\lib\swf\movie.py", line 87, in __init__
    self.parse(self._data)
  File "C:\pyswf-master\build\lib\swf\movie.py", line 143, in parse
    self.parse_tags(data)
  File "C:\pyswf-master\build\lib\swf\tag.py", line 112, in parse_tags
    tag = self.parse_tag(data)
  File "C:\pyswf-master\build\lib\swf\tag.py", line 130, in parse_tag
    tag.parse(data, raw_tag.header.content_length, tag.version)
  File "C:\pyswf-master\build\lib\swf\tag.py", line 1313, in parse
    self.glyphShapeTable.append(data.readSHAPE(self.unitDivisor))
  File "C:\pyswf-master\build\lib\swf\stream.py", line 200, in readSHAPE
    return SWFShape(self, 1, unit_divisor)
  File "C:\pyswf-master\build\lib\swf\data.py", line 50, in __init__
    self.parse(data, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 56, in parse
    self.read_shape_records(data, fillbits, linebits, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 92, in read_shape_records
    style_change_record = data.readSTYLECHANGERECORD(states, fill_bits, line_bits, level)
  File "C:\pyswf-master\build\lib\swf\stream.py", line 216, in readSTYLECHANGERECORD
    return SWFShapeRecordStyleChange(self, states, fill_bits, line_bits, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 605, in __init__
    super(SWFShapeRecordStyleChange, self).__init__(data, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 522, in __init__
    self.parse(data, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 620, in parse
    self.fill_styles.append(data.readFILLSTYLE(level))
  File "C:\pyswf-master\build\lib\swf\stream.py", line 220, in readFILLSTYLE
    return SWFFillStyle(self, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 757, in __init__
    self.parse(data, level)
  File "C:\pyswf-master\build\lib\swf\data.py", line 770, in parse
    raise Exception("Unknown fill style type: 0x%x" % self.type, level)
Exception: ('Unknown fill style type: 0xff', 1)

TypeError: ord() expected a character, but string of length 0 found

pyswf spends a lot of time parsing the file (around 10-20 mins) and then it finally fails with:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-75ab7c2ec624> in <module>()
----> 1 get_ipython().magic(u'time swf.movie.SWF(f)')

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2203         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2204         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205         return self.run_line_magic(magic_name, magic_arg_s)
   2206
   2207     #-------------------------------------------------------------------------

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2124                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2125             with self.builtin_trap:
-> 2126                 result = fn(*args,**kwargs)
   2127             return result
   2128

/usr/local/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)

/usr/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194
    195         if callable(arg):

/usr/local/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)
   1123         if mode=='eval':
   1124             st = clock2()
-> 1125             out = eval(code, glob, local_ns)
   1126             end = clock2()
   1127         else:

<timed eval> in <module>()

/usr/local/lib/python2.7/site-packages/swf/movie.pyc in __init__(self, file)
     85         self._header = None
     86         if self._data is not None:
---> 87             self.parse(self._data)
     88
     89     @property

/usr/local/lib/python2.7/site-packages/swf/movie.pyc in parse(self, data)
    141             self._header._frame_rate = data.readFIXED8()
    142             self._header._frame_count = data.readUI16()
--> 143         self.parse_tags(data)
    144
    145

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse_tags(self, data, version)
    110         tag = None
    111         while type(tag) != TagEnd:
--> 112             tag = self.parse_tag(data)
    113             if tag:
    114                 #print tag.name

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse_tag(self, data)
    128             data.seek(raw_tag.pos_content)
    129             data.reset_bits_pending()
--> 130             tag.parse(data, raw_tag.header.content_length, tag.version)
    131             #except:
    132             #    print "=> tag_error", tag.name

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse(self, data, length, version)
    735                     temp.read(1) # reserved, always 0
    736                 a = ord(temp.read(1)) if is_lossless2 else 0xff
--> 737                 r = ord(temp.read(1))
    738                 g = ord(temp.read(1))
    739                 b = ord(temp.read(1))

TypeError: ord() expected a character, but string of length 0 found

Here is the SWF I used: https://a.pomf.se/rhdxca.swf

FFDec can open and parse it correctly in around 2 seconds.

How to convert a swf document to pdf or other type docs ?

您好!
我想使用您开发的代码读取一个swf格式的文件,具体的文件位置
但是在使用是出线如下问题?

In [2]: file = open("a.swf", "rb")

In [3]: obj = SWF(fil)
%%file  file    file=   filter  

In [3]: obj = SWF(file)
%%file  file    file=   

In [3]: obj = SWF(file)
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-3dffa1f5b810> in <module>()
----> 1 obj = SWF(file)

/usr/local/lib/python2.7/site-packages/swf/movie.pyc in __init__(self, file)
     99         self._header = None
    100         if self._data is not None:
--> 101             self.parse(self._data)
    102 
    103     @property

/usr/local/lib/python2.7/site-packages/swf/movie.pyc in parse(self, data)
    161         self._header._frame_rate = data.readFIXED8()
    162         self._header._frame_count = data.readUI16()
--> 163         self.parse_tags(data)
    164 
    165     def __str__(self):

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse_tags(self, data, version)
    161         tag = None
    162         while type(tag) != TagEnd:
--> 163             tag = self.parse_tag(data)
    164             if tag:
    165                 #print tag.name

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse_tag(self, data)
    179             data.seek(raw_tag.pos_content)
    180             data.reset_bits_pending()
--> 181             tag.parse(data, raw_tag.header.content_length, tag.version)
    182             #except:
    183             #    print "=> tag_error", tag.name

/usr/local/lib/python2.7/site-packages/swf/tag.pyc in parse(self, data, length, version)
    888             s.close()
    889 
--> 890             im = Image.fromstring("RGBA", (self.padded_width, self.bitmap_height), self.image_buffer)
    891             im = im.crop((0, 0, self.bitmap_width, self.bitmap_height))
    892 

/usr/local/lib/python2.7/site-packages/PIL/Image.pyc in fromstring(*args, **kw)
   2078 def fromstring(*args, **kw):
   2079     raise NotImplementedError("fromstring() has been removed. " +
-> 2080                     "Please call frombytes() instead.")
   2081 
   2082 

NotImplementedError: fromstring() has been removed. Please call frombytes() instead.

Print SWF(file) not working.

from swf.movie import SWF <--- works fine
file = open('CT12KORJ001.swf', 'rb' ) <---- works fine
print SWF(file)

Traceback (most recent call last):
  File "", line 1, in
  File "build/bdist.macosx-10.8-intel/egg/swf/movie.py", line 87, in init
  File "build/bdist.macosx-10.8-intel/egg/swf/movie.py", line 143, in parse
  File "build/bdist.macosx-10.8-intel/egg/swf/tag.py", line 112, in parse_tags

Why am I getting this? Where have I made my mistake, Did I leave anything out? Did the install go badly? It didn't indicate so.

Please also reply to my email - [email protected]

John

error parsing DEFINEFONT3 Tag

I'm parsing some swf when I encountered this error. The file does't seem to conform to the swf file spec, however, Adobe Flash Player can play it.

Traceback (most recent call last):
  File "c.py", line 4, in <module>
    swf = SWF(f)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/movie.py", line 87, in __init__
    self.parse(self._data)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/movie.py", line 143, in parse
    self.parse_tags(data)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/tag.py", line 112, in parse_tags
    tag = self.parse_tag(data)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/tag.py", line 131, in parse_tag
    tag.parse(data, raw_tag.header.content_length, tag.version)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/tag.py", line 1314, in parse
    self.glyphShapeTable.append(data.readSHAPE(self.unitDivisor))
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/stream.py", line 200, in readSHAPE
    return SWFShape(self, 1, unit_divisor)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 50, in __init__
    self.parse(data, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 57, in parse
    self.read_shape_records(data, fillbits, linebits, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 93, in read_shape_records
    style_change_record = data.readSTYLECHANGERECORD(states, fill_bits, line_bits, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/stream.py", line 216, in readSTYLECHANGERECORD
    return SWFShapeRecordStyleChange(self, states, fill_bits, line_bits, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 607, in __init__
    super(SWFShapeRecordStyleChange, self).__init__(data, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 522, in __init__
    self.parse(data, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 622, in parse
    self.fill_styles.append(data.readFILLSTYLE(level))
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/stream.py", line 220, in readFILLSTYLE
    return SWFFillStyle(self, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 760, in __init__
    self.parse(data, level)
  File "/Library/Python/2.7/site-packages/pyswf-1.4-py2.7.egg/swf/data.py", line 773, in parse
    raise Exception("Unknown fill style type: 0x%x" % self.type, level)
Exception: ('Unknown fill style type: 0xf', 1)

Here is the file: https://www.dropbox.com/s/n02lbplm77exmhp/page003.swf

Just need to use utcfromtimestamp.

pyswf/swf/tag.py

Line 2147 in 3740cc8

s += " compileTime: %d (%s)" % (self.compileTime, datetime.datetime.fromtimestamp(self.compileTime//1000.0).ctime())

s += " compileTime: %d (%s)" % (self.compileTime, datetime.datetime.utcfromtimestamp(self.compileTime//1000.0).ctime())

Still maintained?

@timknip Hi, do you still maintain this project? if it's possible, can you merge some pull request please like the PR #24.
Sorry to open an "empty" issue, but I don't find another way to contact you.
Thank you

Support python 3

Please add support for python 3.x.

>>> from swf.movie import SWF
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    from swf.movie import SWF
  File "C:\Users\username\AppData\Local\Programs\Python\Python35-32\lib\site-packages\swf\movie.py", line 4, in <module>
    from tag import SWFTimelineContainer
ImportError: No module named 'tag'

Duplicate IDs

For example when exporting this one:

cdn.floorplanner.com/assets/elements/2d/2329/v550_verbena01.swf

TypeError : unsupported operand type(s) for |: 'int' and 'str'

Traceback (most recent call last):
File "osWalk.py", line 22, in
convertToSvg(path)
File "osWalk.py", line 10, in convertToSvg
swf = SWF(file)
File "build\bdist.win32\egg\swf\movie.py", line 100, in init
self.parse(self._data)
File "build\bdist.win32\egg\swf\movie.py", line 162, in parse
self.parse_tags(data)
File "build\bdist.win32\egg\swf\tag.py", line 163, in parse_tags
tag = self.parse_tag(data)
File "build\bdist.win32\egg\swf\tag.py", line 181, in parse_tag
tag.parse(data, raw_tag.header.content_length, tag.version)
File "build\bdist.win32\egg\swf\tag.py", line 359, in parse
self._shapes = data.readSHAPEWITHSTYLE(self.level)
File "build\bdist.win32\egg\swf\stream.py", line 253, in readSHAPEWITHSTYLE
return SWFShapeWithStyle(self, level, unit_divisor)
File "build\bdist.win32\egg\swf\data.py", line 485, in init
super(SWFShapeWithStyle, self).init(data, level, unit_divisor)
File "build\bdist.win32\egg\swf\data.py", line 57, in init
self.parse(data, level)
File "build\bdist.win32\egg\swf\data.py", line 515, in parse
self.read_shape_records(data, num_fillbits, num_linebits, level)
File "build\bdist.win32\egg\swf\data.py", line 101, in read_shape_records
shape_record = data.readSTRAIGHTEDGERECORD(num_bits)
File "build\bdist.win32\egg\swf\stream.py", line 261, in readSTRAIGHTEDGERECOR
D
return SWFShapeRecordStraightEdge(self, num_bits)
File "build\bdist.win32\egg\swf\data.py", line 567, in init
super(SWFShapeRecordStraightEdge, self).init(data, level)
File "build\bdist.win32\egg\swf\data.py", line 547, in init
self.parse(data, level)
File "build\bdist.win32\egg\swf\data.py", line 573, in parse
if self.general_line_flag or not self.vert_line_flag
File "build\bdist.win32\egg\swf\stream.py", line 114, in readSB
return int32(self.readbits(bits) << shift) >> shift
File "build\bdist.win32\egg\swf\stream.py", line 67, in readbits
return self._read_bytes_aligned(bits // 8)
File "build\bdist.win32\egg\swf\stream.py", line 54, in _read_bytes_aligned
return reduce(lambda x, y: x << 8 | y, buf, 0)
File "build\bdist.win32\egg\swf\stream.py", line 54, in
return reduce(lambda x, y: x << 8 | y, buf, 0)
TypeError: unsupported operand type(s) for |: 'int' and 'str'

Can pyswf generate SWF files from scratch?

I'm trying to convert some SVG files to SWF for an old web project I'm restoring (http://grafarc.org/flash/view.htm). The files themselves are very basic, just static vector outlines made mostly of straight-edged shapes.

Is pyswf capable of generating an SWF from scratch, or can it only read them from existing files? I can't quite tell from the documentation.

-Cassidy

Not decompiling Actions?

Hi there!

I'm trying to decompile the flash that's available here [0] and it's not working as expected. I tried adding some debugging code to the action factory in actions.py and all I see is ONE call to it with a 0x07 (Stop) code; after that and for some unknown reason no more calls to the factory are made.

I also tried to modify the factory method in order to add the ActionGetURL class and it did not work (because the factory is called only once).

Any idea on what could be wrong? I'm willing to debug and help with the testing process :)

[0] http://demo.testfire.net/subscribe.swf

picture2swf

How to create a SWF file with a picture set

ModuleNotFoundError: No module named 'tag'

I just installed pyswf 1.5.4 for the first time from pip and was not able to import it due to this error:

>>> from swf.movie import SWF
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/swf/movie.py", line 4, in <module>
    from tag import SWFTimelineContainer
ModuleNotFoundError: No module named 'tag'

TagDefineEditText is not read correctly

"data.reset_bits_pending()" is required after "self.bounds = data.readRECT()", otherwise there's 1 byte shift.
fontHeight have to be read with hasFont or hasFontClass flag. Currently only hasFont is checked.
Otherwise there's 2 bytes shift after that.

Ref1: http://sourceforge.net/adobe/swfinvestigator/code/17/tree/trunk/SWFInvestigator/src/decompiler/swfdump/TagDecoder.as#l1191
Ref2: http://sourceforge.net/adobe/swfinvestigator/code/17/tree/trunk/SWFInvestigator/src/decompiler/swfdump/TagDecoder.as#l1162
Example: http://pastebin.com/jyjd1FrB

how to Implement pics in flash movie ?

""
how to use bitmaps and JPEGtables with ur nice lib
in other words "how to Implement pics in flash movie ?"
sorry that it is not proper usage of issues
thanks

""

sorry for that stupid question now figured that lib not for writing movies yet , thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.