[原创]python获取swf的宽和高

swf格式其实是公开的,据说在adobe的官网上有,不过我没找到,感兴趣的同学去找原文阅读,因为项目只需要提取出swf的宽和高,所以只作相关分析。

00000000: 4357 5308 483a 0500 789c 7cbb 6554 5c4d
00000010: d335 7c70 770d eeee 1adc dd1d 0602 c1dd
首先载入我们的swf. 切换到十六进制方式。我们需要的宽和高信息就在上面的字节序列里,其中

头3个字节内容为43 57 53  或 46 57 53。  其中43 57 53 代表的是cws,也就是这个Swf是压缩过的。而46 57 53代表的是fws,也就是这个swf是未压缩过的。本次实验中使用的flash基本上是cws的。如果新建一个空白fla,再导出swf的话。那么头部就是fws的。同学们可以自己实验下。这3个字节对于我们来说的作用是cws的swf我们需要对其内容进行解压缩。而这种压缩方式就是标准的zlib格式。而fws的我们直接就可以分析了。


接下来的5个字节08 48 3a 05 00我们忽略不计,里面包含了flash的版本号和其它信息,感兴趣的同学自己看看。

最关键的是78 9c 7c bb 65 54 5c 4d  d3这里9个字节,里面包含的是宽和高的信息。这里是要运算得到的。注意我们不能直接拿来运算,先由头3个字节来确定,flash是否是压缩过的,如果是压缩过的,那么这9个字节是不能直接运算的,要先解压缩为fws格式,才能运算。

新格式为: 46 57 53 + 原头部08 48 3a 05 00这5个字节 +  从这里9个字节开始至文件尾的数据以zlib格式解压缩。 这样就是新文件格式了,不懂的同学看最后面的py源码。
这里只需要知道如果是cws的,那么要先解压缩就可以了。附上解压后的头部:
00000000: 4657 5308 483a 0500 8000 0272 e000 00a4  FWS.H:…..r….
00000010: 6000 2d08 0044 1100 0000 0043 0200 0000  `.-..D…..C….
下面就可以开始分析了。
包含宽高信息的9个字节:80 00 02 72 e0 00 00 a4  60
把每个字节的十六进制值转为二进制码,不足8位的头部补0:
0×80 = 10000000
0×00 = 00000000
0×02 = 00000010
0×72 = 01110010
0xe0 = 11100000
0×00 = 00000000
0×00 = 00000000
0xa4 = 10100100
0×60 = 01100000
把2进制码连成新字串得到:
100000000000000000000010011100101110000000000000000000001010010001100000
去掉头部5位,形成新字串:
0000000000000000010011100101110000000000000000000001010010001100000
每15位分隔字串,得到5组,丢弃最后一组。
000000000000000
001001110010111
000000000000000
000000101001000
1100000
留下的4组其中第2和第4组就是宽和高,但并不是最终的
(001001110010111)2 = (5015)10
(000000101001000)2 = (328)10
最终的宽和高要依据9个字节的第一个字节来确定是哪种类型的,比如
80 00 02 72 e0 00 00 a4  60这里首字节是80,那么最终宽高应该是
w = 5015 / 5 = 1003
h = 328 / 1.24 = 264  (取整,和dw相比有一点偏差)
如果首字节是78,那么就要各除以20,才是最终的宽和高。
如果首字节是70,那么上面所有的算法不成立,这个还没有分析出来,因为项目使用的flash没有这种情况。

如果表述的不详细的地方,请结合参考资料和源代码理解。如果有任何意义请留言提出。谢谢。
附上python源代码:

本文首发于http://www.hkcat.org/407.html,转载请带上链接,谢谢

  • 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、付费专栏及课程。

余额充值