I want to override the console.log
function in order to save the data other scripts log. My script executes before any other script, so I have full control over the environment. This is my current function for overwriting console.log
:
+function(){
var a = Function.prototype, b = 'toString', c = a[b], d = c.apply(c).split(c.name), e = [], f = [], g = function(a, b){
e.push(a);
f.push(b);
return a;
}, _ = [];
a[b] = function(h){
return g(function toString(){
var i = e.indexOf(this);
return i != -1 ? f[i] || d.join(this.name) : h.apply(this);
});
}(c);
console.log = function(a){
return g(function log(){
var b = [], i;
for(i in arguments) b.push(arguments[i]);
_.push(b.slice());
return a.apply(this, arguments);
});
}(console.log);
}();
My question is simple: is it possible that some script executed after this can reveal that I have an overwritten console.log
function?
I will use it for debugging scripts sent from users to my Node.js server application. I am using vm
module, so I need to overwrite sandbox the object's console.log
function in order to trace what users log to console in received scripts.
If this code looks obfuscated, here is a better version.