Created
April 14, 2011 23:51
-
-
Save claus/920852 to your computer and use it in GitHub Desktop.
Dump all static text contained in a SWF (using as3swf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.MovieClip; | |
import com.codeazur.as3swf.SWF; | |
import com.codeazur.as3swf.tags.ITag; | |
import com.codeazur.as3swf.tags.TagDefineText; | |
import com.codeazur.as3swf.data.SWFTextRecord; | |
import com.codeazur.as3swf.data.SWFGlyphEntry; | |
import com.codeazur.as3swf.tags.TagDefineFont2; | |
public class DumpText extends MovieClip | |
{ | |
public function DumpText() | |
{ | |
// loaderInfo.bytes is a ByteArray containing the raw, | |
// uncompressed SWF of the document class instance. | |
// Parse the SWF this code is running in: | |
var swf:SWF = new SWF(loaderInfo.bytes); | |
// loop over all tags | |
for each(var tag:ITag in swf.tags) | |
{ | |
// identify DefineText tags | |
if(tag is TagDefineText) | |
{ | |
trace("TextField contents:"); | |
var defineText:TagDefineText = tag as TagDefineText; | |
// loop over all text records in the DefineText tag | |
for(var i:uint = 0; i < defineText.records.length; i++) | |
{ | |
var str:String = ""; | |
var textRecord:SWFTextRecord = defineText.records[i]; | |
// get the DefineFont tag used for this text record | |
var defineFont:TagDefineFont2 = swf.getCharacter(textRecord.fontId) as TagDefineFont2; | |
if(defineFont != null) | |
{ | |
// loop over all glyph entries in the text record | |
for(var j:uint = 0; j < textRecord.glyphEntries.length; j++) | |
{ | |
var glyphEntry:SWFGlyphEntry = textRecord.glyphEntries[j]; | |
// the glyph entry's index property points into the glyph- and | |
// code table arrays of the respective DefineFont tag | |
str += String.fromCharCode(defineFont.codeTable[glyphEntry.index]); | |
} | |
trace(" " + i + ": \"" + str + "\" (fontId: " + textRecord.fontId + ")"); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Claus, du rockst!