def export_single_shape(self, shape_tag, swf): from swf.movie import SWF # find a typical use of this shape example_place_objects = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.hasCharacter and x.characterId == shape_tag.characterId] if len(example_place_objects): place_object = example_place_objects[0] characters = swf.build_dictionary() ids_to_export = place_object.get_dependencies() ids_exported = set() tags_to_export = [] # this had better form a dag! while len(ids_to_export): id = ids_to_export.pop() if id in ids_exported or id not in characters: continue tag = characters[id] ids_to_export.update(tag.get_dependencies()) tags_to_export.append(tag) ids_exported.add(id) tags_to_export.reverse() tags_to_export.append(place_object) else: place_object = TagPlaceObject() place_object.hasCharacter = True place_object.characterId = shape_tag.characterId tags_to_export = [ shape_tag, place_object ] stunt_swf = SWF() stunt_swf.tags = tags_to_export return super(SingleShapeSVGExporter, self).export(stunt_swf)
def execute(self, input_data): # Spin up SWF class swf = SWF() # Get the raw_bytes raw_bytes = input_data['sample']['raw_bytes'] # Parse it swf.parse(StringIO(raw_bytes)) # Header info head = swf.header output = {'version':head.version,'file_length':head.file_length,'frame_count':head.frame_count, 'frame_rate':head.frame_rate,'frame_size':head.frame_size.__str__(),'compressed':head.compressed} # Loop through all the tags output['tags'] = [tag.__str__() for tag in swf.tags] # Add the meta data to the output output.update(input_data['meta']) return output ''' # Map all tag names to indexes tag_map = {tag.name:index for tag,index in enumerate(swf.tags)} # FileAttribute Info file_attr_tag = swf.tags[tag_map] ''' '''
def doit(inf, outf): swf = SWF(inf) # swf-in-an-swf data = getimagedata(swf) swf2 = SWF(StringIO(data)) exporter = SVGExporter() svg = swf2.export(exporter) outf.write(svg.read())
def export(self, swf, shape, **export_opts): """ Exports the specified shape of the SWF to SVG. @param swf The SWF. @param shape Which shape to export, either by characterId(int) or as a Tag object. """ # If `shape` is given as int, find corresponding shape tag. if isinstance(shape, Tag): shape_tag = shape else: shapes = [x for x in swf.all_tags_of_type((TagDefineShape, TagDefineSprite)) if x.characterId == shape] if len(shapes): shape_tag = shapes[0] else: raise Exception("Shape %s not found" % shape) from swf.movie import SWF # find a typical use of this shape example_place_objects = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.hasCharacter and x.characterId == shape_tag.characterId] if len(example_place_objects): place_object = example_place_objects[0] characters = swf.build_dictionary() ids_to_export = place_object.get_dependencies() ids_exported = set() tags_to_export = [] # this had better form a dag! while len(ids_to_export): id = ids_to_export.pop() if id in ids_exported or id not in characters: continue tag = characters[id] ids_to_export.update(tag.get_dependencies()) tags_to_export.append(tag) ids_exported.add(id) tags_to_export.reverse() tags_to_export.append(place_object) else: place_object = TagPlaceObject() place_object.hasCharacter = True place_object.characterId = shape_tag.characterId tags_to_export = [ shape_tag, place_object ] stunt_swf = SWF() stunt_swf.tags = tags_to_export return super(SingleShapeSVGExporterMixin, self).export(stunt_swf, **export_opts)
ip2.rstrip() # internalIp = ip2.split('lo:')[1].replace(' ', '') # print internalIp except: print 'We could not find internal ip of your app or your system,' \ 'problem maybe ocurred because this is working by linux system and you are using windows system' from swf.movie import SWF from swf.export import SVGExporter # create a file object file = open('C:/Users/Hamed/IGC/Desktop/trash/1.swf', 'rb') # load and parse the SWF swf = SWF(file) # print SWF(file) # create the SVG exporter svg_exporter = SVGExporter() # export! svg = swf.export(svg_exporter) # save the SVG open('C:/Users/Hamed/IGC/Desktop/trash/1.svg', 'wb').write(svg.read()) import gfx doc = gfx.open("swf", "C:/Users/Hamed/IGC/Desktop/trash/1.swf")
#!/usr/bin/env python """ Read coachmap.swf and export all coaches to dist/coaches/*.{svg,js}. """ from swf.movie import SWF from swf.export import SVGExporter, SingleShapeSVGExporterMixin, FrameSVGExporterMixin, NamesSVGExporterMixin from swf.tag import TagPlaceObject, TagDefineShape, TagDefineSprite, TagFrameLabel from subprocess import call import json print "Parsing..." swf = SWF(open('coachmap.swf')) # NB: the order of these mixins matter. class CoachExporter(SingleShapeSVGExporterMixin, FrameSVGExporterMixin, NamesSVGExporterMixin, SVGExporter): pass exporter = CoachExporter() # 1) Find the PlaceObject tag "floorplan". placeobject = [x for x in swf.all_tags_of_type(TagPlaceObject) if x.instanceName == 'floorplan'][0] # 2) Find corresponding DefineSprite. sprite = [x for x in swf.all_tags_of_type((TagDefineShape, TagDefineSprite)) if x.characterId == placeobject.characterId][0] # 3) Remove background (id=362) to get a tight viewbox for each coach type. sprite.tags = [t for t in sprite.tags if not hasattr(t, 'characterId') or t.characterId != 362] # 4) Remove filter from placeobject so there's something to see.
#!/usr/bin/env python #!/usr/bin/python #!python from swf.actions import ActionGetURL from swf.movie import SWF from swf.tag import TagDefineButton2 import sys import argparse parser = argparse.ArgumentParser(description="Read and output the URLs linked to in a SWF file.") parser.add_argument("--swf", type=argparse.FileType('rb'), help="Location of SWF file to parse", required=True) options = parser.parse_args() # Load and parse the SWF. swf = SWF(options.swf) # Print all of the URLs that are targeted via ActionGetURL actions on Button2 tags. for button in swf.all_tags_of_type(TagDefineButton2): for buttonAction in button.buttonActions: for action in buttonAction.actions: if isinstance(action, ActionGetURL): print action.urlString