如何在C#中确定swf文件的actionscript版本?

时间:2010-02-02 21:25:42

标签: c# flash actionscript

实现这一目标需要哪些库或方法?

2 个答案:

答案 0 :(得分:2)

读取SWF文件的前4个字节。前3个字节是Signature,它读取(CWS或FWS),下一个字节是SWF文件版本。所以你不需要任何库,只需简单的文件IO即可。对于actionscript版本,您需要查找FileAttributes标记。所以这里是伪代码。 (在SWF文件数据中使用Little Endian,因此请相应地编写readInt或readShort函数。)

signature = read 3 UTF Bytes as String;
version = read one byte;
size = read unsigned int; (int is 32 bit)
if (signature == "CWS") // i.e. SWF is compressed
  then uncompress the rest of the bytes; //swf uses zlib compression, first 7 bytes are compressed
rect_byte = read unsigned Byte;
rect_bits = rect_byte >> 3; //first 5 bits says how many bits are required for one dimensoin of the swf
total_bits = rect_bits * 4;
rect_bytes = Math.ceil((total_bits - 3)/ 8); //till here we have information about swf dimension
read rect_bytes number of bytes;
read unsigned short as frame rate;
read unsigned short as frame count;
while true do {
  read unsigned short into swf_tag_code_len;
  tagcode = swf_tag_code_len >>6; // first 6 bits determine the tag code
  taglen = swf_tag_code_len & 0x3F; // last 10 bits determines the length of tag (if length is less than 63)
  if (taglen >= 63) { // if tag is bigger than 63 bytes, then next four bytes tell the length
    taglen = read unsgined int;
  }
  if (tagcode == 69) {// here we go, we are looking for this tag (fileattribute) {
    b = read unsigned byte;
    if (b & (1 << 3)) { // 4th least significant bit tell about actionscript version
      it is actionscript version 3;
    } else { either it is 1.0 or 2.0;}
  }
}

答案 1 :(得分:0)

有一个商业图书馆可以帮助您的努力:

http://www.aspose.com/categories/.net-components/aspose.flash-for-.net/default.aspx

但是,您的另一个选择是直接解析和阅读SWF,并使用如下指南:http://www.m2osw.com/swf_alexref.html