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 


Winapi List functions of a Module

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Corruptor
Advanced Cheater
Reputation: 3

Joined: 10 Aug 2011
Posts: 82

PostPosted: Tue Jun 11, 2013 8:02 pm    Post subject: Winapi List functions of a Module Reply with quote

Well, so far i found out that you can list the loaded module handles (which practically are just their offsets cast to a HMODULE) using EnumProcessModules. Furthermore, i found out that GetProcAddress can be used to find a specific function inside of this module. At least, most of the time.
The problem is that i ran into a module where GetProcAddress seems to fail; it just doesnt find the functions i tell it to find, constantly returning ERROR_MOD_NOT_FOUND even though i am 100% sure that this function does exist (at least i can find it with cheat engine, so i highly assume that its there)

So i thought i might just list all the functions from that module and look what functions actually ARE there, just to find that i have absolutely no clue how to do that. I mean, it has to be possible somehow as cheat engine is obviously able to do that somehow, but i just can't seem to find anything about it. (Probably im just searching for the wrong terms).

long story short: how do i list them? Very Happy
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 Jun 11, 2013 8:21 pm    Post subject: Reply with quote

GetProcAddress does not work remotely. It is specifically for the modules located in the process that is calling the function.

If you need to get the address of an export from a dll, load it into your memory space then call GetProcAddress on it when it is loaded inside your own process.

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

Joined: 10 Aug 2011
Posts: 82

PostPosted: Wed Jun 12, 2013 6:08 am    Post subject: Reply with quote

In hindsight, i should have known, given the fact that GetProcAddress doesn't even take a process handle as a parameter Embarassed
Also explains why it worked for the kernel.dll; afaik this one is always mapped to the exact same position.

However, as far as i know, both the position of the loaded dll as well as the position of their functions may vary every time someone loads the dll into his virtual memory, so if i loaded the dll and then used GetProcAddress on the newly loaded dll, wouldn't i get an address that is unique for my process?
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 Jun 12, 2013 6:13 am    Post subject: This post has 2 review(s) Reply with quote

Corruptor wrote:
In hindsight, i should have known, given the fact that GetProcAddress doesn't even take a process handle as a parameter Embarassed
Also explains why it worked for the kernel.dll; afaik this one is always mapped to the exact same position.

However, as far as i know, both the position of the loaded dll as well as the position of their functions may vary every time someone loads the dll into his virtual memory, so if i loaded the dll and then used GetProcAddress on the newly loaded dll, wouldn't i get an address that is unique for my process?


You can calculate the position internally and make the call remotely still.

Load the library into your own address space and call GetProcAddress on the function you want. Then subtract the function address from the base address returned from LoadLibrary. That will give you the function offset.

Then locate the module remotely in the target process, get its base address, then add the offset you got locally and you will have the function address in the remote target as well.

Then you can use CreateRemoteThread to call it. Keep in mind you may have to inject a stub to call it properly if the function expects arguments and such.

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

Joined: 10 Aug 2011
Posts: 82

PostPosted: Wed Jun 12, 2013 3:55 pm    Post subject: Reply with quote

Works like a charm. Thanks a lot for your help Smile
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