View previous topic :: View next topic |
Author |
Message |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Tue Sep 01, 2009 4:52 pm Post subject: [JS] how can I rename a native function? |
|
|
basically, what I want to do is make it so that calling close() only works if you've filled in an argument that resolves to true, e.g. Code: | close = function(t){t ? close() : null} | but that doesn't work because it is just looping back to itself; so I tried Code: | var close_true = close;
close = function(t){t ? close_true() : null} | but now, close_true is actually acting like this Code: | function(){close();} | rather than a separate close function, and obviously, it doesn't work as it results in the same problem as before.
So what do I do!?
|
|
Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Tue Sep 01, 2009 5:59 pm Post subject: |
|
|
Can't you just call a separate function?
Code: | function _close(t) {
if(t) close();
}
// do your normal stuff...
// blah blah blah, more code
var x = true;
_close(x); |
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time. |
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Tue Sep 01, 2009 7:59 pm Post subject: |
|
|
No I want to use it for a greasemonkey script to stop a website from doing what it wants.
|
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Sep 01, 2009 8:13 pm Post subject: |
|
|
Function:
Code: |
function(argument)
{
if(argument)
close();
else
return false;
return true;
}
|
Example usage:
Code: |
var closed;
closed = function(argument);
if(closed)
/* closed successfully */
else
/* did not close */
|
Is that what you are asking for?
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Tue Sep 01, 2009 9:10 pm Post subject: |
|
|
What I want is like a hook on the function called "close" which is a native function i.e. the following is true Code: | close.toString() == "function close() {\n\
[native code]\n\
}" | so that when it is called, it only works if I want it to work.
if you're wondering why I don't catch the "close" in the servers code; it is because the name of the function it is in is hashed.
@nwongfeiying; what you wrote makes no sense as if it closed then the rest of the code wouldn't execute, and I'm sure it is a void, too.
@Athaem I know how to append new scripts; that isn't what I'm asking here. I'm asking about native code (close() is written by your browsers developers, not the page developers).
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Sep 01, 2009 9:27 pm Post subject: |
|
|
shhac wrote: | @Athaem I know how to append new scripts; that isn't what I'm asking here. I'm asking about native code (close() is written by your browsers developers, not the page developers). |
The point of linking that, was to tell you that you should just copy the script, and override their functions with the ones you want checked.
|
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Tue Sep 01, 2009 9:45 pm Post subject: |
|
|
Athaem wrote: | shhac wrote: | @Athaem I know how to append new scripts; that isn't what I'm asking here. I'm asking about native code (close() is written by your browsers developers, not the page developers). |
The point of linking that, was to tell you that you should just copy the script, and override their functions with the ones you want checked. | The method that guy uses is really inefficient, and, as I keep saying, it isn't what I'm trying to do. You can't replace native functions like that and then use the original purpose.
I can't modify the function that isn't native without knowing its name and it isn't something static which is why I wanted to get the one I do know the name of.
|
|
Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Tue Sep 01, 2009 9:55 pm Post subject: |
|
|
My code made sense. It just wasn't what you were looking for. I don't think anyone knows what you're looking for. Your request is poorly stated.
|
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Tue Sep 01, 2009 10:11 pm Post subject: |
|
|
Yes I'm aware it is poorly stated. I'm having difficulty saying what I want to do because I'm not sure how this type of thing is done in JS.
I could explain it in terms of another programming language easier maybe;
VB.NET would look something like this (where Exit would be the VB.NET equivalent to close in JavaScript)
Code: | Protected Overrides Sub Exit(Optional ByVal t As Boolean = False)
If t Then
Exit()
End If
End Sub |
And creating a second function to hold a copy of the original is fine too, as I don't know if you can achieve it as simply as a proper programming language.
The closest thing I've found is Code: | var base_foo;
function foo(){
return 'foo is called';
}
base_foo = foo;
function foo(){
return 'overrided ' + base_foo();
}
alert(base_foo()); | But it doesn't seem to work when the function uses native code because base_foo = foo; is not working the same way.
Code above was para-coded from here > http://dataerror.blogspot.com/2005/08/javascript-function-overriding-part-4.html
Edit:
Following code appears to work in some cases (but not all) Code: | var orig_close = close;
function close(t){
if(t) orig_close();
}
close(true); |
|
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Fri Sep 11, 2009 11:13 am Post subject: |
|
|
yay reviving old threads
Figured out how to make it always work - put the new name as a constant, not a variable and it will protect it even if the original is changed in any way. Code: | const _close = close;
function close(t){
if(t) _close();
} | then to use
|
|
Back to top |
|
 |
|