Pro.SWF
— 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:
Represents an ActionScript Byte Code (ABC) file.
Represents an SWF (Shockwave Flash) file object.
SWFTag
()Represents a tag within an SWF file.
List of
SWFTag
elements.
SWFTagListIt
(obj)Iterator class for
SWFTagList
.Attributes:
The tag code for the CSMTextSettings tag.
The tag code for the ContiguousTagsEnd tag.
The tag code for the DefineBinaryData tag.
The tag code for the DefineBits tag.
The tag code for the DefineBitsJPEG2 tag.
The tag code for the DefineBitsJPEG3 tag.
The tag code for the DefineBitsJPEG4 tag.
The tag code for the DefineBitsLossless tag.
The tag code for the DefineBitsLossless2 tag.
The tag code for the DefineButton tag.
The tag code for the DefineButton2 tag.
The tag code for the DefineButtonCxform tag.
The tag code for the DefineButtonSound tag.
The tag code for the DefineEditText tag.
The tag code for the DefineFont tag.
The tag code for the DefineFont2 tag.
The tag code for the DefineFont3 tag.
The tag code for the DefineFont4 tag.
The tag code for the DefineFontAlignZones tag.
The tag code for the DefineFontInfo tag.
The tag code for the DefineFontInfo2 tag.
The tag code for the DefineFontName tag.
The tag code for the DefineMorphShape tag.
The tag code for the DefineMorphShape2 tag.
The tag code for the DefineScalingGrid tag.
The tag code for the DefineSceneAndFrameLabelData tag.
The tag code for the DefineShape tag.
The tag code for the DefineShape2 tag.
The tag code for the DefineShape3 tag.
The tag code for the DefineShape4 tag.
The tag code for the DefineSound tag.
The tag code for the DefineSprite tag.
The tag code for the DefineText tag.
The tag code for the DefineText2 tag.
The tag code for the DefineVideoStream tag.
The tag code for the DoABC tag.
The tag code for the DoAction tag.
The tag code for the DoInitAction tag.
The tag code for the EnableDebugger tag.
The tag code for the EnableDebugger2 tag.
The tag code for the End tag.
The tag code for the ExportAssets tag.
Flag indicating the use of ActionScript 3.0.
Flag indicating the presence of metadata.
Flag indicating the use of direct bitmap rendering.
Flag indicating the use of GPU compositing.
Flag indicating network access permission.
Mask of valid bits in the FileAttributes flags.
The tag code for the FileAttributes tag.
The tag code for the FrameLabel tag.
The tag code for the ImportAssets tag.
The tag code for the ImportAssets2 tag.
The tag code for the JPEGTables tag.
The tag code for the Metadata tag.
The tag code for the PlaceObject tag.
The tag code for the PlaceObject2 tag.
The tag code for the PlaceObject3 tag.
The tag code for the Protect tag.
Represents a rectangle type used in SWF structures.
The tag code for the RemoveObject tag.
The tag code for the RemoveObject2 tag.
The tag code for the ScriptLimits tag.
The tag code for the SetBackgroundColor tag.
The tag code for the SetTabIndex tag.
The tag code for the ShowFrame tag.
The tag code for the SoundStreamBlock tag.
The tag code for the SoundStreamHead tag.
The tag code for the SoundStreamHead2 tag.
The tag code for the StartSound tag.
The tag code for the StartSound2 tag.
Represents a string type used in SWF structures.
The tag code for the SymbolClass tag.
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 returnsFalse
.- Return type
bool
See also
Process()
.
- Process() → bool¶
Processes the ABC bytecode.
- Returns
Returns
True
if the processing was successful; otherwise returnsFalse
.- 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.
Decompresses the SWF file if it is compressed.
Enumerates the tags within the SWF file.
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.
Checks if the SWF file is compressed.
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.
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 returnsFalse
.- 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 returnsFalse
.- 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
See also
GetStoredTags()
.
- GetStoredTags() → Pro.SWF.SWFTagList¶
Retrieves the stored tags from the SWF file.
- Returns
Returns the list of stored tags.
- Return type
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 returnsFalse
.- 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
- 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
- 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
- WasCompressed() → bool¶
Checks if the SWF file was compressed before decompression.
- Returns
Returns
True
if the file was compressed and has been decompressed; otherwise returnsFalse
.- 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:
The offset of the tag within the SWF file.
Reserved for future use.
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 positioni
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
- 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 ofvalue
; otherwise returnsFalse
.- Return type
bool
- 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()
andcontains()
.
- 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 positioni
in the list. Ifi
is0
, the value is prepended to the list. Ifi
issize()
, 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()
andremoveAt()
.
- isEmpty() → bool¶
Checks whether the list is empty.
- Returns
Returns
True
if the list contains no items; otherwise returnsFalse
.- Return type
bool
See also
size()
.
- iterator() → Pro.SWF.SWFTagListIt¶
Creates an iterator for the list.
- Returns
Returns the iterator.
- Return type
- 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.
- 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
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 returnsFalse
.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 returnsFalse
.
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 returnsFalse
.- Return type
bool
See also
hasPrevious()
andnext()
.
- 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 returnsFalse
.- Return type
bool
See also
hasNext()
andprevious()
.
- next() → Pro.SWF.SWFTag¶
- Returns
Returns the next item and advances the iterator by one position.
- Return type
See also
hasNext()
andprevious()
.
- previous() → Pro.SWF.SWFTag¶
- Returns
Returns the previous item and moves the iterator back by one position.
- Return type
See also
hasPrevious()
andnext()
.
- toBack() → None¶
Moves the iterator to the back of the container (after the last item).
See also
toFront()
andprevious()
.
- 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.