开发者

How can the actionscript version of a swf file be determined in C#?

What libraries or methods would be needed to achieve 开发者_运维问答this?


Read first 4 bytes of SWF file. First 3 bytes are Signature which reads (CWS or FWS) and next byte is SWF file version. So you don't need any library, just simple File IO will suffice. For actionscript version you need to look for FileAttributes Tag. So here is pseudo code for doing this. (in SWF file data is in Little Endian, so write your readInt or readShort function accordingly).

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;}
  }
}


There is a commercial library that may help with your endeavor:

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

However, your other option is to parse and read the SWF directly and use a guide like this: http://www.m2osw.com/swf_alexref.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜