解析/读取SWF头

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解析/读取SWF头相关的知识,希望对你有一定的参考价值。

  1. var xURLLoader : URLLoader = new URLLoader();
  2. var xByte : uint;
  3. var xNBits : int;
  4. var xOffset : int;
  5.  
  6. pbGet.addEventListener(MouseEvent.CLICK, fOnClick);
  7. xURLLoader.addEventListener(Event.COMPLETE, fOnComplete);
  8. xURLLoader.dataFormat = URLLoaderDataFormat.BINARY;
  9.  
  10. function fParse(v : ByteArray) : Object
  11. {
  12. var vFormat : String;
  13. var vSwfVersion : int;
  14. var vFileLength : int;
  15. var vFrameRate : int;
  16. var vTotalFrames : int;
  17. var vFrameSize : Rectangle;
  18.  
  19. v.endian = Endian.LITTLE_ENDIAN;
  20.  
  21. vFormat = v.readUTFBytes(3);
  22. vSwfVersion = v.readByte();
  23. vFileLength = v.readUnsignedInt();
  24. v.readBytes(v);
  25. v.length -= 8;
  26. if (vFormat == "CWS")
  27. v.uncompress();
  28. v.position = 0;
  29. vFrameSize = new Rectangle();
  30. vFrameSize.left = xfReadNBits(v, true) / 20;
  31. vFrameSize.right = xfReadNBits(v) / 20;
  32. vFrameSize.top = xfReadNBits(v) / 20;
  33. vFrameSize.bottom = xfReadNBits(v) / 20;
  34. vFrameRate = v.readUnsignedByte() / 256 + v.readUnsignedByte();
  35. vTotalFrames = v.readUnsignedShort();
  36. return {
  37. mFormat: vFormat,
  38. mSwfVersion: vSwfVersion,
  39. mFileLength: vFileLength,
  40. mFrameSize: vFrameSize,
  41. mFrameRate: vFrameRate,
  42. mTotalFrames: vTotalFrames
  43. };
  44. }
  45.  
  46. function xfReadNBits(v : ByteArray, vStart : Boolean = false) : uint
  47. {
  48. var n : uint;
  49.  
  50. if (vStart)
  51. {
  52. xByte = v.readUnsignedByte();
  53. xNBits = xByte >> 3;
  54. xOffset = 3;
  55. }
  56.  
  57. n = xByte << (32 - xOffset) >> (32 - xNBits);
  58. xOffset -= xNBits;
  59. while (xOffset < 0)
  60. {
  61. xByte = v.readUnsignedByte();
  62. n |= (xOffset < -8) ? (xByte << (-xOffset - 8)) : (xByte >> (-xOffset - 8));
  63. xOffset += 8;
  64. }
  65. return n;
  66. }
  67.  
  68. function fOnClick(e : MouseEvent) : void
  69. {
  70. xURLLoader.load(new URLRequest("http://" + tfUrl.text));
  71. }
  72.  
  73. function fOnComplete(e : Event) : void
  74. {
  75. var i : int;
  76. var vData : Object;
  77.  
  78. vData = fParse(xURLLoader.data);
  79. tfFormat.text = vData.mFormat;
  80. tfVersion.text = vData.mSwfVersion;
  81. tfFileLength.text = vData.mFileLength;
  82. tfWidth.text = vData.mFrameSize.width;
  83. tfHeight.text = vData.mFrameSize.height;
  84. tfFrameRate.text = vData.mFrameRate;
  85. tfTotalFrames.text = vData.mTotalFrames;
  86. }

以上是关于解析/读取SWF头的主要内容,如果未能解决你的问题,请参考以下文章

swf文件结构解析

将数据存储在 SWF 文件中,无需解析它们

生成或解析 HTML 为 SWF

Tomcat请求解析-请求行和请求头

C++ ifstream ofstream 用法解析(iostreamfstream头文件)(ios::appios::ateios::inios::outios::trunc)(未完)

C++ ifstream ofstream 用法解析(iostreamfstream头文件)(ios::appios::ateios::inios::outios::trunc)(未完)