From a2a25f8c3fdf7338eef2054f86570a2f42ffe0ea Mon Sep 17 00:00:00 2001 From: "mosse.benjamin" Date: Fri, 25 Mar 2011 07:17:01 +0000 Subject: [PATCH] fixing beefjs json code to work on IE git-svn-id: https://beef.googlecode.com/svn/trunk@803 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- lib/server/dynamichandler.rb | 1 + modules/beefjs/browser.js | 1 - modules/beefjs/encode/json.js | 40 +++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/server/dynamichandler.rb b/lib/server/dynamichandler.rb index 97f3232f7..ae7098473 100644 --- a/lib/server/dynamichandler.rb +++ b/lib/server/dynamichandler.rb @@ -51,6 +51,7 @@ module BeEF data += sp[:data] end end + p Base64.decode64(data) data = JSON.parse(Base64.decode64(data)).first data['beefhook'] = packet[:beefhook] data['request'] = @request diff --git a/modules/beefjs/browser.js b/modules/beefjs/browser.js index e513a5030..c502ff0ee 100644 --- a/modules/beefjs/browser.js +++ b/modules/beefjs/browser.js @@ -204,7 +204,6 @@ beef.browser = { * @example: beef.browser.isO() */ isO: function() { - console.log("isO called"); return this.isO952() || this.isO960() || this.isO10() || this.isO11(); }, diff --git a/modules/beefjs/encode/json.js b/modules/beefjs/encode/json.js index 2b7c9ba3c..42f7a0fdc 100644 --- a/modules/beefjs/encode/json.js +++ b/modules/beefjs/encode/json.js @@ -18,12 +18,12 @@ beef.encode.json = { return o + ""; if (type == "string") - return $.quoteString(o); + return $j.quoteString(o); if (type == 'object') { if (typeof o.toJSON == "function") - return $.toJSON( o.toJSON() ); + return $j.toJSON( o.toJSON() ); if (o.constructor === Date) { @@ -57,7 +57,7 @@ beef.encode.json = { { var ret = []; for (var i = 0; i < o.length; i++) - ret.push( $.toJSON(o[i]) || "null" ); + ret.push( $j.toJSON(o[i]) || "null" ); return "[" + ret.join(",") + "]"; } @@ -70,22 +70,50 @@ beef.encode.json = { if (type == "number") name = '"' + k + '"'; else if (type == "string") - name = $.quoteString(k); + name = $j.quoteString(k); else continue; //skip non-string or number keys if (typeof o[k] == "function") continue; //skip pairs where the value is a function. - var val = $.toJSON(o[k]); + var val = $j.toJSON(o[k]); pairs.push(name + ":" + val); } return "{" + pairs.join(", ") + "}"; } - + }, + + quoteString: function(string) { + if (string.match(this._escapeable)) + { + return '"' + string.replace(this._escapeable, function (a) + { + var c = this._meta[a]; + if (typeof c === 'string') return c; + c = a.charCodeAt(); + return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); + }) + '"'; + } + return '"' + string + '"'; + }, + + _escapeable: /["\\\x00-\x1f\x7f-\x9f]/g, + + _meta : { + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' } } +$j.toJSON = function(o) {return beef.encode.json.stringify(o);} +$j.quoteString = function(o) {return beef.encode.json.quoteString(o);} + beef.regCmp('beef.encode.json');