daily pastebin goal
15%
SHARE
TWEET

torbutton-jshooks4.js

a guest Nov 9th, 2015 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Bug 1506 P1: We're almost certainly going to replace this stuff with direct
  2. // patches of the JS VM.
  3.  
  4. window.__HookObjects = function() {
  5.   if (typeof(window.__tb_hooks_ran) === "boolean") {
  6.       return false;
  7.   }
  8.  
  9.   // No pref for this.. Should be mostly harmless..
  10.   if(true) {
  11.       // Wrap in anonymous function to protect scr variables just in case.
  12.       (function () {
  13.           var origHeight = window.innerHeight;
  14.           var origWidth = window.innerWidth;
  15.  
  16.           Object.defineProperty(window.__proto__, "innerWidth",
  17.                           {get: function() { return Math.round(origWidth/50.0)*50;},
  18.                           configurable: false});
  19.           Object.defineProperty(window.__proto__, "innerHeight",
  20.                           {get: function() { return Math.round(origHeight/50.0)*50;},
  21.                           configurable: false});
  22.           Object.defineProperty(window.__proto__, "outerWidth",
  23.                           {get: function() { return Math.round(origWidth/50.0)*50;},
  24.                           configurable: false});
  25.           Object.defineProperty(window.__proto__, "outerHeight",
  26.                           {get: function() { return Math.round(origHeight/50.0)*50;},
  27.                           configurable: false});
  28.           Object.defineProperty(window.__proto__, "screenX",
  29.                           {get: function() { return 0;},
  30.                           configurable: false});
  31.           Object.defineProperty(window.__proto__, "screenY",
  32.                           {get: function() { return 0;},
  33.                           configurable: false});
  34.           Object.defineProperty(MouseEvent.prototype, "screenX",
  35.                           {get: function() { return this.clientX;},
  36.                           configurable: false});
  37.           Object.defineProperty(MouseEvent.prototype, "screenY",
  38.                           {get: function() { return this.clientY;},
  39.                           configurable: false});
  40.  
  41.           // We can't define individual getters/setters for window.screen
  42.           // for some reason. works in html but not in these hooks.. No idea why
  43.  
  44.           var scr = new Object();
  45.           var origScr = window.screen;
  46.           scr.__defineGetter__("height", function() { return window.innerHeight; });
  47.           scr.__defineGetter__("width", function() { return window.innerWidth; });
  48.  
  49.           scr.__defineGetter__("availTop", function() { return 0;});
  50.           scr.__defineGetter__("availLeft", function() { return 0;});
  51.  
  52.           scr.__defineGetter__("top", function() { return 0;});
  53.           scr.__defineGetter__("left", function() { return 0;});
  54.  
  55.           scr.__defineGetter__("availHeight", function() { return window.innerHeight;});
  56.           scr.__defineGetter__("availWidth", function() { return window.innerWidth;});
  57.  
  58.           scr.__defineGetter__("colorDepth", function() { return origScr.colorDepth;});
  59.           scr.__defineGetter__("pixelDepth", function() { return origScr.pixelDepth;});
  60.  
  61.           scr.__defineGetter__("availTop", function() { return 0;});
  62.           scr.__defineGetter__("availLeft", function() { return 0;});
  63.  
  64.           Object.defineProperty(window.__proto__, "screen",
  65.                       {get: function() { return scr;},
  66.                       configurable: false});
  67.  
  68.       })();
  69.  
  70.   }
  71.  
  72.   if(window.__tb_hook_date == true) { // don't feel like indenting this
  73.   // XXX: events should not have timeStamp, unless they are of type MozBeforePaint?
  74.  
  75.   /* Timezone fix for http://gemal.dk/browserspy/css.html */
  76.   var reparseDate = function(d, str) {
  77.     /* Rules:
  78.      *   - If they specify a timezone, it is converted to local
  79.      *     time. All getter fucntions then convert properly to
  80.      *     UTC. No mod needed.
  81.      *   - If they specify UTC timezone, then it is converted
  82.      *     to local time. All getter functions then convert back.
  83.      *     No mod needed.
  84.      *   - If they specify NO timezone, it is local time.
  85.      *     The UTC conversion then reveals the offset. Fix.
  86.      */
  87.    
  88.     /* Step 1: Remove everything inside ()'s (they are "comments") */
  89.     var s = str.toLowerCase();
  90.     var re = new RegExp('\\(.*\\)', "gm");
  91.     s = s.replace(re, "");
  92.  
  93.     /* Step 2: Look for +/-. If found, do nothing */
  94.     if(s.indexOf("+") == -1 && s.indexOf("-") == -1) {
  95.       /* Step 3: Look for timezone string from
  96.        * http://lxr.mozilla.org/seamonkey/source/js/src/jsdate.c
  97.        */
  98.       if(s.indexOf(" gmt") == -1 && s.indexOf(" ut") == -1 &&
  99.          s.indexOf(" est") == -1 && s.indexOf(" edt") == -1 &&
  100.          s.indexOf(" cst") == -1 && s.indexOf(" cdt") == -1 &&
  101.          s.indexOf(" mst") == -1 && s.indexOf(" mdt") == -1 &&
  102.          s.indexOf(" pst") == -1 && s.indexOf(" pdt")) {
  103.         /* No timezone specified. Adjust. */
  104.         d.setTime(d.getTime()-(d.getTimezoneOffset()*60000));
  105.       }
  106.     }
  107.   }
  108.  
  109.   // XXX: Each origin should have its own unique offset from the real date
  110.   // XXX: Subsequent calls to the ms timer should be monotonically increasing, but randomized
  111.  
  112.   var origDate = window.Date;
  113.   var newDate = function() {
  114.     /* DO NOT make 'd' a member! EvilCode will use it! */
  115.     var d;
  116.     var a = arguments;
  117.     /* apply doesn't seem to work for constructors :( */
  118.     if(arguments.length == 0) d=new origDate();
  119.     if(arguments.length == 1) d=new origDate(a[0]);
  120.     if(arguments.length == 3) d=new origDate(a[0],a[1],a[2]);
  121.     if(arguments.length == 4) d=new origDate(a[0],a[1],a[2],a[3]);
  122.     if(arguments.length == 5) d=new origDate(a[0],a[1],a[2],a[3],a[4]);
  123.     if(arguments.length == 6) d=new origDate(a[0],a[1],a[2],a[3],a[4],a[5]);
  124.     if(arguments.length == 7) d=new origDate(a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
  125.     if(arguments.length > 7) d=new origDate();
  126.  
  127.     if(arguments.length > 0) {
  128.       if((arguments.length == 1) && typeof(a[0]) == "string") {
  129.         reparseDate(d,a[0]);
  130.       } else if(arguments.length > 1) {
  131.         /* Numerical value. No timezone given, adjust. */
  132.         d.setTime(d.getTime()-(d.getTimezoneOffset()*60000));
  133.       }
  134.     }
  135.  
  136.     // XXX: the native valueOf seems to sometimes return toString and
  137.     // sometimes return getTime depending on context (which we can't detect)
  138.     // It seems as though we can't win here..
  139.     window.Date.prototype.valueOf=function(){return d.getTime()};
  140.     window.Date.prototype.getTime=function(){return d.getTime();} /* UTC already */
  141.     window.Date.prototype.getFullYear=function(){return d.getUTCFullYear();}  
  142.     window.Date.prototype.getYear=function() {return d.getYear();}
  143.     window.Date.prototype.getMonth=function(){return d.getUTCMonth();}
  144.     window.Date.prototype.getDate=function() {return d.getUTCDate();}
  145.     window.Date.prototype.getDay=function() {return d.getUTCDay();}
  146.     window.Date.prototype.getHours=function(){return d.getUTCHours();}
  147.     window.Date.prototype.getMinutes=function(){return d.getUTCMinutes();}
  148.     window.Date.prototype.getSeconds=function(){return d.getUTCSeconds();}
  149.     window.Date.prototype.getMilliseconds=function(){return d.getUTCMilliseconds();}
  150.     window.Date.prototype.getTimezoneOffset=function(){return 0;}
  151.  
  152.     window.Date.prototype.setTime =
  153.        function(x) {return d.setTime(x);}
  154.     window.Date.prototype.setFullYear=function(x){return d.setUTCFullYear(x);}
  155.     window.Date.prototype.setYear=function(x){return d.setYear(x);}
  156.     window.Date.prototype.setMonth=function(x){return d.setUTCMonth(x);}
  157.     window.Date.prototype.setDate=function(x){return d.setUTCDate(x);}
  158.     window.Date.prototype.setDay=function(x){return d.setUTCDay(x);}
  159.     window.Date.prototype.setHours=function(x){return d.setUTCHours(x);}
  160.     window.Date.prototype.setMinutes=function(x){return d.setUTCMinutes(x);}
  161.     window.Date.prototype.setSeconds=function(x){return d.setUTCSeconds(x);}
  162.     window.Date.prototype.setMilliseconds=
  163.        function(x) {return d.setUTCMilliseconds(x);}
  164.  
  165.     window.Date.prototype.getUTCFullYear=function(){return d.getUTCFullYear();}  
  166.     window.Date.prototype.getUTCMonth=function(){return d.getUTCMonth();}
  167.     window.Date.prototype.getUTCDate=function() {return d.getUTCDate();}
  168.     window.Date.prototype.getUTCDay=function() {return d.getUTCDay();}
  169.     window.Date.prototype.getUTCHours=function(){return d.getUTCHours();}
  170.     window.Date.prototype.getUTCMinutes=function(){return d.getUTCMinutes();}
  171.     window.Date.prototype.getUTCSeconds=function(){return d.getUTCSeconds();}
  172.     window.Date.prototype.getUTCMilliseconds=
  173.        function(){return d.getUTCMilliseconds();}
  174.      
  175.     window.Date.prototype.setUTCFullYear=function(x){return d.setUTCFullYear(x);}
  176.     window.Date.prototype.setUTCMonth=function(x){return d.setUTCMonth(x);}
  177.     window.Date.prototype.setUTCDate=function(x){return d.setUTCDate(x);}
  178.     window.Date.prototype.setUTCDay=function(x){return d.setUTCDay(x);}
  179.     window.Date.prototype.setUTCHours=function(x){return d.setUTCHours(x);}
  180.     window.Date.prototype.setUTCMinutes=function(x){return d.setUTCMinutes(x);}
  181.     window.Date.prototype.setUTCSeconds=function(x){return d.setUTCSeconds(x);}
  182.     window.Date.prototype.setUTCMilliseconds=
  183.         function(x) {return d.setUTCMilliseconds(x);}
  184.  
  185.     window.Date.prototype.toUTCString=function(){return d.toUTCString();}
  186.     window.Date.prototype.toGMTString=function(){return d.toGMTString();}
  187.     window.Date.prototype.toString=function(){return d.toUTCString();}
  188.     window.Date.prototype.toLocaleString=function(){return d.toUTCString();}
  189.    
  190.     /* Fuck 'em if they can't take a joke: */
  191.     window.Date.prototype.toLocaleTimeString=function(){return d.toUTCString();}
  192.     window.Date.prototype.toLocaleDateString=function(){return d.toUTCString();}
  193.     window.Date.prototype.toDateString=function(){return d.toUTCString();}
  194.     window.Date.prototype.toTimeString=function(){return d.toUTCString();}
  195.    
  196.     /* Hack to solve the problem of multiple date objects
  197.      * all sharing the same lexically scoped d every time a new one is
  198.      * created. This hack creates a fresh new prototype reference for
  199.      * the next object to use with a different d binding.
  200.      * It doesn't break stuff because at the start of this function,
  201.      * the interpreter grabbed a reference to Date.prototype. During
  202.      * this function we modified Date.prototype to create the new methods
  203.      * with the lexically scoped d reference.
  204.      */
  205.  
  206.     // valueOf gets called for implicit string conversion??
  207.     window.Date.prototype = window.eval(window.Object.prototype.toSource());
  208.     return d.toUTCString();
  209.   }
  210.  
  211.   // Need to do this madness so that we use the window's notion of Function
  212.   // for the constructor. If this is not done, then changes to Function
  213.   // and Object in the real window are not propogated to Date (for example,
  214.   // to extend the Date class with extra functions via a generic inheritance
  215.   // framework added onto Object - this is done by livejournal and others)
  216.   var newWrappedDate = window.eval("function() { return newDate(); }");
  217.  
  218.   newWrappedDate.parse=function(s) {
  219.     var d = new origDate(s);
  220.     if(typeof(s) == "string") reparseDate(d, s);
  221.     return d.getTime();    
  222.   }
  223.  
  224.   newWrappedDate.now=function(){return origDate.now();}
  225.   newWrappedDate.UTC=function(){return origDate.apply(origDate, arguments); }
  226.  
  227.   // d = new Date();
  228.   // d.__proto__ === Date.prototype
  229.   // d.constructor === Date
  230.   // d.__proto__ === d.constructor.prototype
  231.   // Date.prototype.__proto__  ===  Date.prototype.constructor.prototype
  232.   // window.__proto__ === Window.prototypea
  233.  
  234.   Object.defineProperty(window.__proto__, "Date",
  235.                       {get: function() { return newWrappedDate;},
  236.                       configurable: false});
  237.  
  238.   } // window.__tb_hook_date == true
  239.  
  240.   //Object.defineProperty(window.Components.__proto__, "lookupMethod",
  241.   //        {get: function() { return function (a,b) { return function() { return a[b]; }; };},
  242.   //         configurable: false});
  243.  
  244.   return true;
  245. }
  246.  
  247. if (typeof(window.__HookObjects) != "undefined") {
  248.     var res = 23;
  249.  
  250.     if(!window.__HookObjects()) {
  251.         res = 13;
  252.     }
  253.  
  254.     window.__HookObjects = undefined;
  255.     delete window['__HookObjects'];
  256.     delete window['__CheckFlag'];
  257.     delete window['__tb_set_uagent'];
  258.     delete window['__tb_oscpu'];
  259.     delete window['__tb_platform'];
  260.     delete window['__tb_productSub'];
  261.  
  262.     window.__tb_hooks_ran = true;
  263.  
  264.     res; // Secret result code.
  265. } else {
  266.     42;
  267. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top