SWF Information

Adobe FlashのSWFファイルの情報を表示します。

Get Adobe Flash Player
package
{
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	import flash.utils.Endian;
	import com.bit101.components.*;

	[SWF(width = "380", height = "200", frameRate = "30")]
	public class SwfInformation extends Sprite
	{
		private var label1:Label;
		private var label2:Label;
		private var fileReference:FileReference;

		private var productInfoProducts:Vector.<String> = Vector.<String>([
			"unknown",
			"Macromedia Flex for J2EE",
			"Macromedia Flex for .NET",
			"Adobe Flex"
		]);
		private var fileAttributesString:Vector.<String> = Vector.<String>([
			"UseDirectBlit",
			"UseGPU",
			"HasMetadata",
			"ActionScript3",
			"SuppressCrossDomainCaching",
			"SwfRelativeUrls",
			"UseNetwork"
		]);

		public function SwfInformation()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			Style.LABEL_TEXT = 0x333333;
			new PushButton(this, 5, 5, "LOAD", loadSwf);
			label1 = new Label(this, 5, 25);
			label2 = new Label(this, 135, 25);
		}

		private function loadSwf(event:MouseEvent):void
		{
			fileReference = new FileReference();
			fileReference.addEventListener(Event.SELECT, onLoadSwfSelect);
			fileReference.browse([new FileFilter("SWF File", "*.swf")]);
		}

		private function onLoadSwfSelect(event:Event):void
		{
			fileReference.addEventListener(Event.COMPLETE, onLoadSwfComplete);
			fileReference.load();
		}

		private function onLoadSwfComplete(event:Event):void
		{
			fileReference.removeEventListener(Event.SELECT, onLoadSwfSelect);
			fileReference.removeEventListener(Event.COMPLETE, onLoadSwfComplete);
			var data:ByteArray = ByteArray(fileReference.data);
			var headBuf:ByteArray = new ByteArray();
			var dataBuf:ByteArrayEx = new ByteArrayEx();
			headBuf.endian = Endian.LITTLE_ENDIAN;
			dataBuf.endian = Endian.LITTLE_ENDIAN;
			data.readBytes(headBuf, 0, 8);
			data.readBytes(dataBuf);

			if (headBuf[1] == 0x57 && headBuf[2] == 0x53) {
//				if (headBuf[0] == 0x46) {
//				} else
				if (headBuf[0] == 0x43) {
					dataBuf.uncompress();
				}
			}

			var label1Str:String = "";
			var label2Str:String = "";

			label1Str += "Signature: " + headBuf.readMultiByte(3, "us-ascii") + "\n";
			label1Str += "Version: " + headBuf.readUnsignedByte() + "\n";
			label1Str += "FileLength: " + headBuf.readUnsignedInt() + "\n";

			var nBits:int = dataBuf.readBits(5);
			label1Str += "FrameSize:\n";
			label1Str += "\tXmin: " + (dataBuf.readBits(nBits) / 20) + "\n";
			label1Str += "\tXmax: " + (dataBuf.readBits(nBits) / 20) + "\n";
			label1Str += "\tYmin: " + (dataBuf.readBits(nBits) / 20) + "\n";
			label1Str += "\tYmax: " + (dataBuf.readBits(nBits) / 20) + "\n";
			dataBuf.positionAlignment();
			label1Str += "FrameRate: " + (dataBuf.readUnsignedShort() / 0x100) + "\n";
			label1Str += "FrameCount: " + dataBuf.readUnsignedShort() + "\n";

			var tag:int;
			var tagType:int, tagSize:int;
			var tagNextPosition:int;
			do {
				tag = dataBuf.readUnsignedShort();
				tagType = tag >> 6;
				tagSize = tag & 0x3F;
				if (tagSize == 0x3F) {
					tagSize = dataBuf.readUnsignedInt();
				}
				tagNextPosition = dataBuf.position + tagSize;
				if (tagType == 41) {
					label2Str += "ProductInfo:\n";
					label2Str += "\tProduct: " + productInfoProducts[dataBuf.readUnsignedInt()] + "\n";
					dataBuf.position += 4;
					label2Str += "\tVersion: " + dataBuf.readUnsignedByte() + "." + dataBuf.readUnsignedByte() + "\n";
					label2Str += "\tBuild: " + dataBuf.readUnsignedLong() + "\n";
					var compileDate:Date = new Date();
					compileDate.setTime(dataBuf.readUnsignedLong());
					label2Str += "\tCompileDate: " + compileDate.toLocaleString() + "\n";
				}
				if (tagType == 69) {
					label2Str += "FileAttributes:\n";
					dataBuf.readBits(1);
					for (var i:int = 0; i < 7; i++) {
						label2Str += "\t" + fileAttributesString[i] + ": ";
						label2Str += dataBuf.readBits(1) ? "true" : "false";
						label2Str += "\n";
					}
				}
				dataBuf.position = tagNextPosition;
			} while (tagType != 0);
			label1.text = label1Str;
			label2.text = label2Str;

			headBuf.clear();
			dataBuf.clear();
		}
	}
}

import flash.utils.ByteArray;
import flash.utils.Endian;

class ByteArrayEx extends ByteArray
{
	private var bitPosition:int;

	public function ByteArrayEx()
	{
		bitPosition = 0;
	}

	public function readUnsignedLong():Number
	{
		var value1:Number, value2:Number;
		value1 = readUnsignedInt();
		value2 = readUnsignedInt();
		if (endian == Endian.BIG_ENDIAN) {
			value1 *= 0x100000000;
		} else {
			value2 *= 0x100000000;
		}
		return value1 + value2;
	}

	public function positionAlignment():void
	{
		if (bitPosition > 0) {
			position++;
			bitPosition = 0;
		}
	}

	public function readBit():int
	{
		var value:int = this[position];
		value = (value >> (7 - bitPosition++)) & 1;
		if (bitPosition > 7) {
			position++;
			bitPosition = 0;
		}
		return value;
	}

	public function readBits(length:int):int
	{
		var value:int = 0;
		for (var i:int = 0; i < length; i++) {
			value <<= 1;
			value |= readBit();
		}
		return value;
	}
}
[トップページに戻る]