You can embed an swf, or any other binary octet stream, containing -harder to get to- data as a hexadecimal string into your project. Note: This is not true data security. Nothing is securable in actionscript, but you CAN make it hard(er) to get to.
So to describe my last attempt to hide some game xml data that I embedded in an second swf i went ahead like this to embed that swf as a hex string in my main project like this:

  • 1) Create a seperate empty project along your main project and create a simple swf containing the protectable data.

  • 2) I'm not a smoker but let's say you want secure the class "SensimillaPlantagesXml.as" containing your sensitive sensimilla location xml data. Compile that class into "sensitive.swf" (uhum). Make sure that that class is embedded into the swf by including a reference to it in your document's main class new SensimillaPlantagesXml() or just put 'SensimillaPlantagesXml' as a word in your documentclass's constructor

  • 3)Create a second project along your main project that will serve as a hexadecimal tracer: Embed the swf in it with the Embed tag. We will now convert the binary application octet stream from 'sensitive.swf' to a hexadecimal string:

  • [ftf w="600" h="300"] package data { import com.latcho.helper.transform.BinHex; import flash.utils.ByteArray; public class TraceBinToHexString { [Embed(source = 'bin/sensitive.swf', mimeType = "application/octet-stream")] static private const Bin: Class; public function TraceBinToHexString() { var ba:ByteArray = ByteArray( new Bin() ); trace( BinHex.binToHex(ba ) ); } } } [/ftf]
  • 4) This will leave us with a long hexadecimal string in the trace output window, representing your swf as hexadecimal data. The class to do the Binary to Hexadecimal conversion I will include later, below in this post.
  • Trace Output: 4357530a2a60000078dad55c4d6cdbd87626f547cbffae6399444f9274a3d4a642b4e9cc4719eedb.........
  • 5)Copy that string without additional spaces and paste it in a 'Data' class under a variable, called var _hexData here.

  • 6)So let me show you now how you load this hexadcimal string, and parse it as an accessible swf within you main project:

  • [ftf w="700" h="800"] package nl.greenberry.gogeo.data { import com.latcho.helper.transform.BinHex; import flash.display.Loader; import flash.events.Event; import flash.events.EventDispatcher; import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.utils.ByteArray; import flash.utils.getDefinitionByName; public class Data extends EventDispatcher { /* hex data representing your binary swf */ private static var _hexData:String = '4357530a2a60000078dad55c4d6cdb...way-longer.....'; /** load the binary swf data by converting the hex string * to a (binary) ByteArray: BinHex.HexToBin(_hexData) --> will return return a BytArray * Then we feed the bytes into a Loader instance it's loadbytes() function. **/ public function Data() { var loader:Loader = new Loader() loader.loadBytes( BinHex.HexToBin(_hexData), new LoaderContext(false, ApplicationDomain.currentDomain) ); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onData); } /** * Anytime after this load completion event fired you can call your 'sensitive' * wherever within in your main project. * To simplify this example we immediatly access our obsfucated xml data here * So your loaded swf and all it's contained classes are now loaded and accessible; * We retrieve them by a term called reflection. */ private function onData(e:Event):void { var class_ref:Class = getDefinitionByName('SensimillaPlantagesXml') as Class; // var mySensitiveClass:MyDataInterface = new class_ref(); var mySensitiveClass:* = new class_ref(); trace(mySensitiveClass.xmlData); // we drop the typing because if you use the type 'SensimillaPlantagesXml' // dor the mySensitiveClass variable then the class with sensitive data // will get compiled in your project // and we want to prevent that. // A sollution for this issue is creating an interface that you can import here // and use that as a type for the mySensitiveClass variable. // You need to implement that interface too in the SensimillaPlantagesXml Class. // var mySensitive:MyDataInterface = new class_ref());--> // The interface can then contain a function get xmlData():XML // as the SensimillaPlantagesXml Class does includes it too } } } [/ftf]
    The only easy way to get to ALL the data of the embedded-hex-swf is (including bitmaps) is making an swf file from it; Now be my guest and write me a short (AIR?) tutorial please :). This procedure is not super secure but discourages our fast'n easy decompiler friends. Still better then posting the data over http. If the process is not clear by now, please let me know, so I can improve above instructions. Here you can see the transformation class that contains the two static functions binToHex() and hexToBin();
    And here you can see BinHex.as: [ftf w="600" h="675"] package com.latcho.helper.transform { import flash.utils.ByteArray; public class BinHex { public static function binToHex(binData:ByteArray):String { var len:uint = binData.length; var s:String = ''; var hh:String; for (var i:uint = 0; i < len; i++) { hh=binData.readUnsignedByte().toString(16); s += (hh.length == 1) ? '0'+hh : hh; } return s; } public static function hexToBin(value:String):ByteArray { var ba:ByteArray = new ByteArray(); var len:uint = value.length; for (var i:uint = 0; i < len; i += 2) { var c:String = value.charAt(i) + value.charAt(i + 1); ba.writeByte(parseInt(c, 16)); } return ba; } } } [/ftf] Download BinHex.as

    Ciao !

    See this post as raw text