You are here: Recent News » SWF 9 File Format

 

SWF 9 File Format

Flash Player 9 is now available, which means additions to the SWF file format. This page is dedicated to documenting the new things that have been added.

As a side note, the method used to document the format is Discovery through Observation which is perfectly legal.

Note: More accurate information on the ABC format has been released by Adobe through the open source Tamarin project. In addition, the official SWF and FLV File Format Specification is available under certain license terms.

Tags

The following tags have been added into the SWF9 format :

  • 0×48 : ActionScript3 tag (command line compiler output)
  • 0x4C : ActionScript3 tag (flex 2 ide output, just slightly different)
  • 0×52 : ActionScript3 startup class ?
    • int32 : ???
    • 0-ending string : class name
  • 0×56 : ???
    • all swf exported by Adobe flash 9 public alpha contain this tag,mybe it is scene table.
  • other tags : please list them and provide ways of at least producing them

The following tags have been changed in the SWF9 format:

  • 0×45 : FileAttributes tag; the previously reserved bits 3-1 in the first byte after the record header may now be non-zero

ActionScript 3

The AS3 tag content is completely different from previous AS2 one. In particular, the complete classes and methods types are included in the format, whereas AS1/AS2 was only opcodes needed to run the program.

AS3 structure

The AS3 tag structure is composed of several lists of elements. The lists are either 0-based or 1-based.

  • 0-based lists means that you read an as3-integer followed by n items.
  • 1-based lists means that you read an as3-integer. If 0 then there is no elements in the list else there is (n-1) items following.

AS3 integer

The AS3 Integer can be encoded into between 1 and 5 bytes.

  • if the integer is between 0×00 and 0x7F then only one byte (representing the integer)
  • if between 0×80 and 0x3FFF then 2 bytes :
    • (i & 0x7F) | 0×80
    • (i » 7)
  • if between 0×4000 and 0x1FFFFF then 3 bytes :
    • (i & 0x7F) | 0×80
    • (i » 7) | 0×80
    • (i » 14)
  • if between 0×200000 and 0xFFFFFFF then 4 bytes :
    • (i & 0x7F) | 0×80
    • (i » 7) | 0×80
    • (i » 14) | 0×80
    • (i » 21)
  • if more or equal than 0×10000000 :
    • (i & 0x7F) | 0×80
    • (i » 7) | 0×80
    • (i » 14) | 0×80
    • (i » 21) | 0×80
    • (i » 28)

The format is actually quite easy to read, since you read bytes until you get one that is lower than 128.

Struture Details

Here’s the structure of the AS3 tag :

  • if the tag is 0x4C, then there is the following header :
    • int32 : ????
    • 0-ended string : frame name (which usage ?)
  • int32 : magic value (version ?)
    • 0x002E0010 with Flex Builder Beta 3
  • 1-based list of AS3 integers : integer table
  • the \0 byte ???
  • 1-based list of 8-bytes doubles : float table
  • 1-based list of 0-ending strings : identifier table
  • 1-based list of AS3 rights : base-rights table
  • 1-based list of AS3 rights groups : rights table
  • 1-based list of AS3 type : type table
  • 0-based list of AS3 method type : method type table
  • 0-based list of AS3 metadatas : metadata table
  • 0-based list of AS3 class : class table
    • followed by n AS3 static declarations : static table
  • 0-based list of AS3 initializer : init table
  • 0-based list of AS3 function : function table

This is very similar to Java Bytecode structure. Several tables are declared, with everytime indexes into previously declared tables. For instance base-rights table will consists in indexes into the identifier table, and rights table of indexes into the base-rigths table.

Indexes into table can start either at 1 or 0, depending on the data structure. It is unrelated to the way the table is stored. Optional indexes are stored are either 0 (no binding) or (index + 1).

The meaning of each table is following.

integer table

32-bit integers used in the program

float table

64-bit floating point values used in the program

identifier table

strings are identifiers used in the program and class structure.

base-right table

Each base-right is composed of the following data :

  • a byte giving the type of the right (see below)
  • an AS3 integer giving the index in the identifier table

The byte can be one of the following :

  • 0×05 : private
  • 0×08 : ???
  • 0×16 : public
  • 0×17 : internal
  • 0×18 : protected
  • 0x1A : ???

The integer in the identifier table is the namespace associated with the rights

rights group table

Each rights group is composed of the following data :

  • 1 byte : indicating the number of rights
  • one AS3 int per index in the base-right table

type table

Each type starts with one byte the can be one of the following :

  • 0×09 : a class or interface ??
    • one AS3 int index into the identifier table
    • one AS3 int index into the base rights table
  • 0×07 : a method or variable type
    • one AS3 int index into the base rights table
    • one AS3 int into the identifier table
  • 0x1B : ???
    • one AS3 int data
  • 0x0E : ???
    • two AS3 int data

method type table

Each method type has the following datas :

  • one byte : number of arguments
  • one AS3 int optional index into the type table : return type
  • one AS3 int optional index into the type table per argument : arguments types
  • one AS3 int : ???
  • one byte : some bit-flags
    • 0×01 : ???
    • 0×02 : ???
    • 0×04 : the method as variable arguments
    • 0×08 : the method as default params
      • default params data is following flags
    • 0×10 : ???
    • 0×20 : method is marked “native”
    • 0×40 : ???
    • 0×80 : method as debug parameter names
      • one AS3 int index into identifier table per parameter is following

The optional default parameters data consist of the following :

  • one byte for the number of values
  • one optional AS3 value per argument value

For instance if the method has 5 arguments and a default value for the second one, it will store “4” as the default values count, then the value itself followed by three 0.

as3 value

to complete...

metadata table

to complete...

class table

to complete...

statics table

to complete...

initializers table

to complete...

function table

to complete...

flash9.txt · Last modified: 2007/07/27 14:20 by dr_zeus