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 


When do API's get called?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
xeratal
Advanced Cheater
Reputation: 1

Joined: 05 Nov 2005
Posts: 93

PostPosted: Tue Dec 27, 2011 8:17 pm    Post subject: When do API's get called? Reply with quote

Seems like an obvious answer,

but I've tried e.g. go SendInput API in a program which I know uses it, then get that address, and search call <address#>.
Can't find it in the normal programs memory region.

Even in CheatEngine, I tried searching for a call to WriteProcessMemory - only one came up, at API CloseProfileUserMapping. Is CE simply calling something which eventually calls CloseProfileUserMapping and then WriteProcessMemory or am I doing something wrong?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Dec 27, 2011 8:22 pm    Post subject: Reply with quote

APIs are called when the application invokes them. They are just calls. If you want to log API information just set a breakpoint on the API itself rather then looking for all the calls to it.

1. Attach to the process.
2. Open memory viewer.
3. Hit Ctrl+G and enter the API name, ex. 'WriteProcessMemory' without the quotes.

Set a break at the start and you can look at the call stack to see where it was called and the params passed to it. I recommend using OllyDbg for debugging though since it has a bit more in depth stuff with breakpoints and known API calls that can make your life easier.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
xeratal
Advanced Cheater
Reputation: 1

Joined: 05 Nov 2005
Posts: 93

PostPosted: Tue Dec 27, 2011 8:30 pm    Post subject: Reply with quote

I thought of that but since I couldn't even find a single call to it (well besides that one example for CE) I assumed that I wouldn't get anything by doing that.

I'll try now - will update if any results...

-Edit add

It worked! I found that it was one of the things I thought might be happening, that is one API was calling another API so it was in the 7xxxxxxx area of memory...

But I cheated to find the return address because my computer was crashing if I traced anything more than 10 lines of code in that area...
Just for knowledge - if I wanted to find the return address, where would that be in? I thought it would be in one of the registers, probably EBP or ESP, but when I looked it up it wasn't. Or is it that a "ret" statement would do something like "return to whatever comes out of the stack next" or something like that? If so, could you explain how to view the stack in CE if possible? That's another thing I could never figure out Sad

P.S. I've used Olly a little but I'm trying to extend my knowledge of CE for now.
Back to top
View user's profile Send private message
Geri
Moderator
Reputation: 111

Joined: 05 Feb 2010
Posts: 5627

PostPosted: Tue Dec 27, 2011 9:22 pm    Post subject: Reply with quote

Return addresses are in the stack. You can see the stack in the lower right corner when you are debugging.
_________________
My trainers can be found here: http://www.szemelyesintegracio.hu/cheats

If you are interested in any of my crappy articles/tutorials about CE and game hacking, you can find them here:
http://www.szemelyesintegracio.hu/cheats/41-game-hacking-articles

Don't request cheats or updates.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 28, 2011 3:17 pm    Post subject: Reply with quote

Take Minesweeper for example, when a flag is used this is called:

Code:

0100346A - 8B 44 24 04                - mov eax,[esp+04]
0100346E - 01 05 94510001             - add [01005194],eax
01003474 - E8 88F3FFFF                - call 01002801
01003479 - C2 0400                    - ret 0004


ret 0004 because one argument was passed to this function (eax).
We want to find the return address so we break on the first instruction, mov.

When you go back into Minesweeper, use a flag (right-click) to trigger the breakpoint. So now we are set. Look at the bottom right in the memory viewer for the stack info. To read it easier, right-click it and choose 'full stack'.

In our case the stack should look something like this:
0x0007FD48 (esp+0) - 0x010037B4 - This is our return address.
0x0007FD4C (esp+4) - 0xFFFFFFFF - This is the first param to our function.
0x0007FD50 (esp+Cool - 0x7E428D8B - etc.
0x0007FD54 (esp+C) - 0x010021BB - etc.

So read 0x0007FD48 as a pointer and you get the return address. (This will change depending on the function and such.)

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions 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