Flash Kid Logo  
Home - Tutorials - Applications - Games - Books - Directory - Community - Site Map - Contact Us  
 
 


 
 
Protect Flash SWF Files

Author: Sergei Kaul
Difficulty Level: Advanced
Flash Version: All
Prerequisites: ActionScript Basics

Introduction:

Flash publishers have always been concerned about the security of valuable content which at times they don’t want to be copied or redistributed without their consent. However unfortunately Flash has been unable to address this concern of developers so far.



To cover this gap, publishers and vendors have come up with a number of techniques to protect flash content on the web. Some techniques are implemented within swf file, some are applied by distributing content and some are done by encrypting swf files. In this tutorial we will cover two techniques of swf protection.
This step-by-step tutorial will teach you how to make your swf secure by setting the trial period for swf file.

Implementing Trial Period:

Let's consider a simple example to show the implementation of trial period detector. Open any flash document, select appropriate frame and open the Action Script Panel (F9). Then enter the following code inside the actions panel:

function trialDetector():void {
            const yyyy:Number = 2008; // year
            const mmmm:Number = 0; // month-1 ( 0 (January), ... 11 (December))
            const dddd:Number = 1; // day of month (1,2,...,30,31)
            var expirationDate:Date = new Date(yyyy,mmmm,dddd);
            var currentDate:Date = new Date();
            if (currentDate > expirationDate){
            // expiration has been detected
                        for(;;); // use appropriate action here, for example - infinite loop to stop movie clip
            }
}

trialDetector();

Test your movie (Ctrl+Enter). You should see the "freezing" movie.

Don't forget to change values for yyyy, mmmm and dddd (in this example expiration date is equal to Jan 1 2008). Also change the function name - use something abstract instead of "trialDetector" to camouflage designation of this function.

Encrypting SWF File:
Is this method secure? Unfortunately, answer is NO. There are a lot of free swf decompilers avaialble in market. You can use the trial version of Sothink Decompiler flash to understand how easily anyone can remove trial restriction and steal your flash work.

Decompiled swf file's actionscript
Fig. 1 - Decompiled swf file’s actionscript

As you can see decompiler extracts ActionScript code from swf file in readable format. Moreover this decompiler can convert a swf file to fla format and an intruder can change source code to remove trial restriction.

Decompiled swf file's resources
Fig. 2 - Decompiled swf file’s resources

Even  swf file’s resources like images, sounds & movieclips can be stolen using common decompilers.

If you need more secure protection you can use SwfShield. This online tool protects swf files from being stolen.

Click "ProtectSWF" to login as guest without registration.

SWF file protection using SwfShield
Fig. 3 - SWF file protection using SwfShield

SwfShield is as easy as 1-2-3. Set desired trial period and click Build protected swf button. Select swf file to be protected, then enter name for protected file. That is all.

Let's run flash decompiler again and examine the content of protected swf file.

Decompiled swf file's resources after protection
Fig. 4 - Decompiled SWF file’s resources after protection

There are no original shapes, sounds etc. The original content is encrypted and hidden. The first decrypting layer is visible only.

You learnt two methods of protecting swf files against unauthorized use. The first one is free but everyone familiar with flash decompilers can easily overpass this approach. The second method is not free but it uses sophisticated encryption and protects complete swf file against de-compilation.



Exercises:

  1. Name three different types of techniques for securing flash swf files on web.

  2. Why swf is not secure even after implementing trial period mechanism?

  3. Download a free swf decompiler and decompile a swf file. Are you able to extract code from original swf file?
  1. Download a free swf decompiler and decompile a swf file. Are you able to extract source files from original swf file?

  2. Can you think of any other ways of protecting your flash content?

 
 

 
 
Related Links
Discussion Forums for Tutorials
 
 


 
 
 
 
© 2010 flashkid.org! All Rights Reserved.
 
   
 
a project of: xonsolutions.com, other projects: tutorialkid.org