Git Product home page Git Product logo

yaswfp's Introduction

yaswfp

Yet Another SWF Parser.

You can pronounce whatever you like :)

How to use it

You can use swfparser.py as command line program or as a module.

If you execute directly the usage is:

swfparser.py [-h] [-t] [-e] filepath

positional arguments:
  filepath         the SWF file to parse

optional arguments:
  -h, --help       show this help message and exit
  -t, --show-tags  show the first level tags of the file
  -e, --extended   show all objects with full detail and nested

If you want to use it as a module, you can use the SWFParser class directly or the handy parsefile function:

>>> swf = swfparser.parsefile(<yourSWFfile>)
>>> swf.header
Header(name=Header, FileLength=4228, ...)
>>> len(swf.tags)
365
>>> swf.tags[0]
UnknownObject(name=SetBackgroundColor, raw_payload=b'\xff\xff\xff')
>>> swf.tags[3]
>>> obj = swf.tags[3]
>>> obj
PlaceObject2(name=PlaceObject2, CharacterId=1, ...)
>>> obj.CharacterId
1
>>> obj.Matrix.ScaleX
65536

This follows the SWF File Format Specification Version 19, but it is not (yet) 100% covered, so you may find some unknown objects.

How to deal with still-unknown-objects

Not all the spec is covered (this is a work in progress!).

When the parser finds a structure that still can't process (because more programming is needed), will just return an UnknownObject object with the unparsed bytes, or will raise an exception if you set the unknown_alert flag:

SWFParser.unknown_alert = True

Add new structures to the parser is very simple. I'll be very glad to do it if you offer a real stream of bytes as an example or even a sample SWF file with the still missing object inside.

Checking coverage

There is an easy way of checking how many of the objects (tags, actions, structures, etc) are properly covered by the parser: just use the coverage parameter:

$ python3 yaswfp/swfparser.py -c yaswfp/tests/samples/1252533834.swf
Header(Signature='CWS', ...)
Tags count: 55
Coverage is 97.3% of 74 total items
Most common parsed objects:
   22 PlaceObject2
   21 ShowFrame
   10 LineStyleArray
Most common Unknown objects
    2 DefineMorphShape2

Development

To run the tests:

./test

You'll need python3-flake8 and python3-nose. Of course, this is Python 3.

To complete some methods or be able to parse new structures, we should add examples that show that new stuff, see current "sanity" tests. Yes, unit tests are desirable, feel free to add those too.

The project is hosted in GitHub:

https://github.com/facundobatista/yaswfp

Contact

Any doubt, any question, any suggestion, or whatever, feel free to open an issue in GitHub or find me in IRC, I'm facundobatista in Freenode.

Thanks!

yaswfp's People

Contributors

facundobatista avatar evawall avatar yonomitt avatar

Stargazers

 avatar Dawey avatar deminearchiver avatar Evgeny avatar  avatar Nikita Kalitin avatar  avatar  avatar  avatar Pablo P. avatar Winston (Winny) Weinert avatar  avatar  avatar nucular avatar Arron Zhao avatar  avatar  avatar gpt dev avatar Alli avatar Alexander Knorr avatar Michael avatar Minh-Triet Pham Tran avatar Nicolas Seriot avatar Roman Bazhin avatar Steeve Barbeau avatar  avatar  avatar Andres Riancho avatar Giuseppe Massaro avatar

Watchers

 avatar Minh-Triet Pham Tran avatar James Cloos avatar Andres Riancho avatar  avatar  avatar  avatar

yaswfp's Issues

Option to return numerical values in "human" understandable format

According to the SWF file spec, many numerical values are stored in twips (1/20th of a pixel at a replay size of 100%) instead of pixels. Additionally, fixed point values are stored in an integer format.

It would be nice to have an option to return these as the "human" understandable values to make things easier for people who need these values anyway.

Link to the spec: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/swf/pdf/swf-file-format-spec.pdf

Parsing of SWF files which don't match parser's version crash

foo@eug:~/PycharmProjects/yaswfp$ nosetests3 yaswfp/tests/test_sanity.py -s
.E
======================================================================
ERROR: test_subscribe (yaswfp.tests.test_sanity.SanityTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pablo/PycharmProjects/yaswfp/yaswfp/tests/test_sanity.py", line 36, in test_subscribe
    swf = parsefile(os.path.join(BASEDIR, 'wivet1.swf'))
  File "/home/pablo/PycharmProjects/yaswfp/yaswfp/swfparser.py", line 1100, in parsefile
    return SWFParser(fh)
  File "/home/pablo/PycharmProjects/yaswfp/yaswfp/swfparser.py", line 288, in __init__
    self.tags = self._process_tags()
  File "/home/pablo/PycharmProjects/yaswfp/yaswfp/swfparser.py", line 327, in _process_tags
    tag_name = TAG_NAMES[tag_type]
KeyError: 63

----------------------------------------------------------------------
Ran 2 tests in 0.045s

FAILED (errors=1)
foo@eug:~/PycharmProjects/yaswfp$ 

Tag the source

It would be nice if the source could be tagged. This would allow one to download the source tarball from here and then run the tests.

An alternative would be to include the tests in the source that is published on PyPI.

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.