<?xml version="1.0" encoding="utf-8"?> <!-- see http://makc3d.wordpress.com/2010/02/09/open-source-swf-obfuscator/ for details --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import flash.events.Event; import flash.net.FileFilter; import flash.net.FileReference; import flash.utils.ByteArray; import mx.controls.Alert; private function sampleDefinitionsList ():void { // you cannot obtain definitions list without actually parsing swf :( // for simple way to do it, see http://etcs.ru/blog/as3/getdefinitionnames/ taList.text = "_transform\rAbstractRenderSession\raway3d.core\rView3D"; } private function obfuscate ():void { Alert.show ("In following dialog, select SWF file to obfuscate.", "Information", 0x4, null, loadFile); } private function loadFile (e:Event):void { ref = new FileReference; ref.addEventListener (Event.SELECT, swfSelected); ref.browse ([new FileFilter("SWF Files", "*.swf")]); } private function swfSelected (e:Event):void { ref.addEventListener (Event.COMPLETE, swfLoaded); ref.load (); } private function swfLoaded (e:Event):void { // place uncompressed swf in byte array if (ref.data.readMultiByte (3, "us-ascii") == "CWS") { swf = decompress (ref.data); } else { swf = ref.data; } // sort definitions list by length for long defs to be processed 1st var defs:Array = taList.text.split ("\r"); defs.sort (function (a:String, b:String):int { var aL:int = a.length, bL:int = b.length; if (aL < bL) return 1; else if (aL > bL) return -1; return 0; }); // generate random translation var i:int, poops:Array = []; for (i = 0; i < defs.length; i++) { var s:String = ""; while ((s == "") || (poops.indexOf (s) > -1)) s = randomString (defs [i].length); poops [i] = s; } // obfuscate while (defs.length > 0) { var def:String = defs.shift (); var poop:String = poops.shift (); swf.position = 0; while (findString (swf, def)) for (i = 0; i < poop.length; i++) swf.writeByte (poop.charCodeAt (i)); } Alert.show ("In following dialog, select where to save obfuscated SWF file.", "Information", 0x4, null, saveFile); } private function saveFile (e:Event):void { new FileReference().save (compress (swf)); } private var ref:FileReference; private var swf:ByteArray; private function randomString (length:int):String { var s:String = ""; while (s.length < length) s += String.fromCharCode (33 + int (32 * Math.random ())); return s; } private function findString (data:ByteArray, string:String):Boolean { var i:int = 0; while (data.bytesAvailable) { var char:int = data.readByte (); if (char == string.charCodeAt (i)) { i++; if (i == string.length) { // we found match data.position -= string.length; return true; } } else { i = 0; } } return false; } // compression functions by Nikita Leshenko // http://active.tutsplus.com/tutorials/workflow/protect-your-flash-files-from-decompilers-by-using-encryption/ private function compress (data:ByteArray):ByteArray { var header:ByteArray = new ByteArray; var decompressed:ByteArray = new ByteArray; var compressed:ByteArray = new ByteArray; header.writeBytes (data, 3, 5); // read the header, excluding the signature decompressed.writeBytes (data, 8); // read the rest decompressed.compress (); compressed.writeMultiByte ("CWS", "us-ascii"); // mark as compressed compressed.writeBytes (header); compressed.writeBytes (decompressed); return compressed; } private function decompress (data:ByteArray):ByteArray { var header:ByteArray = new ByteArray; var compressed:ByteArray = new ByteArray; var decompressed:ByteArray = new ByteArray; header.writeBytes (data, 3, 5); // read the uncompressed header, excluding the signature compressed.writeBytes (data, 8); // read the rest, compressed compressed.uncompress (); decompressed.writeMultiByte ("FWS", "us-ascii"); // mark as uncompressed decompressed.writeBytes (header); // write the header back decompressed.writeBytes (compressed); // write the now uncompressed content return decompressed; } ]]> </mx:Script> <mx:Button width="400" label="Load and obfuscate SWF" click="obfuscate()"/> <mx:Label text="Please edit the list of definitions to be obfuscated in the text area below"/> <mx:TextArea id="taList" width="400" height="350" initialize="sampleDefinitionsList()" /> </mx:Application> SWF Obfuscator