Advertisement
Guest User

Script from Skype detection

a guest
Jul 3rd, 2011
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ActionScript 3.0
  2. //  package com
  3. //    package skype
  4. //      package detection
  5. //        class Detection
  6. package com.skype.detection
  7. {
  8.     import flash.display.*;
  9.     import flash.events.*;
  10.     import flash.external.*;
  11.     import flash.net.*;
  12.     import flash.system.*;
  13.     import flash.text.*;
  14.     import flash.utils.*;
  15.    
  16.     public class Detection extends flash.display.MovieClip
  17.     {
  18.         public function Detection()
  19.         {
  20.             ourDomains = ["*.skype.com", "*.skype.test", "*.skype.net"];
  21.             super();
  22.             setupStage();
  23.             setupSecurity();
  24.             addEventListener(Event.ENTER_FRAME, onEnterFrame);
  25.             return;
  26.         }
  27.  
  28.         private function setupStage():void
  29.         {
  30.             var loc1:*;
  31.             try
  32.             {
  33.                 stage.align = StageAlign.TOP_LEFT;
  34.                 stage.scaleMode = StageScaleMode.NO_SCALE;
  35.             }
  36.             catch (e:Error)
  37.             {
  38.             };
  39.             revisionText.appendText(REVISION.slice(11, -2));
  40.             return;
  41.         }
  42.  
  43.         private function cloneObject(arg1:Object):Object
  44.         {
  45.             var loc2:*;
  46.             loc2 = null;
  47.             var loc1:*;
  48.             loc1 = {};
  49.             var loc3:*;
  50.             loc3 = 0;
  51.             var loc4:*;
  52.             loc4 = arg1;
  53.             for (loc2 in loc4)
  54.             {
  55.                 loc1[loc2] = arg1[loc2];
  56.             }
  57.             return loc1;
  58.         }
  59.  
  60.         private function initRest():void
  61.         {
  62.             context = getLoaderContext();
  63.             setupExternalInterface();
  64.             detect();
  65.             notify();
  66.             fixCorruption();
  67.             return;
  68.         }
  69.  
  70.         private function debugData():void
  71.         {
  72.             var loc1:*;
  73.             loc1 = ["installed: " + this.installed, "version: " + this.version, "language: " + this.language, "platform: " + this.platform, "segment: " + this.segment];
  74.             myTrace(loc1.join(", "));
  75.             detailsText.text = loc1.join("\n");
  76.             return;
  77.         }
  78.  
  79.         public function getData():Object
  80.         {
  81.             var loc1:*;
  82.             loc1 = {};
  83.             loc1.version = version;
  84.             loc1.platform = platform;
  85.             loc1.language = language;
  86.             loc1.segment = segment;
  87.             return loc1;
  88.         }
  89.  
  90.         private function detect():void
  91.         {
  92.             var loc2:*;
  93.             loc2 = null;
  94.             var loc1:*;
  95.             loc1 = SharedObject.getLocal("ui/preferences", "/");
  96.             installed = !(loc1.data.ui_version == undefined);
  97.             segment = getUserSegment();
  98.             if (installed)
  99.             {
  100.                 version = loc1.data.ui_version;
  101.                 language = loc1.data.ui_language;
  102.                 loc2 = loc1.data.os_version;
  103.                 if (loc2.indexOf("Macintosh") == -1)
  104.                 {
  105.                     if (loc2.indexOf("Linux") == -1)
  106.                     {
  107.                         if (!(loc2.indexOf("Windows") == -1) || !(loc2.indexOf("Service Pack ") == -1) || !(loc2.indexOf("5.01.2600") == -1) || !(loc2.indexOf("6.00.600") == -1) || !(loc2.indexOf("6.01.") == -1))
  108.                         {
  109.                             platform = "windows";
  110.                         }
  111.                         else
  112.                         {
  113.                             platform = "unknown";
  114.                         }
  115.                     }
  116.                     else
  117.                     {
  118.                         platform = "linux";
  119.                     }
  120.                 }
  121.                 else
  122.                 {
  123.                     platform = "mac";
  124.                 }
  125.             }
  126.             loc1.flush();
  127.             debugData();
  128.             return;
  129.         }
  130.  
  131.         private function isOurDomain(arg1:String):Boolean
  132.         {
  133.             var loc2:*;
  134.             loc2 = null;
  135.             var loc1:*;
  136.             loc1 = "";
  137.             if (arg1 && (arg1.indexOf("http://") == 0 || arg1.indexOf("https://") == 0))
  138.             {
  139.                 loc1 = arg1.split("/")[2].split(":")[0];
  140.                 myTrace("Using domain name " + loc1 + " in checks");
  141.             }
  142.             if (!loc1.length)
  143.             {
  144.                 return false;
  145.             }
  146.             var loc3:*;
  147.             loc3 = 0;
  148.             while (loc3 < ourDomains.length)
  149.             {
  150.                 loc2 = ourDomains[loc3];
  151.                 if (loc2.indexOf("*") != 0)
  152.                 {
  153.                     if (loc1 == loc2)
  154.                     {
  155.                         myTrace("Our domain " + loc2 + " matched exactly");
  156.                         return true;
  157.                     }
  158.                 }
  159.                 else
  160.                 {
  161.                     loc2 = loc2.substring(1, loc2.length);
  162.                     if (loc1.lastIndexOf(loc2) == loc1.length - loc2.length || loc1 == loc2.substring(1, loc2.length))
  163.                     {
  164.                         myTrace("Our domain " + ourDomains[loc3] + " wildcard matched");
  165.                         return true;
  166.                     }
  167.                 }
  168.                 loc3 = (loc3 + 1);
  169.             }
  170.             return false;
  171.         }
  172.  
  173.         public function getSessionData():Object
  174.         {
  175.             if (context != CONTEXT_OUR)
  176.             {
  177.                 return {};
  178.             }
  179.             var loc1:*;
  180.             loc1 = SharedObject.getLocal("user/session", "/");
  181.             var loc2:*;
  182.             loc2 = cloneObject(loc1.data);
  183.             loc2.segment = getUserSegment();
  184.             return loc2;
  185.         }
  186.  
  187.         public function setUserSegment(arg1:String):Boolean
  188.         {
  189.             if (context != CONTEXT_OUR)
  190.             {
  191.                 return false;
  192.             }
  193.             arg1 = arg1.replace(new RegExp("[^-a-z]", "g"), "");
  194.             var loc1:*;
  195.             loc1 = SharedObject.getLocal("user/segment", "/");
  196.             loc1.data.segment = arg1;
  197.             segment = arg1;
  198.             return true;
  199.         }
  200.  
  201.         private function setupExternalInterface():void
  202.         {
  203.             var loc1:*;
  204.             if (!ExternalInterface.available)
  205.             {
  206.                 return;
  207.             }
  208.             try
  209.             {
  210.                 ExternalInterface.addCallback("isInstalled", isInstalled);
  211.                 ExternalInterface.addCallback("getData", getData);
  212.                 if (context == CONTEXT_OUR)
  213.                 {
  214.                     ExternalInterface.addCallback("getSharedObjectData", getSharedObjectData);
  215.                     ExternalInterface.addCallback("getSessionData", getSessionData);
  216.                     ExternalInterface.addCallback("clearSessionData", clearSessionData);
  217.                     ExternalInterface.addCallback("getUserSegment", getUserSegment);
  218.                     ExternalInterface.addCallback("setUserSegment", setUserSegment);
  219.                 }
  220.             }
  221.             catch (e:SecurityError)
  222.             {
  223.                 myTrace("ExternalInterface addCallback calls failed, likely Flash Player security sandbox issue. " + undefined.message);
  224.             }
  225.             catch (e:Error)
  226.             {
  227.                 myTrace("ExternalInterface addCallback calls failed. " + undefined.message);
  228.             }
  229.             return;
  230.         }
  231.  
  232.         public function getUserSegment():String
  233.         {
  234.             if (context != CONTEXT_OUR)
  235.             {
  236.                 return "";
  237.             }
  238.             var loc1:*;
  239.             loc1 = SharedObject.getLocal("user/segment", "/");
  240.             return loc1.data && loc1.data.segment ? loc1.data.segment : "";
  241.         }
  242.  
  243.         private function onEnterFrame(arg1:flash.events.Event):void
  244.         {
  245.             removeEventListener(Event.ENTER_FRAME, onEnterFrame);
  246.             initRest();
  247.             return;
  248.         }
  249.  
  250.         public function downloadSkype(arg1:flash.display.DisplayObjectContainer, arg2:Function=null):Boolean
  251.         {
  252.             var callbackFunction:Function=null;
  253.             var loader:flash.display.Loader;
  254.             var root:flash.display.DisplayObjectContainer;
  255.  
  256.             var loc1:*;
  257.             loader = null;
  258.             root = arg1;
  259.             callbackFunction = arg2;
  260.             if (installed)
  261.             {
  262.                 return false;
  263.             }
  264.             try
  265.             {
  266.                 loader = new Loader();
  267.                 loader.load(new URLRequest(INSTALL_SWF_URL));
  268.                 root.addChild(loader);
  269.                 startCheckingSkypeInstalled(callbackFunction);
  270.             }
  271.             catch (e:Error)
  272.             {
  273.                 myTrace("Could not load installer swf: " + undefined);
  274.                 return false;
  275.             }
  276.             return true;
  277.         }
  278.  
  279.         private function getHostingPageURL():String
  280.         {
  281.             var result:String;
  282.  
  283.             var loc1:*;
  284.             result = "";
  285.             if (ExternalInterface.available)
  286.             {
  287.                 try
  288.                 {
  289.                     result = ExternalInterface.call("window.location.href.toString");
  290.                 }
  291.                 catch (e:Error)
  292.                 {
  293.                 };
  294.             }
  295.             return result;
  296.         }
  297.  
  298.         public function getSharedObjectData():Object
  299.         {
  300.             if (context != CONTEXT_OUR)
  301.             {
  302.                 return {};
  303.             }
  304.             var loc1:*;
  305.             loc1 = SharedObject.getLocal("ui/preferences", "/");
  306.             return cloneObject(loc1.data);
  307.         }
  308.  
  309.         private function startCheckingSkypeInstalled(arg1:Function=null):void
  310.         {
  311.             installCallback = arg1;
  312.             installTimer = new Timer(1000);
  313.             installTimer.addEventListener(TimerEvent.TIMER, checkSkypeInstalled);
  314.             installTimer.start();
  315.             return;
  316.         }
  317.  
  318.         private function notify():void
  319.         {
  320.             var i:int;
  321.             var jsMethods:Array;
  322.  
  323.             var loc1:*;
  324.             jsMethods = null;
  325.             i = 0;
  326.             jsMethods = new Array("SkypeDetection.setReady", "SKYPE.util.ClientDetection.ready");
  327.             if (ExternalInterface.available && (context == CONTEXT_OUR || context == CONTEXT_TOP))
  328.             {
  329.                 i = 0;
  330.                 while (i < jsMethods.length)
  331.                 {
  332.                     try
  333.                     {
  334.                         ExternalInterface.call(jsMethods[i]);
  335.                     }
  336.                     catch (e:Error)
  337.                     {
  338.                         myTrace("Could not notify JS method " + jsMethods[i]);
  339.                     }
  340.                     i = (i + 1);
  341.                 }
  342.             }
  343.             return;
  344.         }
  345.  
  346.         public function clearSessionData():Boolean
  347.         {
  348.             if (context != CONTEXT_OUR)
  349.             {
  350.                 return false;
  351.             }
  352.             var loc1:*;
  353.             loc1 = SharedObject.getLocal("user/session", "/");
  354.             loc1.clear();
  355.             return true;
  356.         }
  357.  
  358.         private function fixCorruption():void
  359.         {
  360.             var loc1:*;
  361.             loc1 = SharedObject.getLocal("ui/preferences", "/");
  362.             if (loc1.data.download_date && loc1.data.ui_version == undefined)
  363.             {
  364.                 myTrace("Clearing corrupted sharedobject!");
  365.                 loc1.clear();
  366.             }
  367.             else
  368.             {
  369.                 if (loc1.data.download_date && loc1.data.ui_version.length)
  370.                 {
  371.                     myTrace("Removing download_date botched data");
  372.                     delete loc1.data.download_date;
  373.                 }
  374.             }
  375.             loc1.flush();
  376.             return;
  377.         }
  378.  
  379.         private function setupSecurity():void
  380.         {
  381.             Security.exactSettings = false;
  382.             Security.allowDomain("*");
  383.             return;
  384.         }
  385.  
  386.         private function getLoaderContext():String
  387.         {
  388.             var loc1:*;
  389.             loc1 = null;
  390.             if (loaderInfo.loaderURL != loaderInfo.url)
  391.             {
  392.                 if (isOurDomain(loaderInfo.loaderURL))
  393.                 {
  394.                     myTrace("Loaded from our domain swf");
  395.                     loc1 = CONTEXT_OUR;
  396.                 }
  397.                 else
  398.                 {
  399.                     myTrace("Loaded inside other domain swf: " + loaderInfo.loaderURL);
  400.                     loc1 = CONTEXT_OTHER;
  401.                 }
  402.             }
  403.             else
  404.             {
  405.                 if (isOurDomain(getHostingPageURL()))
  406.                 {
  407.                     myTrace("Loaded from our domain html");
  408.                     loc1 = CONTEXT_OUR;
  409.                 }
  410.                 else
  411.                 {
  412.                     myTrace("Loaded as top level swf");
  413.                     loc1 = CONTEXT_TOP;
  414.                 }
  415.             }
  416.             return loc1;
  417.         }
  418.  
  419.         private function checkSkypeInstalled(arg1:flash.events.TimerEvent):void
  420.         {
  421.             detect();
  422.             if (installed && !(installCallback == null))
  423.             {
  424.                 installTimer.stop();
  425.                 myTrace("Skype is now installed, running callback.");
  426.                 installCallback();
  427.             }
  428.             return;
  429.         }
  430.  
  431.         public function isInstalled():Boolean
  432.         {
  433.             return installed;
  434.         }
  435.  
  436.         private function myTrace(arg1:String):void
  437.         {
  438.             trace("[SkypeDetection AS3] " + arg1);
  439.             return;
  440.         }
  441.  
  442.         private const CONTEXT_TOP:String="top";
  443.  
  444.         private const INSTALL_SWF_URL:String="http://api.skype.com/detection/installskype_as3.swf";
  445.  
  446.         private const CONTEXT_OTHER:String="other";
  447.  
  448.         public const REVISION:String="$Revision: 28581 $";
  449.  
  450.         private const CONTEXT_OUR:String="our";
  451.  
  452.         private var installCallback:Function;
  453.  
  454.         public var detailsText:flash.text.TextField;
  455.  
  456.         public var revisionText:flash.text.TextField;
  457.  
  458.         private var context:String;
  459.  
  460.         public var segment:String="";
  461.  
  462.         private var ourDomains:*;
  463.  
  464.         public var version:String="";
  465.  
  466.         public var language:String="";
  467.  
  468.         private var installTimer:flash.utils.Timer;
  469.  
  470.         public var platform:String="";
  471.  
  472.         public var installed:Boolean=false;
  473.     }
  474. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement