Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[JS] how can I rename a native function?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Tue Sep 01, 2009 4:52 pm    Post subject: [JS] how can I rename a native function? Reply with quote

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
View user's profile Send private message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Tue Sep 01, 2009 5:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Tue Sep 01, 2009 7:59 pm    Post subject: Reply with quote

No I want to use it for a greasemonkey script to stop a website from doing what it wants.
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Sep 01, 2009 8:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Sep 01, 2009 9:07 pm    Post subject: Reply with quote

http://www.squakmt.com/replacing_javascript/index.htm
Back to top
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Tue Sep 01, 2009 9:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Sep 01, 2009 9:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Tue Sep 01, 2009 9:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Sep 01, 2009 9:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Tue Sep 01, 2009 10:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Fri Sep 11, 2009 11:13 am    Post subject: Reply with quote

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
Code:
close(true)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites