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 


Trying to make Global Function [RESOLVED]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
です
Newbie cheater
Reputation: 0

Joined: 09 Feb 2008
Posts: 20

PostPosted: Sat Feb 23, 2008 4:08 pm    Post subject: Trying to make Global Function [RESOLVED] Reply with quote

I searched around the forums, also checked Wikipedia and various documentations for x86 assembly... but I couldn't find anything on what I want to do.

In CE, I want to use registersymbol to register a function that I want to be able to call from anywhere. The function is basically a very simple custom division (which works perfectly, btw) without remainders or float support.

The way I'm using it is:
Code:
push eax
mov eax,[004a7f74]
push ebx
mov ebx,[004a7f78]
call DivisionMain
mov [004a7f7c],ecx
pop eax
pop ebx
pop ecx
jmp 00401ff2

And I return like this:
Code:
GotAnswer:
ret

Where eax = number to be divided, ebx = number to be divided by, ecx = answer. Of course, I haven't shown my whole code here because it's not necessary.

Now, DivisionMain is registered. I made the call to it, and stepped through it in the debugger with a simple number (10 / 5) and successfully got the answer of 2. But, when I call ret, it jumps back to 00000000, and is stuck there in an infinite loop which results in an unhandled exception.

According to Wikipedia:
Quote:
In addition to the simple jump operations, there are the call (call a subroutine) and ret (return from subroutine) instructions. Before transferring control to the subroutine, call pushes the segment offset address of the instruction following the call onto the stack; ret pops this value off the stack, and jumps to it, effectively returning the flow of control to that part of the program. In the case of a far call, the segment base is pushed following the offset.


ret is supposed to pop the topmost value from the stack and return to it. So my code should return to mov [004a7f7c],ecx, but instead goes to 00000000.

Can I not use global functions like this?


Last edited by です on Tue Feb 26, 2008 8:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25859
Location: The netherlands

PostPosted: Sat Feb 23, 2008 6:19 pm    Post subject: Reply with quote

there are 2 things that I don't get

1:
2 pushes, 3 pops ?

2:
What type of parametertype does DivisionMain use (stdcall, or registers?)
if stdcall, the 2 pushes will be poped off by the DivisionMain
if registers the push isn't even needed, unless you just wanted to save the value, in which case, why the 3th pop ?

if c-decl, then the pushes will not be popped off by DivisionMain and you have to pop them off yourself. But again, why the 3th pop ?

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
です
Newbie cheater
Reputation: 0

Joined: 09 Feb 2008
Posts: 20

PostPosted: Sat Feb 23, 2008 6:50 pm    Post subject: Reply with quote

Since ecx is the answer to the division, DivisionMain pushes it. Also, I'm just using registers as parameters (I guess?).

Basically, it works like this:

push eax //number to divide
push ebx //number to divide eax by
call DivisionMain
...
// now inside of DivisionMain:
push ecx // answer, which is the result of division behind the scenes, which returns the right value
...
ret
...
// what ret SHOULD return to:
-do stuff with ecx here-
pop eax
pop ebx
pop ecx



If I absolutely have to post more of the division code I will, but I'm perfectly sure that there's no errors in it.

EDIT: Maybe the problem is the way I'm doing it. I have an auto-assemble script that injects the division function and registers a symbol. Then, I have another auto-assemble script that triggers when I fire a shot, which is the code that you see calling DivisionMain.

EDIT2: (not sure if I can double post to just say it's resolved, so I'll just edit)

It seems I didn't completely understand how it worked. I thought that each register had it's own stack so I could just push and pop whenever I wanted. It must have been returning to 0 because I had pushed ecx (usually at 0) to the top of the stack, when ret would pop the value on the top and return to it. So stupidity on my part.
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 Gamehacking 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