Pro.SWF — API for parsing Adobe Flash files

Overview

The Pro.SWF module contains the API for parsing Adobe Flash files.

Disassembling ActionScript2 Bytecode

The following code example demonstrates how to disassemble ActionScript2 bytecode:

from Pro.Core import *
from Pro.SWF import *

def disassembleActionScript2(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = SWFObject()
    if not obj.Load(c):
        return
    if obj.IsCompressed():
        obj.Decompress()
    tl = obj.EnumerateTags()
    obj.SetStoredTags(tl)
    out = proTextStream()
    obj.AS2Disassemble(out)
    print(out.buffer)

Disassembling ActionScript3 Bytecode

The following code example demonstrates how to disassemble ActionScript3 bytecode:

from Pro.Core import *
from Pro.SWF import *

def disassembleActionScript3(fname):
    c = createContainerFromFile(fname)
    if c.isNull():
        return
    obj = SWFObject()
    if not obj.Load(c):
        return
    if obj.IsCompressed():
        obj.Decompress()
    tl = obj.EnumerateTags()
    obj.SetStoredTags(tl)
    n = tl.size()
    for i in range(n):
        tag = tl.at(i)
        if tag.type == DoABC:
            # found ABC object
            taglen, hdrsize = obj.GetTagLength(tag)
            abcobj = ABCFileObject()
            # skip initial structure
            delta = obj.TagDoABC(tag.offset + hdrsize).Size()
            # load ABC object
            s = obj.GetStream()
            base = tag.offset + hdrsize + delta
            s.setRange(base, taglen - hdrsize - delta)
            if abcobj.Load(s) and abcobj.Process():
                out = proTextStream()
                abcobj.GenerateOutput(out);
                print(out.buffer)

Module API

Pro.SWF module API.

Classes:

ABCFileObject()

Represents an ActionScript Byte Code (ABC) file.

SWFObject()

Represents an SWF (Shockwave Flash) file object.

SWFTag()

Represents a tag within an SWF file.

SWFTagList()

List of SWFTag elements.

SWFTagListIt(obj)

Iterator class for SWFTagList.

Attributes:

CSMTextSettings

The tag code for the CSMTextSettings tag.

ContiguousTagsEnd

The tag code for the ContiguousTagsEnd tag.

DefineBinaryData

The tag code for the DefineBinaryData tag.

DefineBits

The tag code for the DefineBits tag.

DefineBitsJPEG2

The tag code for the DefineBitsJPEG2 tag.

DefineBitsJPEG3

The tag code for the DefineBitsJPEG3 tag.

DefineBitsJPEG4

The tag code for the DefineBitsJPEG4 tag.

DefineBitsLossless

The tag code for the DefineBitsLossless tag.

DefineBitsLossless2

The tag code for the DefineBitsLossless2 tag.

DefineButton

The tag code for the DefineButton tag.

DefineButton2

The tag code for the DefineButton2 tag.

DefineButtonCxform

The tag code for the DefineButtonCxform tag.

DefineButtonSound

The tag code for the DefineButtonSound tag.

DefineEditText

The tag code for the DefineEditText tag.

DefineFont

The tag code for the DefineFont tag.

DefineFont2

The tag code for the DefineFont2 tag.

DefineFont3

The tag code for the DefineFont3 tag.

DefineFont4

The tag code for the DefineFont4 tag.

DefineFontAlignZones

The tag code for the DefineFontAlignZones tag.

DefineFontInfo

The tag code for the DefineFontInfo tag.

DefineFontInfo2

The tag code for the DefineFontInfo2 tag.

DefineFontName

The tag code for the DefineFontName tag.

DefineMorphShape

The tag code for the DefineMorphShape tag.

DefineMorphShape2

The tag code for the DefineMorphShape2 tag.

DefineScalingGrid

The tag code for the DefineScalingGrid tag.

DefineSceneAndFrameL

The tag code for the DefineSceneAndFrameLabelData tag.

DefineShape

The tag code for the DefineShape tag.

DefineShape2

The tag code for the DefineShape2 tag.

DefineShape3

The tag code for the DefineShape3 tag.

DefineShape4

The tag code for the DefineShape4 tag.

DefineSound

The tag code for the DefineSound tag.

DefineSprite

The tag code for the DefineSprite tag.

DefineText

The tag code for the DefineText tag.

DefineText2

The tag code for the DefineText2 tag.

DefineVideoStream

The tag code for the DefineVideoStream tag.

DoABC

The tag code for the DoABC tag.

DoAction

The tag code for the DoAction tag.

DoInitAction

The tag code for the DoInitAction tag.

EnableDebugger

The tag code for the EnableDebugger tag.

EnableDebugger2

The tag code for the EnableDebugger2 tag.

End

The tag code for the End tag.

ExportAssets

The tag code for the ExportAssets tag.

FA_ActionScript3

Flag indicating the use of ActionScript 3.0.

FA_HasMetaData

Flag indicating the presence of metadata.

FA_UseDirectBlit

Flag indicating the use of direct bitmap rendering.

FA_UseGPU

Flag indicating the use of GPU compositing.

FA_UseNetwork

Flag indicating network access permission.

FA_ValidBits

Mask of valid bits in the FileAttributes flags.

FileAttributes

The tag code for the FileAttributes tag.

FrameLabel

The tag code for the FrameLabel tag.

ImportAssets

The tag code for the ImportAssets tag.

ImportAssets2

The tag code for the ImportAssets2 tag.

JPEGTables

The tag code for the JPEGTables tag.

Metadata

The tag code for the Metadata tag.

PlaceObject

The tag code for the PlaceObject tag.

PlaceObject2

The tag code for the PlaceObject2 tag.

PlaceObject3

The tag code for the PlaceObject3 tag.

Protect

The tag code for the Protect tag.

Rect_t

Represents a rectangle type used in SWF structures.

RemoveObject

The tag code for the RemoveObject tag.

RemoveObject2

The tag code for the RemoveObject2 tag.

ScriptLimits

The tag code for the ScriptLimits tag.

SetBackgroundColo

The tag code for the SetBackgroundColor tag.

SetTabIndex

The tag code for the SetTabIndex tag.

ShowFrame

The tag code for the ShowFrame tag.

SoundStreamBlock

The tag code for the SoundStreamBlock tag.

SoundStreamHead

The tag code for the SoundStreamHead tag.

SoundStreamHead2

The tag code for the SoundStreamHead2 tag.

StartSound

The tag code for the StartSound tag.

StartSound2

The tag code for the StartSound2 tag.

String_t

Represents a string type used in SWF structures.

SymbolClass

The tag code for the SymbolClass tag.

VideoFrame

The tag code for the VideoFrame tag.

class ABCFileObject

Bases: Pro.Core.CFFObject

Represents an ActionScript Byte Code (ABC) file.

This class provides methods to process and generate output from ABC files contained within SWF files.

Methods:

GenerateOutput(out)

Generates disassembled output of the ABC bytecode to the provided text stream.

Process()

Processes the ABC bytecode.

GenerateOutput(out: Pro.Core.NTTextStream)bool

Generates disassembled output of the ABC bytecode to the provided text stream.

Parameters

out (NTTextStream) – The output text stream to write the disassembled bytecode to.

Returns

Returns True if the output was successfully generated; otherwise returns False.

Return type

bool

See also Process().

Process()bool

Processes the ABC bytecode.

Returns

Returns True if the processing was successful; otherwise returns False.

Return type

bool

See also GenerateOutput().

CSMTextSettings: Final[int]

The tag code for the CSMTextSettings tag.

This tag defines text settings for advanced anti-aliasing.

ContiguousTagsEnd: Final[int]

The tag code for the ContiguousTagsEnd tag.

Marks the end of contiguous tags.

DefineBinaryData: Final[int]

The tag code for the DefineBinaryData tag.

Contains binary data that can be referenced by other tags.

DefineBits: Final[int]

The tag code for the DefineBits tag.

Defines a bitmap character with JPEG compression.

DefineBitsJPEG2: Final[int]

The tag code for the DefineBitsJPEG2 tag.

Defines a bitmap character with JPEG compression, allowing inlined JPEG tables.

DefineBitsJPEG3: Final[int]

The tag code for the DefineBitsJPEG3 tag.

Defines a bitmap character with JPEG compression and alpha channel data.

DefineBitsJPEG4: Final[int]

The tag code for the DefineBitsJPEG4 tag.

An enhanced version of DefineBitsJPEG3 with deblocking filter parameters.

DefineBitsLossless: Final[int]

The tag code for the DefineBitsLossless tag.

Defines a bitmap character with lossless compression (ZLIB).

DefineBitsLossless2: Final[int]

The tag code for the DefineBitsLossless2 tag.

An enhanced version of DefineBitsLossless supporting 32-bit RGBA colors.

DefineButton: Final[int]

The tag code for the DefineButton tag.

Defines a simple button character.

DefineButton2: Final[int]

The tag code for the DefineButton2 tag.

Defines a button character with additional capabilities like color transforms.

DefineButtonCxform: Final[int]

The tag code for the DefineButtonCxform tag.

Associates a color transform with a button for color effects.

DefineButtonSound: Final[int]

The tag code for the DefineButtonSound tag.

Defines sounds for button states such as over and down.

DefineEditText: Final[int]

The tag code for the DefineEditText tag.

Defines an editable text field.

DefineFont: Final[int]

The tag code for the DefineFont tag.

Defines a set of glyph shapes for a font.

DefineFont2: Final[int]

The tag code for the DefineFont2 tag.

An extended font definition supporting layout information.

DefineFont3: Final[int]

The tag code for the DefineFont3 tag.

An enhanced font definition supporting 32-bit code points.

DefineFont4: Final[int]

The tag code for the DefineFont4 tag.

Defines a font using OpenType technology.

DefineFontAlignZones: Final[int]

The tag code for the DefineFontAlignZones tag.

Specifies alignment zones for font glyphs to improve text rendering.

DefineFontInfo: Final[int]

The tag code for the DefineFontInfo tag.

Provides font metadata such as name and style.

DefineFontInfo2: Final[int]

The tag code for the DefineFontInfo2 tag.

An extended version of DefineFontInfo with language code support.

DefineFontName: Final[int]

The tag code for the DefineFontName tag.

Associates a name and copyright information with a font.

DefineMorphShape: Final[int]

The tag code for the DefineMorphShape tag.

Defines a morphing shape that transitions between two shapes.

DefineMorphShape2: Final[int]

The tag code for the DefineMorphShape2 tag.

An enhanced version of DefineMorphShape with new fill styles.

DefineScalingGrid: Final[int]

The tag code for the DefineScalingGrid tag.

Defines a 9-slice scaling grid for scaling objects.

DefineSceneAndFrameL: Final[int]

The tag code for the DefineSceneAndFrameLabelData tag.

Associates scene and frame label data with the SWF file.

DefineShape: Final[int]

The tag code for the DefineShape tag.

Defines a shape character.

DefineShape2: Final[int]

The tag code for the DefineShape2 tag.

An extended version of DefineShape with additional features.

DefineShape3: Final[int]

The tag code for the DefineShape3 tag.

Adds support for new fill styles to DefineShape2.

DefineShape4: Final[int]

The tag code for the DefineShape4 tag.

An enhanced version of DefineShape3 with advanced fill styles.

DefineSound: Final[int]

The tag code for the DefineSound tag.

Defines a sound character.

DefineSprite: Final[int]

The tag code for the DefineSprite tag.

Defines a sprite, which is a sequence of control tags.

DefineText: Final[int]

The tag code for the DefineText tag.

Defines a static text character.

DefineText2: Final[int]

The tag code for the DefineText2 tag.

An extended version of DefineText with alpha transparency support.

DefineVideoStream: Final[int]

The tag code for the DefineVideoStream tag.

Defines a video stream character.

DoABC: Final[int]

The tag code for the DoABC tag.

Contains ActionScript 3.0 bytecode.

DoAction: Final[int]

The tag code for the DoAction tag.

Contains a series of ActionScript bytecode instructions.

DoInitAction: Final[int]

The tag code for the DoInitAction tag.

Contains initialization actions for a sprite.

EnableDebugger: Final[int]

The tag code for the EnableDebugger tag.

Enables the debugger with a password.

EnableDebugger2: Final[int]

The tag code for the EnableDebugger2 tag.

An extended version of EnableDebugger without a password field.

End: Final[int]

The tag code for the End tag.

Marks the end of the SWF file.

ExportAssets: Final[int]

The tag code for the ExportAssets tag.

Exports symbols for use in other SWF files.

FA_ActionScript3: Final[int]

Flag indicating the use of ActionScript 3.0.

Used in the FileAttributes tag.

FA_HasMetaData: Final[int]

Flag indicating the presence of metadata.

Used in the FileAttributes tag.

FA_UseDirectBlit: Final[int]

Flag indicating the use of direct bitmap rendering.

Used in the FileAttributes tag.

FA_UseGPU: Final[int]

Flag indicating the use of GPU compositing.

Used in the FileAttributes tag.

FA_UseNetwork: Final[int]

Flag indicating network access permission.

Used in the FileAttributes tag.

FA_ValidBits: Final[int]

Mask of valid bits in the FileAttributes flags.

Used for validation.

FileAttributes: Final[int]

The tag code for the FileAttributes tag.

Specifies attributes of the SWF file.

FrameLabel: Final[int]

The tag code for the FrameLabel tag.

Associates a label with the current frame.

ImportAssets: Final[int]

The tag code for the ImportAssets tag.

Imports assets from another SWF file.

ImportAssets2: Final[int]

The tag code for the ImportAssets2 tag.

An extended version of ImportAssets with support for URL encoding.

JPEGTables: Final[int]

The tag code for the JPEGTables tag.

Defines JPEG encoding tables for subsequent JPEG images.

Metadata: Final[int]

The tag code for the Metadata tag.

Contains XML metadata for the SWF file.

PlaceObject: Final[int]

The tag code for the PlaceObject tag.

Places a character onto the display list.

PlaceObject2: Final[int]

The tag code for the PlaceObject2 tag.

An extended version of PlaceObject with additional capabilities.

PlaceObject3: Final[int]

The tag code for the PlaceObject3 tag.

An enhanced version of PlaceObject2 with further capabilities.

Protect: Final[int]

The tag code for the Protect tag.

Protects the SWF file from import into the Flash authoring tool.

Rect_t: Final[int]

Represents a rectangle type used in SWF structures.

RemoveObject: Final[int]

The tag code for the RemoveObject tag.

Removes a character from the display list.

RemoveObject2: Final[int]

The tag code for the RemoveObject2 tag.

Removes a character from the display list without specifying the character ID.

class SWFObject

Bases: Pro.Core.CFFObject

Represents an SWF (Shockwave Flash) file object.

Methods:

AS2Disassemble(out)

Disassembles ActionScript 2.0 bytecode and writes it to the provided text stream.

Decompress()

Decompresses the SWF file if it is compressed.

EnumerateTags()

Enumerates the tags within the SWF file.

GetStoredTags()

Retrieves the stored tags from the SWF file.

GetTagLength(offset_or_tag)

Retrieves the length of a tag and its header.

GetTagName(t)

Retrieves the name of a tag given its type.

IsCompressed()

Checks if the SWF file is compressed.

SWFHeader()

Retrieves the SWF header structure.

SetStoredTags(tags)

Stores the provided list of tags for later retrieval.

TagDefineBinaryData(offset)

Retrieves the DefineBinaryData tag structure at the specified offset.

TagDoABC(offset)

Retrieves the DoABC tag structure at the specified offset.

WasCompressed()

Checks if the SWF file was compressed before decompression.

AS2Disassemble(out: Pro.Core.NTTextStream)bool

Disassembles ActionScript 2.0 bytecode and writes it to the provided text stream.

Parameters

out (NTTextStream) – The output text stream to write the disassembled bytecode to.

Returns

Returns True if disassembly was successful; otherwise returns False.

Return type

bool

See also Decompress().

Decompress()bool

Decompresses the SWF file if it is compressed.

Returns

Returns True if decompression was successful or the file was already uncompressed; otherwise returns False.

Return type

bool

See also IsCompressed().

EnumerateTags()Pro.SWF.SWFTagList

Enumerates the tags within the SWF file.

Returns

Returns a list of tags found in the SWF file.

Return type

SWFTagList

See also GetStoredTags().

GetStoredTags()Pro.SWF.SWFTagList

Retrieves the stored tags from the SWF file.

Returns

Returns the list of stored tags.

Return type

SWFTagList

See also SetStoredTags().

GetTagLength(offset_or_tag: Union[Pro.SWF.SWFTag, int])tuple

Retrieves the length of a tag and its header.

Parameters

offset_or_tag (Union[SWFTag, int]) – Either the offset of the tag or a SWFTag object.

Returns

Returns the length of the tag and its header.

Return type

tuple[int, int]

See also EnumerateTags().

GetTagName(t: SWFTagType)str

Retrieves the name of a tag given its type.

Parameters

t (SWFTagType) – The type of the tag.

Returns

Returns the name of the tag as a string.

Return type

str

IsCompressed()bool

Checks if the SWF file is compressed.

Returns

Returns True if the file is compressed; otherwise returns False.

Return type

bool

See also Decompress().

SWFHeader()Pro.Core.CFFStruct

Retrieves the SWF header structure.

Returns

Returns the SWF header as a CFFStruct.

Return type

CFFStruct

SetStoredTags(tags: Pro.SWF.SWFTagList)None

Stores the provided list of tags for later retrieval.

Parameters

tags (SWFTagList) – The list of tags to store.

See also GetStoredTags().

TagDefineBinaryData(offset: int)Pro.Core.CFFStruct

Retrieves the DefineBinaryData tag structure at the specified offset.

Parameters

offset (int) – The offset of the tag in the SWF file.

Returns

Returns the tag structure as a CFFStruct.

Return type

CFFStruct

TagDoABC(offset: int)Pro.Core.CFFStruct

Retrieves the DoABC tag structure at the specified offset.

Parameters

offset (int) – The offset of the tag in the SWF file.

Returns

Returns the tag structure as a CFFStruct.

Return type

CFFStruct

WasCompressed()bool

Checks if the SWF file was compressed before decompression.

Returns

Returns True if the file was compressed and has been decompressed; otherwise returns False.

Return type

bool

See also Decompress().

class SWFTag

Represents a tag within an SWF file.

A tag contains information such as the type of data and its location within the file.

Attributes:

offset

The offset of the tag within the SWF file.

reserved

Reserved for future use.

type

The type of the tag.

offset

The offset of the tag within the SWF file.

reserved

Reserved for future use.

type

The type of the tag.

class SWFTagList

List of SWFTag elements.

Methods:

append(value)

Inserts value at the end of the list.

at(i)

Returns the item at index position i in the list.

clear()

Removes all items from the list.

contains(value)

Checks the presence of an element in the list.

count(value)

Returns the number of occurrences of value in the list.

indexOf(value[, start])

Searches for an element in the list.

insert(i, value)

Inserts value at index position i in the list.

isEmpty()

Checks whether the list is empty.

iterator()

Creates an iterator for the list.

removeAll(value)

Removes all occurrences of value in the list and returns the number of entries removed.

removeAt(i)

Removes the item at index position i.

reserve(alloc)

Reserve space for alloc elements.

size()

Returns the number of items in the list.

takeAt(i)

Removes the item at index position i and returns it.

append(value: Pro.SWF.SWFTag)None

Inserts value at the end of the list.

Parameters

value (SWFTag) – The value to add to the list.

See also insert().

at(i: int)Pro.SWF.SWFTag

Returns the item at index position i in the list. i must be a valid index position in the list (i.e., 0 <= i < size()).

Parameters

i (int) – The index of the element to return.

Returns

Returns the requested element.

Return type

SWFTag

clear()None

Removes all items from the list.

contains(value: Pro.SWF.SWFTag)bool

Checks the presence of an element in the list.

Parameters

value (SWFTag) – The value to check for.

Returns

Returns True if the list contains an occurrence of value; otherwise returns False.

Return type

bool

See also indexOf() and count().

count(value: Pro.SWF.SWFTag)int

Returns the number of occurrences of value in the list.

Parameters

value (SWFTag) – The value to count.

Returns

Returns the number of occurrences.

Return type

int

See also indexOf() and contains().

indexOf(value: Pro.SWF.SWFTag, start: int = 0)int

Searches for an element in the list.

Parameters
  • value (SWFTag) – The value to search for.

  • start (int) – The start index.

Returns

Returns the index position of the first occurrence of value in the list. Returns -1 if no item was found.

Return type

int

See also contains().

insert(i: int, value: Pro.SWF.SWFTag)None

Inserts value at index position i in the list. If i is 0, the value is prepended to the list. If i is size(), the value is appended to the list.

Parameters
  • i (int) – The position at which to add the value.

  • value (SWFTag) – The value to add.

See also append() and removeAt().

isEmpty()bool

Checks whether the list is empty.

Returns

Returns True if the list contains no items; otherwise returns False.

Return type

bool

See also size().

iterator()Pro.SWF.SWFTagListIt

Creates an iterator for the list.

Returns

Returns the iterator.

Return type

SWFTagListIt

removeAll(value: Pro.SWF.SWFTag)int

Removes all occurrences of value in the list and returns the number of entries removed.

Parameters

value (SWFTag) – The value to remove from the list.

Returns

Returns the number of entries removed.

Return type

int

See also removeAt().

removeAt(i: int)None

Removes the item at index position i. i must be a valid index position in the list (i.e., 0 <= i < size()).

Parameters

i (int) – The index of the item to remove.

See also removeAll().

reserve(alloc: int)None

Reserve space for alloc elements. Calling this method doesn’t change the size of the list.

Parameters

alloc (int) – The amount of elements to reserve space for.

size()int
Returns

Returns the number of items in the list.

Return type

int

See also isEmpty().

takeAt(i: int)Pro.SWF.SWFTag

Removes the item at index position i and returns it. i must be a valid index position in the list (i.e., 0 <= i < size()).

Parameters

i (int) – The index of the element to remove from the list.

Returns

Returns the removed element. If you don’t use the return value, removeAt() is more efficient.

Return type

SWFTag

See also removeAt().

class SWFTagListIt(obj: Pro.SWF.SWFTagList)

Iterator class for SWFTagList.

Parameters

obj (SWFTagList) – The object to iterate over.

Methods:

hasNext()

Returns True if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returns False.

hasPrevious()

Returns True if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returns False.

next()

Returns the next item and advances the iterator by one position.

previous()

Returns the previous item and moves the iterator back by one position.

toBack()

Moves the iterator to the back of the container (after the last item).

toFront()

Moves the iterator to the front of the container (before the first item).

hasNext()bool
Returns

Returns True if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returns False.

Return type

bool

See also hasPrevious() and next().

hasPrevious()bool
Returns

Returns True if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returns False.

Return type

bool

See also hasNext() and previous().

next()Pro.SWF.SWFTag
Returns

Returns the next item and advances the iterator by one position.

Return type

SWFTag

See also hasNext() and previous().

previous()Pro.SWF.SWFTag
Returns

Returns the previous item and moves the iterator back by one position.

Return type

SWFTag

See also hasPrevious() and next().

toBack()None

Moves the iterator to the back of the container (after the last item).

See also toFront() and previous().

toFront()None

Moves the iterator to the front of the container (before the first item).

See also toBack() and next().

ScriptLimits: Final[int]

The tag code for the ScriptLimits tag.

Specifies limits for script execution.

SetBackgroundColo: Final[int]

The tag code for the SetBackgroundColor tag.

Sets the background color of the SWF file.

SetTabIndex: Final[int]

The tag code for the SetTabIndex tag.

Specifies the tab order of objects.

ShowFrame: Final[int]

The tag code for the ShowFrame tag.

Marks the end of a frame.

SoundStreamBlock: Final[int]

The tag code for the SoundStreamBlock tag.

Contains a block of streaming sound data.

SoundStreamHead: Final[int]

The tag code for the SoundStreamHead tag.

Defines the properties of streaming sound data.

SoundStreamHead2: Final[int]

The tag code for the SoundStreamHead2 tag.

An extended version of SoundStreamHead.

StartSound: Final[int]

The tag code for the StartSound tag.

Starts the playback of a sound.

StartSound2: Final[int]

The tag code for the StartSound2 tag.

An extended version of StartSound with additional capabilities.

String_t: Final[int]

Represents a string type used in SWF structures.

SymbolClass: Final[int]

The tag code for the SymbolClass tag.

Maps symbols to ActionScript classes.

VideoFrame: Final[int]

The tag code for the VideoFrame tag.

Defines a single frame of video data.