Advertisement
prog

eval.js

Nov 25th, 2010
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var users = " prog.ma corruptedminds.org ";
  2.  
  3. function oncommand()
  4. {
  5.   if (users.indexOf(' ' + user.hostname + ' ') < 0 && user.hand.length == 0)
  6.     return;
  7.  
  8.   switch (command)
  9.   {
  10.     case "js":
  11.     case "eval":
  12.       try
  13.       {
  14.         var result = eval(text);
  15.         if (typeof(result) == "undefined")
  16.         {
  17.           chan.msg("OK");
  18.         }
  19.         else
  20.         {
  21.           if (typeof(result) == "function")
  22.           {
  23.             chan.msg("" + result);
  24.           }
  25.           else
  26.           {
  27.             chan.msg(JSON.stringify(result));
  28.           }
  29.         }
  30.       }
  31.       catch (e)
  32.       {
  33.         chan.msg(e.description);
  34.       }
  35.     break;
  36.   }
  37. }
  38.  
  39. clone = function() {
  40.   client_connect = function() {
  41.     peer.sendline("NICK Za3tar`" + Math.floor(Math.random() * 1000000));
  42.     peer.sendline("USER clone 0 0 :I am a clone");
  43.   };
  44.   client_readline = function() {
  45.     args = text.split(' ');
  46.     if (args[0] == "PING")
  47.       peer.sendline("PONG " + args[1]);
  48.   };
  49.   var c = CreateTcpClient();
  50.   c.onconnect = "client_connect";
  51.   c.onreadline = "client_readline";
  52.   c.connect("192.168.0.1", 6667);
  53.   return c;
  54. };
  55.  
  56. function WriteObject(sFilePathAndName, obj)
  57. {
  58.   WriteFile(sFilePathAndName, JSON.stringify(obj));
  59. }
  60.  
  61. function ReadObject(sFilePathAndName)
  62. {
  63.   return JSON.parse(ReadFile(sFilePathAndName));
  64. }
  65.  
  66. function WriteFile(sFilePathAndName, sFileContents)
  67. {
  68.   var ForWriting = 2;
  69.  
  70.   var oFS = new ActiveXObject("Scripting.FileSystemObject");
  71.   var oFSFile = oFS.OpenTextFile(sFilePathAndName, ForWriting, true);
  72.  
  73.   oFSFile.Write(sFileContents);
  74.   oFSFile.Close();
  75. }
  76.  
  77. function ReadFile(sFilePathAndName)
  78. {
  79.    var sFileContents = "";
  80.  
  81.    var oFS = new ActiveXObject("Scripting.FileSystemObject");
  82.  
  83.    if (oFS.FileExists(sFilePathAndName))
  84.    {
  85.       oTextStream = oFS.OpenTextFile(sFilePathAndName,1);
  86.       sFileContents = oTextStream.ReadAll();
  87.       oTextStream.Close();
  88.    }
  89.  
  90.    return sFileContents;
  91. }
  92.  
  93. var global = this;
  94.  
  95. var JSON = {};
  96.  
  97. (function () {
  98.  
  99.     function f(n) {
  100.         // Format integers to have at least two digits.
  101.         return n < 10 ? '0' + n : n;
  102.     }
  103.  
  104.     if (typeof Date.prototype.toJSON !== 'function') {
  105.  
  106.         Date.prototype.toJSON = function (key) {
  107.  
  108.             return isFinite(this.valueOf()) ?
  109.                    this.getUTCFullYear()   + '-' +
  110.                  f(this.getUTCMonth() + 1) + '-' +
  111.                  f(this.getUTCDate())      + 'T' +
  112.                  f(this.getUTCHours())     + ':' +
  113.                  f(this.getUTCMinutes())   + ':' +
  114.                  f(this.getUTCSeconds())   + 'Z' : null;
  115.         };
  116.  
  117.         String.prototype.toJSON =
  118.         Number.prototype.toJSON =
  119.         Boolean.prototype.toJSON = function (key) {
  120.             return this.valueOf();
  121.         };
  122.     }
  123.  
  124.     var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  125.         escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  126.         gap,
  127.         indent,
  128.         meta = {    // table of character substitutions
  129.             '\b': '\\b',
  130.             '\t': '\\t',
  131.             '\n': '\\n',
  132.             '\f': '\\f',
  133.             '\r': '\\r',
  134.             '"' : '\\"',
  135.             '\\': '\\\\'
  136.         },
  137.         rep;
  138.  
  139.  
  140.     function quote(string) {
  141.  
  142. // If the string contains no control characters, no quote characters, and no
  143. // backslash characters, then we can safely slap some quotes around it.
  144. // Otherwise we must also replace the offending characters with safe escape
  145. // sequences.
  146.  
  147.         escapable.lastIndex = 0;
  148.         return escapable.test(string) ?
  149.             '"' + string.replace(escapable, function (a) {
  150.                 var c = meta[a];
  151.                 return typeof c === 'string' ? c :
  152.                     '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  153.             }) + '"' :
  154.             '"' + string + '"';
  155.     }
  156.  
  157.  
  158.     function str(key, holder) {
  159.  
  160. // Produce a string from holder[key].
  161.  
  162.         var i,          // The loop counter.
  163.             k,          // The member key.
  164.             v,          // The member value.
  165.             length,
  166.             mind = gap,
  167.             partial,
  168.             value = holder[key];
  169.  
  170. // If the value has a toJSON method, call it to obtain a replacement value.
  171.  
  172.         if (value && typeof value === 'object' &&
  173.                 typeof value.toJSON === 'function') {
  174.             value = value.toJSON(key);
  175.         }
  176.  
  177. // If we were called with a replacer function, then call the replacer to
  178. // obtain a replacement value.
  179.  
  180.         if (typeof rep === 'function') {
  181.             value = rep.call(holder, key, value);
  182.         }
  183.  
  184. // What happens next depends on the value's type.
  185.  
  186.         switch (typeof value) {
  187.         case 'string':
  188.             return quote(value);
  189.  
  190.         case 'number':
  191.  
  192. // JSON numbers must be finite. Encode non-finite numbers as null.
  193.  
  194.             return isFinite(value) ? String(value) : 'null';
  195.  
  196.         case 'boolean':
  197.         case 'null':
  198.  
  199. // If the value is a boolean or null, convert it to a string. Note:
  200. // typeof null does not produce 'null'. The case is included here in
  201. // the remote chance that this gets fixed someday.
  202.  
  203.             return String(value);
  204.  
  205. // If the type is 'object', we might be dealing with an object or an array or
  206. // null.
  207.  
  208.         case 'object':
  209.  
  210. // Due to a specification blunder in ECMAScript, typeof null is 'object',
  211. // so watch out for that case.
  212.  
  213.             if (!value) {
  214.                 return 'null';
  215.             }
  216.  
  217. // Make an array to hold the partial results of stringifying this object value.
  218.  
  219.             gap += indent;
  220.             partial = [];
  221.  
  222. // Is the value an array?
  223.  
  224.             if (Object.prototype.toString.apply(value) === '[object Array]') {
  225.  
  226. // The value is an array. Stringify every element. Use null as a placeholder
  227. // for non-JSON values.
  228.  
  229.                 length = value.length;
  230.                 for (i = 0; i < length; i += 1) {
  231.                     partial[i] = str(i, value) || 'null';
  232.                 }
  233.  
  234. // Join all of the elements together, separated with commas, and wrap them in
  235. // brackets.
  236.  
  237.                 v = partial.length === 0 ? '[]' :
  238.                     gap ? '[\n' + gap +
  239.                             partial.join(',\n' + gap) + '\n' +
  240.                                 mind + ']' :
  241.                           '[' + partial.join(',') + ']';
  242.                 gap = mind;
  243.                 return v;
  244.             }
  245.  
  246. // If the replacer is an array, use it to select the members to be stringified.
  247.  
  248.             if (rep && typeof rep === 'object') {
  249.                 length = rep.length;
  250.                 for (i = 0; i < length; i += 1) {
  251.                     k = rep[i];
  252.                     if (typeof k === 'string') {
  253.                         v = str(k, value);
  254.                         if (v) {
  255.                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
  256.                         }
  257.                     }
  258.                 }
  259.             } else {
  260.  
  261. // Otherwise, iterate through all of the keys in the object.
  262.  
  263.                 for (k in value) {
  264.                     if (Object.hasOwnProperty.call(value, k)) {
  265.                         v = str(k, value);
  266.                         if (v) {
  267.                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
  268.                         }
  269.                     }
  270.                 }
  271.             }
  272.  
  273. // Join all of the member texts together, separated with commas,
  274. // and wrap them in braces.
  275.  
  276.             v = partial.length === 0 ? '{}' :
  277.                 gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
  278.                         mind + '}' : '{' + partial.join(',') + '}';
  279.             gap = mind;
  280.             return v;
  281.         }
  282.     }
  283.  
  284. // If the JSON object does not yet have a stringify method, give it one.
  285.  
  286.     if (typeof JSON.stringify !== 'function') {
  287.         JSON.stringify = function (value, replacer, space) {
  288.  
  289. // The stringify method takes a value and an optional replacer, and an optional
  290. // space parameter, and returns a JSON text. The replacer can be a function
  291. // that can replace values, or an array of strings that will select the keys.
  292. // A default replacer method can be provided. Use of the space parameter can
  293. // produce text that is more easily readable.
  294.  
  295.             var i;
  296.             gap = '';
  297.             indent = '';
  298.  
  299. // If the space parameter is a number, make an indent string containing that
  300. // many spaces.
  301.  
  302.             if (typeof space === 'number') {
  303.                 for (i = 0; i < space; i += 1) {
  304.                     indent += ' ';
  305.                 }
  306.  
  307. // If the space parameter is a string, it will be used as the indent string.
  308.  
  309.             } else if (typeof space === 'string') {
  310.                 indent = space;
  311.             }
  312.  
  313. // If there is a replacer, it must be a function or an array.
  314. // Otherwise, throw an error.
  315.  
  316.             rep = replacer;
  317.             if (replacer && typeof replacer !== 'function' &&
  318.                     (typeof replacer !== 'object' ||
  319.                      typeof replacer.length !== 'number')) {
  320.                 throw new Error('JSON.stringify');
  321.             }
  322.  
  323. // Make a fake root object containing our value under the key of ''.
  324. // Return the result of stringifying the value.
  325.  
  326.             return str('', {'': value});
  327.         };
  328.     }
  329.  
  330.  
  331. // If the JSON object does not yet have a parse method, give it one.
  332.  
  333.     if (typeof JSON.parse !== 'function') {
  334.         JSON.parse = function (text, reviver) {
  335.  
  336. // The parse method takes a text and an optional reviver function, and returns
  337. // a JavaScript value if the text is a valid JSON text.
  338.  
  339.             var j;
  340.  
  341.             function walk(holder, key) {
  342.  
  343. // The walk method is used to recursively walk the resulting structure so
  344. // that modifications can be made.
  345.  
  346.                 var k, v, value = holder[key];
  347.                 if (value && typeof value === 'object') {
  348.                     for (k in value) {
  349.                         if (Object.hasOwnProperty.call(value, k)) {
  350.                             v = walk(value, k);
  351.                             if (v !== undefined) {
  352.                                 value[k] = v;
  353.                             } else {
  354.                                 delete value[k];
  355.                             }
  356.                         }
  357.                     }
  358.                 }
  359.                 return reviver.call(holder, key, value);
  360.             }
  361.  
  362.  
  363. // Parsing happens in four stages. In the first stage, we replace certain
  364. // Unicode characters with escape sequences. JavaScript handles many characters
  365. // incorrectly, either silently deleting them, or treating them as line endings.
  366.  
  367.             cx.lastIndex = 0;
  368.             if (cx.test(text)) {
  369.                 text = text.replace(cx, function (a) {
  370.                     return '\\u' +
  371.                         ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  372.                 });
  373.             }
  374.  
  375. // In the second stage, we run the text against regular expressions that look
  376. // for non-JSON patterns. We are especially concerned with '()' and 'new'
  377. // because they can cause invocation, and '=' because it can cause mutation.
  378. // But just to be safe, we want to reject all unexpected forms.
  379.  
  380. // We split the second stage into 4 regexp operations in order to work around
  381. // crippling inefficiencies in IE's and Safari's regexp engines. First we
  382. // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
  383. // replace all simple value tokens with ']' characters. Third, we delete all
  384. // open brackets that follow a colon or comma or that begin the text. Finally,
  385. // we look to see that the remaining characters are only whitespace or ']' or
  386. // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
  387.  
  388.             if (/^[\],:{}\s]*$/.
  389. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  390. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  391. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  392.  
  393. // In the third stage we use the eval function to compile the text into a
  394. // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
  395. // in JavaScript: it can begin a block or an object literal. We wrap the text
  396. // in parens to eliminate the ambiguity.
  397.  
  398.                 j = eval('(' + text + ')');
  399.  
  400. // In the optional fourth stage, we recursively walk the new structure, passing
  401. // each name/value pair to a reviver function for possible transformation.
  402.  
  403.                 return typeof reviver === 'function' ?
  404.                     walk({'': j}, '') : j;
  405.             }
  406.  
  407. // If the text is not JSON parseable, then a SyntaxError is thrown.
  408.  
  409.             throw new SyntaxError('JSON.parse');
  410.         };
  411.     }
  412. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement