Protecting your SWF with secureSWF

February 8th, 2010

secureSWF
This is a topic I’m worry from long time ago, especially when I work as freelancer becouse when I show the project to the clients I always think they will decompile the SWF and they will dissapear. Quite paranoid on my part but not so far removed from reality(possible). Fortunately I never had any problems about this, but I still prefer to be protected in this regard. Besides these abuses also are used for other purposes such as theft of ideas, search for security flaws and exploits, and so on. It is also a very important issue when your application will give some commercially valuable prizes, as it is even more tempting to get the full benefit of some gruesome way.

Anyone with a copy of a Flash decompiler such as ASV or Sothink Decompiler can look at your ActionScript code. Suddenly, your licensing code, copy protection mechanisms, and proprietary logic are much more available for all to see – whether it’s legal or not. Anyone can use the details of your software for whatever reason they like. They can search for security flaws to exploit, steal unique ideas, crack programs, etc.

Actionscript is a language very easy to decompile, decompilers are over 22 today. This is not a design flaw in the language, is simply a reality of interpreted language such as Java,. NET, etc.

The encryption of the SWF (more like the code obfuscation) it is the code will be confused and difficult to understand. It is noteworthy that not a real encryption.

Well finally and not more widespread, despite all the protection it gives us the obfuscation code still vulnerable to the illegal redistribution of our application, anyone can download the SWF and publish it elsewhere. To solve this secureSWF has a protective system of domains (the movie will only work within the domains we specify) and also a encrypted loader (generates a separate swf that will be the shipper of our movie, assigns names to swf encrypted and decrypted it at runtime doing much more complex the issue of downloading our swf), the grace of this is protecting us from attacks or SWF rippers grabbers, they are going to collect as SWF.

secureSWF is the most sophisticated ActionScript obfuscation, code protection, and SWF encryption solution for Adobe’s Flash and Flex.
It provides state-of-the-art techniques to stop Flash decompilers, prevent illegal copying and redistribution, and help you increase your Flash application’s security.

What secureSWF’s SWF Encryption Does


  • Control Flow Obfuscation
  • Changes possible areas of the code flow that doesn’t affect the way the application runs. It also inserts extra control flow statements in certain areas of the code to make decompilation virtually impossible.

  • Dynamic Code Wrapping
  • Dynamically wraps up the ActionScript byte-code blocks in SWF files to make finding entry points of the code very difficult for Flash decompilers. This will usually crash the decompiler.

  • Statement-level Randomization
  • Will randomly restructure the sequence of the byte-code instructions that the decompiler uses to reform a complete ActionScript statement. It removes all the possible links between the compiled byte-code and the ActionScript source code making decompiling a very difficult process.

  • String Encryption
  • Will replace sensitive literal strings in your code with a function call that gets the string from an encrypted byte array.

    The Information secureSWF Removes


  • Packages (and internal namespaces for AS3)
  • Classes
  • Functions (getters and setters as well)
  • Variables (local and global variables for AS1 and AS2)
  • Handles Inheritance and Polymorphism
  • Dynamic Variables (even the ones done by AS2 eval)
  • Removes Function Parameters Names
  • Frame Labels
  • Symbol Instance Names
  • Button Names
  • Textfield Names
  • Edit Textfield Variables
  • SWF Metadata
  • ActionScript 3 Metadata

  • Getting Started secureSWF


    secureSWF Manual


    Demo



    Only to show you the result of the secureSWF encryption I wrote this basic class.

    Before

    package
    {
    	import flash.display.Sprite;
    	import flash.display.StageAlign;
    	import flash.display.StageQuality;
    	import flash.display.StageScaleMode;
     
    	public class Main extends Sprite
    	{
    		private var _draw:Sprite;
     
    		public function Main()
    		{
    			super();
    			configStage();
    			createDraw();
    			testFor();
    		}
     
    		private function testFor():void
    		{
    			for (var i:int = 0; i < 10; i++) 
    			{
    				trace(i);
    			}
    		}
     
    		private function createDraw():void
    		{
    			_draw = new Sprite();
    			addChild(_draw);
    			_draw.graphics.beginFill(0xff0000);
    			_draw.graphics.drawRect(0, 0, 100, 100);
    			_draw.graphics.endFill();
    		}
     
    		private function configStage():void
    		{
    			stage.scaleMode = StageScaleMode.NO_SCALE;
    			stage.quality = StageQuality.BEST;
    			stage.align = StageAlign.TOP_LEFT;
    		}
    	}
    }

    After

    package
    {
    	import flash.display.*;
     
    	public class do extends Object
    	{
    		public function do(  )
    		{
    			var _local_1:boolen;
    			var _local_2 = false<NULL&param2;
    			if( _local_2&&_local_1 )
    			{
    			}
    			if( _local_2 )
    			{
    				this.break();
    				if( _local_2 )
    				{
    					this.if();
    					if( _local_2&&_local_2 )
    					{
    						this. do();
    					}
    					return;
    		}
    		private function if(  ):void
    		{
    			var _local_1:boolen;
    			var _local_2 = ^===<-^false++;
    			if( _local_1 )
    			{
    				 case = new Sprite();
    				if( _local_2&&this )
    				{
    				}
    				addChild(this. case);
    				if( _local_2&&_local_1 )
    				{
    					this. case.graphics.beginFill(16711680);
    					if( _local_1 )
    					{
    						_local_2 = 0>0;
    						drawRect(,this instanceof 0-0,100,100);
    						this. case.graphics.endFill();
    					}
    				}
    				return;
    		}
    		private var  case:Sprite;
    		private function break(  ):void
    		{
    			var _local_1:boolen;
    			var _local_2:Object;
    			if( _local_2 )
    			{
    			}
    			stage.scaleMode = StageScaleMode.NO_SCALE;
    			if( _local_2 )
    			{
    				stage.quality = StageQuality.BEST;
    				if( 0-0||this )
    				{
    					stage.align = StageAlign.TOP_LEFT;
    				}
    				return;
    		}
    		private function  do(  ):void
    		{
    			var _local_2 = true as param2>=param2;
    			var _local_3:boolen;
    			var _local_1:int;
    			while( _local_1<10 )
    			{
    			}
    			return;
    		}
    	}
    }



    How you can see, the result is very crazy, but the code execution do exactly the same of the original. For this example I used the standard encryption (exist others), but with more hard security settings my decompiler crash. :) very nice!!

    Well, this example is the end of my post. I hope you like it. Any comment or suggestions will be welcome.

    Sponsored by secureSWF

    miguelMoraleda Actionscript 3, Actionscript 3, Flash ,

    Car Racing Game Prototype using Unity3D

    November 23rd, 2009

    carExample-unity3d
    car-Example2-unity3d
    car-Example3-unity3d

    Well, once again writing about Unity3D, the latest good news is that now the engine is free but it has some restrictions (no dynamic shadows, shaders, etc). I recommend to everyone who is interested in developing games to download it, start to play, enjoy it!!.

    The images above belongs to the actual version of a racing game prototype that I am working on in my free time. The demo has bugs and is not finished yet, but I want to show you the posibilities of Unity3D Pro and its dynamic shadow system. I hope you enjoy this demo, feel free to leave me any comments or suggestions.

    VIEW EXAMPLE



    miguelMoraleda Unity3D

    Point in Polygon with actionscript 3

    October 28th, 2009

    Testing whether a point is inside a polygon is a basic operation in computer graphics. Here a example of how to do that in a very simple way.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    
    private function insidePolygon(pointList:Array, p:Point):Boolean
    {
    	var counter:int = 0;
    	var i:int;
    	var xinters:Number;
    	var p1:PointTest;
    	var p2:PointTest;
    	var n:int = pointList.length;
     
    	p1 = pointList[0];
    	for (i = 1; i <= n; i++)
    	{
    		p2 = pointList[i % n];
    		if (p.y > Math.min(p1.y, p2.y))
    		{
    			if (p.y <= Math.max(p1.y, p2.y))
    			{
    				if (p.x <= Math.max(p1.x, p2.x))
    				{
    					if (p1.y != p2.y) {
    						xinters = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
    						if (p1.x == p2.x || p.x <= xinters)
    							counter++;
    					}
    				}
    			}
    		}
    		p1 = p2;
    	}
    	if (counter % 2 == 0)
    	{
    		return(false);
    	}
    	else
    	{
    		return(true);
    	}
    }

    DEMO
    SOURCE
    Reference

    miguelMoraleda Actionscript 3, Actionscript 3, Flash

    Adobe AIR 2.0, New features

    October 14th, 2009

    In this first post I will tell you about the new features that are coming with AIR 2.0

  • Start native processes and applications: In AIR 2.0 you will be able to start a native application installed in the OS from you AIR application. This is very very useful.
  • Native Installers: You’ll also have Native Installers for the OS. You will be able to generate .exe, .dmg, .rpm or .deb when you package the file. Obviously the .air file is also included in the list.
  • New classes. FilePromise, URLFilePromise: You will use these classes when you want to download a file from the server but you don’t have the file reference yet. That’s why you will be telling AIR that you have a promise of a file.
  • Socket servers: This is an extraordinary feature. You will be able to configure and start a socket server from the AIR application. We know that FlashPlayer can connect to socket servers but now you will be able to start one from the AIR app and also secure socket servers with TLS
  • IPv6: Now you’ll have compatibility with IPv6.
  • NetworkInfo class: With this new class we can check detail information about the network in the hosting device. Information like the interfaces that are available in the host.
  • UDP support: We can now connect by UDP.
  • Audio encoding: This is an extraordinary functionality because with this feature we will be able to record the sound captured by the microphone without any server like FMS or any other. Basically we can encode the sound raw info as a sound.
  • Global Error Handling: Have you ever tried to handle the multiple errors that you forgot to catch ? Now we can do it. The global error handling will work as a general try and catch block for any exception that could happen during the app execution.
  • JavaScript Debugging and profiling: The ability to debug and profile javascript code in the AIR app will be integrated into the AIR 2.0 runtime. Profiling will be only available from Aptana.
  • New webkit features: Now the engine has a module that supports CSS3 :-D , custom styles can be applied to scrollbars, we can break up text across columns, and more.
  • Profiles for AIR applications: Defined in the application descriptor, we now have a set of profiles that enable/disable some functionality in the Application. We have a “desktop” profile, a “NativeDesktop” profile (for native installers), “mobile” profile (for mobile AIR applications) and “extenden mobile” profile.
  • AIR Mobile applications: Yes, we can now create AIR applications for mobile devices, including the iPhone and the applications for iPhone will be package as .ipa, a native iPhone Application.
  • miguelMoraleda Air, Flash

    Unity3D – continue playing

    September 28th, 2009

    Here my last example using Unity3D, it is a very simple First Person Game. I made it following the fps tutorial from official web site of unity (view tutorial). All model are from free 3d models pages and is the part that take more time in the example :) ..

    View EXAMPLE

    unity3D example 3

    unity3D example 3

    unity3D example 1

    unity3D example 1

    unity3D example 2

    unity3D example 2



    miguelMoraleda Games, Unity3D ,

    Finding used zone of a image with transparent zones.

    August 19th, 2009

    To find used zone of a image I use this code.

    1
    2
    3
    4
    
    //Create a color mask with a alpha tolerance value. (_alphaTolerance is the percent)
    var maskTolerance:uint = Math.round((2.55) * (100 -_alphaTolerance)) << 24;	
    //Get used zone
    var usedZone:Rectangle = image.bitmapData.getColorBoundsRect(maskTolerance, maskTolerance, true);

    VIEW EXAMPLE
    DOWNLOAD EXAMPLE



    miguelMoraleda Actionscript 3, Flash

    Google Sky, Moon and Mars with gmaps-utility-library-flash

    July 19th, 2009

    Reading about google maps I found a utility library for google maps that add the maps of the Sky, Moon and Mars. The library contains more tools.
    For more information visit the google code page of this library
    http://code.google.com/p/gmaps-utility-library-flash/

    GOOGLE SKY EXAMPLE (or press the image to go)
    googleSky

    GOOGLE MOON EXAMPLE (or press the image to go)
    googleMoon

    GOOGLE MARS EXAMPLE (or press the image to go)
    googleMars



    admin Actionscript 3, Flash

    Tutorial Actionscript 3 – How To Google Maps API

    July 19th, 2009

    The Google Maps API lets you embed Google Maps in your own web pages with JavaScript. The API provides a number of utilities for manipulating maps (just like on the http://maps.google.com web page) and adding content to the map through a variety of services, allowing you to create robust maps applications on your website.

    In this post I will explain how to use the Google Maps API.

    1.- The first thing that you need is to get your API KEY
    Go to http://code.google.com/apis/maps/signup.html

    After read and accept the terms and conditions and give your domain name. You will get your key.

    googleMaps

    2.- The next step is download the library kit of google maps for actionscript and flex.
    To download the kit CLICK HERE
    The kit contains 2 .swc files with the library.

    3.- With the key and api we are ready to start with the code. Create a new project and config the library path to read the swc file downloaded. In your Flash IDE press edit-preferences-actionscript- actionscript 3 and add the folder with your swc files.

    4.- THE CODE.

    var _map:Map = new Map();
    _map.key = "ACA DEBEN PONER SU KEY";
    _map.language = "es";
    _map.setSize(new Point(stage.stageWidth, stage.stageHeight));
    _map.addEventListener(MapEvent.MAP_READY, onMapReady);
    _map.y = 50;
    addChild(_map);
     
    function onMapReady(event:Event):void {
    	_map.setCenter(new LatLng(40.736072, -73.992062), 14, MapType.NORMAL_MAP_TYPE);
    }

    With this simple code we have our example working.

    googleMaps

    I hope this post help you to understand how works the google maps API. Any question or suggestions are welcome

    VIEW EXAMPLE
    DOWNLOAD EXAMPLE



    miguelMoraleda Actionscript 3, Flash

    Tutorial actionscript3 – Loading sound and play as loop

    July 10th, 2009

    DOWNLOAD EXAMPLE

    package
    {
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.media.Sound;
    	import flash.media.SoundChannel;
    	import flash.net.URLRequest;
     
    	/**
    	 * This class load a sound and play it in loop.
    	 * @author http://www.miguelmoraleda.com
    	 */
    	public class Main extends Sprite
    	{
    		private var soundFactory:Sound;
    		private var song:SoundChannel;
     
    		public function Main()
    		{
    			super();
     
    			loadSound("sound.mp3");
    		}
     
    		/**
    		 * Load the sound
    		 * @param	url
    		 */
    		private function loadSound(url:String):void
    		{
    			var request:URLRequest = new URLRequest(url);
                soundFactory = new Sound();
                soundFactory.addEventListener(Event.COMPLETE, completeHandler);
                soundFactory.load(request);
    		}
     
    		/**
    		 * When sound is loaded, play it.
    		 * @param	e
    		 */
    		private function completeHandler(e:Event):void
    		{
    			soundFactory.removeEventListener(Event.COMPLETE, completeHandler);
    			playSound();
    		}
     
    		/**
    		 * Play the sound and add listener to sound complete.
    		 */
    		private function playSound():void
    		{
                song = soundFactory.play();
    			song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
    		}
     
    		/**
    		 * when the sound is finish play again.
    		 * @param	e
    		 */
    		private function soundCompleteHandler(e:Event):void
    		{
    			song.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
    			playSound();
    		}
    	}
    }



    miguelMoraleda Actionscript 3, Flash

    Augmented Reality – levelHead v1.0, 3-cube speedrun

    May 23rd, 2009
    Get Adobe Flash playerPlugin by wpburn.com wordpress themes