SWF file structure analysis

zhaozj2021-02-16  106

The following is some of my recently studied SWF files.

Section 1

The overall structure of the SWF file is the composition of Header Body.

The beginning of the file is a [file head]

Its structure is as follows:

Byte Name Description 1 Signature "f" Represents Non-encrypted format, "c" Represents encrypted format 1 signature "w" No Special meaning 1 Signature "S" no special meaning 1 version of the version number, it represents the corresponding player version 4 FileLength The length of the file, the lower position is in the previous N frameSize Rect structure, indicating that the screen size, the specific structure, and the length is discussed separately according to data change. 2 Framerate frame frequency, default is 12, high in the previous 2 framecount frame, indicate the number of frames under the roots, the low position

The above is SWF, the simplest TAG, a complete SWF file consists of many independent TAGs. Each TAG includes a head and a data body, and the head has two types, short TAG type and long TAG type.

The short TAG type consists of 2byte, the first 10 bits represent a TAG type, and the last 6 bits represent a TAG length.

The long TAG type is composed of 6byte. The first 10 bits represent a TAG type, and the last 6 bit fixed to all 1, and the last 4 Byte represents the length of the TAG.

The length of the tag is different from the length FileLength of the file head, which is the length of the TAG head.

(In addition) Only non-encrypted SWF files can be parsed directly from the above method, and the encrypted file requires additional step processing. Specific methods are not described here due to copyright issues.

This information may not be aware of Flash design, but if someone is used, I will continue to analyze, if someone is doing this investigation, welcome to discuss with me.

chapter 2

The previous section describes the SWF file consists of 1 head and 1 body.

And parse the structure of the Header, and a brief description of a TAG's header section.

The rest of the following is the body of the SWF file.

The entire file body is composed of a large number of tags, and the TAG type code and length can be immediately known by analyzing the TAG's HEAD section.

If you can't identify the type of TAG, you can use the length of the tag to skip this TAG directly.

This way ensures the compatibility of the version, even if new TAGs appear, the old version of the player can also parse the full SWF file without errors, and it is not possible to provide new features.

The following is an image concept of the SWF file structure.

(File HEADER) | (Tag 1) (Tag 3) (...) | (Tag Header) | (TAG Type Code) (TAG Length)

Do you have a basic understanding of the SWF file?

The next section I will analyze a few SWF must have TAG, including BackgroundColor Tag, Showframe Tag and End Tag.

Section 3

SetBackgroundColor Tag

This tag is the first TAG directly following the file head, which is inevitable in the file.

Its structure is as follows:

Length (BIT) Name 16 Header Tag Head, Short TAG Type Code is 9 24 BackgroundColor RGB type, right 3 bytes, named red, green, blue

Showframe tag

This is the last second TAG of the document, which is inevitable.

The structure is as follows:

Length (BIT) Name 16 Header Tag Head, Short TAG Type Code is 1END TAG

End Tag, its role does not need me to say, inevitably the last TAG of the file.

Length (BIT) Name 16 Header Tag Head, Short TAG Type Code is 0

The next section I will talk about the meaning of Character ID and Depth and the basic TAG of TextField.

(Also) Thanks a Supplement and explanation of AOL.

Section 4

A TextField is a text box, with 3 text boxes, static, dynamic, and input. As a TAG, it only has two, static and dynamic, input type but is a special form of dynamics.

Here, the composition of dynamic text boxes is discussed here.

It consists of 3 TAG, 2 definitions TAG and a control tag

They are:

Define Tag DefineFont2 DefineEditText (for Player 7.0, please check the player version)

Control Tag PlaceObject2

DefineFont2 defines a font information, defineEditText references the defined font and defines the displayed text information, and the PlaceObject references the defined text information and controls the display of the text.

The reference between them is based on the Character ID.

The Character ID is a numerical indicator starting from 1. If there is a lack in the middle, all the CHARACTER IDs starting from the lack are ignored, while repeated, the latter will override the first TAG.

DEFINEFONT2 is also the same as a Character ID to indicate yourself, DefineEditText and PlaceObject2 are the same. But not all TAG has a Character ID.

In addition, PLACEOBJECT2 also has a Character ID, but it is not used to indicate yourself, but used to call.

And depth depth has only PlaceObject2 in 3 TAG.

This is the same. I will explain in the next section. (Sorry, I said a little every time!)

Section 5

DefineFont2

This tag's role is to define a font, or a set of static outline characters for use to use DefineEditText.

Almost all information about text can be set in this TAG, so this is also a quite complex TAG.

Its structure is as follows:

Length (bit) Name headerLength header tag header, type code 48 16 FontID character ID, uniquely identifies 1 FontFlagsHasLayout according literally, determines whether there is a modification of the flag 1 FontFlagsShiftJIS whether ShiftJIS encoding 1 FontFlagsSmallText whether small font 1 FontFlagsANSI Whether to use ANSI encoding 1 FontFlagswideOffset $ uses 32-bit offset 1 FontFlagSwideCodes Whether to use 16-bit text encoding 1 FontFlagsital text is whether it is a bold 8 languageCode language code, there is a corresponding code table corresponding to 8 FontNamelen file name length FontNamelen * 8 FontName file name (using UTF8 code) 16 NUMGLYPHS outline characters 32/16 offsettable According to FontFlagswideOffsets, 32 bits, otherwise the 16-bit 32/16 CodeTableOffset is not * NUMGLYPHS GLYPHSHAPETABLE profile word information, the SHAPE structure ( Is a complex structure) 16/8 CodeTable is 16 bits according to Fontflagswidecodes. Coding table, for fixed value UCS-2 16/0 Fontascent According to FontFlagshasLayout, 16/0 fontdescent is 16-bit according to FontFlagshasLayout, otherwise, no 5/0 fontleading is 16 bits according to FontflagshasLayout, otherwise, this field is not 16/0 * NumGlyphs FontAdvanceTable according FontFlagsHasLayout, 16 bits, or the absence of the field RECT * NumGlyphs FontBoundsTable according FontFlagsHasLayout, 16-bit, or no according to the field 16/0 KerningCount FontFlagsHasLayout, 16 bits, or the absence of the Field kerningRecord * kerningCount FontkerningTable is 16 bits according to FontFlagshasLayout, otherwise there is no such thing as you carefully read the content, I admire you. In fact, if the information of this Tag of dynamic text is simply analyzed, it is enough to analyze the above FontName section, and other information is only for the outline, that is, static text is valid. Seeing this, you should understand a little, dynamic text is in the information, only one font name, but static text contains his outline information (included in Shape). This is the biggest difference between dynamic text and static text.

转载请注明原文地址:https://www.9cbs.com/read-10676.html

New Post(0)