1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/usr/bin/env python3
# Copyright 2014 Facundo Batista
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# For further info, check http://github.com/facundobatista/yaswfp
"""Parse a SWF file and expose all its internals."""
import argparse
import os
import sys
project_basedir = os.path.abspath(os.path.dirname(os.path.dirname(
os.path.realpath(sys.argv[0]))))
if project_basedir not in sys.path:
sys.path.insert(0, project_basedir)
from yaswfp import swfparser
parser = argparse.ArgumentParser(
description='Parse a SWF file and show all its internals')
parser.add_argument('filepath', help='the SWF file to parse')
parser.add_argument('-t', '--show-tags', action='store_true',
help='show the first level tags of the file')
parser.add_argument('-e', '--extended', action='store_true',
help='show all objects with full detail and nested')
parser.add_argument('-c', '--coverage', action='store_true',
help='indicate a percentage of coverage of given file')
args = parser.parse_args()
swf = swfparser.parsefile(args.filepath)
print(swf.header)
print("Tags count:", len(swf.tags))
if args.coverage:
swf.coverage()
if args.show_tags:
for tag in swf.tags:
print(tag)
if args.extended:
def _show(obj, level, prefix=""):
indent = level * " "
indent_sub = indent + " "
if isinstance(obj, list):
prefix_next = "- "
children = [(item.name, item) for item in obj]
else:
prefix_next = ""
children = [(name, getattr(obj, name)) for name in obj._attribs]
class_name = obj.__class__.__name__
if obj.name == class_name:
tit = obj.name
else:
tit = "{} ({})".format(obj.name, class_name)
if children:
final = ":"
else:
final = ""
print("{}{}{}{}".format(indent, prefix, tit, final))
for name, child in children:
if hasattr(child, '_attribs'):
# complex child
_show(child, level + 1, prefix_next)
elif isinstance(child, list) and child and any(
isinstance(x, swfparser.SWFObject) for x in child):
# special case for a list
print("{}{}{}:".format(indent_sub, prefix, name))
_show(child, level + 1, prefix_next)
else:
print("{}{}: {!r}".format(indent_sub, name, child))
for tag in swf.tags:
_show(tag, 0)
|