解析SWF底层

写一个例子,来解析一下swf的结构。

as3.0代码部分:
var txt:TextField;
//
txt = new TextField();
txt.text = "HelloWorld!";
txt.x=0;
txt.y=0;
this.addChild(txt);

///

这面这段代码写在这里即可,只做测试使用:

1

格式为FWS,即为解压格式,下面上一段字节码的解析图:

doabc

下面来一步一步的解析这些字节码:

先看头部:

46 57 53 0A 4B 02 00 00 70 00 0B B8 00 00 BB 80 00 1E 01 00

看结构部分:

head

46 57 53 即为FWS,解压模式

0A 为Version,为flashplayer播放器的版本号,为10版本

FileLength 为UI32 ,即4B 02 00 00,倒着读取为 00 00 02 4B = 587,就是swf有587个字节

filelength

FrameSize,为Rect类型:

看Rect类型

rect

70 转成2进制为 0111 0000 ,取UB[5] = 0111 0 = 14,取4个SB[14]

00 转成2进制为   0000 0000

0B 转成2进制为   0000 1011

B8 转成2进制为   1011 1000

00 转成2进制为  0000 0000

00 转成2进制为 0000 0000

BB 转成2进制为 1011 1011

80转成2进制为 1000 0000

剩下 00 1E 01 00

0111 0 @ 000 0000 0000 000 @ 0 1011 1011 1000  0 @  000 0000 0000 000 @  0 1011 1011 1000 0 @ 000

Xmin = 000 0000 0000 000  =0

Xmax =0 1011 1011 1000  0 =6000/20 = 300

Yminx=000 0000 0000 000 =0

Ymax=0 1011 1011 1000 0 =6000/20 = 300

分辨率为300*300

继续,FrameRate为U16,00 1E = 30,帧频30

FrameCount为U16,01 00 = 01,为一帧

头部信息解析完毕。

//

下面为44 11,倒着读,11 44,转成2进制为 0001 0001 0100 0100,高10(0001 0001 01=69),tagid=69,为FileAttributes,低6(00 0100=4),长度为短类型,读取后4位,即为数据。数据为08 00 00 00

FileAttributes

08 00 00 00
08的二进制0000 1000
Reserved UB[1] =0 Must be 0
UseDirectBlit  UB[1]=0  will not use hardware accelerated graphics facilities
UseGPU  UB[1]=0 will not use hardware  accelerated graphics facilities
HasMetadata UB[1] = 0 ,说明没有Metadata

ActionScript3 UB[1] = 1,说明为as3
Reserved UB[2] Must be 0
UseNetwork UB[1] =0 说明为本地访问
///
Reserved UB[24] Must be 0

43 02 FF FF FF

setBackgroundColor
同上一个解读一样就是43 02,倒着读02 43转成2进制0000 0010 0100 0011,高10为0000 0010 01 = 9,低6为00 0011 =3,
tagid=9,为SetBackgroundColor,3为长度,即FF FF FF,BackgroundColor RGB Color of the display background,就是RGB啦

BF 15 0C 00 00 00 01 00 E5 9C BA E6 99 AF 20 31 00 00

QQ截图未命名
解析一下 BF 15,倒着读 15 BF转成2进制为0001 0101 1011 1111,高10为0001 0101 10 = 86,tagid=86,为DefineSceneAndFrameLabelData,低6为11 1111,为长类型,读取后4位为:0C 00 00 00 ,还是倒着读 就是00 00 00 0C=12,数据就是后12个字节,为01 00 E5 9C BA E6 99 AF 20 31 00 00

这里面有个EncodedU32,比较特殊的一个东西,看说明:
 encoded

SceneCount EncodedU32 Number of scenes,这个就是读取了 01 转成2进制就是0000 0001,第8位为0,结束,SceneCount =1
Offset1 EncodedU32 Frame offset for scene 1 这个就是读取了 00 转成2进制就是0000 0000,第8位为0,结束,Offset1= 0
Name1 STRING Name of scene 1
E5 9C BA E6 99 AF 20 31 == 场景 1 后面的00 表示string结束,最后的00 应该表示这个tag结束

下面的那一段就是DoABC,也就是存储代码的地方,单拿出来写吧,跳过去先,看下面的那段字节吧。
3F 13 1A 00 00 00 01 00 00 00 74 65 73 74 5F 66 6C 61 2E 4D 61 69 6E 54 69 6D 65 6C 69 6E 65 00
3F 13,13 3F转成2进制 0001 0011 0011 1111,高10 为0001 0011 00 = 76,为SymbolClass,低6为11 1111,0x3F长类型,length = 1A 00 00 00,也就是00 00 00 1A = 26,有26个字节,取后26个字节为01 00 00 00 74 65 73 74 5F 66 6C 61 2E 4D 61 69 6E 54 69 6D 65 6C 69 6E 65 00

SymbolClass

NumSymbols UI16 = 01 00 就是00 01 = 1,说明就一个关联型tag
Tag U16  = 00 00,就是第一个的编号,0开始,id=0
Name STRING = 74 65 73 74 5F 66 6C 61 2E 4D 61 69 6E 54 69 6D 65 6C 69 6E 65 (test_fla.MainTimeline)00(表示结束)
一般这个为文档类,这个比较重要

40 00 00 00 最后的这几个字节其实就是表示swf的结尾部分,40 00 其实就是 showFrame,这个标签很关键,虚拟机在解析swf时,检测到这个showframe标签,才会解析这个标签前面的部分,showframe代表一帧,00 00 是end标签,就是表示结束。

未完待续。。。 。。。(DoABC单独拿出来写!)

转载于:https://my.oschina.net/zhyuliang/blog/206087

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SWFTools is a collection of utilities for working with Adobe Flash files (SWF files). The tool collection includes programs for reading SWF files, combining them, and creating them from other content (like images, sound files, videos or sourcecode). SWFTools is released under the GPL. The current collection is comprised of the programs detailed below: • PDF2SWF A PDF to SWF Converter. Generates one frame per page. Enables you to have fully formatted text, including tables, formulas, graphics etc. inside your Flash Movie. It's based on the xpdf PDF parser from Derek B. Noonburg. • SWFCombine A multi-function tool for inserting SWFs into Wrapper SWFs, contatenating SWFs, stacking SWFs or for basic parameter manipulation (e.g. changing size). • SWFStrings Scans SWFs for text data. • SWFDump Prints out various informations about SWFs, like contained images/fonts/sounds, disassembly of contained code as well as cross-reference and bounding box data. • JPEG2SWF Takes one or more JPEG pictures and generates a SWF slideshow from them. Supports motion estimation compression (h.263) for better compression of video sequences. • PNG2SWF Like JPEG2SWF, only for PNGs. • GIF2SWF Converts GIFs to SWF. Also able to handle animated gifs. • WAV2SWF Converts WAV audio files to SWFs, using the L.A.M.E. MP3 encoder library. • AVI2SWF Converts AVI animation files to SWF. It supports Flash MX H.263 compression. Some examples can be found at examples.html. (Notice: this tool is not included anymore in the latest version, as ffmpeg or mencoder do a better job nowadays) • Font2SWF Converts font files (TTF, Type1) to SWF. • SWFBBox Allows to read out, optimize and readjust SWF bounding boxes. • SWFC A tool for creating SWF files from simple script files. Includes support for both ActionScript 2.0 as well as ActionScript 3.0. • SWFExtract Allows to extract Movieclips, Sounds, Images etc. from SWF files. • AS3Compile A standalone ActionScript 3.0 compiler. Mostly compatible with Flex. SWFTools

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值