Skip to content

Instantly share code, notes, and snippets.

@mntone
Last active December 27, 2015 02:09
Show Gist options
  • Save mntone/7250623 to your computer and use it in GitHub Desktop.
Save mntone/7250623 to your computer and use it in GitHub Desktop.
Program for checking amf0/amf3 raw byte array.
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.engine.*;
import flash.utils.*;
/**
* ...
* @author mntone
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener( Event.ADDED_TO_STAGE, init );
// entry point
var data:ByteArray = new ByteArray();
data.objectEncoding = ObjectEncoding.AMF0;
data.writeObject( 131 );
data.writeObject( "test" );
data.position = 0;
// check
var str:String = "len: " + data.length + "\n";
var copyAndPaste:String = "";
var length:int = data.length;
var i:int;
for( i = 0; i < length; ++i )
{
var b:uint = data.readUnsignedByte();
str += "[" + i.toString() + "] " + b.toString( 16 ) + "\n";
copyAndPaste += "0x" + b.toString( 16 ) + ", ";
}
trace( copyAndPaste );
var ef:ElementFormat = new ElementFormat();
ef.fontSize = 16;
ef.fontDescription = new FontDescription( "Consolas" );
var tb:TextBlock = new TextBlock();
tb.content = new TextElement( str, ef );
var ptf:TextLine = null;
for( var j:int = 0; j < i + 1; ++j )
{
var tf:TextLine = tb.createTextLine( ptf, 640 );
tf.x = 10 + 80 * int( j / 36 );
tf.y = 20 + 16 * ( j % 36 );
addChild( tf );
ptf = tf;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment