Saturday, 15 May 2010

javascript - Overwrite an object function from an external script before it is called -



javascript - Overwrite an object function from an external script before it is called -

i'm trying write greasemonkey script or userscript prepare bug in website, deals erroneous function of object. can prepare problem manually, adding breakpoint @ line of code generates function prototype, , manually overwriting function prototype using js console. however, don't think there way code. external script loaded @ end of html body, problem code executed within same script.

is there way somehow inject javascript code page, when ft.prototype.j created, can modify it? problem code obfuscated , minified, i'm not sure half of does.

here basic rundown of code:

//what do????? function a(a, b) { function c() {} c.prototype = b.prototype; a.f = b.prototype; a.prototype = new c; a.prototype.constructor = } function ft(a, b) { $.call(this, b); //some stuff } //doing jquery? a(ft, $); ft.prototype.j = function (a) { //modifies dom content }; //code after calls object.j

if add together in line of code ft.prototype.j = function() {} //my own function, greasemonkey script, gives me error, expected, ft not defined. but, if execute line @ end of load, broken function has been run, , dom infected.

thanks.

i think can perform magic getters/setters , object.defineproperty, since function declared globally:

(function() { var ft; function myj() { // whatever want } object.defineproperty(window, "ft", { // utilize unsafewindow in gm? configurable: true, enumerable: true, get: function() { homecoming ft; }, set: function(n) { // hah, we've catched function declaration! ft = n; // making non-writable lead exception object.defineproperty(ft.prototype, "j", { get: function() { homecoming myj; }, set: function() { /* ignore it! */ } }); } }); })();

now if executes code you've posted in question, setters invoked , can values want.

javascript

No comments:

Post a Comment